123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- class DepositOrder extends Model
- {
- use ModelHelpers;
- const NO_TAG = 'Y';
- //押金订单表
- protected $table = "deposit_orders";
- protected $guarded = [];
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停'
- ];
- const PAY_STATUS_OK = 1;
- const PAY_STATUS_NO = 0;
- public static $payStatusMaps = [
- self::PAY_STATUS_NO => '未支付',
- self::PAY_STATUS_OK => '缴纳成功'
- ];
- const PAY_TYPE_WECHAT = 0;
- public static $payTypeMaps = [
- self::PAY_TYPE_WECHAT => '微信支付'
- ];
- const REFUND_OK = 1;
- const REFUND_NO = 0;
- public static $refundMaps = [
- self::REFUND_OK => '已退款',
- self::REFUND_NO => '未退款'
- ];
- // 交易类型 用is_refund 判断
- public static $transactionTypeMaps = [
- self::REFUND_OK => '退还押金',
- self::REFUND_NO => '缴纳押金'
- ];
- public function depositRefund(){
- return $this->hasOne(DepositRefund::class,'deposit_id','id');
- }
- public function users(){
- return $this->belongsTo('App\Models\User','user_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;
- }
- }
|