1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- class DepositOrder extends Model
- {
- protected $guarded = [];
- const NO_TAG = 'Y';
- 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_NO = 0;
- const PAY_TYPE_WECHAT = 1;
- public static $payTypeMaps = [
- self::PAY_TYPE_NO => '待支付',
- self::PAY_TYPE_WECHAT => '微信支付'
- ];
- const REFUND_OK = 1;
- const REFUND_NO = 0;
- public static $refundMaps = [
- self::REFUND_OK => '已退款',
- self::REFUND_NO => '未退款'
- ];
- /**
- * 生成订单号
- * @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;
- }
- public function pay_order_callback()
- {
- // 修改用户押金状态
- User::where('id', $this->attributes['user_id'])->update([
- 'deposit_money' => $this->attributes['money'],
- 'is_deposit' => User::DEPOSIT_OK
- ]);
- $this->save();
- return true;
- }
- }
|