| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <?php
- namespace addons\Scratch\backend\controllers;
- use addons\Scratch\common\logic\ScratchLogic;
- use addons\Scratch\common\models\ScratchModel;
- use Yii;
- /**
- * Class ScratchController
- * @package addons\Scratch\backend\controllers
- */
- class ScratchController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * @return string
- */
- public function actionIndex()
- {
- return $this->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());
- }
- }
- }
|