StoreController.php 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\constants\OptionSetting;
  9. use app\jobs\StoreSyncJob;
  10. use app\models\AccountLog;
  11. use app\models\ActivityCutPriceLog;
  12. use app\models\ActivityCutPriceOrder;
  13. use app\models\ActivityOrderRebateSelfOrder;
  14. use app\models\ActivityOrderRebateSelfUser;
  15. use app\models\ActivityRebateOrderNLog;
  16. use app\models\Admin;
  17. use app\models\BonusPoolLevel;
  18. use app\models\Cash;
  19. use app\models\Form;
  20. use app\models\IntegralAppreciationCashLog;
  21. use app\models\IntegralAppreciationCommunity;
  22. use app\models\IntegralAppreciationPool;
  23. use app\models\IntegralAppreciationPoolSub;
  24. use app\models\IntegralAppreciationUser;
  25. use app\models\IntegralAppreciationUserIntegralLog;
  26. use app\models\IntegralSetting;
  27. use app\models\OldUserTreePath;
  28. use app\models\Option;
  29. use app\models\Order;
  30. use app\models\OrderComment;
  31. use app\models\OrderDetail;
  32. use app\models\OrderRefund;
  33. use app\models\Promoter;
  34. use app\models\PtActivityOrder;
  35. use app\models\PtActivityOrderDetail;
  36. use app\models\PublicRankingTask;
  37. use app\models\PublicRankingUser;
  38. use app\models\QueueAccountLog;
  39. use app\models\QueueLog;
  40. use app\models\RechargeReOrder;
  41. use app\models\ReportCommitIntegral;
  42. use app\models\ReportInfo;
  43. use app\models\ReportPool;
  44. use app\models\ReportPoolDetail;
  45. use app\models\ReportPoolLevel;
  46. use app\models\SaaSLeaguePriceLog;
  47. use app\models\Share;
  48. use app\models\ShareDetail;
  49. use app\models\ShareGroupMoney;
  50. use app\models\ShareGroupMoneySub;
  51. use app\models\ShareGroupPurchaseParentLog;
  52. use app\models\ShareGroupPurchaseUser;
  53. use app\models\ShareGroupSupportLog;
  54. use app\models\ShareHolder;
  55. use app\models\ShareHolderFrostLog;
  56. use app\models\ShareHolderLevelLog;
  57. use app\models\ShareHolderOutLog;
  58. use app\models\ShareHolderParentOutLog;
  59. use app\models\Store;
  60. use app\models\StoreTemplate;
  61. use app\models\SaasCategory;
  62. use app\models\StoreCopy;
  63. use app\models\SuperSales;
  64. use app\models\SuperSalesMoney;
  65. use app\models\SuperSalesRepeatOrder;
  66. use app\models\SuperSalesSub;
  67. use app\models\SuperSalesUser;
  68. use app\models\TeamBonusOrderExt;
  69. use app\models\TeamGrades;
  70. use app\models\TeamGradesAudit;
  71. use app\models\TeamGradesDividendLog;
  72. use app\models\TeamGradesPool;
  73. use app\models\TeamGradesPoolDetail;
  74. use app\models\TeamGradesPoolDetailExt;
  75. use app\models\User;
  76. use app\models\UserShareMoney;
  77. use app\models\UserTreePath;
  78. use app\models\VideoShopGoodsExt;
  79. use app\models\VideoShopOrderExt;
  80. use app\models\VideoShopOrderExtAli;
  81. use app\models\VideoShopSharer;
  82. use app\models\VideoShopUser;
  83. use app\modules\admin\models\MerchantForm;
  84. use app\modules\admin\models\SubmitFormForm;
  85. use app\modules\client\models\v1\LoginForm;
  86. use app\utils\Delivery\Delivery;
  87. use app\utils\Wechat\WechatMini;
  88. use Yii;
  89. use app\modules\admin\models\StoreForm;
  90. use app\modules\admin\models\SaasCategoryForm;
  91. use yii\base\BaseObject;
  92. use app\models\SaasUser;
  93. use app\models\Salesman;
  94. use yii\helpers\Json;
  95. use app\utils\IotCloudHelper;
  96. use app\constants\Kefu;
  97. use app\models\StoreMoneyLog;
  98. use app\models\Supplier;
  99. use app\models\Mch;
  100. class StoreController extends BaseController
  101. {
  102. /**
  103. * 获取商城列表
  104. */
  105. public function actionList()
  106. {
  107. $admin = get_admin();
  108. $form = new StoreForm();
  109. $admin_id = $admin->id;
  110. if ($admin->username == 'admin' || $admin->type == Admin::ADMIN_TYPE_SAAS_STAFF) {
  111. $admin_id = null;
  112. }
  113. $form->id = get_params("id");
  114. $form->name = get_params("name");
  115. $form->mobile = get_params("mobile");
  116. $form->user_name = get_params("user_name");
  117. $form->category_id = get_params("category_id", -1);
  118. $form->status = get_params('status', -1);
  119. $form->business_model = get_params('business_model', -1);
  120. $form->province_id = get_params('province_id');
  121. $form->city_id = get_params('city_id');
  122. $form->district_id = get_params('district_id');
  123. $form->start_time = get_params('start_time');
  124. $form->end_time = get_params('end_time');
  125. $form->integral_profit_status = get_params('integral_profit_status');
  126. $result = $form->getList($admin_id);
  127. return $this->asJson($result);
  128. }
  129. //申请单列表
  130. public function actionGetAuditList()
  131. {
  132. $form = new StoreForm();
  133. $form->name = get_params("name");
  134. $form->admin_id = get_params("admin_id", 0);
  135. $form->salesman_id = get_params("salesman_id", 0);
  136. $form->status = get_params("status", -1);
  137. $result = $form->getAuditList();
  138. return $this->asJson($result);
  139. }
  140. //申请审核
  141. public function actionStoreAudit()
  142. {
  143. $form = new StoreForm();
  144. $form->id = post_params("id", 0);
  145. $form->status = post_params("status", -1);
  146. $form->business_model = post_params("business_model", -1);
  147. $form->qrcode_id = post_params("qrcode_id", -1);
  148. $result = $form->storeAudit();
  149. return $this->asJson($result);
  150. }
  151. //店铺初始化
  152. public function actionStoreInit()
  153. {
  154. $id = input_params("id", 0);
  155. $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
  156. if($default){
  157. $default = json_decode($default, true);
  158. }else{
  159. return $this->asJson([
  160. 'code' => 0,
  161. 'msg' => '暂无默认模板',
  162. ]);
  163. }
  164. $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $id]), 0, 1);
  165. // $res = StoreCopy::doCopy($default['store_id'], $id, $default['type']);
  166. // return $this->asJson($res);
  167. return $this->asJson([
  168. 'code' => 0,
  169. 'msg' => '操作成功'
  170. ]);
  171. }
  172. //
  173. public function actionGetQrcode()
  174. {
  175. $form = new StoreForm();
  176. $form->business_model = post_params("business_model");
  177. $res = $form->getQrcode();
  178. return $this->asJson($res);
  179. }
  180. //绑定业务员
  181. public function actionBindSalesman()
  182. {
  183. $form = new StoreForm();
  184. $form->id = post_params("id", 0);
  185. $form->salesman_id = post_params("salesman_id", -1);
  186. $result = $form->bindSalesman();
  187. return $this->asJson($result);
  188. }
  189. /**
  190. * @return \yii\web\Response
  191. * 获取没有成为云仓的商城
  192. */
  193. public function actionGetList()
  194. {
  195. $form = new StoreForm();
  196. $result = $form->getStoreList();
  197. return $this->asJson($result);
  198. }
  199. /**
  200. * 添加商城
  201. */
  202. public function actionAdd()
  203. {
  204. $saas_user_id = post_params('saas_user_id');
  205. $name = post_params('name');
  206. $username = post_params('username');
  207. $password = post_params('password');
  208. $area = post_params('area');
  209. $logo = post_params('logo');
  210. // $store_number= post_params('storeNumber');
  211. $form = new StoreForm();
  212. return $this->asJson($form->add($name, $password, $username, $area, $saas_user_id, $logo, 0));
  213. }
  214. public function actionSetData()
  215. {
  216. $form = new StoreForm();
  217. return $this->asJson($form->initStoreData());
  218. }
  219. /**
  220. * 修改密码
  221. */
  222. public function actionSetPassword()
  223. {
  224. $form = new StoreForm();
  225. if (\Yii::$app->request->isPost) {
  226. $store_id = post_params('store_id');
  227. $password = post_params("password");
  228. $name = post_params("name");
  229. $username = post_params("username");
  230. $saas_user_id = post_params("saas_user_id");
  231. $res = $form->setPassword($store_id, $password, $name, $username, $saas_user_id);
  232. } else {
  233. $store_id = get_params('store_id');
  234. $admin = Admin::findOne([
  235. 'type' => 'store',
  236. 'type_id' => $store_id
  237. ]);
  238. $saas_user = SaasUser::findOne($admin->saas_user_id);
  239. $store = Store::findOne($store_id);
  240. $res = [
  241. 'code' => 0,
  242. 'msg' => '获取成功',
  243. 'data' => [
  244. 'name' => $admin->name,
  245. 'username' => $admin->username,
  246. 'saas_user_id' => $admin->saas_user_id,
  247. 'saas_user' => $saas_user,
  248. ]
  249. ];
  250. }
  251. return $this->asJson($res);
  252. }
  253. /**
  254. * 删除商城
  255. */
  256. public function actionDel()
  257. {
  258. $store_id = post_params('store_id');
  259. $form = new StoreForm();
  260. return $this->asJson($form->delete($store_id));
  261. }
  262. /**
  263. * 设置saas分销参数
  264. */
  265. public function actionSetShareParams()
  266. {
  267. $store_id = post_params('storeId') ?: post_params('store_id');
  268. $params = [
  269. 'level' => post_params('level', 0),
  270. 'is_rebate' => post_params('is_rebate', 0),
  271. 'price_type' => post_params('price_type', 0),
  272. 'level_one' => post_params('level_one', 0),
  273. 'level_two' => post_params('level_two', 0),
  274. 'level_three' => post_params('level_three', 0),
  275. ];
  276. $form = new StoreForm();
  277. return $this->asJson($form->setShareParams($store_id, $params));
  278. }
  279. /**
  280. * 设置商铺开通续费金额信息
  281. */
  282. // public function actionSetStoreCost(){
  283. // $store_id = post_params('storeId') ?: post_params('store_id');
  284. // $params = [
  285. // 'open_price' => post_params('open_price', 0),
  286. // 'renew_price' => post_params('renew_price', 0),
  287. // 'end_time' => strtotime(post_params('end_time')),
  288. // 'profit' => post_params('profit', 0),
  289. // 'is_use_default' => post_params('is_use_default', 1),
  290. // ];
  291. // $form = new StoreForm();
  292. // return $this->asJson($form->setCost($store_id, $params));
  293. // }
  294. /**
  295. * 获取商铺开通续费金额信息
  296. */
  297. public function actionGetStoreCost()
  298. {
  299. $store_id = get_params('storeId');
  300. $form = new StoreForm();
  301. return $this->asJson($form->getCost($store_id));
  302. }
  303. /**
  304. * 缴纳商铺费用逻辑
  305. */
  306. public function actionPayFee()
  307. {
  308. $store_id = get_params('storeId');
  309. $form = new StoreForm();
  310. return $this->asJson($form->payFee($store_id));
  311. }
  312. /**
  313. * 判断是否缴纳成功
  314. */
  315. public function actionGetIsPay()
  316. {
  317. $order_id = get_params('order_id');
  318. $form = new StoreForm();
  319. return $this->asJson($form->isPay($order_id));
  320. }
  321. /**
  322. * 获取店铺续费订单
  323. */
  324. public function actionStoreReOrder()
  325. {
  326. $store_id = get_params('store_id');
  327. $form = new StoreForm();
  328. $form->attributes = get_params();
  329. return $this->asJson($form->reOrderList($store_id));
  330. }
  331. /**
  332. * 获取saas分销参数
  333. */
  334. public function actionGetShareParams()
  335. {
  336. $store_id = get_params('storeId');
  337. $form = new StoreForm();
  338. return $this->asJson($form->getShareParams($store_id));
  339. }
  340. /**
  341. * 获取推荐人信息
  342. */
  343. public function actionGetReferralParams()
  344. {
  345. $store_id = get_params('storeId');
  346. $form = new StoreForm();
  347. return $this->asJson($form->getReferralParams($store_id));
  348. }
  349. /**
  350. * 设置推荐人信息
  351. */
  352. public function actionSetReferralParams()
  353. {
  354. $store_id = post_params('storeId');
  355. $params = post_params('lists');
  356. $form = new StoreForm();
  357. return $this->asJson($form->setReferralParams($store_id, $params));
  358. }
  359. /**
  360. * 获取商城返利比例
  361. */
  362. public function actionGetTransferProfitParams()
  363. {
  364. $store_id = get_params('storeId');
  365. $form = new StoreForm();
  366. return $this->asJson($form->getTransferProfitParams($store_id));
  367. }
  368. /**
  369. * 设置商城返利比例
  370. */
  371. public function actionSetTransferProfitParams()
  372. {
  373. $store_id = post_params('storeId');
  374. $params = [
  375. 'transfer_profit' => post_params('transfer_profit', 0),
  376. 'scan_transfer_profit' => post_params('scan_transfer_profit', 0),
  377. 'food_transfer_profit' => post_params('food_transfer_profit', 0),
  378. 'cashier_transfer_profit' => post_params('cashier_transfer_profit', 0),
  379. ];
  380. $form = new StoreForm();
  381. return $this->asJson($form->SetTransferProfitParams($store_id, $params));
  382. }
  383. /**
  384. * 获取商城基本信息
  385. */
  386. public function actionGetStoreInfo()
  387. {
  388. $store_id = get_params('storeId', get_store_id());
  389. $form = new StoreForm();
  390. return $this->asJson($form->getInfo($store_id));
  391. }
  392. public function actionJoinAlliance()
  393. {
  394. $store_id = post_params('storeId', get_store_id());
  395. $status = post_params('status');
  396. $form = new StoreForm();
  397. return $this->asJson($form->joinAlliance($store_id, $status));
  398. }
  399. public function actionGetCheckList()
  400. {
  401. $form = new StoreForm();
  402. return $this->asJson($form->getCheckList());
  403. }
  404. public function actionDouyinInfo()
  405. {
  406. $form = new StoreForm();
  407. $store_id = get_params('storeId', get_store_id());
  408. if (\Yii::$app->request->isPost) {
  409. $content = post_params('content', '');
  410. $params = [
  411. 'app_id' => post_params('app_id', ''),
  412. 'app_secret' => post_params('app_secret', ''),
  413. 'salt' => post_params('salt', ''),
  414. 'token' => post_params('token', '')
  415. ];
  416. return $this->asJson($form->setDouyinInfo($store_id, $content, $params));
  417. }
  418. return $this->asJson($form->getDouyinInfo($store_id));
  419. }
  420. /**
  421. * 获取商城参数
  422. */
  423. public function actionGetStoreParams()
  424. {
  425. $store_id = get_params('storeId');
  426. $form = new StoreForm();
  427. return $this->asJson($form->getStoreParams($store_id));
  428. }
  429. /**
  430. * 设置商城参数
  431. */
  432. public function actionSetStoreParams()
  433. {
  434. $store_id = post_params('storeId');
  435. $params = [
  436. 'name' => post_params('name', ''),
  437. 'balance' => post_params('balance', 0),
  438. 'logo' => post_params('logo', ''),
  439. 'coordinate' => post_params('coordinate', ''),
  440. 'address' => post_params('address', ''),
  441. 'category_id' => post_params('category_id', 0),
  442. 'category_option' => post_params('category_option', []),
  443. 'address_info' => post_params('address_info'),
  444. 'area' => post_params('area'),
  445. 'sales' => post_params('sales', 0),
  446. 'rank' => post_params('rank', 5),
  447. 'per_spend' => post_params('per_spend', 0),
  448. 'tags' => post_params('tags', []),
  449. 'user_name' => post_params('user_name', ''),
  450. 'contact_tel' => post_params('contact_tel', ''),
  451. 'start_time' => post_params('start_time', '00:00'),
  452. 'end_time' => post_params('end_time', '23:59'),
  453. 'open_status' => post_params('open_status', 1),
  454. 'shop_time_type' => post_params('shop_time_type', 0),
  455. 'is_time_forbid' => post_params('is_time_forbid', 1),
  456. 'is_set_distance' => post_params('is_set_distance', 0),
  457. 'distance' => post_params('distance', 0),
  458. 'store_admin' => post_params('store_admin', 0),
  459. 'business_model' => post_params('business_model', 0),
  460. 'self_mini' => post_params('self_mini', 0),
  461. 'store_permission' => post_params('store_permission', []),
  462. 'cost_end_time' => post_params('cost_end_time', []),
  463. 'salesman_id' => post_params('salesman_id', 0),
  464. 'is_add_goods' => post_params('is_add_goods', 1),
  465. 'mini_auth_num' => post_params('mini_auth_num', 0),
  466. 'is_store_traffic_sharing' => post_params('is_store_traffic_sharing', 0),
  467. ];
  468. $form = new StoreForm();
  469. return $this->asJson($form->setStoreParams($store_id, $params));
  470. }
  471. /**
  472. * 获取商城类目数据
  473. */
  474. public function actionGetCategoryInfo()
  475. {
  476. $categoryForm = new SaasCategoryForm();
  477. return $this->asJson($categoryForm->getList(false));
  478. }
  479. /**
  480. * 自定义表单
  481. * @return array|mixed|\yii\web\Response
  482. */
  483. public function actionForm()
  484. {
  485. $store_id = get_store_id();
  486. $form_list = Form::find()->where(['is_delete' => 0, 'store_id' => $store_id])->orderBy(['sort' => SORT_ASC])->asArray()->all();
  487. if (\Yii::$app->request->isPost) {
  488. $form = new SubmitFormForm();
  489. $form->store_id = $store_id;
  490. $form->attributes = post_params();
  491. return $this->asJson($form->save());
  492. }
  493. return $this->asJson([
  494. 'code' => 0,
  495. 'msg' => 'success',
  496. 'data' => [
  497. 'form_list' => $form_list,
  498. 'is_form' => intval(Option::get('is_form', $store_id, 'store', 0)['value']),
  499. 'form_name' => Option::get('form_name', $store_id, 'store', '表单名称')['value']
  500. ]
  501. ]);
  502. }
  503. /**
  504. * @return \yii\web\Response
  505. */
  506. public function actionGetDeliveryInfo()
  507. {
  508. $store_id = get_store_id();
  509. $result = Option::getDeliveryConfig();
  510. $store = Store::findOne($store_id);
  511. $category_one = $category_two = '';
  512. if ($store->delivery_category) {
  513. $arr = explode(',', $store->delivery_category);
  514. $category_one = $arr[0];
  515. $category_two = $arr[1];
  516. }
  517. //判断是否设置地区、地址、坐标、联系人、联系方式 ,否则跳转
  518. $is_jump = 0;
  519. if (empty($store->address) || empty($store->province_id) || empty($store->city_id) || empty($store->district_id) || empty($store->contact_tel) || empty($store->user_name)) {
  520. $is_jump = 1;
  521. }
  522. $data = [
  523. 'type' => $store->delivery_type,
  524. 'config' => $result,
  525. 'wechat_msg_token' => $store->wechat_msg_token ?: '',
  526. 'category_one' => $category_one,
  527. 'category_two' => $category_two,
  528. 'category_level_one' => Delivery::$validLevelOneCategory,
  529. 'category_level_list' => Delivery::$validLevelCategory,
  530. 'is_jump' => $is_jump,
  531. 'wechat_delivery_type' => $store->wechat_delivery_type
  532. ];
  533. $keys = [
  534. 'local_sym_sn',
  535. 'local_sym_key',
  536. 'rsa_sn',
  537. 'rsa_private_key'
  538. ];
  539. $delivery_data = Option::get($keys, $store_id, 'delivery');
  540. if (empty($delivery_data)) {
  541. $delivery_data = [
  542. 'local_sym_sn' => '',
  543. 'local_sym_key' => '',
  544. 'rsa_sn' => '',
  545. 'rsa_private_key' => ''
  546. ];
  547. } else {
  548. $arr = [];
  549. foreach ($delivery_data as $value) {
  550. $index = array_search($value['name'], $keys);
  551. unset($keys[$index]);
  552. $arr[$value['name']] = $value['value'];
  553. }
  554. foreach ($keys as $key) {
  555. $arr[$key] = '';
  556. }
  557. $delivery_data = $arr;
  558. }
  559. $data = array_merge($data, $delivery_data);
  560. return $this->asJson([
  561. 'code' => 0,
  562. 'msg' => 'success',
  563. 'data' => $data
  564. ]);
  565. }
  566. /**
  567. * @return \yii\web\Response
  568. */
  569. public function actionSetDeliveryInfo()
  570. {
  571. $delivery_shop_id = trim(post_params('delivery_shop_id'));
  572. $delivery_app_secret= trim(post_params('delivery_app_secret'));
  573. $delivery_shop_no = trim(post_params('delivery_shop_no' ,''));
  574. $type = trim(post_params('type'));
  575. $wechat_msg_token = trim(post_params('wechat_msg_token'));
  576. $delivery_category_one = post_params('category_one');
  577. $delivery_category_two = post_params('category_two');
  578. $wechat_delivery_type = post_params('wechat_delivery_type', 0);//0即时配送 1同城配送
  579. $local_sym_sn = post_params('local_sym_sn', '');//对称密钥编号
  580. $local_sym_key = post_params('local_sym_key', '');//对称密钥密钥明文
  581. $rsa_sn = post_params('rsa_sn', '');//非对称密钥编号
  582. $rsa_private_key = post_params('rsa_private_key', '');//非对称密钥私玥
  583. $store_id = get_store_id();
  584. $store = Store::findOne($store_id);
  585. $store->wechat_delivery_type = $wechat_delivery_type;
  586. $store->save();
  587. if (intval($wechat_delivery_type) === 0) {
  588. if (empty($delivery_shop_id) || empty($delivery_app_secret) || empty($delivery_shop_no) || empty($wechat_msg_token)
  589. || empty($delivery_category_one) || empty($delivery_category_two) || empty($type)) {
  590. return $this->asJson([
  591. 'code' => 1,
  592. 'msg' => '参数有误'
  593. ]);
  594. }
  595. $res = Delivery::getBindAccount();
  596. if ($res['code'] > 0) {
  597. if ($res['code'] == 48001) {
  598. return $this->asJson([
  599. 'code' => 1,
  600. 'msg' => '请在微信小程序后台开通即时配送物流服务'
  601. ]);
  602. }
  603. }
  604. if (empty($res['data']['shop_list'])) {
  605. return $this->asJson([
  606. 'code' => 1,
  607. 'msg' => '当前未绑定运力账号,暂不能保存选择同城配送方式',
  608. '$res' => $res,
  609. ]);
  610. }
  611. $shop_list = $res['data']['shop_list'];
  612. $delivery_arr = array_column($shop_list, 'delivery_id');
  613. $delivery_arr_id = array_column($shop_list, null, 'delivery_id');
  614. if (!in_array(Delivery::$deliveryIdArr[$type], $delivery_arr) || $delivery_arr_id[Delivery::$deliveryIdArr[$type]]['audit_result'] != 0) {
  615. return $this->asJson([
  616. 'code' => 1,
  617. 'msg' => '当前账号未在微信后台绑定或者并未审核通过'
  618. ]);
  619. }
  620. if ($type == 1) {
  621. Option::set('sf_app_key', $delivery_shop_id, $store_id, 'store');
  622. Option::set('sf_app_secret', $delivery_app_secret, $store_id, 'store');
  623. Option::set('sf_shop_no', $delivery_shop_no, $store_id, 'store');
  624. }
  625. if ($type == 2) {
  626. Option::set('dd_app_key', $delivery_shop_id, $store_id, 'store');
  627. Option::set('dd_app_secret', $delivery_app_secret, $store_id, 'store');
  628. Option::set('dd_shop_no', $delivery_shop_no, $store_id, 'store');
  629. }
  630. if ($type == 3) {
  631. Option::set('ss_app_key', $delivery_shop_id, $store_id, 'store');
  632. Option::set('ss_app_secret', $delivery_app_secret, $store_id, 'store');
  633. Option::set('ss_shop_no', $delivery_shop_no, $store_id, 'store');
  634. }
  635. if ($type == 4) {
  636. Option::set('mt_app_key', $delivery_shop_id, $store_id, 'store');
  637. Option::set('mt_app_secret', $delivery_app_secret, $store_id, 'store');
  638. Option::set('mt_shop_no', $delivery_shop_no, $store_id, 'store');
  639. }
  640. if ($type == 5) {
  641. Option::set('uu_app_key', $delivery_shop_id, $store_id, 'store');
  642. Option::set('uu_app_secret', $delivery_app_secret, $store_id, 'store');
  643. Option::set('uu_shop_no', $delivery_shop_no, $store_id, 'store');
  644. }
  645. $store->delivery_type = $type;
  646. $store->wechat_msg_token = $wechat_msg_token;
  647. $store->delivery_category = $delivery_category_one . ',' . $delivery_category_two;
  648. if ($store->save()) {
  649. return $this->asJson([
  650. 'code' => 0,
  651. 'msg' => 'success',
  652. ]);
  653. }
  654. } else {
  655. $keys = [
  656. 'local_sym_sn',
  657. 'local_sym_key',
  658. 'rsa_sn',
  659. 'rsa_private_key'
  660. ];
  661. $data = [
  662. $local_sym_sn,
  663. $local_sym_key,
  664. $rsa_sn,
  665. $rsa_private_key
  666. ];
  667. Option::set($keys, $data, $store_id, 'delivery');
  668. return $this->asJson([
  669. 'code' => 0,
  670. 'msg' => 'success',
  671. ]);
  672. }
  673. return $this->asJson([
  674. 'code' => 1,
  675. 'msg' => $store->errors[0],
  676. ]);
  677. }
  678. public function actionFoodSettingInfo()
  679. {
  680. $store_id = get_store_id();
  681. $mch_id = intval(get_mch_id());
  682. $store = Store::findOne($store_id);
  683. if($mch_id){
  684. $store = Mch::findOne($mch_id);
  685. }
  686. if (!$store->food_payment) {
  687. $payment = [
  688. [
  689. 'key' => 'alipay',
  690. 'value' => 0,
  691. 'name' => ''
  692. ],
  693. [
  694. 'key' => 'wechat',
  695. 'value' => 1,
  696. 'name' => ''
  697. ],
  698. [
  699. 'key' => 'huodao',
  700. 'value' => 0,
  701. 'name' => ''
  702. ],
  703. [
  704. 'key' => 'friend',
  705. 'value' => 0,
  706. 'name' => ''
  707. ],
  708. ];
  709. $store->food_payment = Json::encode($payment);
  710. $store->save();
  711. }
  712. $default_food_delivery = (int)Option::get('default_food_delivery', $store_id, 'store', 0)['value']; //到店自提
  713. //点餐页面标题
  714. $food_page_title = Option::get('food_page_title', $store_id, 'store', '')['value'];
  715. if($mch_id){
  716. $food_open_time = Option::get('food_open_time', $mch_id, 'mch', '')['value'];
  717. $default_food_delivery = (int)Option::get('default_food_delivery', $mch_id, 'mch', 0)['value']; //到店自提
  718. $food_page_title = Option::get('food_page_title', $mch_id, 'mch', '')['value'];
  719. }
  720. return $this->asJson([
  721. 'code' => 0,
  722. 'msg' => 'success',
  723. 'data' => [
  724. 'food_payment' => Json::decode($store->food_payment),
  725. 'food_pay_type' => $store->food_pay_type,
  726. 'food_open_time' => $food_open_time,
  727. 'default_food_delivery' => $default_food_delivery,
  728. 'food_page_title' => $food_page_title ?: '手机点餐'
  729. ]
  730. ]);
  731. }
  732. public function actionFoodSetting()
  733. {
  734. $store_id = get_store_id();
  735. $mch_id = intval(get_mch_id());
  736. $store = Store::findOne($store_id);
  737. $payment = post_params('food_payment');
  738. $pay_type = post_params('food_pay_type', 0);
  739. $food_page_title = post_params('food_page_title');
  740. $default_food_delivery = post_params('default_food_delivery', 0);
  741. if($mch_id){
  742. $store = Mch::findOne($mch_id);
  743. Option::set('default_food_delivery', $default_food_delivery, $mch_id, 'mch');
  744. $food_open_time = post_params('food_open_time', '');
  745. Option::set('food_open_time', $food_open_time, $mch_id, 'mch');
  746. Option::set('food_page_title', $food_page_title, $mch_id, 'mch');
  747. }else{
  748. Option::set('default_food_delivery', $default_food_delivery, $store_id, 'store');
  749. Option::set('food_page_title', $food_page_title, $store_id, 'store');
  750. }
  751. $store->food_pay_type = $pay_type;
  752. $store->food_payment = $payment;
  753. if (!$store->save()) {
  754. return $this->asJson([
  755. 'code' => 1,
  756. 'msg' => $store->errors
  757. ]);
  758. }
  759. return $this->asJson([
  760. 'code' => 0,
  761. 'msg' => '保存成功'
  762. ]);
  763. }
  764. public function actionChangeJoinUnionStatus()
  765. {
  766. $id = post_params('id');
  767. $status = post_params('status');
  768. if (!$id) {
  769. return $this->asJson([
  770. 'code' => 1,
  771. 'msg' => '参数错误'
  772. ]);
  773. }
  774. if (!in_array($status, [0, 1])) {
  775. return $this->asJson([
  776. 'code' => 1,
  777. 'msg' => '参数错误'
  778. ]);
  779. }
  780. $store = Store::findOne($id);
  781. if (!$store) {
  782. return $this->asJson([
  783. 'code' => 1,
  784. 'msg' => '商城未找到'
  785. ]);
  786. }
  787. $store->is_alliance = $status;
  788. $store->save();
  789. return $this->asJson([
  790. 'code' => 0,
  791. 'msg' => '保存成功'
  792. ]);
  793. }
  794. // app设置
  795. public function actionSettingApp()
  796. {
  797. $store_id = get_store_id();
  798. if (\Yii::$app->request->isPost) {
  799. $client_privacy_id = post_params('client_privacy_id', '');
  800. $client_service_id = post_params('client_service_id', '');
  801. $app_down_android = post_params('app_down_android', '');
  802. $app_down_ios = post_params('app_down_ios', '');
  803. Option::set('client_privacy_id', $client_privacy_id, $store_id, 'app');
  804. Option::set('client_service_id', $client_service_id, $store_id, 'app');
  805. Option::set('app_down_android', $app_down_android, $store_id, 'app');
  806. Option::set('app_down_ios', $app_down_ios, $store_id, 'app');
  807. return $this->asJson([
  808. 'code' => 0,
  809. 'msg' => '保存成功',
  810. ]);
  811. }
  812. $data = [
  813. 'client_privacy_id' => Option::get('client_privacy_id', $store_id, 'app', '')['value'],
  814. 'client_service_id' => Option::get('client_service_id', $store_id, 'app', '')['value'],
  815. 'app_down_android' => Option::get('app_down_android', $store_id, 'app', '')['value'],
  816. 'app_down_ios' => Option::get('app_down_ios', $store_id, 'app', '')['value'],
  817. ];
  818. return $this->asJson([
  819. 'code' => 0,
  820. 'data' => $data,
  821. 'msg' => 'success',
  822. ]);
  823. }
  824. // 版权设置
  825. public function actionCopyrightSetting()
  826. {
  827. $store_id = get_store_id();
  828. if (\Yii::$app->request->isPost) {
  829. $web_name = post_params('web_name', '');
  830. $web_log = post_params('web_log', '');
  831. $copyright = post_params('copyright', '');
  832. $help_logo = post_params('help_logo', '');
  833. $describe = post_params('describe', '');
  834. $passport_bg = post_params('passport_bg', '');
  835. $store_share_title = post_params('store_share_title', '');
  836. $store_share_logo = post_params('store_share_logo', '');
  837. $store_share_desc = post_params('store_share_desc', '');
  838. Option::set('web_name', $web_name, $store_id, 'web');
  839. Option::set('web_log', $web_log, $store_id, 'web');
  840. Option::set('copyright', $copyright, $store_id, 'web');
  841. Option::set('help_logo', $help_logo, $store_id, 'web');
  842. Option::set('describe', $describe, $store_id, 'web');
  843. Option::set('passport_bg', $passport_bg, $store_id, 'web');
  844. // Option::set('store_share_title', $store_share_title, $store_id, 'web');
  845. // Option::set('store_share_logo', $store_share_logo, $store_id, 'web');
  846. // Option::set('store_share_desc', $store_share_desc, $store_id, 'web');
  847. $store = Store::findOne($store_id);
  848. if ($store) {
  849. if ($web_name) {
  850. $store->name = $web_name;
  851. }
  852. if ($web_log) {
  853. $store->logo = $web_log;
  854. }
  855. $store->save();
  856. }
  857. return $this->asJson([
  858. 'code' => 0,
  859. 'msg' => '保存成功',
  860. ]);
  861. }
  862. $data = [
  863. 'web_name' => Option::get('web_name', $store_id, 'web', '')['value'],
  864. 'web_log' => Option::get('web_log', $store_id, 'web', '')['value'],
  865. 'copyright' => Option::get('copyright', $store_id, 'web', '')['value'],
  866. 'passport_bg' => Option::get('passport_bg', $store_id, 'web', '')['value'],
  867. 'help_logo' => Option::get('help_logo', $store_id, 'web', '')['value'],
  868. 'describe' => Option::get('describe', $store_id, 'web', '')['value'],
  869. // 'store_share_title' => Option::get('store_share_title', $store_id, 'web', '')['value'],
  870. // 'store_share_logo' => Option::get('store_share_logo', $store_id, 'web', '')['value'],
  871. // 'store_share_desc' => Option::get('store_share_desc', $store_id, 'web', '')['value'],
  872. ];
  873. return $this->asJson([
  874. 'code' => 0,
  875. 'data' => $data,
  876. 'msg' => 'success',
  877. ]);
  878. }
  879. /**
  880. * 积分设置
  881. * @return \yii\web\Response
  882. */
  883. public function actionIntegralSetting()
  884. {
  885. $store_id = get_store_id();
  886. $data = [
  887. 'register_rule' => '',
  888. 'register_integral' => '1',
  889. 'register_integral_end' => '5',
  890. 'register_continuation' => 0,
  891. 'register_reward' => '1',
  892. 'register_reward_end' => '10',
  893. 'register_status' => 1
  894. ];
  895. $integral_setting = IntegralSetting::findOne(['store_id' => $store_id]);
  896. $integral_setting['register_integral_end'] = $integral_setting['register_integral_end'] ?? '5';
  897. $integral_setting['register_reward_end'] = $integral_setting['register_reward_end'] ?? '5';
  898. $integral_setting['register_status'] = (int)$integral_setting['register_status'];
  899. return $this->asJson(
  900. [
  901. 'code' => 0,
  902. 'msg' => 'success',
  903. 'data' => $integral_setting ?: $data
  904. ]
  905. );
  906. }
  907. /**
  908. * 积分设置保存
  909. * @return \yii\web\Response
  910. */
  911. public function actionIntegralSettingSave()
  912. {
  913. $register_status = post_params('register_status', 1);
  914. $register_rule = post_params('register_rule', '');
  915. $register_integral = post_params('register_integral', 1);
  916. $register_continuation = post_params('register_continuation', 0);
  917. $register_reward = post_params('register_reward', 1);
  918. $register_integral_end = post_params('register_integral_end', 5);
  919. $register_reward_end = post_params('register_reward_end', 5);
  920. $integral_setting = IntegralSetting::findOne(['store_id' => get_store_id()]);
  921. if ($register_integral < 1 || $register_reward_end < 1) {
  922. return $this->asJson([
  923. 'code' => 1,
  924. 'msg' => '积分需大于0'
  925. ]);
  926. }
  927. if ($register_integral_end < $register_integral) {
  928. return $this->asJson([
  929. 'code' => 1,
  930. 'msg' => '每日签到获得分数区间错误'
  931. ]);
  932. }
  933. if ($register_reward_end < $register_reward) {
  934. return $this->asJson([
  935. 'code' => 1,
  936. 'msg' => '连续签到奖励积分区间设置错误'
  937. ]);
  938. }
  939. $integral_setting = $integral_setting ?: new IntegralSetting();
  940. $integral_setting->store_id = get_store_id();
  941. $integral_setting->register_continuation = $register_continuation;
  942. $integral_setting->register_integral = $register_integral;
  943. $integral_setting->register_rule = $register_rule;
  944. $integral_setting->register_reward = $register_reward;
  945. $integral_setting->register_integral_end = $register_integral_end;
  946. $integral_setting->register_reward_end = $register_reward_end;
  947. $integral_setting->register_status = $register_status;
  948. if ($integral_setting->save()) {
  949. return $this->asJson([
  950. 'code' => 0,
  951. 'msg' => '保存成功'
  952. ]);
  953. } else {
  954. return $this->asJson([
  955. 'code' => 1,
  956. 'msg' => $integral_setting->errors[0]
  957. ]);
  958. }
  959. }
  960. /**
  961. * ocr接口调用参数配置
  962. * @return \yii\web\Response
  963. */
  964. public function actionOcrSetting()
  965. {
  966. $default = [
  967. 'app_secret' => '',
  968. 'app_key' => '',
  969. ];
  970. if (\Yii::$app->request->getIsPost()) {
  971. $content = post_params('content', $default);
  972. Option::set('ocr', json_encode($content), get_store_id(), 'store');
  973. return $this->asJson([
  974. 'code' => 0,
  975. 'msg' => '保存成功',
  976. ]);
  977. } else {
  978. $content = Option::get('ocr', get_store_id(), 'store', json_encode($default));
  979. return $this->asJson([
  980. 'code' => 0,
  981. 'msg' => 'success',
  982. 'data' => json_decode($content['value']),
  983. ]);
  984. }
  985. }
  986. // 联盟券设置
  987. public function actionSettingLeague()
  988. {
  989. $store_id = get_store_id();
  990. if (\Yii::$app->request->isPost) {
  991. // $store_this_profit = post_params('store_this_profit', '');
  992. $goods_send_profit = post_params('goods_send_profit', '');
  993. $goods_take_price = post_params('goods_take_price', '');
  994. $is_show_alliance_coupon = post_params('is_show_alliance_coupon', 0);
  995. // Option::set('store_this_profit', $store_this_profit, $store_id, 'store');
  996. Option::set('goods_send_profit', $goods_send_profit, $store_id, 'store');
  997. Option::set('goods_take_price', $goods_take_price, $store_id, 'store');
  998. Option::set('is_show_alliance_coupon', $is_show_alliance_coupon, $store_id, 'store');
  999. return $this->asJson([
  1000. 'code' => 0,
  1001. 'msg' => '保存成功',
  1002. ]);
  1003. }
  1004. $data = [
  1005. // 'store_this_profit' => Option::get('store_this_profit', $store_id, 'store', '')['value'],
  1006. 'goods_send_profit' => Option::get('goods_send_profit', $store_id, 'store', '')['value'],
  1007. 'goods_take_price' => Option::get('goods_take_price', $store_id, 'store', '')['value'],
  1008. 'is_show_alliance_coupon' => Option::get('is_show_alliance_coupon', $store_id, 'store', 0)['value'],
  1009. ];
  1010. return $this->asJson([
  1011. 'code' => 0,
  1012. 'data' => $data,
  1013. 'msg' => 'success',
  1014. ]);
  1015. }
  1016. // 当面付分佣设置
  1017. public function actionSettingFacePayProfit()
  1018. {
  1019. $store_id = get_store_id();
  1020. if (\Yii::$app->request->isPost) {
  1021. $face_first_profit = post_params('face_first_profit', '');
  1022. $face_second_profit = post_params('face_second_profit', '');
  1023. $face_third_profit = post_params('face_third_profit', '');
  1024. // $face_pay_path = post_params('face_pay_path');
  1025. // if (isset($face_pay_path)) {
  1026. // $face_pay_path = json_encode($face_pay_path, JSON_UNESCAPED_UNICODE);
  1027. // Option::set('face_pay_path', $face_pay_path, $store_id,'store');
  1028. // }
  1029. $rate = post_params('rate');
  1030. $rate_type = post_params('rate_type');
  1031. if(isset($rate)){
  1032. Option::set('face_rate', $rate, $store_id, 'store');
  1033. Option::set('face_rate_type', $rate_type, $store_id, 'store');
  1034. }
  1035. Option::set('face_first_profit', $face_first_profit, $store_id, 'store');
  1036. Option::set('face_second_profit', $face_second_profit, $store_id, 'store');
  1037. Option::set('face_third_profit', $face_third_profit, $store_id, 'store');
  1038. return $this->asJson([
  1039. 'code' => 0,
  1040. 'msg' => '保存成功',
  1041. ]);
  1042. }
  1043. $data = [
  1044. 'face_first_profit' => Option::get('face_first_profit', $store_id, 'store', '')['value'],
  1045. 'face_second_profit' => Option::get('face_second_profit', $store_id, 'store', '')['value'],
  1046. 'face_third_profit' => Option::get('face_third_profit', $store_id, 'store', '')['value'],
  1047. 'rate' => Option::get('face_rate', $store_id, 'store')['value'],
  1048. 'rate_type' => Option::get('face_rate_type', $store_id, 'store')['value'],
  1049. // 'face_pay_path' => Option::get('face_pay_path', $store_id, 'store', '')['value']
  1050. ];
  1051. // $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null;
  1052. return $this->asJson([
  1053. 'code' => 0,
  1054. 'data' => $data,
  1055. 'msg' => 'success',
  1056. ]);
  1057. }
  1058. public function actionFaceMarketingProfit()
  1059. {
  1060. $store_id = get_store_id();
  1061. if (\Yii::$app->request->isPost) {
  1062. $send_integral_profit = post_params('send_integral_profit', '');
  1063. Option::set('face_send_integral_profit', $send_integral_profit, $store_id, 'store');
  1064. return $this->asJson([
  1065. 'code' => 0,
  1066. 'msg' => '保存成功',
  1067. ]);
  1068. }
  1069. $data = [
  1070. 'send_integral_profit' => Option::get('face_send_integral_profit', $store_id, 'store', '0')['value']
  1071. ];
  1072. // $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null;
  1073. return $this->asJson([
  1074. 'code' => 0,
  1075. 'data' => $data,
  1076. 'msg' => 'success',
  1077. ]);
  1078. }
  1079. /**
  1080. * 销售溢价比
  1081. */
  1082. public function actionStoreRate()
  1083. {
  1084. try {
  1085. $store_id = get_store_id();
  1086. $store = Store::findOne($store_id);
  1087. $data = [];
  1088. if (\Yii::$app->request->isGet) {
  1089. $cloud_is_update = Option::get('cloud_is_update', $store_id, 'store')['value'];
  1090. $reduce_type = Option::get('reduce_type', $store_id, 'store')['value'];
  1091. $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value'];
  1092. $repeat_update_goods_price = Option::get('repeat_update_goods_price', $store_id, 'store')['value'];
  1093. $store_cloud_send_type = Option::get('store_cloud_send_type', $store_id, 'store')['value'];
  1094. $arr = [
  1095. 'rate' => $store->rate,
  1096. // 'is_auth_trans' => $store->is_auth_trans,
  1097. 'cloud_is_update' => (int)$cloud_is_update,
  1098. 'reduce_type' => $reduce_type,
  1099. 'sale_price_type' => (int)$sale_price_type,
  1100. 'repeat_update_goods_price' => (int)$repeat_update_goods_price,
  1101. 'store_cloud_send_type' => json_decode($store_cloud_send_type, true) ?: ['express']
  1102. ];
  1103. //自动优先扣除方式
  1104. $form = new MerchantForm();
  1105. $result = $form->setCloudMerchantConfig();
  1106. if ($result['code'] === 0) {
  1107. $arr['reduce_type'] = (int)$result['data']['reduce_type'];
  1108. }
  1109. $data = [
  1110. 'code' => 0,
  1111. 'msg' => "获取成功",
  1112. 'data' => $arr
  1113. ];
  1114. } elseif (\Yii::$app->request->isPost) {
  1115. $rate = floatval(post_params('rate', 0));
  1116. $reduce_type = post_params('reduce_type', 0);
  1117. // $is_auth_trans = post_params('is_auth_trans', 0);
  1118. $cloud_is_update = post_params('cloud_is_update', 0);
  1119. $sale_price_type = post_params('sale_price_type', 0);
  1120. $repeat_update_goods_price = post_params('repeat_update_goods_price', 0);
  1121. $store_cloud_send_type = post_params('store_cloud_send_type');
  1122. if (empty($store_cloud_send_type)) {
  1123. throw new \Exception('请选择发货方式');
  1124. }
  1125. if (!is_array($store_cloud_send_type)) {
  1126. throw new \Exception('发货方式格式错误');
  1127. }
  1128. $open = false;
  1129. array_map(function ($item) use (&$open){
  1130. if (!in_array($item, ['express', 'shop', 'delivery'])) {
  1131. $open = true;
  1132. }
  1133. }, $store_cloud_send_type);
  1134. if ($open) {
  1135. throw new \Exception('发货方式格错误');
  1136. }
  1137. Option::set('sale_price_type', $sale_price_type, get_store_id(), 'store');
  1138. Option::set('cloud_is_update', $cloud_is_update, get_store_id(), 'store');
  1139. Option::set('reduce_type', $reduce_type, get_store_id(), 'store');
  1140. Option::set('repeat_update_goods_price', $repeat_update_goods_price, get_store_id(), 'store');
  1141. Option::set('store_cloud_send_type', json_encode($store_cloud_send_type, JSON_UNESCAPED_UNICODE), get_store_id(), 'store');
  1142. $store->rate = $rate;
  1143. // $store->is_auth_trans = $is_auth_trans;
  1144. if (!$store->save()) {
  1145. throw new \Exception(json_encode($store->errors));
  1146. }
  1147. //自动优先扣除方式
  1148. $form = new MerchantForm();
  1149. $result = $form->setCloudMerchantConfig($reduce_type);
  1150. if ($result['code'] === 0) {
  1151. $arr['reduce_type'] = (int)$result['data']['reduce_type'];
  1152. }
  1153. $data = [
  1154. 'code' => 0,
  1155. 'msg' => "操作成功",
  1156. ];
  1157. }
  1158. return $this->asJson($data);
  1159. } catch (\Exception $e) {
  1160. return $this->asJson([
  1161. 'code' => 1,
  1162. 'msg' => $e->getMessage(),
  1163. ]);
  1164. }
  1165. }
  1166. /**
  1167. * 获取设备ID和在线状态
  1168. * @return \yii\web\Response
  1169. * @throws \yii\base\InvalidConfigException
  1170. * @author Syan mzsongyan@gmail.com
  1171. * @date 2022-06-02
  1172. */
  1173. public function actionGetVoiceDeviceInfo()
  1174. {
  1175. $store_id = get_store_id();
  1176. $store = Store::findOne($store_id);
  1177. $deviceName = '';
  1178. $online = 0;
  1179. if ($store->device_name) {
  1180. $deviceName = $store->device_name;
  1181. $result = IotCloudHelper::getDeviceInfo($store_id);
  1182. if ($result['code'] == 0) {
  1183. $online = $result['data']['Online'];
  1184. }
  1185. }
  1186. return $this->asJson([
  1187. 'code' => 0,
  1188. 'msg' => 'success',
  1189. 'data' => [
  1190. 'device_name' => $deviceName,
  1191. 'online' => $online,
  1192. ],
  1193. ]);
  1194. }
  1195. /**
  1196. * 绑定设备
  1197. * @return \yii\web\Response|void
  1198. * @author Syan mzsongyan@gmail.com
  1199. * @date 2022-06-02
  1200. */
  1201. public function actionSetVoiceDeviceInfo()
  1202. {
  1203. try {
  1204. $store_id = get_store_id();
  1205. $store = Store::findOne($store_id);
  1206. $deviceName = post_params('device_name');
  1207. $type = post_params('type');
  1208. if($type == 'unbind'){
  1209. $oldDeviceName = $store->device_name;
  1210. $store->device_name = '';
  1211. $store->save();
  1212. return $this->asJson([
  1213. 'code' => 0,
  1214. 'msg' => '解绑成功,设备:' . $oldDeviceName,
  1215. ]);
  1216. }
  1217. if (!$deviceName) {
  1218. throw new \Exception('请输入设备ID');
  1219. }
  1220. if ($deviceName == $store->device_name) {
  1221. return $this->asJson([
  1222. 'code' => 0,
  1223. 'msg' => '绑定成功',
  1224. ]);
  1225. }
  1226. $exist = Store::find()->where(['device_name' => $deviceName])->andWhere(['<>', 'id', $store_id])->one();
  1227. if ($exist) {
  1228. throw new \Exception('该设备ID已经被使用');
  1229. }
  1230. $oldDeviceName = $store->device_name;
  1231. $store->device_name = $deviceName;
  1232. $store->save();
  1233. $result = IotCloudHelper::getDeviceInfo($store_id);
  1234. if ($result['code'] == 1) {
  1235. $store->device_name = $oldDeviceName;
  1236. $store->save();
  1237. throw new \Exception('设备ID不正确或设备未开机');
  1238. }
  1239. return $this->asJson([
  1240. 'code' => 0,
  1241. 'msg' => '绑定成功',
  1242. ]);
  1243. } catch (\Exception $e) {
  1244. return $this->asJson([
  1245. 'code' => 1,
  1246. 'msg' => $e->getMessage(),
  1247. ]);
  1248. }
  1249. }
  1250. public function actionTestVoiceDevice()
  1251. {
  1252. try {
  1253. $type = post_params('type', 1);
  1254. $store_id = get_store_id();
  1255. $name = '微信';
  1256. if ($type == 2) {
  1257. $name = '支付宝';
  1258. }
  1259. $msg = '{"cmd":"voice","msg":"'. $name .'收款999元"}';
  1260. $result = IotCloudHelper::sendMessage($store_id, $msg);
  1261. \Yii::error($result);
  1262. if ($result['code'] == 1) {
  1263. throw new \Exception($result['msg']);
  1264. }
  1265. return $this->asJson([
  1266. 'code' => 0,
  1267. 'msg' => '发送成功',
  1268. ]);
  1269. } catch (\Exception $e) {
  1270. return $this->asJson([
  1271. 'code' => 1,
  1272. 'msg' => $e->getMessage(),
  1273. ]);
  1274. }
  1275. }
  1276. //获取业务员列表
  1277. public function actionSalesmanList()
  1278. {
  1279. try {
  1280. //如果是代理商登陆
  1281. $admin = get_admin();
  1282. $admin_id = $admin->id;
  1283. if ($admin->username == 'admin') {
  1284. $admin_id = null;
  1285. }
  1286. $query = Salesman::find()->alias('s')->leftJoin(['su' => SaasUser::tableName()], 's.saas_user_id = su.id');
  1287. if ($admin_id) {
  1288. $query->where(['s.admin_id' => $admin_id]);
  1289. }
  1290. $salesman = $query->andWhere(['su.is_delete' => 0, 's.is_delete' => 0, 's.status' => 1, 's.type' => 1])->select('s.id, su.name, su.avatar')->asArray()->all();
  1291. return $this->asJson([
  1292. 'code' => 0,
  1293. 'data' => [
  1294. 'list' => $salesman
  1295. ]
  1296. ]);
  1297. } catch (\Exception $e) {
  1298. return $this->asJson([
  1299. 'code' => 1,
  1300. 'msg' => $e->getMessage()
  1301. ]);
  1302. }
  1303. }
  1304. public function actionStoreCopyStatus()
  1305. {
  1306. $id = input_params('id', 0);
  1307. $do = input_params('do', 0);
  1308. $res = StoreCopy::doCopyStatus($id, $do);
  1309. return $this->asJson($res);
  1310. }
  1311. public function actionStoreCopy()
  1312. {
  1313. $from_store_id = input_params('from_store_id', 0);
  1314. $to_store_id = input_params('to_store_id', 0);
  1315. $type = input_params('type', ['home']);
  1316. $type = json_encode($type);
  1317. $model = new \app\models\StoreCopy();
  1318. $model->from_store_id = $from_store_id;
  1319. $model->to_store_id = $to_store_id;
  1320. $model->type = $type;
  1321. $model->save();
  1322. $id = queue_push(new \app\jobs\StoreCopyJob(['id' => $model->id]));
  1323. $res = [
  1324. 'code' => 0,
  1325. 'msg' => '数据量太大,请等待执行',
  1326. 'id' => $id
  1327. ];
  1328. return $this->asJson($res);
  1329. }
  1330. public function actionStoreCopyList()
  1331. {
  1332. $from_store_id = input_params('from_store_id', 0);
  1333. $to_store_id = input_params('to_store_id', 0);
  1334. $type = input_params('type', '');
  1335. $query = StoreCopy::find()->where(['is_delete' => 0])->orderBy('id desc');
  1336. $from_store_id && $query->andWhere(['from_store_id' => $from_store_id]);
  1337. $to_store_id && $query->andWhere(['to_store_id' => $to_store_id]);
  1338. $type && $query->andWhere(['like', 'type', $type]);
  1339. $list = pagination_make($query);
  1340. foreach($list['list'] as &$item){
  1341. $item['from_store_name'] = Store::findOne($item['from_store_id'])['name'];
  1342. $item['to_store_name'] = Store::findOne($item['to_store_id'])['name'];
  1343. }
  1344. return $this->asJson([
  1345. 'code' => 0,
  1346. 'msg' => 'success',
  1347. 'data' => $list,
  1348. ]);
  1349. }
  1350. public function actionTemplateDefaultInfo()
  1351. {
  1352. $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
  1353. if($default){
  1354. $default = json_decode($default, true);
  1355. }
  1356. return $this->asJson([
  1357. 'code' => 0,
  1358. 'msg' => 'success',
  1359. 'default' => $default,
  1360. ]);
  1361. }
  1362. public function actionTemplateDefaultSave()
  1363. {
  1364. $id = input_params('id', 0);
  1365. $type = input_params('type', ['home']);
  1366. $default = [
  1367. 'store_id' => $id,
  1368. 'type' => $type,
  1369. ];
  1370. \app\models\Option::set('store_template_default', json_encode($default), 0, 'saas');
  1371. return $this->asJson([
  1372. 'code' => 0,
  1373. 'msg' => 'success',
  1374. ]);
  1375. }
  1376. public function actionTemplateStatus()
  1377. {
  1378. $id = input_params('id', 0);
  1379. if(strstr($id, ',')){
  1380. $id = explode(',', $id);
  1381. }
  1382. $status = input_params('status', 0);
  1383. StoreTemplate::updateAll(['status' => $status], ['id'=>$id]);
  1384. return $this->asJson([
  1385. 'code' => 0,
  1386. 'msg' => 'success',
  1387. ]);
  1388. }
  1389. public function actionTemplateDel()
  1390. {
  1391. $id = input_params('id', 0);
  1392. $model = StoreTemplate::findOne($id);
  1393. $model->is_delete = 1;
  1394. $model->save();
  1395. return $this->asJson([
  1396. 'code' => 0,
  1397. 'msg' => 'success',
  1398. ]);
  1399. }
  1400. public function actionTemplateAdd()
  1401. {
  1402. $name = input_params('name', '');
  1403. $desc = input_params('desc', '');
  1404. $home_pic = input_params('home_pic', '[]');
  1405. $center_pic = input_params('center_pic', '[]');
  1406. $category_id = input_params('category_id', 0);
  1407. $store_id = input_params('from_store_id', 0);
  1408. $model = new StoreTemplate();
  1409. $model->name = $name;
  1410. $model->desc = $desc;
  1411. $model->home_pic = json_encode($home_pic);
  1412. $model->center_pic = json_encode($center_pic);
  1413. $model->category_id = $category_id;
  1414. $model->store_id = $store_id;
  1415. $model->save();
  1416. return $this->asJson([
  1417. 'code' => 0,
  1418. 'msg' => 'success',
  1419. ]);
  1420. }
  1421. public function actionTemplateList()
  1422. {
  1423. $status = input_params('status', -1);
  1424. $name = input_params('name', '');
  1425. $category_id = input_params('category_id', 0);
  1426. $cond = ['is_delete' => 0];
  1427. // $name && $cond[] = ['like', 'name', $name];
  1428. $status >= 0 && $cond['status'] = $status;
  1429. $category_id && $cond['category_id'] = $category_id;
  1430. $query = StoreTemplate::find()->where($cond);
  1431. $name && $query->andWhere(['like', 'name', $name]);
  1432. $pagination = pagination_make($query);
  1433. $list = $pagination['list'];
  1434. foreach($list as &$item){
  1435. $item['cat_name'] = '-';
  1436. if ($item['category_id'] > 0) {
  1437. $cat = SaasCategory::findOne($item['category_id']);
  1438. if ($cat) {
  1439. $item['cat_name'] = $cat->name;
  1440. }
  1441. }
  1442. $item['home_pic'] = json_decode($item['home_pic'], true);
  1443. $item['center_pic'] = json_decode($item['center_pic'], true);
  1444. }
  1445. return $this->asJson([
  1446. 'code' => 0,
  1447. 'msg' => 'success',
  1448. 'data' => [
  1449. 'data' => $list,
  1450. 'pageNo' => $pagination['pageNo'],
  1451. 'totalCount' => $pagination['totalCount'],
  1452. ],
  1453. ]);
  1454. }
  1455. /**
  1456. * 获取二维码
  1457. */
  1458. public function actionGetQr()
  1459. {
  1460. $store_id = input_params('id', 0);
  1461. $scene = "store:{$store_id}";
  1462. try{
  1463. $res = \app\utils\ShareQrcode::wxQrcode('pages/home/home', $scene);
  1464. }catch(\Exception $e){
  1465. return $this->asJson([
  1466. 'code' => 1,
  1467. 'msg' => '请检查是否已添加小程序',
  1468. 'e' => $e,
  1469. ]);
  1470. }
  1471. if (isset($res['code']) && $res['code'] == 1) {
  1472. return $this->asJson([
  1473. 'code' => 1,
  1474. 'msg' => $res['response']['errmsg'],
  1475. ]);
  1476. }
  1477. return $this->asJson([
  1478. 'code' => 0,
  1479. 'data' => $res['url_path']
  1480. ]);
  1481. }
  1482. public function actionGetKefuInfo()
  1483. {
  1484. $store = Store::findOne(get_store_id());
  1485. if (!$store) {
  1486. return $this->asJson([
  1487. 'code' => 1,
  1488. 'msg' => '数据不存在',
  1489. ]);
  1490. }
  1491. $kefu_auto_reply_img = Option::get('kefu_auto_reply_img', $store->id, 'store', '')['value'];
  1492. $kefu_auto_reply_text = Option::get('kefu_auto_reply_text', $store->id, 'store', '')['value'];
  1493. $is_show_kefu_download = Option::get('is_show_kefu_download', 0, 'saas', 1)['value'];
  1494. return $this->asJson([
  1495. 'code' => 0,
  1496. 'msg' => 'success',
  1497. 'data'=> [
  1498. 'kefu_id' => $store->kefu_id ?: '',
  1499. 'kefu_auto_reply_img' => $kefu_auto_reply_img,
  1500. 'kefu_auto_reply_text' => $kefu_auto_reply_text,
  1501. 'is_show_kefu_download' => intval($is_show_kefu_download)
  1502. ]
  1503. ]);
  1504. }
  1505. public function actionSetKefuInfo()
  1506. {
  1507. $kefu_id = \post_params('kefu_id', '');
  1508. $kefu_auto_reply_img = \post_params('kefu_auto_reply_img', '');
  1509. $kefu_auto_reply_text = \post_params('kefu_auto_reply_text', '');
  1510. $store = Store::findOne(get_store_id());
  1511. if (!$store) {
  1512. return $this->asJson([
  1513. 'code' => 1,
  1514. 'msg' => '数据不存在',
  1515. ]);
  1516. }
  1517. Option::set('kefu_auto_reply_img', $kefu_auto_reply_img, $store->id, 'store');
  1518. Option::set('kefu_auto_reply_text', $kefu_auto_reply_text, $store->id, 'store');
  1519. if (!empty($kefu_id)) {
  1520. if (!preg_match('/^1[3456789]\d{9}$/i', $kefu_id)) {
  1521. return $this->asJson([
  1522. 'code' => 1,
  1523. 'msg' => '客服手机号格式错误',
  1524. ]);
  1525. }
  1526. $url = Kefu::API_HOST;
  1527. $host = \str_replace(['http://', 'https://'], '', \Yii::$app->request->hostInfo);
  1528. $res = http_post($url . '/api/regKefu', [
  1529. 'form_params' => [
  1530. 'token' => \Yii::$app->getKefuApiToken(),
  1531. 'host' => $host,
  1532. 'mobile' => $kefu_id,
  1533. 'kefu_auto_reply_img' => $kefu_auto_reply_img,
  1534. 'kefu_auto_reply_text' => $kefu_auto_reply_text,
  1535. ]
  1536. ]);
  1537. if ($res->getStatusCode() != 200) {
  1538. return $this->asJson([
  1539. 'code' => 1,
  1540. 'msg' => '请求出错!',
  1541. ]);
  1542. }
  1543. $content = json_decode((string)$res->getBody(), true);
  1544. if ($content['code'] == 0) {
  1545. $store->kefu_id = $kefu_id;
  1546. $store->save();
  1547. }
  1548. } else {
  1549. $store->kefu_id = '';
  1550. $store->save();
  1551. $content = [
  1552. 'code' => 0,
  1553. 'msg' => '保存成功',
  1554. ];
  1555. }
  1556. return $this->asJson($content);
  1557. }
  1558. //清除数据可选项
  1559. public function actionDelShareHolderOption() {
  1560. $array = [
  1561. [
  1562. 'title' => '用户',
  1563. 'key' => 'user',
  1564. 'is_checked' => 1,
  1565. 'is_disabled' => 1
  1566. ],
  1567. [
  1568. 'title' => '订单',
  1569. 'key' => 'order',
  1570. 'is_checked' => 1,
  1571. 'is_disabled' => 1
  1572. ],
  1573. [
  1574. 'title' => '链动2+1',
  1575. 'key' => 'shareHolder',
  1576. 'is_checked' => 1,
  1577. 'is_disabled' => 0
  1578. ],
  1579. [
  1580. 'title' => '全域分佣',
  1581. 'key' => 'report',
  1582. 'is_checked' => 0,
  1583. 'is_disabled' => 0
  1584. ],
  1585. [
  1586. 'title' => '37拼购',
  1587. 'key' => 'shareGroup',
  1588. 'is_checked' => 0,
  1589. 'is_disabled' => 0
  1590. ],
  1591. [
  1592. 'title' => '团队极差分红',
  1593. 'key' => 'teamBonus',
  1594. 'is_checked' => 0,
  1595. 'is_disabled' => 0
  1596. ],
  1597. [
  1598. 'title' => '团队业绩分红',
  1599. 'key' => 'teamGrades',
  1600. 'is_checked' => 0,
  1601. 'is_disabled' => 0
  1602. ],
  1603. [
  1604. 'title' => '超级卖货',
  1605. 'key' => 'superSales',
  1606. 'is_checked' => 0,
  1607. 'is_disabled' => 0
  1608. ],
  1609. [
  1610. 'title' => '增值积分',
  1611. 'key' => 'integralAppreciation',
  1612. 'is_checked' => 0,
  1613. 'is_disabled' => 0
  1614. ],
  1615. [
  1616. 'title' => '视频号爆单',
  1617. 'key' => 'videoShop',
  1618. 'is_checked' => 0,
  1619. 'is_disabled' => 0
  1620. ],
  1621. [
  1622. 'title' => '排队免单',
  1623. 'key' => 'freeQueue',
  1624. 'is_checked' => 0,
  1625. 'is_disabled' => 0
  1626. ],
  1627. ];
  1628. return $this->asJson([
  1629. 'code' => 0,
  1630. 'msg' => '',
  1631. 'data' => [
  1632. 'key_list' => $array
  1633. ]
  1634. ]) ;
  1635. }
  1636. //删除链动以及其他测试数据
  1637. public function actionDelShareHolderTestInfo()
  1638. {
  1639. try {
  1640. $safe_code = post_params('safe_code');
  1641. $captcha = post_params('captcha');
  1642. $del_key = post_params('del_key');
  1643. $store = Store::findOne(get_store_id());
  1644. if (empty($safe_code) && empty($safe_code)) {
  1645. throw new \Exception("安全码和验证码二选一");
  1646. }
  1647. if (!empty($captcha)) {
  1648. $form = new LoginForm();
  1649. $form->store_id = get_store_id();
  1650. $form->phone = $store->contact_tel;
  1651. $form->verify_code = $captcha;
  1652. $verifySmsCode = $form->verifySmsCode(LoginForm::TYPE_VERIFY_CODE_CLEAR);
  1653. if ($verifySmsCode['code'] != 0) {
  1654. throw new \Exception($verifySmsCode['msg']);
  1655. }
  1656. }
  1657. if (!empty($safe_code)) {
  1658. if ($safe_code !== "@TianXin100We10Cn") {
  1659. throw new \Exception("安全码错误");
  1660. }
  1661. }
  1662. $user = User::find()->where(['store_id' => get_store_id()])->select('id, binding')->asArray()->all();
  1663. $user_id = array_column($user, 'id');
  1664. $user_mobile = array_column($user, 'binding');
  1665. $del_key = $del_key ?: [];
  1666. $order_id = Order::find()->where(['store_id' => get_store_id()])->select('id')->column();
  1667. Order::deleteAll(['store_id' => get_store_id()]);
  1668. OrderDetail::deleteAll(['order_id' => $order_id]);
  1669. OrderRefund::deleteAll(['store_id' => get_store_id()]);
  1670. OrderComment::deleteAll(['store_id' => get_store_id()]);
  1671. // SaasUser::deleteAll();
  1672. User::deleteAll(['store_id' => get_store_id()]);
  1673. SaasUser::updateAll(['access_token' => ''], ['mobile' => $user_mobile]);
  1674. UserTreePath::deleteAll(["OR", ['parent_id' => $user_id], ['child_id' => $user_id]]);
  1675. OldUserTreePath::deleteAll(["OR", ['parent_id' => $user_id], ['child_id' => $user_id]]);
  1676. ShareDetail::deleteAll(['store_id' => get_store_id()]);
  1677. ShareHolder::deleteAll(['store_id' => get_store_id()]);
  1678. ShareHolderFrostLog::deleteAll(["OR", ['parent_user_id' => $user_id], ['child_user_id' => $user_id]]);
  1679. ShareHolderOutLog::deleteAll(["OR", ['parent_user_id' => $user_id], ['child_user_id' => $user_id]]);
  1680. BonusPoolLevel::deleteAll(['store_id' => get_store_id()]);
  1681. ShareHolderLevelLog::deleteAll(['store_id' => get_store_id()]);
  1682. ShareHolderParentOutLog::deleteAll(['store_id' => get_store_id()]);
  1683. Cash::deleteAll(['store_id' => get_store_id()]);
  1684. AccountLog::deleteAll(['store_id' => get_store_id()]);
  1685. \app\plugins\scanCodePay\models\Order::deleteAll(['store_id' => get_store_id()]);
  1686. Share::deleteAll(['store_id' => get_store_id()]);
  1687. UserShareMoney::deleteAll(['store_id' => get_store_id()]);
  1688. //拼团
  1689. // $ptActivityOrderId = PtActivityOrder::find()->where(['store_id' => get_store_id()])->select('id')->column();
  1690. // PtActivityOrder::deleteAll(['store_id' => get_store_id()]);
  1691. // PtActivityOrderDetail::deleteAll(['order_id' => $ptActivityOrderId]);
  1692. //砍价
  1693. // ActivityCutPriceLog::deleteAll(['store_id' => get_store_id()]);
  1694. // ActivityCutPriceOrder::deleteAll(['store_id' => get_store_id()]);
  1695. //消费全返
  1696. // ActivityOrderRebateSelfOrder::deleteAll(['store_id' => get_store_id()]);
  1697. // ActivityOrderRebateSelfUser::deleteAll(['store_id' => get_store_id()]);
  1698. //推N返1
  1699. // ActivityRebateOrderNLog::deleteAll(['store_id' => get_store_id()]);
  1700. //全域分佣
  1701. if (in_array('report', $del_key)) {
  1702. ReportCommitIntegral::deleteAll(['store_id' => get_store_id()]);
  1703. ReportInfo::deleteAll(['store_id' => get_store_id()]);
  1704. ReportPool::deleteAll(['store_id' => get_store_id()]);
  1705. ReportPoolDetail::deleteAll(['store_id' => get_store_id()]);
  1706. ReportPoolLevel::deleteAll(['store_id' => get_store_id()]);
  1707. }
  1708. //团队级差分红
  1709. if (in_array('teamBonus', $del_key)) {
  1710. TeamBonusOrderExt::deleteAll(['store_id' => get_store_id()]);
  1711. }
  1712. //37拼购
  1713. if (in_array('shareGroup', $del_key)) {
  1714. $shareGroupMoneyId = ShareGroupMoney::find()->where(['store_id' => get_store_id()])->select('id')->column();
  1715. ShareGroupMoney::deleteAll(['store_id' => get_store_id()]);
  1716. ShareGroupMoneySub::deleteAll(['share_money_id' => $shareGroupMoneyId]);
  1717. ShareGroupSupportLog::deleteAll(['store_id' => get_store_id()]);
  1718. ShareGroupPurchaseParentLog::deleteAll(['store_id' => get_store_id()]);
  1719. ShareGroupPurchaseUser::deleteAll(['store_id' => get_store_id()]);
  1720. }
  1721. //超级卖货系统
  1722. if (in_array('superSales', $del_key)) {
  1723. $superSalesId = SuperSales::find()->where(['store_id' => get_store_id()])->select('id')->column();
  1724. SuperSales::deleteAll(['store_id' => get_store_id()]);
  1725. SuperSalesSub::deleteAll(['sales_id' => $superSalesId]);
  1726. SuperSalesUser::deleteAll(['store_id' => get_store_id()]);
  1727. SuperSalesMoney::deleteAll(['store_id' => get_store_id()]);
  1728. SuperSalesRepeatOrder::deleteAll(['store_id' => get_store_id()]);
  1729. }
  1730. //团队业绩
  1731. if (in_array('teamGrades', $del_key)) {
  1732. TeamGrades::deleteAll(['store_id' => get_store_id()]);
  1733. TeamGradesAudit::deleteAll(['store_id' => get_store_id()]);
  1734. TeamGradesDividendLog::deleteAll(['store_id' => get_store_id()]);
  1735. $teamGradesPoolId = TeamGradesPool::find()->where(['store_id' => get_store_id()])->select('id')->column();
  1736. TeamGradesPool::deleteAll(['store_id' => get_store_id()]);
  1737. TeamGradesPoolDetail::deleteAll(['pool_id' => $teamGradesPoolId]);
  1738. TeamGradesPoolDetailExt::deleteAll(['order_id' => $order_id]);
  1739. }
  1740. //消费积分增值
  1741. if (in_array('integralAppreciation', $del_key)) {
  1742. IntegralAppreciationCommunity::deleteAll(['store_id' => get_store_id()]);
  1743. IntegralAppreciationUser::deleteAll(['store_id' => get_store_id()]);
  1744. IntegralAppreciationCashLog::deleteAll(['user_id' => $user_id]);
  1745. IntegralAppreciationUserIntegralLog::deleteAll(['order_id' => $order_id]);
  1746. IntegralAppreciationPool::deleteAll(['store_id' => get_store_id()]);
  1747. IntegralAppreciationPoolSub::deleteAll(['store_id' => get_store_id()]);
  1748. }
  1749. //视频号爆单
  1750. if (in_array('videoShop', $del_key)) {
  1751. PublicRankingTask::deleteAll(['store_id' => get_store_id()]);
  1752. PublicRankingUser::deleteAll(['store_id' => get_store_id()]);
  1753. Promoter::deleteAll(['store_id' => get_store_id()]);
  1754. VideoShopGoodsExt::deleteAll(['store_id' => get_store_id()]);
  1755. VideoShopOrderExt::deleteAll(['store_id' => get_store_id()]);
  1756. VideoShopUser::deleteAll(['store_id' => get_store_id()]);
  1757. VideoShopOrderExtAli::deleteAll(['store_id' => get_store_id()]);
  1758. VideoShopSharer::deleteAll(['store_id' => get_store_id()]);
  1759. }
  1760. //排队免单
  1761. if (in_array('freeQueue', $del_key)) {
  1762. QueueAccountLog::deleteAll(['store_id' => get_store_id()]);
  1763. QueueLog::deleteAll(['store_id' => get_store_id()]);
  1764. }
  1765. return $this->asJson([
  1766. 'code' => 0,
  1767. 'msg' => "操作成功"
  1768. ]);
  1769. } catch (\Exception $e) {
  1770. return $this->asJson([
  1771. 'code' => 1,
  1772. 'msg' => $e->getMessage()
  1773. ]);
  1774. }
  1775. }
  1776. public function actionSendCode()
  1777. {
  1778. $form = new LoginForm();
  1779. $store = Store::findOne(get_store_id());
  1780. $form->phone = $store->contact_tel;
  1781. $form->store_id = get_store_id();
  1782. return $this->asJson($form->sendCode(LoginForm::TYPE_VERIFY_CODE_CLEAR));
  1783. }
  1784. public function actionTimerTaskCopy()
  1785. {
  1786. $autoDownGoods = \Yii::$app->request->hostInfo . '/index.php?r=common/task/auto-off-goods';
  1787. $order = \Yii::$app->request->hostInfo . '/index.php?r=common/task/execute';
  1788. $queue = '';
  1789. $user = get_current_user();
  1790. $www_path = \Yii::$app->basePath . '/';
  1791. $queue_cli = '';
  1792. \ob_start();
  1793. \phpinfo(INFO_GENERAL);
  1794. $phpinfo = \ob_get_contents();
  1795. ob_end_clean();
  1796. \preg_match("/--prefix=(.*)&#039; &#039;/U", $phpinfo, $matches);
  1797. if (isset($matches[1])) {
  1798. $queue_cli = $matches[1] . '/bin/php yii queue/listen';
  1799. $queue = 'su -c "' . $matches[1] . '/bin/php ' . \Yii::$app->basePath . '/yii queue/run' . '" -s /bin/sh ' . $user;
  1800. } else {
  1801. $queue = '获取php cli路径失败, 请手动获取';
  1802. }
  1803. return $this->asJson([
  1804. 'code' => 0,
  1805. 'data' => [
  1806. 'autoDownGoods' => $autoDownGoods,
  1807. 'order' => $order,
  1808. 'queue' => $queue,
  1809. 'queue_cli' => $queue_cli,
  1810. 'www_path' => $www_path,
  1811. ],
  1812. 'msg' => 'success'
  1813. ]);
  1814. }
  1815. public function actionSetAppParams()
  1816. {
  1817. try {
  1818. if (\Yii::$app->request->isPost) {
  1819. $key = [
  1820. OptionSetting::APP_STORE_ANDROID,
  1821. OptionSetting::APP_STORE_ANDROID_VERSION,
  1822. OptionSetting::STORE_APP_LOGO,
  1823. OptionSetting::STORE_APP_BG,
  1824. OptionSetting::APP_STORE_IOS,
  1825. OptionSetting::APP_IS_OPEN_MAP,
  1826. OptionSetting::MAP_APP_CODE,
  1827. ];
  1828. $params = post_params();
  1829. $value = [
  1830. $params['app_store_android'],
  1831. $params['app_store_android_version'],
  1832. $params['store_app_logo'],
  1833. $params['store_app_bg'],
  1834. $params['app_store_ios'],
  1835. $params['app_is_open_map'],
  1836. $params['map_app_code'],
  1837. ];
  1838. Option::set($key, $value, get_store_id(), 'app');
  1839. return $this->asJson([
  1840. 'code' => 0,
  1841. 'msg' => ''
  1842. ]);
  1843. } else {
  1844. $keys = [
  1845. OptionSetting::APP_STORE_ANDROID,
  1846. OptionSetting::APP_STORE_ANDROID_VERSION,
  1847. OptionSetting::STORE_APP_LOGO,
  1848. OptionSetting::STORE_APP_BG,
  1849. OptionSetting::APP_STORE_IOS,
  1850. OptionSetting::APP_IS_OPEN_MAP,
  1851. OptionSetting::MAP_APP_CODE,
  1852. ];
  1853. $data = Option::get($keys, get_store_id(), 'app');
  1854. if (empty($data)) {
  1855. $data = [
  1856. OptionSetting::APP_STORE_ANDROID => '',
  1857. OptionSetting::APP_STORE_ANDROID_VERSION => '',
  1858. OptionSetting::STORE_APP_LOGO => '',
  1859. OptionSetting::STORE_APP_BG => '',
  1860. OptionSetting::APP_STORE_IOS => '',
  1861. OptionSetting::APP_IS_OPEN_MAP => 2,
  1862. OptionSetting::MAP_APP_CODE => '',
  1863. ];
  1864. } else {
  1865. $arr = [];
  1866. foreach ($data as $value) {
  1867. $index = array_search($value['name'], $keys);
  1868. unset($keys[$index]);
  1869. $arr[$value['name']] = $value['value'];
  1870. }
  1871. foreach ($keys as $key) {
  1872. $arr[$key] = '';
  1873. }
  1874. $data = $arr;
  1875. }
  1876. return $this->asJson([
  1877. 'code' => 0,
  1878. 'msg' => 'success',
  1879. 'data' => $data,
  1880. ]);
  1881. }
  1882. } catch (\Exception $e) {
  1883. return $this->asJson([
  1884. 'code' => 1,
  1885. 'msg' => $e->getMessage()
  1886. ]);
  1887. }
  1888. }
  1889. //设置商城版权信息
  1890. public function actionSetCopyright()
  1891. {
  1892. try {
  1893. $store_id = input_params('id') ?? get_store_id();
  1894. if (\Yii::$app->request->isPost) {
  1895. $copyright_params = [];
  1896. $copyright_params['type'] = post_params('type') ?? 0;
  1897. $copyright_params['mini_url'] = post_params('mini_url') ?? '';
  1898. $copyright_params['mobile'] = post_params('mobile') ?? '';
  1899. $copyright_params['logo'] = post_params('logo') ?? '';
  1900. $copyright_params['copyright'] = post_params('copyright') ?? '';
  1901. Option::set('copyright', json_encode($copyright_params), $store_id, 'store');
  1902. return $this->asJson([
  1903. 'code' => 0,
  1904. 'msg' => '操作成功'
  1905. ]);
  1906. } else {
  1907. $copyright = Option::get('copyright', $store_id, 'store', '')['value'];
  1908. $store_admin = Admin::findOne(['type' => 'store', 'type_id' => $store_id, 'is_delete' => 0]);
  1909. $store = Store::findOne($store_id);
  1910. $copyright = json_decode($copyright, true) ?: [
  1911. 'type' => 1,
  1912. 'mini_url' => [
  1913. 'name' => '商城首页',
  1914. 'link' => '/pages/home/home',
  1915. 'open_type' => "switchtab",
  1916. 'params' => []
  1917. ],
  1918. 'mobile' => $store_admin->mobile ?? '',
  1919. 'logo' => $store->logo ?: (Option::get('logo', $store_id, 'store')['value'] ?: Option::get('web_log', $store_id, 'web')['value']),
  1920. 'copyright' => $store->name
  1921. ];
  1922. $copyright['type'] = intval($copyright['type']);
  1923. return $this->asJson([
  1924. 'code' => 0,
  1925. 'msg' => '获取成功',
  1926. 'data' => $copyright
  1927. ]);
  1928. }
  1929. } catch (\Exception $e) {
  1930. return $this->asJson([
  1931. 'code' => 1,
  1932. 'msg' => $e->getMessage()
  1933. ]);
  1934. }
  1935. }
  1936. //设置商城联盟积分比例
  1937. public function actionSetStoreIntegral()
  1938. {
  1939. try {
  1940. $store_id = input_params('id') ?? get_store_id();
  1941. if (\Yii::$app->request->isPost) {
  1942. $face_pay_integral_profit = post_params('face_pay_integral_profit', 0);
  1943. $online_pay_integral_profit = post_params('online_pay_integral_profit', 0);
  1944. Option::set([
  1945. 'face_pay_integral_profit',
  1946. 'online_pay_integral_profit'
  1947. ], [
  1948. $face_pay_integral_profit,
  1949. $online_pay_integral_profit
  1950. ], $store_id, 'saas');
  1951. return $this->asJson([
  1952. 'code' => 0,
  1953. 'msg' => '保存成功'
  1954. ]);
  1955. } else {
  1956. $face_pay_integral_profit = Option::get('face_pay_integral_profit', $store_id, 'saas', 0)['value'];
  1957. $online_pay_integral_profit = Option::get('online_pay_integral_profit', $store_id, 'saas', 0)['value'];
  1958. return $this->asJson([
  1959. 'code' => 0,
  1960. 'msg' => '获取成功',
  1961. 'data' => [
  1962. 'face_pay_integral_profit' => $face_pay_integral_profit,
  1963. 'online_pay_integral_profit' => $online_pay_integral_profit,
  1964. ]
  1965. ]);
  1966. }
  1967. } catch (\Exception $e) {
  1968. return $this->asJson([
  1969. 'code' => 1,
  1970. 'msg' => $e->getMessage()
  1971. ]);
  1972. }
  1973. }
  1974. // 当面付支付后跳转设置
  1975. public function actionSettingFacePayPath()
  1976. {
  1977. $store_id = get_store_id();
  1978. if (\Yii::$app->request->isPost) {
  1979. $face_pay_path = post_params('face_pay_path', '');
  1980. $face_pay_path = json_encode($face_pay_path, JSON_UNESCAPED_UNICODE);
  1981. Option::set('face_pay_path', $face_pay_path, 0, 'saas');
  1982. return $this->asJson([
  1983. 'code' => 0,
  1984. 'msg' => '保存成功',
  1985. ]);
  1986. }
  1987. $data = [
  1988. 'face_pay_path' => Option::get('face_pay_path', 0, 'saas', '')['value']
  1989. ];
  1990. $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null;
  1991. return $this->asJson([
  1992. 'code' => 0,
  1993. 'data' => $data,
  1994. 'msg' => 'success',
  1995. ]);
  1996. }
  1997. //联盟券列表
  1998. public function actionStoreLeagueLog()
  1999. {
  2000. // 区分平台或者商城
  2001. $store_id = get_params('store_id');
  2002. //条件
  2003. $user_name = get_params('user_name');
  2004. $mobile = get_params('mobile');
  2005. $start_time = get_params('start_time');
  2006. $end_time = get_params('end_time');
  2007. //
  2008. $query = SaaSLeaguePriceLog::find()->alias('lpl')
  2009. ->where(['lpl.role' => SaaSLeaguePriceLog::ROLE_USER, 'lpl.is_delete' => 0])
  2010. ->andWhere(['>', 'lpl.league_price', 0]);
  2011. if ($store_id) {
  2012. $query->andWhere(['lpl.store_id' => $store_id]);
  2013. }
  2014. if ($user_name) {
  2015. $query->andWhere(['LIKE', 'su.name', $user_name]);
  2016. }
  2017. if ($mobile) {
  2018. $query->andWhere(['LIKE', 'su.mobile', $mobile]);
  2019. }
  2020. if ($start_time) {
  2021. $start_time = strtotime($start_time);
  2022. $query->andWhere(['>=', 'lpl.addtime', $start_time]);
  2023. }
  2024. if ($end_time) {
  2025. $end_time = strtotime($end_time);
  2026. $query->andWhere(['<=', 'lpl.addtime', $end_time]);
  2027. }
  2028. $query->leftJoin(['su' => SaasUser::tableName()], 'su.id = lpl.saas_user_id');
  2029. $query->select('lpl.id, lpl.saas_user_id, lpl.type, lpl.order_id, lpl.send_or_take_type, lpl.store_id,
  2030. lpl.after, lpl.before, lpl.league_price, lpl.addtime, su.name user_name, su.mobile user_mobile, su.avatar user_avatar')
  2031. ->orderBy('lpl.id desc');
  2032. $pagination = pagination_make($query);
  2033. foreach ($pagination['list'] as &$item) {
  2034. $item['addtime'] = date("Y-m-d H:i:s", $item['addtime']);
  2035. $item['send_or_take_type'] = (int)$item['send_or_take_type'];
  2036. $item['type'] = (int)$item['type'];
  2037. $item['type_name'] = SaaSLeaguePriceLog::getTypeStr($item['type']);
  2038. $item['order_no'] = '';
  2039. if ($item['order_id']) {
  2040. if (in_array($item['type'], [
  2041. SaaSLeaguePriceLog::TYPE_ORDER_REBATE,//下单返利
  2042. SaaSLeaguePriceLog::TYPE_CANCEL,//订单取消退回
  2043. SaaSLeaguePriceLog::TYPE_DEDUCTION,//下单抵扣
  2044. ])) {
  2045. $order = Order::findOne($item['order_id']);
  2046. }
  2047. if ($item['type'] === SaaSLeaguePriceLog::TYPE_LEAGUE_RECHARGE) {//联盟券
  2048. $order = RechargeReOrder::findOne($item['order_id']);
  2049. }
  2050. if (in_array($item['type'], [
  2051. SaaSLeaguePriceLog::TYPE_WITHDRAW,
  2052. SaaSLeaguePriceLog::TYPE_WITHDRAW_REJECT,
  2053. ])) {//联盟券提现
  2054. $order = Cash::findOne($item['order_id']);
  2055. }
  2056. if ($item['type'] === SaaSLeaguePriceLog::TYPE_FACE_PAY_ORDER) {//当面付
  2057. $order = \app\plugins\scanCodePay\models\Order::findOne($item['order_id']);
  2058. }
  2059. if (isset($order)) {
  2060. $item['order_no'] = $order->order_no ?: '';
  2061. }
  2062. }
  2063. $store = Store::findOne($item['store_id']);
  2064. $item['store_name'] = $store ? $store->name : '';
  2065. }
  2066. $league_price_query = Store::find()->where(['is_delete' => 0]);
  2067. if ($store_id) {
  2068. $league_price_query->andWhere(['id' => $store_id]);
  2069. }
  2070. $league_price = $league_price_query->select('league_price')->sum('league_price') ?: 0;
  2071. return $this->asJson([
  2072. 'code' => 0,
  2073. 'msg' => 'success',
  2074. 'data' => [
  2075. 'data' => $pagination['list'],
  2076. 'pageNo' => $pagination['pageNo'],
  2077. 'totalCount' => $pagination['totalCount'],
  2078. 'league_price' => $league_price
  2079. ],
  2080. ]);
  2081. }
  2082. public function actionIsPlatformTransfers()
  2083. {
  2084. $id = get_params('id');
  2085. $isPlatformTransfers = get_params('is_platform_transfers');
  2086. try {
  2087. $transaction = \Yii::$app->db->beginTransaction();
  2088. $store = Store::findOne($id);
  2089. if (!$store) {
  2090. throw new \Exception('店铺不存在');
  2091. }
  2092. $store->is_platform_transfers = $isPlatformTransfers;
  2093. if (!$store->save()) {
  2094. if ($store->hasErrors()) {
  2095. throw new \Exception('Validation failed: ' . implode(', ', $store->getFirstErrors()));
  2096. } else {
  2097. throw new \Exception('Failed to save the changes.');
  2098. }
  2099. }
  2100. $transaction->commit();
  2101. return $this->asJson([
  2102. 'code' => 0,
  2103. 'msg' => 'Success',
  2104. 'data' => $store,
  2105. ]);
  2106. } catch (\Exception $e) {
  2107. if (isset($transaction) && $transaction->isActive) {
  2108. $transaction->rollBack();
  2109. }
  2110. return $this->asJson([
  2111. 'code' => 1,
  2112. 'msg' => $e->getMessage(),
  2113. 'data' => []
  2114. ]);
  2115. }
  2116. }
  2117. public function actionStoreRecharge()
  2118. {
  2119. $data = get_params();
  2120. $rechargeType = $data['recharge_type'];
  2121. $id = $data['id'];
  2122. $money = $data['money'];
  2123. $store = Store::findOne($id);
  2124. $before = $store->store_balance;
  2125. $after = 0;
  2126. if ($rechargeType == 1) {
  2127. $store->total_store_quota += $money;
  2128. $store->store_balance += $money;
  2129. $store->price += $money;
  2130. $store->total_price += $money;
  2131. $after = $store->store_balance;
  2132. $result = StoreMoneyLog::saveLog($id, StoreMoneyLog::LOG_TYPE_INCOME, StoreMoneyLog::TYPE_STORE, $money, "后台充值: {$money}", $before, $after);
  2133. } else {
  2134. if ($store->store_balance >= $money) {
  2135. $store->store_balance -= $money;
  2136. $store->total_price -= $money;
  2137. $store->price -= $money;
  2138. $after = $store->store_balance;
  2139. $result = StoreMoneyLog::saveLog($id, StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_STORE, $money, "后台扣除: {$money}", $before, $after);
  2140. } else {
  2141. return $this->asJson([
  2142. 'code' => 1,
  2143. 'msg' => 'error',
  2144. 'data' => [],
  2145. ]);
  2146. }
  2147. }
  2148. if ($result !== true) {
  2149. return $this->asJson([
  2150. 'code' => 1,
  2151. 'msg' => 'error',
  2152. 'data' => [],
  2153. ]);
  2154. }
  2155. if (!$store->save()) {
  2156. return $this->asJson([
  2157. 'code' => 1,
  2158. 'msg' => 'error',
  2159. 'data' => [],
  2160. ]);
  2161. }
  2162. return $this->asJson([
  2163. 'code' => 0,
  2164. 'msg' => 'Success',
  2165. 'data' => $store,
  2166. ]);
  2167. }
  2168. public function actionStoreMoneyHistory()
  2169. {
  2170. $id = get_params('id');
  2171. $data = StoreMoneyLog::find()->alias('l')
  2172. ->leftJoin(['s' => Store::tableName()], 's.id = l.store_id')
  2173. ->select('l.*, s.name store_name')
  2174. ->where(['l.store_id' => $id])->orderBy('l.id desc')->asArray()->all();
  2175. foreach ($data as &$value) {
  2176. $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  2177. switch ($value['type']) {
  2178. case 1:
  2179. $value['type'] = '分销提现';
  2180. break;
  2181. case 2:
  2182. $value['type'] = '股东分红提现';
  2183. break;
  2184. case 3:
  2185. $value['type'] = '门店提现';
  2186. break;
  2187. case 4:
  2188. $value['type'] = '2+1提现';
  2189. break;
  2190. default:
  2191. $value['type'] = '后台操作';
  2192. break;
  2193. }
  2194. }
  2195. return $this->asJson([
  2196. 'code' => 0,
  2197. 'msg' => 'Success',
  2198. 'data' => $data,
  2199. ]);
  2200. }
  2201. //获取商城微信小程序码
  2202. public function actionGetWechatQrcode() {
  2203. try {
  2204. $store_id = get_params('store_id');
  2205. $store = Store::findOne($store_id);
  2206. $is_platform = 0;
  2207. if (intval($store->business_model) !== 1) {
  2208. $is_platform = 1;
  2209. }
  2210. $app = WechatMini::getWechatConfig($store_id, 0, 0, $is_platform);
  2211. if (!$app) {
  2212. throw new \Exception('没有对应的小程序');
  2213. }
  2214. $page = "pages/home/home";
  2215. $scene = "store:{$store_id}";
  2216. if ($store->business_model == 2) { //平台运营
  2217. $page = 'pages/shop/shopIndex';
  2218. $scene = "store_id:{$store_id}";
  2219. } elseif ($store->business_model == 3) { //当面付
  2220. $page = 'face-pay/face-pay/payOut';
  2221. $scene = "store_id:{$store_id}";
  2222. } elseif ($store->business_model == 4) { //点餐
  2223. $page = 'alipay-order/orderMeal/orderMeal';
  2224. $scene = "md_id:-1,store_id:{$store_id}";
  2225. }
  2226. $response = $app->app_code->getUnlimit($scene, [
  2227. 'page' => $page
  2228. ]);
  2229. $filename = md5(time() . 'pages_home') . '.jpg';
  2230. $filePath = \Yii::$app->basePath . '/runtime/image/wx_qrcode';
  2231. if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
  2232. $resfilename = $response->saveAs($filePath, $filename);
  2233. if (!empty($resfilename)) {
  2234. $filePath = 'https://' . str_replace(\Yii::$app->basePath, \Yii::$app->request->hostName, $filePath . '/' . $filename);
  2235. return $this->asJson([
  2236. 'code' => 0,
  2237. 'msg' => "获取成功",
  2238. 'data' => $filePath
  2239. ]);
  2240. } else {
  2241. throw new \Exception("数据错误");
  2242. }
  2243. } else {
  2244. throw new \Exception("数据错误");
  2245. }
  2246. } catch (\Exception $e) {
  2247. return $this->asJson([
  2248. 'code' => 1,
  2249. 'msg' => $e->getMessage()
  2250. ]);
  2251. }
  2252. }
  2253. }