DiyController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\controllers;
  8. use app\constants\MchPickLink;
  9. use app\constants\NavbarLink;
  10. use app\constants\PickLink;
  11. use app\models\DeliveryRules;
  12. use app\models\DiyTemplate;
  13. use app\models\NewDiyTemplate;
  14. use app\models\Order;
  15. use app\models\OrderDetail;
  16. use app\models\SeckillActivity;
  17. use app\models\SeckillActivityGoods;
  18. use app\modules\alliance\models\NewDiyForm;
  19. use app\models\Store;
  20. use app\models\Cat;
  21. use app\models\Goods;
  22. use app\models\FoodCat;
  23. use app\models\WechatConfig;
  24. use app\models\Option;
  25. use yii\base\BaseObject;
  26. use yii\helpers\Json;
  27. use app\utils\Tools;
  28. use app\models\SaasCategory;
  29. /**
  30. * Class GoodsController
  31. * @package app\modules\admin\controllers
  32. */
  33. class DiyController extends BaseController
  34. {
  35. private $alliance_store_id = -1; //联盟店铺id=-1
  36. private $store_goods_limit = 6; //商城下展示商品数量
  37. /**
  38. * 获取导航列表 保留结构后期根据项目新建权限
  39. * @return \yii\web\Response
  40. */
  41. public function actionGetLink()
  42. {
  43. return $this->asJson([
  44. 'code' => 0,
  45. 'data' => [
  46. 'list' => NavbarLink::getLink()
  47. ]
  48. ]);
  49. }
  50. /**
  51. * 获取商品信息
  52. */
  53. public function actionGoods()
  54. {
  55. $store_id = post_params('store_id', -1);
  56. $limit = post_params('limit', 20);
  57. $page = post_params('page', 1);
  58. $cat_id = post_params('cat_id', 0);
  59. $goods_id = post_params('goods_id');
  60. $product_type = post_params('product_type', 0);
  61. $this->asJson(NewDiyForm::getGoods([
  62. 'store_id' => $store_id,
  63. 'limit' => $limit,
  64. 'page' => $page,
  65. 'cat_id' => $cat_id,
  66. 'goods_id' => $goods_id,
  67. 'product_type' => $product_type,
  68. ]));
  69. }
  70. /**
  71. * 获取服务商品信息
  72. */
  73. public function actionGetWorkerGoods() {
  74. $ids = get_params('goods_id', '');
  75. $product_type = get_params('product_type', 6);
  76. $query = Goods::find()
  77. ->where(['status' => 1, 'is_delete' => 0, 'store_id' => get_store_id()]);
  78. if (!empty($ids)) {
  79. $ids = json_decode($ids, true);
  80. $query->andWhere(['id' => $ids]);
  81. }
  82. $query->select('id, name, cover_pic, price, original_price, virtual_sales');
  83. $list = $query->asArray()->all();
  84. foreach ($list as &$item) {
  85. $item['order_num'] = OrderDetail::find()->where(['goods_id' => $item['id']])->groupBy('order_id')->count() ?? 0;
  86. $item['sales'] = OrderDetail::find()->alias('od')->where(['od.goods_id' => $item['id'], 'o.is_pay' => 1])
  87. ->leftJoin(['o' => Order::tableName()], 'o.id = od.order_id')->select('od.num')->sum('od.num') ?? 0;
  88. $item['sales'] += $item['virtual_sales'];
  89. $item['sales'] += $item['virtual_sales'];
  90. }
  91. return $this->asJson([
  92. 'code' => 0,
  93. 'msg' => '获取成功',
  94. 'data' => [
  95. 'list' => $list
  96. ]
  97. ]);
  98. }
  99. /**
  100. * 获取店铺AppId
  101. */
  102. public function actionGetAppid(){
  103. $store_id = post_params('new_store_id',0);
  104. if(!is_numeric($store_id)){
  105. return $this->asJson([
  106. 'code' => 1,
  107. 'msg' => '店铺信息有误'
  108. ]);
  109. }
  110. if ($store_id <= 0) {
  111. return $this->asJson([
  112. 'code' => 0,
  113. 'data' => [
  114. "wechat_app_id" => "",
  115. "gh_wechat_app_id" => "",
  116. "alipay_app_id" => "",
  117. "id" => 0,
  118. "name" => "平台自营",
  119. "business_model" => 2
  120. ]
  121. ]);
  122. }
  123. $storeInfo = Store::find()->where(['id'=>$store_id,'is_delete'=>0])->asArray()->one();
  124. if(!$storeInfo){
  125. return $this->asJson([
  126. 'code' => 1,
  127. 'msg' => '店铺信息有误'
  128. ]);
  129. }
  130. $wechatInfo = WechatConfig::find()->where(['store_id'=>$store_id,'is_delete'=>0,'type'=>1])->asArray()->one();
  131. if($wechatInfo){
  132. $storeInfo['wechat_app_id'] = $wechatInfo['app_id'];
  133. $storeInfo['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id'];
  134. }
  135. $alipayInfo = Option::get('alipay_config',$store_id,'alipay');
  136. if($alipayInfo && $alipayInfo['value']){
  137. $alipayInfo = json_decode($alipayInfo['value'],true);
  138. $storeInfo['alipay_app_id'] = $alipayInfo['app_id'];
  139. }
  140. return $this->asJson([
  141. 'code' => 0,
  142. 'data' => $storeInfo
  143. ]);
  144. }
  145. /**
  146. * 获取diy店铺信息
  147. */
  148. public function actionStoreInfo(){
  149. $latitude = (float)post_params('latitude', 0);
  150. $longitude = (float)post_params('longitude', 0);
  151. $shop_ids = post_params('shop_ids');
  152. $cat_id = post_params('cat_id');
  153. $page = post_params('page',1);
  154. $pageSize = post_params('pageSize',10);
  155. if($latitude && $longitude && !$shop_ids && !$cat_id){
  156. //$storeInfo = $this->getStoreInfoByDistance($latitude,$longitude,$page,$pageSize);
  157. $storeInfo = [];
  158. return $this->asJson([
  159. 'code' => 0,
  160. 'msg' => 'success',
  161. 'data' => $storeInfo
  162. ]);
  163. }
  164. if(!empty($shop_ids)){
  165. // $sql = 'UPDATE cyy_store,(SELECT id d,REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(`coordinate`, ",", 2)), ",", 1)) c from cyy_store) b SET cyy_store.latitude=b.c where cyy_store.id =b.d;
  166. //UPDATE cyy_store,(SELECT id, SUBSTRING_INDEX(`coordinate`, ",", 1) c from cyy_store) b SET cyy_store.longitude=b.c where cyy_store.id =b.id;';
  167. $query = Store::find();
  168. $shop_ids = implode(',', $shop_ids);
  169. $sql = "select id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model,longitude, latitude,acos(cos({$latitude}*pi()/180 )*cos(latitude*pi()/180)*cos({$longitude}*pi()/180 -longitude*pi()/180)+sin({$latitude}*pi()/180 )*sin(latitude*pi()/180))*6370996.81 as
  170. distance from cyy_store where is_delete = 0 and open_status = 1 and id in ({$shop_ids}) ORDER BY distance ASC";
  171. $storeInfo = \Yii::$app->db->createCommand($sql)->queryAll();
  172. // $storeInfo = $query->where(['in','id',$shop_ids])->andWhere(['is_delete'=>0,'open_status'=>1])->select("id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model")->asArray()->all();
  173. if(count($storeInfo) > 0 ){
  174. foreach($storeInfo as $k=>$v){
  175. if($v['distance']){
  176. $storeInfo[$k]['distance'] = $this->distance($v['distance']);
  177. }else{
  178. $storeInfo[$k]['distance'] = '0m';
  179. }
  180. if($v['category_id']){
  181. // $categoryInfo = Cat::find()->where(['id'=>$v['category_id'],'is_delete'=>0])->asArray()->one();
  182. // if($categoryInfo){
  183. // $storeInfo[$k]['category_name'] = $categoryInfo['name'];
  184. // }else{
  185. // $storeInfo[$k]['category_name'] = '';
  186. // }
  187. $cat = SaasCategory::findOne($v['category_id']);
  188. if ($cat) {
  189. $storeInfo[$k]['category_name'] = $cat->name;
  190. }else{
  191. $storeInfo[$k]['category_name'] = '';
  192. }
  193. }else{
  194. $storeInfo[$k]['category_name'] = '';
  195. }
  196. if($v['business_model']==3){
  197. $goodsInfo = [];
  198. }elseif($v['business_model']==4){
  199. $goodsInfo = Goods::find()->alias('g')
  200. ->leftJoin(['fc' => FoodCat::tableName()], 'fc.id=g.cat_id')
  201. ->where(['g.store_id' => $v['id'], 'g.is_delete' => 0])
  202. ->andWhere(['g.md_food_id' => -1])->select("g.id,g.name,g.price,g.original_price,g.cover_pic")->limit($this->store_goods_limit)->asArray()
  203. ->orderBy('g.sort DESC')->all();
  204. }else{
  205. //获取6条商品记录
  206. $goodsInfo = Goods::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'status'=>1])->andWhere(['md_food_id' => 0])->select("id,name,price,original_price,cover_pic")
  207. ->limit($this->store_goods_limit)->orderBy('sort DESC')->asArray()->all();
  208. }
  209. if(count($goodsInfo) > 0){
  210. $storeInfo[$k]['goodsInfo'] = $goodsInfo;
  211. }else{
  212. $storeInfo[$k]['goodsInfo'] = [];
  213. }
  214. $wechatInfo = WechatConfig::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'type'=>1])->asArray()->one();
  215. if($wechatInfo){
  216. $storeInfo[$k]['wechat_app_id'] = $wechatInfo['app_id'];
  217. $storeInfo[$k]['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id'];
  218. }
  219. $alipayInfo = Option::get('alipay_config',$v['id'],'alipay');
  220. if($alipayInfo && $alipayInfo['value']){
  221. $alipayInfo = json_decode($alipayInfo['value'],true);
  222. $storeInfo[$k]['alipay_app_id'] = $alipayInfo['app_id'];
  223. }
  224. }
  225. }
  226. return $this->asJson([
  227. 'code' => 0,
  228. 'msg' => 'success',
  229. 'data' => [
  230. 'data' => $storeInfo
  231. ]
  232. ]);
  233. }
  234. if(!empty($cat_id)){
  235. // $query = Store::find();
  236. $sql = "select id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model, longitude, latitude,acos(cos({$latitude}*pi()/180 )*cos(latitude*pi()/180)*cos({$longitude}*pi()/180 -longitude*pi()/180)+sin({$latitude}*pi()/180 )*sin(latitude*pi()/180))*6370996.81 as
  237. distance from cyy_store where is_delete = 0 and open_status = 1 AND category_id={$cat_id} AND business_model!=1";
  238. // $storeInfo = $query->where(['is_delete'=>0,'open_status'=>1,'category_id'=>$cat_id])->select("id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model");
  239. // $countQuery = clone $query;
  240. $count = \Yii::$app->db->createCommand($sql)->queryScalar();
  241. $offset = ($page - 1) * $pageSize;
  242. $sql .= " ORDER BY distance ASC LIMIT {$pageSize} OFFSET {$offset}";
  243. $list['list'] = \Yii::$app->db->createCommand($sql)->queryAll();
  244. // $query->offset(($page - 1) * $pageSize)->limit($pageSize);
  245. // $list['list'] = $query->asArray()->all();
  246. if(count($list['list']) > 0 ){
  247. foreach($list['list'] as $k=>$v){
  248. if($v['distance']){
  249. $list['list'][$k]['distance'] = $this->distance($v['distance']);
  250. }else{
  251. $list['list'][$k]['distance'] = '0m';
  252. }
  253. if($v['category_id']){
  254. $categoryInfo = SaasCategory::find()->where(['id'=>$v['category_id'],'is_delete'=>0])->asArray()->one();
  255. if($categoryInfo){
  256. $list['list'][$k]['category_name'] = $categoryInfo['name'];
  257. }else{
  258. $list['list'][$k]['category_name'] = '';
  259. }
  260. }else{
  261. $list['list'][$k]['category_name'] = '';
  262. }
  263. if($v['business_model']==3){
  264. $goodsInfo = [];
  265. }elseif($v['business_model']==4){
  266. $goodsInfo = Goods::find()->alias('g')
  267. ->leftJoin(['fc' => FoodCat::tableName()], 'fc.id=g.cat_id')
  268. ->where(['g.store_id' => $v['id'], 'g.is_delete' => 0])
  269. ->andWhere(['g.md_food_id' => -1])->select("g.id,g.name,g.price,g.original_price,g.cover_pic")
  270. ->limit($this->store_goods_limit)->asArray()->orderBy('g.sort DESC')->all();
  271. }else{
  272. //获取6条商品记录
  273. $goodsInfo = Goods::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'status'=>1])->andWhere(['md_food_id' => 0])
  274. ->select("id,name,price,original_price,cover_pic")->limit($this->store_goods_limit)
  275. ->orderBy('sort DESC')->asArray()->all();
  276. }
  277. if(count($goodsInfo) > 0){
  278. $list['list'][$k]['goodsInfo'] = $goodsInfo;
  279. }else{
  280. $list['list'][$k]['goodsInfo'] = [];
  281. }
  282. $wechatInfo = WechatConfig::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'type'=>1])->asArray()->one();
  283. if($wechatInfo){
  284. $list['list'][$k]['wechat_app_id'] = $wechatInfo['app_id'];
  285. $list['list'][$k]['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id'];
  286. }
  287. $alipayInfo = Option::get('alipay_config',$v['id'],'alipay');
  288. if($alipayInfo && $alipayInfo['value']){
  289. $alipayInfo = json_decode($alipayInfo['value'],true);
  290. $list['list'][$k]['alipay_app_id'] = $alipayInfo['app_id'];
  291. }
  292. }
  293. }
  294. return $this->asJson([
  295. 'code' => 0,
  296. 'msg' => 'success',
  297. 'data' => [
  298. 'data' => $list['list'],
  299. 'page' => $page,
  300. 'totalCount' => $count
  301. ]
  302. ]);
  303. }
  304. return $this->asJson([
  305. 'code' => 0,
  306. 'msg' => 'success',
  307. 'data' => []
  308. ]);
  309. }
  310. public static function distance($distance)
  311. {
  312. if ($distance == -1) {
  313. return -1;
  314. }
  315. if ($distance > 1000) {
  316. $distance = round($distance / 1000, 2) . 'km';
  317. } else {
  318. $distance = round($distance, 2);
  319. $distance .= 'm';
  320. }
  321. return $distance;
  322. }
  323. private function getStoreInfoByDistance($latitude,$longitude,$page=1,$pageSize=10){
  324. $connection = \Yii::$app->db;
  325. $num = ($page - 1 ) * $pageSize;
  326. $sql = "SELECT *,
  327. 6378.138 * 2 * ASIN(
  328. SQRT(
  329. POW(
  330. SIN(
  331. (
  332. $latitude * PI() / 180 - lat * PI() / 180
  333. ) / 2
  334. ), 2
  335. ) + COS( $latitude * PI() / 180) * COS(lat * PI() / 180) * POW(
  336. SIN(
  337. (
  338. $longitude * PI() / 180 - lng * PI() / 180
  339. ) / 2
  340. ), 2
  341. )
  342. )
  343. ) * 1000 AS distance
  344. FROM
  345. ( SELECT id,`name`,logo,address,category_id,sales,rank,per_spend,coordinate,business_model,substring_index(coordinate, ',',1) AS lat,substring_index(coordinate, ',',-1) AS lng FROM cyy_store WHERE is_delete = 0 and open_status = 1 ) store
  346. ORDER BY
  347. distance ASC
  348. Limit $num , $pageSize";
  349. $command = $connection->createCommand($sql);
  350. $res = $command->queryAll();
  351. foreach($res as $k=>$v){
  352. if($v['distance']){
  353. if ($v['distance'] < 1000) {
  354. $res[$k]['distance'] = round($v['distance'], 2) . "m";
  355. } else {
  356. $res[$k]['distance'] = round($v['distance'] / 1000 , 2) . "km";
  357. }
  358. }
  359. if($v['category_id']){
  360. $categoryInfo = Cat::find()->where(['id'=>$v['category_id'],'is_delete'=>0])->asArray()->one();
  361. if($categoryInfo){
  362. $res[$k]['category_name'] = $categoryInfo['name'];
  363. }else{
  364. $res[$k]['category_name'] = '';
  365. }
  366. } //获取6条商品记录
  367. $goodsInfo = Goods::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'status'=>1])->select("id,name,price,original_price,cover_pic")->limit($this->store_goods_limit)->orderBy('sort')->asArray()->all();
  368. if(count($goodsInfo) > 0){
  369. $res[$k]['goodsInfo'] = $goodsInfo;
  370. }else{
  371. $res[$k]['goodsInfo'] = [];
  372. }
  373. $wechatInfo = WechatConfig::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'type'=>1])->asArray()->all();
  374. if($wechatInfo){
  375. $res[$k]['wechat_app_id'] = $wechatInfo['app_id'];
  376. }
  377. $alipayInfo = Option::get('alipay_config',$v['id'],'alipay');
  378. if($alipayInfo && $alipayInfo['value']){
  379. $alipayInfo = json_decode($alipayInfo['value'],true);
  380. $res[$k]['alipay_app_id'] = $alipayInfo['app_id'];
  381. }
  382. }
  383. $count = Store::find()->where(['is_delete'=>0,'open_status'=>1])->count();
  384. $data = [
  385. 'data'=>$res,
  386. 'page'=>$page,
  387. 'count'=>$count
  388. ];
  389. return $data;
  390. }
  391. /**
  392. * 获取首页模板
  393. */
  394. public function actionNewIndex()
  395. {
  396. $store_id = get_params('store_id',-1);
  397. $params = [
  398. 'is_delete' => 0,
  399. 'is_index' => 1,
  400. 'store_id' =>$store_id
  401. //'store_id' => $this->alliance_store_id
  402. ];
  403. $id = get_params('id');
  404. if (!empty($id)) {
  405. unset($params['is_index'], $params['store_id']);
  406. $params['id'] = $id;
  407. }
  408. $template = NewDiyTemplate::findOne($params);
  409. $controls = NewDiyTemplate::find()
  410. ->where([
  411. 'store_id' => $store_id,
  412. //'store_id' => $this->alliance_store_id,
  413. 'is_delete' => 0,
  414. 'type' => 100
  415. ])->asArray()->one()['template'];//商城控件
  416. $platform_controls = NewDiyTemplate::find()
  417. ->where([
  418. 'store_id' => -1,
  419. //'store_id' => $this->alliance_store_id,
  420. 'is_delete' => 0,
  421. 'type' => 100
  422. ])->asArray()->one()['template'];
  423. $controls_arr = json_decode($controls, true);
  424. $platform_controls_arr = json_decode($platform_controls, true);
  425. if (!empty($controls_arr) && !empty($platform_controls_arr)) {
  426. $open = true;
  427. foreach ($controls_arr as &$controls_item) {
  428. if ($controls_item['controlComName'] === 'widgetNavControl') {
  429. $open = false;
  430. foreach ($platform_controls_arr as $platform_controls_item) {
  431. if ($platform_controls_item['controlComName'] === 'widgetNavControl') {
  432. $controls_item = $platform_controls_item;
  433. }
  434. }
  435. }
  436. if ($controls_item['controlComName'] === 'widgetWxControl') {
  437. $store = Store::findOne($store_id);
  438. $kefu_id = '';
  439. if ($store && $store->kefu_id) {
  440. $kefu_id = $store->kefu_id;
  441. } else {
  442. $controls_item['kefuType'] = 0;
  443. }
  444. $controls_item['kefu_id'] = $kefu_id;
  445. }
  446. }
  447. if ($open) {
  448. $platformWidgetNavControl = [];
  449. foreach ($platform_controls_arr as $platform_controls_item) {
  450. if ($platform_controls_item['controlComName'] === 'widgetNavControl') {
  451. $platformWidgetNavControl = $platform_controls_item;
  452. }
  453. }
  454. array_unshift($controls_arr, $platformWidgetNavControl);
  455. }
  456. }
  457. $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE);
  458. return $this->asJson([
  459. 'code' => 0,
  460. 'data' => [
  461. 'template' => $template,
  462. 'controls' => $controls,
  463. ]
  464. ]);
  465. }
  466. /**
  467. * 系统页面列表
  468. * @return \yii\web\Response
  469. */
  470. public function actionSystemTemplateList() {
  471. $store_id = get_params('store_id',0);
  472. if(!is_numeric($store_id)){
  473. return $this->asJson([
  474. 'code' => 1,
  475. 'msg' => '店铺信息为必传',
  476. ]);
  477. }
  478. $list = NewDiyTemplate::find()
  479. ->where([
  480. 'store_id' => $this->store_id,
  481. 'is_delete' => 0,
  482. 'name' => 'system'
  483. ])->orderBy(['id' => SORT_ASC])->asArray()->all();
  484. foreach ($list as $index => &$item) {
  485. $template = json_decode($item['template'], true);
  486. if ($template['system_type'] === 'my') {
  487. foreach ($template['templates'] as &$tem) {
  488. if ($tem['comName'] === 'userWallet') {
  489. $open = false;
  490. foreach ($tem['params']['list'] as $i) {
  491. if ($i['controlComName'] === 'walletItemControl' && !isset($i['walletItemType'])){
  492. $open = true;
  493. break;
  494. }
  495. }
  496. if ($open) {
  497. if ($open) {
  498. $tem['params']['list'] = [
  499. [
  500. "name" => "店铺积分",
  501. "subName" => "积分换好物",
  502. "controlComName" => "walletItemControl",
  503. "walletItemType" => "walletSaasStoreIntegral",
  504. "color" => "#262626",
  505. "subColor" => "#bbbbbb"
  506. ],
  507. [
  508. "name" => "优惠券",
  509. "subName" => "下单立省",
  510. "controlComName" => "walletItemControl",
  511. "walletItemType" => "walletSaasCoupon",
  512. "color" => "#262626",
  513. "subColor" => "#bbbbbb"
  514. ],
  515. [
  516. "name" => "联盟券",
  517. "subName" => "联盟券",
  518. "controlComName" => "walletItemControl",
  519. "walletItemType" => "walletSaasLeaguePrice",
  520. "color" => "#262626",
  521. "subColor" => "#bbbbbb"
  522. ],
  523. [
  524. "name" => "联盟积分",
  525. "subName" => "积分换好物",
  526. "controlComName" => "walletItemControl",
  527. "walletItemType" => "walletSaasIntegral",
  528. "color" => "#262626",
  529. "subColor" => "#bbbbbb"
  530. ]
  531. ];
  532. }
  533. }
  534. }
  535. }
  536. }
  537. if ($template['system_type'] === 'goodsDetail' && intval($this->store_id) > 0) {
  538. $_open = true;
  539. }
  540. $item['template'] = json_encode($template, JSON_UNESCAPED_UNICODE);
  541. }
  542. $list = array_values($list);
  543. if (empty($_open)) {
  544. $order_detail_template = [
  545. 'name' => 'system',
  546. 'store_id' => 0,
  547. 'template' => '{"page_name":"商品详情","is_index":"0","page_type":1,"system_type":"goodsDetail","page_link":"","theme":{"color":""},"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":"","comName":"goodsSwiperImgs","icon":"","controlComName":"","params":{}},{"name":"商品详情页面-商品介绍","type":"","comName":"goodsIntroduce","icon":"","controlComName":"goodsIntroduceControl","params":{"showMemberPrice":false,"showOriginPrice":false},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品优惠活动","type":"","comName":"goodsDiscount","icon":"","controlComName":"goodsDiscountControl","params":{"showGoodsDiscount":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品sku属性选择","type":"","comName":"goodsAttribute","icon":"","controlComName":"goodsAttributeControl","params":{"showAddress":true,"showNearbyShop":true,"showFreight":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品评价","type":"","comName":"goodsEvaluate","icon":"","controlComName":"goodsEvaluateControl","params":{"showEvaluate":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品评价","type":"","comName":"goodsShopEntry","icon":"","controlComName":"goodsShopEntryControl","params":{"showGoodsShopEntry":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-底部导航","type":"","comName":"goodsFootNav","icon":"","controlComName":"goodsFootNavControl","params":{"styleType":"1","tabList":[{"text":"店铺","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/857370f6a7a788ff0674b4255dabc91974b402a0.png","link":{},"fontColor":"#262626"},{"text":"客服","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/aa7a96931ae57b070af3bd38f9553a40b7d9bd4f.png","link":{},"fontColor":"#262626"},{"text":"购物车","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/5d156040e27daf1da32d3a4241355684f4708f7e.png","link":{},"fontColor":"#262626"}],"buyBtn":{"text":"立即购买","color":"#FFFFFF","bgColor":"#FBBA10"},"cartBtn":{"text":"加入购物车","color":"#FFFFFF","bgColor":"#F0250E"}},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","borderRadius":0}}],"controlComName":"pageControl","id":""}',
  548. 'type' => 1,
  549. 'id' => 1
  550. ];
  551. $list = array_merge($list, [$order_detail_template]);
  552. }
  553. $controls = NewDiyTemplate::find()
  554. ->where([
  555. 'store_id' => $this->store_id,
  556. 'is_delete' => 0,
  557. 'type' => 100
  558. ])->asArray()->one()['template'];
  559. $controls_arr = json_decode($controls, true);
  560. foreach ($controls_arr as &$controls_item) {
  561. if ($controls_item['controlComName'] === 'widgetWxControl') {
  562. $store = Store::findOne($store_id);
  563. $kefu_id = '';
  564. if ($store && $store->kefu_id) {
  565. $kefu_id = $store->kefu_id;
  566. } else {
  567. $controls_item['kefuType'] = 0;
  568. }
  569. $controls_item['kefu_id'] = $kefu_id;
  570. }
  571. }
  572. $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE);
  573. return $this->asJson([
  574. 'code' => 0,
  575. 'msg' => '加载成功',
  576. 'data' => [
  577. 'list' => $list,
  578. 'controls' => $controls,
  579. ]
  580. ]);
  581. }
  582. /**
  583. * 获取商品优惠详情
  584. */
  585. public function actionAddress() {
  586. $form = new GoodsForm();
  587. $form->attributes = get_params();
  588. return $this->asJson($form->getAddress());
  589. }
  590. /**
  591. * 获取DIY模板
  592. */
  593. public function actionTemplateUnit()
  594. {
  595. $type = get_params('type', 'goods');
  596. $template = DiyTemplate::findOne([
  597. 'is_delete' => 0,
  598. 'type' => $type,
  599. 'store_id' => get_store_id()
  600. ]);
  601. if (is_platform() && $type == 'controls') {
  602. $tabbar = Option::get('tabbar', 0, 'saas', json_encode([]));
  603. $tabbar = json_decode($tabbar['value'], true);
  604. $temp = json_decode($template->template, true);
  605. foreach ($temp as $key => $value) {
  606. if ($value['name'] == '底部导航') {
  607. $temp[$key]['param']['list'] = $tabbar;
  608. }
  609. }
  610. $template->template = json_encode($temp, JSON_UNESCAPED_UNICODE);
  611. }
  612. return $this->asJson([
  613. 'code' => 0,
  614. 'data' => [
  615. 'template' => $template
  616. ]
  617. ]);
  618. }
  619. /**
  620. * 获取秒杀商品信息
  621. */
  622. public function actionSeckillActivity()
  623. {
  624. try {
  625. $id = get_params('activeId', 20);
  626. $seckill_activity = SeckillActivity::find()->where([
  627. 'AND',
  628. ['store_id' => get_store_id(), 'is_delete' => 0, 'id' => $id, 'is_platform' => 0],
  629. ['>', 'end_time', time()]
  630. ])->select('id, start_time, end_time, name, store_id')->asArray()->all();
  631. $pagination = [
  632. 'list' => [],
  633. 'pageNo' => 0,
  634. 'totalCount' => 0
  635. ];
  636. if ($seckill_activity) {
  637. foreach ($seckill_activity as &$item) {
  638. $query = SeckillActivityGoods::find()->alias('sag')->where([
  639. 'sag.is_delete' => 0,
  640. 'sag.activity_id' => $item['id']
  641. ])->leftJoin(['g' => Goods::tableName()], 'sag.goods_id = g.id')
  642. ->andWhere([
  643. 'g.status' => 1,
  644. 'g.is_delete' => 0
  645. ])->select("g.id, g.cover_pic, g.delivery_rules_id, g.name, sag.seckill_num,
  646. sag.seckill_price price, g.price original_price, sag.sale_num, sag.attr, sag.use_attr, sag.virtual_sales, sag.virtual_num");
  647. $pagination = pagination_make($query);
  648. $item['seckill_activity_goods'] = $pagination['list'];
  649. foreach ($item['seckill_activity_goods'] as &$activity_good) {
  650. if ((int)$activity_good['use_attr'] === 1) {
  651. $attr = json_decode($activity_good['attr'], true);
  652. $activity_good['price'] = sprintf('%.2f', $attr[0]['seckill_price']);
  653. }
  654. $activity_good['delivery_rules'] = DeliveryRules::find()->where([
  655. 'id' => $activity_good['delivery_rules_id'],
  656. 'status' => 1, 'is_delete' => 0
  657. ])->select('type, times, days, name')->one();
  658. if ($activity_good['delivery_rules']) {
  659. $days = "下单" . $activity_good['delivery_rules']['days'] . "天后";
  660. $activity_good['delivery_rules']['times'] =
  661. (int)$activity_good['delivery_rules']['type'] === 1 ? $days : date("m月d日 H:i:s", $activity_good['delivery_rules']['times']);
  662. $activity_good['delivery_rules']['type'] .= '';
  663. }
  664. if (((int)$activity_good['seckill_num'] + $activity_good['virtual_sales']) === 0 || ((int)$activity_good['sale_num'] + $activity_good['virtual_sales']) === 0) {
  665. $activity_good['progress'] = 0;
  666. } else {
  667. $activity_good['progress'] = sprintf('%.2f', (($activity_good['sale_num'] * 1) / ($activity_good['seckill_num'] + $activity_good['sale_num'])) * 100);
  668. $activity_good['seckill_num'] <= 0 && $activity_good['progress'] = 100;
  669. if ($item['start_time'] > time()) {
  670. $activity_good['progress'] = 0;
  671. $activity_good['virtual_sales'] = 0;
  672. }
  673. }
  674. // $activity_good['seckill_num'] -= $activity_good['sale_num'];
  675. }
  676. }
  677. }
  678. return $this->asJson([
  679. 'code' => 0,
  680. 'data' => [
  681. 'list' => $seckill_activity,
  682. 'pageNo' => $pagination['pageNo'],
  683. 'totalCount' => $pagination['totalCount']
  684. ],
  685. ]);
  686. } catch (\Exception $e) {
  687. return $this->asJson([
  688. 'code' => 0,
  689. 'data' => []
  690. ]);
  691. }
  692. }
  693. }