StoreBargainServices.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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. declare (strict_types=1);
  12. namespace app\services\activity\bargain;
  13. use app\dao\activity\bargain\StoreBargainDao;
  14. use app\jobs\ProductLogJob;
  15. use app\Request;
  16. use app\services\BaseServices;
  17. use app\services\order\StoreOrderServices;
  18. use app\services\product\product\StoreCategoryServices;
  19. use app\services\product\product\StoreDescriptionServices;
  20. use app\services\product\product\StoreProductServices;
  21. use app\services\product\sku\StoreProductAttrResultServices;
  22. use app\services\product\sku\StoreProductAttrServices;
  23. use app\services\product\sku\StoreProductAttrValueServices;
  24. use app\services\system\attachment\SystemAttachmentServices;
  25. use app\services\user\UserServices;
  26. use app\services\wechat\WechatServices;
  27. use crmeb\exceptions\AdminException;
  28. use crmeb\services\CacheService;
  29. use crmeb\services\MiniProgramService;
  30. use crmeb\services\UploadService;
  31. use crmeb\services\UtilService;
  32. use Guzzle\Http\EntityBody;
  33. use think\exception\ValidateException;
  34. /**
  35. *
  36. * Class StoreBargainServices
  37. * @package app\services\activity
  38. * @method get(int $id, array $field) 获取一条数据
  39. * @method getBargainIdsArray(array $ids, array $field)
  40. * @method sum(array $where, string $field)
  41. * @method update(int $id, array $data)
  42. * @method addBargain(int $id, string $field)
  43. * @method value(array $where, string $field)
  44. * @method validWhere()
  45. * @method getList(array $where, int $page = 0, int $limit = 0) 获取砍价列表
  46. */
  47. class StoreBargainServices extends BaseServices
  48. {
  49. /**
  50. * StoreCombinationServices constructor.
  51. * @param StoreBargainDao $dao
  52. */
  53. public function __construct(StoreBargainDao $dao)
  54. {
  55. $this->dao = $dao;
  56. }
  57. /**
  58. * 判断砍价商品是否开启
  59. * @param int $bargainId
  60. * @return int|string
  61. */
  62. public function validBargain($bargainId = 0)
  63. {
  64. $where = [];
  65. $time = time();
  66. $where[] = ['is_del', '=', 0];
  67. $where[] = ['status', '=', 1];
  68. $where[] = ['start_time', '<', $time];
  69. $where[] = ['stop_time', '>', $time - 85400];
  70. if ($bargainId) $where[] = ['id', '=', $bargainId];
  71. return $this->dao->getCount($where);
  72. }
  73. /**
  74. * 获取后台列表
  75. * @param array $where
  76. * @return array
  77. */
  78. public function getStoreBargainList(array $where)
  79. {
  80. [$page, $limit] = $this->getPageValue();
  81. $list = $this->dao->getList($where, $page, $limit);
  82. $count = $this->dao->count($where);
  83. /** @var StoreBargainUserServices $storeBargainUserServices */
  84. $storeBargainUserServices = app()->make(StoreBargainUserServices::class);
  85. $ids = array_column($list, 'id');
  86. $countAll = $storeBargainUserServices->getAllCount([['bargain_id', 'in', $ids]]);
  87. $countSuccess = $storeBargainUserServices->getAllCount([
  88. ['status', '=', 3],
  89. ['bargain_id', 'in', $ids]
  90. ]);
  91. /** @var StoreBargainUserHelpServices $storeBargainUserHelpServices */
  92. $storeBargainUserHelpServices = app()->make(StoreBargainUserHelpServices::class);
  93. $countHelpAll = $storeBargainUserHelpServices->getHelpAllCount([['bargain_id', 'in', $ids]]);
  94. foreach ($list as &$item) {
  95. $item['count_people_all'] = $countAll[$item['id']] ?? 0;//参与人数
  96. $item['count_people_help'] = $countHelpAll[$item['id']] ?? 0;//帮忙砍价人数
  97. $item['count_people_success'] = $countSuccess[$item['id']] ?? 0;//砍价成功人数
  98. $item['stop_status'] = $item['stop_time'] < time() ? 1 : 0;
  99. if ($item['status']) {
  100. if ($item['start_time'] > time())
  101. $item['start_name'] = '未开始';
  102. else if ($item['stop_time'] < time())
  103. $item['start_name'] = '已结束';
  104. else if ($item['stop_time'] > time() && $item['start_time'] < time()) {
  105. $item['start_name'] = '进行中';
  106. }
  107. } else $item['start_name'] = '已结束';
  108. }
  109. return compact('list', 'count');
  110. }
  111. /**
  112. * 保存数据
  113. * @param int $id
  114. * @param array $data
  115. */
  116. public function saveData(int $id, array $data)
  117. {
  118. $description = $data['description'];
  119. $detail = $data['attrs'];
  120. $items = $data['items'];
  121. $data['start_time'] = strtotime($data['section_time'][0]);
  122. $data['stop_time'] = strtotime($data['section_time'][1]);
  123. $data['image'] = $data['images'][0];
  124. $data['images'] = json_encode($data['images']);
  125. $data['stock'] = $detail[0]['stock'];
  126. $data['quota'] = $detail[0]['quota'];
  127. $data['quota_show'] = $detail[0]['quota'];
  128. $data['price'] = $detail[0]['price'];
  129. $data['min_price'] = $detail[0]['min_price'];
  130. $data['logistics'] = implode(',', $data['logistics']);
  131. if ($detail[0]['min_price'] < 0 || $detail[0]['price'] <= 0 || $detail[0]['min_price'] === '' || $detail[0]['price'] === '') throw new ValidateException('金额不能小于0');
  132. if ($detail[0]['min_price'] >= $detail[0]['price']) throw new ValidateException('砍价最低价不能大于或等于起始金额');
  133. if ($detail[0]['quota'] > $detail[0]['stock']) throw new ValidateException('限量不能超过商品库存');
  134. //按照能砍掉的金额计算最大设置人数,并判断填写的砍价人数是否大于最大设置人数
  135. $bNum = bcmul(bcsub((string)$data['price'], (string)$data['min_price'], 2), '100');
  136. if ($data['people_num'] > $bNum) throw new ValidateException('砍价人数不能大于' . $bNum . '人');
  137. unset($data['section_time'], $data['description'], $data['attrs'], $data['items'], $detail[0]['min_price'], $detail[0]['_index'], $detail[0]['_rowKey']);
  138. /** @var StoreDescriptionServices $storeDescriptionServices */
  139. $storeDescriptionServices = app()->make(StoreDescriptionServices::class);
  140. /** @var StoreProductAttrServices $storeProductAttrServices */
  141. $storeProductAttrServices = app()->make(StoreProductAttrServices::class);
  142. /** @var StoreProductServices $storeProductServices */
  143. $storeProductServices = app()->make(StoreProductServices::class);
  144. $this->transaction(function () use ($id, $data, $description, $detail, $items, $storeDescriptionServices, $storeProductAttrServices, $storeProductServices) {
  145. if ($id) {
  146. $res = $this->dao->update($id, $data);
  147. $storeDescriptionServices->saveDescription((int)$id, $description, 2);
  148. $skuList = $storeProductServices->validateProductAttr($items, $detail, (int)$id, 2);
  149. $valueGroup = $storeProductAttrServices->saveProductAttr($skuList, (int)$id, 2);
  150. if (!$res) throw new AdminException('修改失败');
  151. } else {
  152. if (!$storeProductServices->getOne(['is_show' => 1, 'is_del' => 0, 'id' => $data['product_id']])) {
  153. throw new AdminException('原商品已下架或移入回收站');
  154. }
  155. $data['add_time'] = time();
  156. $res = $this->dao->save($data);
  157. $storeDescriptionServices->saveDescription((int)$res->id, $description, 2);
  158. $skuList = $storeProductServices->validateProductAttr($items, $detail, (int)$res->id, 2);
  159. $valueGroup = $storeProductAttrServices->saveProductAttr($skuList, (int)$res->id, 2);
  160. if (!$res) throw new AdminException('添加失败');
  161. }
  162. $res = true;
  163. foreach ($valueGroup->toArray() as $item) {
  164. $res = $res && CacheService::setStock($item['unique'], (int)$item['quota_show'], 2);
  165. }
  166. if (!$res) {
  167. throw new AdminException('占用库存失败');
  168. }
  169. });
  170. }
  171. /**
  172. * 获取砍价详情
  173. * @param int $id
  174. * @return array|\think\Model|null
  175. */
  176. public function getInfo(int $id)
  177. {
  178. $info = $this->dao->get($id);
  179. if ($info) {
  180. if ($info['start_time'])
  181. $start_time = date('Y-m-d H:i:s', $info['start_time']);
  182. if ($info['stop_time'])
  183. $stop_time = date('Y-m-d H:i:s', $info['stop_time']);
  184. if (isset($start_time) && isset($stop_time))
  185. $info['section_time'] = [$start_time, $stop_time];
  186. else
  187. $info['section_time'] = [];
  188. unset($info['start_time'], $info['stop_time']);
  189. }
  190. $info['give_integral'] = intval($info['give_integral']);
  191. $info['price'] = floatval($info['price']);
  192. $info['postage'] = floatval($info['postage']);
  193. $info['cost'] = floatval($info['cost']);
  194. $info['bargain_max_price'] = floatval($info['bargain_max_price']);
  195. $info['bargain_min_price'] = floatval($info['bargain_min_price']);
  196. $info['min_price'] = floatval($info['min_price']);
  197. $info['weight'] = floatval($info['weight']);
  198. $info['volume'] = floatval($info['volume']);
  199. $info['logistics'] = explode(',', $info['logistics']);
  200. /** @var StoreDescriptionServices $storeDescriptionServices */
  201. $storeDescriptionServices = app()->make(StoreDescriptionServices::class);
  202. $info['description'] = $storeDescriptionServices->getDescription(['product_id' => $id, 'type' => 2]);
  203. $info['attrs'] = $this->attrList($id, $info['product_id']);
  204. return $info;
  205. }
  206. /**
  207. * 获取规格
  208. * @param int $id
  209. * @param int $pid
  210. * @return mixed
  211. */
  212. public function attrList(int $id, int $pid)
  213. {
  214. /** @var StoreProductAttrResultServices $storeProductAttrResultServices */
  215. $storeProductAttrResultServices = app()->make(StoreProductAttrResultServices::class);
  216. $bargainResult = $storeProductAttrResultServices->value(['product_id' => $id, 'type' => 2], 'result');
  217. $items = json_decode($bargainResult, true)['attr'];
  218. $productAttr = $this->getattr($items, $pid, 0);
  219. $bargainAttr = $this->getattr($items, $id, 2);
  220. foreach ($productAttr as $pk => $pv) {
  221. foreach ($bargainAttr as &$sv) {
  222. if ($pv['detail'] == $sv['detail']) {
  223. $productAttr[$pk] = $sv;
  224. }
  225. }
  226. $productAttr[$pk]['detail'] = json_decode($productAttr[$pk]['detail']);
  227. }
  228. $attrs['items'] = $items;
  229. $attrs['value'] = $productAttr;
  230. foreach ($items as $key => $item) {
  231. $header[] = ['title' => $item['value'], 'key' => 'value' . ($key + 1), 'align' => 'center', 'minWidth' => 80];
  232. }
  233. $header[] = ['title' => '图片', 'slot' => 'pic', 'align' => 'center', 'minWidth' => 120];
  234. $header[] = ['title' => '砍价起始金额', 'slot' => 'price', 'align' => 'center', 'minWidth' => 80];
  235. $header[] = ['title' => '砍价最低价', 'slot' => 'min_price', 'align' => 'center', 'minWidth' => 80];
  236. $header[] = ['title' => '成本价', 'key' => 'cost', 'align' => 'center', 'minWidth' => 80];
  237. $header[] = ['title' => '原价', 'key' => 'ot_price', 'align' => 'center', 'minWidth' => 80];
  238. $header[] = ['title' => '库存', 'key' => 'stock', 'align' => 'center', 'minWidth' => 80];
  239. $header[] = ['title' => '限量', 'slot' => 'quota', 'align' => 'center', 'minWidth' => 80];
  240. $header[] = ['title' => '重量(KG)', 'key' => 'weight', 'align' => 'center', 'minWidth' => 80];
  241. $header[] = ['title' => '体积(m³)', 'key' => 'volume', 'align' => 'center', 'minWidth' => 80];
  242. $header[] = ['title' => '商品编号', 'key' => 'bar_code', 'align' => 'center', 'minWidth' => 80];
  243. $attrs['header'] = $header;
  244. return $attrs;
  245. }
  246. /**
  247. * 获取规格
  248. * @param $attr
  249. * @param $id
  250. * @param $type
  251. * @return array
  252. */
  253. public function getattr($attr, $id, $type)
  254. {
  255. /** @var StoreProductAttrValueServices $storeProductAttrValueServices */
  256. $storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
  257. $value = attr_format($attr)[1];
  258. $valueNew = [];
  259. $count = 0;
  260. if ($type == 2) {
  261. $min_price = $this->dao->value(['id' => $id], 'min_price');
  262. } else {
  263. $min_price = 0;
  264. }
  265. foreach ($value as $key => $item) {
  266. $detail = $item['detail'];
  267. // sort($item['detail'], SORT_STRING);
  268. $suk = implode(',', $item['detail']);
  269. $sukValue = $storeProductAttrValueServices->getColumn(['product_id' => $id, 'type' => $type, 'suk' => $suk], 'bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
  270. if (count($sukValue)) {
  271. foreach (array_values($detail) as $k => $v) {
  272. $valueNew[$count]['value' . ($k + 1)] = $v;
  273. }
  274. $valueNew[$count]['detail'] = json_encode($detail);
  275. $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
  276. $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
  277. $valueNew[$count]['min_price'] = $min_price ? floatval($min_price) : 0;
  278. $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;
  279. $valueNew[$count]['ot_price'] = isset($sukValue[$suk]['ot_price']) ? floatval($sukValue[$suk]['ot_price']) : 0;
  280. $valueNew[$count]['stock'] = $sukValue[$suk]['stock'] ? intval($sukValue[$suk]['stock']) : 0;
  281. $valueNew[$count]['quota'] = $sukValue[$suk]['quota'] ? intval($sukValue[$suk]['quota']) : 0;
  282. $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
  283. $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ? floatval($sukValue[$suk]['weight']) : 0;
  284. $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ? floatval($sukValue[$suk]['volume']) : 0;
  285. $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ? floatval($sukValue[$suk]['brokerage']) : 0;
  286. $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ? floatval($sukValue[$suk]['brokerage_two']) : 0;
  287. $valueNew[$count]['opt'] = $type != 0;
  288. $count++;
  289. }
  290. }
  291. return $valueNew;
  292. }
  293. /**
  294. * TODO 获取砍价表ID
  295. * @param int $bargainId $bargainId 砍价商品
  296. * @param int $bargainUserUid $bargainUserUid 开启砍价用户编号
  297. * @param int $status $status 砍价状态 1参与中 2 活动结束参与失败 3活动结束参与成功
  298. * @return mixed
  299. */
  300. public function getBargainUserTableId($bargainId = 0, $bargainUserUid = 0)
  301. {
  302. return $this->dao->value(['bargain_id' => $bargainId, 'uid' => $bargainUserUid, 'is_del' => 0], 'id');
  303. }
  304. /**
  305. * TODO 获取用户可以砍掉的价格
  306. * @param $id $id 用户参与砍价表编号
  307. * @return float
  308. * @throws \think\db\exception\DataNotFoundException
  309. * @throws \think\db\exception\ModelNotFoundException
  310. * @throws \think\exception\DbException
  311. */
  312. public function getBargainUserDiffPriceFloat($id)
  313. {
  314. $price = $this->dao->get($id, ['bargain_price,bargain_price_min']);
  315. return (float)bcsub($price['bargain_price'], $price['bargain_price_min'], 2);
  316. }
  317. /**
  318. * TODO 获取用户砍掉的价格
  319. * @param int $id $id 用户参与砍价表编号
  320. * @return float
  321. */
  322. public function getBargainUserPrice($id = 0)
  323. {
  324. return (float)$this->dao->value(['id' => $id], 'price');
  325. }
  326. /**
  327. * 获取一条砍价商品
  328. * @param int $bargainId
  329. * @param string $field
  330. * @return array
  331. */
  332. public function getBargainOne($bargainId = 0, $field = 'id,product_id,title,price,min_price,image')
  333. {
  334. if (!$bargainId) return [];
  335. $bargain = $this->dao->getOne(['id' => $bargainId], $field);
  336. if ($bargain) return $bargain->toArray();
  337. else return [];
  338. }
  339. /**
  340. * 砍价列表
  341. * @return array
  342. */
  343. public function getBargainList()
  344. {
  345. /** @var StoreBargainUserServices $bargainUserService */
  346. $bargainUserService = app()->make(StoreBargainUserServices::class);
  347. [$page, $limit] = $this->getPageValue();
  348. $list = $this->dao->BargainList($page, $limit);
  349. foreach ($list as &$item) {
  350. $item['people'] = $bargainUserService->getUserIdList($item['id']);
  351. $item['price'] = floatval($item['price']);
  352. }
  353. return $list;
  354. }
  355. /**
  356. * 后台页面设计获取砍价列表
  357. * @param $where
  358. * @return array
  359. * @throws \think\db\exception\DataNotFoundException
  360. * @throws \think\db\exception\DbException
  361. * @throws \think\db\exception\ModelNotFoundException
  362. */
  363. public function getDiyBargainList($where)
  364. {
  365. $where['status'] = 1;
  366. unset($where['is_show']);
  367. [$page, $limit] = $this->getPageValue();
  368. $list = $this->dao->DiyBargainList($where, $page, $limit);
  369. $count = $this->dao->getCount($where);
  370. $cateIds = implode(',', array_column($list, 'cate_id'));
  371. /** @var StoreCategoryServices $storeCategoryServices */
  372. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  373. $cateList = $storeCategoryServices->getCateArray($cateIds);
  374. foreach ($list as &$item) {
  375. $cateName = array_filter($cateList, function ($val) use ($item) {
  376. if (in_array($val['id'], explode(',', $item['cate_id']))) {
  377. return $val;
  378. }
  379. });
  380. $item['cate_name'] = implode(',', array_column($cateName, 'cate_name'));
  381. $item['store_name'] = $item['title'];
  382. $item['price'] = floatval($item['price']);
  383. $item['is_product_type'] = 1;
  384. }
  385. return compact('count', 'list');
  386. }
  387. /**
  388. * 首页砍价商品
  389. * @param $where
  390. * @return array
  391. */
  392. public function getHomeList($where)
  393. {
  394. [$page, $limit] = $this->getPageValue();
  395. $where['is_del'] = 0;
  396. $where['is_show'] = 1;
  397. $data = [];
  398. $list = $this->dao->getHomeList($where, $page, $limit);
  399. foreach ($list as &$item) {
  400. $item['price'] = floatval($item['price']);
  401. }
  402. $data['list'] = $list;
  403. return $data;
  404. }
  405. /**获取单条砍价
  406. * @param Request $request
  407. * @param int $id
  408. * @return mixed
  409. * @throws \think\db\exception\DataNotFoundException
  410. * @throws \think\db\exception\DbException
  411. * @throws \think\db\exception\ModelNotFoundException
  412. */
  413. public function getBargain(Request $request, int $id)
  414. {
  415. $bargain = $this->dao->getOne(['id' => $id], '*', ['description']);
  416. if (!$bargain) throw new ValidateException('砍价商品不存在');
  417. $this->dao->addBargain($id, 'look');
  418. $bargain['time'] = time();
  419. if ($bargain['stop_time'] < time()) throw new ValidateException('砍价已结束');
  420. $user = $request->user();
  421. $data['userInfo']['uid'] = $user['uid'];
  422. $data['userInfo']['nickname'] = $user['nickname'];
  423. $data['userInfo']['avatar'] = $user['avatar'];
  424. /** @var StoreProductAttrServices $storeProductAttrServices */
  425. $storeProductAttrServices = app()->make(StoreProductAttrServices::class);
  426. list($productAttr, $productValue) = $storeProductAttrServices->getProductAttrDetail($id, $user->uid, 0, 2, $bargain['product_id']);
  427. foreach ($productValue as $v) {
  428. $bargain['attr'] = $v;
  429. }
  430. $data['bargain'] = get_thumb_water($bargain);
  431. $bargainNew = get_thumb_water($bargain, 'small');
  432. $data['bargain']['small_image'] = $bargainNew['image'];
  433. /** @var StoreOrderServices $orderService */
  434. $orderService = app()->make(StoreOrderServices::class);
  435. $data['bargainSumCount'] = $orderService->count(['bargain_id' => $id, 'uid' => $user['uid']]);
  436. /** @var StoreBargainUserServices $bargainUserService */
  437. $bargainUserService = app()->make(StoreBargainUserServices::class);
  438. $data['userBargainStatus'] = $bargainUserService->count(['bargain_id' => $id, 'uid' => $user->uid, 'is_del' => 0]);
  439. //用户访问事件
  440. event('user.userVisit', [$user['uid'], $id, 'bargain', $bargain['product_id'], 'view']);
  441. //浏览记录
  442. ProductLogJob::dispatch(['visit', ['uid' => $user['uid'], 'product_id' => $bargain['product_id']]]);
  443. return $data;
  444. }
  445. /**
  446. * 验证砍价是否能支付
  447. * @param int $bargainId
  448. * @param int $uid
  449. */
  450. public function checkBargainUser(int $bargainId, int $uid)
  451. {
  452. /** @var StoreBargainUserServices $bargainUserServices */
  453. $bargainUserServices = app()->make(StoreBargainUserServices::class);
  454. $bargainUserInfo = $bargainUserServices->getOne(['uid' => $uid, 'bargain_id' => $bargainId, 'status' => 1, 'is_del' => 0]);
  455. if (!$bargainUserInfo)
  456. throw new ValidateException('砍价失败');
  457. $bargainUserTableId = $bargainUserInfo['id'];
  458. if ($bargainUserInfo['bargain_price_min'] < bcsub((string)$bargainUserInfo['bargain_price'], (string)$bargainUserInfo['price'], 2)) {
  459. throw new ValidateException('砍价未成功');
  460. }
  461. if ($bargainUserInfo['status'] == 3)
  462. throw new ValidateException('砍价已支付');
  463. /** @var StoreBargainServices $bargainService */
  464. $bargainService = app()->make(StoreBargainServices::class);
  465. /** @var StoreProductAttrValueServices $attrValueServices */
  466. $attrValueServices = app()->make(StoreProductAttrValueServices::class);
  467. $res = $attrValueServices->getOne(['product_id' => $bargainId, 'type' => 2]);
  468. if (!$bargainService->validBargain($bargainId) || !$res) {
  469. throw new ValidateException('该商品已下架或删除');
  470. }
  471. $StoreBargainInfo = $bargainService->get($bargainId);
  472. if (1 > $res['quota']) {
  473. throw new ValidateException('该商品库存不足');
  474. }
  475. $product_stock = $attrValueServices->value(['product_id' => $StoreBargainInfo['product_id'], 'suk' => $res['suk'], 'type' => 0], 'stock');
  476. if ($product_stock < 1) {
  477. throw new ValidateException('该商品库存不足');
  478. }
  479. //修改砍价状态
  480. $this->setBargainUserStatus($bargainId, $uid, $bargainUserTableId);
  481. return true;
  482. }
  483. /**
  484. * 修改砍价状态
  485. * @param int $bargainId
  486. * @param int $uid
  487. * @param int $bargainUserTableId
  488. * @return bool|\crmeb\basic\BaseModel
  489. */
  490. public function setBargainUserStatus(int $bargainId, int $uid, int $bargainUserTableId)
  491. {
  492. if (!$bargainId || !$uid) return false;
  493. if (!$bargainUserTableId) return false;
  494. /** @var StoreBargainUserServices $bargainUserServices */
  495. $bargainUserServices = app()->make(StoreBargainUserServices::class);
  496. $count = $bargainUserServices->count(['id' => $bargainUserTableId, 'uid' => $uid, 'bargain_id' => $bargainId, 'status' => 1]);
  497. if (!$count) return false;
  498. $userPrice = $bargainUserServices->value(['id' => $bargainUserTableId, 'uid' => $uid, 'bargain_id' => $bargainId, 'status' => 1], 'price');
  499. $price = $bargainUserServices->get($bargainUserTableId, ['bargain_price', 'bargain_price_min']);
  500. $price = bcsub($price['bargain_price'], $price['bargain_price_min'], 2);
  501. if (bcsub($price, $userPrice, 2) > 0) {
  502. return false;
  503. }
  504. return $bargainUserServices->updateBargainStatus($bargainUserTableId);
  505. }
  506. /**
  507. * 参与砍价
  508. * @param int $uid
  509. * @param int $bargainId
  510. * @return string
  511. * @throws \think\db\exception\DataNotFoundException
  512. * @throws \think\db\exception\DbException
  513. * @throws \think\db\exception\ModelNotFoundException
  514. */
  515. public function setBargain(int $uid, int $bargainId)
  516. {
  517. if (!$bargainId) throw new ValidateException('参数错误');
  518. $bargainInfo = $this->dao->getOne([
  519. ['is_del', '=', 0],
  520. ['status', '=', 1],
  521. ['start_time', '<', time()],
  522. ['stop_time', '>', time()],
  523. ['id', '=', $bargainId],
  524. ]);
  525. if (!$bargainInfo) throw new ValidateException('砍价已结束');
  526. $bargainInfo = $bargainInfo->toArray();
  527. /** @var StoreBargainUserServices $bargainUserService */
  528. $bargainUserService = app()->make(StoreBargainUserServices::class);
  529. $count = $bargainUserService->count(['bargain_id' => $bargainId, 'uid' => $uid, 'is_del' => 0, 'status' => 1]);
  530. if ((int)sys_config('bargain_subscribe')) {
  531. /** @var WechatServices $wechat */
  532. $wechat = app()->make(WechatServices::class);
  533. $subscribe = $wechat->get(['uid' => $uid, 'subscribe' => 1]);
  534. if (!$subscribe) return 'subscribe';
  535. }
  536. if ($count === false) {
  537. throw new ValidateException('参数错误');
  538. } elseif ($count) {
  539. return 'SUCCESSFUL';
  540. } else {
  541. $count = $bargainUserService->count(['uid' => $uid, 'bargain_id' => $bargainId, 'type' => 1]);
  542. if ($count >= $bargainInfo['num']) throw new ValidateException('您不能再发起此件商品砍价');
  543. $res = $bargainUserService->setBargain($bargainId, $uid, $bargainInfo);
  544. }
  545. if (!$res) {
  546. throw new ValidateException('参与失败');
  547. } else {
  548. return 'SUCCESS';
  549. }
  550. }
  551. /**
  552. * @param Request $request
  553. * @param int $bargainId
  554. * @param int $bargainUserUid
  555. * @return string
  556. * @throws \think\Exception
  557. * @throws \think\db\exception\DataNotFoundException
  558. * @throws \think\db\exception\ModelNotFoundException
  559. */
  560. public function setHelpBargain(int $uid, int $bargainId, int $bargainUserUid)
  561. {
  562. if (!$bargainId || !$bargainUserUid) throw new ValidateException('参数错误');
  563. $bargainInfo = $this->dao->getOne([
  564. ['is_del', '=', 0],
  565. ['status', '=', 1],
  566. ['start_time', '<', time()],
  567. ['stop_time', '>', time()],
  568. ['id', '=', $bargainId],
  569. ]);
  570. if (!$bargainInfo) throw new ValidateException('砍价已结束');
  571. if ((int)sys_config('bargain_subscribe')) {
  572. /** @var WechatServices $wechat */
  573. $wechat = app()->make(WechatServices::class);
  574. $subscribe = $wechat->get(['uid' => $uid, 'subscribe' => 1]);
  575. if (!$subscribe) return 'subscribe';
  576. }
  577. /** @var StoreBargainUserHelpServices $userHelpService */
  578. $userHelpService = app()->make(StoreBargainUserHelpServices::class);
  579. /** @var StoreBargainUserServices $bargainUserService */
  580. $bargainUserService = app()->make(StoreBargainUserServices::class);
  581. $bargainUserTableId = $bargainUserService->getBargainUserTableId($bargainId, $bargainUserUid);
  582. if (!$bargainUserTableId) throw new ValidateException('该分享未开启砍价');
  583. $count = $userHelpService->isBargainUserHelpCount($bargainId, $bargainUserTableId, $uid);
  584. if (!$count) return 'SUCCESSFUL';
  585. $res = $userHelpService->setBargainUserHelp($bargainId, $bargainUserTableId, $uid);
  586. if ($res) {
  587. if (!$bargainUserService->getSurplusPrice($bargainUserTableId, 1)) {
  588. $bargainInfo = $this->dao->get($bargainId);//TODO 获取砍价商品信息
  589. $bargainUserInfo = $bargainUserService->get($bargainUserTableId);// TODO 获取用户参与砍价信息
  590. //用户发送消息
  591. event('notice.notice', [['uid' => $bargainUserUid, 'bargainInfo' => $bargainInfo, 'bargainUserInfo' => $bargainUserInfo,], 'bargain_success']);
  592. }
  593. return 'SUCCESS';
  594. } else throw new ValidateException('砍价失败');
  595. }
  596. /**
  597. * 减库存加销量
  598. * @param int $num
  599. * @param int $bargainId
  600. * @param string $unique
  601. * @return bool
  602. */
  603. public function decBargainStock(int $num, int $bargainId, string $unique)
  604. {
  605. $product_id = $this->dao->value(['id' => $bargainId], 'product_id');
  606. if ($unique) {
  607. /** @var StoreProductAttrValueServices $skuValueServices */
  608. $skuValueServices = app()->make(StoreProductAttrValueServices::class);
  609. //减去砍价商品sku的库存增加销量
  610. $res = false !== $skuValueServices->decProductAttrStock($bargainId, $unique, $num, 2);
  611. //减去砍价商品的库存和销量
  612. $res = $res && $this->dao->decStockIncSales(['id' => $bargainId, 'type' => 2], $num);
  613. //减掉普通商品sku的库存加销量
  614. $suk = $skuValueServices->value(['unique' => $unique, 'product_id' => $bargainId], 'suk');
  615. $productUnique = $skuValueServices->value(['suk' => $suk, 'product_id' => $product_id, 'type' => 0], 'unique');
  616. if ($productUnique) {
  617. $res = $res && $skuValueServices->decProductAttrStock($product_id, $productUnique, $num);
  618. }
  619. } else {
  620. //减去砍价商品的库存和销量
  621. $res = false !== $this->dao->decStockIncSales(['id' => $bargainId, 'type' => 2], $num);
  622. }
  623. /** @var StoreProductServices $services */
  624. $services = app()->make(StoreProductServices::class);
  625. //减掉普通商品的库存加销量
  626. $res = $res && $services->decProductStock($num, $product_id);
  627. return $res;
  628. }
  629. /**
  630. * 减销量加库存
  631. * @param int $num
  632. * @param int $bargainId
  633. * @param string $unique
  634. * @return bool
  635. */
  636. public function incBargainStock(int $num, int $bargainId, string $unique)
  637. {
  638. $product_id = $this->dao->value(['id' => $bargainId], 'product_id');
  639. if ($unique) {
  640. /** @var StoreProductAttrValueServices $skuValueServices */
  641. $skuValueServices = app()->make(StoreProductAttrValueServices::class);
  642. //减去砍价商品sku的销量,增加库存和限购数量
  643. $res = false !== $skuValueServices->incProductAttrStock($bargainId, $unique, $num, 2);
  644. //减去砍价商品的销量,增加库存
  645. $res = $res && $this->dao->incStockDecSales(['id' => $bargainId, 'type' => 2], $num);
  646. //减掉普通商品sku的销量,增加库存
  647. $suk = $skuValueServices->value(['unique' => $unique, 'product_id' => $bargainId], 'suk');
  648. $productUnique = $skuValueServices->value(['suk' => $suk, 'product_id' => $product_id], 'unique');
  649. if ($productUnique) {
  650. $res = $res && $skuValueServices->incProductAttrStock($product_id, $productUnique, $num);
  651. }
  652. } else {
  653. //减去砍价商品的销量,增加库存
  654. $res = false !== $this->dao->incStockDecSales(['id' => $bargainId, 'type' => 2], $num);
  655. }
  656. /** @var StoreProductServices $services */
  657. $services = app()->make(StoreProductServices::class);
  658. //减掉普通商品的库存加销量
  659. $res = $res && $services->incProductStock($num, $product_id);
  660. return $res;
  661. }
  662. /**
  663. * @param $bargainId
  664. * @param $user
  665. * @return bool|string
  666. * @throws \think\db\exception\DataNotFoundException
  667. * @throws \think\db\exception\DbException
  668. * @throws \think\db\exception\ModelNotFoundException
  669. */
  670. public function poster($bargainId, $user, $from)
  671. {
  672. $storeBargainInfo = $this->dao->get($bargainId, ['title', 'image', 'price']);
  673. if (!$storeBargainInfo) {
  674. throw new ValidateException('砍价信息没有查到');
  675. }
  676. /** @var StoreBargainUserServices $services */
  677. $services = app()->make(StoreBargainUserServices::class);
  678. $bargainUser = $services->get(['bargain_id' => $bargainId, 'uid' => $user['uid']], ['price', 'bargain_price_min']);
  679. if (!$bargainUser) {
  680. throw new ValidateException('用户砍价信息未查到');
  681. }
  682. try {
  683. $siteUrl = sys_config('site_url');
  684. $data['title'] = $storeBargainInfo['title'];
  685. $data['image'] = $storeBargainInfo['image'];
  686. $data['price'] = bcsub($storeBargainInfo['price'], $bargainUser['price'], 2);
  687. $data['label'] = '已砍至';
  688. $price = bcsub($storeBargainInfo['price'], $bargainUser['price'], 2);
  689. $data['msg'] = '还差' . (bcsub($price, $bargainUser['bargain_price_min'], 2)) . '元即可砍价成功';
  690. /** @var SystemAttachmentServices $systemAttachmentServices */
  691. $systemAttachmentServices = app()->make(SystemAttachmentServices::class);
  692. if ($from == 'wechat') {
  693. $name = $bargainId . '_' . $user['uid'] . '_' . $user['is_promoter'] . '_bargain_share_wap.jpg';
  694. //公众号
  695. $imageInfo = $systemAttachmentServices->getInfo(['name' => $name]);
  696. if (!$imageInfo) {
  697. $codeUrl = set_http_type($siteUrl . '/pages/activity/goods_bargain_details/index?id=' . $bargainId . '&bargain=' . $user['uid'] . '&spread=' . $user['uid'], 1);//二维码链接
  698. $imageInfo = UtilService::getQRCodePath($codeUrl, $name);
  699. if (is_string($imageInfo)) {
  700. throw new ValidateException('二维码生成失败');
  701. }
  702. $systemAttachmentServices->save([
  703. 'name' => $imageInfo['name'],
  704. 'att_dir' => $imageInfo['dir'],
  705. 'satt_dir' => $imageInfo['thumb_path'],
  706. 'att_size' => $imageInfo['size'],
  707. 'att_type' => $imageInfo['type'],
  708. 'image_type' => $imageInfo['image_type'],
  709. 'module_type' => 2,
  710. 'time' => $imageInfo['time'],
  711. 'pid' => 1,
  712. 'type' => 1
  713. ]);
  714. $url = $imageInfo['dir'];
  715. } else $url = $imageInfo['att_dir'];
  716. $data['url'] = $url;
  717. if ($imageInfo['image_type'] == 1) $data['url'] = $siteUrl . $url;
  718. $posterImage = UtilService::setShareMarketingPoster($data, 'wap/activity/bargain/poster');
  719. if (!is_array($posterImage)) {
  720. throw new ValidateException('海报生成失败');
  721. }
  722. $systemAttachmentServices->save([
  723. 'name' => $posterImage['name'],
  724. 'att_dir' => $posterImage['dir'],
  725. 'satt_dir' => $posterImage['thumb_path'],
  726. 'att_size' => $posterImage['size'],
  727. 'att_type' => $posterImage['type'],
  728. 'image_type' => $posterImage['image_type'],
  729. 'module_type' => 2,
  730. 'time' => $posterImage['time'],
  731. 'pid' => 1,
  732. 'type' => 1
  733. ]);
  734. if ($posterImage['image_type'] == 1) $posterImage['dir'] = $siteUrl . $posterImage['dir'];
  735. $wapPosterImage = set_http_type($posterImage['dir'], 1);//公众号推广海报
  736. return $wapPosterImage;
  737. } else {
  738. //小程序
  739. $name = $bargainId . '_' . $user['uid'] . '_' . $user['is_promoter'] . '_bargain_share_routine.jpg';
  740. $imageInfo = $systemAttachmentServices->getInfo(['name' => $name]);
  741. if (!$imageInfo) {
  742. $valueData = 'id=' . $bargainId . '&bargain=' . $user['uid'];
  743. /** @var UserServices $userServices */
  744. $userServices = app()->make(UserServices::class);
  745. if ($userServices->checkUserPromoter((int)$user['uid'], $user)) {
  746. $valueData .= '&spread=' . $user['uid'];
  747. }
  748. $res = MiniProgramService::qrcodeService()->appCodeUnlimit($valueData, 'pages/activity/goods_bargain_details/index', 280);
  749. if (!$res) throw new ValidateException('二维码生成失败');
  750. $uploadType = (int)sys_config('upload_type', 1);
  751. $upload = UploadService::init();
  752. $res = (string)EntityBody::factory($res);
  753. $res = $upload->to('routine/activity/bargain/code')->validate()->setAuthThumb(false)->stream($res, $name);
  754. if ($res === false) {
  755. throw new ValidateException($upload->getError());
  756. }
  757. $imageInfo = $upload->getUploadInfo();
  758. $imageInfo['image_type'] = $uploadType;
  759. if ($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl . $imageInfo['dir']);
  760. else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
  761. if (!$remoteImage['status']) throw new ValidateException($remoteImage['msg']);
  762. $systemAttachmentServices->save([
  763. 'name' => $imageInfo['name'],
  764. 'att_dir' => $imageInfo['dir'],
  765. 'satt_dir' => $imageInfo['thumb_path'],
  766. 'att_size' => $imageInfo['size'],
  767. 'att_type' => $imageInfo['type'],
  768. 'image_type' => $imageInfo['image_type'],
  769. 'module_type' => 2,
  770. 'time' => time(),
  771. 'pid' => 1,
  772. 'type' => 1
  773. ]);
  774. $url = $imageInfo['dir'];
  775. } else $url = $imageInfo['att_dir'];
  776. $data['url'] = $url;
  777. if ($imageInfo['image_type'] == 1)
  778. $data['url'] = $siteUrl . $url;
  779. $posterImage = UtilService::setShareMarketingPoster($data, 'routine/activity/bargain/poster');
  780. if (!is_array($posterImage)) throw new ValidateException('海报生成失败');
  781. $systemAttachmentServices->save([
  782. 'name' => $posterImage['name'],
  783. 'att_dir' => $posterImage['dir'],
  784. 'satt_dir' => $posterImage['thumb_path'],
  785. 'att_size' => $posterImage['size'],
  786. 'att_type' => $posterImage['type'],
  787. 'image_type' => $posterImage['image_type'],
  788. 'module_type' => 2,
  789. 'time' => $posterImage['time'],
  790. 'pid' => 1,
  791. 'type' => 1
  792. ]);
  793. if ($posterImage['image_type'] == 1) $posterImage['dir'] = $siteUrl . $posterImage['dir'];
  794. $routinePosterImage = set_http_type($posterImage['dir'], 0);//小程序推广海报
  795. return $routinePosterImage;
  796. }
  797. } catch (\Exception $e) {
  798. return false;
  799. }
  800. }
  801. /**
  802. * 获取砍价海报信息
  803. * @param int $bargainId
  804. * @param $user
  805. * @throws \think\db\exception\DataNotFoundException
  806. * @throws \think\db\exception\DbException
  807. * @throws \think\db\exception\ModelNotFoundException
  808. */
  809. public function posterInfo(int $bargainId, $user)
  810. {
  811. $storeBargainInfo = $this->dao->get($bargainId, ['title', 'image', 'price']);
  812. if (!$storeBargainInfo) {
  813. throw new ValidateException('砍价信息没有查到');
  814. }
  815. /** @var StoreBargainUserServices $services */
  816. $services = app()->make(StoreBargainUserServices::class);
  817. $bargainUser = $services->get(['bargain_id' => $bargainId, 'uid' => $user['uid']], ['price', 'bargain_price_min']);
  818. if (!$bargainUser) {
  819. throw new ValidateException('用户砍价信息未查到');
  820. }
  821. $data['url'] = '';
  822. $data['title'] = $storeBargainInfo['title'];
  823. $data['image'] = $storeBargainInfo['image'];
  824. $data['price'] = bcsub($storeBargainInfo['price'], $bargainUser['price'], 2);
  825. $data['label'] = '已砍至';
  826. $price = bcsub($storeBargainInfo['price'], $bargainUser['price'], 2);
  827. $data['msg'] = '还差' . (bcsub($price, $bargainUser['bargain_price_min'], 2)) . '元即可砍价成功';
  828. //只有在小程序端,才会生成二维码
  829. if (\request()->isRoutine()) {
  830. try {
  831. /** @var SystemAttachmentServices $systemAttachmentServices */
  832. $systemAttachmentServices = app()->make(SystemAttachmentServices::class);
  833. //小程序
  834. $name = $bargainId . '_' . $user['uid'] . '_' . $user['is_promoter'] . '_bargain_share_routine.jpg';
  835. $siteUrl = sys_config('site_url');
  836. $imageInfo = $systemAttachmentServices->getInfo(['name' => $name]);
  837. if (!$imageInfo) {
  838. $valueData = 'id=' . $bargainId . '&bargain=' . $user['uid'];
  839. /** @var UserServices $userServices */
  840. $userServices = app()->make(UserServices::class);
  841. if ($userServices->checkUserPromoter((int)$user['uid'], $user)) {
  842. $valueData .= '&spread=' . $user['uid'];
  843. }
  844. $res = MiniProgramService::qrcodeService()->appCodeUnlimit($valueData, 'pages/activity/goods_bargain_details/index', 280);
  845. if (!$res) throw new ValidateException('二维码生成失败');
  846. $uploadType = (int)sys_config('upload_type', 1);
  847. $upload = UploadService::init();
  848. $res = (string)EntityBody::factory($res);
  849. $res = $upload->to('routine/activity/bargain/code')->validate()->setAuthThumb(false)->stream($res, $name);
  850. if ($res === false) {
  851. throw new ValidateException($upload->getError());
  852. }
  853. $imageInfo = $upload->getUploadInfo();
  854. $imageInfo['image_type'] = $uploadType;
  855. if ($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl . $imageInfo['dir']);
  856. else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
  857. if (!$remoteImage['status']) throw new ValidateException($remoteImage['msg']);
  858. $systemAttachmentServices->save([
  859. 'name' => $imageInfo['name'],
  860. 'att_dir' => $imageInfo['dir'],
  861. 'satt_dir' => $imageInfo['thumb_path'],
  862. 'att_size' => $imageInfo['size'],
  863. 'att_type' => $imageInfo['type'],
  864. 'image_type' => $imageInfo['image_type'],
  865. 'module_type' => 2,
  866. 'time' => time(),
  867. 'pid' => 1,
  868. 'type' => 1
  869. ]);
  870. $url = $imageInfo['dir'];
  871. } else $url = $imageInfo['att_dir'];
  872. if ($imageInfo['image_type'] == 1) {
  873. $data['url'] = $siteUrl . $url;
  874. } else {
  875. $data['url'] = $url;
  876. }
  877. } catch (\Throwable $e) {
  878. }
  879. }
  880. return $data;
  881. }
  882. /**
  883. * 验证砍价下单库存限量
  884. * @param int $uid
  885. * @param int $bargainId
  886. * @param int $cartNum
  887. * @param string $unique
  888. * @return array
  889. * @throws \think\db\exception\DataNotFoundException
  890. * @throws \think\db\exception\DbException
  891. * @throws \think\db\exception\ModelNotFoundException
  892. */
  893. public function checkBargainStock(int $uid, int $bargainId, int $cartNum = 1, string $unique = '')
  894. {
  895. if (!$this->validBargain($bargainId)) {
  896. throw new ValidateException('该商品已下架或删除');
  897. }
  898. /** @var StoreProductAttrValueServices $attrValueServices */
  899. $attrValueServices = app()->make(StoreProductAttrValueServices::class);
  900. $attrInfo = $attrValueServices->getOne(['product_id' => $bargainId, 'type' => 2]);
  901. if (!$attrInfo || $attrInfo['product_id'] != $bargainId) {
  902. throw new ValidateException('请选择有效的商品属性');
  903. }
  904. $productInfo = $this->dao->get($bargainId, ['*', 'title as store_name']);
  905. /** @var StoreBargainUserServices $bargainUserService */
  906. $bargainUserService = app()->make(StoreBargainUserServices::class);
  907. $bargainUserInfo = $bargainUserService->getOne(['uid' => $uid, 'bargain_id' => $bargainId, 'status' => 1, 'is_del' => 0]);
  908. if ($bargainUserInfo['bargain_price_min'] < bcsub((string)$bargainUserInfo['bargain_price'], (string)$bargainUserInfo['price'], 2)) {
  909. throw new ValidateException('砍价未成功');
  910. }
  911. $unique = $attrInfo['unique'];
  912. if ($cartNum > $attrInfo['quota']) {
  913. throw new ValidateException('该商品库存不足' . $cartNum);
  914. }
  915. return [$attrInfo, $unique, $productInfo, $bargainUserInfo];
  916. }
  917. }