DiyController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use api\controllers\OnAuthController;
  4. use common\enums\DiyEnum;
  5. use common\enums\OrderStatusEnum;
  6. use common\enums\StatusEnum;
  7. use common\events\census\ViewsEvent;
  8. use common\models\diy\DiyComponentsData;
  9. use common\models\diy\DiyPage;
  10. use common\models\goods\GoodsCate;
  11. use common\models\mall\MallAddons;
  12. use common\models\order\Order;
  13. use common\models\user\User;
  14. use Yii;
  15. use yii\helpers\Json;
  16. use common\logic\statistics\StatisticsHandle;
  17. use common\enums\EventNameEnum;
  18. use common\models\goods\template\GoodsDecorationTemplate;
  19. use common\models\mall\Mall;
  20. /**
  21. * 装修控制器
  22. *
  23. *
  24. * Class DiyController
  25. * @package frontend\controllers
  26. */
  27. class DiyController extends OnAuthController
  28. {
  29. public $enableCsrfValidation = false;
  30. public $modelClass = '';
  31. /**
  32. * 不用进行登录验证的方法
  33. *
  34. * 例如: ['index', 'update', 'create', 'view', 'delete']
  35. * 默认全部需要验证
  36. *
  37. * @var array
  38. */
  39. protected $authOptional = ['index', 'get-components-data'];
  40. /**
  41. * 获取装修页面
  42. * @return mixed|void
  43. */
  44. public function actionIndex()
  45. {
  46. $params = Yii::$app->request->get();
  47. // 验证
  48. $res = Yii::$app->services->validate->validate($params,[
  49. [['id'], 'safe'],
  50. [['id', 'goods_id'], 'integer'],
  51. [['template'], 'string'],
  52. ]);
  53. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  54. $where[] = ['=', 'mall_id', $this->mall_id];
  55. $where[] = ['=', 'status', StatusEnum::ENABLED];
  56. if (isset($params['template'])) {
  57. $where[] = ['=', 'template', $params['template']];
  58. if ($params['template'] == DiyEnum::HOME_PAGE) {
  59. $where[] = ['=', 'is_home_page', StatusEnum::ENABLED];
  60. }
  61. } else {
  62. $where[] = ['=', 'id', $params['id']];
  63. }
  64. if($params['template'] == DiyEnum::GOODS_DETAIL){
  65. $data = GoodsDecorationTemplate::getGoodsDecoration($this->mall_id, $params['goods_id'] ?? 0);
  66. }else if ($params['template'] == 'store_steward'){
  67. $data = \addons\StoreSteward\common\models\AddonsStoreDiyPage::getOne([
  68. ['mall_id' => $this->mall_id],
  69. ['status' => StatusEnum::ENABLED],
  70. ['id' => $params['id']],
  71. ], true, [], '', 'id,title,content,is_show_bottom_nav');
  72. }else {
  73. // 获取装修页面内容
  74. $data = DiyPage::getOne($where, true, [], '', 'id,title,content,is_show_bottom_nav');
  75. $data['is_expire'] = Mall::getIsExpired($this->mall_id);
  76. }
  77. // 小程序配置替换修改
  78. if (!empty($data['content'])) {
  79. $platform = str_replace('-', '_', $this->platform);
  80. $data['content'] = str_replace([
  81. "{$platform}_appid",
  82. "{$platform}_app_path",
  83. ], [
  84. 'appid',
  85. 'app_path'
  86. ], $data['content']);
  87. // 如果非支付宝的情况下需要将支付宝入群按钮移除
  88. }
  89. // 获取商城有效的插件
  90. // $valid_addons = MallAddons::getValidAddons($this->mall_id);
  91. // $data['valid_addons'] = $valid_addons;
  92. //浏览
  93. $event = new ViewsEvent($this->mall_id);
  94. $event_data['mall_id'] =$this->mall_id;
  95. $event_data['user_id'] =$this->user_id??0;
  96. $event_data['goods_id'] = $params['goods_id']??0;
  97. \Yii::$app->services->events->dispatch($event, $event_data, $event->listeners);
  98. return $this->success('',$data);
  99. }
  100. /**
  101. * 根据标识获取对应组件的内容
  102. * @Author: lun
  103. * @DateTime: 2021/11/2 0002 14:23
  104. * @Copyright: copyright (c) 2021 广东七件事集团
  105. */
  106. public function actionGetComponentsData()
  107. {
  108. $params = Yii::$app->request->post('form');
  109. $list = Json::decode($params, true);
  110. if (empty($list)) return $this->error('请求数据为空');
  111. // 获取数据
  112. $user_id = $this->user_id > 0 ? $this->user_id : 0;
  113. $data = DiyComponentsData::getCompentsData($this->mall_id, $list, $user_id);
  114. return $this->success('操作成功',$data);
  115. }
  116. }