asArray()->all(); $processRuleTree = Tree::ruleTree($processRule); return $processRuleTree; } public function actionNoteList(){ $get = \Yii::$app->request->get(); $this->requestValidate($get, [ ['rule_id', 'required'] ]); $ruleNotes = ProcessRuleNote::find()->where(['rule_id' => $get['rule_id']])->asArray()->all(); return $ruleNotes; } public function actionAdd(){ $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['name', 'required'], ['pid','required'], ['calc_method','in','range'=>[1,2,3]], [['name','unit'],'string'], ['price','double'] ]); $processRule = new ProcessRule(); $processRule->attributes = $post; $res = $processRule->save(); if(!$res){ throw new \Exception('添加加工规则失败'); } return ['success']; } public function actionAddNote(){ $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['rule_id', 'required'], ['note', 'required'] ]); $processRuleNote = new ProcessRuleNote(); $processRuleNote->attributes = $post; $res = $processRuleNote->save(); if(!$res){ throw new \Exception('添加加工规则备注失败'); } return ['success']; } public function actionUpdate(){ $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['name', 'required'], ['id','required'] ]); $processRule = ProcessRule::find()->where(['id' => $post['id']])->one(); $processRule->name = $post['name']; $processRule->calc_method = $post['calc_method']; $processRule->price = $post['price']; $processRule->unit = $post['unit']; $res = $processRule->saveOrFail(); if(!$res){ throw new \Exception('更新加工规则失败'); } return ['success']; } public function actionUpdateNote(){ $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['note', 'required'], ['id','required'] ]); $processRuleNote = ProcessRuleNote::find()->where(['id' => $post['id']])->one(); $processRuleNote->note = $post['note']; $res = $processRuleNote->saveOrFail(); if(!$res){ throw new \Exception('更新加工规则备注失败'); } return ['success']; } public function actionDelete(){ $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['id','required'] ]); $processRule = ProcessRule::find()->where(['id' => $post['id']])->one(); if(!$processRule){ throw new \Exception("规则不存在"); } if($processRule->pid){ $processRuleNote = new ProcessRuleNote(); $processRuleNote->rule_id = $processRule->id; $processRuleNote->delete(); } $processRule->delete(); return ['success']; } public function actionDeleteNote(){ $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['id','required'] ]); $processRuleNote = ProcessRuleNote::find()->where(['id' => $post['id']])->one(); if(!$processRuleNote){ throw new \Exception("规则备注不存在"); } $processRuleNote->delete(); return ['success']; } }