StoreOrderRefund.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * refund_type
  107. * @param $query
  108. * @param $value
  109. */
  110. public function searchRefundTypeAttr($query, $value)
  111. {
  112. if (is_array($value)) {
  113. $query->whereIn('refund_type', $value);
  114. } else {
  115. if ($value > 0) $query->where('refund_type', $value);
  116. }
  117. }
  118. /**
  119. * @param $query
  120. * @param $value
  121. */
  122. public function searchRefundStatusAttr($query, $value)
  123. {
  124. if ($value == 1) {
  125. $query->whereIn('refund_type', [1, 2, 4, 5]);
  126. } elseif ($value == 2) {
  127. $query->where('refund_type', 6);
  128. }
  129. }
  130. }