public function actionSave() { $accountId = $this->getAccountId(); $request = Yii::$app->request; $adminId = $request->post("id"); $admin = User::findOne($adminId); if ($admin == null) { return ['code' => 1209, 'msg' => 'not login']; } $cookbookId = $request->post('cookbookId', null); $title = $request->post('title', ''); $image = $request->post('image', ''); $content = $request->post('content', ''); $ingredient = $request->post('ingredient', []); $startDate = $request->post('startDate', ''); $endDate = $request->post('endDate', ''); $shareUrl = $request->post('shareUrl', ''); $isSampleOpen = $request->post('isSampleOpen', 'N'); $sample = $request->post('sample', []); $active = $request->post('active', 'Y'); $type = $request->post('type', []); $video = $request->post('video', ''); $restaurantName = $request->post('restaurantName', ''); $cookName = $request->post('cookName', ''); $tip = $request->post('tip', ''); $creativeExperience = $request->post('creativeExperience', ''); $deliciousSecret = $request->post('deliciousSecret', ''); $cookbook = null; if ($cookbookId != null) { $cookbook = Cookbook::findOne($cookbookId); } if ($cookbook == null) { $cookbook = new Cookbook(); $cookbook->createdDate = time(); } //Sort time $activeSortTime = $cookbook->activeSortTime; $inactiveSortTime = $cookbook->inactiveSortTime; if ($activeSortTime == null) { $activeSortTime = $cookbook->createdDate; $inactiveSortTime = $cookbook->createdDate; } if ($active == 'Y' && $startDate / 1000 < time()) { if ($cookbook->startDate < time() && $cookbook->active == 'Y') { $inactiveSortTime = $endDate / 1000; } else { $activeSortTime = time(); $inactiveSortTime = $endDate / 1000; } } else { if ($cookbook->startDate < time() && $cookbook->active == 'Y') { $inactiveSortTime = time(); $activeSortTime = $startDate / 1000; } else { $activeSortTime = $startDate / 1000; } } $cookbook->activeSortTime = $activeSortTime; $cookbook->inactiveSortTime = $inactiveSortTime; //lock samples for ($i = 0; $i < count($cookbook->sample); $i++) { $result = Sample::unlockSample($cookbook->sample[$i]); } for ($j = 0; $j < count($sample); $j++) { $result = Sample::lockSample($sample[$j]); if ($result['code'] == 500) { return ['code' => 1204, 'msg' => $result]; } } $cookbook->title = $title; $cookbook->image = $image; $cookbook->content = $content; $cookbook->ingredient = $this->clearHashKey($ingredient); $cookbook->startDate = strlen($startDate) > 0 ? $startDate / 1000 : null; $cookbook->endDate = strlen($endDate) > 0 ? $endDate / 1000 : null; $cookbook->isSampleOpen = $isSampleOpen; $cookbook->sample = $this->clearHashKey($sample); $cookbook->active = $active; $cookbook->updatedDate = time(); $cookbook->operator = $admin['name']; $cookbook->type = $type; $cookbook->shareUrl = $shareUrl; $cookbook->accountId = $accountId; $cookbook->video = $video; $cookbook->restaurantName = $restaurantName; $cookbook->cookName = $cookName; $cookbook->hasImportImg = true; $cookbook->tip = $tip; $cookbook->creativeExperience = $creativeExperience; $cookbook->deliciousSecret = $deliciousSecret; $cookbook->save(); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return $cookbook->_id; }
public function actionDelete() { $sampleId = $this->getParams('sampleId', ''); $sample = Sample::find()->where(['_id' => $sampleId])->one(); if ($sample == '') { return ['code' => 1300, 'msg' => 'sample not found']; } $sample->isDeleted = true; $sample->save(); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['code' => 200, 'msg' => 'OK']; }