'待支付', self::PAY_TYPE_WECHAT => '微信支付', self::PAY_TYPE_ACCOUNT => '余额支付' ]; const PAY_STATUS_OK = 1; const PAY_STATUS_NO = 0; public static $payStatusMaps = [ self::PAY_STATUS_NO => '未支付', self::PAY_STATUS_OK => '已支付' ]; public function users() { return $this->belongsTo(User::class, 'user_id', 'id'); } public function bikes() { return $this->belongsTo(Bike::class, 'bike_id', 'id'); } public function area() { return $this->belongsTo(Area::class, 'area_id', 'id'); } /** * 生成订单号 * @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_PUNISHMENT_ORDER, $this->attributes['area_id'], $this->attributes['id'], PunishmentOrder::class); WalletLog::log(WalletLog::OPERATE_TYPE_SUB, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_SUB_WECHAT_PAY_PUNISHMENT_ORDER, $this->attributes['area_id'], $this->attributes['id'], PunishmentOrder::class); //修改订单记录 $this->pay_status = PunishmentOrder::PAY_STATUS_OK; $this->pay_time = now(); $this->pay_type = PunishmentOrder::PAY_TYPE_WECHAT; $this->save(); return true; } }