StoreRefundOrder.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\order;
  12. use app\common\model\BaseModel;
  13. use app\common\model\store\service\StoreService;
  14. use app\common\model\system\merchant\Merchant;
  15. use app\common\model\system\merchant\MerchantAdmin;
  16. use app\common\model\user\User;
  17. class StoreRefundOrder extends BaseModel
  18. {
  19. public static function tablePk(): ?string
  20. {
  21. return 'refund_order_id';
  22. }
  23. public static function tableName(): string
  24. {
  25. return 'store_refund_order';
  26. }
  27. public function getPicsAttr($val)
  28. {
  29. return $val ? explode(',', $val) : [];
  30. }
  31. public function setPicsAttr($val)
  32. {
  33. return $val ? implode(',', $val) : '';
  34. }
  35. public function refundProduct()
  36. {
  37. return $this->hasMany(StoreRefundProduct::class, 'refund_order_id', 'refund_order_id');
  38. }
  39. public function admin()
  40. {
  41. return $this->hasOne(MerchantAdmin::class, 'merchant_admin_id', 'admin_id');
  42. }
  43. public function services()
  44. {
  45. return $this->hasOne(StoreService::class, 'service_id', 'admin_id');
  46. }
  47. public function merchant()
  48. {
  49. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  50. }
  51. public function user()
  52. {
  53. return $this->hasOne(User::class, 'uid', 'uid');
  54. }
  55. public function order()
  56. {
  57. return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
  58. }
  59. public function searchDataAttr($query, $value)
  60. {
  61. return getModelTime($query, $value);
  62. }
  63. public function getPhoneAttr($value)
  64. {
  65. if (env('SHOW_PHONE',false) && app('request')->hasMacro('adminInfo') && $value && is_numeric($value)){
  66. if (app('request')->userType() !== 2 || app('request')->adminInfo()['level'] != 0) {
  67. return substr_replace($value, '****', 3, 4);
  68. }
  69. }
  70. return $value;
  71. }
  72. public function getAutoRefundTimeAttr()
  73. {
  74. $merAgree = systemConfig('mer_refund_order_agree') ?: 7;
  75. return strtotime('+' . $merAgree . ' day', strtotime($this->status_time));
  76. }
  77. public function getCombineRefundParams()
  78. {
  79. return [
  80. 'sub_mchid' => $this->merchant->sub_mchid,
  81. 'order_sn' => $this->order->order_sn,
  82. 'refund_order_sn' => $this->refund_order_sn,
  83. 'refund_price' => $this->refund_price,
  84. 'pay_price' => $this->order->pay_price,
  85. 'refund_message' => $this->refund_message,
  86. 'open_id' => $this->user->wechat->routine_openid ?? null,
  87. 'transaction_id' => $this->order->transaction_id,
  88. ];
  89. }
  90. public function getCreateUserAttr()
  91. {
  92. switch ($this->user_type){
  93. case 1:
  94. return $this->user->nickname ?? '无';
  95. break;
  96. case 3:
  97. return $this->admin->real_name ?? '无';
  98. break;
  99. case 4:
  100. return $this->services->nickname ?? '无';
  101. break;
  102. }
  103. return '无';
  104. }
  105. public function platform()
  106. {
  107. return $this->hasOne(StoreOrderStatus::class, 'order_sn', 'refund_order_sn')
  108. ->where('type', 'refund')
  109. ->whereIn('change_type', 'refund_platform_refuse,refund_platform_agree');
  110. }
  111. }