MPage.Class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: XiaoMing
  5. * Date: 2020/3/19
  6. * Time: 12:16
  7. */
  8. namespace JinDouYun\Model\System;
  9. use JinDouYun\Cache\PageCache;
  10. use JinDouYun\Controller\Common\Logger;
  11. use JinDouYun\Dao\Market\DUserCoupon;
  12. use JinDouYun\Dao\System\DPage;
  13. use JinDouYun\Dao\System\DPageDefault;
  14. use JinDouYun\Model\Customer\MCustomer;
  15. use JinDouYun\Model\Goods\MGoods;
  16. use JinDouYun\Model\Market\MActivity;
  17. use JinDouYun\Model\Market\MCoupon;
  18. use JinDouYun\Model\Merchant\MMerchant;
  19. use JinDouYun\Model\Shop\MShop;
  20. use Mall\Framework\Core\ErrorCode;
  21. use Mall\Framework\Core\ResultWrapper;
  22. use Mall\Framework\Core\StatusCode;
  23. class MPage
  24. {
  25. private $objDPage;
  26. private $onlineEnterpriseId;
  27. private $onlineUserId;
  28. private $areaCode;
  29. private $shopId;
  30. /**
  31. * MPage constructor.
  32. * @param $onlineUserId
  33. * @param $enterpriseId
  34. * @param null $areaCode
  35. * @throws \Exception
  36. */
  37. public function __construct($onlineUserId, $enterpriseId, $areaCode = null)
  38. {
  39. $this->onlineUserId = $onlineUserId;
  40. $this->onlineEnterpriseId = $enterpriseId;
  41. $this->areaCode = $areaCode;
  42. $this->objDPage = new DPage('default');
  43. $this->objDPage->setTable($this->objDPage->get_Table() . '_' . $this->onlineEnterpriseId);
  44. self::__initDefaultPage();
  45. self::__initEnablePage();
  46. }
  47. /**
  48. * 1.初始化默认模版
  49. */
  50. private function __initDefaultPage()
  51. {
  52. //查询是否有默认的模版
  53. $dbResult = $this->objDPage->get(['pageType' => StatusCode::$pageType['home'], 'isDefault' => StatusCode::$standard]);
  54. if (!empty($dbResult)) {
  55. return;
  56. }
  57. $objDPageDefault = new DPageDefault();//系统默认模版表
  58. $default = $objDPageDefault->get([
  59. 'deleteStatus' => StatusCode::$standard,
  60. 'enableStatus' => StatusCode::$standard,
  61. 'isDefault' => StatusCode::$standard,
  62. 'pageType' => StatusCode::$pageType['home']
  63. ]);
  64. if (empty($default)) {
  65. return;
  66. }
  67. $this->objDPage->insert([
  68. 'pageType' => $default['pageType'],
  69. 'pageName' => $default['pageName'],
  70. 'pageData' => $default['pageData'],
  71. 'deleteStatus' => $default['deleteStatus'],
  72. 'isDefault' => $default['isDefault'],
  73. 'enableStatus' => StatusCode::$delete,
  74. ]);
  75. }
  76. /**
  77. * 2.是否有已启用的模版,没有则启用系统默认模版
  78. */
  79. private function __initEnablePage()
  80. {
  81. //查询是否有已启用的模版,没有则启用系统默认模版
  82. $enablePage = $this->objDPage->get([
  83. 'deleteStatus' => StatusCode::$standard,
  84. 'enableStatus' => StatusCode::$standard,
  85. 'pageType' => StatusCode::$pageType['home'],
  86. 'shopId' => 0,
  87. ]);
  88. if (!empty($enablePage)) {
  89. return;
  90. }
  91. //没有启用的模版,更新默认模版的启用状态
  92. $this->objDPage->update(['enableStatus' => StatusCode::$standard], ['isDefault' => StatusCode::$standard,'shopId' => 0, 'pageType' => StatusCode::$pageType['home']]);
  93. }
  94. /**
  95. * 保存页面
  96. *
  97. * @param $params
  98. * @param bool $isStore
  99. * @param $shopId
  100. * @return ResultWrapper
  101. */
  102. public function save($params,bool $isStore,$shopId)
  103. {
  104. if ($isStore === true){
  105. $objMMerchant = new MMerchant($this->onlineEnterpriseId,$this->onlineUserId);
  106. $merchResult = $objMMerchant->getMerchByShopId($shopId);
  107. if (!$merchResult->isSuccess()){
  108. return ResultWrapper::fail($merchResult->getData(),$merchResult->getErrorCode());
  109. }
  110. $merch = $merchResult->getData();
  111. $params['shopId'] = $shopId;
  112. $params['merchantId'] = $merch['merchantId'];
  113. }
  114. if (isset($params['id'])) {
  115. $dbResult = $this->objDPage->get(['id' => $params['id']]);
  116. if ($dbResult === false) {
  117. return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  118. }
  119. if ($dbResult['isDefault'] == StatusCode::$standard) {
  120. $params['isDefault'] = StatusCode::$standard;
  121. }
  122. $params['enableStatus'] = $dbResult['enableStatus'];//启用状态
  123. }
  124. if (!isset($params['id'])) {
  125. $params['enableStatus'] = StatusCode::$delete;
  126. }
  127. $dbResult = $this->objDPage->replace($params);
  128. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  129. return ResultWrapper::success($dbResult);
  130. }
  131. /**
  132. * 获取页面详情
  133. *
  134. * @param $id
  135. * @return ResultWrapper
  136. */
  137. public function getPageInfo($id)
  138. {
  139. $dbResult = $this->objDPage->get(['id' => $id], 'id,pageType,pageName,pageData,enableStatus');
  140. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  141. if (!empty($dbResult['pageData'])) $dbResult['pageData'] = json_decode($dbResult['pageData'], true);
  142. return ResultWrapper::success($dbResult);
  143. }
  144. /**
  145. * 启用页面/禁用页面
  146. *
  147. * @param $params
  148. * @return ResultWrapper
  149. */
  150. public function updateEnableStatus($params)
  151. {
  152. $dbResult = $this->objDPage->get(['id' => $params['id']]);
  153. if ($dbResult === false) {
  154. return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  155. }
  156. //专题活动可以启用多个
  157. if ($dbResult['pageType'] != StatusCode::$pageType['special']) {
  158. //如果是启用操作,先禁用相同类型的已启用的,在启用当前的
  159. if ($params['enableStatus'] == StatusCode::$standard) {
  160. $condition = [
  161. 'enableStatus' => StatusCode::$standard,
  162. 'deleteStatus' => StatusCode::$standard,
  163. 'pageType' => $dbResult['pageType']
  164. ];
  165. $dbResult = $this->objDPage->update(['enableStatus' => StatusCode::$delete],$condition);
  166. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  167. }
  168. }
  169. $dbResult = $this->objDPage->update(['enableStatus' => $params['enableStatus']], $params['id']);
  170. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  171. return ResultWrapper::success($dbResult);
  172. }
  173. /**
  174. * 删除页面
  175. *
  176. * @param $id
  177. * @return ResultWrapper
  178. */
  179. public function del($id)
  180. {
  181. $dbResult = $this->objDPage->get(['id' => $id]);
  182. if ($dbResult === false) {
  183. return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  184. }
  185. if ($dbResult['isDefault'] == StatusCode::$standard) {
  186. return ResultWrapper::fail('系统模版模版不能删除', ErrorCode::$paramError);
  187. }
  188. $dbResult = $this->objDPage->update(['deleteStatus' => StatusCode::$delete], $id);
  189. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  190. return ResultWrapper::success($dbResult);
  191. }
  192. /**
  193. * 获取页面列表
  194. *
  195. * @param $selectParams
  196. * @return ResultWrapper
  197. */
  198. public function getAll($selectParams)
  199. {
  200. $limit = $selectParams['limit'];
  201. unset($selectParams['limit']);
  202. $offset = $selectParams['offset'];
  203. unset($selectParams['offset']);
  204. $selectParams['deleteStatus'] = StatusCode::$standard;
  205. $dbResult = $this->objDPage->select($selectParams, 'id,pageType,pageName,enableStatus,isDefault', 'createTime DESC', $limit, $offset);
  206. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  207. $total = $this->objDPage->count($selectParams);
  208. $return = [
  209. 'data' => $dbResult,
  210. 'total' => ($total) ? intval($total) : 0,
  211. ];
  212. return ResultWrapper::success($return);
  213. }
  214. /**
  215. * 获取app首页
  216. *
  217. * @return ResultWrapper
  218. * @throws \Exception
  219. * @param int $pageType
  220. *
  221. */
  222. public function home($pageType = 1,$shopId = null)
  223. {
  224. $dbResult = $this->objDPage->get_field('pageData',
  225. [
  226. 'deleteStatus' => StatusCode::$standard,
  227. 'pageType' => $pageType,
  228. 'enableStatus' => StatusCode::$standard,
  229. 'shopId' => 0
  230. ]
  231. );
  232. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  233. $items = empty($dbResult) ? [] : json_decode($dbResult, true);
  234. foreach ($items as $key => &$item) {
  235. $setting = $item['modelData'];//模块配置信息
  236. switch ($item['comName']){
  237. case 'GoodsGroup':
  238. // 获取商品组模块数据 goodsFrom =1 自动获取 2手动选择
  239. if ($setting['navStyle'] == 2) {
  240. foreach ($setting['tabList'] as $index => &$val) {
  241. $item['modelData']['tabList'][$index]['data'] = ($val['goodsFrom'] == 1) ? self::goodsModule($val) : self::checkGoods($val['goods_ids']);// 根据商品的id或信息检索商品数据
  242. }
  243. } else {
  244. $items[$key]['data'] = $setting['goodsFrom'] == 1 ? self::goodsModule($setting) : self::checkGoods($item['modelData']['goods_ids']); // 根据商品的id或信息检索商品数据
  245. }
  246. break;
  247. case 'CouponGroup':
  248. //获取优惠券模块数据
  249. $items[$key]['data'] = self::couponModule($setting);
  250. break;
  251. case 'LimitedSeckill':
  252. //获取秒杀商品模块数据
  253. $items[$key]['data'] = self::secKillModule($setting);
  254. break;
  255. case 'Notice':
  256. //获取公告数据
  257. $items[$key]['data'] = self::noticeModule(['type'=>StatusCode::$standard]);
  258. break;
  259. }
  260. }
  261. return ResultWrapper::success($items);
  262. }
  263. /**
  264. * Doc: (des="")
  265. * User: XMing
  266. * Date: 2020/12/29
  267. * Time: 10:14 上午
  268. * @param $merchantId
  269. * @param $pageType
  270. * @return ResultWrapper
  271. * @throws \Exception
  272. */
  273. public function shopHome($merchantId,$pageType)
  274. {
  275. $dbResult = $this->objDPage->get(
  276. [
  277. 'deleteStatus' => StatusCode::$standard,
  278. 'pageType' => $pageType,
  279. 'enableStatus' => StatusCode::$standard,
  280. 'merchantId' => $merchantId
  281. ],'pageData,shopId'
  282. );
  283. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  284. $shopId = getArrayItem($dbResult,'shopId',0);
  285. $items = empty($dbResult['pageData']) ? [] : json_decode($dbResult['pageData'],true);
  286. foreach ($items as $key => &$item) {
  287. $setting = $item['modelData'];
  288. switch ($item['comName']){
  289. case 'GoodsGroup':
  290. //获取商品组模块数据
  291. if ($setting['navStyle'] == 2) {
  292. foreach ($setting['tabList'] as $index => &$val) {
  293. $item['modelData']['tabList'][$index]['data'] = ($val['goodsFrom'] == 1) ? self::goodsModule($val,$shopId) : self::checkGoods($val['goods_ids'],$shopId);
  294. }
  295. } else {
  296. $items[$key]['data'] = $setting['goodsFrom'] == 1 ? self::goodsModule($setting,$shopId) : self::checkGoods($item['modelData']['goods_ids'],$shopId);
  297. }
  298. break;
  299. case 'CouponGroup':
  300. //获取优惠券模块数据
  301. $items[$key]['data'] = self::couponModule($setting);
  302. break;
  303. case 'LimitedSeckill':
  304. //获取秒杀商品模块数据
  305. $items[$key]['data'] = self::secKillModule($setting);
  306. break;
  307. case 'Notice':
  308. //获取公告数据
  309. $items[$key]['data'] = self::noticeModule($setting);
  310. break;
  311. }
  312. }
  313. return ResultWrapper::success($items);
  314. }
  315. /**
  316. * 检测商品
  317. *
  318. * @param $goodsIds
  319. * @param int $shopId
  320. * @return array
  321. * @throws \Exception
  322. */
  323. private function checkGoods($goodsIds,$shopId = 0)
  324. {
  325. $objMGoods = new MGoods($this->onlineEnterpriseId, true, $this->onlineUserId);
  326. $pageParams = pageToOffset(1, 100);
  327. $selectParams = [
  328. 'limit' => $pageParams['limit'],
  329. 'offset' => $pageParams['offset'],
  330. 'userCenterId' => $this->onlineUserId,
  331. 'goodsIds' => $goodsIds,
  332. 'areaCode' => $this->areaCode,
  333. 'shopId' => $this->shopId
  334. ];
  335. if (isset($shopId) && !empty($shopId)){
  336. $selectParams['shopId'] = $shopId;
  337. }
  338. // 根据MD5查询需要的数据
  339. $md5Key = md5(json_encode($selectParams));
  340. $objPageCache = new PageCache();
  341. $goodsCacheData = $objPageCache->getPage($md5Key);
  342. if(!empty($goodsCacheData)){
  343. return self::formatGoods($goodsCacheData);
  344. }
  345. $result = $objMGoods->search($selectParams);
  346. if (!$result->isSuccess()) return [];
  347. $goodsData = $result->getData()['data'];
  348. // 写入缓存
  349. $objPageCache->addPage($md5Key,$goodsData);
  350. return self::formatGoods($goodsData);
  351. }
  352. /**
  353. * 市场价格
  354. * @param array $data
  355. * @return array
  356. */
  357. private function formatGoods($data)
  358. {
  359. if (empty($data)){
  360. return $data;
  361. }
  362. foreach ($data as $key => $value){
  363. if (isset($value['salePrice'])){
  364. continue;
  365. }
  366. $data[$key]['salePrice'] = isset($value['minSalePrice']) ? $value['minSalePrice'] : '0.00';
  367. }
  368. return $data;
  369. }
  370. /**
  371. * 获取开启的一条公告
  372. * @param $params
  373. * @return array|mixed
  374. */
  375. private function noticeModule($params)
  376. {
  377. $objMAnnouncement = new MAnnouncement($this->onlineEnterpriseId);
  378. $notice = $objMAnnouncement->getAnnouncement($params);
  379. if (!$notice->isSuccess()) {
  380. return (object)[];
  381. }
  382. return empty($notice->getData()) ? (object) [] : $notice->getData();
  383. }
  384. /**
  385. * 商品模块数据
  386. *
  387. * @param $params
  388. * @return array
  389. * @throws \Exception
  390. */
  391. private function goodsModule($params,$shopId = 0)
  392. {
  393. $objMGoods = new MGoods($this->onlineEnterpriseId, true, $this->onlineUserId);
  394. $pageParams = pageToOffset(1, isset($params['goodsNum']) ? $params['goodsNum'] : 10);
  395. $selectParams = [
  396. //'categoryId' => isset($params['categoryPath'][0]) ? $params['categoryPath'][0] : '',
  397. 'categoryPath' => isset($params['categoryPath']) ? $params['categoryPath'] : [],
  398. 'limit' => $pageParams['limit'],
  399. 'offset' => $pageParams['offset'],
  400. 'userCenterId' => $this->onlineUserId,
  401. 'areaCode' => $this->areaCode,
  402. 'shopId' => $this->shopId
  403. ];
  404. if (isset($shopId) && !empty($shopId)){
  405. $selectParams['shopId'] = $shopId;
  406. }
  407. // 根据MD5查询需要的数据
  408. $md5Key = md5(json_encode($selectParams));
  409. $objPageCache = new PageCache();
  410. $goodsCacheData = $objPageCache->getPage($md5Key);
  411. if(!empty($goodsCacheData)){
  412. return self::formatGoods($goodsCacheData);
  413. }
  414. $result = $objMGoods->search($selectParams);
  415. if (!$result->isSuccess()) return [];
  416. $goodsData = $result->getData();
  417. $goodsData = isset($goodsData['data']) ? $goodsData['data'] : [];
  418. // 写入缓存
  419. $objPageCache->addPage($md5Key,$goodsData);
  420. return self::formatGoods($goodsData);
  421. }
  422. /**
  423. * 优惠券列表
  424. *
  425. * @param $params
  426. * @return array|ResultWrapper|mixed
  427. * @throws \Exception
  428. */
  429. private function couponModule($params)
  430. {
  431. $objMCoupon = new MCoupon($this->onlineUserId, $this->onlineEnterpriseId);
  432. $paramsData = [
  433. 'grantType' => StatusCode::$grantType['receive'],
  434. ];
  435. $dbResult = $objMCoupon->couponList($paramsData);
  436. if (!$dbResult->isSuccess()) {
  437. return [];
  438. }
  439. $coupon = $dbResult->getData();
  440. if (!empty($this->onlineUserId)) {
  441. //用户已经登录,删除其中已经领取过的:
  442. $objDUserCoupon = new DUserCoupon();
  443. $sql = 'SELECT couponId,count(`id`) as num FROM qianniao_user_coupon_' . $this->onlineEnterpriseId . ' WHERE userId=' . $this->onlineUserId . ' GROUP BY couponId';
  444. $countCoupon = $objDUserCoupon->query($sql);
  445. if ($countCoupon === false) {
  446. return $coupon;
  447. }
  448. $groupNum = [];//优惠券对应领取数量
  449. if (!empty($countCoupon)) {
  450. foreach ($countCoupon as $count) {
  451. $groupNum[$count['couponId']] = $count['num'];
  452. }
  453. }
  454. foreach ($coupon as $key => $val) {
  455. $haveNum = isset($groupNum[$val['id']]) ? $groupNum[$val['id']] : 0;
  456. if ($haveNum >= $val['allowNum']) {
  457. //领取达到了上限
  458. unset($coupon[$key]);
  459. continue;
  460. }
  461. }
  462. }
  463. $coupon = array_slice($coupon, 0, $params['couponNum']);
  464. return $coupon;
  465. }
  466. /**
  467. * 秒杀商品数据
  468. *
  469. * @param $params
  470. * @return array
  471. * @throws \Exception
  472. */
  473. private function secKillModule($params)
  474. {
  475. if (empty($params['seckill_id'])) {
  476. return [];
  477. }
  478. $objMActivity = new MActivity($this->onlineUserId, $this->onlineEnterpriseId, $this->areaCode);
  479. $dbResult = $objMActivity->getInfo($params['seckill_id']);
  480. if (!$dbResult->isSuccess()) {
  481. return [];
  482. }
  483. $skillGoods = $dbResult->getData();
  484. //没有活动
  485. if (empty($skillGoods)){
  486. return [];
  487. }
  488. // 判断秒杀活动是否审核通过
  489. if (isset($skillGoods['auditStatus']) && $skillGoods['auditStatus'] != StatusCode::$auditStatus['auditPass']) {
  490. return [];
  491. }
  492. if ($skillGoods['enableStatus'] == StatusCode::$delete) {
  493. //此活动已下架
  494. return [];
  495. }
  496. //获取用户类型
  497. $customerType = null;
  498. if (!empty($this->onlineUserId)) {
  499. $objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  500. $customer = $objMCustomer->getCustomerInfoByUserCenterId($this->onlineUserId);
  501. if (!$customer->isSuccess()) {
  502. $customerType = null;
  503. } else {
  504. $customer = $customer->getData();
  505. $customerType = isset($customer['type']) ? $customer['type'] : null;
  506. }
  507. }
  508. //如果客户类型和活动不符合
  509. if ($skillGoods['customerRange'] == StatusCode::$delete) {
  510. if (empty($customerType)) {
  511. return [];
  512. }
  513. //客户类型
  514. $mapping = explode(',', trim($skillGoods['customerSourceId'], ','));
  515. if (!in_array($customerType, $mapping)) {
  516. return [];
  517. }
  518. }
  519. $skillGoods['inActivity'] = StatusCode::$standard;
  520. $skillGoods['msg'] = '活动进行中';
  521. if (!isset($skillGoods['startTime']) || !isset($skillGoods['endTime'])) {
  522. return [];
  523. }
  524. if ($skillGoods['startTime'] > time()) {
  525. $skillGoods['activityGoods'] = [];//删除商品
  526. $skillGoods['msg'] = '活动暂未开始';
  527. $skillGoods['inActivity'] = StatusCode::$delete;
  528. } elseif ($skillGoods['endTime'] < time()) {
  529. $skillGoods['activityGoods'] = [];//删除商品
  530. $skillGoods['msg'] = '活动已结束';
  531. $skillGoods['inActivity'] = StatusCode::$delete;
  532. }
  533. if (isset($skillGoods['activityGoods'])) {
  534. foreach ($skillGoods['activityGoods'] as &$goods) {
  535. $goods['originPrice'] = $goods['salePrice'];//原价
  536. $goods['salePrice'] = $goods['price'];//现在的秒杀活动价
  537. }
  538. }
  539. return $skillGoods;
  540. }
  541. /**
  542. * 获取专题活动
  543. * @param $selectParams
  544. * @return ResultWrapper
  545. */
  546. public function getSpecial($selectParams)
  547. {
  548. $limit = $selectParams['limit'];
  549. unset($selectParams['limit']);
  550. $offset = $selectParams['offset'];
  551. unset($selectParams['offset']);
  552. $selectParams['deleteStatus'] = StatusCode::$standard;
  553. $selectParams['pageType'] = StatusCode::$pageType['special'];
  554. $selectParams['enableStatus'] = StatusCode::$standard;
  555. $dbResult = $this->objDPage->select($selectParams, '*', 'updateTime DESC', $limit, $offset);
  556. $total = $this->objDPage->count($selectParams);
  557. if ($dbResult === false) {
  558. return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  559. }
  560. foreach ($dbResult as $key => &$value) {
  561. $pageData = json_decode($value['pageData'], true);
  562. $dbResult[$key]['pageData'] = $pageData;
  563. }
  564. $data = [
  565. 'data' => $dbResult,
  566. 'total' => $total
  567. ];
  568. return ResultWrapper::success($data);
  569. }
  570. /**
  571. * 主要用来获取主题详情页
  572. * @param $id
  573. * @param
  574. * @return ResultWrapper
  575. * @throws \Exception
  576. */
  577. public function getDetailById($id)
  578. {
  579. $dbResult = $this->objDPage->get_field('pageData',
  580. ['id' => $id, 'enableStatus' => StatusCode::$standard, 'deleteStatus' => StatusCode::$standard]
  581. );
  582. if ($dbResult === false) return ResultWrapper::fail($this->objDPage->error(), ErrorCode::$dberror);
  583. $items = empty($dbResult) === true ? [] : json_decode($dbResult, true);
  584. foreach ($items as $key => &$item) {
  585. $setting = $item['modelData'];//模块配置信息
  586. switch ($item['comName']){
  587. case 'GoodsGroup':
  588. //获取商品组模块数据
  589. if ($setting['navStyle'] == 2) {
  590. foreach ($setting['tabList'] as $index => &$val) {
  591. $item['modelData']['tabList'][$index]['data'] = ($val['goodsFrom'] == 1) ? self::goodsModule($val) : self::checkGoods($val['goods_ids']);
  592. }
  593. } else {
  594. $items[$key]['data'] = $setting['goodsFrom'] == 1 ? self::goodsModule($setting) : self::checkGoods($item['modelData']['goods_ids']);
  595. }
  596. break;
  597. case 'CouponGroup':
  598. //获取优惠券模块数据
  599. $items[$key]['data'] = self::couponModule($setting);
  600. break;
  601. case 'LimitedSeckill':
  602. //获取秒杀商品模块数据
  603. $items[$key]['data'] = self::secKillModule($setting);
  604. break;
  605. case 'Notice':
  606. //获取公告数据
  607. $items[$key]['data'] = self::noticeModule($setting);
  608. break;
  609. }
  610. /**if ($item['comName'] == 'GoodsGroup') {
  611. //获取商品组模块数据
  612. if ($setting['navStyle'] == 2) {
  613. foreach ($setting['tabList'] as $index => &$val) {
  614. $item['modelData']['tabList'][$index]['data'] = ($val['goodsFrom'] == 1) ? self::goodsModule($val) : self::checkGoods($val['goods_ids']);
  615. }
  616. } else {
  617. $items[$key]['data'] = $setting['goodsFrom'] == 1 ? self::goodsModule($setting) : self::checkGoods($item['modelData']['goods_ids']);
  618. }
  619. } elseif ($item['comName'] == 'CouponGroup') {
  620. //获取优惠券模块数据
  621. $items[$key]['data'] = self::couponModule($setting);
  622. } elseif ($item['comName'] == 'LimitedSeckill') {
  623. //获取秒杀商品模块数据
  624. $items[$key]['data'] = self::secKillModule($setting);
  625. }**/
  626. }
  627. return ResultWrapper::success($items);
  628. }
  629. }