public function actionSave()
 {
     $accountId = $this->getAccountId();
     $adminId = $this->getParams("id");
     $admin = User::findOne($adminId);
     if ($admin == null) {
         return ['code' => 1209, 'msg' => 'not login'];
     }
     $name = $this->getParams('name', '');
     if ($name == '') {
         return ['code' => 1202, 'msg' => 'Name is required.'];
     }
     $category = $this->getParams('category', '');
     if ($category == '') {
         return ['code' => 1202, 'msg' => 'Category is required.'];
     }
     $radio = $this->getParams('radio', true);
     $cookingtypeId = $this->getParams('cookingtypeId', '');
     $cookingType = null;
     if ($cookingtypeId != '') {
         $cookingType = CookingType::findOne($cookingtypeId);
         if ($cookingType == null) {
             return ['code' => 1204, 'msg' => 'cooking type not found.'];
         } else {
             $cookingTypes = CookingType::find()->where(['category' => $cookingType->name])->all();
             for ($i = 0; $i < count($cookingTypes); $i++) {
                 $cookingTypes[$i]->category = $name;
                 $cookingTypes[$i]->save();
             }
         }
     } else {
         $cookingType = new CookingType();
     }
     $cookingType->name = $name;
     $cookingType->category = $category;
     $cookingType->operator = $admin['name'];
     $cookingType->radio = $radio . '';
     $cookingType->accountId = $accountId;
     $cookingType->save();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'save success'];
 }
Beispiel #2
0
 public static function initCookingType($accountId)
 {
     if (self::checkExist($accountId, '最新食譜')) {
         $cookingType = new CookingType();
         $cookingType->name = '最新食譜';
         $cookingType->category = '固定分類';
         $cookingType->operator = '';
         $cookingType->accountId = $accountId;
         $cookingType->save();
     }
 }