RefundLog.php 2.3 KB

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