DepositRefund.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = 'BT';
  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. /**
  47. * 生成订单号
  48. * @return bool|string
  49. * User: Mead
  50. */
  51. public static function makeNo()
  52. {
  53. // 订单流水号前缀
  54. $prefix = self::NO_TAG . date('YmdHis');
  55. for ($i = 0; $i < 10; $i++) {
  56. // 随机生成 6 位的数字
  57. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  58. // 判断是否已经存在
  59. if (!static::query()->where('no', $no)->exists()) {
  60. return $no;
  61. }
  62. }
  63. Log::warning('find order no failed');
  64. return false;
  65. }
  66. public function pay_order_callback()
  67. {
  68. DepositOrder::where('id', $this->attributes['deposit_id'])->update([
  69. 'is_refund' => DepositOrder::REFUND_OK
  70. ]);
  71. // 修改用户押金状态
  72. User::where('id', $this->attributes['user_id'])->update([
  73. 'deposit_money' => 0,
  74. 'is_deposit' => User::DEPOSIT_NO
  75. ]);
  76. return true;
  77. }
  78. }