'array', 'end_use_bike_location' => 'array', ]; const REDIS_BIKE_LOCATION_TAG = 'bike_locations'; const NO_TAG = 'O'; // 骑行中 const STATUS_RIDE_BIKE = 1; // 骑车结束,待支付 const STATUS_CLOSE_BIKE = 2; // 订单完成 const STATUS_COMPLETE_ORDER = 3; // 订单关闭(不够计费直接关闭) const STATUS_CLOSE_ORDER = 4; // 临时停车中 const STATUS_PAUSE_BIKE = 0; public static $statusMaps = [ self::STATUS_PAUSE_BIKE => '临时停车', self::STATUS_RIDE_BIKE => '骑行中', self::STATUS_CLOSE_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 COUPON_OK = 1; const COUPON_NO = 0; public static $couponMaps = [ self::COUPON_NO => '未使用优惠券', self::COUPON_OK => '使用优惠券' ]; const RIDING_CARD_OK = 1; const RIDING_CARD_NO = 0; public static $ridingCardMaps = [ self::RIDING_CARD_NO => '未使用骑行卡', self::RIDING_CARD_OK => '已使用骑行卡', ]; const PREFERENTIAL_NO = 0; const PREFERENTIAL_CARD_RIDING = 1; const PREFERENTIAL_COUPON = 2; const PREFERENTIAL_FREE_MINUTE = 3; public static $preferentialTypeMaps = [ self::PREFERENTIAL_NO => '无优惠', self::PREFERENTIAL_CARD_RIDING => '骑行卡优惠', self::PREFERENTIAL_COUPON => '优惠券优惠', self::PREFERENTIAL_FREE_MINUTE => '时长优惠', ]; 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 => '系统自动结算', ]; const TRADE_STATE_SUCCESS = 'SUCCESS'; const TRADE_STATE_REFUND = 'REFUND'; const TRADE_STATE_NOTPAY = 'NOTPAY'; const TRADE_STATE_CLOSED = 'CLOSED'; const TRADE_STATE_REVOKED = 'REVOKED'; const TRADE_STATE_USERPAYING = 'USERPAYING'; const TRADE_STATE_PAYERROR = 'PAYERROR'; public static $tradeStateMaps = [ self::TRADE_STATE_SUCCESS => '支付成功', self::TRADE_STATE_REFUND => '转入退款', self::TRADE_STATE_NOTPAY => '未支付', self::TRADE_STATE_CLOSED => '已关闭', self::TRADE_STATE_REVOKED => '已撤销(刷卡支付)', self::TRADE_STATE_USERPAYING => '用户支付中', self::TRADE_STATE_PAYERROR => '支付失败(其他原因,如银行返回失败)', ]; 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() { return $this->end_use_bike_time->timestamp; } public function setPreferentialTypeAttribute($value) { $this->attributes['preferential_type'] = '-' . $value . '-'; } public function getPreferentialTypeAttribute() { return trim($this->attributes['preferential_type'], '-'); } public function getPreferentialTypeNameAttribute() { if ($this->attributes['preferential_type'] == '-0-') { return '无优惠'; } else { $str = ''; $preferential_type_arr = str2arr(trim($this->attributes['preferential_type'], '-'), '-'); foreach ($preferential_type_arr as $v) { $str .= self::$preferentialTypeMaps[$v] . ','; } return rtrim($str, ','); } } // public function locations() // { // return $this->hasMany(LocationLogMongodb::class); // } /** * 生成订单号 * @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() { $order = $this->attributes; //添加钱包记录 WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_ADD_WECHAT_PAY_ORDER, $this->attributes['area_id'], $this->attributes['id'], Order::class); WalletLog::log(WalletLog::OPERATE_TYPE_SUB, $this->attributes['pay_money'], $this->attributes['user_id'], WalletLog::TYPE_SUB_WECHAT_PAY_ORDER, $this->attributes['area_id'], $this->attributes['id'], Order::class); //修改订单记录 $this->pay_status = Order::PAY_STATUS_OK; $this->pay_time = now(); $this->pay_type = Order::PAY_TYPE_WECHAT; $this->status = Order::STATUS_COMPLETE_ORDER; if ($this->attributes['is_coupon'] == self::COUPON_OK) { CouponsUserBag::useCoupon($this->attributes['id'], $this->attributes['coupon_user_bags_id']); //优惠方式 if ($this->preferential_type == 0) { $this->preferential_type = arr2str([Order::PREFERENTIAL_COUPON], '-'); } else { $arr = str2arr($this->preferential_type, '-'); $this->preferential_type = arr2str(array_merge($arr, [Order::PREFERENTIAL_COUPON]), '-'); } // 更新订单得优惠金额 $this->preferential_money = bcsub(bcadd($this->attributes['time_money'], $this->attributes['dispatch_money'], 2), $this->attributes['pay_money'], 2); // 更新优惠券优惠金额 $this->coupon_preferential_money = bcsub($this->attributes['preferential_money'], $this->attributes['card_preferential_money'], 2); } $this->save(); return true; } /** * 退款回调 * User: Mead */ public function refund_order_callback() { 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', Order::class)->update([ 'status' => 1 ]); } }