RefundLog.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. public static $payStatusMaps = [
  22. self::PAY_STATUS_NO => '已支付',
  23. self::PAY_STATUS_OK => '未支付',
  24. self::PAY_STATUS_ERROR => '退款异常'
  25. ];
  26. const PAY_TYPE_WECHAT = 0;
  27. public static $payTypeMaps = [
  28. self::PAY_TYPE_WECHAT => '微信支付'
  29. ];
  30. const REFUND_OK = 1;
  31. const REFUND_NO = 0;
  32. public static $refundMaps = [
  33. self::REFUND_OK => '已退款',
  34. self::REFUND_NO => '未退款'
  35. ];
  36. const TYPE_USER = 0;
  37. public static $typeMaps = [
  38. self::TYPE_USER => '用户发起一般退款'
  39. ];
  40. const CHECK_STATUS_OK = 1;
  41. const CHECK_STATUS_NO = 0;
  42. public static $checkStatusMaps = [
  43. self::CHECK_STATUS_NO => '审核通过',
  44. self::CHECK_STATUS_OK => '审核未通过'
  45. ];
  46. public function users(){
  47. return $this->belongsTo('App\Models\User','user_id','id');
  48. }
  49. public function area(){
  50. return $this->belongsTo(Area::class,'area_id','id');
  51. }
  52. /**
  53. * 生成订单号
  54. * @return bool|string
  55. * User: Mead
  56. */
  57. public static function makeNo()
  58. {
  59. // 订单流水号前缀
  60. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  61. for ($i = 0; $i < 10; $i++) {
  62. // 随机生成 6 位的数字
  63. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  64. // 判断是否已经存在
  65. if (!static::query()->where('no', $no)->exists()) {
  66. return $no;
  67. }
  68. }
  69. Log::warning('find order no failed');
  70. return false;
  71. }
  72. public function pay_order_callback()
  73. {
  74. DepositOrder::where('id', $this->attributes['deposit_id'])->update([
  75. 'is_refund' => DepositOrder::REFUND_OK
  76. ]);
  77. // 修改用户押金状态
  78. User::where('id', $this->attributes['user_id'])->update([
  79. 'deposit_money' => 0,
  80. 'is_deposit' => User::DEPOSIT_NO
  81. ]);
  82. return true;
  83. }
  84. }