| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\constants\OptionSetting;
- use app\jobs\StoreSyncJob;
- use app\models\AccountLog;
- use app\models\ActivityCutPriceLog;
- use app\models\ActivityCutPriceOrder;
- use app\models\ActivityOrderRebateSelfOrder;
- use app\models\ActivityOrderRebateSelfUser;
- use app\models\ActivityRebateOrderNLog;
- use app\models\Admin;
- use app\models\BonusPoolLevel;
- use app\models\Cash;
- use app\models\Form;
- use app\models\IntegralAppreciationCashLog;
- use app\models\IntegralAppreciationCommunity;
- use app\models\IntegralAppreciationPool;
- use app\models\IntegralAppreciationPoolSub;
- use app\models\IntegralAppreciationUser;
- use app\models\IntegralAppreciationUserIntegralLog;
- use app\models\IntegralSetting;
- use app\models\OldUserTreePath;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderComment;
- use app\models\OrderDetail;
- use app\models\OrderRefund;
- use app\models\Promoter;
- use app\models\PtActivityOrder;
- use app\models\PtActivityOrderDetail;
- use app\models\PublicRankingTask;
- use app\models\PublicRankingUser;
- use app\models\QueueAccountLog;
- use app\models\QueueLog;
- use app\models\RechargeReOrder;
- use app\models\ReportCommitIntegral;
- use app\models\ReportInfo;
- use app\models\ReportPool;
- use app\models\ReportPoolDetail;
- use app\models\ReportPoolLevel;
- use app\models\SaaSLeaguePriceLog;
- use app\models\Share;
- use app\models\ShareDetail;
- use app\models\ShareGroupMoney;
- use app\models\ShareGroupMoneySub;
- use app\models\ShareGroupPurchaseParentLog;
- use app\models\ShareGroupPurchaseUser;
- use app\models\ShareGroupSupportLog;
- use app\models\ShareHolder;
- use app\models\ShareHolderFrostLog;
- use app\models\ShareHolderLevelLog;
- use app\models\ShareHolderOutLog;
- use app\models\ShareHolderParentOutLog;
- use app\models\Store;
- use app\models\StoreTemplate;
- use app\models\SaasCategory;
- use app\models\StoreCopy;
- use app\models\SuperSales;
- use app\models\SuperSalesMoney;
- use app\models\SuperSalesRepeatOrder;
- use app\models\SuperSalesSub;
- use app\models\SuperSalesUser;
- use app\models\TeamBonusOrderExt;
- use app\models\TeamGrades;
- use app\models\TeamGradesAudit;
- use app\models\TeamGradesDividendLog;
- use app\models\TeamGradesPool;
- use app\models\TeamGradesPoolDetail;
- use app\models\TeamGradesPoolDetailExt;
- use app\models\User;
- use app\models\UserShareMoney;
- use app\models\UserTreePath;
- use app\models\VideoShopGoodsExt;
- use app\models\VideoShopOrderExt;
- use app\models\VideoShopOrderExtAli;
- use app\models\VideoShopSharer;
- use app\models\VideoShopUser;
- use app\modules\admin\models\MerchantForm;
- use app\modules\admin\models\SubmitFormForm;
- use app\modules\client\models\v1\LoginForm;
- use app\utils\Delivery\Delivery;
- use app\utils\Wechat\WechatMini;
- use Yii;
- use app\modules\admin\models\StoreForm;
- use app\modules\admin\models\SaasCategoryForm;
- use yii\base\BaseObject;
- use app\models\SaasUser;
- use app\models\Salesman;
- use yii\helpers\Json;
- use app\utils\IotCloudHelper;
- use app\constants\Kefu;
- use app\models\StoreMoneyLog;
- use app\models\Supplier;
- use app\models\Mch;
- class StoreController extends BaseController
- {
- /**
- * 获取商城列表
- */
- public function actionList()
- {
- $admin = get_admin();
- $form = new StoreForm();
- $admin_id = $admin->id;
- if ($admin->username == 'admin' || $admin->type == Admin::ADMIN_TYPE_SAAS_STAFF) {
- $admin_id = null;
- }
- $form->id = get_params("id");
- $form->name = get_params("name");
- $form->mobile = get_params("mobile");
- $form->user_name = get_params("user_name");
- $form->category_id = get_params("category_id", -1);
- $form->status = get_params('status', -1);
- $form->business_model = get_params('business_model', -1);
- $form->province_id = get_params('province_id');
- $form->city_id = get_params('city_id');
- $form->district_id = get_params('district_id');
- $form->start_time = get_params('start_time');
- $form->end_time = get_params('end_time');
- $form->integral_profit_status = get_params('integral_profit_status');
- $result = $form->getList($admin_id);
- return $this->asJson($result);
- }
- //申请单列表
- public function actionGetAuditList()
- {
- $form = new StoreForm();
- $form->name = get_params("name");
- $form->admin_id = get_params("admin_id", 0);
- $form->salesman_id = get_params("salesman_id", 0);
- $form->status = get_params("status", -1);
- $result = $form->getAuditList();
- return $this->asJson($result);
- }
- //申请审核
- public function actionStoreAudit()
- {
- $form = new StoreForm();
- $form->id = post_params("id", 0);
- $form->status = post_params("status", -1);
- $form->business_model = post_params("business_model", -1);
- $form->qrcode_id = post_params("qrcode_id", -1);
- $result = $form->storeAudit();
- return $this->asJson($result);
- }
- //店铺初始化
- public function actionStoreInit()
- {
- $id = input_params("id", 0);
- $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
- if($default){
- $default = json_decode($default, true);
- }else{
- return $this->asJson([
- 'code' => 0,
- 'msg' => '暂无默认模板',
- ]);
- }
- $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $id]), 0, 1);
- // $res = StoreCopy::doCopy($default['store_id'], $id, $default['type']);
- // return $this->asJson($res);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- }
- //
- public function actionGetQrcode()
- {
- $form = new StoreForm();
- $form->business_model = post_params("business_model");
- $res = $form->getQrcode();
- return $this->asJson($res);
- }
- //绑定业务员
- public function actionBindSalesman()
- {
- $form = new StoreForm();
- $form->id = post_params("id", 0);
- $form->salesman_id = post_params("salesman_id", -1);
- $result = $form->bindSalesman();
- return $this->asJson($result);
- }
- /**
- * @return \yii\web\Response
- * 获取没有成为云仓的商城
- */
- public function actionGetList()
- {
- $form = new StoreForm();
- $result = $form->getStoreList();
- return $this->asJson($result);
- }
- /**
- * 添加商城
- */
- public function actionAdd()
- {
- $saas_user_id = post_params('saas_user_id');
- $name = post_params('name');
- $username = post_params('username');
- $password = post_params('password');
- $area = post_params('area');
- $logo = post_params('logo');
- // $store_number= post_params('storeNumber');
- $form = new StoreForm();
- return $this->asJson($form->add($name, $password, $username, $area, $saas_user_id, $logo, 0));
- }
- public function actionSetData()
- {
- $form = new StoreForm();
- return $this->asJson($form->initStoreData());
- }
- /**
- * 修改密码
- */
- public function actionSetPassword()
- {
- $form = new StoreForm();
- if (\Yii::$app->request->isPost) {
- $store_id = post_params('store_id');
- $password = post_params("password");
- $name = post_params("name");
- $username = post_params("username");
- $saas_user_id = post_params("saas_user_id");
- $res = $form->setPassword($store_id, $password, $name, $username, $saas_user_id);
- } else {
- $store_id = get_params('store_id');
- $admin = Admin::findOne([
- 'type' => 'store',
- 'type_id' => $store_id
- ]);
- $saas_user = SaasUser::findOne($admin->saas_user_id);
- $store = Store::findOne($store_id);
- $res = [
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'name' => $admin->name,
- 'username' => $admin->username,
- 'saas_user_id' => $admin->saas_user_id,
- 'saas_user' => $saas_user,
- ]
- ];
- }
- return $this->asJson($res);
- }
- /**
- * 删除商城
- */
- public function actionDel()
- {
- $store_id = post_params('store_id');
- $form = new StoreForm();
- return $this->asJson($form->delete($store_id));
- }
- /**
- * 设置saas分销参数
- */
- public function actionSetShareParams()
- {
- $store_id = post_params('storeId') ?: post_params('store_id');
- $params = [
- 'level' => post_params('level', 0),
- 'is_rebate' => post_params('is_rebate', 0),
- 'price_type' => post_params('price_type', 0),
- 'level_one' => post_params('level_one', 0),
- 'level_two' => post_params('level_two', 0),
- 'level_three' => post_params('level_three', 0),
- ];
- $form = new StoreForm();
- return $this->asJson($form->setShareParams($store_id, $params));
- }
- /**
- * 设置商铺开通续费金额信息
- */
- // public function actionSetStoreCost(){
- // $store_id = post_params('storeId') ?: post_params('store_id');
- // $params = [
- // 'open_price' => post_params('open_price', 0),
- // 'renew_price' => post_params('renew_price', 0),
- // 'end_time' => strtotime(post_params('end_time')),
- // 'profit' => post_params('profit', 0),
- // 'is_use_default' => post_params('is_use_default', 1),
- // ];
- // $form = new StoreForm();
- // return $this->asJson($form->setCost($store_id, $params));
- // }
- /**
- * 获取商铺开通续费金额信息
- */
- public function actionGetStoreCost()
- {
- $store_id = get_params('storeId');
- $form = new StoreForm();
- return $this->asJson($form->getCost($store_id));
- }
- /**
- * 缴纳商铺费用逻辑
- */
- public function actionPayFee()
- {
- $store_id = get_params('storeId');
- $form = new StoreForm();
- return $this->asJson($form->payFee($store_id));
- }
- /**
- * 判断是否缴纳成功
- */
- public function actionGetIsPay()
- {
- $order_id = get_params('order_id');
- $form = new StoreForm();
- return $this->asJson($form->isPay($order_id));
- }
- /**
- * 获取店铺续费订单
- */
- public function actionStoreReOrder()
- {
- $store_id = get_params('store_id');
- $form = new StoreForm();
- $form->attributes = get_params();
- return $this->asJson($form->reOrderList($store_id));
- }
- /**
- * 获取saas分销参数
- */
- public function actionGetShareParams()
- {
- $store_id = get_params('storeId');
- $form = new StoreForm();
- return $this->asJson($form->getShareParams($store_id));
- }
- /**
- * 获取推荐人信息
- */
- public function actionGetReferralParams()
- {
- $store_id = get_params('storeId');
- $form = new StoreForm();
- return $this->asJson($form->getReferralParams($store_id));
- }
- /**
- * 设置推荐人信息
- */
- public function actionSetReferralParams()
- {
- $store_id = post_params('storeId');
- $params = post_params('lists');
- $form = new StoreForm();
- return $this->asJson($form->setReferralParams($store_id, $params));
- }
- /**
- * 获取商城返利比例
- */
- public function actionGetTransferProfitParams()
- {
- $store_id = get_params('storeId');
- $form = new StoreForm();
- return $this->asJson($form->getTransferProfitParams($store_id));
- }
- /**
- * 设置商城返利比例
- */
- public function actionSetTransferProfitParams()
- {
- $store_id = post_params('storeId');
- $params = [
- 'transfer_profit' => post_params('transfer_profit', 0),
- 'scan_transfer_profit' => post_params('scan_transfer_profit', 0),
- 'food_transfer_profit' => post_params('food_transfer_profit', 0),
- 'cashier_transfer_profit' => post_params('cashier_transfer_profit', 0),
- ];
- $form = new StoreForm();
- return $this->asJson($form->SetTransferProfitParams($store_id, $params));
- }
- /**
- * 获取商城基本信息
- */
- public function actionGetStoreInfo()
- {
- $store_id = get_params('storeId', get_store_id());
- $form = new StoreForm();
- return $this->asJson($form->getInfo($store_id));
- }
- public function actionJoinAlliance()
- {
- $store_id = post_params('storeId', get_store_id());
- $status = post_params('status');
- $form = new StoreForm();
- return $this->asJson($form->joinAlliance($store_id, $status));
- }
- public function actionGetCheckList()
- {
- $form = new StoreForm();
- return $this->asJson($form->getCheckList());
- }
- public function actionDouyinInfo()
- {
- $form = new StoreForm();
- $store_id = get_params('storeId', get_store_id());
- if (\Yii::$app->request->isPost) {
- $content = post_params('content', '');
- $params = [
- 'app_id' => post_params('app_id', ''),
- 'app_secret' => post_params('app_secret', ''),
- 'salt' => post_params('salt', ''),
- 'token' => post_params('token', '')
- ];
- return $this->asJson($form->setDouyinInfo($store_id, $content, $params));
- }
- return $this->asJson($form->getDouyinInfo($store_id));
- }
- /**
- * 获取商城参数
- */
- public function actionGetStoreParams()
- {
- $store_id = get_params('storeId');
- $form = new StoreForm();
- return $this->asJson($form->getStoreParams($store_id));
- }
- /**
- * 设置商城参数
- */
- public function actionSetStoreParams()
- {
- $store_id = post_params('storeId');
- $params = [
- 'name' => post_params('name', ''),
- 'balance' => post_params('balance', 0),
- 'logo' => post_params('logo', ''),
- 'coordinate' => post_params('coordinate', ''),
- 'address' => post_params('address', ''),
- 'category_id' => post_params('category_id', 0),
- 'category_option' => post_params('category_option', []),
- 'address_info' => post_params('address_info'),
- 'area' => post_params('area'),
- 'sales' => post_params('sales', 0),
- 'rank' => post_params('rank', 5),
- 'per_spend' => post_params('per_spend', 0),
- 'tags' => post_params('tags', []),
- 'user_name' => post_params('user_name', ''),
- 'contact_tel' => post_params('contact_tel', ''),
- 'start_time' => post_params('start_time', '00:00'),
- 'end_time' => post_params('end_time', '23:59'),
- 'open_status' => post_params('open_status', 1),
- 'shop_time_type' => post_params('shop_time_type', 0),
- 'is_time_forbid' => post_params('is_time_forbid', 1),
- 'is_set_distance' => post_params('is_set_distance', 0),
- 'distance' => post_params('distance', 0),
- 'store_admin' => post_params('store_admin', 0),
- 'business_model' => post_params('business_model', 0),
- 'self_mini' => post_params('self_mini', 0),
- 'store_permission' => post_params('store_permission', []),
- 'cost_end_time' => post_params('cost_end_time', []),
- 'salesman_id' => post_params('salesman_id', 0),
- 'is_add_goods' => post_params('is_add_goods', 1),
- 'mini_auth_num' => post_params('mini_auth_num', 0),
- 'is_store_traffic_sharing' => post_params('is_store_traffic_sharing', 0),
- ];
- $form = new StoreForm();
- return $this->asJson($form->setStoreParams($store_id, $params));
- }
- /**
- * 获取商城类目数据
- */
- public function actionGetCategoryInfo()
- {
- $categoryForm = new SaasCategoryForm();
- return $this->asJson($categoryForm->getList(false));
- }
- /**
- * 自定义表单
- * @return array|mixed|\yii\web\Response
- */
- public function actionForm()
- {
- $store_id = get_store_id();
- $form_list = Form::find()->where(['is_delete' => 0, 'store_id' => $store_id])->orderBy(['sort' => SORT_ASC])->asArray()->all();
- if (\Yii::$app->request->isPost) {
- $form = new SubmitFormForm();
- $form->store_id = $store_id;
- $form->attributes = post_params();
- return $this->asJson($form->save());
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'form_list' => $form_list,
- 'is_form' => intval(Option::get('is_form', $store_id, 'store', 0)['value']),
- 'form_name' => Option::get('form_name', $store_id, 'store', '表单名称')['value']
- ]
- ]);
- }
- /**
- * @return \yii\web\Response
- */
- public function actionGetDeliveryInfo()
- {
- $store_id = get_store_id();
- $result = Option::getDeliveryConfig();
- $store = Store::findOne($store_id);
- $category_one = $category_two = '';
- if ($store->delivery_category) {
- $arr = explode(',', $store->delivery_category);
- $category_one = $arr[0];
- $category_two = $arr[1];
- }
- //判断是否设置地区、地址、坐标、联系人、联系方式 ,否则跳转
- $is_jump = 0;
- if (empty($store->address) || empty($store->province_id) || empty($store->city_id) || empty($store->district_id) || empty($store->contact_tel) || empty($store->user_name)) {
- $is_jump = 1;
- }
- $data = [
- 'type' => $store->delivery_type,
- 'config' => $result,
- 'wechat_msg_token' => $store->wechat_msg_token ?: '',
- 'category_one' => $category_one,
- 'category_two' => $category_two,
- 'category_level_one' => Delivery::$validLevelOneCategory,
- 'category_level_list' => Delivery::$validLevelCategory,
- 'is_jump' => $is_jump,
- 'wechat_delivery_type' => $store->wechat_delivery_type
- ];
- $keys = [
- 'local_sym_sn',
- 'local_sym_key',
- 'rsa_sn',
- 'rsa_private_key'
- ];
- $delivery_data = Option::get($keys, $store_id, 'delivery');
- if (empty($delivery_data)) {
- $delivery_data = [
- 'local_sym_sn' => '',
- 'local_sym_key' => '',
- 'rsa_sn' => '',
- 'rsa_private_key' => ''
- ];
- } else {
- $arr = [];
- foreach ($delivery_data as $value) {
- $index = array_search($value['name'], $keys);
- unset($keys[$index]);
- $arr[$value['name']] = $value['value'];
- }
- foreach ($keys as $key) {
- $arr[$key] = '';
- }
- $delivery_data = $arr;
- }
- $data = array_merge($data, $delivery_data);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- /**
- * @return \yii\web\Response
- */
- public function actionSetDeliveryInfo()
- {
- $delivery_shop_id = trim(post_params('delivery_shop_id'));
- $delivery_app_secret= trim(post_params('delivery_app_secret'));
- $delivery_shop_no = trim(post_params('delivery_shop_no' ,''));
- $type = trim(post_params('type'));
- $wechat_msg_token = trim(post_params('wechat_msg_token'));
- $delivery_category_one = post_params('category_one');
- $delivery_category_two = post_params('category_two');
- $wechat_delivery_type = post_params('wechat_delivery_type', 0);//0即时配送 1同城配送
- $local_sym_sn = post_params('local_sym_sn', '');//对称密钥编号
- $local_sym_key = post_params('local_sym_key', '');//对称密钥密钥明文
- $rsa_sn = post_params('rsa_sn', '');//非对称密钥编号
- $rsa_private_key = post_params('rsa_private_key', '');//非对称密钥私玥
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- $store->wechat_delivery_type = $wechat_delivery_type;
- $store->save();
- if (intval($wechat_delivery_type) === 0) {
- if (empty($delivery_shop_id) || empty($delivery_app_secret) || empty($delivery_shop_no) || empty($wechat_msg_token)
- || empty($delivery_category_one) || empty($delivery_category_two) || empty($type)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数有误'
- ]);
- }
- $res = Delivery::getBindAccount();
- if ($res['code'] > 0) {
- if ($res['code'] == 48001) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请在微信小程序后台开通即时配送物流服务'
- ]);
- }
- }
- if (empty($res['data']['shop_list'])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前未绑定运力账号,暂不能保存选择同城配送方式',
- '$res' => $res,
- ]);
- }
- $shop_list = $res['data']['shop_list'];
- $delivery_arr = array_column($shop_list, 'delivery_id');
- $delivery_arr_id = array_column($shop_list, null, 'delivery_id');
- if (!in_array(Delivery::$deliveryIdArr[$type], $delivery_arr) || $delivery_arr_id[Delivery::$deliveryIdArr[$type]]['audit_result'] != 0) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前账号未在微信后台绑定或者并未审核通过'
- ]);
- }
- if ($type == 1) {
- Option::set('sf_app_key', $delivery_shop_id, $store_id, 'store');
- Option::set('sf_app_secret', $delivery_app_secret, $store_id, 'store');
- Option::set('sf_shop_no', $delivery_shop_no, $store_id, 'store');
- }
- if ($type == 2) {
- Option::set('dd_app_key', $delivery_shop_id, $store_id, 'store');
- Option::set('dd_app_secret', $delivery_app_secret, $store_id, 'store');
- Option::set('dd_shop_no', $delivery_shop_no, $store_id, 'store');
- }
- if ($type == 3) {
- Option::set('ss_app_key', $delivery_shop_id, $store_id, 'store');
- Option::set('ss_app_secret', $delivery_app_secret, $store_id, 'store');
- Option::set('ss_shop_no', $delivery_shop_no, $store_id, 'store');
- }
- if ($type == 4) {
- Option::set('mt_app_key', $delivery_shop_id, $store_id, 'store');
- Option::set('mt_app_secret', $delivery_app_secret, $store_id, 'store');
- Option::set('mt_shop_no', $delivery_shop_no, $store_id, 'store');
- }
- if ($type == 5) {
- Option::set('uu_app_key', $delivery_shop_id, $store_id, 'store');
- Option::set('uu_app_secret', $delivery_app_secret, $store_id, 'store');
- Option::set('uu_shop_no', $delivery_shop_no, $store_id, 'store');
- }
- $store->delivery_type = $type;
- $store->wechat_msg_token = $wechat_msg_token;
- $store->delivery_category = $delivery_category_one . ',' . $delivery_category_two;
- if ($store->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- ]);
- }
- } else {
- $keys = [
- 'local_sym_sn',
- 'local_sym_key',
- 'rsa_sn',
- 'rsa_private_key'
- ];
- $data = [
- $local_sym_sn,
- $local_sym_key,
- $rsa_sn,
- $rsa_private_key
- ];
- Option::set($keys, $data, $store_id, 'delivery');
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => $store->errors[0],
- ]);
- }
- public function actionFoodSettingInfo()
- {
- $store_id = get_store_id();
- $mch_id = intval(get_mch_id());
- $store = Store::findOne($store_id);
- if($mch_id){
- $store = Mch::findOne($mch_id);
- }
- if (!$store->food_payment) {
- $payment = [
- [
- 'key' => 'alipay',
- 'value' => 0,
- 'name' => ''
- ],
- [
- 'key' => 'wechat',
- 'value' => 1,
- 'name' => ''
- ],
- [
- 'key' => 'huodao',
- 'value' => 0,
- 'name' => ''
- ],
- [
- 'key' => 'friend',
- 'value' => 0,
- 'name' => ''
- ],
- ];
- $store->food_payment = Json::encode($payment);
- $store->save();
- }
- $default_food_delivery = (int)Option::get('default_food_delivery', $store_id, 'store', 0)['value']; //到店自提
- //点餐页面标题
- $food_page_title = Option::get('food_page_title', $store_id, 'store', '')['value'];
- if($mch_id){
- $food_open_time = Option::get('food_open_time', $mch_id, 'mch', '')['value'];
- $default_food_delivery = (int)Option::get('default_food_delivery', $mch_id, 'mch', 0)['value']; //到店自提
- $food_page_title = Option::get('food_page_title', $mch_id, 'mch', '')['value'];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'food_payment' => Json::decode($store->food_payment),
- 'food_pay_type' => $store->food_pay_type,
- 'food_open_time' => $food_open_time,
- 'default_food_delivery' => $default_food_delivery,
- 'food_page_title' => $food_page_title ?: '手机点餐'
- ]
- ]);
- }
- public function actionFoodSetting()
- {
- $store_id = get_store_id();
- $mch_id = intval(get_mch_id());
- $store = Store::findOne($store_id);
- $payment = post_params('food_payment');
- $pay_type = post_params('food_pay_type', 0);
- $food_page_title = post_params('food_page_title');
- $default_food_delivery = post_params('default_food_delivery', 0);
- if($mch_id){
- $store = Mch::findOne($mch_id);
- Option::set('default_food_delivery', $default_food_delivery, $mch_id, 'mch');
- $food_open_time = post_params('food_open_time', '');
- Option::set('food_open_time', $food_open_time, $mch_id, 'mch');
- Option::set('food_page_title', $food_page_title, $mch_id, 'mch');
- }else{
- Option::set('default_food_delivery', $default_food_delivery, $store_id, 'store');
- Option::set('food_page_title', $food_page_title, $store_id, 'store');
- }
- $store->food_pay_type = $pay_type;
- $store->food_payment = $payment;
- if (!$store->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $store->errors
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- }
- public function actionChangeJoinUnionStatus()
- {
- $id = post_params('id');
- $status = post_params('status');
- if (!$id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- if (!in_array($status, [0, 1])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- $store = Store::findOne($id);
- if (!$store) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '商城未找到'
- ]);
- }
- $store->is_alliance = $status;
- $store->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- }
- // app设置
- public function actionSettingApp()
- {
- $store_id = get_store_id();
- if (\Yii::$app->request->isPost) {
- $client_privacy_id = post_params('client_privacy_id', '');
- $client_service_id = post_params('client_service_id', '');
- $app_down_android = post_params('app_down_android', '');
- $app_down_ios = post_params('app_down_ios', '');
- Option::set('client_privacy_id', $client_privacy_id, $store_id, 'app');
- Option::set('client_service_id', $client_service_id, $store_id, 'app');
- Option::set('app_down_android', $app_down_android, $store_id, 'app');
- Option::set('app_down_ios', $app_down_ios, $store_id, 'app');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- $data = [
- 'client_privacy_id' => Option::get('client_privacy_id', $store_id, 'app', '')['value'],
- 'client_service_id' => Option::get('client_service_id', $store_id, 'app', '')['value'],
- 'app_down_android' => Option::get('app_down_android', $store_id, 'app', '')['value'],
- 'app_down_ios' => Option::get('app_down_ios', $store_id, 'app', '')['value'],
- ];
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success',
- ]);
- }
- // 版权设置
- public function actionCopyrightSetting()
- {
- $store_id = get_store_id();
- if (\Yii::$app->request->isPost) {
- $web_name = post_params('web_name', '');
- $web_log = post_params('web_log', '');
- $copyright = post_params('copyright', '');
- $help_logo = post_params('help_logo', '');
- $describe = post_params('describe', '');
- $passport_bg = post_params('passport_bg', '');
- $store_share_title = post_params('store_share_title', '');
- $store_share_logo = post_params('store_share_logo', '');
- $store_share_desc = post_params('store_share_desc', '');
- Option::set('web_name', $web_name, $store_id, 'web');
- Option::set('web_log', $web_log, $store_id, 'web');
- Option::set('copyright', $copyright, $store_id, 'web');
- Option::set('help_logo', $help_logo, $store_id, 'web');
- Option::set('describe', $describe, $store_id, 'web');
- Option::set('passport_bg', $passport_bg, $store_id, 'web');
- // Option::set('store_share_title', $store_share_title, $store_id, 'web');
- // Option::set('store_share_logo', $store_share_logo, $store_id, 'web');
- // Option::set('store_share_desc', $store_share_desc, $store_id, 'web');
- $store = Store::findOne($store_id);
- if ($store) {
- if ($web_name) {
- $store->name = $web_name;
- }
- if ($web_log) {
- $store->logo = $web_log;
- }
- $store->save();
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- $data = [
- 'web_name' => Option::get('web_name', $store_id, 'web', '')['value'],
- 'web_log' => Option::get('web_log', $store_id, 'web', '')['value'],
- 'copyright' => Option::get('copyright', $store_id, 'web', '')['value'],
- 'passport_bg' => Option::get('passport_bg', $store_id, 'web', '')['value'],
- 'help_logo' => Option::get('help_logo', $store_id, 'web', '')['value'],
- 'describe' => Option::get('describe', $store_id, 'web', '')['value'],
- // 'store_share_title' => Option::get('store_share_title', $store_id, 'web', '')['value'],
- // 'store_share_logo' => Option::get('store_share_logo', $store_id, 'web', '')['value'],
- // 'store_share_desc' => Option::get('store_share_desc', $store_id, 'web', '')['value'],
- ];
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success',
- ]);
- }
- /**
- * 积分设置
- * @return \yii\web\Response
- */
- public function actionIntegralSetting()
- {
- $store_id = get_store_id();
- $data = [
- 'register_rule' => '',
- 'register_integral' => '1',
- 'register_integral_end' => '5',
- 'register_continuation' => 0,
- 'register_reward' => '1',
- 'register_reward_end' => '10',
- 'register_status' => 1
- ];
- $integral_setting = IntegralSetting::findOne(['store_id' => $store_id]);
- $integral_setting['register_integral_end'] = $integral_setting['register_integral_end'] ?? '5';
- $integral_setting['register_reward_end'] = $integral_setting['register_reward_end'] ?? '5';
- $integral_setting['register_status'] = (int)$integral_setting['register_status'];
- return $this->asJson(
- [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $integral_setting ?: $data
- ]
- );
- }
- /**
- * 积分设置保存
- * @return \yii\web\Response
- */
- public function actionIntegralSettingSave()
- {
- $register_status = post_params('register_status', 1);
- $register_rule = post_params('register_rule', '');
- $register_integral = post_params('register_integral', 1);
- $register_continuation = post_params('register_continuation', 0);
- $register_reward = post_params('register_reward', 1);
- $register_integral_end = post_params('register_integral_end', 5);
- $register_reward_end = post_params('register_reward_end', 5);
- $integral_setting = IntegralSetting::findOne(['store_id' => get_store_id()]);
- if ($register_integral < 1 || $register_reward_end < 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '积分需大于0'
- ]);
- }
- if ($register_integral_end < $register_integral) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '每日签到获得分数区间错误'
- ]);
- }
- if ($register_reward_end < $register_reward) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '连续签到奖励积分区间设置错误'
- ]);
- }
- $integral_setting = $integral_setting ?: new IntegralSetting();
- $integral_setting->store_id = get_store_id();
- $integral_setting->register_continuation = $register_continuation;
- $integral_setting->register_integral = $register_integral;
- $integral_setting->register_rule = $register_rule;
- $integral_setting->register_reward = $register_reward;
- $integral_setting->register_integral_end = $register_integral_end;
- $integral_setting->register_reward_end = $register_reward_end;
- $integral_setting->register_status = $register_status;
- if ($integral_setting->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $integral_setting->errors[0]
- ]);
- }
- }
- /**
- * ocr接口调用参数配置
- * @return \yii\web\Response
- */
- public function actionOcrSetting()
- {
- $default = [
- 'app_secret' => '',
- 'app_key' => '',
- ];
- if (\Yii::$app->request->getIsPost()) {
- $content = post_params('content', $default);
- Option::set('ocr', json_encode($content), get_store_id(), 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- } else {
- $content = Option::get('ocr', get_store_id(), 'store', json_encode($default));
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => json_decode($content['value']),
- ]);
- }
- }
- // 联盟券设置
- public function actionSettingLeague()
- {
- $store_id = get_store_id();
- if (\Yii::$app->request->isPost) {
- // $store_this_profit = post_params('store_this_profit', '');
- $goods_send_profit = post_params('goods_send_profit', '');
- $goods_take_price = post_params('goods_take_price', '');
- $is_show_alliance_coupon = post_params('is_show_alliance_coupon', 0);
- // Option::set('store_this_profit', $store_this_profit, $store_id, 'store');
- Option::set('goods_send_profit', $goods_send_profit, $store_id, 'store');
- Option::set('goods_take_price', $goods_take_price, $store_id, 'store');
- Option::set('is_show_alliance_coupon', $is_show_alliance_coupon, $store_id, 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- $data = [
- // 'store_this_profit' => Option::get('store_this_profit', $store_id, 'store', '')['value'],
- 'goods_send_profit' => Option::get('goods_send_profit', $store_id, 'store', '')['value'],
- 'goods_take_price' => Option::get('goods_take_price', $store_id, 'store', '')['value'],
- 'is_show_alliance_coupon' => Option::get('is_show_alliance_coupon', $store_id, 'store', 0)['value'],
- ];
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success',
- ]);
- }
- // 当面付分佣设置
- public function actionSettingFacePayProfit()
- {
- $store_id = get_store_id();
- if (\Yii::$app->request->isPost) {
- $face_first_profit = post_params('face_first_profit', '');
- $face_second_profit = post_params('face_second_profit', '');
- $face_third_profit = post_params('face_third_profit', '');
- // $face_pay_path = post_params('face_pay_path');
- // if (isset($face_pay_path)) {
- // $face_pay_path = json_encode($face_pay_path, JSON_UNESCAPED_UNICODE);
- // Option::set('face_pay_path', $face_pay_path, $store_id,'store');
- // }
- $rate = post_params('rate');
- $rate_type = post_params('rate_type');
- if(isset($rate)){
- Option::set('face_rate', $rate, $store_id, 'store');
- Option::set('face_rate_type', $rate_type, $store_id, 'store');
- }
- Option::set('face_first_profit', $face_first_profit, $store_id, 'store');
- Option::set('face_second_profit', $face_second_profit, $store_id, 'store');
- Option::set('face_third_profit', $face_third_profit, $store_id, 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- $data = [
- 'face_first_profit' => Option::get('face_first_profit', $store_id, 'store', '')['value'],
- 'face_second_profit' => Option::get('face_second_profit', $store_id, 'store', '')['value'],
- 'face_third_profit' => Option::get('face_third_profit', $store_id, 'store', '')['value'],
- 'rate' => Option::get('face_rate', $store_id, 'store')['value'],
- 'rate_type' => Option::get('face_rate_type', $store_id, 'store')['value'],
- // 'face_pay_path' => Option::get('face_pay_path', $store_id, 'store', '')['value']
- ];
- // $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null;
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success',
- ]);
- }
- public function actionFaceMarketingProfit()
- {
- $store_id = get_store_id();
- if (\Yii::$app->request->isPost) {
- $send_integral_profit = post_params('send_integral_profit', '');
- Option::set('face_send_integral_profit', $send_integral_profit, $store_id, 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- $data = [
- 'send_integral_profit' => Option::get('face_send_integral_profit', $store_id, 'store', '0')['value']
- ];
- // $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null;
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success',
- ]);
- }
- /**
- * 销售溢价比
- */
- public function actionStoreRate()
- {
- try {
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- $data = [];
- if (\Yii::$app->request->isGet) {
- $cloud_is_update = Option::get('cloud_is_update', $store_id, 'store')['value'];
- $reduce_type = Option::get('reduce_type', $store_id, 'store')['value'];
- $sale_price_type = Option::get('sale_price_type', $store_id, 'store')['value'];
- $repeat_update_goods_price = Option::get('repeat_update_goods_price', $store_id, 'store')['value'];
- $store_cloud_send_type = Option::get('store_cloud_send_type', $store_id, 'store')['value'];
- $arr = [
- 'rate' => $store->rate,
- // 'is_auth_trans' => $store->is_auth_trans,
- 'cloud_is_update' => (int)$cloud_is_update,
- 'reduce_type' => $reduce_type,
- 'sale_price_type' => (int)$sale_price_type,
- 'repeat_update_goods_price' => (int)$repeat_update_goods_price,
- 'store_cloud_send_type' => json_decode($store_cloud_send_type, true) ?: ['express']
- ];
- //自动优先扣除方式
- $form = new MerchantForm();
- $result = $form->setCloudMerchantConfig();
- if ($result['code'] === 0) {
- $arr['reduce_type'] = (int)$result['data']['reduce_type'];
- }
- $data = [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $arr
- ];
- } elseif (\Yii::$app->request->isPost) {
- $rate = floatval(post_params('rate', 0));
- $reduce_type = post_params('reduce_type', 0);
- // $is_auth_trans = post_params('is_auth_trans', 0);
- $cloud_is_update = post_params('cloud_is_update', 0);
- $sale_price_type = post_params('sale_price_type', 0);
- $repeat_update_goods_price = post_params('repeat_update_goods_price', 0);
- $store_cloud_send_type = post_params('store_cloud_send_type');
- if (empty($store_cloud_send_type)) {
- throw new \Exception('请选择发货方式');
- }
- if (!is_array($store_cloud_send_type)) {
- throw new \Exception('发货方式格式错误');
- }
- $open = false;
- array_map(function ($item) use (&$open){
- if (!in_array($item, ['express', 'shop', 'delivery'])) {
- $open = true;
- }
- }, $store_cloud_send_type);
- if ($open) {
- throw new \Exception('发货方式格错误');
- }
- Option::set('sale_price_type', $sale_price_type, get_store_id(), 'store');
- Option::set('cloud_is_update', $cloud_is_update, get_store_id(), 'store');
- Option::set('reduce_type', $reduce_type, get_store_id(), 'store');
- Option::set('repeat_update_goods_price', $repeat_update_goods_price, get_store_id(), 'store');
- Option::set('store_cloud_send_type', json_encode($store_cloud_send_type, JSON_UNESCAPED_UNICODE), get_store_id(), 'store');
- $store->rate = $rate;
- // $store->is_auth_trans = $is_auth_trans;
- if (!$store->save()) {
- throw new \Exception(json_encode($store->errors));
- }
- //自动优先扣除方式
- $form = new MerchantForm();
- $result = $form->setCloudMerchantConfig($reduce_type);
- if ($result['code'] === 0) {
- $arr['reduce_type'] = (int)$result['data']['reduce_type'];
- }
- $data = [
- 'code' => 0,
- 'msg' => "操作成功",
- ];
- }
- return $this->asJson($data);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage(),
- ]);
- }
- }
- /**
- * 获取设备ID和在线状态
- * @return \yii\web\Response
- * @throws \yii\base\InvalidConfigException
- * @author Syan mzsongyan@gmail.com
- * @date 2022-06-02
- */
- public function actionGetVoiceDeviceInfo()
- {
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- $deviceName = '';
- $online = 0;
- if ($store->device_name) {
- $deviceName = $store->device_name;
- $result = IotCloudHelper::getDeviceInfo($store_id);
- if ($result['code'] == 0) {
- $online = $result['data']['Online'];
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'device_name' => $deviceName,
- 'online' => $online,
- ],
- ]);
- }
- /**
- * 绑定设备
- * @return \yii\web\Response|void
- * @author Syan mzsongyan@gmail.com
- * @date 2022-06-02
- */
- public function actionSetVoiceDeviceInfo()
- {
- try {
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- $deviceName = post_params('device_name');
- $type = post_params('type');
- if($type == 'unbind'){
- $oldDeviceName = $store->device_name;
- $store->device_name = '';
- $store->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '解绑成功,设备:' . $oldDeviceName,
- ]);
- }
- if (!$deviceName) {
- throw new \Exception('请输入设备ID');
- }
- if ($deviceName == $store->device_name) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '绑定成功',
- ]);
- }
- $exist = Store::find()->where(['device_name' => $deviceName])->andWhere(['<>', 'id', $store_id])->one();
- if ($exist) {
- throw new \Exception('该设备ID已经被使用');
- }
- $oldDeviceName = $store->device_name;
- $store->device_name = $deviceName;
- $store->save();
- $result = IotCloudHelper::getDeviceInfo($store_id);
- if ($result['code'] == 1) {
- $store->device_name = $oldDeviceName;
- $store->save();
- throw new \Exception('设备ID不正确或设备未开机');
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '绑定成功',
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage(),
- ]);
- }
- }
- public function actionTestVoiceDevice()
- {
- try {
- $type = post_params('type', 1);
- $store_id = get_store_id();
- $name = '微信';
- if ($type == 2) {
- $name = '支付宝';
- }
- $msg = '{"cmd":"voice","msg":"'. $name .'收款999元"}';
- $result = IotCloudHelper::sendMessage($store_id, $msg);
- \Yii::error($result);
- if ($result['code'] == 1) {
- throw new \Exception($result['msg']);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '发送成功',
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage(),
- ]);
- }
- }
- //获取业务员列表
- public function actionSalesmanList()
- {
- try {
- //如果是代理商登陆
- $admin = get_admin();
- $admin_id = $admin->id;
- if ($admin->username == 'admin') {
- $admin_id = null;
- }
- $query = Salesman::find()->alias('s')->leftJoin(['su' => SaasUser::tableName()], 's.saas_user_id = su.id');
- if ($admin_id) {
- $query->where(['s.admin_id' => $admin_id]);
- }
- $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();
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $salesman
- ]
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionStoreCopyStatus()
- {
- $id = input_params('id', 0);
- $do = input_params('do', 0);
- $res = StoreCopy::doCopyStatus($id, $do);
- return $this->asJson($res);
- }
- public function actionStoreCopy()
- {
- $from_store_id = input_params('from_store_id', 0);
- $to_store_id = input_params('to_store_id', 0);
- $type = input_params('type', ['home']);
- $type = json_encode($type);
- $model = new \app\models\StoreCopy();
- $model->from_store_id = $from_store_id;
- $model->to_store_id = $to_store_id;
- $model->type = $type;
- $model->save();
- $id = queue_push(new \app\jobs\StoreCopyJob(['id' => $model->id]));
- $res = [
- 'code' => 0,
- 'msg' => '数据量太大,请等待执行',
- 'id' => $id
- ];
- return $this->asJson($res);
- }
- public function actionStoreCopyList()
- {
- $from_store_id = input_params('from_store_id', 0);
- $to_store_id = input_params('to_store_id', 0);
- $type = input_params('type', '');
- $query = StoreCopy::find()->where(['is_delete' => 0])->orderBy('id desc');
- $from_store_id && $query->andWhere(['from_store_id' => $from_store_id]);
- $to_store_id && $query->andWhere(['to_store_id' => $to_store_id]);
- $type && $query->andWhere(['like', 'type', $type]);
- $list = pagination_make($query);
- foreach($list['list'] as &$item){
- $item['from_store_name'] = Store::findOne($item['from_store_id'])['name'];
- $item['to_store_name'] = Store::findOne($item['to_store_id'])['name'];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list,
- ]);
- }
- public function actionTemplateDefaultInfo()
- {
- $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
- if($default){
- $default = json_decode($default, true);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'default' => $default,
- ]);
- }
- public function actionTemplateDefaultSave()
- {
- $id = input_params('id', 0);
- $type = input_params('type', ['home']);
- $default = [
- 'store_id' => $id,
- 'type' => $type,
- ];
- \app\models\Option::set('store_template_default', json_encode($default), 0, 'saas');
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- ]);
- }
- public function actionTemplateStatus()
- {
- $id = input_params('id', 0);
- if(strstr($id, ',')){
- $id = explode(',', $id);
- }
- $status = input_params('status', 0);
- StoreTemplate::updateAll(['status' => $status], ['id'=>$id]);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- ]);
- }
- public function actionTemplateDel()
- {
- $id = input_params('id', 0);
- $model = StoreTemplate::findOne($id);
- $model->is_delete = 1;
- $model->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- ]);
- }
- public function actionTemplateAdd()
- {
- $name = input_params('name', '');
- $desc = input_params('desc', '');
- $home_pic = input_params('home_pic', '[]');
- $center_pic = input_params('center_pic', '[]');
- $category_id = input_params('category_id', 0);
- $store_id = input_params('from_store_id', 0);
- $model = new StoreTemplate();
- $model->name = $name;
- $model->desc = $desc;
- $model->home_pic = json_encode($home_pic);
- $model->center_pic = json_encode($center_pic);
- $model->category_id = $category_id;
- $model->store_id = $store_id;
- $model->save();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- ]);
- }
- public function actionTemplateList()
- {
- $status = input_params('status', -1);
- $name = input_params('name', '');
- $category_id = input_params('category_id', 0);
- $cond = ['is_delete' => 0];
- // $name && $cond[] = ['like', 'name', $name];
- $status >= 0 && $cond['status'] = $status;
- $category_id && $cond['category_id'] = $category_id;
- $query = StoreTemplate::find()->where($cond);
- $name && $query->andWhere(['like', 'name', $name]);
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$item){
- $item['cat_name'] = '-';
- if ($item['category_id'] > 0) {
- $cat = SaasCategory::findOne($item['category_id']);
- if ($cat) {
- $item['cat_name'] = $cat->name;
- }
- }
- $item['home_pic'] = json_decode($item['home_pic'], true);
- $item['center_pic'] = json_decode($item['center_pic'], true);
-
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- ],
- ]);
- }
- /**
- * 获取二维码
- */
- public function actionGetQr()
- {
- $store_id = input_params('id', 0);
- $scene = "store:{$store_id}";
- try{
- $res = \app\utils\ShareQrcode::wxQrcode('pages/home/home', $scene);
- }catch(\Exception $e){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请检查是否已添加小程序',
- 'e' => $e,
- ]);
- }
- if (isset($res['code']) && $res['code'] == 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $res['response']['errmsg'],
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'data' => $res['url_path']
- ]);
- }
- public function actionGetKefuInfo()
- {
- $store = Store::findOne(get_store_id());
- if (!$store) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据不存在',
- ]);
- }
- $kefu_auto_reply_img = Option::get('kefu_auto_reply_img', $store->id, 'store', '')['value'];
- $kefu_auto_reply_text = Option::get('kefu_auto_reply_text', $store->id, 'store', '')['value'];
- $is_show_kefu_download = Option::get('is_show_kefu_download', 0, 'saas', 1)['value'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data'=> [
- 'kefu_id' => $store->kefu_id ?: '',
- 'kefu_auto_reply_img' => $kefu_auto_reply_img,
- 'kefu_auto_reply_text' => $kefu_auto_reply_text,
- 'is_show_kefu_download' => intval($is_show_kefu_download)
- ]
- ]);
- }
- public function actionSetKefuInfo()
- {
- $kefu_id = \post_params('kefu_id', '');
- $kefu_auto_reply_img = \post_params('kefu_auto_reply_img', '');
- $kefu_auto_reply_text = \post_params('kefu_auto_reply_text', '');
- $store = Store::findOne(get_store_id());
- if (!$store) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据不存在',
- ]);
- }
- Option::set('kefu_auto_reply_img', $kefu_auto_reply_img, $store->id, 'store');
- Option::set('kefu_auto_reply_text', $kefu_auto_reply_text, $store->id, 'store');
- if (!empty($kefu_id)) {
- if (!preg_match('/^1[3456789]\d{9}$/i', $kefu_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '客服手机号格式错误',
- ]);
- }
- $url = Kefu::API_HOST;
- $host = \str_replace(['http://', 'https://'], '', \Yii::$app->request->hostInfo);
- $res = http_post($url . '/api/regKefu', [
- 'form_params' => [
- 'token' => \Yii::$app->getKefuApiToken(),
- 'host' => $host,
- 'mobile' => $kefu_id,
- 'kefu_auto_reply_img' => $kefu_auto_reply_img,
- 'kefu_auto_reply_text' => $kefu_auto_reply_text,
- ]
- ]);
- if ($res->getStatusCode() != 200) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请求出错!',
- ]);
- }
- $content = json_decode((string)$res->getBody(), true);
- if ($content['code'] == 0) {
- $store->kefu_id = $kefu_id;
- $store->save();
- }
- } else {
- $store->kefu_id = '';
- $store->save();
- $content = [
- 'code' => 0,
- 'msg' => '保存成功',
- ];
- }
- return $this->asJson($content);
- }
- //清除数据可选项
- public function actionDelShareHolderOption() {
- $array = [
- [
- 'title' => '用户',
- 'key' => 'user',
- 'is_checked' => 1,
- 'is_disabled' => 1
- ],
- [
- 'title' => '订单',
- 'key' => 'order',
- 'is_checked' => 1,
- 'is_disabled' => 1
- ],
- [
- 'title' => '链动2+1',
- 'key' => 'shareHolder',
- 'is_checked' => 1,
- 'is_disabled' => 0
- ],
- [
- 'title' => '全域分佣',
- 'key' => 'report',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '37拼购',
- 'key' => 'shareGroup',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '团队极差分红',
- 'key' => 'teamBonus',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '团队业绩分红',
- 'key' => 'teamGrades',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '超级卖货',
- 'key' => 'superSales',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '增值积分',
- 'key' => 'integralAppreciation',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '视频号爆单',
- 'key' => 'videoShop',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- [
- 'title' => '排队免单',
- 'key' => 'freeQueue',
- 'is_checked' => 0,
- 'is_disabled' => 0
- ],
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'key_list' => $array
- ]
- ]) ;
- }
- //删除链动以及其他测试数据
- public function actionDelShareHolderTestInfo()
- {
- try {
- $safe_code = post_params('safe_code');
- $captcha = post_params('captcha');
- $del_key = post_params('del_key');
- $store = Store::findOne(get_store_id());
- if (empty($safe_code) && empty($safe_code)) {
- throw new \Exception("安全码和验证码二选一");
- }
- if (!empty($captcha)) {
- $form = new LoginForm();
- $form->store_id = get_store_id();
- $form->phone = $store->contact_tel;
- $form->verify_code = $captcha;
- $verifySmsCode = $form->verifySmsCode(LoginForm::TYPE_VERIFY_CODE_CLEAR);
- if ($verifySmsCode['code'] != 0) {
- throw new \Exception($verifySmsCode['msg']);
- }
- }
-
- if (!empty($safe_code)) {
- if ($safe_code !== "@TianXin100We10Cn") {
- throw new \Exception("安全码错误");
- }
- }
- $user = User::find()->where(['store_id' => get_store_id()])->select('id, binding')->asArray()->all();
- $user_id = array_column($user, 'id');
- $user_mobile = array_column($user, 'binding');
- $del_key = $del_key ?: [];
- $order_id = Order::find()->where(['store_id' => get_store_id()])->select('id')->column();
- Order::deleteAll(['store_id' => get_store_id()]);
- OrderDetail::deleteAll(['order_id' => $order_id]);
- OrderRefund::deleteAll(['store_id' => get_store_id()]);
- OrderComment::deleteAll(['store_id' => get_store_id()]);
- // SaasUser::deleteAll();
- User::deleteAll(['store_id' => get_store_id()]);
- SaasUser::updateAll(['access_token' => ''], ['mobile' => $user_mobile]);
- UserTreePath::deleteAll(["OR", ['parent_id' => $user_id], ['child_id' => $user_id]]);
- OldUserTreePath::deleteAll(["OR", ['parent_id' => $user_id], ['child_id' => $user_id]]);
- ShareDetail::deleteAll(['store_id' => get_store_id()]);
- ShareHolder::deleteAll(['store_id' => get_store_id()]);
- ShareHolderFrostLog::deleteAll(["OR", ['parent_user_id' => $user_id], ['child_user_id' => $user_id]]);
- ShareHolderOutLog::deleteAll(["OR", ['parent_user_id' => $user_id], ['child_user_id' => $user_id]]);
- BonusPoolLevel::deleteAll(['store_id' => get_store_id()]);
- ShareHolderLevelLog::deleteAll(['store_id' => get_store_id()]);
- ShareHolderParentOutLog::deleteAll(['store_id' => get_store_id()]);
- Cash::deleteAll(['store_id' => get_store_id()]);
- AccountLog::deleteAll(['store_id' => get_store_id()]);
- \app\plugins\scanCodePay\models\Order::deleteAll(['store_id' => get_store_id()]);
- Share::deleteAll(['store_id' => get_store_id()]);
- UserShareMoney::deleteAll(['store_id' => get_store_id()]);
- //拼团
- // $ptActivityOrderId = PtActivityOrder::find()->where(['store_id' => get_store_id()])->select('id')->column();
- // PtActivityOrder::deleteAll(['store_id' => get_store_id()]);
- // PtActivityOrderDetail::deleteAll(['order_id' => $ptActivityOrderId]);
- //砍价
- // ActivityCutPriceLog::deleteAll(['store_id' => get_store_id()]);
- // ActivityCutPriceOrder::deleteAll(['store_id' => get_store_id()]);
- //消费全返
- // ActivityOrderRebateSelfOrder::deleteAll(['store_id' => get_store_id()]);
- // ActivityOrderRebateSelfUser::deleteAll(['store_id' => get_store_id()]);
- //推N返1
- // ActivityRebateOrderNLog::deleteAll(['store_id' => get_store_id()]);
- //全域分佣
- if (in_array('report', $del_key)) {
- ReportCommitIntegral::deleteAll(['store_id' => get_store_id()]);
- ReportInfo::deleteAll(['store_id' => get_store_id()]);
- ReportPool::deleteAll(['store_id' => get_store_id()]);
- ReportPoolDetail::deleteAll(['store_id' => get_store_id()]);
- ReportPoolLevel::deleteAll(['store_id' => get_store_id()]);
- }
- //团队级差分红
- if (in_array('teamBonus', $del_key)) {
- TeamBonusOrderExt::deleteAll(['store_id' => get_store_id()]);
- }
- //37拼购
- if (in_array('shareGroup', $del_key)) {
- $shareGroupMoneyId = ShareGroupMoney::find()->where(['store_id' => get_store_id()])->select('id')->column();
- ShareGroupMoney::deleteAll(['store_id' => get_store_id()]);
- ShareGroupMoneySub::deleteAll(['share_money_id' => $shareGroupMoneyId]);
- ShareGroupSupportLog::deleteAll(['store_id' => get_store_id()]);
- ShareGroupPurchaseParentLog::deleteAll(['store_id' => get_store_id()]);
- ShareGroupPurchaseUser::deleteAll(['store_id' => get_store_id()]);
- }
- //超级卖货系统
- if (in_array('superSales', $del_key)) {
- $superSalesId = SuperSales::find()->where(['store_id' => get_store_id()])->select('id')->column();
- SuperSales::deleteAll(['store_id' => get_store_id()]);
- SuperSalesSub::deleteAll(['sales_id' => $superSalesId]);
- SuperSalesUser::deleteAll(['store_id' => get_store_id()]);
- SuperSalesMoney::deleteAll(['store_id' => get_store_id()]);
- SuperSalesRepeatOrder::deleteAll(['store_id' => get_store_id()]);
- }
- //团队业绩
- if (in_array('teamGrades', $del_key)) {
- TeamGrades::deleteAll(['store_id' => get_store_id()]);
- TeamGradesAudit::deleteAll(['store_id' => get_store_id()]);
- TeamGradesDividendLog::deleteAll(['store_id' => get_store_id()]);
- $teamGradesPoolId = TeamGradesPool::find()->where(['store_id' => get_store_id()])->select('id')->column();
- TeamGradesPool::deleteAll(['store_id' => get_store_id()]);
- TeamGradesPoolDetail::deleteAll(['pool_id' => $teamGradesPoolId]);
- TeamGradesPoolDetailExt::deleteAll(['order_id' => $order_id]);
- }
- //消费积分增值
- if (in_array('integralAppreciation', $del_key)) {
- IntegralAppreciationCommunity::deleteAll(['store_id' => get_store_id()]);
- IntegralAppreciationUser::deleteAll(['store_id' => get_store_id()]);
- IntegralAppreciationCashLog::deleteAll(['user_id' => $user_id]);
- IntegralAppreciationUserIntegralLog::deleteAll(['order_id' => $order_id]);
- IntegralAppreciationPool::deleteAll(['store_id' => get_store_id()]);
- IntegralAppreciationPoolSub::deleteAll(['store_id' => get_store_id()]);
- }
- //视频号爆单
- if (in_array('videoShop', $del_key)) {
- PublicRankingTask::deleteAll(['store_id' => get_store_id()]);
- PublicRankingUser::deleteAll(['store_id' => get_store_id()]);
- Promoter::deleteAll(['store_id' => get_store_id()]);
- VideoShopGoodsExt::deleteAll(['store_id' => get_store_id()]);
- VideoShopOrderExt::deleteAll(['store_id' => get_store_id()]);
- VideoShopUser::deleteAll(['store_id' => get_store_id()]);
- VideoShopOrderExtAli::deleteAll(['store_id' => get_store_id()]);
- VideoShopSharer::deleteAll(['store_id' => get_store_id()]);
- }
- //排队免单
- if (in_array('freeQueue', $del_key)) {
- QueueAccountLog::deleteAll(['store_id' => get_store_id()]);
- QueueLog::deleteAll(['store_id' => get_store_id()]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => "操作成功"
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- public function actionSendCode()
- {
- $form = new LoginForm();
- $store = Store::findOne(get_store_id());
- $form->phone = $store->contact_tel;
- $form->store_id = get_store_id();
- return $this->asJson($form->sendCode(LoginForm::TYPE_VERIFY_CODE_CLEAR));
- }
- public function actionTimerTaskCopy()
- {
- $autoDownGoods = \Yii::$app->request->hostInfo . '/index.php?r=common/task/auto-off-goods';
- $order = \Yii::$app->request->hostInfo . '/index.php?r=common/task/execute';
- $queue = '';
- $user = get_current_user();
- $www_path = \Yii::$app->basePath . '/';
- $queue_cli = '';
- \ob_start();
- \phpinfo(INFO_GENERAL);
- $phpinfo = \ob_get_contents();
- ob_end_clean();
- \preg_match("/--prefix=(.*)' '/U", $phpinfo, $matches);
- if (isset($matches[1])) {
- $queue_cli = $matches[1] . '/bin/php yii queue/listen';
- $queue = 'su -c "' . $matches[1] . '/bin/php ' . \Yii::$app->basePath . '/yii queue/run' . '" -s /bin/sh ' . $user;
- } else {
- $queue = '获取php cli路径失败, 请手动获取';
- }
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'autoDownGoods' => $autoDownGoods,
- 'order' => $order,
- 'queue' => $queue,
- 'queue_cli' => $queue_cli,
- 'www_path' => $www_path,
- ],
- 'msg' => 'success'
- ]);
- }
- public function actionSetAppParams()
- {
- try {
- if (\Yii::$app->request->isPost) {
- $key = [
- OptionSetting::APP_STORE_ANDROID,
- OptionSetting::APP_STORE_ANDROID_VERSION,
- OptionSetting::STORE_APP_LOGO,
- OptionSetting::STORE_APP_BG,
- OptionSetting::APP_STORE_IOS,
- OptionSetting::APP_IS_OPEN_MAP,
- OptionSetting::MAP_APP_CODE,
- ];
- $params = post_params();
- $value = [
- $params['app_store_android'],
- $params['app_store_android_version'],
- $params['store_app_logo'],
- $params['store_app_bg'],
- $params['app_store_ios'],
- $params['app_is_open_map'],
- $params['map_app_code'],
- ];
- Option::set($key, $value, get_store_id(), 'app');
- return $this->asJson([
- 'code' => 0,
- 'msg' => ''
- ]);
- } else {
- $keys = [
- OptionSetting::APP_STORE_ANDROID,
- OptionSetting::APP_STORE_ANDROID_VERSION,
- OptionSetting::STORE_APP_LOGO,
- OptionSetting::STORE_APP_BG,
- OptionSetting::APP_STORE_IOS,
- OptionSetting::APP_IS_OPEN_MAP,
- OptionSetting::MAP_APP_CODE,
- ];
- $data = Option::get($keys, get_store_id(), 'app');
- if (empty($data)) {
- $data = [
- OptionSetting::APP_STORE_ANDROID => '',
- OptionSetting::APP_STORE_ANDROID_VERSION => '',
- OptionSetting::STORE_APP_LOGO => '',
- OptionSetting::STORE_APP_BG => '',
- OptionSetting::APP_STORE_IOS => '',
- OptionSetting::APP_IS_OPEN_MAP => 2,
- OptionSetting::MAP_APP_CODE => '',
- ];
- } else {
- $arr = [];
- foreach ($data as $value) {
- $index = array_search($value['name'], $keys);
- unset($keys[$index]);
- $arr[$value['name']] = $value['value'];
- }
- foreach ($keys as $key) {
- $arr[$key] = '';
- }
- $data = $arr;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data,
- ]);
- }
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- //设置商城版权信息
- public function actionSetCopyright()
- {
- try {
- $store_id = input_params('id') ?? get_store_id();
- if (\Yii::$app->request->isPost) {
- $copyright_params = [];
- $copyright_params['type'] = post_params('type') ?? 0;
- $copyright_params['mini_url'] = post_params('mini_url') ?? '';
- $copyright_params['mobile'] = post_params('mobile') ?? '';
- $copyright_params['logo'] = post_params('logo') ?? '';
- $copyright_params['copyright'] = post_params('copyright') ?? '';
- Option::set('copyright', json_encode($copyright_params), $store_id, 'store');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- } else {
- $copyright = Option::get('copyright', $store_id, 'store', '')['value'];
- $store_admin = Admin::findOne(['type' => 'store', 'type_id' => $store_id, 'is_delete' => 0]);
- $store = Store::findOne($store_id);
- $copyright = json_decode($copyright, true) ?: [
- 'type' => 1,
- 'mini_url' => [
- 'name' => '商城首页',
- 'link' => '/pages/home/home',
- 'open_type' => "switchtab",
- 'params' => []
- ],
- 'mobile' => $store_admin->mobile ?? '',
- 'logo' => $store->logo ?: (Option::get('logo', $store_id, 'store')['value'] ?: Option::get('web_log', $store_id, 'web')['value']),
- 'copyright' => $store->name
- ];
- $copyright['type'] = intval($copyright['type']);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => $copyright
- ]);
- }
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- //设置商城联盟积分比例
- public function actionSetStoreIntegral()
- {
- try {
- $store_id = input_params('id') ?? get_store_id();
- if (\Yii::$app->request->isPost) {
- $face_pay_integral_profit = post_params('face_pay_integral_profit', 0);
- $online_pay_integral_profit = post_params('online_pay_integral_profit', 0);
- Option::set([
- 'face_pay_integral_profit',
- 'online_pay_integral_profit'
- ], [
- $face_pay_integral_profit,
- $online_pay_integral_profit
- ], $store_id, 'saas');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功'
- ]);
- } else {
- $face_pay_integral_profit = Option::get('face_pay_integral_profit', $store_id, 'saas', 0)['value'];
- $online_pay_integral_profit = Option::get('online_pay_integral_profit', $store_id, 'saas', 0)['value'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'face_pay_integral_profit' => $face_pay_integral_profit,
- 'online_pay_integral_profit' => $online_pay_integral_profit,
- ]
- ]);
- }
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- // 当面付支付后跳转设置
- public function actionSettingFacePayPath()
- {
- $store_id = get_store_id();
- if (\Yii::$app->request->isPost) {
- $face_pay_path = post_params('face_pay_path', '');
- $face_pay_path = json_encode($face_pay_path, JSON_UNESCAPED_UNICODE);
- Option::set('face_pay_path', $face_pay_path, 0, 'saas');
- return $this->asJson([
- 'code' => 0,
- 'msg' => '保存成功',
- ]);
- }
- $data = [
- 'face_pay_path' => Option::get('face_pay_path', 0, 'saas', '')['value']
- ];
- $data['face_pay_path'] = json_decode($data['face_pay_path'], true) ?: null;
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'msg' => 'success',
- ]);
- }
- //联盟券列表
- public function actionStoreLeagueLog()
- {
- // 区分平台或者商城
- $store_id = get_params('store_id');
- //条件
- $user_name = get_params('user_name');
- $mobile = get_params('mobile');
- $start_time = get_params('start_time');
- $end_time = get_params('end_time');
- //
- $query = SaaSLeaguePriceLog::find()->alias('lpl')
- ->where(['lpl.role' => SaaSLeaguePriceLog::ROLE_USER, 'lpl.is_delete' => 0])
- ->andWhere(['>', 'lpl.league_price', 0]);
- if ($store_id) {
- $query->andWhere(['lpl.store_id' => $store_id]);
- }
- if ($user_name) {
- $query->andWhere(['LIKE', 'su.name', $user_name]);
- }
- if ($mobile) {
- $query->andWhere(['LIKE', 'su.mobile', $mobile]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'lpl.addtime', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'lpl.addtime', $end_time]);
- }
- $query->leftJoin(['su' => SaasUser::tableName()], 'su.id = lpl.saas_user_id');
- $query->select('lpl.id, lpl.saas_user_id, lpl.type, lpl.order_id, lpl.send_or_take_type, lpl.store_id,
- lpl.after, lpl.before, lpl.league_price, lpl.addtime, su.name user_name, su.mobile user_mobile, su.avatar user_avatar')
- ->orderBy('lpl.id desc');
- $pagination = pagination_make($query);
- foreach ($pagination['list'] as &$item) {
- $item['addtime'] = date("Y-m-d H:i:s", $item['addtime']);
- $item['send_or_take_type'] = (int)$item['send_or_take_type'];
- $item['type'] = (int)$item['type'];
- $item['type_name'] = SaaSLeaguePriceLog::getTypeStr($item['type']);
- $item['order_no'] = '';
- if ($item['order_id']) {
- if (in_array($item['type'], [
- SaaSLeaguePriceLog::TYPE_ORDER_REBATE,//下单返利
- SaaSLeaguePriceLog::TYPE_CANCEL,//订单取消退回
- SaaSLeaguePriceLog::TYPE_DEDUCTION,//下单抵扣
- ])) {
- $order = Order::findOne($item['order_id']);
- }
- if ($item['type'] === SaaSLeaguePriceLog::TYPE_LEAGUE_RECHARGE) {//联盟券
- $order = RechargeReOrder::findOne($item['order_id']);
- }
- if (in_array($item['type'], [
- SaaSLeaguePriceLog::TYPE_WITHDRAW,
- SaaSLeaguePriceLog::TYPE_WITHDRAW_REJECT,
- ])) {//联盟券提现
- $order = Cash::findOne($item['order_id']);
- }
- if ($item['type'] === SaaSLeaguePriceLog::TYPE_FACE_PAY_ORDER) {//当面付
- $order = \app\plugins\scanCodePay\models\Order::findOne($item['order_id']);
- }
- if (isset($order)) {
- $item['order_no'] = $order->order_no ?: '';
- }
- }
- $store = Store::findOne($item['store_id']);
- $item['store_name'] = $store ? $store->name : '';
- }
- $league_price_query = Store::find()->where(['is_delete' => 0]);
- if ($store_id) {
- $league_price_query->andWhere(['id' => $store_id]);
- }
- $league_price = $league_price_query->select('league_price')->sum('league_price') ?: 0;
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $pagination['list'],
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount'],
- 'league_price' => $league_price
- ],
- ]);
- }
- public function actionIsPlatformTransfers()
- {
- $id = get_params('id');
- $isPlatformTransfers = get_params('is_platform_transfers');
- try {
- $transaction = \Yii::$app->db->beginTransaction();
- $store = Store::findOne($id);
- if (!$store) {
- throw new \Exception('店铺不存在');
- }
- $store->is_platform_transfers = $isPlatformTransfers;
- if (!$store->save()) {
- if ($store->hasErrors()) {
- throw new \Exception('Validation failed: ' . implode(', ', $store->getFirstErrors()));
- } else {
- throw new \Exception('Failed to save the changes.');
- }
- }
- $transaction->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'Success',
- 'data' => $store,
- ]);
- } catch (\Exception $e) {
- if (isset($transaction) && $transaction->isActive) {
- $transaction->rollBack();
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage(),
- 'data' => []
- ]);
- }
- }
- public function actionStoreRecharge()
- {
- $data = get_params();
- $rechargeType = $data['recharge_type'];
- $id = $data['id'];
- $money = $data['money'];
- $store = Store::findOne($id);
- $before = $store->store_balance;
- $after = 0;
- if ($rechargeType == 1) {
- $store->total_store_quota += $money;
- $store->store_balance += $money;
- $store->price += $money;
- $store->total_price += $money;
- $after = $store->store_balance;
- $result = StoreMoneyLog::saveLog($id, StoreMoneyLog::LOG_TYPE_INCOME, StoreMoneyLog::TYPE_STORE, $money, "后台充值: {$money}", $before, $after);
- } else {
- if ($store->store_balance >= $money) {
- $store->store_balance -= $money;
- $store->total_price -= $money;
- $store->price -= $money;
- $after = $store->store_balance;
- $result = StoreMoneyLog::saveLog($id, StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_STORE, $money, "后台扣除: {$money}", $before, $after);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'error',
- 'data' => [],
- ]);
- }
- }
- if ($result !== true) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'error',
- 'data' => [],
- ]);
- }
- if (!$store->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'error',
- 'data' => [],
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'Success',
- 'data' => $store,
- ]);
- }
- public function actionStoreMoneyHistory()
- {
- $id = get_params('id');
- $data = StoreMoneyLog::find()->alias('l')
- ->leftJoin(['s' => Store::tableName()], 's.id = l.store_id')
- ->select('l.*, s.name store_name')
- ->where(['l.store_id' => $id])->orderBy('l.id desc')->asArray()->all();
- foreach ($data as &$value) {
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- switch ($value['type']) {
- case 1:
- $value['type'] = '分销提现';
- break;
- case 2:
- $value['type'] = '股东分红提现';
- break;
- case 3:
- $value['type'] = '门店提现';
- break;
- case 4:
- $value['type'] = '2+1提现';
- break;
- default:
- $value['type'] = '后台操作';
- break;
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'Success',
- 'data' => $data,
- ]);
- }
- //获取商城微信小程序码
- public function actionGetWechatQrcode() {
- try {
- $store_id = get_params('store_id');
- $store = Store::findOne($store_id);
- $is_platform = 0;
- if (intval($store->business_model) !== 1) {
- $is_platform = 1;
- }
- $app = WechatMini::getWechatConfig($store_id, 0, 0, $is_platform);
- if (!$app) {
- throw new \Exception('没有对应的小程序');
- }
- $page = "pages/home/home";
- $scene = "store:{$store_id}";
- if ($store->business_model == 2) { //平台运营
- $page = 'pages/shop/shopIndex';
- $scene = "store_id:{$store_id}";
- } elseif ($store->business_model == 3) { //当面付
- $page = 'face-pay/face-pay/payOut';
- $scene = "store_id:{$store_id}";
- } elseif ($store->business_model == 4) { //点餐
- $page = 'alipay-order/orderMeal/orderMeal';
- $scene = "md_id:-1,store_id:{$store_id}";
- }
- $response = $app->app_code->getUnlimit($scene, [
- 'page' => $page
- ]);
- $filename = md5(time() . 'pages_home') . '.jpg';
- $filePath = \Yii::$app->basePath . '/runtime/image/wx_qrcode';
- if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
- $resfilename = $response->saveAs($filePath, $filename);
- if (!empty($resfilename)) {
- $filePath = 'https://' . str_replace(\Yii::$app->basePath, \Yii::$app->request->hostName, $filePath . '/' . $filename);
- return $this->asJson([
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $filePath
- ]);
- } else {
- throw new \Exception("数据错误");
- }
- } else {
- throw new \Exception("数据错误");
- }
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- }
|