* @license GPL https://xxx.com * @link https://xxx.com * @ctime: 2020/4/30 15:32 */ namespace App\Models; use App\Traits\ModelHelpers; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Log; class DepositCardOrder extends Model { use ModelHelpers; protected $table = 'deposit_card_orders'; protected $fillable = [ 'no', 'area_id', 'user_id', 'deposit_cards_id', 'money' , 'effective_days', 'discount' , 'pay_money', 'pay_type', 'pay_status', 'pay_time', 'merchant_id',]; const NO_TAG = 'M'; const PAY_TYPE_WECHAT = 1; const PAY_TYPE_ACCOUNT = 2; const PAY_TYPE_ADMIN_GIVE = 3; const PAY_TYPE_INVITE_NEW_USER_GIVE = 4; public static $payTypeMaps = [ self::PAY_TYPE_WECHAT => '微信支付', self::PAY_TYPE_ACCOUNT => '余额支付', self::PAY_TYPE_ADMIN_GIVE => '后台赠送', self::PAY_TYPE_INVITE_NEW_USER_GIVE => '邀请新用户赠送' ]; const PAY_STATUS_OK = 1; const PAY_STATUS_NO = 0; public static $payStatusMaps = [ self::PAY_STATUS_OK => '支付成功', self::PAY_STATUS_NO => '支付失败', ]; const STATUS_OK = 1; const STATUS_NO = 0; public static $statusMaps = [ self::STATUS_OK => '支付成功', self::STATUS_NO => '支付失败' ]; public function users() { return $this->belongsTo(User::class, 'user_id', 'id'); } public function areas() { return $this->belongsTo(Area::class, 'area_id', 'id'); } public function depositCard(){ return $this->belongsTo(DepositCard::class,'deposit_cards_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() // { // // 修改用户押金状态 // User::where('id', $this->attributes['user_id'])->update([ // 'deposit_expire_time' => Carbon::now()->addDays($this->attributes['effective_days']), // 'deposit_type' => User::DEPOSIT_CARD, // 'is_deposit' => User::DEPOSIT_OK // ]); // // $this->save(); // // return true; // } }