BaseController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace business\controllers;
  3. use biz\admin\services\AdminToMerchantService;
  4. use biz\auth\services\MenuService;
  5. use biz\goods\services\CategoryRelateService;
  6. use biz\goods\services\UsageRelationService;
  7. use biz\merchant\services\AdminService;
  8. use biz\merchant\services\MerchantAssetService;
  9. use biz\merchant\services\MerchantExtendService;
  10. use biz\merchant\services\MerchantService;
  11. use common\components\error;
  12. use common\components\jwt;
  13. use common\components\stringUtil;
  14. use common\components\validate;
  15. use common\services\xhUserService;
  16. use Yii;
  17. use common\services\xhWxOpenService;
  18. use common\services\xhMerchantAssetService;
  19. use common\services\xhMerchantExtendService;
  20. use common\services\xhMerchantService;
  21. use common\services\xhAdminService;
  22. use common\components\util;
  23. use common\components\weixinUtil;
  24. use common\components\jsSDK;
  25. use common\services\xhAdminToMerchantService;
  26. use yii\web\Cookie;
  27. class BaseController extends PublicController
  28. {
  29. public $admin, $adminId, $adminAvatar, $account;
  30. public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
  31. public $openMerchant, $openMerchantId;
  32. public $appId;
  33. public $isWeixin = false;
  34. public $isLogin = false;
  35. public $withoutLogin = [];//不需要登陆的方法名
  36. public $validate = true;
  37. protected $service;
  38. // 设置允许与不允许方法 shizq 2019-12-05
  39. protected $allowActions = [];
  40. protected $notAllowActions = [];
  41. public function beforeAction($action)
  42. {
  43. //token验证
  44. //$adminId = jwt::getLoginId();
  45. $adminId = 1;
  46. if (empty($adminId)) {
  47. $this->validate = false;
  48. }
  49. //方法开放设置 shizq 2019-12-05
  50. if (in_array($action->id, $this->notAllowActions)) {
  51. util::fail($action->id . ' not allow');
  52. }
  53. //游客可以访问的方法
  54. if (in_array($action->id, $this->withoutLogin)) {
  55. $this->validate = true;
  56. }
  57. if ($this->validate == false) {
  58. util::notLogin();
  59. }
  60. $admin = AdminService::getById($adminId);
  61. if (empty($admin)) {
  62. util::fail('没有找到管理员');
  63. }
  64. $merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
  65. if (empty($merchantId)) {
  66. util::fail('没有找到商家信息');
  67. }
  68. $merchant = MerchantService::getById($merchantId);
  69. $merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
  70. $merchantAsset = MerchantAssetService::getByMerchantId($merchantId);
  71. Yii::$app->params['adminId'] = $adminId;
  72. Yii::$app->params['admin'] = $admin;
  73. Yii::$app->params['merchantId'] = $merchantId;
  74. Yii::$app->params['merchant'] = $merchant;
  75. Yii::$app->params['merchant'] = $merchant;
  76. Yii::$app->params['merchantAsset'] = $merchantAsset;
  77. Yii::$app->params['merchantExtend'] = $merchantExtend;
  78. $this->adminId = $adminId;
  79. $this->merchantId = $merchantId;
  80. $this->merchant = $merchant;
  81. $this->merchantExtend = $merchantExtend;
  82. $this->merchantAsset = $merchantAsset;
  83. return parent::beforeAction($action);
  84. }
  85. public function actionList()
  86. {
  87. $where = null;
  88. $service = $this->service;
  89. $list = $service::getList('*', $where);
  90. util::success($list);
  91. }
  92. public function actionAdd()
  93. {
  94. $data = Yii::$app->request->post();
  95. $service = $this->service;
  96. $re = $service::add($data);
  97. util::success($re);
  98. }
  99. public function actionGet()
  100. {
  101. $id = Yii::$app->request->get('id');
  102. $service = $this->service;
  103. $ad = $service::getById($id);
  104. util::success($ad);
  105. }
  106. public function actionUpdate()
  107. {
  108. $data = Yii::$app->request->post();
  109. $id = $data['id'];
  110. $service = $this->service;
  111. $re = $service::updateById($id, $data);
  112. util::success($re);
  113. }
  114. public function actionDelete()
  115. {
  116. $id = Yii::$app->request->get('id');
  117. $service = $this->service;
  118. $re = $service::deleteById($id);
  119. util::success($re);
  120. }
  121. }