123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- *
- *
- * @category xxx
- * @package PSR
- * @subpackage Documentation\API
- * @author xxx <xxx@xxx.com>
- * @license GPL https://xxx.com
- * @link https://xxx.com
- * @ctime: 2020/4/30 15:32
- */
- namespace App\Models;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- class DepositCardOrder extends Model
- {
- protected $table = 'deposit_card_orders';
- protected $fillable = ['no', 'area_id', 'user_id', 'deposit_cards_id', 'money', 'effective_days', 'discount', 'pay_money', 'pay_type', 'pay_status', 'pay_time', 'status'];
- const NO_TAG = 'M';
- const PAY_TYPE_WECHAT = 1;
- const PAY_TYPE_ACCOUNT = 2;
- const PAY_TYPE_ADMIN_GIVE = 3;
- const PAY_TYPE_INVITE_NEW_USER_GIVE = 4;
- public static $payTypeMaps = [
- self::PAY_TYPE_WECHAT => '微信支付',
- self::PAY_TYPE_ACCOUNT => '余额支付',
- self::PAY_TYPE_ADMIN_GIVE => '后台赠送',
- self::PAY_TYPE_INVITE_NEW_USER_GIVE => '邀请新用户赠送'
- ];
- const PAY_STATUS_OK = 1;
- const PAY_STATUS_NO = 0;
- public static $payStatusMaps = [
- self::PAY_STATUS_OK => '支付成功',
- self::PAY_STATUS_NO => '支付失败',
- ];
- const STATUS_OK = 1;
- const STATUS_NO = 0;
- public static $statusMaps = [
- self::STATUS_OK => '支付成功',
- self::STATUS_NO => '支付失败'
- ];
- /**
- * 生成订单号
- * @return bool|string
- * User: Mead
- */
- public static function makeNo()
- {
- // 订单流水号前缀
- $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
- for ($i = 0; $i < 10; $i++) {
- // 随机生成 6 位的数字
- $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
- // 判断是否已经存在
- if (!static::query()->where('no', $no)->exists()) {
- return $no;
- }
- }
- Log::warning('find order no failed');
- return false;
- }
- public function pay_order_callback()
- {
- //添加钱包记录
- WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_ADD_WECHAT_PAY_CARD_DEPOSIT_ORDER, $this->attributes['area_id'], $this->attributes['id'], DepositCardOrder::class);
- WalletLog::log(WalletLog::OPERATE_TYPE_SUB, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_SUB_WECHAT_PAY_CARD_DEPOSIT_ORDER, $this->attributes['area_id'], $this->attributes['id'], DepositCardOrder::class);
- // 修改用户押金状态
- $user = User::find($this->attributes['user_id']);
- $deposit_expire_time = Carbon::parse($user->deposit_expire_time);
- if (Carbon::now()->gte($deposit_expire_time)) {
- $time = Carbon::now();
- } else {
- $time = $deposit_expire_time;
- }
- //判断用户是否已经缴纳押金
- if ((int)$user->is_deposit === User::DEPOSIT_OK && (int)$user->deposit_type === User::DEPOSIT_MONEY) {
- //已交押金
- User::where('id', $this->attributes['user_id'])->update([
- 'deposit_expire_time' => $time->addDays($this->attributes['effective_days'])
- ]);
- } else {
- //未交押金
- User::where('id', $this->attributes['user_id'])->update([
- 'deposit_expire_time' => $time->addDays($this->attributes['effective_days']),
- 'deposit_type' => User::DEPOSIT_CARD,
- 'is_deposit' => User::DEPOSIT_OK
- ]);
- }
- $this->save();
- return true;
- }
- }
|