BaseController.php 3.4 KB

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