250], [['form_name'], 'default', 'value' => '我的表单'], [['is_form'], 'default', 'value' => 0], ]; } public function save() { if (!$this->validate()) { return $this->getErrorSummary(false)[0]; } $t = \Yii::$app->db->beginTransaction(); Form::updateAll(['is_delete' => 1], ['store_id' => $this->store_id]); if ($this->is_form == 1) { if (!$this->form_list) { return [ 'code'=>1, 'msg'=>'请填写表单设置' ]; } } if ($this->form_list) { $this->form_list = array_values($this->form_list); foreach ($this->form_list as $index => $value) { if (!$value['name']) { return [ 'code' => 1, 'msg' => '请输入字段名称' ]; } if (in_array($value['type'], ['radio', 'checkbox'])) { if (!$value['default']) { return [ 'code' => 1, 'msg' => '请输入单选或多选的默认值' ]; } } if ($value['id']) { $form = Form::findOne(['store_id' => $this->store_id, 'id' => $value['id']]); } else { $form = new Form(); } $form->is_delete = 0; $form->created_at = time(); $form->type = $value['type']; $form->name = $value['name']; $form->default = $value['default']; $form->required = $value['required'] ? $value['required'] : 0; $form->tip = $value['tip']; $form->sort = $index; $form->store_id = $this->store_id; if(!$form->save()){ $t->rollBack(); return [ 'code' => 1, 'msg' => $form->errors[0] ]; } } } $t->commit(); Option::set('is_form', $this->is_form, $this->store_id, 'store'); Option::set('form_name', $this->form_name, $this->store_id, 'store'); return [ 'code' => 0, 'msg' => '成功' ]; } }