123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- /**
- * 普通订单
- * */
- class Order extends Model
- {
- use ModelHelpers;
- const NO_TAG = 'O';
- const ORDER_TYPE = 0;
- protected $guarded = [];
- //
- // 骑行中
- 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 ADMIN_SETTLE_ORDER_AUTO_CLOSE = 2;
- const ADMIN_SETTLE_ORDER_ADMIN = 1;
- const ADMIN_SETTLE_ORDER_USER = 0;
- public static $adminSettleOrderMaps = [
- self::ADMIN_SETTLE_ORDER_USER => '正常结算',
- self::ADMIN_SETTLE_ORDER_ADMIN => '管理员结算',
- self::ADMIN_SETTLE_ORDER_AUTO_CLOSE => '系统自动结算',
- ];
- const PAY_STATUS_OK = 1;
- const PAY_STATUS_NO = 0;
- public static $payStatusMaps = [
- self::PAY_STATUS_NO => '已支付',
- self::PAY_STATUS_OK => '未支付'
- ];
- const REFUND_MONEY_OK = 1;
- const REFUND_MONEY_NO = 0;
- public static $refundMoneyMaps = [
- self::REFUND_MONEY_NO => '未返还',
- self::REFUND_MONEY_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 PREFERENTIAL_NO = 0;
- const PREFERENTIAL_CARD_RIDING = 1;
- public static $preferentialTypeMaps = [
- self::PREFERENTIAL_NO => '无优惠',
- self::PREFERENTIAL_CARD_RIDING => '骑行卡优惠',
- ];
- public function users()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
- public function bikes()
- {
- return $this->belongsTo(Bike::class, 'bike_id', 'id');
- }
- public function order_bike_operates()
- {
- return $this->hasMany(OrderBikeOperate::class, 'order_id', 'id');
- }
- public function area()
- {
- return $this->belongsTo(Area::class, 'area_id', 'id');
- }
- public function locationsLog()
- {
- return $this->hasMany(LocationsLog::class, 'order_id', 'id');
- }
- public function walletLogs()
- {
- return $this->morphMany(WalletLog::class, 'log');
- }
- public function getOrderTypeAttribute(){
- return self::ORDER_TYPE;
- }
- /**
- * 生成订单号
- * @return bool|string
- * User: Mead
- */
- public static function makeNo()
- {
- // 订单流水号前缀
- $prefix = 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;
- }
- /**
- * 根据用户id 查询今日订单次数
- * @param $user_id
- *
- * */
- public static function getTodayOrderNum($user_id){
- return self::query()->where('created_at','>',Carbon::today())->where('user_id',$user_id)->count();
- }
- }
|