You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StorePromotions.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. namespace app\model\activity\promotions;
  3. use app\model\activity\coupon\StoreCouponIssue;
  4. use app\model\product\product\StoreProduct;
  5. use crmeb\basic\BaseModel;
  6. use crmeb\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * 促销活动活动
  10. * Class StorePromotions
  11. * @package app\model\activity\promotions
  12. */
  13. class StorePromotions extends BaseModel
  14. {
  15. use ModelTrait;
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'store_promotions';
  26. protected $updateTime = false;
  27. /**
  28. * 优惠叠加
  29. * @param $value
  30. * @return string
  31. */
  32. protected function setDiscountUseAttr($value)
  33. {
  34. if ($value) {
  35. return is_array($value) ? implode(',', $value) : $value;
  36. }
  37. return '';
  38. }
  39. /**
  40. * 优惠叠加
  41. * @param $value
  42. * @return array|false|string[]
  43. */
  44. protected function getDiscountUseAttr($value)
  45. {
  46. if ($value) {
  47. return is_string($value) ? explode(',', $value) : $value;
  48. }
  49. return [];
  50. }
  51. /**
  52. * 标签
  53. * @param $value
  54. * @return array|mixed
  55. */
  56. protected function getLabelIdAttr($value)
  57. {
  58. if ($value) {
  59. return is_string($value) ? explode(',', $value) : $value;
  60. }
  61. return [];
  62. }
  63. /**
  64. * 关联商品
  65. * @param $value
  66. * @return array|mixed
  67. */
  68. protected function getProductIdAttr($value)
  69. {
  70. if ($value) {
  71. return is_string($value) ? explode(',', $value) : $value;
  72. }
  73. return [];
  74. }
  75. /**
  76. * 叠加使用
  77. * @param $value
  78. * @return array|mixed
  79. */
  80. protected function getOverlayAttr($value)
  81. {
  82. if ($value) {
  83. return is_string($value) ? explode(',', $value) : $value;
  84. }
  85. return [];
  86. }
  87. /**
  88. * 赠送优惠券
  89. * @param $value
  90. * @return array|mixed
  91. */
  92. protected function getIGiveCouponIdAttr($value)
  93. {
  94. if ($value) {
  95. return is_string($value) ? explode(',', $value) : $value;
  96. }
  97. return [];
  98. }
  99. /**
  100. * 赠送商品
  101. * @param $value
  102. * @return array|mixed
  103. */
  104. protected function getIGiveProductIdAttr($value)
  105. {
  106. if ($value) {
  107. return is_string($value) ? explode(',', $value) : $value;
  108. }
  109. return [];
  110. }
  111. /**
  112. * 赠送商品
  113. * @param $value
  114. * @return array|mixed
  115. */
  116. protected function getIGiveProductUniqueAttr($value)
  117. {
  118. if ($value) {
  119. return is_string($value) ? explode(',', $value) : $value;
  120. }
  121. return [];
  122. }
  123. /**
  124. * 添加时间获取器
  125. * @param $value
  126. * @return false|string
  127. */
  128. protected function getAddTimeAttr($value)
  129. {
  130. if ($value) return date('Y-m-d H:i:s', (int)$value);
  131. return '';
  132. }
  133. /**
  134. * 关联商品
  135. * @return \think\model\relation\HasMany
  136. */
  137. public function products()
  138. {
  139. return $this->hasMany(StorePromotionsAuxiliary::class, 'promotions_id', 'id')->where('type',1);
  140. }
  141. /**
  142. * 关联优惠券
  143. * @return \think\model\relation\HasOne
  144. */
  145. public function giveCoupon()
  146. {
  147. return $this->hasMany(StorePromotionsAuxiliary::class, 'promotions_id', 'id')->where('type',2);
  148. }
  149. /**
  150. * 赠送商品
  151. * @return \think\model\relation\HasOne
  152. */
  153. public function giveProducts()
  154. {
  155. return $this->hasMany(StorePromotionsAuxiliary::class, 'promotions_id', 'id')->where('type',3);
  156. }
  157. /**
  158. * 阶梯优惠
  159. * @return \think\model\relation\HasMany
  160. */
  161. public function promotions()
  162. {
  163. return $this->hasMany(self::class, 'pid', 'id')->order('id asc');
  164. }
  165. /**
  166. * pid搜索器
  167. * @param Model $query
  168. * @param $value
  169. */
  170. public function searchPidAttr($query, $value)
  171. {
  172. if ($value !== '') $query->where('pid', $value);
  173. }
  174. /**
  175. * type搜索器
  176. * @param Model $query
  177. * @param $value
  178. */
  179. public function searchTypeAttr($query, $value)
  180. {
  181. if ($value) $query->where('type', $value);
  182. }
  183. /**
  184. * store_id搜索器
  185. * @param $query
  186. * @param $value
  187. */
  188. public function searchStoreIdAttr($query, $value)
  189. {
  190. if ($value !== '') $query->where('store_id', $value);
  191. }
  192. /**
  193. * promotions_type搜索器
  194. * @param $query
  195. * @param $value
  196. */
  197. public function searchPromotionsTypeAttr($query, $value)
  198. {
  199. if ($value !== '') $query->where('promotions_type', $value);
  200. }
  201. /**
  202. * promotions_cate搜索器
  203. * @param Model $query
  204. * @param $value
  205. */
  206. public function searchPromotionsCateAttr($query, $value)
  207. {
  208. if ($value !== '') $query->where('promotions_cate', $value);
  209. }
  210. /**
  211. * name搜索器
  212. * @param Model $query
  213. * @param $value
  214. */
  215. public function searchNameAttr($query, $value)
  216. {
  217. if ($value !== '') $query->whereLike('name', "%" . $value . "%");
  218. }
  219. /**
  220. * threshold_type搜索器
  221. * @param Model $query
  222. * @param $value
  223. */
  224. public function searchThresholdTypeAttr($query, $value)
  225. {
  226. if ($value !== '') $query->where('threshold_type', $value);
  227. }
  228. /**
  229. * discount_type搜索器
  230. * @param Model $query
  231. * @param $value
  232. */
  233. public function searchDiscountTypeAttr($query, $value)
  234. {
  235. if ($value !== '') $query->where('discount_type', $value);
  236. }
  237. /**
  238. * n_piece_n_discount搜索器
  239. * @param Model $query
  240. * @param $value
  241. */
  242. public function searchNPieceNDiscountAttr($query, $value)
  243. {
  244. if ($value !== '') $query->where('n_piece_n_discount', $value);
  245. }
  246. /**
  247. * product_partake_type搜索器
  248. * @param Model $query
  249. * @param $value
  250. */
  251. public function searchProductPartakeTypeAttr($query, $value)
  252. {
  253. if ($value !== '') $query->where('product_partake_type', $value);
  254. }
  255. /**
  256. * 是否删除搜索器
  257. * @param Model $query
  258. * @param $value
  259. * @param $data
  260. */
  261. public function searchIsDelAttr($query, $value, $data)
  262. {
  263. $query->where('is_del', $value ?? 0);
  264. }
  265. /**
  266. * 状态搜索器
  267. * @param Model $query
  268. * @param $value
  269. * @param $data
  270. */
  271. public function searchStatusAttr($query, $value, $data)
  272. {
  273. if ($value != '') $query->where('status', $value);
  274. }
  275. }