| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace addons\SmartForm\backend\controllers;
- use addons\SmartForm\common\models\SmartFormTemplateGoods;
- use common\enums\StatusEnum;
- use common\helpers\FormatHelper;
- use addons\SmartForm\common\models\AddonsSmartFormTemplate; # 装修表单
- use Yii;
- /**
- * 表单商品管理
- *
- * Class FormGoodsController
- * @package addons\SmartForm\backend\controllers
- */
- class FormGoodsController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 获取商品关联表单信息
- * @return mixed|void
- */
- public function actionInfo()
- {
- try {
- $get = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['goods_id'], 'required'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $where[] = ['=', 'goods_id', $get['goods_id']];
- $with = ['template'];
- $info = SmartFormTemplateGoods::getOne($where, true,$with);
- if (!$info) {
- return $this->error('商品未关联表单');
- }
- //$template = AddonsSmartFormTemplate::findOne(['id' => $info['template_id']]);
- //$info['template'] = $template->toArray();
- $this->success('获取成功', $info);
- } catch (\Exception $e) {
- $exception = FormatHelper::exception($e, "获取表单商品失败");
- Yii::error($exception);
- return $this->error($exception);
- }
- }
- /**
- * 保存商品关联表单
- * @return mixed|void
- */
- public function actionEdit()
- {
- try {
- $request = Yii::$app->request;
- if ($request->isPost) {
- $post = Yii::$app->request->post('form');
- $post = json_decode($post,true);
- $res = Yii::$app->services->validate->validate($post, [
- [['goods_id'], 'required'],
- [['status', 'template_id', 'goods_id'], 'integer'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $post['mall_id'] = $this->mall_id;
- SmartFormTemplateGoods::setData($post);
- return $this->success('操作成功');
- }
- } catch (\Exception $e) {
- $exception = FormatHelper::exception($e, "保存表单商品失败");
- Yii::error($exception);
- return $this->error($exception);
- }
- }
- }
|