public function actionCookbookBatchHandle()
 {
     $accountId = $this->getAccountId();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $operation = $this->getParams('operation', '');
     if (strlen($operation) == 0) {
         return ['code' => 1202, 'msg' => 'operation is required.'];
     }
     $onSaleTime = $this->getParams('onSaleTime', '');
     $cookbookId = $this->getParams('cookbookId', '');
     $tags = $this->getParams('tags', '');
     if (count($cookbookId) <= 0) {
         return ['code' => 1202, 'msg' => 'cookbookId is required.'];
     }
     if ($operation == 'on') {
         for ($i = 0; $i < count($cookbookId); $i++) {
             $cookbook = Cookbook::findOne($cookbookId[$i]);
             if ($cookbook == null) {
                 return ['code' => 1204, 'msg' => 'cookbook not found.'];
             }
             $cookbook->active = 'Y';
             if ($onSaleTime == '') {
                 $onSaleTime = time();
             } else {
                 $onSaleTime = strlen($onSaleTime) > 0 ? $onSaleTime / 1000 : null;
             }
             $cookbook->startDate = $onSaleTime;
             //Sort time
             $activeSortTime = $cookbook->activeSortTime;
             $inactiveSortTime = $cookbook->inactiveSortTime;
             if ($activeSortTime == null) {
                 $activeSortTime = $cookbook->createdDate;
                 $inactiveSortTime = $cookbook->createdDate;
             }
             $activeSortTime = time();
             $inactiveSortTime = $cookbook->endDate;
             $cookbook->activeSortTime = $activeSortTime;
             $cookbook->inactiveSortTime = $inactiveSortTime;
             $cookbook->save();
         }
     } else {
         if ($operation == 'off') {
             for ($i = 0; $i < count($cookbookId); $i++) {
                 $cookbook = Cookbook::findOne($cookbookId[$i]);
                 if ($cookbook == null) {
                     return ['code' => 1204, 'msg' => 'cookbook not found.'];
                 }
                 $cookbook->active = 'N';
                 //Sort time
                 $activeSortTime = $cookbook->activeSortTime;
                 $inactiveSortTime = $cookbook->inactiveSortTime;
                 if ($activeSortTime == null) {
                     $activeSortTime = $cookbook->createdDate;
                     $inactiveSortTime = $cookbook->createdDate;
                 }
                 $inactiveSortTime = time();
                 $activeSortTime = $cookbook->startDate;
                 $cookbook->activeSortTime = $activeSortTime;
                 $cookbook->inactiveSortTime = $inactiveSortTime;
                 $cookbook->save();
             }
         } else {
             if ($operation == 'del') {
                 for ($i = 0; $i < count($cookbookId); $i++) {
                     Cookbook::deleteAll(['_id' => $cookbookId[$i]]);
                 }
             } else {
                 if ($operation == 'tags') {
                     for ($i = 0; $i < count($cookbookId); $i++) {
                         $cookbook = Cookbook::findOne($cookbookId[$i]);
                         if ($cookbook == null) {
                             return ['code' => 1204, 'msg' => 'cookbook not found.'];
                         }
                         $cookbook->type = array_merge($cookbook->type, $tags);
                         $cookbook->save();
                     }
                 }
             }
         }
     }
     return ['code' => 200, 'msg' => 'OK'];
 }
 public function actionDelete()
 {
     $this->_setJSONFormat(Yii::$app);
     $request = Yii::$app->request;
     $id = $request->post('id');
     $cookbookBatch = CookBookBatch::findOne([$id]);
     $cookbooks = $cookbookBatch->cookbooks;
     foreach ($cookbooks as $cookbook) {
         $cookbookId = $cookbook['cookbookId'];
         $cb = Cookbook::findOne($cookbookId);
         $cb->delete();
     }
     $cookbookBatch->delete();
     return ['code' => '-1'];
 }