| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace business\controllers;
- use biz\admin\services\AdminToMerchantService;
- use biz\auth\services\MenuService;
- use biz\goods\services\CategoryRelateService;
- use biz\goods\services\UsageRelationService;
- use biz\merchant\services\AdminService;
- use biz\merchant\services\MerchantAssetService;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantService;
- use common\components\error;
- use common\components\jwt;
- use common\components\stringUtil;
- use common\components\validate;
- use common\services\xhUserService;
- use Yii;
- use common\services\xhWxOpenService;
- use common\services\xhMerchantAssetService;
- use common\services\xhMerchantExtendService;
- use common\services\xhMerchantService;
- use common\services\xhAdminService;
- use common\components\util;
- use common\components\weixinUtil;
- use common\components\jsSDK;
- use common\services\xhAdminToMerchantService;
- use yii\web\Cookie;
- class BaseController extends PublicController
- {
- public $admin, $adminId, $adminAvatar, $account;
- public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
- public $openMerchant, $openMerchantId;
- public $appId;
- public $isWeixin = false;
- public $isLogin = false;
- public $withoutLogin = [];//不需要登陆的方法名
- public $validate = true;
- protected $service;
- // 设置允许与不允许方法 shizq 2019-12-05
- protected $allowActions = [];
- protected $notAllowActions = [];
-
- public function beforeAction($action)
- {
- //token验证
- //$adminId = jwt::getLoginId();
- $adminId = 1;
- if (empty($adminId)) {
- $this->validate = false;
- }
- //方法开放设置 shizq 2019-12-05
- if (in_array($action->id, $this->notAllowActions)) {
- util::fail($action->id . ' not allow');
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- $admin = AdminService::getById($adminId);
- if (empty($admin)) {
- util::fail('没有找到管理员');
- }
- $merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
- if (empty($merchantId)) {
- util::fail('没有找到商家信息');
- }
- $merchant = MerchantService::getById($merchantId);
- $merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
- $merchantAsset = MerchantAssetService::getByMerchantId($merchantId);
- Yii::$app->params['adminId'] = $adminId;
- Yii::$app->params['admin'] = $admin;
- Yii::$app->params['merchantId'] = $merchantId;
- Yii::$app->params['merchant'] = $merchant;
- Yii::$app->params['merchant'] = $merchant;
- Yii::$app->params['merchantAsset'] = $merchantAsset;
- Yii::$app->params['merchantExtend'] = $merchantExtend;
- $this->adminId = $adminId;
- $this->merchantId = $merchantId;
- $this->merchant = $merchant;
- $this->merchantExtend = $merchantExtend;
- $this->merchantAsset = $merchantAsset;
- return parent::beforeAction($action);
- }
- public function actionList()
- {
- $where = null;
- $service = $this->service;
- $list = $service::getList('*', $where);
- util::success($list);
- }
- public function actionAdd()
- {
- $data = Yii::$app->request->post();
- $service = $this->service;
- $re = $service::add($data);
- util::success($re);
- }
- public function actionGet()
- {
- $id = Yii::$app->request->get('id');
- $service = $this->service;
- $ad = $service::getById($id);
- util::success($ad);
- }
- public function actionUpdate()
- {
- $data = Yii::$app->request->post();
- $id = $data['id'];
- $service = $this->service;
- $re = $service::updateById($id, $data);
- util::success($re);
- }
- public function actionDelete()
- {
- $id = Yii::$app->request->get('id');
- $service = $this->service;
- $re = $service::deleteById($id);
- util::success($re);
- }
- }
|