DepositCardOrder.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. const NO_TAG = 'M';
  23. const PAY_TYPE_WECHAT = 1;
  24. const PAY_TYPE_ACCOUNT = 2;
  25. const PAY_TYPE_ADMIN_GIVE = 3;
  26. const PAY_TYPE_INVITE_NEW_USER_GIVE = 4;
  27. public static $payTypeMaps = [
  28. self::PAY_TYPE_WECHAT => '微信支付',
  29. self::PAY_TYPE_ACCOUNT => '余额支付',
  30. self::PAY_TYPE_ADMIN_GIVE => '后台赠送',
  31. self::PAY_TYPE_INVITE_NEW_USER_GIVE => '邀请新用户赠送'
  32. ];
  33. const PAY_STATUS_OK = 1;
  34. const PAY_STATUS_NO = 0;
  35. public static $payStatusMaps = [
  36. self::PAY_STATUS_OK => '支付成功',
  37. self::PAY_STATUS_NO => '支付失败',
  38. ];
  39. const STATUS_OK = 1;
  40. const STATUS_NO = 0;
  41. public static $statusMaps = [
  42. self::STATUS_OK => '支付成功',
  43. self::STATUS_NO => '支付失败'
  44. ];
  45. public function users()
  46. {
  47. return $this->belongsTo(User::class, 'user_id', 'id');
  48. }
  49. public function areas()
  50. {
  51. return $this->belongsTo(Area::class, 'area_id', 'id');
  52. }
  53. public function depositCard(){
  54. return $this->belongsTo(DepositCard::class,'deposit_cards_id','id');
  55. }
  56. /**
  57. * 生成订单号
  58. * @return bool|string
  59. * User: Mead
  60. */
  61. public static function makeNo()
  62. {
  63. // 订单流水号前缀
  64. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  65. for ($i = 0; $i < 10; $i++) {
  66. // 随机生成 6 位的数字
  67. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  68. // 判断是否已经存在
  69. if (!static::query()->where('no', $no)->exists()) {
  70. return $no;
  71. }
  72. }
  73. Log::warning('find order no failed');
  74. return false;
  75. }
  76. // public function pay_order_callback()
  77. // {
  78. // // 修改用户押金状态
  79. // User::where('id', $this->attributes['user_id'])->update([
  80. // 'deposit_expire_time' => Carbon::now()->addDays($this->attributes['effective_days']),
  81. // 'deposit_type' => User::DEPOSIT_CARD,
  82. // 'is_deposit' => User::DEPOSIT_OK
  83. // ]);
  84. //
  85. // $this->save();
  86. //
  87. // return true;
  88. // }
  89. }