StoreOrderCartInfo.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 订单记录Model
  17. * Class StoreOrderCartInfo
  18. * @package app\model\order
  19. */
  20. class StoreOrderCartInfo extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 模型名称
  25. * @var string
  26. */
  27. protected $name = 'store_order_cart_info';
  28. /**
  29. * 购物车信息获取器
  30. * @param $value
  31. * @return array|mixed
  32. */
  33. public function getCartInfoAttr($value)
  34. {
  35. return is_string($value) ? json_decode($value, true) ?? [] : [];
  36. }
  37. /**
  38. * 订单ID搜索器
  39. * @param Model $query
  40. * @param $value
  41. * @param $data
  42. */
  43. public function searchOidAttr($query, $value, $data)
  44. {
  45. if ($value) {
  46. if (is_array($value)) {
  47. $query->whereIn('oid', $value);
  48. } else {
  49. $query->where('oid', $value);
  50. }
  51. }
  52. }
  53. /**
  54. * UID搜索器
  55. * @param Model $query
  56. * @param $value
  57. */
  58. public function searchUidAttr($query, $value)
  59. {
  60. if ($value) {
  61. if (is_array($value)) {
  62. $query->whereIn('uid', $value);
  63. } else {
  64. $query->where('uid', $value);
  65. }
  66. }
  67. }
  68. /**
  69. * product_id搜索器
  70. * @param Model $query
  71. * @param $value
  72. */
  73. public function searchProductIdAttr($query, $value)
  74. {
  75. if ($value) {
  76. if (is_array($value)) {
  77. $query->whereIn('product_id', $value);
  78. } else {
  79. $query->where('product_id', $value);
  80. }
  81. }
  82. }
  83. /**
  84. * 优惠活动ID搜索器
  85. * @param Model $query
  86. * @param $value
  87. */
  88. public function searchPromotionsIdAttr($query, $value)
  89. {
  90. if ($value) {
  91. if (is_array($value)) {
  92. $query->where(function($q) use ($value) {
  93. foreach ($value as $key => $v) {
  94. $q->whereOr(function ($c) use ($v) {
  95. $c->whereFindInSet('promotions_id', $v);
  96. });
  97. }
  98. });
  99. } else {
  100. $query->whereFindInSet('promotions_id', $value);
  101. }
  102. }
  103. }
  104. /**
  105. * 购物车ID搜索器
  106. * @param Model $query
  107. * @param $value
  108. * @param $data
  109. */
  110. public function searchCartIdAttr($query, $value, $data)
  111. {
  112. if ($value) {
  113. if (is_array($value)) {
  114. $query->whereIn('cart_id', $value);
  115. } else {
  116. $query->where('cart_id', $value);
  117. }
  118. }
  119. }
  120. /**
  121. * 原购物车ID搜索器
  122. * @param Model $query
  123. * @param $value
  124. * @param $data
  125. */
  126. public function searchOldCartIdAttr($query, $value, $data)
  127. {
  128. if (is_array($value)) {
  129. $query->whereIn('old_cart_id', $value);
  130. } else {
  131. $query->where('old_cart_id', $value);
  132. }
  133. }
  134. /**
  135. * 拆分状态搜索器
  136. * @param Model $query
  137. * @param $value
  138. * @param $data
  139. */
  140. public function searchSplitStatusAttr($query, $value)
  141. {
  142. if (is_array($value)) {
  143. $query->whereIn('split_status', $value);
  144. } else {
  145. if (in_array($value, [0, 1, 2])) {
  146. $query->where('split_status', $value);
  147. }
  148. }
  149. }
  150. /**
  151. * 是否赠送搜索器
  152. * @param Model $query
  153. * @param $value
  154. * @param $data
  155. */
  156. public function searchIsGiftAttr($query, $value)
  157. {
  158. if ($value !== '') {
  159. $query->where('is_gift', $value);
  160. }
  161. }
  162. /**
  163. * 是否核销搜索器
  164. * @param Model $query
  165. * @param $value
  166. * @param $data
  167. */
  168. public function searchIsWriteoffAttr($query, $value)
  169. {
  170. if ($value !== '') {
  171. $query->where('is_writeoff', $value);
  172. }
  173. }
  174. }