'array', 'end_use_bike_location' => 'array', 'setting' => 'json', ]; const REDIS_BIKE_LOCATION_TAG = 'bike_locations'; const NO_TAG = 'D'; const NO_OVER_TAG = 'R'; const TYPE_DAY_RENT = 0; public static $typeMaps = [ self::TYPE_DAY_RENT => '日租' ]; // 待支付租金 const STATUS_WAIT_PAY_RENT_MONEY = 0; // 租车中 const STATUS_RENT_BIKE = 1; // 租车结束,待支付 const STATUS_CLOSE_RENT_BIKE = 2; // 已完成 const STATUS_COMPLETE_ORDER = 3; // 订单关闭 const STATUS_CLOSE_ORDER = 4; public static $statusMaps = [ self::STATUS_WAIT_PAY_RENT_MONEY => '待支付租金', self::STATUS_RENT_BIKE => '租车中', self::STATUS_CLOSE_RENT_BIKE => '租车结束,待支付', self::STATUS_COMPLETE_ORDER => '已完成', self::STATUS_CLOSE_ORDER => '订单关闭' ]; const PAY_STATUS_OK = 1; const PAY_STATUS_NO = 0; public static $payStatusMaps = [ self::PAY_STATUS_NO => '已支付', self::PAY_STATUS_OK => '未支付' ]; const PAY_TYPE_NO = 0; const PAY_TYPE_WECHAT = 1; const PAY_TYPE_ACCOUNT = 2; public static $payTypeMaps = [ self::PAY_TYPE_NO => '待支付', self::PAY_TYPE_WECHAT => '微信支付', self::PAY_TYPE_ACCOUNT => '余额支付' ]; const IS_ADMIN_SETTLE_ORDER_USER = 0; const IS_ADMIN_SETTLE_ORDER_ADMIN = 1; const IS_ADMIN_SETTLE_ORDER_SYSTEM = 2; public static $isAdminSettleOrderMaps = [ self::IS_ADMIN_SETTLE_ORDER_USER => '用户结算', self::IS_ADMIN_SETTLE_ORDER_ADMIN => '管理员结算', self::IS_ADMIN_SETTLE_ORDER_SYSTEM => '系统自动结算', ]; public function bike() { return $this->belongsTo(Bike::class); } public function getUseBikeTimeLengthTextAttribute() { if ($this->attributes['use_bike_time_length']) { return format_minutes($this->attributes['use_bike_time_length']); } return '暂无'; } public function getPauseBikeTimeLengthTextAttribute() { if ($this->attributes['pause_bike_time_length']) { return format_minutes($this->attributes['use_bike_time_length']); } return '暂无'; } public function getUseBikeDistanceLengthTextAttribute() { if ($this->attributes['use_bike_distance_length']) { return $this->attributes['use_bike_distance_length'] . 'km'; } return '暂无'; } public function getEndUseBikeTimeTimestampAttribute() { if ($this->attributes['end_use_bike_time']) { return $this->end_use_bike_time->timestamp; } return time(); } /** * 生成订单号 * @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; } /** * 生成二次消费订单号 * @return bool|string * User: Mead */ public static function makeOverNo() { // 订单流水号前缀 $prefix = config('bike.no_tag') . self::NO_OVER_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('over_no', $no)->exists()) { return $no; } } Log::warning('find order no failed'); return false; } public function pay_rent_order_callback() { $order = $this->attributes; //添加钱包记录 WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $this->attributes['rent_pay_money'], $this->attributes['user_id'], WalletLog::TYPE_ADD_WECHAT_PAY_RENT_ORDER, $this->attributes['area_id'], $this->attributes['id'], RentOrder::class); WalletLog::log(WalletLog::OPERATE_TYPE_SUB, $this->attributes['rent_pay_money'], $this->attributes['user_id'], WalletLog::TYPE_SUB_WECHAT_PAY_RENT_ORDER, $this->attributes['area_id'], $this->attributes['id'], RentOrder::class); Bike::where('id', $this->attributes['bike_id'])->update([ 'is_rent' => Bike::RENT_YES, 'is_riding' => Bike::RIDING_YES ]); // 更新orders redis (new BikeStatusInfoSyncHandler())->toBikeRideStatus(BikeStatusInfoSyncHandler::ROLE_USER, $order['bike_no'], [ 'id' => $this->attributes['id'], 'bike_id' => $order['bike_id'], 'area_id' => $order['area_id'], 'is_rent' => 1 ]); return true; } public function pay_rent_over_order_callback() { $order = $this->attributes; //添加钱包记录 WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_ADD_WECHAT_PAY_RENT_ORDER_MONEY, $this->attributes['area_id'], $this->attributes['id'], RentOrder::class); WalletLog::log(WalletLog::OPERATE_TYPE_SUB, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_SUB_WECHAT_PAY_RENT_ORDER_MONEY, $this->attributes['area_id'], $this->attributes['id'], RentOrder::class); $location['lat'] = $order['end_use_bike_location']['latitude']; $location['lng'] = $order['end_use_bike_location']['longitude']; (new BikeStatusInfoSyncHandler())->toBikeWaitRideStatus($order['bike_no'], $location['lng'], $location['lat']); return true; } /** * 退款回调 * User: Mead */ public function refund_order_callback() { return WalletLog::where('type', WalletLog::TYPE_SUB_ORDER_MONEY_PAY_WECHAT)->where('operate_type', WalletLog::OPERATE_TYPE_SUB)->where('log_id', $this->attributes['id'])->where('user_id', $this->attributes['user_id'])->where('log_type', RentOrder::class)->update([ 'status' => 1 ]); } }