DefaultController.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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\librarys\KuaiDi100\KuaiDi100;
  10. use app\models\AboutArticle;
  11. use app\models\AccessoriesWorks;
  12. use app\models\AppNavbar;
  13. use app\models\BrowseLog;
  14. use app\models\BuyGoodsLog;
  15. use app\models\Coupon;
  16. use app\models\District;
  17. use app\models\Goods;
  18. use app\models\GoodsBrand;
  19. use app\models\Insurance;
  20. use app\models\Mch;
  21. use app\models\Md;
  22. use app\models\Option;
  23. use app\models\Order;
  24. use app\models\SaasCategory;
  25. use app\models\Shop;
  26. use app\models\Store;
  27. use app\models\StoreImageSearchSetting;
  28. use app\models\User;
  29. use app\modules\client\models\v1\CommentListForm;
  30. use app\modules\client\models\v1\GoodsAttrInfoForm;
  31. use app\modules\client\models\v1\IndexForm;
  32. use app\modules\client\controllers\BaseController;
  33. use app\modules\client\models\v1\CatListForm;
  34. use app\modules\client\models\v1\EvaluateCenterForm;
  35. use app\modules\client\models\v1\GoodsListForm;
  36. use app\modules\client\models\v1\IntelligentMatchForm;
  37. use app\modules\client\models\v1\SearchForm;
  38. use app\modules\client\models\v1\ShareQrcodeForm;
  39. use app\modules\client\models\v1\ShopForm;
  40. use app\modules\client\models\v1\ShopListForm;
  41. use app\modules\client\models\v1\StoreConfigForm;
  42. use app\modules\client\models\v1\TopicForm;
  43. use app\modules\client\models\v1\TopicListForm;
  44. use app\modules\client\models\v1\TopicTypeForm;
  45. use app\modules\client\models\v1\UploadForm;
  46. use app\utils\Address\Address;
  47. use app\utils\TiiaHelper;
  48. use yii\helpers\Json;
  49. use app\modules\admin\models\MchForm;
  50. use app\modules\admin\models\mochat\MochatForm;
  51. class DefaultController extends BaseController
  52. {
  53. /**
  54. * 获取商城设置
  55. */
  56. public function actionStore()
  57. {
  58. if (cache()->get('StoreConfig') && false) {
  59. $config = cache()->get('StoreConfig');
  60. } else {
  61. $config = StoreConfigForm::getConfig(get_store_id());
  62. cache()->set('StoreConfig', $config, 60 * 60);
  63. }
  64. if(!cache_lock(['scrm_MSG_TYPE_CLICK_STORE', get_store_id(), MochatForm::MSG_TYPE_CLICK_STORE, get_saas_user_id()], (24 - date('H')) * 3600)){
  65. MochatForm::sendMsg(1, get_store_id(), MochatForm::MSG_TYPE_CLICK_STORE, get_saas_user_id());
  66. }
  67. return $this->asJson([
  68. 'code' => 0,
  69. 'msg' => 'success',
  70. 'data' => $config,
  71. 'getClientConfig' => StoreConfigForm::getClientConfig(get_store_id(), get_mini_id()),
  72. ]);
  73. }
  74. /**
  75. * 商户设置
  76. */
  77. public function actionMchSetting()
  78. {
  79. $store_id = get_store_id();
  80. $form = new MchForm();
  81. $form->attributes = all_params();
  82. $form->store_id = $store_id;
  83. $result = $form->mchSetting();
  84. return $this->asJson([
  85. 'code' => 0,
  86. 'msg' => 'ok',
  87. 'data' => $result,
  88. ]);
  89. }
  90. /**
  91. * 入驻商
  92. */
  93. public function actionMch()
  94. {
  95. $mch_id = input_params('mch_id');
  96. $store_id = get_store_id();
  97. $form = new MchForm();
  98. $form->attributes = all_params();
  99. $form->store_id = $store_id;
  100. $form->mch_id = $mch_id;
  101. $result = $form->mchInfo();
  102. return $this->asJson($result);
  103. }
  104. /**
  105. * 入驻商
  106. */
  107. public function actionMchList()
  108. {
  109. $store_id = get_store_id();
  110. $form = new MchForm();
  111. $form->attributes = all_params();
  112. $form->store_id = $store_id;
  113. $form->orderByDis = get_params('orderByDis', 1);
  114. $form->is_open = Mch::IS_OPEN_TRUE;
  115. $result = $form->mchList();
  116. return $this->asJson($result);
  117. }
  118. /**
  119. * 入驻商注册
  120. */
  121. public function actionMchReg()
  122. {
  123. $store_id = get_store_id();
  124. $user_id = get_user_id();
  125. $saas_user_id = get_saas_user_id();
  126. $form = new MchForm();
  127. $form->attributes = all_params();
  128. $form->store_id = $store_id;
  129. $form->user_id = $user_id;
  130. $form->saas_id = $saas_user_id;
  131. $result = $form->mchReg();
  132. return $this->asJson($result);
  133. }
  134. /**
  135. * 入驻商注册记录
  136. */
  137. public function actionMchRegInfo()
  138. {
  139. $store_id = get_store_id();
  140. $user_id = get_user_id();
  141. $form = new MchForm();
  142. $form->store_id = $store_id;
  143. $form->user_id = $user_id;
  144. $result = $form->mchAuditList();
  145. return $this->asJson($result);
  146. }
  147. /**
  148. * 入驻商分类列表
  149. */
  150. public function actionMchCommonCatList()
  151. {
  152. $store_id = get_store_id();
  153. $form = new MchForm();
  154. $form->attributes = all_params();
  155. $form->store_id = $store_id;
  156. $form->is_show = 1;
  157. $result = $form->mchCommonCatList();
  158. return $this->asJson($result);
  159. }
  160. /**
  161. * 入驻商商品分类
  162. */
  163. public function actionMchCat()
  164. {
  165. $mch_id = input_params('mch_id');
  166. $goodsCatList = MchForm::goodsCatList($mch_id, 1);
  167. return $this->asJson([
  168. 'code' => 0,
  169. 'msg' => 'success',
  170. 'data' => $goodsCatList,
  171. ]);
  172. }
  173. /**
  174. * 入驻商访客
  175. */
  176. public function actionMchVisit()
  177. {
  178. $form = new MchForm();
  179. $form->mch_id = get_mch_id();
  180. $result = $form->mchVisit(input_params('date'), 1);
  181. return $this->asJson([
  182. 'code' => 0,
  183. 'msg' => 'success',
  184. 'data' => $result,
  185. ]);
  186. }
  187. /**
  188. * 送礼配置
  189. */
  190. public function actionGivingGiftsConf()
  191. {
  192. $conf = \app\modules\admin\models\givingGifts\GivingGiftsForm::conf(get_store_id());
  193. return $this->asJson([
  194. 'code' => 0,
  195. 'data' => $conf,
  196. ]);
  197. }
  198. public function actionGetArea() {
  199. return $this->asJson([
  200. 'code' => 0,
  201. 'msg' => 'success',
  202. 'data' => [
  203. 'area' => file_get_contents('web/v1/statics/area/area.json'),
  204. 'province' => file_get_contents('web/v1/statics/area/province.json'),
  205. 'city' => file_get_contents('web/v1/statics/area/city.json')
  206. ]
  207. ]);
  208. }
  209. /**
  210. * 平台小程序信息接口
  211. */
  212. public function actionPlatform()
  213. {
  214. if (cache()->get('PlatformConfig') && false) {
  215. $config = cache()->get('PlatformConfig');
  216. } else {
  217. $config = StoreConfigForm::getPlatformConfig();
  218. cache()->set('PlatformConfig', $config, 60 * 60);
  219. }
  220. return $this->asJson([
  221. 'code' => 0,
  222. 'msg' => 'success',
  223. 'data' => $config
  224. ]);
  225. }
  226. /**
  227. * 获取导航栏配置
  228. */
  229. public function actionNavbar()
  230. {
  231. return $this->asJson([
  232. 'code' => 0,
  233. 'data' => AppNavbar::getNavbar(get_store_id())
  234. ]);
  235. }
  236. /**
  237. * 获取首页DIY信息
  238. */
  239. public function actionIndex()
  240. {
  241. $form = new IndexForm();
  242. $form->store_id = get_store_id();
  243. $form->_platform = \Yii::$app->request->get('_platform');
  244. $form->page_id = \Yii::$app->request->get('page_id');
  245. return $this->asJson($form->search());
  246. }
  247. /**
  248. * 商品评价列表
  249. * @return \yii\web\Response
  250. */
  251. public function actionCommentList()
  252. {
  253. $form = new CommentListForm();
  254. $form->attributes = get_params();
  255. return $this->asJson($form->search());
  256. }
  257. /**
  258. * 获取规格详情
  259. * @return mixed
  260. */
  261. public function actionGoodsAttrInfo()
  262. {
  263. $form = new GoodsAttrInfoForm();
  264. $form->attributes = get_params();
  265. $form->is_pt = get_params('is_pt', 0);
  266. return $this->asJson($form->search());
  267. }
  268. /**
  269. * 判断是否多城市版本
  270. * @return \yii\web\Response
  271. */
  272. public function actionStoreType()
  273. {
  274. return $this->asJson([
  275. 'code' => 0,
  276. 'data' => 0
  277. ]);
  278. }
  279. /**
  280. * 获取所有地区
  281. * @return \yii\web\Response
  282. */
  283. public function actionDistrict()
  284. {
  285. $list = District::getAll();
  286. return $this->asJson([
  287. 'code' => 0,
  288. 'data' => $list
  289. ]);
  290. }
  291. /**
  292. * 顶部导航栏颜色
  293. * @return \yii\web\Response
  294. */
  295. public function actionNavigationBarColor()
  296. {
  297. $navigation_bar_color = Option::get('navigation_bar_color', get_store_id(), 'navbar',Json::encode( [
  298. 'frontColor' => '#000000',
  299. 'backgroundColor' => '#ffffff',
  300. ]));
  301. return $this->asJson([
  302. 'code' => 0,
  303. 'data' => Json::decode($navigation_bar_color['value'])
  304. ]);
  305. }
  306. /**
  307. * 评价中心
  308. */
  309. public function actionEvaluateCenter()
  310. {
  311. $form = new EvaluateCenterForm();
  312. $form->store_id = get_store_id();
  313. $form->attributes = get_params();
  314. return $this->asJson($form->search());
  315. }
  316. /**
  317. * 添加浏览记录
  318. */
  319. public function actionBrowse()
  320. {
  321. if (get_user_id() > 0) {
  322. $start = strtotime(date('Y-m-d',time()));
  323. $form = BrowseLog::find()->where([
  324. 'log_id' => get_params('id'),
  325. 'type' => get_params('type'),
  326. 'store_id' => get_store_id(),
  327. 'user_id' => get_user_id(),
  328. 'is_delete' => 0
  329. ])->andWhere([
  330. ">",
  331. 'created_at',
  332. $start
  333. ])->one();
  334. $form = $form ?: new BrowseLog();
  335. $form->log_id = get_params('id');
  336. $form->type = get_params('type');
  337. $form->store_id = get_store_id();
  338. $form->user_id = get_user_id();
  339. $form->created_at = time();
  340. $form->save();
  341. }
  342. return $this->asJson([
  343. 'code' => 0,
  344. 'msg' => 'success'
  345. ]);
  346. }
  347. /**
  348. * 浏览记录列表
  349. */
  350. public function actionBrowseList()
  351. {
  352. $choose_day = get_params('day');
  353. if (!empty($choose_day)) {
  354. $day = strtotime($choose_day);
  355. } else {
  356. $day = strtotime(date('Y-m-d', time()));
  357. }
  358. $browse_list = BrowseLog::find()->where([
  359. 'type' => 0,
  360. 'store_id' => get_store_id(),
  361. 'user_id' => get_user_id(),
  362. 'is_delete' => 0
  363. ])->andWhere(['>', 'created_at', $day])->andWhere(['<=', 'created_at', $day + 3600 * 24])->all();
  364. $re_arr = [];
  365. foreach ($browse_list as $k => $v) {
  366. $goods_info = Goods::find()->select('id, name, cover_pic, price')->where([
  367. 'id' => $v['log_id'],
  368. 'store_id' => get_store_id()
  369. ])->asArray()->one();
  370. $goods_info['log_id'] = $v['id'];
  371. $re_arr[] = $goods_info;
  372. }
  373. $browse_list_shop = BrowseLog::find()->where([
  374. 'type' => 1,
  375. 'store_id' => get_store_id(),
  376. 'user_id' => get_user_id(),
  377. 'is_delete' => 0
  378. ])->andWhere(['>', 'created_at', $day])->andWhere(['<=', 'created_at', $day + 3600 * 24])->all();
  379. $re_shop_arr = [];
  380. // 门店浏览记录
  381. foreach ($browse_list_shop as $k => $v) {
  382. $shops_info = Shop::find()->select(['id', 'name', 'cover_url as logo', 'mobile as tel', 'score'])->where([
  383. 'id' => $v['log_id'],
  384. 'store_id' => get_store_id()
  385. ])->asArray()->one();
  386. $shops_info['log_id'] = $v['id'];
  387. $re_shop_arr[] = $shops_info;
  388. }
  389. $data = [
  390. 're_arr' => $re_arr,
  391. 're_shop_arr' => $re_shop_arr
  392. ];
  393. return $this->asJson([
  394. 'code' => 0,
  395. 'msg' => 'success',
  396. 'data' => $data
  397. ]);
  398. }
  399. /**
  400. * 删除商品浏览记录
  401. */
  402. public function actionDelGoodsLog()
  403. {
  404. $del_id = get_params('id');
  405. $del_list = get_params('list');
  406. if (!empty($del_id)) {
  407. $log_info = BrowseLog::find()->where([
  408. 'id' => $del_id,
  409. 'type' => 0,
  410. 'store_id' => get_store_id(),
  411. 'user_id' => get_user_id(),
  412. 'is_delete' => 0
  413. ])->one();
  414. $log_info->is_delete = 1;
  415. if ($log_info->save()) {
  416. return $this->asJson(['code' => 0, 'msg' => '删除成功']);
  417. } else {
  418. return $this->asJson(['code' => 1, 'msg' => '删除失败']);
  419. }
  420. } else if(!empty($del_list)) {
  421. $del_list_arr = explode(',', $del_list);
  422. foreach ($del_list_arr as $v) {
  423. $log_info = BrowseLog::find()->where([
  424. 'id' => $v,
  425. 'type' => 0,
  426. 'store_id' => get_store_id(),
  427. 'user_id' => get_user_id(),
  428. 'is_delete' => 0
  429. ])->one();
  430. $log_info->is_delete = 1;
  431. $log_info->save();
  432. }
  433. return $this->asJson(['code' => 0, 'msg' => '删除成功']);
  434. }
  435. }
  436. /**
  437. * 删除门店浏览记录
  438. */
  439. public function actionDelShopLog()
  440. {
  441. $del_id = get_params('id');
  442. if (!empty($del_id)) {
  443. $log_info = BrowseLog::find()->where([
  444. 'id' => $del_id,
  445. 'type' => 1,
  446. 'store_id' => get_store_id(),
  447. 'user_id' => get_user_id(),
  448. 'is_delete' => 0
  449. ])->one();
  450. $log_info->is_delete = 1;
  451. if ($log_info->save()) {
  452. return $this->asJson(['code' => 0, 'msg' => '删除成功']);
  453. } else {
  454. return $this->asJson(['code' => 1, 'msg' => '删除失败']);
  455. }
  456. }
  457. }
  458. /**
  459. * 分类列表
  460. */
  461. public function actionCatList()
  462. {
  463. $form = new CatListForm();
  464. $form->attributes = get_params();
  465. $form->store_id = get_store_id();
  466. return $this->asJson($form->search());
  467. }
  468. /**
  469. * 搜索页搜索分类
  470. */
  471. public function actionCats()
  472. {
  473. $form = new SearchForm();
  474. return $this->asJson($form->cats());
  475. }
  476. /**
  477. * 搜索页搜索接口
  478. */
  479. public function actionSearch()
  480. {
  481. $form = new SearchForm();
  482. $form->attributes = get_params();
  483. $form->cat = json_decode(get_params('cat'));
  484. $form->store_id = get_store_id();
  485. return $this->asJson($form->search());
  486. }
  487. /**
  488. * 默认商品列表
  489. */
  490. public function actionGoodsList()
  491. {
  492. $form = new GoodsListForm();
  493. $form->attributes = get_params();
  494. $form->store_id = get_store_id();
  495. $form->mch_id = get_mch_id();
  496. $form->user_id = get_user_id();
  497. $form->is_accessories = get_params('is_accessories',0);
  498. return $this->asJson($form->search());
  499. }
  500. /**
  501. * 获取品牌列表
  502. */
  503. public function actionGetBrandList()
  504. {
  505. $list = GoodsBrand::getList(get_store_id());
  506. return $this->asJson([
  507. 'code' => 0,
  508. 'data' => [
  509. 'list' => $list
  510. ]
  511. ]);
  512. }
  513. /**
  514. * 上传图片
  515. */
  516. public function actionUploadImage()
  517. {
  518. $form = new UploadForm();
  519. $form->store_id = get_store_id();
  520. // return $this->asJson($_FILES);
  521. return $this->asJson($form->uploadFile('image', 'image'));
  522. }
  523. /**
  524. * 专题列表
  525. * @return \yii\web\Response
  526. */
  527. public function actionTopicList()
  528. {
  529. $form = new TopicListForm();
  530. $form->attributes = get_params();
  531. $form->store_id = get_store_id();
  532. return $this->asJson($form->search());
  533. }
  534. /**
  535. * 专题详情
  536. * @return \yii\web\Response
  537. */
  538. public function actionTopic()
  539. {
  540. $form = new TopicForm();
  541. $form->attributes = get_params();
  542. $form->store_id = get_store_id();
  543. if (get_user_id() > 0) {
  544. $form->user_id = get_user_id();
  545. }
  546. return $this->asJson($form->search());
  547. }
  548. /**
  549. * 专题分类
  550. * @return \yii\web\Response
  551. */
  552. public function actionTopicType()
  553. {
  554. $form = new TopicTypeForm();
  555. $form->store_id = get_store_id();
  556. return $this->asJson($form->search());
  557. }
  558. /**
  559. * 专题海报
  560. * @return \yii\web\Response
  561. */
  562. public function actionTopicQrcode()
  563. {
  564. $form = new ShareQrcodeForm();
  565. $form->attributes = get_params();
  566. $form->store_id = get_store_id();
  567. $form->type = 6;
  568. if (get_user_id() > 0) {
  569. $form->user = get_user();
  570. $form->user_id = get_user_id();
  571. }
  572. return $this->asJson($form->search());
  573. }
  574. /**
  575. * 门店列表
  576. * @return \yii\web\Response
  577. */
  578. public function actionShopList()
  579. {
  580. $form = new ShopListForm();
  581. $form->store_id = get_store_id();
  582. $form->user = get_user();
  583. $form->attributes = get_params();
  584. return $this->asJson($form->search());
  585. }
  586. /**
  587. * 门店详情
  588. * @return \yii\web\Response
  589. */
  590. public function actionShopDetail()
  591. {
  592. $form = new ShopForm();
  593. $form->store_id = get_store_id();
  594. $form->user = get_user();
  595. $form->attributes = get_params();
  596. return $this->asJson($form->search());
  597. }
  598. /**
  599. * 获取当前具体位置
  600. * @return \yii\web\Response
  601. */
  602. public function actionLocationContent()
  603. {
  604. $longitude = $_REQUEST['longitude']; //用户当前定位的经度
  605. $latitude = $_REQUEST['latitude']; //用户当前定位的纬度
  606. $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
  607. if (get_store_id() > 0) {
  608. $tencent_map_key = Option::get(OptionSetting::TENCENT_MAP_KEY, get_store_id(), 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, get_store_id(), 'store', '')['value'] ?: $tencent_map_key)['value'];
  609. }
  610. $place_url = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' . $latitude . ',' . $longitude . '&key=' . $tencent_map_key;
  611. $json_place = file_get_contents($place_url);
  612. $place_arr = json_decode($json_place, true);
  613. $address = $place_arr['result']['address_component'];
  614. return $this->asJson([
  615. 'code' => 0,
  616. 'msg' => 'success',
  617. 'data' => $address ?? [
  618. 'city' => '',
  619. 'district' => '',
  620. 'nation' => '',
  621. 'province' => '',
  622. 'street' => '',
  623. 'street_number' => '',
  624. ]
  625. ]);
  626. }
  627. /**
  628. * 文章详情
  629. * @return \yii\web\Response
  630. */
  631. public function actionArticleDetail()
  632. {
  633. $id = get_params('id');
  634. if ($id == 'about_us') {
  635. $model = AboutArticle::find()->where([
  636. 'store_id' => get_store_id(),
  637. 'is_delete' => 0,
  638. ])->orderBy('id ASC')->one();
  639. if (!$model) {
  640. $model = new AboutArticle();
  641. $model->name = '关于我们';
  642. $model->store_id = get_store_id();
  643. $model->desc = '关于我们';
  644. $model->save();
  645. }
  646. $data = [
  647. 'id' => $model->id,
  648. 'title' => $model->name,
  649. 'content' => $model->desc,
  650. ];
  651. return $this->asJson([
  652. 'code' => 0,
  653. 'msg' => 'success',
  654. 'data' => $data
  655. ]);
  656. } elseif ($id == 'pt_rules') {
  657. $model = AboutArticle::find()->where([
  658. 'store_id' => get_store_id(),
  659. 'type' => 1,
  660. 'is_delete' => 0
  661. ])->one();
  662. if (!$model) {
  663. $model = new AboutArticle();
  664. $model->name = '拼团规则';
  665. $model->store_id = get_store_id();
  666. $model->desc = '拼团规则';
  667. $model->type = 1;
  668. $model->save();
  669. }
  670. $data = [
  671. 'id' => $model->id,
  672. 'title' => $model->name,
  673. 'content' => $model->desc,
  674. ];
  675. return $this->asJson([
  676. 'code' => 0,
  677. 'msg' => 'success',
  678. 'data' => $data
  679. ]);
  680. } elseif ($id == 'holder_agreement') {
  681. $holder_agreement = Option::get('holder_agreement', get_store_id(), 'store', '')['value'];
  682. $data = [
  683. 'title' => '股东协议',
  684. 'content' => $holder_agreement,
  685. ];
  686. return $this->asJson([
  687. 'code' => 0,
  688. 'msg' => 'success',
  689. 'data' => $data
  690. ]);
  691. } else {
  692. $model = AboutArticle::find()->where([
  693. 'is_delete' => 0,
  694. 'id' => $id,
  695. ])->select('id,name as title,desc as content')->asArray()->one();
  696. if (empty($model)) {
  697. return $this->asJson([
  698. 'code' => 1,
  699. 'msg' => '内容不存在'
  700. ]);
  701. }
  702. return $this->asJson([
  703. 'code' => 0,
  704. 'msg' => 'success',
  705. 'data' => $model
  706. ]);
  707. }
  708. }
  709. /**
  710. * 文章列表
  711. * @return \yii\web\Response
  712. */
  713. public function actionArticleList()
  714. {
  715. $list = AboutArticle::find()->where([
  716. 'store_id' => get_store_id(),
  717. 'is_delete' => 0
  718. ])->andWhere(['>', 'id' , 1])->orderBy('sort DESC,created_at DESC')
  719. ->select('id,name as title')->asArray()->all();
  720. return $this->asJson([
  721. 'code' => 0,
  722. 'msg' => 'success',
  723. 'data' => ['list' => $list]
  724. ]);
  725. }
  726. /**
  727. * 领券中心
  728. * @return \yii\web\Response
  729. */
  730. public function actionCouponList()
  731. {
  732. $coupon_id = intval(input_params('coupon_id', 0));
  733. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => ['list' => Coupon::getList(0, 0, 1, [], $coupon_id)]]);
  734. }
  735. /**
  736. * 领券中心
  737. * @return \yii\web\Response
  738. */
  739. public function actionSaasCouponList()
  740. {
  741. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => ['list' => Coupon::getList(0, 0, 1)]]);
  742. }
  743. public function actionGoodsQrcode()
  744. {
  745. $form = new ShareQrcodeForm();
  746. $form->attributes = \Yii::$app->request->get();
  747. $form->store_id = get_store_id();
  748. $form->type = 0;
  749. $form->user = get_user();
  750. $form->user_id = get_user_id();
  751. return $this->asJson($form->search());
  752. }
  753. /**
  754. * 购买数据
  755. */
  756. public function actionBuyData()
  757. {
  758. $key = "buy_data";
  759. $cache = cache()->get($key);
  760. $data = null;
  761. if ($data) {
  762. $data = json_decode($cache);
  763. $cha_time = time() - (int)$data->time;
  764. }
  765. unset($data->time);
  766. if ($data && $data->store_id == get_store_id()) {
  767. $user = mb_strlen($data->user, 'UTF-8') > 5 ? mb_substr($data->user, 0, 4, 'UTF-8') . '...' : $data->user;
  768. $address = mb_strlen($data->address, 'UTF-8') > 8 ? mb_substr($data->address, 0, 7, 'UTF-8') . '...' : $data->address;
  769. $data->url = '/goods/goods/goods?id=' . $data->goods;
  770. $data->content = $user . '购买了' . $address;
  771. return $this->asJson([
  772. 'code' => 0,
  773. 'data' => $data,
  774. 'cha_time' => $cha_time,
  775. 'md5' => md5(json_encode($data)),
  776. ]);
  777. } else {
  778. return $this->asJson([
  779. 'code' => 1,
  780. 'data' => null
  781. ]);
  782. }
  783. }
  784. /**
  785. * 根据位置解析地址
  786. */
  787. public function actionAddressSmart()
  788. {
  789. $store_id = get_store_id();
  790. $address = get_params('address');
  791. $tencent_map_key = Option::get(OptionSetting::TENCENT_MAP_KEY, $store_id, 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, $store_id, 'store', '')['value'])['value'];
  792. //通过地址信息获取经纬度
  793. if (empty($tencent_map_key)) {
  794. $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
  795. }
  796. $url = 'https://apis.map.qq.com/ws/geocoder/v1/?';
  797. $params = [
  798. 'key' => $tencent_map_key,
  799. 'address' => $address,
  800. ];
  801. $url .= http_build_query($params);
  802. $json = file_get_contents($url);
  803. $tencent_result = json_decode($json, true);
  804. if ($tencent_result['status'] === 0) {
  805. $address_area = $tencent_result['result']['address_components'];
  806. } else {
  807. $address_area = $address;
  808. }
  809. $res = $this->addressSmart(['address' => $address_area]);
  810. return $this->asJson([
  811. 'code' => 0,
  812. 'data' => $res
  813. ]);
  814. }
  815. public function addressSmart($params = []) {
  816. $res = $params['address'];
  817. if (is_string($params['address'])) {
  818. $res = Address::smart($params['address'], false);
  819. }
  820. $province_id = District::find()->where(['and', ['like', 'name', $res['province']], ['level' => 'province']])->one()->id;
  821. $city_id = District::findOne(['name' => $res['city'], 'level' => 'city'])->id;
  822. $region_id = District::findOne(['name' => $res['region'] ?? $res['district'], 'level' => 'district'])->id;
  823. if (!$province_id || !$city_id || !$region_id) {
  824. $province_id = District::findOne(['name' => '其他', 'level' => 'province'])->id;
  825. $city_id = District::findOne(['name' => '其他', 'level' => 'city'])->id;
  826. $region_id = District::findOne(['name' => '其他', 'level' => 'district'])->id;
  827. $res['province'] = '其他';
  828. $res['city'] = '其他';
  829. $res['region'] = '其他';
  830. }
  831. $res['region'] = $res['region'] ?: $res['district'];
  832. $res['province_id'] = $province_id;
  833. $res['city_id'] = $city_id;
  834. $res['region_id'] = $region_id;
  835. return $res;
  836. }
  837. /**
  838. * 上传图片后返回相似的商品ID
  839. * @return \yii\web\Response
  840. * User: hankaige
  841. * DATE TIME: 2023/1/17 11:05
  842. */
  843. public function actionSearchImage(){
  844. $tiia = new TiiaHelper();
  845. $postData = post_params();
  846. $status = Option::get('tencent_image_setting_status',0,'saas')['value'];
  847. if($status == 0){
  848. return $this->asJson(['code'=>1,'msg'=>'平台未开启以图搜图功能']);
  849. }
  850. $storeImageSetting = StoreImageSearchSetting::findOne(['store_id'=>get_store_id()]);
  851. $res = $tiia::searchImage($storeImageSetting->group_id,$postData['image']);
  852. if($res['code'] == 0){
  853. $goodsId = array_column($res['data']['ImageInfos'],'EntityId');
  854. }else{
  855. $goodsId = [];
  856. }
  857. // $goodsId = [1,2,3,4,5,6,7];
  858. return $this->asJson(['code'=>0,'data'=>$goodsId]);
  859. }
  860. /**
  861. * 获取智配页面数据
  862. * @return \yii\web\Response
  863. * User: hankaige
  864. * DATE TIME: 2023/1/28 15:20
  865. */
  866. public function actionIntelligentMatch(){
  867. $form = new IntelligentMatchForm();
  868. $form->store_id = get_store_id();
  869. $form->goods_id = get_params('goods_id');
  870. $result = $form->getIntelligentMatch();
  871. return $this->asJson($result);
  872. }
  873. /**
  874. * 根据场景分类获取场景
  875. * @return \yii\web\Response
  876. * User: hankaige
  877. * DATE TIME: 2023/1/28 15:24
  878. */
  879. public function actionIntelligentScene(){
  880. $form = new IntelligentMatchForm();
  881. $form->store_id = get_store_id();
  882. $form->cat_id = get_params('cat_id');
  883. $result = $form->getScene();
  884. return $this->asJson($result);
  885. }
  886. /**
  887. * 生成用户智配作品图 分享使用
  888. * @return void|\yii\web\Response
  889. * User: hankaige
  890. * DATE TIME: 2023/1/30 09:37
  891. */
  892. public function actionMakeWorks(){
  893. if(empty(post_params('image'))){
  894. return $this->asJson(['code'=>1,'msg'=>'图片链接不能为空']);
  895. }
  896. $model = new AccessoriesWorks();
  897. $model->user_id = get_user_id();
  898. $model->user_name = User::findOne(get_user_id())->nickname;
  899. $model->store_id = get_store_id();
  900. $model->image = post_params('image');
  901. $model->goods_ids = post_params('goods_id');
  902. $model->created_at = time();
  903. if($model->save()){
  904. return $this->asJson(['code' => 0, 'data' => ['works_id'=>$model->id], 'msg' => '配置信息保存成功']);
  905. }
  906. }
  907. /**
  908. * 获取分享页面的信息
  909. * @return \yii\web\Response
  910. * User: hankaige
  911. * DATE TIME: 2023/1/30 13:48
  912. */
  913. public function actionGetWorksItem(){
  914. $id = get_params('id',0);
  915. $item = AccessoriesWorks::findOne($id);
  916. if(!$item){
  917. return $this->asJson(['code'=>1,'msg'=>'作品不存在']);
  918. }
  919. $goodsId = explode(',',$item['goods_ids']);
  920. $goodsList = Goods::find()->where(['id'=>$goodsId,'status'=>1,'store_id' => get_store_id()])->asArray()->all();
  921. foreach ($goodsList as &$value){
  922. $goods = Goods::findOne($value['id']);
  923. $value['attr_group_list'] = $goods->getAttrGroupList();
  924. $value['num'] = $goods->getNum();
  925. }
  926. return $this->asJson(['code'=>0,'data'=>[
  927. 'works' => $item,
  928. 'goods_list' => $goodsList
  929. ]]);
  930. }
  931. /* begin 2023/12/11 15:58:20 WPing丶 */
  932. /**
  933. * 模块名:actionGetInsurance
  934. * 代码描述:通过手机号获取保单
  935. * 作者:WPing丶
  936. * 请求方式:GET
  937. * 创建时间:2023/12/11 15:58:42
  938. * @param int phone 手机号
  939. */
  940. public function actionGetInsurance()
  941. {
  942. $phone = get_params('phone');
  943. $Insurance = Insurance::find()->where(['phone' => $phone, 'store_id' => get_store_id()])->asArray()->one();
  944. $Insurance['insurance_size'] = $this->getFileSize($Insurance['insurance']);
  945. $Insurance['report_size'] = $this->getFileSize($Insurance['report']);
  946. if($Insurance){
  947. return $this->asJson([
  948. 'code' => 0,
  949. 'data' => $Insurance,
  950. 'msg' => '查找成功'
  951. ]);
  952. }else{
  953. return $this->asJson([
  954. 'code' => 1,
  955. 'msg' => '未找到保单'
  956. ]);
  957. }
  958. }
  959. /**
  960. * 模块名:getFileSize
  961. * 代码描述:获取远程文件大小
  962. * 作者:WPing丶
  963. * 请求方式:GET
  964. * 创建时间:2023/12/20 16:33:30
  965. * @param string url 远程文件地址
  966. */
  967. public function getFileSize($url) {
  968. // 使用 cURL 初始化
  969. $ch = curl_init($url);
  970. // 设置 cURL 选项,让其仅获取头部信息
  971. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  972. curl_setopt($ch, CURLOPT_HEADER, true);
  973. curl_setopt($ch, CURLOPT_NOBODY, true);
  974. // 执行 cURL 请求
  975. $response = curl_exec($ch);
  976. // 关闭 cURL 资源
  977. curl_close($ch);
  978. // 解析头部信息,获取文件大小
  979. $headers = explode("\n", $response);
  980. foreach ($headers as $header) {
  981. if (strpos($header, 'Content-Length:') !== false) {
  982. $size = trim(str_replace('Content-Length:', '', $header));
  983. return $this->formatSizeUnits($size);
  984. break;
  985. }
  986. }
  987. }
  988. /**
  989. * 模块名:formatSizeUnits
  990. * 代码描述:字节数转化
  991. * 作者:WPing丶
  992. * 请求方式:GET
  993. * 创建时间:2023/12/20 16:34:28
  994. * @param int bytes 字节数
  995. */
  996. function formatSizeUnits($bytes) {
  997. $units = array('B', 'KB', 'MB', 'GB', 'TB');
  998. $i = 0;
  999. while ($bytes >= 1024 && $i < count($units) - 1) {
  1000. $bytes /= 1024;
  1001. $i++;
  1002. }
  1003. return round($bytes, 2) . ' ' . $units[$i];
  1004. }
  1005. /* end */
  1006. // 获取商品购买记录
  1007. public function actionBuyGoodsLog(){
  1008. $goodsId = get_params('goods_id');
  1009. $time = get_params('time',0);
  1010. $itemQuery = BuyGoodsLog::find()->where(['goods_id'=>$goodsId,'store_id'=>get_store_id()])->andWhere(['>','created_at', time() - 3 * 24 * 3600]);
  1011. if($time){
  1012. $itemQuery->andWhere(['<','created_at',$time]);
  1013. }
  1014. $item = $itemQuery->orderBy('created_at DESC')->asArray()->one();
  1015. if($item){
  1016. $item['nickname'] = func_substr_replace($item['nickname'],'*',1,mb_strlen($item['nickname'],'utf-8') - 1);
  1017. }
  1018. return $this->asJson(['code'=>0,'data'=>$item]);
  1019. }
  1020. /**
  1021. * 扫码获取二维码门店信息
  1022. * @return \yii\web\Response
  1023. * @author: hankaige
  1024. * @Time: 2024/4/16 10:41
  1025. */
  1026. public function actionGetMdInfo(){
  1027. $mdId = get_params('md_id');
  1028. if(empty($mdId)){
  1029. return $this->asJson(['code'=>1,'msg' => '门店ID不能为空']);
  1030. }
  1031. $mdInfo = Md::find()->where(['id'=>$mdId,'store_id'=>get_store_id()])->asArray()->one();
  1032. if($mdInfo){
  1033. return $this->asJson(['code'=>0,'data'=>$mdInfo]);
  1034. }else{
  1035. return $this->asJson(['code'=>1,'msg'=>'门店不存在']);
  1036. }
  1037. }
  1038. /**
  1039. * 地址识别
  1040. */
  1041. public function actionAddressRecognition() {
  1042. try {
  1043. $store_id = get_store_id();
  1044. $content = post_params('content');
  1045. if (empty(trim($content))) {
  1046. throw new \Exception('缺少必填参数');
  1047. }
  1048. $tencent_map_key = Option::get(OptionSetting::TENCENT_MAP_KEY, $store_id, 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, $store_id, 'store', '')['value'])['value'];
  1049. //通过地址信息获取经纬度
  1050. if (empty($tencent_map_key)) {
  1051. $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
  1052. }
  1053. if (empty(trim($tencent_map_key))) {
  1054. throw new \Exception('缺少地图参数 将不能正确获取省市区信息');
  1055. }
  1056. $kuaiDi100UseChange = Option::get(OptionSetting::KUAIDI100_USE_CHANGE, $store_id, 'kuaidi100')['value'];
  1057. if($kuaiDi100UseChange == 1){
  1058. //获取配置信息
  1059. $key = Option::get(OptionSetting::KUAIDI100_SECRET_KEY_NEW, $store_id, 'kuaidi100')['value'];
  1060. $secret = Option::get(OptionSetting::KUAIDI100_SECRET_SECRET_NEW, $store_id, 'kuaidi100')['value'];
  1061. $kuaiDi100Api = new KuaiDi100(['key' => $key, 'secret' => $secret]);
  1062. $result = $kuaiDi100Api->addressResolution($content);
  1063. if($result['code'] != 200){
  1064. throw new \Exception($result['message']);
  1065. }
  1066. $address = [
  1067. 'name' => $result['data']['result'][0]['name'],
  1068. 'mobile' => $result['data']['result'][0]['mobile'][0]
  1069. ];
  1070. $address_area = $result['data']['result'][0]['xzq']['fullName'] . '' . $result['data']['result'][0]['xzq']['subArea'];
  1071. }else{
  1072. //获取配置信息
  1073. $secret_key = Option::get(OptionSetting::KUAIDI100_SECRET_KEY, $store_id, 'kuaidi100')['value'];
  1074. $secret_code = Option::get(OptionSetting::KUAIDI100_SECRET_CODE, $store_id, 'kuaidi100')['value'];
  1075. $secret_secret = Option::get(OptionSetting::KUAIDI100_SECRET_SECRET, $store_id, 'kuaidi100')['value'];
  1076. $secret_sign = Option::get(OptionSetting::KUAIDI100_SECRET_SIGN, $store_id, 'kuaidi100')['value'];
  1077. if (empty($secret_key) || empty($secret_secret) || empty($secret_code)) {
  1078. $secret_key = Option::get(OptionSetting::KUAIDI100_SECRET_KEY, 0, 'saas')['value'];
  1079. $secret_secret = Option::get(OptionSetting::KUAIDI100_SECRET_SECRET, 0, 'saas')['value'];
  1080. $secret_code = Option::get(OptionSetting::KUAIDI100_SECRET_CODE, 0, 'saas')['value'];
  1081. $secret_sign = Option::get(OptionSetting::KUAIDI100_SECRET_SIGN, 0, 'saas')['value'];
  1082. }
  1083. $secret_sign_ = strtoupper(md5($secret_key . $secret_secret));
  1084. if (!empty($secret_sign)) {
  1085. //验证信息 (感觉没必要)
  1086. if ($secret_sign !== $secret_sign_) {
  1087. throw new \Exception('验证签名失败');
  1088. }
  1089. }
  1090. $params = 'secret_key=' . $secret_key . '&';
  1091. $params .= 'secret_code=' . $secret_code .'&';
  1092. $params .= 'secret_sign=' . $secret_sign_ .'&';
  1093. $params .= 'content=' . $content;
  1094. $ch = curl_init();
  1095. curl_setopt($ch,CURLOPT_POST,1);
  1096. curl_setopt($ch,CURLOPT_HEADER,0);
  1097. curl_setopt($ch,CURLOPT_URL,'http://cloud.kuaidi100.com/api');
  1098. curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
  1099. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1100. $result = curl_exec($ch);
  1101. $result = json_decode($result, true);
  1102. if ($result['code'] !== 200) {
  1103. throw new \Exception($result['message']);
  1104. }
  1105. // $result = [
  1106. // 'code' => 200,
  1107. // "message" => "success",
  1108. // "data"=> [
  1109. // [
  1110. // 'address' => "建业智慧港1308",
  1111. // 'mobile' => ['15538531881'],
  1112. // 'name' => '张三',
  1113. // 'content' => "张三,15538531881,河南省洛阳市洛龙区建业智慧港1308",
  1114. // 'xzq' => [
  1115. // 'code' => 410311,
  1116. // 'province' => "河南",
  1117. // 'city' => '洛阳市',
  1118. // 'level' => 3,
  1119. // 'district' => '洛龙区',
  1120. // 'pCode' => '410300',
  1121. // 'fullName' => '河南,洛阳市,洛龙区',
  1122. // 'subArea' => '建业智慧港1308'
  1123. // ]
  1124. // ]
  1125. // ]
  1126. // ];
  1127. $address = [
  1128. 'name' => $result['data'][0]['name'],
  1129. 'mobile' => $result['data'][0]['mobile'][0]
  1130. ];
  1131. $address_area = $result['data'][0]['xzq']['fullName'] . '' . $result['data'][0]['xzq']['subArea'];
  1132. }
  1133. $url = 'https://apis.map.qq.com/ws/geocoder/v1/?';
  1134. $params = [
  1135. 'key' => $tencent_map_key,
  1136. 'address' => $address_area,
  1137. ];
  1138. $url .= http_build_query($params);
  1139. $json = file_get_contents($url);
  1140. $tencent_result = json_decode($json, true);
  1141. if ($tencent_result['status'] !== 0) {
  1142. throw new \Exception($tencent_result['message']);
  1143. }
  1144. $address['latitude'] = $tencent_result['result']['location']['lat'];
  1145. $address['longitude'] = $tencent_result['result']['location']['lng'];
  1146. $address_area = $tencent_result['result']['address_components']['province'] .
  1147. $tencent_result['result']['address_components']['city'] .
  1148. $tencent_result['result']['address_components']['district'] .
  1149. $tencent_result['result']['title'];
  1150. $smart = $this->addressSmart(['address' => $address_area]);
  1151. $address = array_merge($address, $smart);
  1152. $address['addr'] = $result['data']['result'][0]['xzq']['subArea'];
  1153. return $this->asJson([
  1154. 'code' => 0,
  1155. 'msg' => '识别成功',
  1156. 'data' => $address
  1157. ]);
  1158. } catch (\Exception $e) {
  1159. return $this->asJson([
  1160. 'code' => 1,
  1161. 'msg' => $e->getMessage()
  1162. ]);
  1163. }
  1164. }
  1165. //获取商城分类
  1166. public function actionGetStoreCategory()
  1167. {
  1168. return $this->asJson([
  1169. 'code' => 0,
  1170. 'msg' => '',
  1171. 'data' => [
  1172. 'list' => SaasCategory::getList()
  1173. ]
  1174. ]);
  1175. }
  1176. //获取商城列表
  1177. public function actionGetStoreList() {
  1178. try {
  1179. $mch_common_cat_id = get_params('mch_common_cat_id');
  1180. $name = get_params('name');
  1181. $orderByDis = get_params('orderByDis');
  1182. $orderByAi = get_params('orderByAi');
  1183. $lng = get_params('lng', '0') ?: '0';
  1184. $lat = get_params('lat', '0') ?: '0';
  1185. $dis = get_params('dis');
  1186. $pageNo = input_params('pageNo', input_params('page', 1)) ?: 1;
  1187. $pageSize = input_params('pageSize', \Yii::$app->params['pageSize']) ?: \Yii::$app->params['pageSize'];
  1188. $type = intval(get_params('type', 0));
  1189. //查询非独立运营店铺
  1190. $self_mini_store_id = Option::find()->where(['name' => 'self_mini', 'group' => 'store', 'value' => 0])
  1191. ->select('store_id')->column();
  1192. //查询未加入共享流量的店铺 给过滤掉
  1193. $filter_store_id = Option::find()->where([
  1194. 'name' => 'is_store_traffic_sharing',
  1195. 'group' => 'store',
  1196. 'value' => 0,
  1197. 'store_id' => $self_mini_store_id ?: [0]
  1198. ])->select('store_id')->column();
  1199. $store_id = array_values(array_diff($self_mini_store_id, $filter_store_id));
  1200. $saasUser = get_saas_user();
  1201. if ($type) {
  1202. //已购店铺
  1203. if (!$saasUser) {
  1204. return $this->asJson([
  1205. 'code' => 401,
  1206. 'msg' => '登录失败'
  1207. ]);
  1208. }
  1209. $trade_status_str = implode(',', [
  1210. Order::ORDER_FLOW_NO_SEND,
  1211. Order::ORDER_FLOW_SEND,
  1212. Order::ORDER_FLOW_CONFIRM
  1213. ]);
  1214. $store_id_str = implode(',', $store_id ?: [0]);
  1215. $user_table = User::tableName();
  1216. $order_table = Order::tableName();
  1217. $scan_order_table = \app\plugins\scanCodePay\models\Order::tableName();
  1218. $order_sql = "SELECT o.* FROM {$user_table} u LEFT JOIN (
  1219. SELECT user_id, store_id, pay_time, pay_price from {$order_table} WHERE trade_status IN ({$trade_status_str}) UNION ALL
  1220. SELECT user_id, store_id, created_at pay_time, total_price pay_price FROM {$scan_order_table} WHERE is_pay = 1
  1221. ) o ON u.id = o.user_id
  1222. WHERE u.is_delete = 0 AND o.user_id IS NOT NULL ";
  1223. $order_sql_ = $order_sql . " AND u.binding = '{$saasUser->mobile}' AND u.store_id in ({$store_id_str}) GROUP BY o.store_id ";
  1224. $store_id = array_values(array_column(\Yii::$app->db->createCommand($order_sql_)->queryAll(), 'store_id'));
  1225. }
  1226. $store_table_name = Store::tableName();
  1227. $sql = "select s.* from (select id, name, logo, province_id, city_id, district_id, address, contact_tel tel, category_id,
  1228. acos(cos({$lat}*pi()/180 )*cos(latitude*pi()/180)*cos({$lng}*pi()/180 -longitude*pi()/180)+sin({$lat}*pi()/180 )
  1229. *sin(latitude*pi()/180))*6370996.81 as dis from {$store_table_name} where is_delete = 0) as s";
  1230. $store_id_str = implode(',', $store_id ?: [0]);
  1231. $sql .= " where s.id in ({$store_id_str}) ";
  1232. if (!is_null($mch_common_cat_id) && $mch_common_cat_id > 0) {
  1233. $sql .= " and s.category_id = {$mch_common_cat_id} ";
  1234. }
  1235. if (!empty($name)) {
  1236. $name = trim($name);
  1237. $sql .= " AND s.name LIKE '%{$name}%' ";
  1238. }
  1239. if ($dis) {
  1240. $sql .= " AND s.dis <= {$dis} ";
  1241. }
  1242. $orderByStr = '';
  1243. if ($orderByAi) {
  1244. $orderByStr = ' order by s.id ASC';
  1245. }
  1246. if ($orderByDis) {
  1247. $orderByStr = ' order by s.dis asc';
  1248. }
  1249. if (empty($orderByStr)) {
  1250. $orderByStr = ' order by s.id DESC';
  1251. }
  1252. $sql .= $orderByStr;
  1253. $totalCount = \Yii::$app->db->createCommand($sql)->query()->count();
  1254. $pageInitNum = ($pageNo - 1) * $pageSize;
  1255. $sql .= " LIMIT {$pageSize} OFFSET {$pageInitNum}";
  1256. $list = \Yii::$app->db->createCommand($sql)->queryAll();
  1257. // $pagination = pagination_make($query);
  1258. foreach ($list as &$item) {
  1259. $item['dis'] = $item['dis'] ?: 0;
  1260. if(isset($item['dis'])){
  1261. $item['dis_str'] = $item['dis'] > 1000 ? (round($item['dis'] / 1000, 2) . 'km') : (round($item['dis'], 0) . 'm');
  1262. }
  1263. $item['province'] = \app\models\District::findOne($item['province_id'])->name ?: '';
  1264. $item['city'] = \app\models\District::findOne($item['city_id'])->name ?: '';
  1265. $item['district'] = \app\models\District::findOne($item['district_id'])->name ?: '';
  1266. $item['address'] = $item['province'] . $item['city'] . $item['district'] . $item['address'];
  1267. if (empty($item['name'])) {
  1268. $item['name'] = Option::get('name', $item['id'], 'store', '')['value'];
  1269. }
  1270. if (empty($item['logo'])) {
  1271. $item['logo'] = Option::get('web_log', $item['id'], 'web', '')['value'];
  1272. }
  1273. $item['order_count'] = $item['order_total_price'] = 0;
  1274. $item['order_labels'] = '';
  1275. if ($type) {
  1276. //已购店铺
  1277. $user = User::findOne(['store_id' => $item['id'], 'is_delete' => 0, 'binding' => $saasUser->mobile]);
  1278. if ($user) {
  1279. $user_order_data = \Yii::$app->db->createCommand($order_sql . " AND u.id = {$user->id} ORDER BY o.pay_time DESC ")->queryAll();
  1280. $item['order_count'] = count($user_order_data);
  1281. $item['order_total_price'] = floor_num(array_sum(array_column($user_order_data ?: [], 'pay_price')) ?: 0, 2);
  1282. if ($user_order_data) {
  1283. $first_order = $user_order_data[0];
  1284. $first_order_time = $first_order['pay_time'];
  1285. $diff_time = time() - $first_order_time;
  1286. if ($diff_time <= 86400) {
  1287. $item['order_labels'] = '你今天买过的店';
  1288. } else {
  1289. $day = floor($diff_time / 86400);
  1290. $item['order_labels'] = "你{$day}天前买过的店";
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. return $this->asJson([
  1297. 'code' => 0,
  1298. 'msg' => 'success',
  1299. 'data' => [
  1300. 'totalCount' => $totalCount,
  1301. 'list' => $list,
  1302. 'pageNo' => $pageNo,
  1303. 'pageSize' => $pageSize,
  1304. ],
  1305. ]);
  1306. } catch (\Exception $e) {
  1307. \Yii::error($e);
  1308. return $this->asJson([
  1309. 'code' => 1,
  1310. 'msg' => $e->getMessage()
  1311. ]);
  1312. }
  1313. }
  1314. }