StoreOrderRefund.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\order;
  12. use app\model\supplier\SystemSupplier;
  13. use app\model\user\User;
  14. use app\model\order\StoreOrder;
  15. use crmeb\basic\BaseModel;
  16. use crmeb\traits\ModelTrait;
  17. use think\Model;
  18. /**
  19. * Class StoreOrderRefund
  20. * @package app\model\order
  21. */
  22. class StoreOrderRefund extends BaseModel
  23. {
  24. use ModelTrait;
  25. protected $pk = 'id';
  26. protected $name = 'store_order_refund';
  27. /**
  28. * 购物车信息获取器
  29. * @param $value
  30. * @return array|mixed
  31. */
  32. public function getCartInfoAttr($value)
  33. {
  34. return is_string($value) ? json_decode($value, true) ?? [] : [];
  35. }
  36. /**
  37. * 图片获取器
  38. * @param $value
  39. * @return array|mixed
  40. */
  41. public function getRefundImgAttr($value)
  42. {
  43. return is_string($value) ? json_decode($value, true) ?? [] : [];
  44. }
  45. /**
  46. * 图片获取器
  47. * @param $value
  48. * @return array|mixed
  49. */
  50. public function getRefundGoodsImgAttr($value)
  51. {
  52. return is_string($value) ? json_decode($value, true) ?? [] : [];
  53. }
  54. /**
  55. * 一对一关联订单表
  56. * @return StoreOrderRefund|\think\model\relation\HasOne
  57. */
  58. public function order()
  59. {
  60. return $this->hasOne(StoreOrder::class, 'id', 'store_order_id');
  61. }
  62. /**
  63. * 一对一关联用户表
  64. * @return \think\model\relation\HasOne
  65. */
  66. public function user()
  67. {
  68. return $this->hasOne(User::class, 'uid', 'uid', false)->field(['uid', 'avatar', 'nickname', 'phone', 'now_money', 'integral', 'delete_time'])->bind([
  69. 'avatar' => 'avatar',
  70. 'nickname' => 'nickname',
  71. 'phone' => 'phone',
  72. 'now_money' => 'now_money',
  73. 'integral' => 'integral',
  74. 'delete_time' => 'delete_time',
  75. ]);
  76. }
  77. /**
  78. * 订单ID搜索器
  79. * @param $query
  80. * @param $value
  81. */
  82. public function searchStoreOrderIdAttr($query, $value)
  83. {
  84. if ($value !== '') {
  85. if (is_array($value)) {
  86. $query->whereIn('store_order_id', $value);
  87. } else {
  88. $query->where('store_order_id', $value);
  89. }
  90. }
  91. }
  92. /**
  93. * 门店ID
  94. * @param $query
  95. * @param $value
  96. */
  97. public function searchStoreIdAttr($query, $value)
  98. {
  99. if ($value !== '') {
  100. if ($value == -1) {//所有门店
  101. $query->where('store_id', '>', 0);
  102. } else {
  103. $query->where('store_id', $value);
  104. }
  105. }
  106. }
  107. /**
  108. * @param Model $query
  109. * @param $value
  110. */
  111. public function searchUidAttr($query, $value)
  112. {
  113. if ($value !== '' && !is_null($value)) {
  114. if (is_array($value)) {
  115. $query->whereIn('uid', $value);
  116. } else {
  117. $query->where('uid', $value);
  118. }
  119. }
  120. }
  121. /**
  122. * is_cancel
  123. * @param Model $query
  124. * @param $value
  125. */
  126. public function searchIsCancelAttr($query, $value)
  127. {
  128. if ($value !== '' && !is_null($value)) $query->where('is_cancel', $value);
  129. }
  130. /**
  131. * is_del搜索器
  132. * @param Model $query
  133. * @param $value
  134. */
  135. public function searchIsDelAttr($query, $value)
  136. {
  137. if ($value !== '' && !is_null($value)) $query->where('is_del', $value);
  138. }
  139. /**
  140. * 供应商ID
  141. * @param $query
  142. * @param $value
  143. */
  144. public function searchSupplierIdAttr($query, $value)
  145. {
  146. if ($value !== '') {
  147. if ($value == -1) {
  148. $query->where('supplier_id', '>', 0);
  149. } else {
  150. $query->where('supplier_id', $value);
  151. }
  152. }
  153. }
  154. /**
  155. * 一对一关联供应商
  156. * @return \think\model\relation\HasOne
  157. */
  158. public function supplier()
  159. {
  160. return $this->hasOne(SystemSupplier::class, 'id', 'supplier_id')->field(['id', 'supplier_name'])->bind([
  161. 'supplier_name'
  162. ]);
  163. }
  164. }