RefundLog.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Log;
  6. class RefundLog extends Model
  7. {
  8. use ModelHelpers;
  9. //
  10. protected $guarded = [];
  11. const NO_TAG = 'T';
  12. const STATUS_OK = 1;
  13. const STATUS_PAUSE = 0;
  14. public static $statusMaps = [
  15. self::STATUS_OK => '正常',
  16. self::STATUS_PAUSE => '暂停'
  17. ];
  18. const PAY_STATUS_OK = 1;
  19. const PAY_STATUS_NO = 0;
  20. const PAY_STATUS_ERROR = 2;
  21. const PAY_STATUS_WAIT = 3;
  22. const PAY_STATUS_ALIPAYMINI_PAY = 4;
  23. public static $payStatusMaps = [
  24. self::PAY_STATUS_NO => '已支付',
  25. self::PAY_STATUS_OK => '未支付',
  26. self::PAY_STATUS_ERROR => '退款异常',
  27. self::PAY_STATUS_WAIT => '退款排队中',
  28. self::PAY_STATUS_ALIPAYMINI_PAY => '退款方式错误',
  29. ];
  30. const PAY_TYPE_WECHAT = 1;
  31. const PAY_TYPE_ALIPAYMINI = 2;
  32. const PAY_TYPE_ALIPAYMINI_CREDIT = 3;
  33. public static $payTypeMaps = [
  34. self::PAY_TYPE_WECHAT => '微信支付',
  35. self::PAY_TYPE_ALIPAYMINI => '支付宝小程序支付',
  36. self::PAY_TYPE_ALIPAYMINI_CREDIT => '支付宝免押金支付',
  37. ];
  38. const REFUND_OK = 1;
  39. const REFUND_NO = 0;
  40. public static $refundMaps = [
  41. self::REFUND_OK => '已退款',
  42. self::REFUND_NO => '未退款'
  43. ];
  44. const TYPE_USER = 0;
  45. public static $typeMaps = [
  46. self::TYPE_USER => '用户发起一般退款'
  47. ];
  48. const CHECK_STATUS_OK = 1;
  49. const CHECK_STATUS_NO = 0;
  50. public static $checkStatusMaps = [
  51. self::CHECK_STATUS_NO => '审核通过',
  52. self::CHECK_STATUS_OK => '审核未通过'
  53. ];
  54. public function users()
  55. {
  56. return $this->belongsTo('App\Models\User', 'user_id', 'id');
  57. }
  58. public function area()
  59. {
  60. return $this->belongsTo(Area::class, 'area_id', 'id');
  61. }
  62. /**
  63. * 生成订单号
  64. * @return bool|string
  65. * User: Mead
  66. */
  67. public static function makeNo()
  68. {
  69. // 订单流水号前缀
  70. $prefix = AdminMerchant::getOrderTag() . self::NO_TAG . date('YmdHis');
  71. for ($i = 0; $i < 10; $i++) {
  72. // 随机生成 6 位的数字
  73. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  74. // 判断是否已经存在
  75. if (!static::query()->where('no', $no)->exists()) {
  76. return $no;
  77. }
  78. }
  79. Log::warning('find order no failed');
  80. return false;
  81. }
  82. public function pay_order_callback()
  83. {
  84. DepositOrder::where('id', $this->attributes['deposit_id'])->update([
  85. 'is_refund' => DepositOrder::REFUND_OK
  86. ]);
  87. // 修改用户押金状态
  88. User::where('id', $this->attributes['user_id'])->update([
  89. 'deposit_money' => 0,
  90. 'is_deposit' => User::DEPOSIT_NO
  91. ]);
  92. return true;
  93. }
  94. }