RefundLog.php 2.2 KB

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