StoreCart.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\product\product\StoreProduct;
  13. use app\model\product\sku\StoreProductAttrValue;
  14. use crmeb\basic\BaseModel;
  15. use crmeb\traits\ModelTrait;
  16. use think\Model;
  17. /**
  18. * 购物车Model
  19. * Class StoreCart
  20. * @package app\model\order
  21. */
  22. class StoreCart extends BaseModel
  23. {
  24. use ModelTrait;
  25. /**
  26. * 数据表主键
  27. * @var string
  28. */
  29. protected $pk = 'id';
  30. /**
  31. * 模型名称
  32. * @var string
  33. */
  34. protected $name = 'store_cart';
  35. /**
  36. * 自动添加字段
  37. * @var string[]
  38. */
  39. protected $insert = ['add_time'];
  40. /**
  41. * 添加时间修改器
  42. * @return int
  43. */
  44. protected function setAddTimeAttr()
  45. {
  46. return time();
  47. }
  48. /**
  49. * 一对一关联
  50. * 购物车关联商品商品详情
  51. * @return \think\model\relation\HasOne
  52. */
  53. public function productInfo()
  54. {
  55. return $this->hasOne(StoreProduct::class, 'id', 'product_id');
  56. }
  57. /**
  58. * 一对一关联
  59. * 购物车关联商品商品规格
  60. * @return \think\model\relation\HasOne
  61. */
  62. public function attrInfo()
  63. {
  64. return $this->hasOne(StoreProductAttrValue::class, 'unique', 'product_attr_unique');
  65. }
  66. /**
  67. * 类型搜索器
  68. * @param Model $query
  69. * @param $value
  70. * @param $data
  71. */
  72. public function searchTypeAttr($query, $value, $data)
  73. {
  74. $query->where('type', $value);
  75. }
  76. /**
  77. * 是否支付
  78. * @param Model $query
  79. * @param $value
  80. * @param $data
  81. */
  82. public function searchIsPayAttr($query, $value, $data)
  83. {
  84. $query->where('is_pay', $value);
  85. }
  86. /**
  87. * 是否删除
  88. * @param Model $query
  89. * @param $value
  90. * @param $data
  91. */
  92. public function searchIsDelAttr($query, $value, $data)
  93. {
  94. $query->where('is_del', $value);
  95. }
  96. /**
  97. * 是否立即支付
  98. * @param Model $query
  99. * @param $value
  100. * @param $data
  101. */
  102. public function searchIsNewAttr($query, $value, $data)
  103. {
  104. $query->where('is_new', $value);
  105. }
  106. /**
  107. * 查询用户购物车
  108. * @param Model $query
  109. * @param $value
  110. * @param $data
  111. */
  112. public function searchUidAttr($query, $value, $data)
  113. {
  114. $query->where('uid', $value);
  115. }
  116. /**
  117. * 商品ID搜索器
  118. * @param Model $query
  119. * @param $value
  120. * @param $data
  121. */
  122. public function searchProductIdAttr($query, $value, $data)
  123. {
  124. if (is_array($value)) {
  125. $query->whereIn('product_id', $value);
  126. } else {
  127. $query->where('product_id', $value);
  128. }
  129. }
  130. /**
  131. * 商品规格唯一值搜索器
  132. * @param Model $query
  133. * @param $value
  134. * @param $data
  135. */
  136. public function searchProductAttrUniqueAttr($query, $value, $data)
  137. {
  138. $query->where('product_attr_unique', $value);
  139. }
  140. /**
  141. * 拼团ID搜索器
  142. * @param Model $query
  143. * @param $value
  144. * @param $data
  145. */
  146. public function searchCombinationIdAttr($query, $value, $data)
  147. {
  148. $query->where('combination_id', $value);
  149. }
  150. /**
  151. * 砍价ID搜索器
  152. * @param Model $query
  153. * @param $value
  154. * @param $data
  155. */
  156. public function searchBargainIdAttr($query, $value, $data)
  157. {
  158. $query->where('bargain_id', $value);
  159. }
  160. /**
  161. * 秒杀ID搜索器
  162. * @param Model $query
  163. * @param $value
  164. * @param $data
  165. */
  166. public function searchSeckillIdAttr($query, $value, $data)
  167. {
  168. $query->where('seckill_id', $value);
  169. }
  170. /**
  171. * 一对多关联
  172. * 商品关联优惠卷模板id
  173. * @return \think\model\relation\HasMany
  174. */
  175. public function product()
  176. {
  177. return $this->hasMany(StoreProduct::class, 'id', 'product_id');
  178. }
  179. }