Product.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\product;
  12. use app\common\dao\store\StoreSeckillActiveDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\store\coupon\StoreCouponProduct;
  15. use app\common\model\store\Guarantee;
  16. use app\common\model\store\GuaranteeTemplate;
  17. use app\common\model\store\GuaranteeValue;
  18. use app\common\model\store\parameter\ParameterValue;
  19. use app\common\model\store\shipping\ShippingTemplate;
  20. use app\common\model\store\StoreBrand;
  21. use app\common\model\store\StoreCategory;
  22. use app\common\model\store\StoreSeckillActive;
  23. use app\common\model\store\StoreSeckillTime;
  24. use app\common\model\system\form\Form;
  25. use app\common\model\system\merchant\Merchant;
  26. use app\common\model\store\parameter\ParameterProduct;
  27. use app\common\repositories\store\StoreCategoryRepository;
  28. use crmeb\services\VicWordService;
  29. use think\db\BaseQuery;
  30. use think\facade\Db;
  31. use think\model\concern\SoftDelete;
  32. class Product extends BaseModel
  33. {
  34. use SoftDelete;
  35. protected $deleteTime = 'is_del';
  36. protected $defaultSoftDelete = 0;
  37. /**
  38. * @Author:Qinii
  39. * @Date: 2020/5/8
  40. * @return string
  41. */
  42. public static function tablePk(): string
  43. {
  44. return 'product_id';
  45. }
  46. /**
  47. * @Author:Qinii
  48. * @Date: 2020/5/8
  49. * @return string
  50. */
  51. public static function tableName(): string
  52. {
  53. return 'store_product';
  54. }
  55. /*
  56. * -----------------------------------------------------------------------------------------------------------------
  57. * 属性
  58. * -----------------------------------------------------------------------------------------------------------------
  59. */
  60. public function getSliderImageAttr($value)
  61. {
  62. if (empty($value)) return [];
  63. return !is_array($value) ? explode(',', $value) : $value;
  64. }
  65. public function getGiveCouponIdsAttr($value)
  66. {
  67. if (empty($value)) return [];
  68. return !is_array($value) ? explode(',', $value) : $value;
  69. }
  70. public function getGoodIdsAttr($value, $data)
  71. {
  72. if (empty($value)) return [];
  73. return !is_array($value) ? explode(',', $value) : $value;
  74. }
  75. //public function getParamTempIdAttr($value)
  76. //{
  77. // if (empty($value)) return [];
  78. // return !is_array($value) ? explode(',', $value) : $value;
  79. //}
  80. public function getMaxExtensionAttr($value)
  81. {
  82. if ($this->extension_type) {
  83. $org_extension = ($this->attrValue()->order('extension_one DESC')->value('extension_one'));
  84. } else {
  85. $org_extension = bcmul(($this->attrValue()->order('price DESC')->value('price')), systemConfig('extension_one_rate'), 2);
  86. }
  87. $spreadUser = (request()->hasMacro('isLogin') && request()->isLogin() && request()->userType() == 1) ? request()->userInfo() : null;
  88. if ($spreadUser && $spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
  89. $org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
  90. }
  91. return $org_extension;
  92. }
  93. public function getMinExtensionAttr($value)
  94. {
  95. if ($this->extension_type) {
  96. $org_extension = ($this->attrValue()->order('extension_two ASC')->value('extension_two'));
  97. } else {
  98. $org_extension = bcmul(($this->attrValue()->order('price ASC')->value('price')), systemConfig('extension_two_rate'), 2);
  99. }
  100. $spreadUser = (request()->hasMacro('isLogin') && request()->isLogin() && request()->userType() == 1) ? request()->userInfo() : null;
  101. if ($spreadUser && $spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
  102. $org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
  103. }
  104. return $org_extension;
  105. }
  106. public function check()
  107. {
  108. if (!$this || !$this->is_show || !$this->is_used || !$this->status || $this->is_del || !$this->mer_status) return false;
  109. return true;
  110. }
  111. /**
  112. * 秒杀商品结束时间
  113. * @return false|int
  114. * @author Qinii
  115. * @day 2020-08-15
  116. */
  117. public function getEndTimeAttr()
  118. {
  119. if ($this->product_type !== 1) return true;
  120. $end_day = strtotime($this->seckillActive['end_day']);
  121. if ($end_day > time()) {
  122. return strtotime($this->seckillActive['end_day']);
  123. } else {
  124. return time();
  125. }
  126. }
  127. /**
  128. * 自动上架时间转换
  129. * @param $value
  130. * @param $data
  131. * @return string
  132. */
  133. public function getAutoOnTimeAttr($value,$data)
  134. {
  135. if($value){
  136. return date('Y-m-d H:i:s',$value);
  137. }
  138. }
  139. /**
  140. * 自动下架时间转换
  141. * @param $value
  142. * @param $data
  143. * @return string
  144. */
  145. public function getAutoOffTimeAttr($value,$data)
  146. {
  147. if($value){
  148. return date('Y-m-d H:i:s',$value);
  149. }
  150. }
  151. /**
  152. * 秒杀商品状态
  153. * @return int|true
  154. * FerryZhao 2024/4/25
  155. */
  156. public function getSeckillStatusAttr($value,$data)
  157. {
  158. if ($this->product_type !== 1) return true;
  159. if ($this->seckillActive && $this->seckillActive['active_status'] !== -1) {
  160. $end_day = strtotime($this->seckillActive->getData('end_day'));
  161. if ($end_day <= time()) return -1;//已结束
  162. $start_day = strtotime($this->seckillActive['start_day']);
  163. if ($start_day <= time()) {
  164. $currentHour = date('G', time());
  165. $data = StoreSeckillTime::whereIn('seckill_time_id',$this->seckillActive->seckill_time_ids)
  166. ->where('start_time','<=',$currentHour)->where('end_time','>',$currentHour)
  167. ->where('status',1)
  168. ->find();
  169. if ($data) {
  170. return 1;
  171. } else {
  172. return 0;
  173. }
  174. } else {
  175. //还未开始
  176. return 0;
  177. }
  178. }
  179. //已结束
  180. return -1;
  181. }
  182. public function getImageAttr($value)
  183. {
  184. if (is_int(strpos($value, 'http'))) {
  185. return $value;
  186. } else {
  187. return rtrim(systemConfig('site_url'), '/') . $value;
  188. }
  189. }
  190. public function getTopReplyAttr()
  191. {
  192. $res = [];
  193. if (systemConfig('sys_reply_status')) {
  194. $res = ProductReply::where('product_id', $this->product_id)->where('is_del', 0)->with(['orderProduct'])->field('reply_id,uid,nickname,merchant_reply_content,avatar,order_product_id,product_id,product_score,service_score,postage_score,comment,pics,rate,create_time')
  195. ->order('sort DESC,create_time DESC')->limit(1)->find();
  196. if (!$res) return null;
  197. if ($res['orderProduct'])
  198. $res['sku'] = $res['orderProduct']['cart_info']['productAttr']['sku'];
  199. unset($res['orderProduct']);
  200. if (strlen($res['nickname']) > 1) {
  201. $str = mb_substr($res['nickname'], 0, 1) . '*';
  202. if (strlen($res['nickname']) > 2) {
  203. $str .= mb_substr($res['nickname'], -1, 1);
  204. }
  205. $res['nickname'] = $str;
  206. }
  207. }
  208. return $res;
  209. }
  210. public function getUsStatusAttr()
  211. {
  212. return ($this->status == 1) ? ($this->is_used == 1 ? ($this->mer_status == 1 && $this->is_show == 1 ? 1 : 0) : -1) : -1;
  213. }
  214. public function getGuaranteeTemplateAttr()
  215. {
  216. $gua = GuaranteeTemplate::where('guarantee_template_id', $this->guarantee_template_id)->where('status', 1)->where('is_del', 0)->find();
  217. if (!$gua) return [];
  218. $guarantee_id = GuaranteeValue::where('guarantee_template_id', $this->guarantee_template_id)->column('guarantee_id');
  219. return Guarantee::where('guarantee_id', 'in', $guarantee_id)->where('status', 1)->where('is_del', 0)->select();
  220. }
  221. public function getMaxIntegralAttr()
  222. {
  223. if (systemConfig('integral_status') && merchantConfig($this->mer_id, 'mer_integral_status')) {
  224. $price = ($this->attrValue()->order('price DESC')->value('price'));
  225. $rate = ($this->integral_rate < 0) ? merchantConfig($this->mer_id, 'mer_integral_rate') : $this->integral_rate;
  226. $rate = $rate > 0 ? $rate / 100 : 0;
  227. return bcmul($price, $rate, 2);
  228. }
  229. return '0';
  230. }
  231. public function getHotRankingAttr()
  232. {
  233. if ($this->product_type == 0) {
  234. $where = [
  235. 'is_show' => 1,
  236. 'status' => 1,
  237. 'is_used' => 1,
  238. 'product_type' => 0,
  239. 'mer_status' => 1,
  240. 'is_gift_bag' => 0,
  241. 'cate_id' => $this->cate_id
  242. ];
  243. self::where($where)->order('sales DESC');
  244. }
  245. }
  246. public function getOtPriceAttr($value)
  247. {
  248. if ($this->product_type == 20) {
  249. return (int)$value;
  250. }
  251. return $value;
  252. }
  253. public function getCustomTempIdAttr($value)
  254. {
  255. return !empty($value) ? json_decode($value, true) : [];
  256. }
  257. public function getLabelsAttr($value)
  258. {
  259. return !empty($value) ? json_decode($value, true) : [];
  260. }
  261. /**
  262. * 商品参数
  263. * @author Qinii
  264. * @day 2022/11/24
  265. */
  266. public function getParameterParamsAttr()
  267. {
  268. $parameter_value_id = ParameterProduct::where('product_id',$this->product_id)->column('parameter_value_id');
  269. $data = ParameterValue::whereIn('parameter_value_id',$parameter_value_id)->select()->toArray();
  270. $parameter = [];
  271. foreach ($data as $item) {
  272. $parameter[$item['name']][] = $item['value'];
  273. }
  274. $arr = array_map(function ($k, $v) {
  275. return ['label' => $k, 'value' => $v];
  276. }, array_keys($parameter), $parameter);
  277. return $arr;
  278. }
  279. public function attrResult()
  280. {
  281. return $this->hasOne(ProductResult::class,'product_id','product_id');
  282. }
  283. /**
  284. * 是否是会员
  285. * @return bool
  286. * @author Qinii
  287. * @day 2023/1/4
  288. */
  289. public function getIsVipAttr()
  290. {
  291. if (request()->hasMacro('isLogin') && request()->isLogin()) {
  292. if (request()->userType() == 1) {
  293. $userInfo = request()->userInfo();
  294. return $userInfo->is_svip > 0 ? true : false;
  295. } else {
  296. return true;
  297. }
  298. }
  299. return false;
  300. }
  301. /**
  302. * 是否展示会员价
  303. * @return bool
  304. * @author Qinii
  305. * @day 2023/1/4
  306. */
  307. public function getShowSvipPriceAttr()
  308. {
  309. if ($this->mer_svip_status != 0 && (systemConfig('svip_show_price') != 1 || $this->is_vip) && $this->svip_price_type > 0) {
  310. return true;
  311. }
  312. return false;
  313. }
  314. /**
  315. * 是否显示会员价等信息
  316. * @return array
  317. * @author Qinii
  318. * @day 2022/11/24
  319. */
  320. public function getShowSvipInfoAttr()
  321. {
  322. $res = [
  323. 'show_svip' => true, //是否展示会员入口
  324. 'is_svip' => false, //当前用户是否是会员
  325. 'show_svip_price' => false, //是否展示会员价
  326. 'save_money' => 0, //当前商品会员优化多少钱
  327. ];
  328. if ($this->product_type == 0) {
  329. if (!systemConfig('svip_switch_status')) {
  330. $res['show_svip'] = false;
  331. } else {
  332. $res['is_svip'] = $this->is_vip;
  333. if ($this->show_svip_price) {
  334. $res['show_svip_price'] = true;
  335. $res['save_money'] = bcsub($this->price, $this->svip_price, 2);
  336. }
  337. }
  338. }
  339. return $res;
  340. }
  341. /**
  342. * 获取会员价
  343. * @return int|string
  344. * @author Qinii
  345. * @day 2023/1/4
  346. */
  347. public function getSvipPriceAttr()
  348. {
  349. if ($this->product_type == 0 && $this->mer_svip_status != 0 && $this->show_svip_price) {
  350. //默认比例
  351. if ($this->svip_price_type == 1) {
  352. $rate = merchantConfig($this->mer_id, 'svip_store_rate');
  353. $svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
  354. $price = $this->attrValue()->order('price ASC')->value('price');
  355. return bcmul($price, $svip_store_rate, 2);
  356. }
  357. //自定义
  358. if ($this->svip_price_type == 2) {
  359. return $this->getData('svip_price');
  360. }
  361. }
  362. return 0;
  363. }
  364. public function getIsSvipPriceAttr()
  365. {
  366. if ($this->product_type == 0 && $this->mer_svip_status != 0) {
  367. //默认比例
  368. if ($this->svip_price_type == 1) {
  369. $rate = merchantConfig($this->mer_id, 'svip_store_rate');
  370. $svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
  371. $price = $this->attrValue()->order('price ASC')->value('price');
  372. return bcmul($price, $svip_store_rate, 2);
  373. }
  374. //自定义
  375. if ($this->svip_price_type == 2) {
  376. return $this->getData('svip_price');
  377. }
  378. }
  379. return 0;
  380. }
  381. /*
  382. * -----------------------------------------------------------------------------------------------------------------
  383. * 关联模型
  384. * -----------------------------------------------------------------------------------------------------------------
  385. */
  386. public function merCateId()
  387. {
  388. return $this->hasMany(ProductCate::class, 'product_id', 'product_id')->field('product_id,mer_cate_id');
  389. }
  390. public function attr()
  391. {
  392. return $this->hasMany(ProductAttr::class, 'product_id', 'product_id');
  393. }
  394. public function attrValue()
  395. {
  396. return $this->hasMany(ProductAttrValue::class, 'product_id', 'product_id')->order('value_id ASC');
  397. }
  398. public function oldAttrValue()
  399. {
  400. return $this->hasMany(ProductAttrValue::class, 'product_id', 'old_product_id');
  401. }
  402. public function content()
  403. {
  404. return $this->hasOne(ProductContent::class, 'product_id', 'product_id');
  405. }
  406. public function reservation()
  407. {
  408. return $this->hasOne(ProductReservation::class, 'product_id', 'product_id');
  409. }
  410. protected function temp()
  411. {
  412. return $this->hasOne(ShippingTemplate::class, 'shipping_template_id', 'temp_id');
  413. }
  414. public function storeCategory()
  415. {
  416. return $this->hasOne(StoreCategory::class, 'store_category_id', 'cate_id')->field('store_category_id,cate_name');
  417. }
  418. public function merchant()
  419. {
  420. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id')->field('is_trader,type_id,mer_id,mer_name,mer_avatar,product_score,service_score,postage_score,service_phone,care_count,is_margin');
  421. }
  422. public function reply()
  423. {
  424. return $this->hasMany(ProductReply::class, 'product_id', 'product_id')->order('create_time DESC');
  425. }
  426. public function brand()
  427. {
  428. return $this->hasOne(StoreBrand::class, 'brand_id', 'brand_id')->field('brand_id,brand_name');
  429. }
  430. public function seckillActive()
  431. {
  432. return $this->hasOne(StoreSeckillActive::class, 'seckill_active_id', 'active_id');
  433. }
  434. public function issetCoupon()
  435. {
  436. return $this->hasOne(StoreCouponProduct::class, 'product_id', 'product_id')->alias('A')
  437. ->rightJoin('StoreCoupon B', 'A.coupon_id = B.coupon_id')->where(function (BaseQuery $query) {
  438. $query->where('B.is_limited', 0)->whereOr(function (BaseQuery $query) {
  439. $query->where('B.is_limited', 1)->where('B.remain_count', '>', 0);
  440. });
  441. })->where(function (BaseQuery $query) {
  442. $query->where('B.is_timeout', 0)->whereOr(function (BaseQuery $query) {
  443. $time = date('Y-m-d H:i:s');
  444. $query->where('B.is_timeout', 1)->where('B.start_time', '<', $time)->where('B.end_time', '>', $time);
  445. });
  446. })->field('A.product_id,B.*')->where('status', 1)->where('type', 1)->where('send_type', 0)->where('is_del', 0)
  447. ->order('sort DESC,coupon_id DESC')->hidden(['is_del', 'status']);
  448. }
  449. public function assist()
  450. {
  451. return $this->hasOne(ProductAssist::class, 'product_id', 'product_id');
  452. }
  453. public function productGroup()
  454. {
  455. return $this->hasOne(ProductGroup::class, 'product_id', 'product_id');
  456. }
  457. public function guarantee()
  458. {
  459. return $this->hasOne(GuaranteeTemplate::class, 'guarantee_template_id', 'guarantee_template_id')->where('status', 1)->where('is_del', 0);
  460. }
  461. public function getForm()
  462. {
  463. return $this->hasOne(Form::class, 'form_id', 'mer_form_id');
  464. }
  465. public function getFormName()
  466. {
  467. return $this->hasOne(Form::class, 'form_id', 'mer_form_id')->bind(['mer_form_name' => 'name']);
  468. }
  469. /*
  470. * -----------------------------------------------------------------------------------------------------------------
  471. * 搜索器
  472. * -----------------------------------------------------------------------------------------------------------------
  473. */
  474. public function searchMerCateIdAttr($query, $value)
  475. {
  476. $cate_ids = (StoreCategory::where('path', 'like', '%/' . $value . '/%'))->column('store_category_id');
  477. $cate_ids[] = intval($value);
  478. $product_id = ProductCate::whereIn('mer_cate_id', $cate_ids)->column('product_id');
  479. $query->whereIn('Product.product_id', $product_id);
  480. }
  481. public function searchKeywordAttr($query, $value)
  482. {
  483. if (!$value) return;
  484. if (is_numeric($value)) {
  485. $query->whereLike("Product.store_name|Product.keyword|bar_code|Product.product_id", "%{$value}%");
  486. } else if (is_array($value)) {
  487. $query->where(function ($query) use ($value) {
  488. foreach ($value as $item) {
  489. $query->whereOr('Product.store_name|Product.keyword', 'LIKE', "%$item%");
  490. }
  491. });
  492. } else {
  493. $word = app()->make(VicWordService::class)->getWord($value);
  494. $query->where(function ($query) use ($word, $value) {
  495. foreach ($word as $item) {
  496. $query->whereOr('Product.store_name|Product.keyword', 'LIKE', "%$item%");
  497. }
  498. $query->order(Db::raw('REPLACE(Product.store_name,\'' . $value . '\',\'\')'));
  499. });
  500. }
  501. }
  502. public function searchStatusAttr($query, $value)
  503. {
  504. if ($value === -1) {
  505. $query->where('Product.status', 'in', [-1, -2]);
  506. } else {
  507. $query->where('Product.status', $value);
  508. }
  509. }
  510. public function searchCatePidAttr($query, $value)
  511. {
  512. $storeCategoryRepository = app()->make(StoreCategoryRepository::class);
  513. $ChildIdsData = $storeCategoryRepository->getSearch(['ids' =>$value])->where('is_show', 1)->append(['three_child_ids'])->select()->toArray();
  514. $childIds = array_reduce(array_column($ChildIdsData,'three_child_ids') ?: [], 'array_merge',[]);
  515. $query->whereIn('cate_id',$childIds);
  516. }
  517. public function searchCateIdAttr($query, $value)
  518. {
  519. $query->where('cate_id', $value);
  520. }
  521. public function searchCateIdsAttr($query, $value)
  522. {
  523. $query->whereIn('cate_id', $value);
  524. }
  525. public function searchIsShowAttr($query, $value)
  526. {
  527. if($value == 0){
  528. $query->whereIn('is_show',[0,2]);
  529. }else{
  530. $query->where('is_show', $value);
  531. }
  532. }
  533. public function searchPidAttr($query, $value)
  534. {
  535. $childrenId = app()->make(StoreCategoryRepository::class)->findChildrenId((int)$value);
  536. $ids = array_merge($childrenId, [(int)$value]);
  537. $query->whereIn('cate_id', $ids);
  538. }
  539. public function searchStockAttr($query, $value)
  540. {
  541. $value ? $query->where('stock', '<=', $value) : $query->where('stock', $value);
  542. }
  543. public function searchIsNewAttr($query, $value)
  544. {
  545. $query->where('is_new', $value);
  546. }
  547. public function searchPriceAttr($query, $value)
  548. {
  549. if (empty($value[0]) && !empty($value[1]))
  550. $query->where('price', '<', $value[1]);
  551. if (!empty($value[0]) && empty($value[1]))
  552. $query->where('price', '>', $value[0]);
  553. if (!empty($value[0]) && !empty($value[1]))
  554. $query->whereBetween('price', [$value[0], $value[1]]);
  555. }
  556. public function searchBrandIdAttr($query, $value)
  557. {
  558. $query->whereIn('brand_id', $value);
  559. }
  560. public function searchIsGiftBagAttr($query, $value)
  561. {
  562. $query->where('is_gift_bag', $value);
  563. }
  564. public function searchIsGoodAttr($query, $value)
  565. {
  566. $query->where('is_good', $value);
  567. }
  568. public function searchIsUsedAttr($query, $value)
  569. {
  570. $query->where('is_used', $value);
  571. }
  572. public function searchIsOil($query, $value)
  573. {
  574. $query->where('is_oil', $value);
  575. }
  576. public function searchIsGift($query, $value)
  577. {
  578. $query->where('is_gift', $value);
  579. }
  580. public function searchProductTypeAttr($query, $value)
  581. {
  582. $query->where('Product.product_type', $value);
  583. }
  584. // public function searchSeckillStatusAttr($query, $value)
  585. // {
  586. // $product_id = (new StoreSeckillActiveDao())->getStatus($value)->column('product_id');
  587. // $query->whereIn('Product.product_id', $product_id);
  588. // }
  589. public function searchStoreNameAttr($query, $value)
  590. {
  591. $query->where('Product.store_name', 'like', '%' . $value . '%');
  592. }
  593. public function searchMerStatusAttr($query, $value)
  594. {
  595. $query->where('mer_status', $value);
  596. }
  597. public function searchTypeAttr($query, $value)
  598. {
  599. $query->where('type', $value);
  600. }
  601. public function searchProductIdAttr($query, $value)
  602. {
  603. $query->where('Product.product_id', $value);
  604. }
  605. public function searchProductIdsAttr($query, $value)
  606. {
  607. $query->whereIn('Product.product_id', $value);
  608. }
  609. public function searchNotProductIdAttr($query, $value)
  610. {
  611. if (!empty($value)) {
  612. if (is_array($value)) {
  613. $query->whereNotIn('Product.product_id', $value);
  614. } else {
  615. $query->where('Product.product_id', '<>', $value);
  616. }
  617. }
  618. }
  619. public function searchPriceOnAttr($query, $value)
  620. {
  621. $query->where('price', '>=', $value);
  622. }
  623. public function searchPriceOffAttr($query, $value)
  624. {
  625. $query->where('price', '<=', $value);
  626. }
  627. public function searchisFictiAttr($query, $value)
  628. {
  629. $query->where('type', 'in', $value);
  630. }
  631. public function searchGuaranteeTemplateIdAttr($query, $value)
  632. {
  633. $query->whereIn('guarantee_template_id', $value);
  634. }
  635. public function searchTempIdAttr($query, $value)
  636. {
  637. $query->whereIn('Product.temp_id', $value);
  638. }
  639. public function searchDateAttr($query, $value)
  640. {
  641. getModelTime($query, $value, 'Product.create_time');
  642. }
  643. public function searchFormIdAttr($query, $value)
  644. {
  645. if ($value !== '') {
  646. $query->whereIn('Product.mer_form_id', $value);
  647. }
  648. }
  649. public function searchMerFormIdAttr($query, $value)
  650. {
  651. if ($value !== '') {
  652. $query->whereIn('Product.mer_form_id', $value);
  653. }
  654. }
  655. public function searchCateHotAttr($query, $value)
  656. {
  657. if ($value !== '') {
  658. $query->whereIn('Product.cate_hot', $value);
  659. }
  660. }
  661. public function searchInTypeAttr($query, $value)
  662. {
  663. if ($value !== '') {
  664. $query->whereIn('Product.type', $value);
  665. }
  666. }
  667. public function searchNotActiveIdAttr($query, $value)
  668. {
  669. if ($value !== '') {
  670. $query->where('Product.active_id', '<>',$value);
  671. }
  672. }
  673. }