render('index'); } /** * @return string */ public function actionEdit() { return $this->render('edit'); } /** * @return string */ public function actionLogIndex() { return $this->render('log-index'); } /** * @return string */ public function actionOrderIndex() { return $this->render('order-index'); } /** * 获取列表信息 * @return mixed|void */ public function actionGetList() { try { $postData = \Yii::$app->request->get(); $userId = \Yii::$app->request->get('user_id', ''); $res = \Yii::$app->services->validate ->validate( $postData, [ [['page', 'type', 'keyword'], 'safe'], [['page'], 'default', 'value' => 1], [['type'], 'default', 'value' => 0], ] ); if ($res === false) { throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage()); } return $this->success('ok', ScratchLogic::getList( $this->mall_id, $userId, $postData )); } catch (\ErrorException $errorException) { return $this->error($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * 获取列表信息 * @return mixed|void */ public function actionGetLogList() { try { $postData = \Yii::$app->request->get(); $userId = \Yii::$app->request->get('user_id', ''); $res = \Yii::$app->services->validate ->validate( $postData, [ [['page', 'type', 'keyword'], 'safe'], [['page'], 'default', 'value' => 1], [['type'], 'default', 'value' => 0], ] ); if ($res === false) { throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage()); } return $this->success('ok', ScratchLogic::getLogList( $this->mall_id, $userId, $postData )); } catch (\ErrorException $errorException) { return $this->error($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @return mixed|void * @throws \Exception */ public function actionGetEdit() { try { $id = \Yii::$app->request->get('id', 0); return $this->success('ok', ScratchLogic::getEdit($id, $this->mall_id)); } catch (\ErrorException $errorException) { return $this->error($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @return mixed|void * @throws \Exception */ public function actionSearchGoods() { try { $getData = \Yii::$app->request->get(); return $this->success('ok', ScratchLogic::searchGoods($this->mall_id, $getData)); } catch (\ErrorException $errorException) { return $this->error($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @return mixed|void * @throws \Exception */ public function actionSaveEdit() { try { if (!\Yii::$app->request->isPost) { throw new \ErrorException('NOT IS POST!'); } $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate ->validate( $params, [ [['name'], 'required'], [['name', 'pic', 'type', 'goods_id', 'attr_id', 'num', 'price', 'coupon_id', 'stock', 'balance', 'status'], 'safe'], ] ); if ($res === false) { throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage()); } return $this->success('保存成功', ScratchLogic::saveEdit($this->mall_id, $params)); } catch (\ErrorException $errorException) { return $this->error($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @return \yii\web\Response */ public function actionEditStatus() { try { if (!\Yii::$app->request->isPost) { throw new \ErrorException('NOT IS POST!'); } $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate ->validate( $params, [ [['id'], 'required'], [['status'], 'safe'], ] ); if ($res === false) { throw new \ErrorException(\Yii::$app->services->validate->getErrorMessage()); } return $this->success('操作成功', ScratchLogic::saveEditStatus($this->mall_id, $params)); } catch (\ErrorException $errorException) { return $this->error($errorException->getMessage()); } catch (\Exception $exception) { throw new \Exception($exception->getMessage()); } } /** * @return mixed|void|\yii\web\Response * @throws \Exception */ public function actionDelete() { try { if (!\Yii::$app->request->isPost) { throw new \ErrorException('NOT IS POST!'); } $id = \Yii::$app->request->post('id'); $ScratchModel = ScratchModel::findOne($id); if (!$ScratchModel) { throw new \ErrorException('信息不存在或已被删除'); } $ScratchModel->status = -1; if (!$ScratchModel->save()) { throw new \ErrorException('删除失败'); } return $this->success('删除成功'); }catch (\ErrorException $errorException){ return $this->error($errorException->getMessage()); }catch (\Exception $exception){ throw new \Exception($exception->getMessage()); } } }