DepositRefund.php 2.4 KB

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