BaseController.php 3.3 KB

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