DiyController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\constants\OptionSetting;
  9. use app\models\Admin;
  10. use app\models\Cat;
  11. use app\models\DeliveryRules;
  12. use app\models\District;
  13. use app\models\DiyTemplate;
  14. use app\models\FoodCat;
  15. use app\models\Goods;
  16. use app\models\FoodExtGoods;
  17. use app\models\GoodsCat;
  18. use app\models\Mch;
  19. use app\models\MdGroupActivitiesGoods;
  20. use app\models\NewDiyTemplate;
  21. use app\models\Order;
  22. use app\models\OrderDetail;
  23. use app\models\SeckillActivity;
  24. use app\models\SeckillActivityGoods;
  25. use app\models\WorkerGoodsExt;
  26. use app\modules\client\controllers\BaseController;
  27. use app\modules\client\models\v1\DiyForm;
  28. use app\modules\client\models\v1\OrderCommentForm;
  29. use app\modules\client\models\v1\OrderListForm;
  30. use app\modules\client\models\v1\StoreListForm;
  31. use yii\helpers\Json;
  32. use app\models\Option;
  33. use app\models\Store;
  34. use app\models\User;
  35. /**
  36. * 测试
  37. */
  38. class DiyController extends BaseController
  39. {
  40. /**
  41. * 获取首页模板
  42. */
  43. public function actionIndex()
  44. {
  45. $template = DiyTemplate::findOne([
  46. 'is_delete' => 0,
  47. 'is_index' => 1,
  48. 'store_id' => get_store_id()
  49. ]);
  50. return $this->asJson([
  51. 'code' => 0,
  52. 'data' => [
  53. 'template' => $template
  54. ]
  55. ]);
  56. }
  57. /**
  58. * 获取DIY模板
  59. */
  60. public function actionTemplate()
  61. {
  62. $template = DiyTemplate::findOne([
  63. 'is_delete' => 0,
  64. 'id' => get_params('id', 0),
  65. 'store_id' => get_store_id()
  66. ]);
  67. return $this->asJson([
  68. 'code' => 0,
  69. 'data' => [
  70. 'template' => $template
  71. ]
  72. ]);
  73. }
  74. /**
  75. * 获取DIY模板
  76. */
  77. public function actionTemplateUnit()
  78. {
  79. $type = get_params('type', 'goods');
  80. $template = DiyTemplate::findOne([
  81. 'is_delete' => 0,
  82. 'type' => $type,
  83. 'store_id' => get_store_id()
  84. ]);
  85. if (is_platform() && $type == 'controls') {
  86. $tabbar = Option::get('tabbar', 0, 'saas', json_encode([]));
  87. $tabbar = json_decode($tabbar['value'], true);
  88. $temp = json_decode($template->template, true);
  89. foreach ($temp as $key => $value) {
  90. if ($value['name'] == '底部导航') {
  91. $temp[$key]['param']['list'] = $tabbar;
  92. }
  93. }
  94. $template->template = json_encode($temp, JSON_UNESCAPED_UNICODE);
  95. }
  96. return $this->asJson([
  97. 'code' => 0,
  98. 'data' => [
  99. 'template' => $template
  100. ]
  101. ]);
  102. }
  103. /**
  104. * 获取商品信息
  105. */
  106. public function actionGoods()
  107. {
  108. $limit = get_params('limit', 20);
  109. $page = get_params('page', 1);
  110. $cat_id = get_params('cat_id', 0);
  111. $activities_id = get_params('activities_id', 0);
  112. $goods_id = get_params('goods_id', Json::encode([]));
  113. $product_type = get_params('product_type');
  114. $this->asJson(DiyForm::getGoods([
  115. 'limit' => $limit,
  116. 'page' => $page,
  117. 'cat_id' => $cat_id,
  118. 'goods_id' => $goods_id,
  119. 'product_type' => $product_type,
  120. 'activities_id' => $activities_id,
  121. ]));
  122. }
  123. /**
  124. * 获取分类
  125. */
  126. public function actionGetCat() {
  127. $store_id = get_store_id();
  128. $data = Cat::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'is_show' => 1, 'parent_id' => 0])
  129. ->select('id, name')->orderBy('sort asc')->asArray()->all();
  130. foreach ($data as &$item) {
  131. $item['title'] = $item['name'];
  132. $item['subTitle'] = $item['name'];
  133. $item['link'] = null;
  134. unset($item['name']);
  135. // $arr2 = array_column($arr, 'name');
  136. $goods = [];
  137. $cat_arr = Cat::find()->where(['parent_id' => $item['id'], 'is_delete' => 0])->select('id')->column();
  138. $cat_arr = array_merge($cat_arr, [$item['id']]);
  139. if (!empty($cat_arr)) {
  140. $cat_arr2 = Cat::find()->where(['parent_id' => $cat_arr, 'is_delete' => 0])->select('id')->column();
  141. $cat_arr = array_merge($cat_arr, $cat_arr2);
  142. }
  143. $goods_cat_arr = GoodsCat::find()->where(['cat_id' => $cat_arr, 'is_delete' => 0])->select('goods_id')->column();
  144. $item['data'] = Goods::find()->where(['id' => $goods_cat_arr, 'is_delete' => 0, 'status' => 1])
  145. ->select('id, name, cover_pic, original_price, price, is_negotiable, virtual_sales')->asArray()->all();
  146. foreach ($item['data'] as $key => &$value) {
  147. $goods = Goods::findOne($value['id']);
  148. $value['virtual_sales'] = $goods->getSalesVolume() + $value['virtual_sales'];
  149. }
  150. }
  151. return $this->asJson([
  152. 'code' => 0,
  153. 'data' => [
  154. 'list' => $data
  155. ]
  156. ]);
  157. }
  158. /**
  159. * 获取服务商品信息
  160. */
  161. public function actionGetWorkerGoods() {
  162. $ids = get_params('goods_id', '');
  163. $product_type = get_params('product_type', 6);
  164. if (intval($product_type) === 6) {
  165. $cat_id = get_params('cat_id');
  166. $query = WorkerGoodsExt::find()->alias('wge')->where(['wge.store_id' => get_store_id(), 'g.status' => 1, 'g.is_delete' => 0])
  167. ->leftJoin(['g' => Goods::tableName()], 'g.id = wge.goods_id');
  168. if (!empty($ids)) {
  169. $ids_ = json_decode($ids, true);
  170. if (empty($ids_)) {
  171. $ids = explode(',', $ids);
  172. } else {
  173. $ids = $ids_;
  174. }
  175. $query->andWhere(['g.id' => $ids]);
  176. }
  177. if ($cat_id) {
  178. $query->andWhere(['wge.cat_id' => $cat_id]);
  179. }
  180. $query->select('g.id, g.name, g.cover_pic, wge.desc, g.price, g.original_price, g.virtual_sales');
  181. } else {
  182. $query = Goods::find()
  183. ->where(['status' => 1, 'is_delete' => 0, 'store_id' => get_store_id()]);
  184. if (!empty($ids)) {
  185. $ids = json_decode($ids, true);
  186. $query->andWhere(['id' => $ids]);
  187. }
  188. $query->select('id, name, cover_pic, price, original_price, virtual_sales');
  189. }
  190. $list = $query->asArray()->all();
  191. foreach ($list as &$item) {
  192. $item['order_num'] = OrderDetail::find()->where(['goods_id' => $item['id']])->groupBy('order_id')->count() ?? 0;
  193. $item['sales'] = OrderDetail::find()->alias('od')->where(['od.goods_id' => $item['id'], 'o.is_pay' => 1])
  194. ->leftJoin(['o' => Order::tableName()], 'o.id = od.order_id')->select('od.num')->sum('od.num') ?? 0;
  195. $item['sales'] += $item['virtual_sales'];
  196. }
  197. return $this->asJson([
  198. 'code' => 0,
  199. 'msg' => '获取成功',
  200. 'data' => [
  201. 'list' => $list
  202. ]
  203. ]);
  204. }
  205. /**
  206. * 获取秒杀商品信息
  207. */
  208. public function actionSeckillActivity()
  209. {
  210. try {
  211. $id = get_params('activeId', 20);
  212. $seckill_activity = SeckillActivity::find()->where([
  213. 'AND',
  214. ['store_id' => get_store_id(), 'is_delete' => 0, 'id' => $id],
  215. ['>', 'end_time', time()]
  216. ])->select('id, start_time, end_time, name')->asArray()->all();
  217. $pagination = [
  218. 'list' => [],
  219. 'pageNo' => 0,
  220. 'totalCount' => 0
  221. ];
  222. if ($seckill_activity) {
  223. foreach ($seckill_activity as &$item) {
  224. $query = SeckillActivityGoods::find()->alias('sag')->where([
  225. 'sag.is_delete' => 0,
  226. 'sag.activity_id' => $item['id']
  227. ])->leftJoin(['g' => Goods::tableName()], 'sag.goods_id = g.id')
  228. ->andWhere([
  229. 'g.status' => 1,
  230. 'g.is_delete' => 0
  231. ])->select("g.id, g.cover_pic, g.delivery_rules_id, g.name, sag.seckill_num,
  232. sag.seckill_price price, g.price original_price, sag.sale_num, sag.attr, sag.use_attr, sag.virtual_sales, sag.virtual_num")->groupBy('g.id');
  233. $pagination = pagination_make($query);
  234. $item['seckill_activity_goods'] = $pagination['list'];
  235. foreach ($item['seckill_activity_goods'] as &$activity_good) {
  236. if ((int)$activity_good['use_attr'] === 1) {
  237. $attr = json_decode($activity_good['attr'], true);
  238. $activity_good['price'] = sprintf('%.2f', $attr[0]['seckill_price']);
  239. }
  240. $activity_good['delivery_rules'] = DeliveryRules::find()->where([
  241. 'id' => $activity_good['delivery_rules_id'],
  242. 'status' => 1, 'is_delete' => 0
  243. ])->select('type, times, days, name')->one();
  244. if ($activity_good['delivery_rules']) {
  245. $days = "下单" . $activity_good['delivery_rules']['days'] . "天后";
  246. $activity_good['delivery_rules']['times'] =
  247. (int)$activity_good['delivery_rules']['type'] === 1 ? $days : date("m月d日 H:i:s", $activity_good['delivery_rules']['times']);
  248. $activity_good['delivery_rules']['type'] .= '';
  249. }
  250. if (((int)$activity_good['seckill_num'] + $activity_good['virtual_sales']) === 0 || ((int)$activity_good['sale_num'] + $activity_good['virtual_sales']) === 0) {
  251. $activity_good['progress'] = 0;
  252. } else {
  253. $activity_good['progress'] = sprintf('%.2f', (($activity_good['sale_num'] * 1) / ($activity_good['seckill_num'] + $activity_good['sale_num'])) * 100);
  254. $activity_good['seckill_num'] <= 0 && $activity_good['progress'] = 100;
  255. if ($item['start_time'] > time()) {
  256. $activity_good['progress'] = 0;
  257. $activity_good['virtual_sales'] = 0;
  258. }
  259. }
  260. // $activity_good['seckill_num'] -= $activity_good['sale_num'];
  261. }
  262. }
  263. }
  264. return $this->asJson([
  265. 'code' => 0,
  266. 'data' => [
  267. 'list' => $seckill_activity,
  268. 'pageNo' => $pagination['pageNo'],
  269. 'totalCount' => $pagination['totalCount']
  270. ],
  271. ]);
  272. } catch (\Exception $e) {
  273. return $this->asJson([
  274. 'code' => 0,
  275. 'data' => []
  276. ]);
  277. }
  278. }
  279. /**
  280. * 获取自提点信息
  281. */
  282. public function actionShop()
  283. {
  284. $limit = get_params('limit', 20);
  285. $page = get_params('page', 1);
  286. $shop_id = get_params('shop_id', Json::encode([]));
  287. $longitude = get_params('longitude', 0);
  288. $latitude = get_params('latitude', 0);
  289. if ($latitude) {
  290. $res = DiyForm::getNearbyShop([
  291. 'limit' => $limit,
  292. 'page' => $page,
  293. 'shop_id' => $shop_id,
  294. 'longitude' => $longitude,
  295. 'latitude' => $latitude
  296. ]);
  297. } else {
  298. $res = DiyForm::getShop([
  299. 'limit' => $limit,
  300. 'page' => $page,
  301. 'shop_id' => $shop_id
  302. ]);
  303. }
  304. $this->asJson($res);
  305. }
  306. /**
  307. * 获取自提点信息
  308. */
  309. public function actionMch()
  310. {
  311. $limit = get_params('limit', 20);
  312. $page = get_params('page', 1);
  313. $mch_id = get_params('mch_id', Json::encode([]));
  314. $longitude = get_params('longitude', 0);
  315. $latitude = get_params('latitude', 0);
  316. if ($latitude) {
  317. $res = DiyForm::getNearbyMch([
  318. 'limit' => $limit,
  319. 'page' => $page,
  320. 'mch_id' => $mch_id,
  321. 'longitude' => $longitude,
  322. 'latitude' => $latitude
  323. ]);
  324. } else {
  325. $res = DiyForm::getMch([
  326. 'limit' => $limit,
  327. 'page' => $page,
  328. 'mch_id' => $mch_id
  329. ]);
  330. }
  331. $this->asJson($res);
  332. }
  333. /**
  334. * 获取首页模板
  335. */
  336. public function actionNewIndex()
  337. {
  338. $params = [
  339. 'is_delete' => 0,
  340. 'is_index' => 1,
  341. 'store_id' => get_store_id()
  342. ];
  343. $id = get_params('id');
  344. if (!empty($id)) {
  345. unset($params['is_index']);
  346. $params['id'] = $id;
  347. }
  348. $template = NewDiyTemplate::findOne($params);
  349. $controls = NewDiyTemplate::find()
  350. ->where([
  351. 'store_id' => get_store_id(),
  352. 'is_delete' => 0,
  353. 'type' => 100,
  354. 'name' => 'controls'
  355. ])->asArray()->one()['template'];
  356. if (is_platform()) {
  357. $controls = '[{"name":"导航","is_show":true,"controlComName":"widgetNavControl","show_type":"nav","params":{"defaultColor":"#2e2d2d","activeColor":"#FCBE40","navList":[{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/a94065d9bc45172db3df618616fa174e6908ad97.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0e337d2c6c92e2bbac7b0e57dc022af250bd574e.png","nav_text":"首页","link":{"name":"首页","link":"/pages/union/home/index","open_type":"switchtab","params":[]}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0f7048ecd1c7d0d30278ca9665beca219ff3e778.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/865006703b674a416be49169c691333ae210d055.png","nav_text":"我的","link":{"name":"用户中心","link":"/pages/my/my","id":375,"open_type":"switchtab","params":[]}}]},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"}},{"name":"弹窗","is_show":false,"show_type":"window","controlComName":"widgetPopupControl","params":{"list":[],"rule":1}},{"name":"电话","is_show":true,"show_type":"list","controlComName":"widgetPhoneControl","params":{"phone":"","picUrl":""}},{"name":"微信客服","is_show":true,"show_type":"list","controlComName":"widgetWxControl","params":{"picUrl":""}}]';
  358. }
  359. $data = [
  360. 'template' => $template,
  361. 'controls' => $controls
  362. ];
  363. $data['show'] = true;
  364. // 已指定会员等级 && (用户未登陆 || 用户的会员等级 != 页面设置的会员等级)
  365. if($template['level'] != 0 && (!get_user() || get_user()->level != $template['level'])){
  366. $data['show'] = false;
  367. }
  368. if (\Yii::$app->prod_is_dandianpu()) {
  369. $store = Store::findOne(get_store_id());
  370. if ($store) {
  371. $data['store_name'] = $store->name;
  372. $data['store_logo'] = $store->logo;
  373. }
  374. $self_mini = Option::get('self_mini', $store->id, 'store', 0)['value'];
  375. $is_store_traffic_sharing = Option::get('is_store_traffic_sharing', $store->id, 'store', 1)['value'];
  376. $switch_store = intval(Option::get('one_store_switch_store', 0, 'saas', 0)['value']);
  377. $is_store_traffic_sharing_switch = false;
  378. if (intval($is_store_traffic_sharing) && !intval($self_mini) && $switch_store) {
  379. $is_store_traffic_sharing_switch = true;
  380. }
  381. $controls = json_decode($data['controls'], true);
  382. foreach ($controls as &$control_item) {
  383. if ($control_item['controlComName'] == 'widgetNavControl') {
  384. $tab_open = true;
  385. foreach ($control_item['params']['navList'] as $nav_index => &$nav_item) {
  386. if (isset($nav_item['tab_type']) && $nav_item['tab_type'] == 'store_sharing') {
  387. $nav_item['link']['link'] = '/allianceStore/index/index';
  388. $nav_item['link']['open_type'] = 'navigate';
  389. if (!$is_store_traffic_sharing_switch) {
  390. unset($control_item['params']['navList'][$nav_index]);
  391. }
  392. $tab_open = false;
  393. }
  394. }
  395. $control_item['params']['navList'] = array_values($control_item['params']['navList']);
  396. if ($tab_open && $is_store_traffic_sharing_switch) {
  397. array_push($control_item['params']['navList'], [
  398. "pic_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/store.png',
  399. "active_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/storeActive.png',
  400. "nav_text" => "联盟商家",
  401. "tab_type" => "store_sharing",
  402. "link" => [
  403. "name" => "联盟商家",
  404. "link" => "/allianceStore/index/index",
  405. "open_type" => "navigate",
  406. "params" => [],
  407. "id" => "9421"
  408. ]
  409. ]);
  410. }
  411. }
  412. }
  413. $data['controls'] = json_encode($controls, JSON_UNESCAPED_UNICODE);
  414. }
  415. if(show_shenhe()){
  416. $this->newIndexShowShenhe($data);
  417. }
  418. return $this->asJson([
  419. 'code' => 0,
  420. 'data' => $data,
  421. ]);
  422. }
  423. public function newIndexShowShenhe(&$data) {
  424. $temp = '{"page_name": "首页","is_index": "1","page_type": 0,"page_link": "","theme": {"color": "","time": 1633765304209},"pageCss": {"margin": 0,"padding": 0,"vSpave": 0,"hSpace": 0,"borderRadius": 0,"borderRaNum": 0,"backgroundColor": "","backgroundImage": "","bgImg": "","bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat"},"templates": [{"name": "头部导航","type": "pageHeader","comName": "pageHeader","controlComName": "pageHeaderControl","moduleCss": {"backgroundColor": "#FFF","backgroundImage": "","bgImg": "","useBackground": true,"bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat"},"params": {"text": "首页","showText": 1,"capsuleType": "0","styleType": "1","mdStyle": "1","css": {"color": "#333","fontNum": "18","fontSize": "","fontStyle": "normal","fontWeight": "bold","textDecoration": "inherit","textAlign": "center"}}},{"name": "产品展示","type": "productShow","comName": "productShow","icon": "icon-chanpinzhanshi","controlComName": "productShowControl","moduleCss": {"backgroundColor": "#FFFFFF","backgroundImage": "","bgImg": "","useBackground": true,"bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat","margin": 0,"padding": 0,"borderRadius": 0},"params": {"moduleNameCss": {"color": "#262626","fontNum": "16","fontSize": "","fontStyle": "normal","fontWeight": "bold","textDecoration": "inherit"},"moduleMoreCss": {"color": "#888888","fontNum": "12","fontSize": "","fontStyle": "normal","fontWeight": "normal","textDecoration": "inherit"},"headerBg": {"backgroundColor": "","backgroundImage": "","bgImg": "","useBackground": true,"bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat"},"styleType": "1","moduleName": "","moreText": "更多","showMoreText": false,"showModuleName": true,"showPrice": true,"showSales": true,"showBuyBtn": false,"productDataFrom": "select","selectData": [],"classifyData": "","classifyArr": [],"buyBtnType": "1","producNameColor": "#1D1D1D","priceColor": "#FA2C1B","originPriceColor": "#9B9B9B","saleColor": "#9B9B9B","buyStyle": "add","buyBtnText": "购买","goodsItemOutSpace": 0,"goodsItemInnerSpace": 0,"link": {}}}],"controlComName": "pageControl","id": "1"}';
  425. $data['template']['template'] = $temp;
  426. $tempArr = json_decode($temp, true);
  427. $miniAuditGoodsIds = Option::get(OptionSetting::ACTIVITY_MINI_AUDIT_GOODS, get_store_id(), '', '')['value'];
  428. if(empty($miniAuditGoodsIds)){
  429. return;
  430. }
  431. $goodsIds = explode(',', $miniAuditGoodsIds);
  432. foreach($goodsIds as $id){
  433. $item = [
  434. 'id' => $id,
  435. ];
  436. $tempArr['templates'][1]['params']['selectData'][] = $item;
  437. }
  438. $data['template']['template'] = json_encode($tempArr, JSON_UNESCAPED_UNICODE);
  439. }
  440. /**
  441. * 获取DIY模板
  442. */
  443. public function actionNewTemplateUnit()
  444. {
  445. $id = get_params('id');
  446. $template = NewDiyTemplate::findOne($id);
  447. // if (is_platform() && $template->type = 100) {
  448. // $tabbar = Option::get('tabbar', 0, 'saas', json_encode([]));
  449. // $tabbar = json_decode($tabbar['value'], true);
  450. // $temp = json_decode($template->template, true);
  451. // foreach ($temp as $key => $value) {
  452. // if ($value['name'] == '底部导航') {
  453. // $temp[$key]['param']['list'] = $tabbar;
  454. // }
  455. // }
  456. // $template->template = json_encode($temp, JSON_UNESCAPED_UNICODE);
  457. // }
  458. return $this->asJson([
  459. 'code' => 0,
  460. 'data' => [
  461. 'template' => $template,
  462. 'controls' => NewDiyTemplate::find()
  463. ->where([
  464. 'store_id' => get_store_id(),
  465. 'is_delete' => 0,
  466. 'type' => 100
  467. ])->asArray()->one()['template']
  468. ]
  469. ]);
  470. }
  471. public function actionGetFoodsCatList() {
  472. $data = FoodCat::find()->where([
  473. 'store_id' => get_store_id(),
  474. 'is_delete' => 0,
  475. 'is_show' => 1,
  476. 'md_id' => get_md_id() < 1 ? [0, -1] : get_md_id()
  477. ])->select('id, name')->asArray()->all();
  478. foreach ($data as &$item) {
  479. $item['title'] = $item['name'];
  480. $item['subTitle'] = $item['name'];
  481. $item['link'] = null;
  482. $item['dataFrom'] = "classify";
  483. $item['classifyId'] = $item['id'];
  484. unset($item['name']);
  485. $where['cat_id'] = $item['id'];
  486. $item['data'] = Goods::find()->where(['cat_id' => $item['id'], 'is_delete' => 0, 'status' => 1])
  487. ->select('id, name, cover_pic, original_price, price, is_negotiable, virtual_sales, attr, use_attr')->asArray()->all();
  488. foreach ($item['data'] as &$goods) {
  489. $once_goods = Goods::findOne($goods['id']);
  490. $goods['attr'] = json_decode($goods['attr'], true);
  491. $goods['use_attr'] *= 1;
  492. $attr_group_list = null;
  493. if ($once_goods) {
  494. $attr_group_list = $once_goods->getAttrGroupList();
  495. }
  496. $goods['attr_group_list'] = $attr_group_list;
  497. }
  498. }
  499. return $this->asJson([
  500. 'code' => 0,
  501. 'msg' => '获取成功',
  502. 'data' => [
  503. 'list' => $data,
  504. ]
  505. ]);
  506. }
  507. public function actionGetFoodsList() {
  508. try {
  509. $params = get_params();
  510. $where = [
  511. 'store_id' => get_store_id(),
  512. 'md_food_id' => get_md_id() < 1 ? -1 : get_md_id(),
  513. 'is_delete' => 0,
  514. 'status' => 1
  515. ];
  516. if ($params['goods_id']) {
  517. if (is_string($params['goods_id'])) {
  518. $params['goods_id'] = explode(',', $params['goods_id']);
  519. } else {
  520. try {
  521. $params['goods_id'] = json_decode($params['goods_id'], true);
  522. } catch (\Exception $e) {
  523. }
  524. }
  525. $where['id'] = $params['goods_id'];
  526. }
  527. if ($params['cat_id']) {
  528. $where['cat_id'] = $params['cat_id'];
  529. }
  530. $goods = Goods::find()->where($where)->select('id, food_ext_goods_id, md_food_id, store_id, name, cover_pic, price, original_price, virtual_sales, product_type, attr, use_attr')->asArray()->all();
  531. foreach ($goods as &$good) {
  532. $good['attr'] = json_decode($good['attr'], true);
  533. $good['use_attr'] *= 1;
  534. $once_goods = Goods::findOne($good['id']);
  535. $attr_group_list = null;
  536. if ($once_goods) {
  537. $attr_group_list = $once_goods->getAttrGroupList();
  538. }
  539. $good['attr_group_list'] = $attr_group_list;
  540. $feg = [];
  541. $good['food_ext_goods'] = FoodExtGoods::getAttr($good['food_ext_goods_id'], $good['store_id'], $good['md_food_id'], $feg);
  542. $good['food_ext_goods_model'] = $feg;
  543. }
  544. return $this->asJson([
  545. 'code' => 0,
  546. 'msg' => '获取成功',
  547. 'data' => [
  548. 'goods' => $goods,
  549. ]
  550. ]);
  551. } catch (\Exception $e) {
  552. return $this->asJson([
  553. 'code' => 1,
  554. 'data' => $e->getMessage()
  555. ]);
  556. }
  557. }
  558. /**
  559. * 系统页面列表
  560. * @return \yii\web\Response
  561. */
  562. public function actionSystemTemplateList() {
  563. $store_id = get_store_id();
  564. $list = NewDiyTemplate::find()
  565. ->where([
  566. 'store_id' => $store_id,
  567. 'is_delete' => 0,
  568. 'name' => 'system'
  569. ])->orderBy(['id' => SORT_ASC])->asArray()->all();
  570. $form = new OrderListForm();
  571. $form->store_id = $store_id;
  572. $form->user_id = get_user_id();
  573. foreach ($list as &$item) {
  574. if ($item['template']) {
  575. $template = json_decode($item['template'], true);
  576. if ($template['system_type'] === 'my') {
  577. foreach ($template['templates'] as &$tem_) {
  578. if ($tem_['comName'] === 'userMember' && $tem_['params']['showMemberCode'] === null) {
  579. $tem_['params'] = array_merge($tem_['params'], ['showMemberCode' => true]);
  580. }
  581. /* begin 2024/03/28 16:09:20 新增分销商条件为后台指定的判断 WPing丶 */
  582. $setting = Option::get('share_basic_setting', $store_id);
  583. $setting = $setting ? Json::decode($setting['value']) : [];
  584. $share_condition = $setting['share_condition']['value'];
  585. if($share_condition == 3 && $tem_['comName'] === 'userTools') {
  586. foreach($tem_['params']['list'] as $ut_key => $ut_item) {
  587. $user = User::findOne(get_user_id());
  588. if(($ut_item['link']['link'] == "/user/share/index" || $ut_item['link']['link'] == "\/user\/share\/index") && $user->is_distributor != 1) {
  589. unset($tem_['params']['list'][$ut_key]);
  590. }
  591. }
  592. }
  593. /* end */
  594. if($tem_['comName'] === 'userOrder'){
  595. $hostInfo = \Yii::$app->request->hostName;
  596. $default_tab_list = [
  597. [
  598. "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitPay.png",
  599. "tabText" => "待付款",
  600. "link" => [],
  601. "controlComName" => "userOrderTabItemControl",
  602. "controlComKey" => "userOrderTabWaitPay",
  603. "checked" => true
  604. ],
  605. [
  606. "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitSendOrder.png",
  607. "tabText" => "待发货",
  608. "link" => [],
  609. "controlComName" => "userOrderTabItemControl",
  610. "controlComKey" => "userOrderTabWaitSendOrder",
  611. "checked" => true
  612. ],
  613. [
  614. "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitIncome.png",
  615. "tabText" => "待收货",
  616. "link" => [],
  617. "controlComName" => "userOrderTabItemControl",
  618. "controlComKey" => "userOrderTabWaitIncome",
  619. "checked" => true
  620. ],
  621. [
  622. "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabComplete.png",
  623. "tabText" => "已完成",
  624. "link" => [],
  625. "controlComName" => "userOrderTabItemControl",
  626. "controlComKey" => "userOrderTabComplete",
  627. "checked" => true
  628. ],
  629. // [
  630. // "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitComment.png",
  631. // "tabText" => "待评价",
  632. // "link" => [],
  633. // "controlComName" => "userOrderTabItemControl",
  634. // "controlComKey" => "userOrderTabWaitComment",
  635. // "checked" => false
  636. // ],
  637. [
  638. "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabHandleRefund.png",
  639. "tabText" => "退换售后",
  640. "link" => [],
  641. "controlComName" => "userOrderTabItemControl",
  642. "controlComKey" => "userOrderTabHandleRefund",
  643. "checked" => true
  644. ]
  645. ];
  646. //如果没有controlComKey 则认为是使用的老版本
  647. if (!isset($tem_['params']['tabsList'][0]['controlComKey'])) {
  648. $tem_['params']['tabsList'] = $default_tab_list;
  649. }
  650. foreach ($tem_['params']['tabsList'] as &$tab_item) {
  651. switch ($tab_item['controlComKey']) {
  652. case 'userOrderTabWaitPay'://待付款
  653. $form->status = 0;
  654. $tab_item['order_count'] = $form->searchOrderCount();
  655. break;
  656. case 'userOrderTabWaitSendOrder'://待发货
  657. $form->status = 1;
  658. $tab_item['order_count'] = $form->searchOrderCount();
  659. break;
  660. case 'userOrderTabWaitIncome'://待收货
  661. $form->status = 2;
  662. $tab_item['order_count'] = $form->searchOrderCount();
  663. break;
  664. case 'userOrderTabComplete'://已完成
  665. $form->status = 3;
  666. $tab_item['order_count'] = $form->searchOrderCount();
  667. break;
  668. case 'userOrderTabWaitComment'://已完成
  669. $tab_item['order_count'] = OrderCommentForm::commonComment(get_user_id())->count();
  670. break;
  671. default:
  672. $form->status = 0;
  673. $tab_item['order_count'] = 0;
  674. break;
  675. }
  676. }
  677. }
  678. if ($tem_['comName'] === 'userWallet') {
  679. $open = false;
  680. foreach ($tem_['params']['list'] as $i) {
  681. if ($i['controlComName'] === 'walletItemControl' && !isset($i['walletItemType'])){
  682. $open = true;
  683. break;
  684. }
  685. }
  686. //优化我的钱包字段 增加类型 方便判断
  687. if ($open) {
  688. $tem_['params']['list'] = [
  689. [
  690. "name" => "积分",
  691. "subName" => "",
  692. "controlComName" => "walletItemControl",
  693. "walletItemType" => "walletIntegral",
  694. "color" => "#262626",
  695. "subColor" => "#bbbbbb"
  696. ],
  697. // [
  698. // "name" => "优惠券",
  699. // "subName" => "",
  700. // "controlComName" => "walletItemControl",
  701. // "walletItemType" => "walletCoupon",
  702. // "color" => "#262626",
  703. // "subColor" => "#bbbbbb"
  704. // ],
  705. [
  706. "name" => "余额",
  707. "subName" => "",
  708. "controlComName" => "walletItemControl",
  709. "walletItemType" => "walletBalance",
  710. "color" => "#262626",
  711. "subColor" => "#bbbbbb"
  712. ],
  713. [
  714. "name" => "联盟券",
  715. "subName" => "",
  716. "controlComName" => "walletItemControl",
  717. "walletItemType" => "walletLeaguePrice",
  718. "color" => "#262626",
  719. "subColor" => "#bbbbbb"
  720. ]
  721. ];
  722. }
  723. //判断如果是数字门店 || 独立部署版本 || 装修开关关闭状态就需要不展示联盟券
  724. if (\Yii::$app->prod_is_saas() || !is_open_platform() || (isset($tem_['showCoupon']) && !intval($tem_['showCoupon']))) {
  725. foreach ($tem_['params']['list'] as $params_index => $params_item) {
  726. if ($params_item['walletItemType'] === 'walletLeaguePrice') {
  727. unset($tem_['params']['list'][$params_index]);
  728. }
  729. }
  730. $tem_['params']['list'] = array_values($tem_['params']['list']);
  731. }
  732. }
  733. }
  734. }
  735. $item['template'] = json_encode($template);
  736. }
  737. }
  738. $controls = NewDiyTemplate::find()
  739. ->where([
  740. 'store_id' => get_store_id(),
  741. 'is_delete' => 0,
  742. 'type' => 100,
  743. 'name' => 'controls'
  744. ])->asArray()->one()['template'];
  745. if (is_platform()) {
  746. $controls = '[{"name":"导航","is_show":true,"controlComName":"widgetNavControl","show_type":"nav","params":{"defaultColor":"#2e2d2d","activeColor":"#FCBE40","navList":[{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/a94065d9bc45172db3df618616fa174e6908ad97.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0e337d2c6c92e2bbac7b0e57dc022af250bd574e.png","nav_text":"首页","link":{"name":"首页","link":"/pages/union/home/index","open_type":"switchtab","params":[]}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0f7048ecd1c7d0d30278ca9665beca219ff3e778.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/865006703b674a416be49169c691333ae210d055.png","nav_text":"我的","link":{"name":"用户中心","link":"/pages/my/my","id":375,"open_type":"switchtab","params":[]}}]},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"}},{"name":"弹窗","is_show":false,"show_type":"window","controlComName":"widgetPopupControl","params":{"list":[],"rule":1}},{"name":"电话","is_show":true,"show_type":"list","controlComName":"widgetPhoneControl","params":{"phone":"","picUrl":""}},{"name":"微信客服","is_show":true,"show_type":"list","controlComName":"widgetWxControl","params":{"picUrl":""}}]';
  747. }
  748. if (\Yii::$app->prod_is_dandianpu()) {
  749. $self_mini = Option::get('self_mini', get_store_id(), 'store', 0)['value'];
  750. $is_store_traffic_sharing = Option::get('is_store_traffic_sharing', get_store_id(), 'store', 1)['value'];
  751. $switch_store = intval(Option::get('one_store_switch_store', 0, 'saas', 0)['value']);
  752. $is_store_traffic_sharing_switch = false;
  753. if (intval($is_store_traffic_sharing) && !intval($self_mini) && $switch_store) {
  754. $is_store_traffic_sharing_switch = true;
  755. }
  756. $controls_arr = json_decode($controls, true);
  757. foreach ($controls_arr as &$control_item) {
  758. if ($control_item['controlComName'] == 'widgetNavControl') {
  759. $tab_open = true;
  760. foreach ($control_item['params']['navList'] as $nav_index => &$nav_item) {
  761. if (isset($nav_item['tab_type']) && $nav_item['tab_type'] == 'store_sharing') {
  762. $nav_item['link']['link'] = '/allianceStore/index/index';
  763. $nav_item['link']['open_type'] = 'navigate';
  764. if (!$is_store_traffic_sharing_switch) {
  765. unset($control_item['params']['navList'][$nav_index]);
  766. }
  767. $tab_open = false;
  768. }
  769. }
  770. $control_item['params']['navList'] = array_values($control_item['params']['navList']);
  771. if ($tab_open && $is_store_traffic_sharing_switch) {
  772. array_push($control_item['params']['navList'], [
  773. "pic_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/store.png',
  774. "active_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/storeActive.png',
  775. "nav_text" => "联盟商家",
  776. "tab_type" => "store_sharing",
  777. "link" => [
  778. "name" => "联盟商家",
  779. "link" => "/allianceStore/index/index",
  780. "open_type" => "navigate",
  781. "params" => [],
  782. "id" => "9421"
  783. ]
  784. ]);
  785. }
  786. }
  787. }
  788. $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE);
  789. }
  790. return $this->asJson([
  791. 'code' => 0,
  792. 'msg' => '加载成功',
  793. 'data' => [
  794. 'list' => $list,
  795. 'controls' => $controls,
  796. ]
  797. ]);
  798. }
  799. //获取商城信息
  800. public function actionGetStore() {
  801. $longitude = input_params('longitude', '');
  802. $latitude = input_params('latitude', '');
  803. $store = Store::find()->alias('s')->where(['s.id' => get_store_id()])
  804. ->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id')
  805. ->select('s.id, s.name, s.logo, s.province_id, s.district_id, s.city_id, s.contact_tel mobile, s.address
  806. , s.shop_time_type, s.s_time, s.e_time, s.open_status, s.coordinate')->asArray()->one();
  807. $arr = [$store['province_id'], $store['city_id'], $store['district_id']];
  808. $District = District::find()->where(['id' => $arr])->select('name')->asArray()->column();
  809. [$store['province'], $store['city'], $store['district']] = $District;
  810. $store['distance'] = '';
  811. if (!empty($store['coordinate']) && !empty($longitude) && !empty($latitude)) {
  812. $coordinate = explode(',', $store['coordinate']);
  813. $from = [$longitude, $latitude];
  814. $store['distance'] = $this->distance((new StoreListForm())->get_distance($from, $coordinate, false, 2));
  815. }
  816. // $arr = [
  817. // "id" => 'id',
  818. // 'name' => '商城名称',
  819. // 'logo' => 'logo',
  820. // 'province_id' => '省',
  821. // 'city_id' => '市',
  822. // 'district_id' => '区',
  823. // 'address' => '详细地址',
  824. // 'mobile' => '电话号码',
  825. // 'shop_time_type' => '0:默认全天,1:时间段',
  826. // 's_time' => '开始时间',
  827. // 'e_time' => '结束时间',
  828. // 'open_status' => '营业状态,0:打烊,1:营业'
  829. // ];
  830. return $this->asJson([
  831. 'code' => 0,
  832. 'msg' => "获取成功",
  833. 'data' => $store
  834. ]);
  835. }
  836. private static function distance($distance)
  837. {
  838. if ($distance == -1) {
  839. return -1;
  840. }
  841. if ($distance > 1000) {
  842. $distance = round($distance / 1000, 2) . 'km';
  843. } else {
  844. $distance .= 'm';
  845. }
  846. return $distance;
  847. }
  848. public function actionGetMchList(){
  849. $mchIds = \Yii::$app->request->post('shop_ids');
  850. $catId = \Yii::$app->request->post('cat_id');
  851. $lat = \Yii::$app->request->post('latitude');
  852. $lng = \Yii::$app->request->post('longitude');
  853. $query = Mch::find()->where(['is_delete' => 0,'store_id' => get_store_id(),'is_open' => Mch::IS_OPEN_TRUE])->select('id,name,logo,address');
  854. if(!empty($mchIds)){
  855. $query->andWhere(['id' => explode(',', $mchIds)]);
  856. }
  857. if(!empty($catId)){
  858. $query->andWhere(['mch_common_cat_id' => $catId]);
  859. }
  860. if($lat && $lng){
  861. $queryDis = 'ROUND(st_distance_sphere(point('. $lng .', '. $lat .'), point(longitude, latitude)), 2)';
  862. $query->addSelect([$queryDis . ' dis']);
  863. $query->orderBy('dis ASC, sort DESC');
  864. }
  865. $list = $query->asArray()->all();
  866. foreach($list as &$item){
  867. $item['goodsInfo'] = Goods::find()->where(['mch_id' => $item['id'], 'is_delete' => 0, 'status' => 1])->limit(6)->select('id,name,cover_pic,price,original_price')->asArray()->all();
  868. if(!isset($item['dis'])){
  869. $item['dis'] = '未知';
  870. }else{
  871. if($item['dis'] > 1000){
  872. $item['dis'] = round($item['dis'] / 1000, 2) . 'km';
  873. }else{
  874. $item['dis'] .= 'm';
  875. }
  876. }
  877. }
  878. return $this->asJson([
  879. 'code' => 0,
  880. 'msg' => '加载成功',
  881. 'data' => [
  882. 'list' => $list
  883. ]
  884. ]);
  885. }
  886. }