StoreOrderRefund.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\model\order;
  3. use app\model\user\User;
  4. use crmeb\basic\BaseModel;
  5. use crmeb\traits\ModelTrait;
  6. use think\Model;
  7. class StoreOrderRefund extends BaseModel
  8. {
  9. use ModelTrait;
  10. /**
  11. * 数据表主键
  12. * @var string
  13. */
  14. protected $pk = 'id';
  15. /**
  16. * 模型名称
  17. * @var string
  18. */
  19. protected $name = 'store_order_refund';
  20. /**
  21. * 购物车信息获取器
  22. * @param $value
  23. * @return array|mixed
  24. */
  25. public function getCartInfoAttr($value)
  26. {
  27. return is_string($value) ? json_decode($value, true) ?? [] : [];
  28. }
  29. /**
  30. * 图片获取器
  31. * @param $value
  32. * @return array|mixed
  33. */
  34. public function getRefundImgAttr($value)
  35. {
  36. return is_string($value) ? json_decode($value, true) ?? [] : [];
  37. }
  38. /**
  39. * 一对一关联订单表
  40. * @return StoreOrderRefund|\think\model\relation\HasOne
  41. */
  42. public function order()
  43. {
  44. return $this->hasOne(StoreOrder::class, 'id', 'store_order_id');
  45. }
  46. /**
  47. * 一对一关联用户表
  48. * @return \think\model\relation\HasOne
  49. */
  50. public function user()
  51. {
  52. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'avatar', 'nickname', 'phone'])->bind([
  53. 'avatar' => 'avatar',
  54. 'nickname' => 'nickname',
  55. 'phone' => 'phone'
  56. ]);
  57. }
  58. /**
  59. * 订单ID搜索器
  60. * @param $query
  61. * @param $value
  62. */
  63. public function searchStoreOrderIdAttr($query, $value)
  64. {
  65. if ($value !== '') {
  66. if (is_array($value)) {
  67. $query->whereIn('store_order_id', $value);
  68. } else {
  69. $query->where('store_order_id', $value);
  70. }
  71. }
  72. }
  73. /**
  74. * @param Model $query
  75. * @param $value
  76. */
  77. public function searchUidAttr($query, $value)
  78. {
  79. if ($value !== '' && !is_null($value)) {
  80. if (is_array($value)) {
  81. $query->whereIn('uid', $value);
  82. } else {
  83. $query->where('uid', $value);
  84. }
  85. }
  86. }
  87. /**
  88. * is_cancel
  89. * @param Model $query
  90. * @param $value
  91. */
  92. public function searchIsCancelAttr($query, $value)
  93. {
  94. if ($value !== '' && !is_null($value)) $query->where('is_cancel', $value);
  95. }
  96. /**
  97. * is_del搜索器
  98. * @param Model $query
  99. * @param $value
  100. */
  101. public function searchIsDelAttr($query, $value)
  102. {
  103. if ($value !== '' && !is_null($value)) $query->where('is_del', $value);
  104. }
  105. /**
  106. * is_system_del搜索器
  107. * @param Model $query
  108. * @param $value
  109. */
  110. public function searchIsSystemDelAttr($query, $value)
  111. {
  112. if ($value !== '' && !is_null($value)) $query->where('is_system_del', $value);
  113. }
  114. /**
  115. * refund_type
  116. * @param $query
  117. * @param $value
  118. */
  119. public function searchRefundTypeAttr($query, $value)
  120. {
  121. if (is_array($value)) {
  122. $query->whereIn('refund_type', $value);
  123. } else {
  124. if ($value > 0) $query->where('refund_type', $value);
  125. }
  126. }
  127. /**
  128. * @param $query
  129. * @param $value
  130. */
  131. public function searchRefundStatusAttr($query, $value)
  132. {
  133. if ($value == 1) {
  134. $query->whereIn('refund_type', [1, 2, 4, 5]);
  135. } elseif ($value == 2) {
  136. $query->where('refund_type', 6);
  137. }
  138. }
  139. /**
  140. * 一对一关联订单表
  141. * @return StoreOrderRefund|\think\model\relation\HasOne
  142. */
  143. public function orderData()
  144. {
  145. return $this->hasOne(StoreOrder::class, 'id', 'store_order_id')->field('id, order_id, pay_type, paid, real_name,user_phone, user_address,pay_uid, pay_time')
  146. ->bind([
  147. 'store_order_sn' => 'order_id',
  148. 'pay_type',
  149. 'paid',
  150. 'real_name',
  151. 'user_phone',
  152. 'user_address',
  153. 'pay_uid',
  154. 'pay_time'
  155. ]);
  156. }
  157. /**
  158. * @param $query
  159. * @param $value
  160. */
  161. public function searchKeywordsAttr($query, $value)
  162. {
  163. if ($value !== '') {
  164. $query->where('order_id|refund_phone', 'like', '%' . $value . '%');
  165. }
  166. }
  167. }