| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace api\modules\v1\controllers;
- use api\controllers\OnAuthController;
- use common\enums\DiyEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\StatusEnum;
- use common\events\census\ViewsEvent;
- use common\models\diy\DiyComponentsData;
- use common\models\diy\DiyPage;
- use common\models\goods\GoodsCate;
- use common\models\mall\MallAddons;
- use common\models\order\Order;
- use common\models\user\User;
- use Yii;
- use yii\helpers\Json;
- use common\logic\statistics\StatisticsHandle;
- use common\enums\EventNameEnum;
- use common\models\goods\template\GoodsDecorationTemplate;
- use common\models\mall\Mall;
- /**
- * 装修控制器
- *
- *
- * Class DiyController
- * @package frontend\controllers
- */
- class DiyController extends OnAuthController
- {
- public $enableCsrfValidation = false;
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index', 'get-components-data'];
- /**
- * 获取装修页面
- * @return mixed|void
- */
- public function actionIndex()
- {
- $params = Yii::$app->request->get();
- // 验证
- $res = Yii::$app->services->validate->validate($params,[
- [['id'], 'safe'],
- [['id', 'goods_id'], 'integer'],
- [['template'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- if (isset($params['template'])) {
- $where[] = ['=', 'template', $params['template']];
- if ($params['template'] == DiyEnum::HOME_PAGE) {
- $where[] = ['=', 'is_home_page', StatusEnum::ENABLED];
- }
- } else {
- $where[] = ['=', 'id', $params['id']];
- }
- if($params['template'] == DiyEnum::GOODS_DETAIL){
- $data = GoodsDecorationTemplate::getGoodsDecoration($this->mall_id, $params['goods_id'] ?? 0);
- }else if ($params['template'] == 'store_steward'){
- $data = \addons\StoreSteward\common\models\AddonsStoreDiyPage::getOne([
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ['id' => $params['id']],
- ], true, [], '', 'id,title,content,is_show_bottom_nav');
- }else {
- // 获取装修页面内容
- $data = DiyPage::getOne($where, true, [], '', 'id,title,content,is_show_bottom_nav');
- $data['is_expire'] = Mall::getIsExpired($this->mall_id);
- }
- // 小程序配置替换修改
- if (!empty($data['content'])) {
- $platform = str_replace('-', '_', $this->platform);
- $data['content'] = str_replace([
- "{$platform}_appid",
- "{$platform}_app_path",
- ], [
- 'appid',
- 'app_path'
- ], $data['content']);
- // 如果非支付宝的情况下需要将支付宝入群按钮移除
- }
- // 获取商城有效的插件
- // $valid_addons = MallAddons::getValidAddons($this->mall_id);
- // $data['valid_addons'] = $valid_addons;
- //浏览
- $event = new ViewsEvent($this->mall_id);
- $event_data['mall_id'] =$this->mall_id;
- $event_data['user_id'] =$this->user_id??0;
- $event_data['goods_id'] = $params['goods_id']??0;
- \Yii::$app->services->events->dispatch($event, $event_data, $event->listeners);
-
- return $this->success('',$data);
- }
- /**
- * 根据标识获取对应组件的内容
- * @Author: lun
- * @DateTime: 2021/11/2 0002 14:23
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionGetComponentsData()
- {
- $params = Yii::$app->request->post('form');
- $list = Json::decode($params, true);
- if (empty($list)) return $this->error('请求数据为空');
- // 获取数据
- $user_id = $this->user_id > 0 ? $this->user_id : 0;
- $data = DiyComponentsData::getCompentsData($this->mall_id, $list, $user_id);
- return $this->success('操作成功',$data);
- }
- }
|