DiyGoods.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1\diy;
  8. use app\models\BargainGoods;
  9. use app\models\Cat;
  10. use app\models\common\CommonGoods;
  11. use app\models\Goods;
  12. use app\models\GoodsCat;
  13. use app\models\Mch;
  14. use app\models\Shop;
  15. use app\models\Topic;
  16. use yii\data\Pagination;
  17. use yii\db\ActiveQuery;
  18. use yii\helpers\ArrayHelper;
  19. /**
  20. * @property Store $store
  21. */
  22. class DiyGoods
  23. {
  24. public $store;
  25. public $store_id;
  26. public $type;
  27. public $cat;
  28. public $page;
  29. public $limit = 8;
  30. public $idList;
  31. public $is_page = false;
  32. public $mch;
  33. public $keyword;
  34. // 初始化模板信息
  35. public static function getTemplate(&$template)
  36. {
  37. // 获取需要查找的id
  38. $list = [
  39. 'goods' => [
  40. 'id_list' => [],
  41. 'list' => []
  42. ],
  43. 'miaosha' => [
  44. 'id_list' => [],
  45. 'list' => []
  46. ],
  47. 'pintuan' => [
  48. 'id_list' => [],
  49. 'list' => []
  50. ],
  51. 'bargain' => [
  52. 'id_list' => [],
  53. 'list' => []
  54. ],
  55. 'book' => [
  56. 'id_list' => [],
  57. 'list' => []
  58. ],
  59. 'shop' => [
  60. 'id_list' => [],
  61. 'list' => []
  62. ],
  63. 'lottery' => [
  64. 'id_list' => [],
  65. 'list' => []
  66. ],
  67. 'mch' => [
  68. 'id_list' => [],
  69. 'list' => []
  70. ],
  71. 'integral' => [
  72. 'id_list' => [],
  73. 'list' => []
  74. ],
  75. 'topic' => [
  76. 'id_list' => [],
  77. 'list' => []
  78. ],
  79. ];
  80. foreach ($template as $value) {
  81. if (array_key_exists($value['type'], $list) && $value['param']['list']) {
  82. $type = $value['type'];
  83. if($type == 'shop') {
  84. foreach ($value['param']['list'] as $item) {
  85. if (!in_array($item['id'], $list[$type]['id_list'])) {
  86. $list[$type]['id_list'][] = $item['id'];
  87. }
  88. }
  89. } else if($type == 'mch') {
  90. foreach ($value['param']['list'] as $item) {
  91. if (!in_array($item['id'], $list[$type]['id_list'])) {
  92. $list[$type]['id_list'][] = $item['id'];
  93. }
  94. if ($item['goods_style'] == 2) {
  95. foreach ($item['goods_list'] as $v) {
  96. if (!in_array($v['id'], $list['goods']['id_list'])) {
  97. $list['goods']['id_list'][] = $v['id'];
  98. }
  99. }
  100. }
  101. }
  102. } else {
  103. foreach ($value['param']['list'] as $item) {
  104. if ($item['goods_style'] == 2) {
  105. foreach ($item['goods_list'] as $v) {
  106. if (!in_array($v['id'], $list[$type]['id_list'])) {
  107. $list[$type]['id_list'][] = $v['id'];
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. $ok = false;
  116. foreach ($list as $key => $value) {
  117. if(!empty($value['id_list'])) {
  118. $res = DiyGoods::getGoods($key, $value['id_list']);
  119. $list[$key]['list'] = $res['goods_list'];
  120. $ok = true;
  121. } else {
  122. $list[$key]['list'] = [];
  123. }
  124. }
  125. if ($ok) {
  126. foreach ($template as &$value) {
  127. if (array_key_exists($value['type'], $list) && $value['param']['list']) {
  128. foreach ($value['param']['list'] as &$item) {
  129. if($value['type'] == 'shop') {
  130. if(is_array($list[$value['type']]['list'])) {
  131. foreach ($list[$value['type']]['list'] as $goods) {
  132. if ($goods['id'] == $item['id']) {
  133. $item = $goods;
  134. break;
  135. }
  136. }
  137. }
  138. } else if($value['type'] == 'mch') {
  139. if(is_array($list[$value['type']]['list'])) {
  140. foreach ($list[$value['type']]['list'] as $mch) {
  141. if ($mch['id'] == $item['id']) {
  142. $item['name'] = $mch['name'];
  143. $item['pic_url'] = $mch['pic_url'];
  144. $item['logo'] = $mch['pic_url'];
  145. $item['goods_count'] = $mch['goods_count'];
  146. break;
  147. }
  148. }
  149. }
  150. if ($item['goods_style'] == 2) {
  151. foreach ($item['goods_list'] as &$v) {
  152. if(is_array($list['goods']['list'])){
  153. foreach ($list['goods']['list'] as $goods) {
  154. if ($goods['id'] == $v['id']) {
  155. $v = $goods;
  156. break;
  157. }
  158. }
  159. }
  160. }
  161. unset($v);
  162. // $item['goods_list'] = $list['goods']['list'];
  163. }
  164. } else {
  165. if ($item['goods_style'] == 2) {
  166. $newList = [];
  167. foreach ($item['goods_list'] as $v) {
  168. if(is_array($list[$value['type']]['list'])){
  169. foreach ($list[$value['type']]['list'] as $goods) {
  170. if ($goods['id'] == $v['id']) {
  171. $newList[] = $goods;
  172. break;
  173. }
  174. }
  175. }
  176. }
  177. $item['goods_list'] = $newList;
  178. }
  179. }
  180. }
  181. unset($item);
  182. }
  183. }
  184. unset($value);
  185. }
  186. }
  187. // 获取详情(商城、秒杀、拼团、砍价、积分商城、多商户等)
  188. public static function getGoods($type, $idList = [] , $cat = 0, $limit = 8, $isPage = false, $page = 1, $mch = false)
  189. {
  190. $form = new DiyGoods();
  191. $form->type = $type;
  192. $form->idList = $idList;
  193. $form->cat = $cat;
  194. $form->limit = $limit;
  195. $form->is_page = $isPage;
  196. $form->page = $page;
  197. $form->mch = $mch;
  198. $form->keyword = \Yii::$app->request->get('keyword');
  199. $form->store_id = get_store_id();
  200. $res = $form->getDetail();
  201. return $res;
  202. }
  203. // 获取具体信息
  204. public function getDetail()
  205. {
  206. $res = [];
  207. $type = $this->type;
  208. if (method_exists($this, $type)) {
  209. $res = $this->$type();
  210. }
  211. return $res;
  212. }
  213. private function goods()
  214. {
  215. $query = Goods::find()->alias('g')
  216. ->where(['g.store_id' => get_store_id(), 'g.is_delete' => 0, 'g.type' => 0, 'g.status' => 1]);
  217. if ($this->cat != 0) {
  218. $cat_arr = Cat::getCatId($this->cat);
  219. $query->leftJoin(['gc' => GoodsCat::tableName()], 'gc.goods_id=g.id')
  220. ->andWhere(['gc.is_delete' => 0, 'gc.store_id' => get_store_id(), 'gc.cat_id' => $cat_arr])
  221. ->groupBy('g.id')->orderBy(['g.sort' => SORT_DESC, 'g.created_at' => SORT_DESC]);
  222. }
  223. if($this->mch) {
  224. $query->andWhere(['g.mch_id' => $this->mch]);
  225. }
  226. if($this->keyword) {
  227. $query->andWhere(['like', 'g.name', $this->keyword]);
  228. }
  229. if($this->idList) {
  230. $query->andWhere(['g.id' => $this->idList]);
  231. }
  232. $count = $query->count();
  233. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  234. if($this->is_page) {
  235. $query->limit($pagination->limit)->offset($pagination->offset);
  236. }
  237. $list = $query->orderBy(['g.sort' => SORT_DESC, 'g.id' => SORT_DESC])->all();
  238. $goodsList = [];
  239. /* @var Goods[] $list */
  240. foreach ($list as $key => $item) {
  241. $attrGroupList = json_decode(json_encode($item->getAttrGroupList()), true);
  242. $price = round($item->price, 2);
  243. // $res = CommonGoods::getMemberPrice([
  244. // 'attr' => $item['attr'],
  245. // 'price' => $item['price'],
  246. // 'mch_id' => $item['mch_id'],
  247. // 'is_level' => $item['is_level'],
  248. // ]);
  249. //
  250. // $goodsMemberPrice = $res['min_member_price'] ? $res['min_member_price'] : $item['price'];
  251. $goodsMemberPrice = 0;
  252. $goodsList[] = [
  253. 'attr' => json_decode($item['attr'], true),
  254. 'attr_group_list' => $attrGroupList,
  255. 'id' => $item->id,
  256. 'goods_id' => $item->id,
  257. 'pic_url' => $item->cover_pic,
  258. 'cover_pic' => $item->cover_pic,
  259. 'price' => $price ? $price : 0,
  260. 'original_price' => $item->original_price,
  261. 'verify_card_id' => $item->verify_card_id,
  262. 'name' => $item->name,
  263. 'page_url' => '/goods/goods/goods?id=' . $item->id,
  264. 'use_attr' => $item->use_attr,
  265. 'is_negotiable' => $item->is_negotiable,
  266. 'price_content' => $item->is_negotiable == 0 ? '¥'.$price : '价格面议',
  267. 'goods_member_price' => round($goodsMemberPrice,2),
  268. 'num' => $item->getNum()
  269. ];
  270. }
  271. return [
  272. 'goods_list' => $goodsList,
  273. 'pagination' => $pagination
  274. ];
  275. }
  276. private function miaosha()
  277. {
  278. $date = date('Y-m-d', time());
  279. $time = date('H', time());
  280. $query = MiaoshaGoods::find()->alias('mg')->where([
  281. 'mg.store_id' => get_store_id(), 'mg.is_delete' => 0
  282. ])->joinWith('msGoods g')->andWhere(['g.is_delete' => 0]);
  283. if($this->keyword) {
  284. $query->andWhere(['like', 'g.name', $this->keyword]);
  285. }
  286. if($this->idList) {
  287. $query->andWhere(['mg.id' => $this->idList]);
  288. } else {
  289. $query->andWhere([
  290. 'or',
  291. [
  292. 'and',
  293. ['mg.open_date' => $date],
  294. ['>=', 'mg.start_time', $time]
  295. ],
  296. [
  297. 'and',
  298. ['>', 'mg.open_date', $date],
  299. ]
  300. ]);
  301. }
  302. $count = $query->count();
  303. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  304. if($this->is_page) {
  305. $query->limit($pagination->limit)->offset($pagination->offset);
  306. }
  307. $list = $query->all();
  308. $goodsList = [];
  309. /* @var MiaoshaGoods[] $list */
  310. foreach ($list as $key => $item) {
  311. /* @var MsGoods $msGoods */
  312. $msGoods = $item->msGoods;
  313. $price = $msGoods->original_price;
  314. $attr = json_decode($item['attr'], true);
  315. foreach ($attr as &$value) {
  316. $value['num'] = $value['miaosh_num'];
  317. $value['price'] = $value['miaosh_price'];
  318. if ($price == 0 || ($price > 0 && round($price, 2) >= round($value['miaosha_price'], 2))) {
  319. $price = $value['miaosha_price'];
  320. }
  321. }
  322. unset($value);
  323. $goodsList[] = [
  324. 'attr' => $attr,
  325. 'attr_group' => json_decode(json_encode($msGoods->getAttrGroupList()), true),
  326. 'id' => $item->id,
  327. 'goods_id' => $msGoods->id,
  328. 'pic_url' => $msGoods->cover_pic,
  329. 'cover_pic' => $msGoods->cover_pic,
  330. 'price' => round($price, 2) ? round($price, 2) : 0,
  331. 'original_price' => $msGoods->original_price,
  332. 'name' => $msGoods->name,
  333. 'page_url' => '/pages/miaosha/details/details?id=' . $item->id,
  334. 'use_attr' => $msGoods->use_attr,
  335. 'open_date' => $item->open_date,
  336. 'start_time' => $item->start_time,
  337. 'is_negotiable' => 0,
  338. 'price_content' => '秒杀价:',
  339. 'original_price_content' => '售价:',
  340. ];
  341. }
  342. return [
  343. 'goods_list' => $goodsList,
  344. 'pagination' => $pagination
  345. ];
  346. }
  347. private function pintuan()
  348. {
  349. $query = PtGoods::find()->where([
  350. 'store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1
  351. ])->orderBy(['is_hot' => SORT_DESC, 'addtime' => SORT_DESC]);
  352. if($this->keyword) {
  353. $query->andWhere(['like', 'name', $this->keyword]);
  354. }
  355. if($this->idList) {
  356. $query->andWhere(['id' => $this->idList]);
  357. }
  358. $count = $query->count();
  359. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  360. if($this->is_page) {
  361. $query->limit($pagination->limit)->offset($pagination->offset);
  362. }
  363. $list = $query->all();
  364. $goodsList = [];
  365. /* @var PtGoods[] $list */
  366. foreach ($list as $key => $item) {
  367. $attr = json_decode($item['attr'], true);
  368. $goodsList[] = [
  369. 'attr' => $attr,
  370. 'attr_group' => json_decode(json_encode($item->getAttrGroupList()), true),
  371. 'id' => $item->id,
  372. 'goods_id' => $item->id,
  373. 'pic_url' => $item->cover_pic,
  374. 'cover_pic' => $item->cover_pic,
  375. 'price' => round($item->price, 2) ? round($item->price, 2) : 0,
  376. 'original_price' => $item->original_price,
  377. 'name' => $item->name,
  378. 'page_url' => '/pages/pt/details/details?gid=' . $item->id,
  379. 'use_attr' => $item->use_attr,
  380. 'is_negotiable' => 0,
  381. 'price_content' => $item->group_num . '人团',
  382. 'original_price_content' => '单买价:',
  383. ];
  384. }
  385. return [
  386. 'goods_list' => $goodsList,
  387. 'pagination' => $pagination
  388. ];
  389. }
  390. private function bargain()
  391. {
  392. $query = Goods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1,'type' => 2])->with('bargain');
  393. if($this->keyword) {
  394. $query->andWhere(['like', 'name', $this->keyword]);
  395. }
  396. if($this->idList) {
  397. $query->andWhere(['id' => $this->idList]);
  398. }
  399. $count = $query->count();
  400. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  401. if($this->is_page) {
  402. $query->limit($pagination->limit)->offset($pagination->offset);
  403. }
  404. $list = $query->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC])->all();
  405. $goodsList = [];
  406. /* @var Goods[] $list */
  407. foreach ($list as $key => $item) {
  408. /* @var BargainGoods $goods*/
  409. $goods = $item->bargain;
  410. $goodsList[] = [
  411. 'attr' => json_decode($item->attr, true),
  412. 'attr_group' => json_decode(json_encode($item->getAttrGroupList()), true),
  413. 'goods_id' => $item->id,
  414. 'pic_url' => $item->cover_pic,
  415. 'cover_pic' => $item->cover_pic,
  416. 'original_price' => $item->price,
  417. 'name' => $item->name,
  418. 'use_attr' => $item->use_attr,
  419. 'id' => $item->id,
  420. 'price' => round($goods->min_price, 2) ? round($goods->min_price, 2) : 0,
  421. 'page_url' => '/bargain/goods/goods?goods_id=' . $goods->goods_id,
  422. 'is_negotiable' => 0,
  423. 'begin_time' => $goods->begin_time,
  424. 'end_time' => $goods->end_time,
  425. 'begin_time_text' => $goods->getBeginTimeText(),
  426. 'end_time_text' => $goods->getEndTimeText(),
  427. 'price_content' => '最低价:',
  428. 'original_price_content' => '售价:',
  429. ];
  430. }
  431. return [
  432. 'goods_list' => $goodsList,
  433. 'pagination' => $pagination
  434. ];
  435. }
  436. private function book ()
  437. {
  438. $query = YyGoods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1]);
  439. if($this->keyword) {
  440. $query->andWhere(['like', 'name', $this->keyword]);
  441. }
  442. if($this->idList) {
  443. $query->andWhere(['id' => $this->idList]);
  444. }
  445. $count = $query->count();
  446. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  447. if($this->is_page) {
  448. $query->limit($pagination->limit)->offset($pagination->offset);
  449. }
  450. $list = $query->all();
  451. $goodsList = [];
  452. /* @var YyGoods[] $list */
  453. foreach ($list as $key => $item) {
  454. $price = round($item->price, 2);
  455. $goodsList[] = [
  456. 'attr' => json_decode($item->attr, true),
  457. 'attr_group' => json_decode(json_encode($item->getAttrGroupList()), true),
  458. 'id' => $item->id,
  459. 'goods_id' => $item->id,
  460. 'pic_url' => $item->cover_pic,
  461. 'cover_pic' => $item->cover_pic,
  462. 'price' => $price ? $price : 0,
  463. 'original_price' => $item->original_price,
  464. 'name' => $item->name,
  465. 'page_url' => '/pages/book/details/details?id=' . $item->id,
  466. 'use_attr' => $item->use_attr,
  467. 'is_negotiable' => 0,
  468. 'price_content' => $price ? '¥'.$price : '免费'
  469. ];
  470. }
  471. return [
  472. 'goods_list' => $goodsList,
  473. 'pagination' => $pagination
  474. ];
  475. }
  476. private function shop ()
  477. {
  478. $query = Shop::find()->where(['store_id' => get_store_id(), 'is_delete' => 0]);
  479. if($this->keyword) {
  480. $query->andWhere(['like', 'name', $this->keyword]);
  481. }
  482. if($this->idList) {
  483. $query->andWhere(['id' => $this->idList]);
  484. }
  485. $count = $query->count();
  486. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  487. if($this->is_page) {
  488. $query->limit($pagination->limit)->offset($pagination->offset);
  489. }
  490. $list = $query->all();
  491. $shopList = [];
  492. /* @var Shop[] $list*/
  493. foreach($list as $item) {
  494. $shopList[] = [
  495. 'id' => $item->id,
  496. 'pic_url' => $item->pic_url,
  497. 'name' => $item->name,
  498. 'score' => $item->score,
  499. // 修改手机号为隐藏显示
  500. 'mobile' => substr($item->mobile, 0, 3). '****' .substr($item->mobile, -4),
  501. 'longitude' => $item->longitude,
  502. 'latitude' => $item->latitude,
  503. 'address' => $item->address,
  504. ];
  505. }
  506. return [
  507. 'goods_list' => $shopList,
  508. 'pagination' => $pagination
  509. ];
  510. }
  511. private function lottery()
  512. {
  513. $query = LotteryGoods::find()->alias('lg')->where([
  514. 'and',
  515. ['lg.is_delete' => 0, 'lg.store_id' => get_store_id(), 'lg.status' => 1, 'lg.type' => 0,],
  516. ['<=','lg.start_time',time()],
  517. ['>=','lg.end_time',time()],
  518. ])->joinWith(['goods g'])->andWhere(['g.is_delete' => 0]);
  519. if($this->idList) {
  520. $query->andWhere(['lg.id' => $this->idList]);
  521. }
  522. if($this->keyword) {
  523. $query->andWhere(['like', 'g.name', $this->keyword]);
  524. }
  525. $count = $query->count();
  526. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  527. if($this->is_page) {
  528. $query->limit($pagination->limit)->offset($pagination->offset);
  529. }
  530. $list = $query->all();
  531. $goodsList = [];
  532. /* @var LotteryGoods[] $list */
  533. foreach ($list as $key => $item) {
  534. /* @var Goods $goods */
  535. $goods = $item->goods;
  536. $price = $goods->price;
  537. $attr = json_decode($item['attr'], true);
  538. $goodsList[] = [
  539. 'attr' => $attr,
  540. 'attr_group' => json_decode(json_encode($goods->getAttrGroupList()), true),
  541. 'id' => $item->id,
  542. 'goods_id' => $goods->id,
  543. 'pic_url' => $goods->cover_pic,
  544. 'cover_pic' => $goods->cover_pic,
  545. 'price' => round($price, 2) ? round($price, 2) : 0,
  546. 'original_price' => $goods->original_price,
  547. 'name' => $goods->name,
  548. 'page_url' => '/lottery/goods/goods?id=' . $item->id,
  549. 'use_attr' => $goods->use_attr,
  550. 'end_time' => $item->end_time,
  551. 'start_time' => $item->start_time,
  552. 'is_negotiable' => 0,
  553. 'price_content' => '抽奖:',
  554. 'original_price_content' => '原价:',
  555. ];
  556. }
  557. return [
  558. 'goods_list' => $goodsList,
  559. 'pagination' => $pagination
  560. ];
  561. }
  562. private function mch()
  563. {
  564. $goodsQuery = Goods::find()->alias('g')->where('g.mch_id=m.id')->andWhere(['g.status' => 1, 'g.is_delete' => 0])->select('count(1)');
  565. $query = Mch::find()->alias('m')->where([
  566. 'm.store_id' => get_store_id(), 'm.is_delete' => 0, 'm.is_open' => 1, 'm.is_lock' => 0]);
  567. if($this->keyword) {
  568. $query->andWhere(['like', 'name', $this->keyword]);
  569. }
  570. $count = $query->count();
  571. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  572. if($this->is_page) {
  573. $query->limit($pagination->limit)->offset($pagination->offset);
  574. }
  575. $list = $query->select(['*', 'goods_count' => $goodsQuery])->asArray()->all();
  576. $mchList = [];
  577. /* @var Mch[] $list*/
  578. foreach ($list as $item) {
  579. $mchList[] = [
  580. 'id' => $item['id'],
  581. 'mch_id' => $item['id'],
  582. 'name' => $item['name'],
  583. 'logo' => $item['logo'],
  584. 'header_bg' => $item['header_bg'],
  585. 'pic_url' => $item['logo'],
  586. 'goods_count' => $item['goods_count'],
  587. ];
  588. }
  589. return [
  590. 'goods_list' => $mchList,
  591. 'pagination' => $pagination
  592. ];
  593. }
  594. private function integral()
  595. {
  596. $query = SaasIntegralGoods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1]);
  597. if($this->keyword) {
  598. $query->andWhere(['like', 'name', $this->keyword]);
  599. }
  600. $count = $query->count();
  601. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  602. if($this->is_page) {
  603. $query->limit($pagination->limit)->offset($pagination->offset);
  604. }
  605. $list = $query->all();
  606. $goodsList = [];
  607. /* @var SaasIntegralGoods[] $list */
  608. foreach ($list as $key => $item) {
  609. $price = round($item->price, 2) ? round($item->price, 2) : 0;
  610. $priceContent = "";
  611. if($item->integral) {
  612. $priceContent .= $item->integral.'积分';
  613. }
  614. if($price == 0) {
  615. } else {
  616. $priceContent .= '+¥'.$price;
  617. }
  618. $goodsList[] = [
  619. 'attr' => json_decode($item['attr'], true),
  620. 'attr_group' => json_decode(json_encode($item->getAttrGroupList()), true),
  621. 'id' => $item->id,
  622. 'goods_id' => $item->id,
  623. 'pic_url' => $item->cover_pic,
  624. 'cover_pic' => $item->cover_pic,
  625. 'price' => $price,
  626. 'integral_content' => $priceContent,
  627. 'original_price' => $item->original_price,
  628. 'name' => $item->name,
  629. 'page_url' => '/pages/integral-mall/goods-info/index?goods_id=' . $item->id,
  630. 'use_attr' => $item->use_attr,
  631. 'is_negotiable' => 0,
  632. 'original_price_content' => '原价:¥'.$item->original_price
  633. ];
  634. }
  635. return [
  636. 'goods_list' => $goodsList,
  637. 'pagination' => $pagination
  638. ];
  639. }
  640. private function topic()
  641. {
  642. $query = Topic::find()->where(['store_id' => get_store_id(), 'is_delete' => 0]);
  643. if($this->cat != 0) {
  644. $query->andWhere(['type' => $this->cat]);
  645. }
  646. if($this->idList) {
  647. $query->andWhere(['id' => $this->idList]);
  648. }
  649. if($this->keyword) {
  650. $query->andWhere(['like', 'name', $this->keyword]);
  651. }
  652. $count = $query->count();
  653. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
  654. if($this->is_page) {
  655. $query->limit($pagination->limit)->offset($pagination->offset);
  656. }
  657. $list = $query->all();
  658. $goodsList = [];
  659. /* @var Topic[] $list */
  660. foreach ($list as $key => $item) {
  661. $read_count = intval($item['read_count'] + $item['virtual_read_count']);
  662. if ($read_count < 10000) {
  663. $read_count = $read_count;
  664. }
  665. if ($read_count >= 10000) {
  666. $read_count = intval($read_count / 10000) . '万+';
  667. }
  668. $goodsList[] = [
  669. 'id' => $item->id,
  670. 'goods_id' => $item->id,
  671. 'pic_url' => $item->cover_pic,
  672. 'cover_pic' => $item->cover_pic,
  673. 'title' => $item->title,
  674. 'name' => $item->title,
  675. 'page_url' => '/pages/topic/topic?id=' . $item->id,
  676. 'layout' => $item->layout,
  677. 'read_count' => $read_count,
  678. ];
  679. }
  680. return [
  681. 'goods_list' => $goodsList,
  682. 'pagination' => $pagination
  683. ];
  684. }
  685. // diy组件权限
  686. public static function getDiyAuth()
  687. {
  688. $plugin = \Yii::$app->controller->getUserAuth() ? \Yii::$app->controller->getUserAuth() : [];
  689. if(in_array('integralmall', $plugin)) {
  690. array_push($plugin, 'integral');
  691. }
  692. $defaultAuth = ['search', 'nav', 'banner', 'notice', 'topic',
  693. 'link', 'rubik', 'video' ,'goods', 'waimai', 'shop', 'shop_info', 'time', 'line', 'ad', 'modal', 'float', 'super_brand', 'nearby_mch', 'plate', 'fast_nav', 'recommend_goods', 'hourly_miaosha', 'index_recommend'];
  694. $plugin = array_merge($plugin, $defaultAuth);
  695. return $plugin;
  696. }
  697. }