1, 'msg' => '保存模板数据为空' ]; } $controls = post_params('controls'); $id = post_params('id', 0); $name = post_params('name', "DIY"); $is_index = post_params('is_index', 0); $level = post_params('level',-1);// 默认是普通用户 $type = post_params('type', 0); if ($is_index) { NewDiyTemplate::updateAll(['is_index' => 0], ['store_id' => get_store_id(), 'is_delete' => 0]); // 如果是首页的话 $template中的level字段设置为0 -1是普通用户 0是首页不判断 大于0是会员等级的用户 $level = 0;// 首页用0 } $form = NewDiyTemplate::findOne(['store_id' => get_store_id(), 'is_delete' => 0, 'id' => $id]) ?: new NewDiyTemplate(); $form->store_id = get_store_id(); $form->name = $name; $form->template = $template; $form->is_delete = 0; $form->is_index = $is_index; $form->addtime = time(); $form->type = $type; $form->level = $level; if ($form->save()) { // 保存控件 if ($controls) { self::saveControls($controls); } return [ 'code' => 0, 'msg' => '保存成功', 'data' => [ 'template' => $form, 'controls' => NewDiyTemplate::find() ->where([ 'store_id' => get_store_id(), 'is_delete' => 0, 'type' => 100 ])->asArray()->one()['template'] ] ]; } else { return [ 'code' => 1, 'msg' => $form->errors ]; } } public static function saveControls($controls) { // controls type=100 $controlsDiy = NewDiyTemplate::findOne(['store_id' => get_store_id(), 'is_delete' => 0, 'type' => 100]) ?: new NewDiyTemplate(); $controlsDiy->store_id = get_store_id(); $controlsDiy->name = 'controls'; $controlsDiy->template = $controls; $controlsDiy->is_delete = 0; $controlsDiy->addtime = time(); $controlsDiy->type = 100; $controlsDiy->save(); } public static function getNewTemplateList() { $query = NewDiyTemplate::find() ->where([ 'store_id' => get_store_id(), 'is_delete' => 0, ]); $list = $query->andWhere(['!=', 'type', 100])->orderBy(['id' => SORT_ASC])->asArray()->all(); foreach ($list as &$item) { $template = json_decode($item['template'], true); if ($template['system_type'] === 'goodsDetail') { foreach ($template['templates'] as &$tem) { if ($tem['comName'] === "goodsSwiperImgs") { if (!isset($tem['params']['showFenxiao'])) { $tem['params'] = array_merge($tem['params'], [ 'showFenxiao' => true, 'margin' => 0 ]); } } } } $item['template'] = json_encode($template, JSON_UNESCAPED_UNICODE); } // 这里需要查询发挥是否商城开启以图搜图功能 $imageSearchStatus = (int)Option::get('tencent_image_setting_status',0,'saas',0)['value']; $store = Store::findOne(get_store_id()); $controls = NewDiyTemplate::find() ->where([ 'store_id' => get_store_id(), 'is_delete' => 0, 'type' => 100 ])->asArray()->one()['template']; if ($store && intval($store->business_model) !== 1 && get_store_id() != -1) { if ($controls) { $controls = json_decode($controls, true); unset($item); foreach ($controls as $index => $item) { if ($item['show_type'] === 'nav') { unset($controls[$index]); } } $controls = json_encode(array_values($controls), JSON_UNESCAPED_UNICODE); } } if (get_store_id() > 0 && \Yii::$app->prod_is_dandianpu()) {//供应链系统未使用小程序店铺且使用共享流量店铺开关时候 就增加联盟商家 $self_mini = Option::get('self_mini', get_store_id(), 'store', 0)['value']; $is_store_traffic_sharing = Option::get('is_store_traffic_sharing', get_store_id(), 'store', 1)['value']; $switch_store = intval(Option::get('one_store_switch_store', 0, 'saas', 0)['value']); $is_store_traffic_sharing_switch = false; if (intval($is_store_traffic_sharing) && !intval($self_mini) && $switch_store) { $is_store_traffic_sharing_switch = true; } $controls_arr = json_decode($controls, true); foreach ($controls_arr as &$control_item) { if ($control_item['controlComName'] == 'widgetNavControl') { $tab_open = true; foreach ($control_item['params']['navList'] as $nav_index => &$nav_item) { if (isset($nav_item['tab_type']) && $nav_item['tab_type'] == 'store_sharing') { $nav_item['link']['link'] = '/allianceStore/index/index'; $nav_item['link']['open_type'] = 'navigate'; if (!$is_store_traffic_sharing_switch) { unset($control_item['params']['navList'][$nav_index]); } $tab_open = false; } } $control_item['params']['navList'] = array_values($control_item['params']['navList']); if ($tab_open && $is_store_traffic_sharing_switch) { array_push($control_item['params']['navList'], [ "pic_url" => 'https://' . \Yii::$app->request->hostName. '/web/v1/statics/clientImg/shop/store.png', "active_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/storeActive.png', "nav_text" => "联盟商家", "tab_type" => "store_sharing", "link" => [ "name" => "联盟商家", "link" => "/allianceStore/index/index", "open_type" => "navigate", "params" => [], "id" => "9421" ] ]); } } } $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE); } return [ 'code' => 0, 'msg' => '加载成功', 'data' => [ 'list' => $list, 'image_search_status' => $imageSearchStatus, 'business_model' => intval($store->business_model), 'controls' => $controls ] ]; } }