Diy.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. namespace app\controller\admin\v1\diy;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\newcomer\StoreNewcomerServices;
  14. use app\services\activity\video\VideoServices;
  15. use app\services\article\ArticleServices;
  16. use app\services\diy\DiyServices;
  17. use app\services\other\CacheServices;
  18. use app\services\product\category\StoreProductCategoryServices;
  19. use app\services\product\product\StoreProductServices;
  20. use crmeb\exceptions\AdminException;
  21. use think\facade\App;
  22. /**
  23. * Class Diy
  24. * @package app\controller\admin\v1\diy
  25. */
  26. class Diy extends AuthController
  27. {
  28. /**
  29. * Diy constructor.
  30. * @param App $app
  31. * @param DiyServices $services
  32. */
  33. public function __construct(App $app, DiyServices $services)
  34. {
  35. parent::__construct($app);
  36. $this->services = $services;
  37. }
  38. /**
  39. * DIY列表
  40. * @return mixed
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function getList()
  46. {
  47. $where = $this->request->getMore([
  48. ['status', ''],
  49. ['type', ''],
  50. ['name', ''],
  51. ['version', ''],
  52. ]);
  53. $where['is_del'] = 0;
  54. $data = $this->services->getDiyList($where);
  55. return $this->success($data);
  56. }
  57. /**
  58. * 保存资源
  59. * @param int $id
  60. * @return mixed
  61. */
  62. public function saveData(int $id = 0)
  63. {
  64. $data = $this->request->postMore([
  65. ['name', ''],
  66. ['title', ''],
  67. ['value', ''],
  68. ['type', ''],
  69. ['cover_image', ''],
  70. ['is_show', 0],
  71. ['is_bg_color', 0],
  72. ['is_bg_pic', 0],
  73. ['bg_tab_val', 0],
  74. ['color_picker', ''],
  75. ['bg_pic', ''],
  76. ]);
  77. $value = is_string($data['value']) ? json_decode($data['value'], true) : $data['value'];
  78. $infoDiy = $id ? $this->services->get($id, ['is_diy']) : [];
  79. if ($infoDiy && $infoDiy['is_diy']) {
  80. foreach ($value as $key => &$item) {
  81. if ($item['name'] === 'goodList') {
  82. if (isset($item['selectConfig']['list'])) {
  83. unset($item['selectConfig']['list']);
  84. }
  85. if (isset($item['goodsList']['list']) && is_array($item['goodsList']['list'])) {
  86. $limitMax = config('database.page.limitMax', 50);
  87. if (isset($item['numConfig']['val']) && isset($item['tabConfig']['tabVal']) && $item['tabConfig']['tabVal'] == 0 && $item['numConfig']['val'] > $limitMax) {
  88. return $this->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
  89. }
  90. $item['goodsList']['ids'] = array_column($item['goodsList']['list'], 'id');
  91. unset($item['goodsList']['list'], $item['productList']['list']);
  92. }
  93. } elseif ($item['name'] === 'articleList') {
  94. if (isset($item['selectList']['list']) && is_array($item['selectList']['list'])) {
  95. unset($item['selectList']['list']);
  96. }
  97. } elseif ($item['name'] === 'promotionList') {
  98. if (isset($item['tabConfig']['list']) && $item['tabConfig']['list']) {
  99. $list = $item['tabConfig']['list'];
  100. foreach ($list as &$tabValue) {
  101. if (isset($tabValue['goodsList']['list']) && is_array($tabValue['goodsList']['list'])) {
  102. $limitMax = config('database.page.limitMax', 50);
  103. if (isset($tabValue['numConfig']['val']) && isset($tabValue['tabConfig']['tabVal']) && $tabValue['tabConfig']['tabVal'] == 0 && $tabValue['numConfig']['val'] > $limitMax) {
  104. return $this->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
  105. }
  106. $tabValue['goodsList']['ids'] = array_column($tabValue['goodsList']['list'], 'id');
  107. }
  108. unset($tabValue['goodsList']['list'], $item['productList']['list']);
  109. }
  110. $item['tabConfig']['list'] = $list;
  111. }
  112. } elseif ($item['name'] === 'newVip') {
  113. unset($item['newVipList']['list']);
  114. } elseif ($item['name'] === 'shortVideo') {
  115. unset($item['videoList']);
  116. }
  117. }
  118. $data['value'] = json_encode($value);
  119. } else {
  120. if (isset($value['d_goodList']['selectConfig']['list'])) {
  121. unset($value['d_goodList']['selectConfig']['list']);
  122. } elseif (isset($value['d_goodList']['goodsList']['list'])) {
  123. $limitMax = config('database.page.limitMax', 50);
  124. if (isset($value['d_goodList']['numConfig']['val']) && isset($value['d_goodList']['tabConfig']['tabVal']) && $value['d_goodList']['tabConfig']['tabVal'] == 0 && $value['d_goodList']['numConfig']['val'] > $limitMax) {
  125. return $this->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
  126. }
  127. $value['d_goodList']['goodsList']['ids'] = array_column($value['d_goodList']['goodsList']['list'], 'id');
  128. unset($value['d_goodList']['goodsList']['list']);
  129. } elseif (isset($value['k_newProduct']['goodsList']['list'])) {
  130. $list = [];
  131. foreach ($value['k_newProduct']['goodsList']['list'] as $item) {
  132. $list[] = [
  133. 'image' => $item['image'],
  134. 'store_info' => $item['store_info'],
  135. 'store_name' => $item['store_name'],
  136. 'id' => $item['id'],
  137. 'price' => $item['price'],
  138. 'ot_price' => $item['ot_price'],
  139. ];
  140. }
  141. $value['k_newProduct']['goodsList']['list'] = $list;
  142. } elseif (isset($value['selectList']['list']) && is_array($value['selectList']['list'])) {
  143. unset($value['goodsList']['list']);
  144. }
  145. $data['value'] = json_encode($value);
  146. }
  147. $data['version'] = uniqid();
  148. return $this->success($id ? '修改成功' : '保存成功', ['id' => $this->services->saveData($id, $data)]);
  149. }
  150. /**
  151. * 删除模板
  152. * @param $id
  153. * @return mixed
  154. */
  155. public function del($id)
  156. {
  157. $this->services->del($id);
  158. return $this->success('删除成功');
  159. }
  160. /**
  161. * 使用模板
  162. * @param $id
  163. * @return mixed
  164. */
  165. public function setStatus($id)
  166. {
  167. return $this->success($this->services->setStatus($id));
  168. }
  169. /**
  170. * 获取一条数据
  171. * @param int $id
  172. * @return mixed
  173. */
  174. public function getInfo($id, StoreProductServices $services, StoreNewcomerServices $newcomerServices, VideoServices $videoServices)
  175. {
  176. if (!(int)$id) throw new AdminException('参数错误');
  177. $info = $this->services->get((int)$id);
  178. if ($info) {
  179. $info = $info->toArray();
  180. } else {
  181. throw new AdminException('模板不存在');
  182. }
  183. $info['value'] = json_decode($info['value'], true);
  184. if ($info['value']) {
  185. /** @var ArticleServices $articleServices */
  186. $articleServices = app()->make(ArticleServices::class);
  187. /** @var StoreProductCategoryServices $storeCategoryServices */
  188. $storeCategoryServices = app()->make(StoreProductCategoryServices::class);
  189. if ($info['is_diy']) {
  190. $limitMax = config('database.page.limitMax', 50);
  191. foreach ($info['value'] as &$item) {
  192. switch ($item['name']) {
  193. case 'goodList'://商品列表
  194. $where = [];
  195. //选择方式
  196. $selectValue = $item['tabConfig']['tabVal'] ?? 0;
  197. $num = $item['numConfig']['val'] ?? $limitMax;
  198. $sort = $item['goodsSort']['type'] ?? 0;
  199. if ($sort == 1) {
  200. $where['salesOrder'] = 'desc';
  201. } elseif ($sort == 2) {
  202. $where['priceOrder'] = 'desc';
  203. }
  204. if ($selectValue == 1 && isset($item['goodsList']['ids']) && count($item['goodsList']['ids'])) {//手动选商品
  205. $where['ids'] = $item['goodsList']['ids'];
  206. $item['goodsList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
  207. } elseif ((isset($item['selectConfig']['activeValue']) && $item['selectConfig']['activeValue']) || (isset($item['goodsLabel']['activeValue']) && $item['goodsLabel']['activeValue'])) {//选分类 、标签
  208. $cateIds = $item['selectConfig']['activeValue'] ?? [];
  209. if ($cateIds) {
  210. $ids = $storeCategoryServices->getColumn(['pid' => $cateIds], 'id');
  211. if ($ids) {
  212. $cateIds = array_unique(array_merge($cateIds, $ids));
  213. $where['cate_id'] = $cateIds;
  214. }
  215. }
  216. $storeLabelIds = $item['goodsLabel']['activeValue'] ?? [];
  217. if ($storeLabelIds) {
  218. $where['store_label_id'] = $storeLabelIds;
  219. }
  220. $where['type'] = [0, 2];
  221. $where['is_show'] = 1;
  222. $where['is_del'] = 0;
  223. $where['is_verify'] = 1;
  224. $where['ids'] = '';
  225. $item['productList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
  226. }
  227. break;
  228. case 'articleList'://文章
  229. $data = [];
  230. if ($item['selectConfig']['activeValue'] ?? 0) {
  231. $data = $articleServices->getList(['cid' => $item['selectConfig']['activeValue'] ?? 0], 0, $item['numConfig']['val'] ?? 0);
  232. }
  233. $item['selectList']['list'] = $data['list'] ?? [];
  234. break;
  235. case 'promotionList'://促销列表
  236. if (isset($item['tabConfig']['list']) && $item['tabConfig']['list']) {
  237. $list = $item['tabConfig']['list'];
  238. if ($list) {
  239. foreach ($list as &$tabValue) {
  240. $where = [];
  241. //选择方式
  242. $selectValue = $tabValue['tabVal'] ?? 0;
  243. $num = $tabValue['numConfig']['val'] ?? $limitMax;
  244. $sort = $tabValue['goodsSort'] ?? 0;
  245. if ($sort == 1) {
  246. $where['salesOrder'] = 'desc';
  247. } elseif ($sort == 2) {
  248. $where['priceOrder'] = 'desc';
  249. }
  250. if ($selectValue == 1 && isset($tabValue['goodsList']['ids']) && count($tabValue['goodsList']['ids'])) {//手动选商品
  251. $where['ids'] = $tabValue['goodsList']['ids'];
  252. $tabValue['goodsList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
  253. } elseif ((isset($tabValue['selectConfig']['activeValue']) && $tabValue['selectConfig']['activeValue']) || (isset($tabValue['goodsLabel']['activeValue']) && $tabValue['goodsLabel']['activeValue'])) {//选分类 、标签
  254. $cateIds = $tabValue['selectConfig']['activeValue'] ?? [];
  255. if ($cateIds) {
  256. $ids = $storeCategoryServices->getColumn(['pid' => $cateIds], 'id');
  257. if ($ids) {
  258. $cateIds = array_unique(array_merge($cateIds, $ids));
  259. $where['cate_id'] = $cateIds;
  260. }
  261. }
  262. $storeLabelIds = $tabValue['goodsLabel']['activeValue'] ?? [];
  263. if ($storeLabelIds) {
  264. $where['store_label_id'] = $storeLabelIds;
  265. }
  266. $where['type'] = [0, 2];
  267. $where['is_show'] = 1;
  268. $where['is_del'] = 0;
  269. $where['is_verify'] = 1;
  270. $where['ids'] = '';
  271. $tabValue['productList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
  272. }
  273. }
  274. $item['tabConfig']['list'] = $list;
  275. }
  276. }
  277. break;
  278. case 'newVip'://新人专享
  279. $item['newVipList']['list'] = $newcomerServices->getDiyNewcomerList();
  280. break;
  281. case 'shortVideo'://短视频
  282. $item['videoList'] = $videoServices->getDiyVideoList(0);
  283. break;
  284. }
  285. }
  286. } else {
  287. if ($info['value']) {
  288. if (isset($info['value']['d_goodList']['goodsList'])) {
  289. $info['value']['d_goodList']['goodsList']['list'] = [];
  290. }
  291. if (isset($info['value']['d_goodList']['goodsList']['ids']) && count($info['value']['d_goodList']['goodsList']['ids'])) {
  292. $info['value']['d_goodList']['goodsList']['list'] = $services->getSearchList(['ids' => $info['value']['d_goodList']['goodsList']['ids']]);
  293. }
  294. }
  295. }
  296. }
  297. return $this->success(compact('info'));
  298. }
  299. /**
  300. * 获取uni-app路径
  301. * @return mixed
  302. */
  303. public function getUrl()
  304. {
  305. $url = sys_data('uni_app_link');
  306. if ($url) {
  307. foreach ($url as &$link) {
  308. $link['url'] = $link['link'];
  309. $link['parameter'] = trim($link['param']);
  310. }
  311. } else {
  312. /** @var CacheServices $cache */
  313. $cache = app()->make(CacheServices::class);
  314. $url = $cache->getDbCache('uni_app_url', null);
  315. }
  316. return $this->success(compact('url'));
  317. }
  318. /**
  319. * 获取商品分类
  320. * @return mixed
  321. * @throws \think\db\exception\DataNotFoundException
  322. * @throws \think\db\exception\DbException
  323. * @throws \think\db\exception\ModelNotFoundException
  324. */
  325. public function getCategory()
  326. {
  327. /** @var StoreProductCategoryServices $categoryService */
  328. $categoryService = app()->make(StoreProductCategoryServices::class);
  329. $list = $categoryService->cascaderList();
  330. // $data = [];
  331. // foreach ($list as $value) {
  332. // $data[] = [
  333. // 'id' => $value['id'],
  334. // 'title' => $value['html'] . $value['cate_name']
  335. // ];
  336. // }
  337. return $this->success($list);
  338. }
  339. /**
  340. * 获取商品
  341. * @return mixed
  342. */
  343. public function getProduct()
  344. {
  345. $where = $this->request->getMore([
  346. ['id', 0],//搜索分类
  347. ['salesOrder', ''],//销量排序
  348. ['priceOrder', ''],//价格排序
  349. ['supplier_id', 0],//供应商ID
  350. ['store_id', 0],//门店ID
  351. ['store_label_id', ''],//标签ID
  352. ['ids', ''],//商品ID
  353. ]);
  354. $id = $where['id'];
  355. $where['is_show'] = 1;
  356. $where['is_del'] = 0;
  357. $where['is_verify'] = 1;
  358. $where['type'] = [0, 2];
  359. $where['show_type'] = [0, 1];
  360. if ($where['supplier_id']) {
  361. $where['relation_id'] = $where['supplier_id'];
  362. $where['type'] = 2;
  363. } elseif ($where['store_id']) {
  364. $where['relation_id'] = $where['store_id'];
  365. $where['type'] = 1;
  366. } else {
  367. $where['pid'] = 0;
  368. }
  369. unset($where['supplier_id'], $where['store_id']);
  370. unset($where['id']);
  371. /** @var StoreProductCategoryServices $storeCategoryServices */
  372. $storeCategoryServices = app()->make(StoreProductCategoryServices::class);
  373. if ($storeCategoryServices->value(['id' => $id], 'pid')) {
  374. $where['sid'] = $id;
  375. } else {
  376. $where['cid'] = $id;
  377. }
  378. [$page, $limit] = $this->services->getPageValue();
  379. /** @var StoreProductServices $productService */
  380. $productService = app()->make(StoreProductServices::class);
  381. $list = $productService->getSearchList($where, $page, $limit, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
  382. return $this->success($list);
  383. }
  384. /**
  385. * 获取提货点自提开启状态
  386. * @return mixed
  387. */
  388. public function getStoreStatus()
  389. {
  390. $data['store_status'] = 0;
  391. if (sys_config('store_func_status', 1)) {
  392. $data['store_status'] = sys_config('store_self_mention', 0);
  393. }
  394. return $this->success($data);
  395. }
  396. /**
  397. * 设置模版默认数据
  398. * @param $id
  399. * @return mixed
  400. */
  401. public function setDefaultData($id)
  402. {
  403. if (!$id) throw new AdminException('参数错误');
  404. $info = $this->services->get($id);
  405. if ($info) {
  406. $info->default_value = $info->value;
  407. $info->update_time = time();
  408. $info->save();
  409. event('diy.update');
  410. return $this->success('设置成功');
  411. } else {
  412. throw new AdminException('模板不存在');
  413. }
  414. }
  415. /**
  416. * 还原模板数据
  417. * @param $id
  418. * @return mixed
  419. */
  420. public function Recovery($id)
  421. {
  422. if (!$id) throw new AdminException('参数错误');
  423. $info = $this->services->get($id);
  424. if ($info) {
  425. $info->value = $info->default_value;
  426. $info->update_time = time();
  427. $info->save();
  428. event('diy.update');
  429. return $this->success('还原成功');
  430. } else {
  431. throw new AdminException('模板不存在');
  432. }
  433. }
  434. /**
  435. * 获取二级分类
  436. * @return mixed
  437. */
  438. public function getByCategory()
  439. {
  440. $where = $this->request->getMore([
  441. ['pid', -1],
  442. ['name', '']
  443. ]);
  444. /** @var StoreProductCategoryServices $categoryServices */
  445. $categoryServices = app()->make(StoreProductCategoryServices::class);
  446. return $this->success($categoryServices->getALlByIndex($where));
  447. }
  448. /**
  449. * 获取首页推荐不同类型商品的轮播图和商品
  450. * @param $type
  451. * @return mixed
  452. */
  453. public function groom_list($type)
  454. {
  455. $info['list'] = $this->get_groom_list($type);
  456. return $this->success($info);
  457. }
  458. /**
  459. * 实际获取方法
  460. * @param $type
  461. * @return array
  462. */
  463. protected function get_groom_list($type, int $num = 0)
  464. {
  465. /** @var StoreProductServices $services */
  466. $services = app()->make(StoreProductServices::class);
  467. $info = [];
  468. $where = [];
  469. if ($type == 1) {// 精品推荐
  470. $where['is_best'] = 1;
  471. // 精品推荐个数
  472. } else if ($type == 2) {// 热门榜单
  473. $where['is_hot'] = 1;
  474. } else if ($type == 3) {// 首发新品
  475. $where['is_new'] = 1;
  476. } else if ($type == 4) {// 促销单品
  477. $where['is_benefit'] = 1;
  478. } else if ($type == 5) {// 会员商品
  479. $where = [
  480. ['vip_price', '>', 0],
  481. ['is_vip', '=', 1],
  482. ];
  483. }
  484. $info = $services->getRecommendProduct(0, $where, $num);
  485. return $info;
  486. }
  487. /**
  488. * 一键换色
  489. * @param $status
  490. * @return mixed
  491. */
  492. public function colorChange($status, $type)
  493. {
  494. if (!$status) throw new AdminException('参数错误');
  495. $info = $this->services->get(['template_name' => $type, 'type' => 3]);
  496. if ($info) {
  497. $info->value = $status;
  498. $info->update_time = time();
  499. $info->save();
  500. event('diy.update');
  501. $this->services->cacheStrUpdate('color_change_' . $type . '_3', $status);
  502. return $this->success('设置成功');
  503. } else {
  504. throw new AdminException('模板不存在');
  505. }
  506. }
  507. /**
  508. * 获取颜色选择和分类模板选择
  509. * @param $type
  510. * @return mixed
  511. * @throws \think\db\exception\DataNotFoundException
  512. * @throws \think\db\exception\DbException
  513. * @throws \think\db\exception\ModelNotFoundException
  514. */
  515. public function getColorChange($type)
  516. {
  517. $status = (int)$this->services->getColorChange((string)$type);
  518. return $this->success(compact('status'));
  519. }
  520. /**
  521. * 获取单个diy小程序预览二维码
  522. * @param $id
  523. * @return mixed
  524. */
  525. public function getRoutineCode($id)
  526. {
  527. $image = $this->services->getRoutineCode((int)$id);
  528. return $this->success(compact('image'));
  529. }
  530. /**
  531. * 获取会员中心数据
  532. * @return mixed
  533. * @throws \think\db\exception\DataNotFoundException
  534. * @throws \think\db\exception\DbException
  535. * @throws \think\db\exception\ModelNotFoundException
  536. */
  537. public function getMember()
  538. {
  539. $data = $this->services->getMemberData();
  540. return $this->success($data);
  541. }
  542. /**
  543. * 保存个人中心数据
  544. * @return mixed
  545. */
  546. public function memberSaveData()
  547. {
  548. $data = $this->request->postMore([
  549. ['status', 0],
  550. ['order_status', 0],
  551. ['my_banner_status', 0],
  552. ['menu_status', 1],
  553. ['service_status', 1],
  554. ['vip_type', 1],
  555. ['newcomer_status', 1],
  556. ['newcomer_style', 1],
  557. ['routine_my_banner', []],
  558. ['routine_my_menus', []]
  559. ]);
  560. $this->services->memberSaveData($data);
  561. event('diy.update');
  562. return $this->success('保存成功');
  563. }
  564. /**
  565. * 获取开屏广告
  566. * @return mixed
  567. */
  568. public function getOpenAdv()
  569. {
  570. /** @var CacheServices $cacheServices */
  571. $cacheServices = app()->make(CacheServices::class);
  572. $data = $cacheServices->getDbCache('open_adv','');
  573. $data = $data ?: [];
  574. $data['time'] = (float)($data['time'] ?? 3);
  575. $data['interval_time'] = (float)($data['interval_time'] ?? 24);
  576. return app('json')->success($data);
  577. }
  578. /**
  579. * 保存开屏广告
  580. * @return mixed
  581. */
  582. public function openAdvAdd()
  583. {
  584. $data = $this->request->postMore([
  585. ['status', 0],//状态
  586. ['time', 0],//广告时间
  587. ['interval_time', 24],//再次出现间隔时间
  588. ['type', 'pic'],//类型
  589. ['value', []],
  590. ['video_link','']
  591. ]);
  592. if (!$data['type']) {
  593. $data['type'] = 'pic';
  594. }
  595. /** @var CacheServices $cacheServices */
  596. $cacheServices = app()->make(CacheServices::class);
  597. $cacheServices->setDbCache('open_adv', $data);
  598. event('diy.update');
  599. return app('json')->success('保存成功');
  600. }
  601. /**
  602. * 获取商品详情数据
  603. * @return mixed
  604. * @throws \think\db\exception\DataNotFoundException
  605. * @throws \think\db\exception\DbException
  606. * @throws \think\db\exception\ModelNotFoundException
  607. */
  608. public function getProductDetailDiy()
  609. {
  610. $data = $this->services->getProductDetailDiy();
  611. return $this->success($data);
  612. }
  613. /**
  614. * 保存个人中心数据
  615. * @return mixed
  616. */
  617. public function saveProductDetailDiy()
  618. {
  619. [$content] = $this->request->postMore([
  620. ['product_detail_diy', []],
  621. ], true);
  622. $this->services->saveProductDetailDiy($content);
  623. event('diy.update');
  624. return $this->success('保存成功');
  625. }
  626. /**
  627. * 获取新人礼商品
  628. * @param StoreNewcomerServices $newcomerServices
  629. * @return mixed
  630. */
  631. public function newcomerList(StoreNewcomerServices $newcomerServices)
  632. {
  633. $where = $this->request->getMore([
  634. ['priceOrder', ''],
  635. ['salesOrder', ''],
  636. ]);
  637. return app('json')->success($newcomerServices->getDiyNewcomerList(0, $where));
  638. }
  639. }