DepositCardOrder.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. *
  4. *
  5. * @category xxx
  6. * @package PSR
  7. * @subpackage Documentation\API
  8. * @author xxx <xxx@xxx.com>
  9. * @license GPL https://xxx.com
  10. * @link https://xxx.com
  11. * @ctime: 2020/4/30 15:32
  12. */
  13. namespace App\Models;
  14. use App\Traits\ModelHelpers;
  15. use Carbon\Carbon;
  16. use Illuminate\Database\Eloquent\Model;
  17. use Illuminate\Support\Facades\Log;
  18. class DepositCardOrder extends Model
  19. {
  20. use ModelHelpers;
  21. protected $table = 'deposit_card_orders';
  22. protected $fillable = [
  23. 'no',
  24. 'area_id',
  25. 'user_id',
  26. 'deposit_cards_id',
  27. 'money' ,
  28. 'effective_days',
  29. 'discount' ,
  30. 'pay_money',
  31. 'pay_type',
  32. 'pay_status',
  33. 'pay_time',
  34. 'merchant_id',];
  35. const NO_TAG = 'M';
  36. const PAY_TYPE_WECHAT = 1;
  37. const PAY_TYPE_ACCOUNT = 2;
  38. const PAY_TYPE_ADMIN_GIVE = 3;
  39. const PAY_TYPE_INVITE_NEW_USER_GIVE = 4;
  40. public static $payTypeMaps = [
  41. self::PAY_TYPE_WECHAT => '微信支付',
  42. self::PAY_TYPE_ACCOUNT => '余额支付',
  43. self::PAY_TYPE_ADMIN_GIVE => '后台赠送',
  44. self::PAY_TYPE_INVITE_NEW_USER_GIVE => '邀请新用户赠送'
  45. ];
  46. const PAY_STATUS_OK = 1;
  47. const PAY_STATUS_NO = 0;
  48. public static $payStatusMaps = [
  49. self::PAY_STATUS_OK => '支付成功',
  50. self::PAY_STATUS_NO => '支付失败',
  51. ];
  52. const STATUS_OK = 1;
  53. const STATUS_NO = 0;
  54. public static $statusMaps = [
  55. self::STATUS_OK => '支付成功',
  56. self::STATUS_NO => '支付失败'
  57. ];
  58. public function users()
  59. {
  60. return $this->belongsTo(User::class, 'user_id', 'id');
  61. }
  62. public function areas()
  63. {
  64. return $this->belongsTo(Area::class, 'area_id', 'id');
  65. }
  66. public function depositCard(){
  67. return $this->belongsTo(DepositCard::class,'deposit_cards_id','id');
  68. }
  69. /**
  70. * 生成订单号
  71. * @return bool|string
  72. * User: Mead
  73. */
  74. public static function makeNo()
  75. {
  76. // 订单流水号前缀
  77. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  78. for ($i = 0; $i < 10; $i++) {
  79. // 随机生成 6 位的数字
  80. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  81. // 判断是否已经存在
  82. if (!static::query()->where('no', $no)->exists()) {
  83. return $no;
  84. }
  85. }
  86. Log::warning('find order no failed');
  87. return false;
  88. }
  89. // public function pay_order_callback()
  90. // {
  91. // // 修改用户押金状态
  92. // User::where('id', $this->attributes['user_id'])->update([
  93. // 'deposit_expire_time' => Carbon::now()->addDays($this->attributes['effective_days']),
  94. // 'deposit_type' => User::DEPOSIT_CARD,
  95. // 'is_deposit' => User::DEPOSIT_OK
  96. // ]);
  97. //
  98. // $this->save();
  99. //
  100. // return true;
  101. // }
  102. }