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); } } }