| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\DiyTemplate;
- use app\models\NewDiyTemplate;
- use app\models\Option;
- use app\models\Store;
- use yii\base\Model;
- use yii\helpers\Json;
- class NewDiyForm extends Model
- {
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [[]]
- ];
- }
- public function attributeLabels()
- {
- return [
- ];
- }
- /**
- * 新diy
- * @return array
- */
- public static function saveNewTemplate()
- {
- $template = post_params('template');
- if ($template == '{}') {
- return [
- 'code' => 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
- ]
- ];
- }
- }
|