StoreForm.php 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\jobs\StoreSyncJob;
  9. use app\models\AggregateQrcode;
  10. use app\models\AggregateSaasQrcode;
  11. use app\models\MerchantInfo;
  12. use app\models\Purchase;
  13. use app\models\SaasUser;
  14. use app\models\Salesman;
  15. use app\models\SalesmanNewStore;
  16. use app\models\StoreAudit;
  17. use app\models\StoreReOrder;
  18. use app\models\UploadConfig;
  19. use app\modules\common\controllers\WechatNativeController;
  20. use app\utils\Notice\NoticeSend;
  21. use app\utils\OrderNo;
  22. use app\utils\QrCode;
  23. use app\utils\ShareQrcode;
  24. use app\utils\WechatMerchant\Merchant;
  25. use app\utils\yunst\src\MemberService;
  26. use Yii;
  27. use app\models\Store;
  28. use app\models\StoreCloud;
  29. use yii\base\Model;
  30. use app\models\Admin;
  31. use app\models\Option;
  32. use app\models\Goods;
  33. use app\models\SaasStoreReferral;
  34. use app\models\DiyTemplate;
  35. use app\models\NewDiyTemplate;
  36. use app\models\SaasCategory;
  37. use Exception;
  38. use yii\data\Pagination;
  39. use yii\helpers\Json;
  40. use app\constants\OptionSetting;
  41. class StoreForm extends Model
  42. {
  43. public $page = 1;
  44. public $limit = 10;
  45. public $id;
  46. public $name;
  47. public $user_name;
  48. public $category_id = -1;
  49. public $status = -1; // -1 所有,1 未进件, 2 已进件
  50. public $business_model = -1;
  51. public $salesman_id;
  52. public $admin_id;
  53. public $qrcode_id;
  54. public $mobile;
  55. public $province_id;
  56. public $city_id;
  57. public $district_id;
  58. public $integral_profit_status; //平台积分赠送设置状态
  59. public $start_time;
  60. public $end_time;
  61. public $balance;
  62. public function rules()
  63. {
  64. return [
  65. [['page','limit', 'id', 'category_id', 'status', 'business_model', 'salesman_id', 'admin_id', 'qrcode_id', 'integral_profit_status'],'integer'],
  66. [['name', 'user_name', 'start_time', 'end_time'], 'string'],
  67. [['province_id', 'city_id', 'district_id'], 'safe']
  68. ];
  69. }
  70. //模糊匹配店铺名称
  71. public function getStoreIdByStoreName(){
  72. $name = get_params('name');
  73. if(!$name){
  74. return [
  75. 'code' => 1,
  76. 'msg' => '',
  77. ];
  78. }
  79. $query = Store::find()->where([
  80. 'is_delete' => 0,
  81. ])->andWhere(['like', 'name',$name."%" , false]);
  82. $query->select("id,name,logo");
  83. $pagination = pagination_make($query);
  84. return [
  85. 'code' => 0,
  86. 'msg' => 'success',
  87. 'data' => [
  88. 'data' => $pagination['list'],
  89. 'pageNo' => $pagination['pageNo'],
  90. 'totalCount' => $pagination['totalCount']
  91. ],
  92. ];
  93. }
  94. //商盟店铺列表
  95. public function getAllianceList(){
  96. $category_id = get_params('categoryId');
  97. $name = get_params('name');
  98. $query = Store::find()->where([
  99. 'is_delete' => 0,
  100. ]);
  101. if($category_id){
  102. $query->andWhere(['category_id'=>$category_id]);
  103. }
  104. if($name){
  105. $query->andWhere(['like', 'name',$name."%" , false]);
  106. }
  107. $query->select("id,name,logo");
  108. $pagination = pagination_make($query);
  109. if(isset($pagination['list']) && count($pagination['list']) > 0){
  110. foreach($pagination['list'] as $key=>$val){
  111. //获取6条商品记录
  112. $goodsInfo = Goods::find()->where(['store_id'=>$val['id'],'is_delete'=>0,'status'=>1])->select("id,name,price,original_price,cover_pic")->limit(6)->asArray()->all();
  113. if(count($goodsInfo) > 0){
  114. $pagination['list'][$key]['goodsInfo'] = $goodsInfo;
  115. }else{
  116. $pagination['list'][$key]['goodsInfo'] = [];
  117. }
  118. }
  119. }
  120. return [
  121. 'code' => 0,
  122. 'msg' => 'success',
  123. 'data' => [
  124. 'data' => $pagination['list'],
  125. 'pageNo' => $pagination['pageNo'],
  126. 'totalCount' => $pagination['totalCount']
  127. ],
  128. ];
  129. }
  130. public function getList($admin_id = null, $andWhere = null)
  131. {
  132. $id = $this->id;
  133. $name = $this->name;
  134. $user_name = $this->user_name;
  135. $status = $this->status;
  136. $mobile = $this->mobile;
  137. $start_time = $this->start_time;
  138. $end_time = $this->end_time;
  139. $query = Store::find()->where([
  140. 's.is_delete' => 0,
  141. ]);
  142. if($andWhere){
  143. $query->andWhere($andWhere);
  144. }
  145. if ($this->business_model > -1) {
  146. $query->andWhere(['s.business_model' => $this->business_model]);
  147. }
  148. if (!empty($id)) {
  149. $query->andWhere(['s.id' => $id]);
  150. }
  151. if (!empty($name)) {
  152. $query->andWhere(['LIKE', 's.name', $name]);
  153. }
  154. // if (!empty($mobile)) {
  155. // $query->andWhere(['LIKE', 's.contact_tel', $mobile]);
  156. // }
  157. if (!empty($this->province_id)) {
  158. $query->andWhere(['s.province_id' => $this->province_id]);
  159. }
  160. if (!empty($this->city_id)) {
  161. $query->andWhere(['s.city_id' => $this->city_id]);
  162. }
  163. if (!empty($this->district_id)) {
  164. $query->andWhere(['s.district_id' => $this->district_id]);
  165. }
  166. if ($start_time) {
  167. $start_time = strtotime($start_time);
  168. $query->andWhere(['>=', 's.created_at', $start_time]);
  169. }
  170. if ($end_time) {
  171. $end_time = strtotime($end_time);
  172. $query->andWhere(['<=', 's.created_at', $end_time]);
  173. }
  174. if ($this->integral_profit_status !== null && intval($this->integral_profit_status) !== -1 && in_array($this->integral_profit_status, [0, 1])) {
  175. $profit_where = ['>', 'value', 0];
  176. $store_id_arr = Option::find()->where(['name' => ['face_pay_integral_profit', 'online_pay_integral_profit'], 'group' => 'saas'])
  177. ->andWhere($profit_where)->select('store_id')->column();
  178. if (intval($this->integral_profit_status) === 1) {
  179. $query->andWhere(['in', 's.id', $store_id_arr]);
  180. } else {
  181. $query->andWhere(['NOT IN', 's.id', $store_id_arr]);
  182. }
  183. }
  184. if ($admin_id) {
  185. $ids = Salesman::find()->where(['admin_id' => $admin_id, 'is_delete' => 0])->select('saas_user_id, id')->asArray()->all();
  186. $store_ids = SalesmanNewStore::find()->where(['salesman_saas_id' => array_column($ids, 'saas_user_id')])
  187. ->andWhere(['>', 'store_id', 0])->select('store_id')->column();
  188. $admin_model = Admin::findOne($admin_id);
  189. if ($admin_model->type === Admin::ADMIN_TYPE_DEFAULT) { //如果是区域代理
  190. $area_level = $admin_model->area_level;
  191. if($area_level == 1){
  192. $query->andWhere([
  193. 'or',
  194. ['s.province_id' => $admin_model->province_id, 's.city_id' => $admin_model->city_id, 's.district_id' => $admin_model->district_id],
  195. ['s.admin_id' => $admin_id]
  196. ]);
  197. } elseif ($area_level == 2){
  198. $query->andWhere([
  199. 'or',
  200. ['s.province_id' => $admin_model->province_id, 's.city_id' => $admin_model->city_id],
  201. ['s.admin_id' => $admin_id]
  202. ]);
  203. } elseif ($area_level == 3){
  204. $query->andWhere([
  205. 'or',
  206. ['s.province_id' => $admin_model->province_id],
  207. ['s.admin_id' => $admin_id]
  208. ]);
  209. } else {
  210. $query->andWhere(['s.admin_id' => $admin_id]);
  211. }
  212. } elseif ($admin_model->type === Admin::ADMIN_TYPE_BD_AGENT) {//如果是推广代理
  213. $query->andWhere([
  214. 'or',
  215. ['s.admin_id' => $admin_id],//添加店铺时候修改的
  216. ['in', 's.salesman_id', array_column($ids, 'id')],//修改店铺业务员时候修改的
  217. ['in', 's.store_admin', array_column($ids, 'saas_user_id')],//修改店铺业务员时候修改的
  218. ['in', 's.id', $store_ids]//业务员帮助店铺进件时候增加
  219. ]);
  220. }
  221. }
  222. if ($this->category_id > 0) {
  223. // 筛选类目
  224. $query->andWhere(['s.category_id' => $this->category_id]);
  225. }
  226. if ($this->mobile) {
  227. $query->andWhere(['su.mobile' => $this->mobile]);
  228. }
  229. if ($user_name) {
  230. $query->andWhere(['LIKE', 'su.name', $user_name]);
  231. }
  232. $query->leftJoin(['a' => Admin::tableName()], 'a.type = "store" AND a.type_id = s.id');
  233. $query->leftJoin(['su' => SaasUser::tableName()], 'a.saas_user_id = su.id');
  234. $query->alias('s')->leftJoin(['c_s'=>StoreCloud::tableName()],'s.id=c_s.store_id')->select('s.*,c_s.id is_cloud_store,c_s.is_delete cloud_is_delete')->orderBy('s.id DESC');
  235. if ($this->status > -1) {
  236. $query->leftJoin(['m' => MerchantInfo::tableName()], 's.id=m.bind_store_id')->andWhere(['m.is_delete' => 0]);
  237. if ($this->status == 1) {
  238. $query->andWhere(['<', 'm.status', 3]);
  239. }
  240. if ($this->status == 2) {
  241. $query->andWhere(['m.status' => 3]);
  242. }
  243. }
  244. $query->groupBy('s.id');
  245. $pagination = pagination_make($query);
  246. $list = $pagination['list'];
  247. $currentAdmin = get_admin();
  248. $cache = cacheLock();
  249. foreach ($list as &$item) {
  250. $bd_agent = null;
  251. $salesman = null;
  252. if (empty($item['logo'])) {
  253. $item['logo'] = Option::get('web_log', $item['id'], 'web', '')['value'];
  254. }
  255. // if ($item['admin_id']) {
  256. // $bd_agent = Admin::findOne(['id' => $item['admin_id'], 'type' => 'bd_agent', 'is_delete' => 0]);
  257. // }
  258. if ($item['salesman_id']) {
  259. $salesman = Salesman::findOne(['id' => $item['salesman_id'], 'is_delete' => 0]);
  260. } else {
  261. $salesmanNewStore = \app\models\SalesmanNewStore::findOne(['store_id' => $item['id']]);
  262. if ($salesmanNewStore) {
  263. $salesman = Salesman::findOne(['saas_user_id' => $salesmanNewStore->salesman_saas_id, 'is_delete' => 0]);
  264. }
  265. if (!$salesman) {
  266. $salesman = Salesman::findOne(['saas_user_id' => $item['store_admin'], 'is_delete' => 0]);
  267. }
  268. }
  269. $salesman_admin = null;
  270. if (!empty($salesman)) {
  271. $salesman_admin = [
  272. 'name' => SaasUser::findOne(['id' => $salesman->saas_user_id])->name ?? ''
  273. ];
  274. if ($salesman->admin_id && empty($bd_agent)) {
  275. $bd_agent = Admin::findOne($salesman->admin_id);
  276. }
  277. }
  278. // $salesman_admin = Admin::findOne($salesman->admin_id);
  279. $agent_admin = !empty($bd_agent) ? $bd_agent : '';
  280. $item['agent_admin'] = ($agent_admin && $agent_admin->type == Admin::ADMIN_TYPE_BD_AGENT) ? $agent_admin : null;
  281. $item['salesman_admin'] = $salesman_admin ?? null;
  282. $self_mini = Option::get('self_mini', $item['id'], 'store', 0)['value'];
  283. $item['self_mini'] = $self_mini;
  284. $saasU = SaasUser::findOne($item['store_admin']);
  285. $item['contact_tel'] = $saasU->mobile ?? '';
  286. $item['admin_user_name'] = Admin::findOne(['type' => 'store', 'type_id' => $item['id']])->username;
  287. $item['admin_name'] = Admin::findOne(['type' => 'store', 'type_id' => $item['id']])->name;
  288. $item['face_pay_integral_profit'] = Option::get('face_pay_integral_profit', $item['id'], 'saas', 0)['value'];
  289. $item['online_pay_integral_profit'] = Option::get('online_pay_integral_profit', $item['id'], 'saas', 0)['value'];
  290. $item['integral_profit_status'] = 0;
  291. if ($item['face_pay_integral_profit'] > 0 && $item['online_pay_integral_profit'] > 0) {
  292. $item['integral_profit_status'] = 1;
  293. }
  294. $merchant_info = MerchantInfo::findOne(['bind_store_id' => $item['id'], 'is_delete' => 0]);
  295. if (!$merchant_info) {
  296. $item['wechat_audit_text'] = '待进件';
  297. } else {
  298. if ($merchant_info->status == 1) {
  299. $item['wechat_audit_text'] = '审核中';
  300. } else if ($merchant_info->status == 2) {
  301. $item['wechat_audit_text'] = '已驳回';
  302. } else if ($merchant_info->status == 3) {
  303. $item['wechat_audit_text'] = '已完成';
  304. } else {
  305. $item['wechat_audit_text'] = '待审核';
  306. }
  307. }
  308. if ($item['is_alliance'] === '1') {
  309. $item['is_alliance'] = true;
  310. } else {
  311. $item['is_alliance'] = false;
  312. }
  313. // $option = Option::get('name', $item['id'], 'store', '-');
  314. $item['store_name'] = $item['name'];
  315. if (! $admin_id) {
  316. $admin = Admin::findOne([
  317. 'type' => 'store',
  318. 'type_id' => $item['id']
  319. ]);
  320. if (!$admin) {
  321. $admin = Admin::findOne($item['store_admin_id']);
  322. }
  323. $item['admin'] = $admin;
  324. $item['admin_saas_user'] = $admin? SaasUser::findOne($admin->saas_user_id) : '';
  325. $item['username'] = 'admin';
  326. } else {
  327. $item['username'] = $currentAdmin->username;
  328. }
  329. $item['cat_name'] = '-';
  330. if ($item['category_id'] > 0) {
  331. $cat = SaasCategory::findOne($item['category_id']);
  332. if ($cat) {
  333. $item['cat_name'] = $cat->name;
  334. }
  335. }
  336. // 初始化diy模板
  337. $is = NewDiyTemplate::find()
  338. ->where([
  339. 'store_id' => $item['id'],
  340. 'is_delete' => 0,
  341. 'type' => 100
  342. ])->asArray()->one();
  343. if (!$is) {
  344. $this->initDiyTemplate($item['id']);
  345. }
  346. $key = 'store_' . $item['id']. '_version';
  347. if (\Yii::$app->prod_is_dandianpu()) {
  348. $self_mini = Option::get('self_mini', $item['id'], 'store', 0)['value'];
  349. if (!$self_mini) {
  350. $key = 'store_dandianpu_version';
  351. }
  352. }
  353. $item['version'] = $cache->get($key) ?: '';
  354. }
  355. $currentAdmin = get_admin();
  356. $count = Store::find()->where(['admin_id' => $currentAdmin->id])->count();
  357. $canStoreCount = $currentAdmin->max_app_count - $count;
  358. return [
  359. 'code' => 0,
  360. 'msg' => 'success',
  361. 'data' => [
  362. 'is_super_admin' => $currentAdmin->username == 'admin',
  363. 'data' => $list,
  364. 'pageNo' => $pagination['pageNo'],
  365. 'totalCount' => $pagination['totalCount'],
  366. 'canStoreCount' => $canStoreCount < 0 ? 0 : $canStoreCount,
  367. 'saas' => get_saas_user()
  368. ],
  369. ];
  370. }
  371. public function getStoreList()
  372. {
  373. try {
  374. $query = Store::find()->where(['s.is_delete' => 0, 'a.is_delete' => 0])->alias('s')
  375. ->leftJoin(['c_s'=>StoreCloud::tableName()],'s.id=c_s.store_id')
  376. ->leftJoin(['a'=>Admin::tableName()],'s.admin_id=a.id');//TODO 显示全部店铺 不去掉已经选择的店铺
  377. $admin = get_admin();
  378. $admin_id = $admin->id;
  379. if ($admin->username == 'admin') {
  380. $admin_id = null;
  381. }if ($admin_id) {
  382. $ids = Salesman::find()->where(['admin_id' => $admin_id, 'is_delete' => 0])->select('id')->asArray()->all();
  383. $admin_model = Admin::findOne($admin_id);
  384. $area_level = $admin_model->area_level;
  385. if($area_level == 1){
  386. $query->andWhere([
  387. 'or',
  388. ['s.province_id' => $admin_model->province_id, 's.city_id' => $admin_model->city_id, 's.district_id' => $admin_model->district_id],
  389. ['s.admin_id' => $admin_id],
  390. ['in', 's.salesman_id', array_column($ids, 'id')]
  391. ]);
  392. } elseif ($area_level == 2){
  393. $query->andWhere([
  394. 'or',
  395. ['s.province_id' => $admin_model->province_id, 's.city_id' => $admin_model->city_id],
  396. ['s.admin_id' => $admin_id],
  397. ['in', 's.salesman_id', array_column($ids, 'id')]
  398. ]);
  399. } elseif ($area_level == 3){
  400. $query->andWhere([
  401. 'or',
  402. ['s.province_id' => $admin_model->province_id],
  403. ['s.admin_id' => $admin_id],
  404. ['in', 's.salesman_id', array_column($ids, 'id')]
  405. ]);
  406. } else {
  407. $query->andWhere([
  408. 'or',
  409. ['s.admin_id' => $admin_id],
  410. ['in', 's.salesman_id', array_column($ids, 'id')]
  411. ]);
  412. }
  413. }
  414. $store = $query->select('s.id, s.logo, s.name')->all();
  415. return [
  416. 'code' => 0,
  417. 'msg' => "获取成功",
  418. 'data' => $store
  419. ];
  420. } catch (\Exception $e) {
  421. return [
  422. 'code' => 1,
  423. 'msg' => $e->getMessage()
  424. ];
  425. }
  426. }
  427. public function add($name, $password = "", $username = "", $area = [], $saas_user_id = 0, $logo = "", $end_time = 0)
  428. {
  429. $t = \Yii::$app->db->beginTransaction();
  430. try {
  431. // 取消强制添加手机管理员功能
  432. // if (!$saas_user_id) {
  433. // throw new Exception('请选择管理员用户!');
  434. // }
  435. if (!$name) {
  436. throw new Exception('请输入商城名称!');
  437. }
  438. //判断后台开启通联
  439. // $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value'];
  440. // if ($oldConf) {
  441. // $oldConf = json_decode($oldConf, true);
  442. // if (!empty($oldConf) && !empty(trim($oldConf['appid']))) {
  443. // if (!$store_number) {
  444. // throw new Exception('请输入商城会员编号!');
  445. // }
  446. // $store_info = Store::find()->where(['is_delete' => 0, 'store_number' => $store_number])->one();
  447. // if ($store_info){
  448. // throw new Exception('会员编号已存在');
  449. // }
  450. //
  451. // //调用第三方会员创建接口
  452. // $memberService = new MemberService();
  453. // $res_member = $memberService->createMember($store_number,2);
  454. // debug_log($res_member);
  455. // if ($res_member['subCode'] == "FAIL"){
  456. // throw new Exception($res_member['subMsg']);
  457. // }
  458. // }
  459. // }
  460. //判断如果是区域代理就直接使用区域代理的省市区地址
  461. $area_admin = get_admin();
  462. if ($area_admin->type === Admin::ADMIN_TYPE_DEFAULT && $area_admin->username !== "admin") {
  463. $area['province_id'] = $area_admin->province_id;
  464. $area['city_id'] = $area_admin->city_id;
  465. $area['district_id'] = $area_admin->district_id;
  466. }
  467. // 判断是否已经存在
  468. $is = Admin::find()->where(['name' => $name, 'is_delete' => 0])->one();
  469. if ($is) {
  470. throw new Exception('商城名称已经存在!请更换');
  471. }
  472. if (empty($username)) {
  473. throw new Exception('请输入登陆账户');
  474. }
  475. $is = Admin::find()->where(['username' => $username, 'is_delete' => 0])->one();
  476. if ($is) {
  477. throw new Exception('账户名称已经存在!请更换');
  478. }
  479. $admin = new Admin();
  480. $admin->access_token = \Yii::$app->security->generateRandomString();
  481. $admin->username = $username;
  482. $admin->password = \Yii::$app->security->generatePasswordHash($password ?: '123456');
  483. $admin->name = $name;
  484. $admin->saas_user_id = $saas_user_id;
  485. $admin->type = 'store';
  486. if (isset($area['province_id']) && isset($area['city_id']) && isset($area['district_id'])) {
  487. $admin->province_id = $area['province_id'];
  488. $admin->city_id = $area['city_id'];
  489. $admin->district_id = $area['district_id'];
  490. }
  491. if (!$admin->save()) {
  492. throw new Exception('添加失败!' . array_shift($admin->getFirstErrors()));
  493. }
  494. $store = new Store();
  495. $store->logo = $logo;
  496. // $store->store_number = $store_number;
  497. // $store->yunst_user_id = $res_member['data']['userId'] ?? '';
  498. $store->name = $name;
  499. $store->open_status = 0;
  500. $store->admin_id = get_admin()->id ?? 0;
  501. $store->end_time = $end_time ?: strtotime("+1 year");
  502. if (isset($area['province_id']) && isset($area['city_id']) && isset($area['district_id'])) {
  503. $store->province_id = $area['province_id'];
  504. $store->city_id = $area['city_id'];
  505. $store->district_id = $area['district_id'];
  506. }
  507. if ($store->save()) {
  508. $this->initStorageConfig($store->id);
  509. $admin->type_id = $store->id;
  510. if (!$admin->save()) {
  511. throw new Exception('添加失败!' . array_shift($admin->getFirstErrors()));
  512. }
  513. // 设置商城名称
  514. Option::set('name', $name, $store->id, 'store');
  515. Option::set(OptionSetting::STORE_LOGO, $logo, $store->id, 'store');
  516. Option::set(OptionSetting::WECHAT_IS_SHENHE, '0', $store->id, 'wechat');
  517. Option::set(OptionSetting::WECHAT_ALI_IS_SHENHE, '0', $store->id, 'wechat');
  518. // 初始化DIY页面
  519. // 初始化diy模板
  520. $is = NewDiyTemplate::find()
  521. ->where([
  522. 'store_id' => $store->id,
  523. 'is_delete' => 0,
  524. 'type' => 100
  525. ])->asArray()->one();
  526. if (!$is) {
  527. $this->initDiyTemplate($store->id);
  528. $default = \app\models\Option::get('store_template_default', 0, 'saas', null)['value'];
  529. if($default){
  530. $default = json_decode($default, true);
  531. $default_store_id = $default['store_id'];
  532. }else{
  533. $default_store_id = Store::findOne(['is_delete' => 0])->id ?: 1;
  534. }
  535. try {
  536. $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $store->id]), 0, 1);
  537. debug_log($id, 'queuePush.log');
  538. // $res = \app\models\StoreCopy::doCopy($default_store_id, $store->id, $default['type']);
  539. } catch (\Exception $e) {
  540. debug_log(['message' => $e->getMessage(), 'line' => $e->getLine()], 'queuePush.log');
  541. }
  542. }
  543. //安装完成后装修表中的store_id比本商城的store_id还大 导致订单提交装修无法新增
  544. //解决一下这个问题
  545. $system_diy = NewDiyTemplate::find()
  546. ->where([
  547. 'store_id' => $store->id,
  548. 'is_delete' => 0,
  549. 'name' => 'system'
  550. ])->asArray()->all();
  551. $is_order_diy = false;
  552. foreach ($system_diy as $diy_item) {
  553. $template_detail = json_decode($diy_item['template'], true);
  554. if (isset($template_detail['system_type']) && $template_detail['system_type'] === 'orderPreview') {
  555. $is_order_diy = true;
  556. }
  557. }
  558. if (!$is_order_diy) {
  559. $submit = new NewDiyTemplate();
  560. $submit->store_id = $store->id;
  561. $submit->name = 'system';
  562. $submit->template = '{"page_name":"订单提交","is_index":"0","page_type":1,"system_type":"orderPreview","page_link":"","theme":{"color":"#292929","time":1711097460417},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"#fcfcfc","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"订单预览页面-头部","type":"","comName":"orderPreviewHeader","icon":"","controlComName":"","params":[]},{"name":"订单预览页面-发货方式选择","type":"","comName":"orderPreviewDelivery","icon":"","controlComName":"orderPreviewDeliveryControl","params":{"type":"2","diy_express_name":"快递","diy_delivery_name":"同城","diy_shop_name":"自提"},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":8}},{"name":"订单预览页面-订单主体信息","type":"","comName":"orderPreviewContent","icon":"","controlComName":"","params":[]}],"controlComName":"pageControl","id":"3395"}';
  563. $submit->addtime = time();
  564. $submit->type = 1;
  565. $submit->save();
  566. }
  567. if (\Yii::$app->prod_is_dandianpu()) {
  568. $saas_user = SaasUser::findOne(['id' => $saas_user_id, 'is_delete' => 0]);
  569. if ($saas_user) {
  570. // $saas_user->store_id = $store->id;
  571. // $saas_user->save();
  572. // 创建云仓账号
  573. $this->createStoreCloud($saas_user->mobile, $store, $saas_user);
  574. }
  575. }
  576. $t->commit();
  577. return [
  578. 'code' => 0,
  579. 'msg' => '添加成功!',
  580. 'store' => $store,
  581. ];
  582. } else {
  583. $t->rollBack();
  584. \Yii::error($store->getFirstErrors());
  585. debug_log([__METHOD__, __LINE__, $store->getFirstErrors()], __CLASS__ . '.log');
  586. return [
  587. 'code' => 1,
  588. 'msg' => '添加失败!' . array_shift($store->getFirstErrors()),
  589. ];
  590. }
  591. } catch (\Exception $e) {
  592. $t->rollBack();
  593. \Yii::error($e);
  594. debug_log([__METHOD__, __LINE__, $e->getMessage(), $e->getTrace()], __CLASS__ . '.log');
  595. return [
  596. 'code' => 1,
  597. 'msg' => $e->getMessage(),
  598. ];
  599. }
  600. }
  601. public function initStorageConfig($store_id)
  602. {
  603. $model = new UploadConfig();
  604. $model->store_id = $store_id;
  605. $model->storage_type = "local";
  606. $model->qiniu = json_encode(["bucket" => "","domain" => "","access_key" => "","secret_key" => "","style_api" => ""]);
  607. $model->qcloud = json_encode(["bucket" => "","region" => "","domain" => "","secret_id" => "","secret_key" => ""]);
  608. $model->aliyun = json_encode(["bucket" => "","CNAME" => "","domain" => "","access_key" => "","secret_key" => "","style_api" => ""]);
  609. $model->created_at = time();
  610. $model->save();
  611. $this->initStoreData($store_id);
  612. }
  613. public function initStoreFacePayProfit() {
  614. Option::set('face_first_profit', 0, get_store_id(), 'store');
  615. Option::set('face_second_profit', 0, get_store_id(), 'store');
  616. Option::set('face_third_profit', 0, get_store_id(), 'store');
  617. }
  618. public function initStoreLeague() {
  619. // Option::set('store_this_profit', 0, get_store_id(), 'store');
  620. Option::set('goods_send_profit', 0, get_store_id(), 'store');
  621. Option::set('goods_take_price', 0, get_store_id(), 'store');
  622. }
  623. public function initStoreData($store_id = 0) {
  624. $this->initStoreFacePayProfit();
  625. $this->initStoreLeague();
  626. debug_log('开始获取设置项');
  627. $setting = [];
  628. $settingDefault = OptionSetting::getOptionSetting();
  629. $i = 0;
  630. foreach ($settingDefault as $index => $item) {
  631. foreach ($item['list'] as &$value) {
  632. $value['group'] = $index;
  633. $value['value'] = $value['default'];
  634. if ($index === 'store') {
  635. $store_id = $store_id ?: get_store_id();
  636. $store = Store::findOne($store_id);
  637. $admin = Admin::findOne(['type_id' => $store_id, 'is_delete' => 0]);
  638. if ($value['name'] === 'name') {
  639. $value['value'] = $store->name;
  640. }
  641. if ($value['name'] === 'contact_tel') {
  642. $value['value'] = $admin->mobile;
  643. }
  644. }
  645. }
  646. $setting[$i] = $item;
  647. $setting[$i]['key'] = $index;
  648. $i++;
  649. }
  650. foreach ($setting as $k => $v) {
  651. $setting[] = [
  652. 'name' => $v['name'],
  653. 'key' => $k,
  654. 'list' => Option::getGroup($k)
  655. ];
  656. }
  657. $form = new SettingForm();
  658. $form->data = $setting;
  659. $res = $form->save($store_id);
  660. }
  661. // 初始化diy页面
  662. public function initDiyTemplate($store_id)
  663. {
  664. // 个人中心
  665. $user = new NewDiyTemplate();
  666. $user->store_id = $store_id;
  667. $user->name = 'system';
  668. $user->template = '{"page_name":"我的","is_index":"0","page_type":1,"page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"#f2f2f2","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"头部导航","type":"pageHeader","comName":"pageHeader","controlComName":"pageHeaderControl","moduleCss":{"backgroundColor":"","backgroundImage":"url(https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-23/8212b4f5b2eebc593e503ada46a1336452129b0b.png)","bgImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-23/8212b4f5b2eebc593e503ada46a1336452129b0b.png","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"params":{"text":"页面标题","showText":0,"capsuleType":"2","css":{"color":"#000000","fontNum":"18","fontSize":"","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit","textAlign":"center"}}},{"name":"我的页面-会员模块","type":"","comName":"userMember","icon":"","controlComName":"userMemberControl","moduleCss":{"backgroundColor":"","backgroundImage":"url(https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-23/2e97892d4896b8cdbc17097521b6d763d0e3d8d8.png)","bgImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-23/2e97892d4896b8cdbc17097521b6d763d0e3d8d8.png","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":0,"borderRadius":0},"params":{"styleType":"1","fontColor":"#FFFFFF","memberAdImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-23/fe6cbd7ea663aa37e2ff49a19704016d74649362.png","showModule":true,"beforeBuyText":"开通Super会员,领7张20元无门槛津贴","afterBuyText":"","memberCardCss":{"backgroundColor":"#303478","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","padding":10,"borderRadius":10},"memberCardLink":{},"memberTabGroup":[{"title":"会员专享","subtitle":"好物折扣价","link":{},"picImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/5ea9e3e86ac57f16f40f178bab3e7a1975833997.png","titleColor":"#262626","subtitleColor":"#B4853F","controlComName":"userMemberTabItemControl"},{"title":"Super会员","subtitle":"额外返优惠","link":{},"picImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/5dbcb1077bb59db13386f9b547da98ea0a59c4ce.png","titleColor":"#262626","subtitleColor":"#B4853F","controlComName":"userMemberTabItemControl"},{"title":"送2年Super","subtitle":"领200元支付券","link":{},"picImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/0664e1c403a5e8cbf39661f420b25f32c1cfe00a.png","titleColor":"#262626","subtitleColor":"#B4853F","controlComName":"userMemberTabItemControl"}],"memberTabNum":3,"memberTabCss":{"backgroundColor":"#FDEDCF","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","padding":9,"borderRadius":10}}},{"name":"我的页面-我的订单","type":"","comName":"userOrder","icon":"","controlComName":"userOrderControl","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":10,"borderRadius":10},"params":{"moduleName":"我的订单","showText":1,"moduleNameCss":{"color":"#262626","fontNum":"14","fontSize":"14px","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit"},"moduleMoreCss":{"color":"#888888","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"},"fontColor":"#414141","tabsList":[{"tabImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/8e6630802514bea7480079a7b5bd5490b65307c9.png","tabText":"待付款","link":{},"controlComName":"userOrderTabItemControl"},{"tabImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/2305cab5806a042a2768d22e8f0720b7df36db90.png","tabText":"待发货","link":{},"controlComName":"userOrderTabItemControl"},{"tabImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/a1d3f824ff9c4311bb5c41ea47816bbb6b648dac.png","tabText":"待收货","link":{},"controlComName":"userOrderTabItemControl"},{"tabImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/a0eee0c78a4040b04343466635d17cd0f62505fa.png","tabText":"已完成","link":{},"controlComName":"userOrderTabItemControl"},{"tabImg":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-25/ad8aaca1a0214adca4a238770e87a5a5575579f6.png","tabText":"退换售后","link":{},"controlComName":"userOrderTabItemControl"}]}},{"name":"我的钱包","type":"","comName":"userWallet","icon":"","controlComName":"userWalletControl","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":10,"borderRadius":10},"params":{"showModule":true,"text":"我的钱包","useTitle":1,"showStyle":"1","moduleNameCss":{"color":"#262626","fontNum":"14","fontSize":"14px","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit"},"moduleMoreCss":{"color":"#888888","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"},"list":[{"name":"积分","subName":"","controlComName":"walletItemControl","walletItemType":"walletIntegral","color":"#262626","subColor":"#bbbbbb"},{"name":"余额","subName":"","controlComName":"walletItemControl", "walletItemType": "walletBalance", "color":"#262626","subColor":"#bbbbbb"},{"name":"联盟券","subName":"","controlComName":"walletItemControl", "walletItemType": "walletLeaguePrice","color":"#262626","subColor":"#bbbbbb"}]},"showModule":true},{"name":"工具与服务","type":"","comName":"userTools","icon":"","controlComName":"userToolsControl","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":10,"borderRadius":10},"params":{"showModule":true,"text":"工具与服务","useTitle":1,"showStyle":"1","list":[{"name":"自提点","link":{"name":"自提点后台","link":"/pages/shop/admin","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/8104ce1b57b2c54c98a7e045a95c465a8610c221.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"当面付","link":{"name":"当面付","link":"/face-pay/face-pay/payOut","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/94053d9ae7dc802a88a054567652b7c5a29d305d.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"充值","link":{"name":"充值","link":"/user/balance/recharge","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/47ee3226d562aa1da8cc5b46afbc5cf8b45485c2.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"客服","link":{"name":"客服","link":"contact","open_type":"contact","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/e2593e3e56a08818de608735b73588333d7edca6.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"分销中心","link":{"name":"分销中心","link":"/user/share/index","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/36dc2b4da21efa42ae420ed30bd9414ddbd493c3.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"福利中心","link":{"name":"福利中心","link":"/integral/integral/integral","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/e6aaa9b4b32ad3ec56b71892ab833e38eff53660.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"会员中心","link":{"name":"会员中心","link":"/user/member/member_center","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/adc5a6987dfb4d1adfb0f4b649d8facc758b6ff8.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"地址管理","link":{"name":"地址管理","link":"/user/my/addressmanage","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/705eee495b92cad924fc9c531a0795e9aaf73d5c.png","controlComName":"userToolControl","css":{"color":"#242427","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"关于我们","link":{"name":"关于我们","link":"/user/my/article-detail","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/fdcfc884fa56cb8ff83baa0cec127320688c84ab.png","controlComName":"userToolControl","css":{"color":"#000000","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"我的优惠券","link":{"name":"我的优惠券","link":"/user/my_coupon/my_coupon","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/e24914f07391982282adb5ca25b8f5b3a14bf2ad.png","controlComName":"userToolControl","css":{"color":"#000000","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"我的核销卡","link":{"name":"我的核销卡","link":"/user/write_off_card/write_off_card","open_type":"navigate","params":[]},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-03/9b4e332a77d0eef15c24e8e09f3125a693db6d8a.png","controlComName":"userToolControl","css":{"color":"#000000","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}}]},"showModule":true}],"controlComName":"pageControl","id":"","system_type":"my"}';
  669. $user->addtime = time();
  670. $user->type = 1;
  671. $user->save();
  672. // 购物车
  673. $cart = new NewDiyTemplate();
  674. $cart->store_id = $store_id;
  675. $cart->name = 'system';
  676. $cart->template = '{"page_name":"购物车","is_index":"0","page_type":1,"system_type":"cart","page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"购物车","type":"","comName":"shoppingCart","icon":"","controlComName":"shoppingCartControl","moduleCss":{},"params":{}}],"controlComName":"pageControl","id":""}';
  677. $cart->addtime = time();
  678. $cart->type = 1;
  679. $cart->save();
  680. // 商品详情
  681. $goods = new NewDiyTemplate();
  682. $goods->store_id = $store_id;
  683. $goods->name = 'system';
  684. $goods->template = '{"page_name":"商品详情","is_index":"0","page_type":1,"system_type":"goodsDetail","page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"商品详情页面-头部商品轮播图","type":"","comName":"goodsSwiperImgs","icon":"","controlComName":"","params":{}},{"name":"商品详情页面-商品介绍","type":"","comName":"goodsIntroduce","icon":"","controlComName":"goodsIntroduceControl","params":{"showMemberPrice":true,"showOriginPrice":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品优惠活动","type":"","comName":"goodsDiscount","icon":"","controlComName":"goodsDiscountControl","params":{"showGoodsDiscount":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品sku属性选择","type":"","comName":"goodsAttribute","icon":"","controlComName":"goodsAttributeControl","params":{"showAddress":true,"showNearbyShop":true,"showFreight":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品评价","type":"","comName":"goodsEvaluate","icon":"","controlComName":"goodsEvaluateControl","params":{"showEvaluate":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品评价","type":"","comName":"goodsShopEntry","icon":"","controlComName":"goodsShopEntryControl","params":{"showGoodsShopEntry":false},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-底部导航","type":"","comName":"goodsFootNav","icon":"","controlComName":"goodsFootNavControl","params":{"styleType":"1","tabList":[{"text":"首页","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/857370f6a7a788ff0674b4255dabc91974b402a0.png","link":{"name":"首页","link":"/pages/home/home","open_type":"switchtab","params":[]},"fontColor":"#262626","controlComName":"goodsFootNavItemControl"},{"text":"客服","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/aa7a96931ae57b070af3bd38f9553a40b7d9bd4f.png","link":{"name":"客服","link":"contact","open_type":"contact","params":[]},"fontColor":"#262626","controlComName":"goodsFootNavItemControl"},{"text":"购物车","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/5d156040e27daf1da32d3a4241355684f4708f7e.png","link":{"name":"购物车","link":"/pages/shoppingcart/shoppingcart","open_type":"switchtab","params":[],"id":"1313"},"fontColor":"#262626","controlComName":"goodsFootNavItemControl"}],"buyBtn":{"text":"立即购买","color":"#FFFFFF","bgColor":"#FBBA10"},"cartBtn":{"text":"加入购物车","color":"#FFFFFF","bgColor":"#F0250E"}},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","borderRadius":0}}],"controlComName":"pageControl","id":""}';
  685. $goods->addtime = time();
  686. $goods->type = 1;
  687. $goods->save();
  688. //分类
  689. $cat = new NewDiyTemplate();
  690. $cat->store_id = $store_id;
  691. $cat->name = 'system';
  692. $cat->template = '{"page_name":"分类","is_index":"0","page_type":1,"system_type":"classify","page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"分类页面-头部导航","type":"","comName":"classifyHeader","icon":"","controlComName":"","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"params":{}},{"name":"分类页面-分类左侧列表","type":"","comName":"classifyContent","icon":"","controlComName":"classifyContentControl","params":{"levelNum":"2","styleType":3,"goodsShowType":"1","showModule":true,"abConfig":{"isShow":true,"imgSrc":"","link":{}}}}],"controlComName":"pageControl","id":""}';
  693. $cat->addtime = time();
  694. $cat->type = 1;
  695. $cat->save();
  696. //展示商品详情
  697. $cat = new NewDiyTemplate();
  698. $cat->store_id = $store_id;
  699. $cat->name = 'system';
  700. $cat->template = '{"page_name":"展示商品详情","is_index":"0","page_type":1,"system_type":"showGoodsDetail","page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"展示商品详情页面-头部商品轮播图","type":"","comName":"showGodsSwiperImgs","icon":"","controlComName":"showGoodsSwiperImgsControl","params":{"margin":0,"showFenxiao":true,"show":true}},{"name":"商品信息","type":"","comName":"showGodsInfo","icon":"","controlComName":"showGodsInfoControl","params":{"showPrice":true,"showOriginPrice":true,"showSales":true,"showGoodsName":true,"showCollect":true,"showShare":true,"margin":0}},{"name":"商品内容","type":"","comName":"showGoodsContent","icon":"","controlComName":"showGoodsContentControl","params":{"title":"详情","showTitle":true,"showContent":true,"margin":0}},{"name":"商品详情页面-底部导航","type":"","comName":"showGoodsFootNav","icon":"","controlComName":"showGoodsFootNavControl","params":{"showBtn":true,"styleType":"1","btnText":"进入抖音号","btnColor":"#F0250E","link":{"link":"","name":"","open_type":""}}}],"controlComName":"pageControl","id":""}';
  701. $cat->addtime = time();
  702. $cat->type = 1;
  703. $cat->save();
  704. // 首页
  705. $index = new NewDiyTemplate();
  706. $index->store_id = $store_id;
  707. $index->name = 'DIY';
  708. $index->template = '{"page_name":"首页","is_index":"1","page_type":0,"page_link":"","theme":{"color":"#FCBE40","time":1633765304209},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"#f2f2f2","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"头部导航","type":"pageHeader","comName":"pageHeader","controlComName":"pageHeaderControl","moduleCss":{"backgroundColor":"","backgroundImage":"url(https://chidian.cyyvip.com/web/uploads/images/store_84/2021-12-29/d3e747e32a87e8903f6a8acf7d452d5b4e948941.png)","bgImg":"https://chidian.cyyvip.com/web/uploads/images/store_84/2021-12-29/d3e747e32a87e8903f6a8acf7d452d5b4e948941.png","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"params":{"text":"赤店商城","showText":1,"capsuleType":"1","css":{"color":"#ffffff","fontNum":"16","fontSize":"16px","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit","textAlign":"center"},"styleType":"2","mdStyle":"1"}},{"name":"搜索框","type":"search","comName":"diySearch","controlComName":"diySearchControl","icon":"icon-sousuokuang","moduleCss":{"backgroundColor":"","backgroundImage":"url(https://chidian.cyyvip.com/web/uploads/images/store_84/2021-12-29/35708c731c112046320b2b55b69361289b3334f9.png)","bgImg":"https://chidian.cyyvip.com/web/uploads/images/store_84/2021-12-29/35708c731c112046320b2b55b69361289b3334f9.png","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":0},"params":{"placeholder":"请输入商品或店铺","fixedTop":0,"borderType":"1","styleType":"1","contentAlign":"","inputBgColor":"#ffffff","inputBorder":"#ffffff","inputTextColor":"#9B9B9B","searchBtnColor":"#FA2C1B","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit","textAlign":"inherit"}}},{"name":"门店信息","type":"shopInfoData","comName":"shopInfoData","controlComName":"shopInfoDataControl","icon":"icon-jiudian","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":0},"params":{"mainColor":"#191919","subColor":"#8C8C8C"}},{"name":"产品分类","type":"productClassify","comName":"productClassify","icon":"icon-chanpinfenlei","controlComName":"productClassifyControl","moduleCss":{"backgroundColor":"#FFFFFF","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":0},"params":{"type":"2","styleType":"2","tabStyle":"1","leftTabBg":"#ffffff","classifyList":[],"activeLineColor":"#FA2C1B","defaultTab":{"fontCss":{"color":"#262626","fontNum":"15","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"},"activeColor":"#FA2C1B","activeStyle":"1"},"subtitleTab":{"color":"#FA2C1B","titleColor":"#FA2C1B","subTitleColor":"#ffffff","activeColor":"#FA2C1B","activeStyle":"1","defaultTitleColor":"#000000","defaultSubTitleColor":"#888888"},"showPrice":true,"showSales":true,"showBuyBtn":true,"producNameColor":"#1D1D1D","priceColor":"#FA2C1B","originPriceColor":"#9B9B9B","saleColor":"#9B9B9B","buyStyle":"add","buyBtnText":"购买","buyBtnImg":"","goodsType":"2","goodsItemOutSpace":0,"goodsItemInnerSpace":3,"goodsBgCss":{"backgroundColor":"#FFFFFF","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":1,"padding":0,"borderRadius":0}}}],"controlComName":"pageControl","id":""}';
  709. //$index->template = '{"page_name":"首页","is_index":"1","page_type":0,"page_link":"","theme":{"color":"#FCBE40","time":1633765304209},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"#eb0000","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"头部导航","type":"pageHeader","comName":"pageHeader","controlComName":"pageHeaderControl","moduleCss":{"backgroundColor":"#f82b1c","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"params":{"text":"赤店商城","showText":1,"capsuleType":"2","css":{"color":"#ffffff","fontNum":"18","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit","textAlign":"center"}}},{"name":"搜索框","type":"search","comName":"diySearch","controlComName":"diySearchControl","icon":"icon-sousuokuang","moduleCss":{"backgroundColor":"#f82b1c","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":0},"params":{"placeholder":"请输入商品或店铺","fixedTop":0,"borderType":"1","styleType":"1","contentAlign":"","inputBgColor":"#ffffff","inputBorder":"#ffffff","inputTextColor":"#9B9B9B","searchBtnColor":"#FA2C1B","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit","textAlign":"inherit"}}},{"name":"快捷导航","type":"fastNav","comName":"fastNav","controlComName":"fastNavControl","icon":"icon-kuaijiedaohang","moduleCss":{"backgroundColor":"#fa2c1b","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":5,"padding":0,"borderRadius":0},"params":{"text":"","css":{"color":"#ffffff","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"},"list":[{"text":"首页","link":{}},{"text":"电脑办公","link":{}},{"text":"大家电","link":{}},{"text":"男装","link":{}},{"text":"精品服饰","link":{}},{"text":"潮流包包","link":{}},{"text":"选项卡","link":{}}],"choosedStyle":{"controlComName":"fastNavCurrentControl","style":1,"css":{"color":"#ffffff","fontNum":"16","fontSize":"16px","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit","textAlign":"inherit"},"lineColor":"#ffffff","backgroundColor":"#c2b3b3"}}},{"name":"图片轮播","type":"banner","comName":"swiperImg","icon":"icon-tupianlunbo","controlComName":"swiperImgControl","moduleCss":{"backgroundColor":"#eb2300","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":0},"params":{"bannerList":[{"picUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/518bae500b54c86d38bcbdf123c2eb349bb3473d.jpeg","link":{}},{"picUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/2c704ab8584b045d3b2f5669e48f05373adb8a11.jpeg","link":{}}],"dotsPosition":"center","swiperType":"1"}},{"name":"魔方导航","type":"cubeNav","comName":"cubeNav","controlComName":"cubeNavControl","icon":"icon-mofangdaohang","params":{"columnNumber":"5","numberOfLines":"2","drain":"1","list":[{"name":"附近超市","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/dc27bfbd99e325625995c9f51abdbc51fe7e567a.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"数码电器","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/0512ae6ea7dd643d1e75354788f70feafb50ceb1.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"精选服饰","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/e510beed1bc1c004c6d918ed88735e367ec89b69.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"赤店生鲜","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/5f0a0b1aee4f26564d49d592fd15d4a121898e2f.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"好货到家","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/d148a57be780032fe34db4b1aa476d53733c598d.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"充值缴费","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/5eec9739affa05772bb13e9a9378a9c059fcce47.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"物流查询","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/c6ddd1298ea7f79490821feb6ce966137549a87e.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"领券","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/78149329d99b07edc79e8606d2cb56d0f0b3e22f.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"领福利","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/182f539eede0375db0ecbfc0693f20359bb240b9.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"PLUS会员","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/5c1d68c542e21ea3983d24eaa6347e0f1e26658a.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"进口好货","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/1441bc6d25c2c2519c4255864823386b8649ec8e.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"拍卖众筹","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/3a9fa5bb74c9bd0ed0a181b45cbc010392167050.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"看病购药","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/f1d1cef5b629251a1f68aea34cbc56dc363cec9f.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"玩3C","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/fef0351ce4c18e0cecbf498f7fbcf8d8acbd7c0c.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"沃尔玛","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/bf3fa385564a110407c5a8a0406dda6819b34b37.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"美妆馆","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/31966f5b658ca4cd560727141b8efecb9c775eec.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"旅行","link":{},"iconUrl":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-08/29a3dac01190ac0d3b45e76ac8720a73f0e49837.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"二手好货","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/fa610cbc05534fb51fa52f7ba1be89ed2c9a4330.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"9.9元拼","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/33b028eb11eae036236449a6186f769ff2b4b4c3.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}},{"name":"全部","link":{},"iconUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/da56b1c2f037621494f8f9532a2198e3290105c0.png","controlComName":"cubeItemControl","css":{"color":"#ffffff","fontNum":"12","fontSize":"12px","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}}]},"moduleCss":{"backgroundColor":"#eb2300","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":0}},{"name":"首页推荐","type":"indexRecommend","comName":"indexRecommend","controlComName":"indexRecommendControl","icon":"icon-shouyetuijian","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":10,"borderRadius":10},"params":{"line":1,"text":"首页推荐","useTitle":2,"list":[{"title":{"controlComName":"indexRecommendTitleControl","useTitle":1,"text":"天天低价","css":{"color":"#000000","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit","textAlign":"inherit"}},"subTitle":{"controlComName":"indexRecommendSubtitleControl","useTitle":1,"text":"人气好货限时抢","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"type":{"controlComName":"indexRecommendTypeControl","style":1,"startTime":"2021-10-08 15:28:36","endTime":"2021-10-16 15:28:36","picUrl":""},"pics":{"controlComName":"indexRecommendPicsControl","link":{},"urls":[{"picUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-04-29/27415a2cf5de636ac2dcaea2c52d3cab42d80b2a.png"},{"picUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-04-29/f76a7194e8f9e1f53432b739d1fce8861f45a7cc.png"}]}},{"title":{"controlComName":"indexRecommendTitleControl","useTitle":1,"text":"天天低价","css":{"color":"#000000","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit","textAlign":"inherit"}},"subTitle":{"controlComName":"indexRecommendSubtitleControl","useTitle":2,"text":"人气好货限时抢","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"type":{"controlComName":"indexRecommendTypeControl","style":1,"startTime":"","endTime":"","picUrl":""},"pics":{"controlComName":"indexRecommendPicsControl","link":{},"urls":[{"picUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-04-29/11be51b1bc735a7fd2af0d0aa19cd426c7a29f04.png"},{"picUrl":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-04-29/579a2232b29cdbb1e4ec82ca5d465026b25a5168.png"}]}},{"title":{"controlComName":"indexRecommendTitleControl","useTitle":1,"text":"天天低价","css":{"color":"#000000","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"subTitle":{"controlComName":"indexRecommendSubtitleControl","useTitle":1,"text":"人气好货限时抢","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"type":{"controlComName":"indexRecommendTypeControl","style":1,"startTime":"","endTime":"","picUrl":""},"pics":{"controlComName":"indexRecommendPicsControl","link":{},"urls":[]}},{"title":{"controlComName":"indexRecommendTitleControl","useTitle":1,"text":"天天低价","css":{"color":"#000000","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"subTitle":{"controlComName":"indexRecommendSubtitleControl","useTitle":1,"text":"人气好货限时抢","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"type":{"controlComName":"indexRecommendTypeControl","style":1,"startTime":"","endTime":"","picUrl":""},"pics":{"controlComName":"indexRecommendPicsControl","link":{},"urls":[]}},{"title":{"controlComName":"indexRecommendTitleControl","useTitle":1,"text":"天天低价","css":{"color":"#000000","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"subTitle":{"controlComName":"indexRecommendSubtitleControl","useTitle":1,"text":"人气好货限时抢","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"type":{"controlComName":"indexRecommendTypeControl","style":1,"startTime":"","endTime":"","picUrl":""},"pics":{"controlComName":"indexRecommendPicsControl","link":{},"urls":[]}},{"title":{"controlComName":"indexRecommendTitleControl","useTitle":1,"text":"天天低价","css":{"color":"#000000","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"subTitle":{"controlComName":"indexRecommendSubtitleControl","useTitle":1,"text":"人气好货限时抢","css":{"color":"#000000","fontNum":"14","fontSize":"","fontStyle":"normal","fontWeight":"noraml","textDecoration":"inherit","textAlign":"inherit"}},"type":{"controlComName":"indexRecommendTypeControl","style":1,"startTime":"","endTime":"","picUrl":""},"pics":{"controlComName":"indexRecommendPicsControl","link":{},"urls":[]}}],"moduleNameCss":{"color":"#262626","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"bold","textDecoration":"inherit"},"moduleMoreCss":{"color":"#888888","fontNum":"12","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit"}}},{"name":"公告","type":"notice","comName":"diyNotice","controlComName":"diyNoticeControl","icon":"icon-gonggao","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":10,"borderRadius":10},"params":{"styleType":"2","noticeText":"新商城上线啦!欢迎您!!!!","noticeImg":""}},{"name":"倒计时","type":"marketCountDown","comName":"marketCountDown","icon":"icon-daojishi","controlComName":"marketCountDownControl","moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":10,"padding":10,"borderRadius":8},"params":{"styleType":"1","countDownImg":"http://tianxin100we10.cyyvip.com/web/uploads/images/store_1/2021-09-16/518bae500b54c86d38bcbdf123c2eb349bb3473d.jpeg","justifyContent":"flex-start","startTime":"2021-10-09 13:51:21","endTime":"2021-10-30 13:51:26","link":{},"countDownBgColor":"#FA2C1B","countDownFontColor":"#FFFFFF","css":{"color":"#e21818","fontNum":"16","fontSize":"","fontStyle":"normal","fontWeight":"normal","textDecoration":"inherit","textAlign":"inherit"}}}],"controlComName":"pageControl","id":""}';
  710. $index->addtime = time();
  711. $index->is_index = 1;
  712. $index->type = 1;
  713. $index->save();
  714. //控件
  715. $control = new NewDiyTemplate();
  716. $control->store_id = $store_id;
  717. $control->name = 'controls';
  718. $control->template = '[{"name":"导航","is_show":true,"controlComName":"widgetNavControl","show_type":"nav","params":{"defaultColor":"#2e2d2d","activeColor":"#FCBE40","navList":[{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/a94065d9bc45172db3df618616fa174e6908ad97.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0e337d2c6c92e2bbac7b0e57dc022af250bd574e.png","nav_text":"首页","link":{"name":"首页","link":"/pages/home/home","open_type":"switchtab","params":[]}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_257/2022-09-07/2e6400f46f235fa20731d8a18863330a550a1ef3.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_257/2022-09-07/f417d3de37a1cba65a9290960900c96345670f1f.png","nav_text":"分类","link":{"name":"分类","link":"/pages/cat/cat?cat_id=","open_type":"switchtab","params":[{"key":"cat_id","value":"","desc":"cat_id请填写在商品分类中相关分类的ID"}],"id":""}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/c63e855f172c75d3a3533e6b706be245e81048c6.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/39dda53d348bc336e6f7a6a9da0fc34d341fe5df.png","nav_text":"购物车","link":{"name":"购物车","link":"/pages/shoppingcart/shoppingcart","open_type":"switchtab","params":[]}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0f7048ecd1c7d0d30278ca9665beca219ff3e778.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/865006703b674a416be49169c691333ae210d055.png","nav_text":"我的","link":{"name":"用户中心","link":"/pages/my/my","id":375,"open_type":"switchtab","params":[]}}]},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"}},{"name":"弹窗","is_show":false,"show_type":"window","controlComName":"widgetPopupControl","params":{"list":[],"rule":1}},{"name":"电话","is_show":true,"show_type":"list","controlComName":"widgetPhoneControl","params":{"phone":"","picUrl":""}},{"name":"微信客服","is_show":true,"show_type":"list","controlComName":"widgetWxControl","params":{"picUrl":""}}]';
  719. $control->addtime = time();
  720. $control->type = 100;
  721. $control->save();
  722. // 订单提交
  723. $submit = new NewDiyTemplate();
  724. $submit->store_id = $store_id;
  725. $submit->name = 'system';
  726. $submit->template = '{"page_name":"订单提交","is_index":"0","page_type":1,"system_type":"orderPreview","page_link":"","theme":{"color":"#292929","time":1711097460417},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"#fcfcfc","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"订单预览页面-头部","type":"","comName":"orderPreviewHeader","icon":"","controlComName":"","params":[]},{"name":"订单预览页面-发货方式选择","type":"","comName":"orderPreviewDelivery","icon":"","controlComName":"orderPreviewDeliveryControl","params":{"type":"2","diy_express_name":"快递","diy_delivery_name":"同城","diy_shop_name":"自提"},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":8}},{"name":"订单预览页面-订单主体信息","type":"","comName":"orderPreviewContent","icon":"","controlComName":"","params":[]}],"controlComName":"pageControl","id":"3395"}';
  727. $submit->addtime = time();
  728. $submit->type = 1;
  729. $submit->save();
  730. $this->initDiyTemplateType($store_id, self::diyTemplateTypeList());
  731. }
  732. // 初始化diy页面
  733. public static function diyTemplateTypeList()
  734. {
  735. return [
  736. 'showGoodsDetail',
  737. ];
  738. }
  739. // 初始化diy页面
  740. public function initDiyTemplateType($store_id, $type = [])
  741. {
  742. $t = \Yii::$app->db->beginTransaction();
  743. try {
  744. if(!array_intersect($type, self::diyTemplateTypeList())){
  745. \Yii::error([__METHOD__, __LINE__, $type]);
  746. throw new \Exception('type参数错误!');
  747. }
  748. $hasList = [];
  749. $list = NewDiyTemplate::find()
  750. ->where([
  751. 'store_id' => $store_id,
  752. 'is_delete' => 0,
  753. 'name' => 'system'
  754. ])->orderBy(['id' => SORT_ASC])->asArray()->all();
  755. foreach ($list as &$item) {
  756. if ($item['template']) {
  757. $template = json_decode($item['template'], true);
  758. $system_type = $template['system_type'];
  759. $hasList[] = $system_type;
  760. }
  761. }
  762. $type = array_diff($type, $hasList);
  763. // 展示商品详情
  764. if(in_array('showGoodsDetail', $type)){
  765. $model = new NewDiyTemplate();
  766. $model->store_id = $store_id;
  767. $model->name = 'system';
  768. $model->template = '{"page_name":"展示商品详情","is_index":"0","page_type":1,"system_type":"showGoodsDetail","page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"展示商品详情页面-头部商品轮播图","type":"","comName":"showGodsSwiperImgs","icon":"","controlComName":"showGoodsSwiperImgsControl","params":{"margin":0,"showFenxiao":true,"show":true}},{"name":"商品信息","type":"","comName":"showGodsInfo","icon":"","controlComName":"showGodsInfoControl","params":{"showPrice":true,"showOriginPrice":true,"showSales":true,"showGoodsName":true,"showCollect":true,"showShare":true,"margin":0}},{"name":"商品内容","type":"","comName":"showGoodsContent","icon":"","controlComName":"showGoodsContentControl","params":{"title":"详情","showTitle":true,"showContent":true,"margin":0}},{"name":"商品详情页面-底部导航","type":"","comName":"showGoodsFootNav","icon":"","controlComName":"showGoodsFootNavControl","params":{"showBtn":true,"styleType":"1","btnText":"进入抖音号","btnColor":"#F0250E","link":{"link":"","name":"","open_type":""}}}],"controlComName":"pageControl","id":""}';
  769. $model->addtime = time();
  770. $model->type = 1;
  771. $model->save();
  772. }
  773. $t->commit();
  774. return [
  775. 'code' => 0,
  776. 'msg' => '操作成功!',
  777. 'type' => $type,
  778. ];
  779. } catch (\Exception $e) {
  780. $t->rollBack();
  781. return [
  782. 'code' => 1,
  783. 'msg' => '操作失败!' . $e->getMessage(),
  784. ];
  785. }
  786. }
  787. public function delete($store_id)
  788. {
  789. $t = \Yii::$app->db->beginTransaction();
  790. try {
  791. if (!$store_id) {
  792. throw new \Exception('store_id不能为空!');
  793. }
  794. $store = Store::findOne($store_id);
  795. if (!$store) {
  796. throw new \Exception('未找到商城!');
  797. }
  798. $store->is_delete = 1;
  799. $admin = Admin::findOne(['is_delete' => 0, 'type' => 'store', 'type_id' => $store_id]);
  800. if ($admin) {
  801. Admin::updateAll(['is_delete' => 1], ['is_delete' => 0, 'type' => 'store', 'type_id' => $store_id]);
  802. $saas_user_id = $admin->saas_user_id;
  803. if($saas_user_id){
  804. StoreAudit::deleteAll(['saas_user_id' => $saas_user_id]);
  805. }
  806. }
  807. if (!$store->save()) {
  808. throw new \Exception('操作失败!' . json_encode($store->errors));
  809. }
  810. $t->commit();
  811. return [
  812. 'code' => 0,
  813. 'msg' => '删除成功!',
  814. ];
  815. } catch (\Exception $e) {
  816. return [
  817. 'code' => 1,
  818. 'msg' => $e->getMessage(),
  819. ];
  820. }
  821. }
  822. /**
  823. * 设置分销
  824. *
  825. * @param int $store_id
  826. * @param array $params
  827. * @return array
  828. */
  829. public function setShareParams($store_id, $params)
  830. {
  831. //默认配置
  832. if(intval($store_id) === -1){
  833. $params['level_one'] = number_format($params['level_one'], 2);
  834. $params['level_two'] = number_format($params['level_two'], 2);
  835. $params['level_three'] = number_format($params['level_three'], 2);
  836. $json = json_encode($params);
  837. $res = Option::set(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME);
  838. if(!$res){
  839. return [
  840. 'code' => 1,
  841. 'msg' => '默认配置编辑失败',
  842. ];
  843. }
  844. return [
  845. 'code' => 0,
  846. 'msg' => '默认配置编辑成功',
  847. ];
  848. }
  849. if (!$store_id) {
  850. return [
  851. 'code' => 1,
  852. 'msg' => 'store_id不能为空!',
  853. ];
  854. }
  855. $store = Store::findOne($store_id);
  856. if (!$store) {
  857. return [
  858. 'code' => 1,
  859. 'msg' => '未找到商城!',
  860. ];
  861. }
  862. $params['level_one'] = number_format($params['level_one'], 2);
  863. $params['level_two'] = number_format($params['level_two'], 2);
  864. $params['level_three'] = number_format($params['level_three'], 2);
  865. $store->share_setting = json_encode($params);
  866. if (!union_share_scale_check($store)) {
  867. return [
  868. 'code' => 1,
  869. 'msg' => '保存失败,分销比例超过100%',
  870. ];
  871. }
  872. if ($store->save()) {
  873. return [
  874. 'code' => 0,
  875. 'msg' => '保存成功!',
  876. ];
  877. }
  878. return [
  879. 'code' => 1,
  880. 'msg' => '保存失败!',
  881. ];
  882. }
  883. /**
  884. * 获取分销参数
  885. *
  886. * @param int $store_id
  887. * @return array
  888. */
  889. public function getShareParams($store_id)
  890. {
  891. if (!$store_id) {
  892. return [
  893. 'code' => 1,
  894. 'msg' => 'store_id不能为空!',
  895. ];
  896. }
  897. $store = Store::findOne($store_id);
  898. if (!$store) {
  899. return [
  900. 'code' => 1,
  901. 'msg' => '未找到商城!',
  902. ];
  903. }
  904. if (empty($store->share_setting)) {
  905. return [
  906. 'code' => 0,
  907. 'msg' => 'success',
  908. 'data' => [
  909. 'level' => 0,
  910. 'is_rebate' => 0,
  911. 'price_type' => 0,
  912. 'level_one' => 0,
  913. 'level_two' => 0,
  914. 'level_three' => 0
  915. ],
  916. ];
  917. }
  918. return [
  919. 'code' => 0,
  920. 'msg' => 'success',
  921. 'data' => json_decode($store->share_setting, true),
  922. ];
  923. }
  924. /**
  925. * 设置推荐人参数
  926. *
  927. * @param int $store_id
  928. * @param array $params
  929. * @return array
  930. */
  931. public function setReferralParams($store_id, $params)
  932. {
  933. if (!$store_id) {
  934. return [
  935. 'code' => 1,
  936. 'msg' => 'store_id不能为空!',
  937. ];
  938. }
  939. $store = Store::findOne($store_id);
  940. if (!$store) {
  941. return [
  942. 'code' => 1,
  943. 'msg' => '未找到商城!',
  944. ];
  945. }
  946. try {
  947. // 先删除,再添加
  948. SaasStoreReferral::deleteAll(['store_id' => $store_id]);
  949. foreach ($params as $key => $value) {
  950. $obj = new SaasStoreReferral();
  951. $obj->store_id = $store_id;
  952. $obj->referral_id = $value['referral_id'];
  953. $obj->referral_rebate = $value['referral_rebate'];
  954. $obj->save();
  955. }
  956. return [
  957. 'code' => 0,
  958. 'msg' => '保存成功!',
  959. ];
  960. } catch (Exception $e) {
  961. return [
  962. 'code' => 1,
  963. 'msg' => $e->getMessage(),
  964. ];
  965. }
  966. }
  967. /**
  968. * 获取推荐人参数
  969. *
  970. * @param int $store_id
  971. * @return array
  972. */
  973. public function getReferralParams($store_id)
  974. {
  975. if (!$store_id) {
  976. return [
  977. 'code' => 1,
  978. 'msg' => 'store_id不能为空!',
  979. ];
  980. }
  981. $store = Store::findOne($store_id);
  982. if (!$store) {
  983. return [
  984. 'code' => 1,
  985. 'msg' => '未找到商城!',
  986. ];
  987. }
  988. $lists = SaasStoreReferral::find()
  989. ->where(['store_id' => $store->id])
  990. ->select(['referral_id', 'referral_rebate'])
  991. ->asArray()->all();
  992. return [
  993. 'code' => 0,
  994. 'msg' => 'success',
  995. 'data' => $lists,
  996. ];
  997. }
  998. /**
  999. * 设置商城让利比例
  1000. *
  1001. * @param int $store_id
  1002. * @param array $params
  1003. * @return array
  1004. */
  1005. public function setTransferProfitParams($store_id, $params)
  1006. {
  1007. if (!$store_id) {
  1008. return [
  1009. 'code' => 1,
  1010. 'msg' => 'store_id不能为空!',
  1011. ];
  1012. }
  1013. $store = Store::findOne($store_id);
  1014. if (!$store) {
  1015. return [
  1016. 'code' => 1,
  1017. 'msg' => '未找到商城!',
  1018. ];
  1019. }
  1020. $transfer_profit = number_format($params['transfer_profit'], 2);
  1021. $scan_transfer_profit = number_format($params['scan_transfer_profit'], 2);
  1022. $food_transfer_profit = number_format($params['food_transfer_profit'], 2);
  1023. $cashier_transfer_profit = number_format($params['cashier_transfer_profit'], 2);
  1024. // $league_price = $params['league_price'];
  1025. //取消商城最大让利比例
  1026. //$store_admin = get_admin();
  1027. //$max_price = $store_admin->max_price;
  1028. // $admin_id = get_admin();
  1029. // if ($admin_id->username != 'admin' && $max_price < $transfer_profit) {
  1030. // return [
  1031. // 'code' => 1,
  1032. // 'msg' => '您的可设置佣金金额不足!',
  1033. // ];
  1034. // }
  1035. $store->transfer_profit = $transfer_profit;
  1036. $store->scan_transfer_profit = $scan_transfer_profit;
  1037. $store->food_transfer_profit = $food_transfer_profit;
  1038. $store->cashier_transfer_profit = $cashier_transfer_profit;
  1039. // $store->league_price = $league_price;
  1040. if ($store->save()) {
  1041. return [
  1042. 'code' => 0,
  1043. 'msg' => '保存成功!',
  1044. ];
  1045. }
  1046. return [
  1047. 'code' => 1,
  1048. 'msg' => '保存失败!',
  1049. ];
  1050. }
  1051. /**
  1052. * 获取商城让利比例参数
  1053. *
  1054. * @param int $store_id
  1055. * @return array
  1056. */
  1057. public function getTransferProfitParams($store_id)
  1058. {
  1059. if (!$store_id) {
  1060. return [
  1061. 'code' => 1,
  1062. 'msg' => 'store_id不能为空!',
  1063. ];
  1064. }
  1065. $store = Store::findOne($store_id);
  1066. if (!$store) {
  1067. return [
  1068. 'code' => 1,
  1069. 'msg' => '未找到商城!',
  1070. ];
  1071. }
  1072. //获取代理商最大分佣金额
  1073. //获取代理商信息
  1074. $get_admin = get_admin();
  1075. $max_price = $get_admin->max_price;
  1076. return [
  1077. 'code' => 0,
  1078. 'msg' => 'success',
  1079. 'data' => [
  1080. 'transfer_profit' => $store->transfer_profit,
  1081. 'league_price' => $store->league_price,
  1082. 'max_price' => $max_price,
  1083. 'scan_transfer_profit' => $store->scan_transfer_profit,
  1084. 'food_transfer_profit' => $store->food_transfer_profit,
  1085. 'cashier_transfer_profit' => $store->cashier_transfer_profit
  1086. ],
  1087. ];
  1088. }
  1089. /**
  1090. * 获取商城经纬度等信息
  1091. *
  1092. * @param int $store_id
  1093. * @return array
  1094. */
  1095. public function getStoreParams($store_id)
  1096. {
  1097. $admin = get_admin();
  1098. if (!$store_id) {
  1099. return [
  1100. 'code' => 1,
  1101. 'msg' => 'store_id不能为空!',
  1102. ];
  1103. }
  1104. $store = Store::findOne($store_id);
  1105. if (!$store) {
  1106. return [
  1107. 'code' => 1,
  1108. 'msg' => '未找到商城!',
  1109. ];
  1110. }
  1111. $category_name = '-';
  1112. $category = SaasCategory::findOne($store->category_id);
  1113. if ($category) {
  1114. $category_name = $category->name;
  1115. }
  1116. $name = $store->name;
  1117. $logo = $store->logo;
  1118. if (empty($name)) {
  1119. $name = Option::get('name', $store_id, 'store', '')['value'];
  1120. }
  1121. if (empty($logo)) {
  1122. $logo = Option::get('web_log', $store_id, 'web', '')['value'];
  1123. }
  1124. $self_mini = Option::get('self_mini', $store_id, 'store', 0)['value'];
  1125. $is_store_traffic_sharing = Option::get('is_store_traffic_sharing', $store_id, 'store', 1)['value'];
  1126. $store_permission = [];
  1127. $permission = [];
  1128. $plugin = \Yii::$app->getAttr('plugin');
  1129. $store_permission = json_decode($store->auth);
  1130. $permission = \Yii::$app->getPermission($store->business_model, $store_id);
  1131. AuthRoleForm::formatPermission($permission);
  1132. $is_duli_store_auth = false;
  1133. if (in_array('duli_store', $plugin['union'])) {
  1134. $is_duli_store_auth = true;
  1135. }
  1136. $salesman_id = $store->salesman_id;
  1137. $md_id = -1;
  1138. $page = '';
  1139. if ($store->business_model == 2) { //平台运营
  1140. $page = 'pages/shop/shopIndex';
  1141. $scene = "store_id:{$store_id}";
  1142. } elseif ($store->business_model == 3) { //当面付
  1143. $page = 'face-pay/face-pay/payOut';
  1144. $scene = "store_id:{$store_id}";
  1145. } elseif ($store->business_model == 4) { //点餐
  1146. $page = 'alipay-order/orderMeal/orderMeal';
  1147. $scene = "md_id:{$md_id},store_id:{$store_id}";
  1148. }
  1149. if($page != '') {
  1150. $qr_code_res = ShareQrcode::wxQrcode($page, $scene);
  1151. }
  1152. //是否允许添加产品
  1153. $is_add_goods = Option::get('is_add_goods', $store_id, 'store', 1)['value'];
  1154. return [
  1155. 'code' => 0,
  1156. 'msg' => 'success',
  1157. 'data' => [
  1158. 'is_super_admin' => get_admin()->username == 'admin',
  1159. 'name' => $name,
  1160. 'logo' => $logo,
  1161. 'qr_code_url' => $qr_code_res['url_path'],
  1162. 'coordinate' => $store->coordinate,
  1163. 'address' => $store->address,
  1164. 'category_id' => $store->category_id,
  1165. 'category_name' => $category_name,
  1166. 'option' => is_array($store->info) ? $store->info : \json_decode($store->info, true),
  1167. 'address_info' => [
  1168. 'province_id' => $store->province_id,
  1169. 'city_id' => $store->city_id,
  1170. 'district_id' => $store->district_id
  1171. ],
  1172. 'sales' => $store->sales,
  1173. 'rank' => $store->rank,
  1174. 'per_spend' => $store->per_spend,
  1175. 'tags' => empty($store->tags) ? [] : json_decode($store->tags),
  1176. 'contact_tel' => $store->contact_tel,
  1177. 'user_name' => $store->user_name,
  1178. 'open_status' => $store->open_status,
  1179. 'shop_time_type' => $store->shop_time_type,
  1180. 'is_time_forbid' => $store->is_time_forbid,
  1181. 'is_set_distance' => $store->is_set_distance,
  1182. 'distance' => $store->distance,
  1183. 'start_time' => $store->s_time,
  1184. 'end_time' => $store->e_time,
  1185. 'store_admin' => $store->store_admin,
  1186. 'business_model' => $store->business_model,
  1187. 'self_mini' => $self_mini ? 1 : 0,
  1188. 'permission' => $admin->type == Admin::ADMIN_TYPE_BD_AGENT ? [] : $permission,
  1189. 'store_permission' => $admin->type == Admin::ADMIN_TYPE_BD_AGENT ? [] : $store_permission,
  1190. 'prod_is_shangmeng' => \Yii::$app->prod_is_shangmeng(),
  1191. 'prod_is_saas' => \Yii::$app->prod_is_saas(),
  1192. 'cost_end_time' => date('Y-m-d', $store->end_time),
  1193. 'is_duli_store_auth' => $is_duli_store_auth,
  1194. 'salesman_id' => $salesman_id,
  1195. 'is_add_goods' => (int)$is_add_goods,
  1196. 'balance' => $store->balance,
  1197. 'mini_auth_num' => $store->mini_auth_num,
  1198. 'is_store_traffic_sharing' => isset($is_store_traffic_sharing)? (string)($is_store_traffic_sharing) : '1'
  1199. ],
  1200. ];
  1201. }
  1202. /**
  1203. * 设置商城经纬度信息
  1204. *
  1205. * @param int $store_id
  1206. * @param array $params
  1207. * @return array
  1208. */
  1209. public function setStoreParams($store_id, $params)
  1210. {
  1211. $admin = get_admin();
  1212. if (!$store_id) {
  1213. return [
  1214. 'code' => 1,
  1215. 'msg' => 'store_id不能为空!',
  1216. ];
  1217. }
  1218. $store = Store::findOne($store_id);
  1219. if (!$store) {
  1220. return [
  1221. 'code' => 1,
  1222. 'msg' => '未找到商城!',
  1223. ];
  1224. }
  1225. if (isset($params['coordinate']) && !empty($params['coordinate'])) {
  1226. if (strpos($params['coordinate'], ',') === false) {
  1227. return [
  1228. 'code' => 1,
  1229. 'msg' => '商城坐标信息格式不正确!',
  1230. ];
  1231. }
  1232. $store->coordinate = $params['coordinate'];
  1233. Option::set('coordinate', $params['coordinate'], $store->id, 'store');
  1234. if ($params['coordinate']) {
  1235. $coordinate = explode(',', $params['coordinate']);
  1236. $store->longitude = $coordinate[1];
  1237. $store->latitude = $coordinate[0];
  1238. }
  1239. }
  1240. $store->name = $params['name'];
  1241. $store->logo = $params['logo'];
  1242. // 同步option表
  1243. Option::set('name', $params['name'], $store_id, 'store');
  1244. Option::set('logo', $params['logo'], $store_id, 'store');
  1245. Option::set('contact_tel', $params['contact_tel'], $store_id, 'store');
  1246. Option::set('web_log', $params['logo'], $store_id, 'web');
  1247. $store->address = $params['address'];
  1248. Option::set('address', $params['address'], $store_id, 'store');
  1249. $store->category_id = $params['category_id'];
  1250. $store->sales = $params['sales'];
  1251. $store->rank = $params['rank'];
  1252. $store->per_spend = $params['per_spend'];
  1253. $store->user_name = $params['user_name'];
  1254. $store->contact_tel = $params['contact_tel'];
  1255. $store->tags = json_encode($params['tags'], JSON_UNESCAPED_UNICODE);
  1256. $store->open_status = intval($params['open_status']);
  1257. $shop_time_type = intval($params['shop_time_type']);
  1258. // $store->store_admin = intval($params['store_admin']);
  1259. $store->shop_time_type = $shop_time_type;
  1260. $store->is_time_forbid = intval($params['is_time_forbid']);
  1261. $is_set_distance = intval($params['is_set_distance']);
  1262. $store->balance = intval($params['balance']);
  1263. if ($params['salesman_id']) {
  1264. $salesman = Salesman::findOne($params['salesman_id']);
  1265. $store->salesman_id = $params['salesman_id'];
  1266. $store->store_admin = $salesman->saas_user_id;
  1267. }
  1268. $params['cost_end_time'] && $store->end_time = strtotime($params['cost_end_time']);
  1269. if ($is_set_distance) {
  1270. if (empty($params['distance'])) {
  1271. return [
  1272. 'code' => 1,
  1273. 'msg' => '未设置距离范围'
  1274. ];
  1275. }
  1276. $store->distance = $params['distance'];
  1277. }
  1278. $store->is_set_distance = intval($params['is_set_distance']);
  1279. if ($shop_time_type) {
  1280. if (empty($params['start_time'] || empty($params['end_time']))) {
  1281. return [
  1282. 'code' => 1,
  1283. 'msg' => '请设置开始时间和结束时间'
  1284. ];
  1285. }
  1286. $store->s_time = $params['start_time'];
  1287. $store->e_time = $params['end_time'];
  1288. }
  1289. if (!empty($params['category_option'])) {
  1290. $store->info = json_encode($params['category_option']);
  1291. }
  1292. if ($params['address_info']) {
  1293. Option::set('address_info', json_encode($params['address_info']), $store_id, 'store');
  1294. $store->province_id = $params['address_info']['province_id'];
  1295. $store->city_id = $params['address_info']['city_id'];
  1296. $store->district_id = $params['address_info']['district_id'];
  1297. }
  1298. $store->business_model = intval($params['business_model']);
  1299. Option::set('self_mini', intval($params['self_mini']), $store_id, 'store');
  1300. Option::set('is_store_traffic_sharing', intval($params['is_store_traffic_sharing']), $store_id, 'store');
  1301. Option::set('is_add_goods', $params['is_add_goods'], $store_id, 'store');
  1302. // $plugin = \Yii::$app->getAttr('plugin');
  1303. // if (in_array('store_auth', $plugin['union']) && $store->business_model == 1) {
  1304. if ($admin->type != Admin::ADMIN_TYPE_BD_AGENT) {
  1305. if ($store->business_model == 1 || $store->business_model == 2) {
  1306. $store->auth = json_encode($params['store_permission']);
  1307. } else {
  1308. $store->auth = json_encode([]);
  1309. }
  1310. }
  1311. $store->mini_auth_num = $params['mini_auth_num'];
  1312. if ($store->save()) {
  1313. if ($store->balance == 1) {
  1314. $option = Option::find()->where(["store_id" => get_store_id(), "name" => "combine_pay", "group" => "recharge"])->one();
  1315. if ($option !== null) {
  1316. $option->value = '0';
  1317. if (!$option->save()) {
  1318. $option->getErrors();
  1319. }
  1320. } else {
  1321. // 处理未找到记录的情况,可以抛出异常或者记录日志等
  1322. $option = Option::find()->where(["store_id" => get_store_id(), "name" => "combine_pay", "group" => "recharge"])->one();
  1323. $option = new Option();
  1324. $option->store_id = $store_id;
  1325. $option->name = "combine_pay";
  1326. $option->group = "recharge";
  1327. $option->value = '0';
  1328. if (!$option->save()) {
  1329. $option->getErrors();
  1330. }
  1331. }
  1332. }
  1333. return [
  1334. 'code' => 0,
  1335. 'msg' => '保存成功!',
  1336. ];
  1337. }
  1338. return [
  1339. 'code' => 1,
  1340. 'msg' => $store->getErrorSummary(false),
  1341. ];
  1342. }
  1343. /**
  1344. * 获取商城信息
  1345. */
  1346. public function getInfo($store_id)
  1347. {
  1348. if (!$store_id) {
  1349. // return [
  1350. // 'code' => 1,
  1351. // 'msg' => 'store_id不能为空!',
  1352. // ];
  1353. }
  1354. $store = Store::findOne($store_id);
  1355. if (!$store) {
  1356. // return [
  1357. // 'code' => 1,
  1358. // 'msg' => '未找到商城!',
  1359. // ];
  1360. }
  1361. $path_h5 = path_h5();
  1362. $text = 'https://' . \Yii::$app->request->hostName . '/' . $path_h5 . '/#/?store_id=' . $store_id;
  1363. $filename = md5('_' . $path_h5 . '_' . $store_id);
  1364. $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
  1365. if (!file_exists($path)) {
  1366. QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
  1367. }
  1368. $path_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
  1369. return [
  1370. 'code' => 0,
  1371. 'msg' => 'success',
  1372. 'data' => $store,
  1373. 'h5' => [
  1374. 'url' => $text,
  1375. 'qrcode_url' => $path_url
  1376. ]
  1377. ];
  1378. }
  1379. public function joinAlliance($store_id, $status)
  1380. {
  1381. if (!$store_id) {
  1382. return [
  1383. 'code' => 1,
  1384. 'msg' => 'store_id不能为空!',
  1385. ];
  1386. }
  1387. $store = Store::findOne($store_id);
  1388. if (!$store) {
  1389. return [
  1390. 'code' => 1,
  1391. 'msg' => '未找到商城!',
  1392. ];
  1393. }
  1394. $store->is_alliance = $status;
  1395. if ($store->save()) {
  1396. return [
  1397. 'code' => 0,
  1398. 'msg' => '操作成功!',
  1399. ];
  1400. }
  1401. return [
  1402. 'code' => 1,
  1403. 'msg' => '操作失败!',
  1404. ];
  1405. }
  1406. /**
  1407. * 获取待审核商城
  1408. */
  1409. public function getCheckList()
  1410. {
  1411. $query = Store::find()->where([
  1412. 'is_delete' => 0,
  1413. 'is_alliance' => 2,
  1414. ]);
  1415. $pagination = pagination_make($query);
  1416. $list = $pagination['list'];
  1417. foreach ($list as &$item) {
  1418. $option = Option::get('name', $item['id'], 'store', '-');
  1419. $item['store_name'] = $option['value'];
  1420. }
  1421. return [
  1422. 'code' => 0,
  1423. 'msg' => 'success',
  1424. 'data' => [
  1425. 'data' => $list,
  1426. 'pageNo' => $pagination['pageNo'],
  1427. 'totalCount' => $pagination['totalCount'],
  1428. ],
  1429. ];
  1430. }
  1431. public function getDouyinInfo($store_id)
  1432. {
  1433. if (!$store_id) {
  1434. return [
  1435. 'code' => 1,
  1436. 'msg' => 'store_id不能为空!',
  1437. ];
  1438. }
  1439. $store = Store::findOne($store_id);
  1440. if (!$store) {
  1441. return [
  1442. 'code' => 1,
  1443. 'msg' => '未找到商城!',
  1444. ];
  1445. }
  1446. $default_douyin_config = [
  1447. 'app_id' => '',
  1448. 'app_secret' => '',
  1449. 'salt' => '',
  1450. 'token' => ''
  1451. ];
  1452. $douyin_config = Option::get('douyin', $store_id, 'store', $default_douyin_config)['value'];
  1453. $douyin_config = is_string($douyin_config) ? Json::decode($douyin_config) : $douyin_config;
  1454. return [
  1455. 'code' => 0,
  1456. 'msg' => 'success',
  1457. 'data' => [
  1458. 'douyin_url' => $store->douyin_url,
  1459. 'app_id' => $douyin_config['app_id'],
  1460. 'app_secret' => $douyin_config['app_secret'],
  1461. 'salt' => $douyin_config['salt'],
  1462. 'token' => $douyin_config['token'],
  1463. ],
  1464. ];
  1465. }
  1466. public function setDouyinInfo($store_id, $content, $params)
  1467. {
  1468. if (!$store_id) {
  1469. return [
  1470. 'code' => 1,
  1471. 'msg' => 'store_id不能为空!',
  1472. ];
  1473. }
  1474. $store = Store::findOne($store_id);
  1475. if (!$store) {
  1476. return [
  1477. 'code' => 1,
  1478. 'msg' => '未找到商城!',
  1479. ];
  1480. }
  1481. $store->douyin_url = $content;
  1482. if ($store->save()) {
  1483. if (Option::set('douyin', Json::encode($params), $store_id, 'store')) {
  1484. return [
  1485. 'code' => 0,
  1486. 'msg' => '保存成功!',
  1487. ];
  1488. } else {
  1489. return [
  1490. 'code' => 1,
  1491. 'msg' => '保存失败!',
  1492. ];
  1493. }
  1494. }
  1495. return [
  1496. 'code' => 1,
  1497. 'msg' => $store->errors[0],
  1498. ];
  1499. }
  1500. public function getCost($store_id){
  1501. if (!$store_id) {
  1502. return false;
  1503. }
  1504. $store = Store::findOne($store_id);
  1505. if (!$store) {
  1506. return [
  1507. 'code' => 0,
  1508. 'msg' => '未找到商城!',
  1509. ];
  1510. }
  1511. return [
  1512. 'code' => 0,
  1513. 'msg' => "获取成功",
  1514. 'data'=>[
  1515. "open_price" =>$store->open_price,
  1516. "renew_price" =>$store->renew_price,
  1517. "end_time" =>date("Y-m-d",$store->end_time),
  1518. "profit" =>$store->profit,
  1519. "is_end"=>$store->end_time ? ($store->end_time > time() || !\Yii::$app->isSaas()) : true,
  1520. 'is_use_default' => $store->is_use_default ?? 1
  1521. ]
  1522. ];
  1523. }
  1524. public function setCost($store_id,$params){
  1525. if (!$store_id) {
  1526. return [
  1527. 'code' => 1,
  1528. 'msg' => 'store_id不能为空!',
  1529. ];
  1530. }
  1531. $store = Store::findOne($store_id);
  1532. if (!$store) {
  1533. return [
  1534. 'code' => 1,
  1535. 'msg' => '未找到商城!',
  1536. ];
  1537. }
  1538. $store->open_price = $params['open_price'];
  1539. $store->renew_price = $params['renew_price'];
  1540. $store->end_time = $params['end_time'];
  1541. $store->profit = $params['profit'];
  1542. $store->is_use_default = $params['is_use_default'];
  1543. $res = $store->save();
  1544. if ($res) {
  1545. if (Option::set('store_save', Json::encode($params), $store_id, 'store')) {
  1546. return [
  1547. 'code' => 0,
  1548. 'msg' => "保存成功"
  1549. ];
  1550. }
  1551. }else{
  1552. return [
  1553. 'code' => 1,
  1554. 'msg' => $store->errors[0],
  1555. ];
  1556. }
  1557. }
  1558. public function payFee($store_id){
  1559. $t = \Yii::$app->db->beginTransaction();
  1560. try {
  1561. $store = Store::find()->where(['id' => $store_id])
  1562. ->select("open_price, renew_price, end_time, profit, is_use_default")->one();
  1563. if ($store->end_time > 0 && $store->end_time < time() && \Yii::$app->isSaas()) {
  1564. $admin = Admin::findOne(['type' => 'store', 'type_id' => $store_id]);
  1565. $res = ShareQrcode::wxQrcode('admin/home/home', '0', 1000, 0, 1);
  1566. if ($res['code'] === 0) {
  1567. $array = [
  1568. 'code' => 0,
  1569. 'url' => $res['url_path'],
  1570. 'desc' => '',
  1571. 'name' => '店铺续费'
  1572. ];
  1573. if ($admin->saas_user_id) {
  1574. $saas_user = SaasUser::findOne($admin->saas_user_id);
  1575. $array['desc'] = '请使用管理员'. $saas_user->name .'('. $saas_user->mobile .')扫码续费,完成后刷新';
  1576. } else {
  1577. $array['desc'] = '当前商城未添加管理员,请联系平台添加管理员后扫码续费';
  1578. }
  1579. return $array;
  1580. }
  1581. return $res;
  1582. }
  1583. }catch (\Exception $e){
  1584. $t->rollBack();
  1585. return [
  1586. 'code' => 0,
  1587. 'msg' => $e->getMessage()
  1588. ];
  1589. }
  1590. }
  1591. public function isPay($order_id){
  1592. $order = StoreReOrder::findOne($order_id);
  1593. if($order->is_pay == 1){
  1594. // $store = Store::findOne($order->store_id);
  1595. // $store->end_time = strtotime('+1 year');
  1596. // $store->save();
  1597. return [
  1598. 'code'=>0,
  1599. 'msg'=>"支付成功"
  1600. ];
  1601. }
  1602. }
  1603. //修改密码
  1604. public function setPassword($id = 0, $password = "", $name = '', $user_name = '', $saas_user_id = ''){
  1605. $t = \Yii::$app->db->beginTransaction();
  1606. try {
  1607. // $store = Store::find()->where(['id'=>$id])->select("id,admin_id")->one();
  1608. // if(empty($store) || empty($store->admin_id)){
  1609. // throw new Exception('获取商城信息失败');
  1610. // }
  1611. $admin = Admin::findOne([
  1612. 'type' => 'store',
  1613. 'type_id' => $id
  1614. ]);
  1615. if (!$admin) {
  1616. if($id == 1){
  1617. $admin = new Admin();
  1618. $admin->access_token = \Yii::$app->security->generateRandomString();
  1619. $admin->type = 'store';
  1620. $admin->type_id = 1;
  1621. $admin->name = '';
  1622. $admin->username = '';
  1623. $admin->mobile = '';
  1624. }else{
  1625. throw new Exception('该商城不可更改该信息');
  1626. }
  1627. }
  1628. if ($name) {
  1629. $admin->name = $name;
  1630. }
  1631. if ($user_name) {
  1632. $admin->username = $user_name;
  1633. }
  1634. if ($name && $user_name) {
  1635. $search_admin = Admin::findOne([
  1636. // 'type' => 'store',
  1637. 'username' => $user_name,
  1638. 'is_delete' => 0
  1639. ]);
  1640. if ($search_admin && ($search_admin->id !== $admin->id)) {
  1641. throw new \Exception("用户名已经存在");
  1642. }
  1643. }
  1644. if ($password) {
  1645. $admin->password = \Yii::$app->security->generatePasswordHash($password);
  1646. }
  1647. if ($saas_user_id) {
  1648. $admin->saas_user_id = $saas_user_id;
  1649. }
  1650. $res = $admin->save();
  1651. if(!$res){
  1652. $err = '';
  1653. foreach($admin->errors as $k => $item){
  1654. $err .= $k . ':[' . implode('],[', $item) . '];';
  1655. }
  1656. throw new \Exception($err);
  1657. }
  1658. $platForm = new PlatformForm();
  1659. $store_cloud = StoreCloud::findOne(['store_id' => $id, 'is_delete' => 0]);
  1660. if ($store_cloud) {
  1661. StoreCloud::updateAll(['store_id' => 0], ['store_id' => $id, 'is_delete' => 0]);
  1662. // if (intval($store_cloud->saas_user_id) !== intval($saas_user_id) && $saas_user_id) {
  1663. // $store_cloud = StoreCloud::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  1664. // if (!$store_cloud) {
  1665. // $store_cloud->saas_user_id = $saas_user_id;
  1666. // }
  1667. // }
  1668. $open = false;
  1669. if ($saas_user_id && $store_cloud->saas_user_id !== $saas_user_id) {
  1670. $store_cloud = StoreCloud::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  1671. if (!$store_cloud) {
  1672. throw new \Exception('当前用户未绑定云仓');
  1673. }
  1674. $open = true;
  1675. }
  1676. $old_store_id = $store_cloud->store_id;
  1677. $store_cloud->store_id = $id;
  1678. if ($store_cloud->save() && $open) {
  1679. $platForm->delUserCloudGoodsBind($store_cloud->cloud_user_id, $old_store_id);
  1680. };
  1681. } else {
  1682. $store_cloud = StoreCloud::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  1683. if ($store_cloud) {
  1684. $old_store_id = $store_cloud->store_id;
  1685. $store_cloud->store_id = $id;
  1686. if ($store_cloud->save()) {
  1687. $platForm->delUserCloudGoodsBind($store_cloud->cloud_user_id, $old_store_id);
  1688. }
  1689. }
  1690. }
  1691. // $store_cloud = StoreCloud::find()->where(['OR', ['store_id' => $id], ['saas_user_id' => $saas_user_id]])
  1692. // ->andWhere(['is_delete' => 0])->asArray()->one();
  1693. if (!$store_cloud && get_platform_token()) {
  1694. try {
  1695. $store = Store::findOne($id);
  1696. $saas_user = SaasUser::findOne(['id' => $saas_user_id, 'is_delete' => 0]);
  1697. // 创建云仓账号
  1698. $this->createStoreCloud($saas_user->mobile, $store, $saas_user);
  1699. } catch (\Exception $e) {
  1700. throw new \Exception($e->getMessage());
  1701. }
  1702. }
  1703. $t->commit();
  1704. return [
  1705. 'code'=>0,
  1706. 'msg'=>"修改成功"
  1707. ];
  1708. }catch (\Exception $e){
  1709. $t->rollBack();
  1710. return [
  1711. 'code'=>1,
  1712. 'msg'=>$e->getMessage()
  1713. ];
  1714. }
  1715. }
  1716. public function reOrderList($store_id){
  1717. $query = StoreReOrder::find()->where(['store_id'=>$store_id,'is_delete'=>0,'is_pay'=>1]);
  1718. $count = $query->count();
  1719. $pagination = new Pagination(['totalCount' => $count, 'page' =>$this->page - 1, 'pageSize' => $this->limit]);
  1720. /* @var Order[] $list */
  1721. $data = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
  1722. foreach($data as &$item){
  1723. $item['pay_time'] = date("Y-m-d H:i:s",$item['pay_time']);
  1724. $item['is_pay'] = $item['is_pay'] == 1?"已支付":"未支付";
  1725. }
  1726. return [
  1727. 'code'=>0,
  1728. 'msg'=>"获取成功",
  1729. 'list'=>$data,
  1730. 'count'=>$count
  1731. ];
  1732. }
  1733. /**
  1734. * 获取商城审核列表
  1735. */
  1736. public function getAuditList()
  1737. {
  1738. try {
  1739. //如果是代理商登陆
  1740. $admin = get_admin();
  1741. $admin_id = $admin->id;
  1742. $salesman_id = $this->salesman_id;
  1743. if ($admin->username == 'admin') {
  1744. $admin_id = null;
  1745. }
  1746. $where = [];
  1747. $query = Salesman::find()->alias('s')->leftJoin(['su' => SaasUser::tableName()], 's.saas_user_id = su.id');
  1748. if ($admin_id) {
  1749. $data = [];
  1750. $query->where(['s.admin_id' => $admin_id]);
  1751. } else {
  1752. $data = [0];
  1753. }
  1754. $query->andWhere(['admin_id' => Admin::find()->where(['type' => Admin::ADMIN_TYPE_BD_AGENT])->select('id')]);
  1755. //如果是搜索
  1756. // $admin_id = $this->admin_id;
  1757. // if ($admin_id) {
  1758. // $query->where(['s.admin_id' => $admin_id]);
  1759. // }
  1760. $salesmans = $query->andWhere(['su.is_delete' => 0, 's.is_delete' => 0, 's.status' => 1])->select('s.id, su.name, su.avatar')->asArray()->all();
  1761. $ids = [];
  1762. if ($salesmans) {
  1763. $ids = array_column($salesmans, 'id');
  1764. // $ids = array_merge($ids, $data);
  1765. // $where['sa.salesman_id'] = $ids;
  1766. }
  1767. if ($salesman_id) {
  1768. $where['sa.salesman_id'] = $salesman_id;
  1769. }
  1770. //正常流程开始
  1771. //$status = (int)$this->status;
  1772. //if (in_array($status, [0, 1, 2], true)) {
  1773. // $where['sa.status'] = $status;
  1774. //}
  1775. $admin = Admin::find()->where(['is_delete' => 0, 'type' => 'admin'])->andWhere(['<>', 'name', 'admin'])->select('id, name')->asArray()->all();
  1776. $query = StoreAudit::find()->alias('sa')->where($where)
  1777. // ->andWhere(['!=', 'sa.status', 1])
  1778. ->leftJoin(['sc' => SaasCategory::tableName()], 'sa.cat_id = sc.id')
  1779. ->leftJoin(['su' => SaasUser::tableName()], 'sa.saas_user_id = su.id')
  1780. //->leftJoin(['s' => Salesman::tableName()], 's.saas_user_id = su.id')
  1781. //->leftJoin(['a' => Admin::tableName()], 'a.id = s.admin_id')
  1782. //->andWhere(['s.is_delete' => 0, 'a.is_delete' => 0, 'su.is_delete' => 0])
  1783. ->andWhere(['su.is_delete' => 0])
  1784. ->select('sa.id, sa.is_single_store, sa.saas_user_id, sa.salesman_id, sa.name, sa.logo, sa.mobile, sa.business_pic, sa.permit_pic, sa.status, sa.created_at, su.name username, sc.name category_name, sa.updated_at')
  1785. ->orderBy(', sa.created_at desc, sa.updated_at desc');
  1786. // var_dump($query->createCommand()->getRawSql());die;
  1787. $name = $this->name;
  1788. if ($name) {
  1789. $query->andWhere(['like', 'sa.name', $name]);
  1790. }
  1791. if ($admin_id) {
  1792. $admin_model = Admin::findOne($admin_id);
  1793. $area_level = $admin_model->area_level;
  1794. if($area_level == 1){
  1795. $query->andWhere([
  1796. 'or',
  1797. ['sa.province_id' => $admin_model->province_id, 'sa.city_id' => $admin_model->city_id, 'sa.district_id' => $admin_model->district_id],
  1798. ['in', 'sa.salesman_id', array_column($salesmans, 'id')]
  1799. ]);
  1800. } elseif ($area_level == 2){
  1801. $query->andWhere([
  1802. 'or',
  1803. ['sa.province_id' => $admin_model->province_id, 'sa.city_id' => $admin_model->city_id],
  1804. ['in', 'sa.salesman_id', array_column($salesmans, 'id')]
  1805. ]);
  1806. } elseif ($area_level == 3){
  1807. $query->andWhere([
  1808. 'or',
  1809. ['sa.province_id' => $admin_model->province_id],
  1810. ['in', 'sa.salesman_id', array_column($salesmans, 'id')]
  1811. ]);
  1812. } else {
  1813. $query->andWhere(
  1814. ['in', 'sa.salesman_id', array_column($salesmans, 'id')]
  1815. );
  1816. }
  1817. }
  1818. $status = (int)$this->status;
  1819. if (in_array($status, [0, 1, 2], true)) {
  1820. // if ($status === 1) {
  1821. // $query->andWhere(['<>', 'sa.salesman_id', 0]);
  1822. // } else {
  1823. // $query->andWhere(['sa.salesman_id' => 0]);
  1824. // }
  1825. $query->andWhere(['sa.status' => $status]);
  1826. }
  1827. $pagination = pagination_make($query);
  1828. $list = $pagination['list'];
  1829. foreach ($list as &$item) {
  1830. $Salesman = Salesman::find()->alias('s')->where(['s.id' => $item['salesman_id'], 's.is_delete' => 0])
  1831. ->leftJoin(['su' => SaasUser::tableName()], 's.saas_user_id = su.id')
  1832. ->leftJoin(['a' => Admin::tableName()], 'a.id = s.admin_id')->select('su.name salesman, a.name')->asArray()->one();
  1833. // var_dump($Salesman);die;
  1834. $item['admin_name'] = $Salesman ? $Salesman['name'] : '';
  1835. $item['salesman'] = $Salesman ? $Salesman['salesman'] : '';
  1836. $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
  1837. $item['updated_at'] = !empty($item['updated_at']) ? date('Y-m-d H:i:s', $item['updated_at']) : 0;
  1838. $item['status'] *= 1;
  1839. }
  1840. return [
  1841. 'code' => 0,
  1842. 'msg' => 'success',
  1843. 'data' => [
  1844. 'data' => $list,
  1845. 'pageNo' => $pagination['pageNo'],
  1846. 'totalCount' => $pagination['totalCount'],
  1847. 'salesman' => $salesmans,
  1848. 'admin' => $admin
  1849. ],
  1850. ];
  1851. } catch (\Exception $e) {
  1852. return [
  1853. 'code' => 1,
  1854. 'msg' => $e->getMessage(),
  1855. 'file' => $e->getFile(),
  1856. 'line' => $e->getLine(),
  1857. ];
  1858. }
  1859. }
  1860. public function bindSalesman()
  1861. {
  1862. try {
  1863. $id = $this->id;
  1864. $salesman_id = $this->salesman_id;
  1865. $audit = StoreAudit::findOne($id);
  1866. if (empty($audit)) {
  1867. throw new \Exception("获取不到申请单信息");
  1868. }
  1869. if ((int)$audit->status !== 0) {
  1870. throw new \Exception("申请单已经被处理,不可更改");
  1871. }
  1872. $salesman = Salesman::findOne(['id' => $salesman_id, 'is_delete' => 0]);
  1873. if (empty($salesman)) {
  1874. throw new \Exception("业务员信息未找到");
  1875. }
  1876. if ((int)$salesman->status === 0) {
  1877. throw new \Exception("业务员已经被禁用");
  1878. }
  1879. $audit->salesman_id = $salesman->id;
  1880. $audit->saas_user_id = $salesman->saas_user_id;
  1881. if (!$audit->save()) {
  1882. throw new \Exception("保存失败");
  1883. }
  1884. return [
  1885. 'code' => 0,
  1886. 'msg' => "操作成功"
  1887. ];
  1888. } catch (\Exception $e) {
  1889. return [
  1890. 'code' => 1,
  1891. 'msg' => $e->getMessage()
  1892. ];
  1893. }
  1894. }
  1895. //申请
  1896. public function storeAudit()
  1897. {
  1898. $t = \Yii::$app->db->beginTransaction();
  1899. try {
  1900. $id = $this->id;
  1901. $status = (int)$this->status;
  1902. $business_model = $this->business_model;
  1903. $qrcode_id = $this->qrcode_id;
  1904. $audit = StoreAudit::findOne($id);
  1905. if (empty($audit)) {
  1906. throw new \Exception("获取不到申请单信息");
  1907. }
  1908. if ((int)$audit->status !== 0) {
  1909. throw new \Exception("申请单已经被处理,请勿重复操作");
  1910. }
  1911. if (!in_array($status, [1, 2])) {
  1912. throw new \Exception("状态值错误");
  1913. }
  1914. //同意申请
  1915. if ($status === 1) {
  1916. if ($audit->is_single_store == 0) {
  1917. // if (empty($qrcode_id)) {
  1918. // throw new \Exception("请填写聚合码ID");
  1919. // }
  1920. if (!in_array($business_model, [1, 2, 3, 4])) {
  1921. throw new \Exception("请选择商城类型");
  1922. }
  1923. // if ((int)$business_model === 1) {
  1924. // $AggregateQrcode = AggregateQrcode::findOne($qrcode_id);
  1925. // } else {
  1926. // $AggregateQrcode = AggregateSaasQrcode::findOne($qrcode_id);
  1927. // }
  1928. // if (empty($AggregateQrcode)) {
  1929. // throw new \Exception("对应的聚合码不存在,请重试");
  1930. // }
  1931. // if ($AggregateQrcode->store_id) {
  1932. // throw new \Exception("聚合码已经被使用");
  1933. // }
  1934. }
  1935. // 自动创建admin账号
  1936. $admin = new Admin();
  1937. $admin->access_token = \Yii::$app->security->generateRandomString();
  1938. $admin->saas_user_id = $audit->saas_user_id;
  1939. $admin->username = $audit->name;
  1940. // $admin->password = \Yii::$app->security->generatePasswordHash($audit->mobile);
  1941. // 默认密码改为cyyvipcom 与后台添加商城统一
  1942. if (!empty($audit->password)) {
  1943. $admin->password = $audit->password;
  1944. } else {
  1945. $admin->password = \Yii::$app->security->generatePasswordHash('123456');
  1946. };
  1947. $admin->mobile = $audit->mobile;
  1948. $admin->name = $audit->name;
  1949. $admin->type = 'store';
  1950. // $admin->saas_user_id = $audit->saas_user_id;
  1951. // $file_name = \Yii::$app->runtimePath . '/logs/app_wechat.log';
  1952. //file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 1 . ']' , FILE_APPEND);
  1953. if ($admin->save()) {
  1954. //判断后台开启通联
  1955. // $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value'];
  1956. // if ($oldConf) {
  1957. // $oldConf = json_decode($oldConf, true);
  1958. // if (!empty($oldConf) && !empty(trim($oldConf['appid']))) {
  1959. // //调用第三方会员创建接口
  1960. // $memberService = new MemberService();
  1961. // $res_member = $memberService->createMember($audit->store_number,2);
  1962. // if ($res_member['subCode'] == "FAIL"){
  1963. // throw new Exception($res_member['subMsg']);
  1964. // }
  1965. // }
  1966. // }
  1967. $salesman = null;
  1968. if ($audit->salesman_id > 0) {
  1969. $salesman = Salesman::findOne(['id' => $audit->salesman_id, 'is_delete' => 0]);
  1970. }
  1971. $store_apply_free = Option::get('store_apply_free', 0, 'saas', 0)['value'];
  1972. $store_apply_free_days = Option::get('store_apply_free_days', 0, 'saas', 0)['value'];
  1973. $end_time = time();
  1974. if ($store_apply_free) {
  1975. $end_time = strtotime("+". $store_apply_free_days." day");
  1976. }
  1977. $store = new Store();
  1978. $store->admin_id = $admin->id;
  1979. $store->logo = $audit->logo;
  1980. $store->created_at = time();
  1981. $store->end_time = $end_time;
  1982. // $store->store_number = $audit->store_number;
  1983. // $store->yunst_user_id = $res_member['data']['userId'] ?? '';
  1984. if ($audit->is_single_store == 0) {
  1985. $store->business_model = $business_model;
  1986. } else {
  1987. $store->business_model = 1;
  1988. }
  1989. $store->open_status = 0;
  1990. $store->store_admin = $audit->saas_user_id;
  1991. $store->name = $audit->name;
  1992. $store->salesman_id = $salesman ? $salesman->id : 0;
  1993. $store->province_id = $audit->province_id;
  1994. $store->city_id = $audit->city_id;
  1995. $store->district_id = $audit->district_id;
  1996. $admin->province_id = $audit->province_id;
  1997. $admin->city_id = $audit->city_id;
  1998. $admin->district_id = $audit->district_id;
  1999. if ($store->save()) {
  2000. $costParams = [
  2001. 'open_price' => 0,
  2002. 'renew_price' => 0,
  2003. 'end_time' => $end_time,
  2004. 'profit' => 0,
  2005. 'is_use_default' => 0,
  2006. ];
  2007. $store_apply_free = Option::get('store_apply_free_start', $store->id, 'store', '')['value'];
  2008. if($store_apply_free){
  2009. $store_apply_free_days = Option::get('store_apply_free_days', 0, 'saas', 5)['value'];
  2010. $costParams['end_time'] = time() + $store_apply_free_days * 86400;
  2011. }
  2012. $store_apply_buy_type = Option::get('store_apply_buy_type', 0, 'saas', 'free')['value'];//free/once/renew
  2013. Option::set('store_buy_type', $store_apply_buy_type, $store->id, 'store');
  2014. if($store_apply_buy_type == 'free'){
  2015. $costParams['open_price'] = 0;
  2016. $costParams['renew_price'] = 0;
  2017. $costParams['end_time'] = strtotime('2038-01-01 00:00:00');
  2018. }
  2019. if($store_apply_buy_type == 'once'){
  2020. $store_apply_buy_money = Option::get('store_apply_buy_money', 0, 'saas', 0)['value'];
  2021. $costParams['open_price'] = $store_apply_buy_money;
  2022. $costParams['renew_price'] = 0;
  2023. }
  2024. if($store_apply_buy_type == 'renew'){
  2025. $costParams['open_price'] = 0;
  2026. $costParams['renew_price'] = 0;
  2027. }
  2028. $this->setCost($store->id, $costParams);
  2029. // file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 2 . ']' , FILE_APPEND);
  2030. $admin->type_id = $store->id;
  2031. $admin->save();
  2032. // 绑定关系
  2033. if ($audit->saas_user_id) {
  2034. if (\Yii::$app->prod_is_dandianpu()) {
  2035. $saas_user = SaasUser::findOne(['id' => $audit->saas_user_id, 'is_delete' => 0]);
  2036. if ($saas_user) {
  2037. // $saas_user->store_id = $store->id;
  2038. // $saas_user->save();
  2039. }
  2040. // 创建云仓账号
  2041. // $this->createStoreCloud($audit->mobile, $store, $saas_user);
  2042. } else {
  2043. // Todo
  2044. //SaasStoreReferral::storeBindParent($saas_user->id, $store->id);
  2045. }
  2046. // if (!\Yii::$app->prod_is_dandianpu()) {
  2047. // $saas_store_referral = new SaasStoreReferral();
  2048. // $saas_store_referral->store_id = $store->id;
  2049. // $saas_store_referral->referral_id = $saas_user->id;
  2050. // if (!$saas_store_referral->save()) {
  2051. // $t->rollBack();
  2052. // \Yii::error("绑定关系失败");
  2053. // \Yii::error($saas_store_referral->errors);
  2054. // throw new \Exception("绑定关系失败");
  2055. // }
  2056. // }
  2057. }
  2058. // 初始化商城
  2059. $this->initStorageConfig($store->id);
  2060. // 设置商城名称
  2061. Option::set('name', $store->name, $store->id, 'store');
  2062. Option::set('logo', $store->logo, $store->id, 'store');
  2063. Option::set(OptionSetting::WECHAT_IS_SHENHE, '0', $store->id, 'wechat');
  2064. Option::set(OptionSetting::WECHAT_ALI_IS_SHENHE, '0', $store->id, 'wechat');
  2065. // 初始化DIY页面
  2066. // 初始化diy模板
  2067. $is = NewDiyTemplate::find()
  2068. ->where([
  2069. 'store_id' => $store->id,
  2070. 'is_delete' => 0,
  2071. 'type' => 100
  2072. ])->asArray()->one();
  2073. if (!$is) {
  2074. $this->initDiyTemplate($store->id);
  2075. }
  2076. //安装完成后装修表中的store_id比本商城的store_id还大 导致订单提交装修无法新增
  2077. //解决一下这个问题
  2078. $system_diy = NewDiyTemplate::find()
  2079. ->where([
  2080. 'store_id' => $store->id,
  2081. 'is_delete' => 0,
  2082. 'name' => 'system'
  2083. ])->asArray()->all();
  2084. $is_order_diy = false;
  2085. foreach ($system_diy as $diy_item) {
  2086. $template_detail = json_decode($diy_item['template'], true);
  2087. if (isset($template_detail['system_type']) && $template_detail['system_type'] === 'orderPreview') {
  2088. $is_order_diy = true;
  2089. }
  2090. }
  2091. if (!$is_order_diy) {
  2092. $submit = new NewDiyTemplate();
  2093. $submit->store_id = $store->id;
  2094. $submit->name = 'system';
  2095. $submit->template = '{"page_name":"订单提交","is_index":"0","page_type":1,"system_type":"orderPreview","page_link":"","theme":{"color":"#292929","time":1711097460417},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"#fcfcfc","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"订单预览页面-头部","type":"","comName":"orderPreviewHeader","icon":"","controlComName":"","params":[]},{"name":"订单预览页面-发货方式选择","type":"","comName":"orderPreviewDelivery","icon":"","controlComName":"orderPreviewDeliveryControl","params":{"type":"2","diy_express_name":"快递","diy_delivery_name":"同城","diy_shop_name":"自提"},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":0,"padding":0,"borderRadius":8}},{"name":"订单预览页面-订单主体信息","type":"","comName":"orderPreviewContent","icon":"","controlComName":"","params":[]}],"controlComName":"pageControl","id":"3395"}';
  2096. $submit->addtime = time();
  2097. $submit->type = 1;
  2098. $submit->save();
  2099. }
  2100. try {
  2101. $id = \queue_push(new StoreSyncJob(['type' => 1, 'to_id' => $store->id]), 0, 1);
  2102. debug_log($id, 'queuePush.log');
  2103. // $res = \app\models\StoreCopy::doCopy($default_store_id, $store->id, $default['type']);
  2104. } catch (\Exception $e) {
  2105. debug_log(['message' => $e->getMessage(), 'line' => $e->getLine()], 'queuePush.log');
  2106. }
  2107. //绑定二维码
  2108. if(isset($AggregateQrcode) && !empty($AggregateQrcode)){
  2109. $AggregateQrcode->store_id = $store->id;
  2110. $AggregateQrcode->salesman_id = $salesman ? $salesman->id : 0;
  2111. $AggregateQrcode->admin_id = $salesman ? $salesman->admin_id : 0;
  2112. $AggregateQrcode->shop_bind_time = time();
  2113. $res = $AggregateQrcode->save();
  2114. if(!$res){
  2115. \Yii::error("聚合码绑定失败");
  2116. \Yii::error($AggregateQrcode->errors);
  2117. throw new \Exception("聚合码绑定失败");
  2118. }
  2119. }
  2120. // if ($salesman) {
  2121. // $sales_admin = Admin::findOne($salesman->admin_id);
  2122. // $sales_saas_user_id = $sales_admin->saas_user_id;
  2123. // if ($sales_saas_user_id) {
  2124. // // 代理商绑定
  2125. // $saas_store_referral = new SaasStoreReferral();
  2126. // $saas_store_referral->store_id = $store->id;
  2127. // $saas_store_referral->referral_id = $sales_saas_user_id;
  2128. // if (!$saas_store_referral->save()) {
  2129. // throw new \Exception("代理商绑定失败");
  2130. // }
  2131. // }
  2132. // }
  2133. if ($audit->saas_user_id) {
  2134. // 绑定上级关系
  2135. // if(!SaasStoreReferral::storeBindParent($salesman, $store->id)){
  2136. // $t->rollBack();
  2137. // \Yii::error("绑定上级关系失败");
  2138. // throw new \Exception("绑定上级关系失败");
  2139. // }
  2140. }
  2141. try {
  2142. $merchant = new Merchant();
  2143. $merchant_info = new MerchantInfo();
  2144. $merchant_info->store_id = get_store_id();
  2145. $merchant_info->saas_user_id = $audit->saas_user_id;
  2146. $merchant_info->business_code = $merchant->getBusinessCode();
  2147. $merchant_info->bind_store_id = $store->id;
  2148. $merchant_info->app_status = "1,2";
  2149. $merchant_info->from = 1;
  2150. if (!$merchant_info->save()) {
  2151. \Yii::error($merchant_info->errors);
  2152. throw new \Exception("保存进件信息失败");
  2153. } else {
  2154. $audit->status = 1;
  2155. $audit->merchant_info_id = $merchant_info->id;
  2156. if (!$audit->save()) {
  2157. \Yii::error($audit->errors);
  2158. throw new \Exception("申请单修改失败");
  2159. }
  2160. }
  2161. } catch (\Exception $e) {
  2162. // throw new \Exception($e->getMessage());
  2163. }
  2164. // file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 3 . ']' , FILE_APPEND);
  2165. } else {
  2166. \Yii::error($store->errors);
  2167. throw new \Exception("店铺新增失败." . array_shift($store->getFirstErrors()));
  2168. }
  2169. } else {
  2170. \Yii::error($admin->errors);
  2171. throw new \Exception("新增管理员失败." . array_shift($admin->getFirstErrors()));
  2172. }
  2173. } else {
  2174. $audit->status = 2;
  2175. if (!$audit->save()) {
  2176. \Yii::error($audit->errors);
  2177. throw new \Exception("申请单修改失败");
  2178. }
  2179. }
  2180. if (\Yii::$app->prod_is_dandianpu()) {
  2181. if ($audit->saas_user_id) {
  2182. // 创建云仓账号
  2183. if (isset($store) && isset($saas_user)) {
  2184. $this->createStoreCloud($audit->mobile, $store, $saas_user);
  2185. }
  2186. }
  2187. }
  2188. $t->commit();
  2189. //申请通过发送短信
  2190. $str = '';
  2191. $res = NoticeSend::AgentExamine($id, 2);
  2192. if (isset($res['code']) && $res['code'] !== 0) {
  2193. // throw new \Exception('申请成功,短信发送失败');
  2194. $str = '短信发送失败';
  2195. }
  2196. return [
  2197. 'code' => 0,
  2198. 'store' => $store ? $store : null,
  2199. 'msg' => "操作成功," . $str
  2200. ];
  2201. } catch (\Exception $e) {
  2202. $t->rollBack();
  2203. return [
  2204. 'code' => 1,
  2205. 'msg' => $e->getMessage()
  2206. ];
  2207. }
  2208. }
  2209. // 创建云仓账号
  2210. public function createStoreCloud($mobile, $store, $saas_user){
  2211. try {
  2212. $cloud_token = get_platform_token();
  2213. if (empty($cloud_token)) {
  2214. throw new \Exception("获取云仓token失败");
  2215. }
  2216. if (!$saas_user) {
  2217. throw new \Exception("saas user不存在");
  2218. }
  2219. $storeCloud = StoreCloud::findOne(['is_delete' => 0, 'saas_user_id' => $saas_user->id]);
  2220. $purchase = Purchase::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]);
  2221. if (empty($storeCloud)) {
  2222. $domain = (new OptionSetting)->getCloudDomainName();
  2223. $url = "/cloud/purchase/createPurchase";
  2224. $data['access_token'] = $cloud_token;
  2225. $data['name'] = $store->name;
  2226. $data['logo'] = $saas_user->avatar;
  2227. $data['tel'] = $mobile;
  2228. $data['pwd'] = $mobile;
  2229. $result = cloud_post($domain . $url, $data);
  2230. $result = json_decode($result, true);
  2231. if ((int)$result['code'] > 0) {
  2232. throw new \Exception($result['msg']);
  2233. }
  2234. $mch_id = $result['data']['mch_id'];
  2235. $user_id = $result['data']['user_id'];
  2236. $storeCloud = new StoreCloud();
  2237. $storeCloud->store_id = 0;
  2238. $storeCloud->cloud_user_id = $user_id;
  2239. $storeCloud->cloud_store_id = $mch_id;
  2240. $storeCloud->saas_user_id = $saas_user->id;
  2241. $storeCloud->name = $store->name;
  2242. $storeCloud->password = $mobile;
  2243. $storeCloud->logo = $saas_user->avatar;
  2244. $storeCloud->type = 0;
  2245. $storeCloud->tel = $mobile;
  2246. $storeCloud->created_at = time();
  2247. $storeCloud->store_id = $store->id;
  2248. $storeCloud->province_id = $store->province_id;
  2249. $storeCloud->city_id = $store->city_id;
  2250. $storeCloud->district_id = $store->district_id;
  2251. $storeCloud->save();
  2252. } else {
  2253. // $storeCloud->name = $store->name;
  2254. // $storeCloud->password = $mobile;
  2255. $storeCloud->logo = $saas_user->avatar;
  2256. $storeCloud->saas_user_id = $saas_user->id;
  2257. $storeCloud->store_id = $store->id;
  2258. $storeCloud->province_id = $store->province_id;
  2259. $storeCloud->city_id = $store->city_id;
  2260. $storeCloud->district_id = $store->district_id;
  2261. $storeCloud->save();
  2262. }
  2263. if (!$purchase) {
  2264. $purchase = new \app\models\Purchase();
  2265. $purchase->store_cloud_id = $storeCloud->id;
  2266. $purchase->name = $store->name;
  2267. $purchase->mobile = $mobile;
  2268. $purchase->saas_user_id = $saas_user->id;
  2269. $purchase->status = 1;
  2270. $purchase->province_id = $store->province_id;
  2271. $purchase->city_id = $store->city_id;
  2272. $purchase->district_id = $store->district_id;
  2273. $purchase->save();
  2274. }
  2275. } catch (\Exception $e) {
  2276. return [
  2277. 'code' => 1,
  2278. 'msg' => $e->getMessage()
  2279. ];
  2280. }
  2281. }
  2282. //获取收款码
  2283. public function getQrcode ()
  2284. {
  2285. $business_model = (int)$this->business_model;
  2286. if (in_array($business_model, [1, 2, 3, 4])) {
  2287. if ($business_model === 1) {
  2288. $query = AggregateQrcode::find();
  2289. } else {
  2290. $query = AggregateSaasQrcode::find();
  2291. }
  2292. $qrcode = $query->where(['is_use' => 1, 'store_id' => 0])->select('id')->column();
  2293. return [
  2294. 'code' => 0,
  2295. 'msg' => "SUCCESS",
  2296. 'data' => $qrcode
  2297. ];
  2298. }
  2299. return [
  2300. 'code' => 0,
  2301. 'msg' => "SUCCESS",
  2302. 'data' => []
  2303. ];
  2304. }
  2305. }