BaseController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // Service 模型实例
  21. protected $service;
  22. // 设置允许与不允许方法 shizq 2019-12-05
  23. protected $allowActions = [];
  24. protected $notAllowActions = [];
  25. public function beforeAction($action)
  26. {
  27. //token验证
  28. //$adminId = jwt::getLoginId();
  29. $adminId = 1;
  30. if (empty($adminId)) {
  31. $this->validate = false;
  32. }
  33. //方法开放设置 shizq 2019-12-05
  34. if (in_array($action->id, $this->notAllowActions)) {
  35. util::fail($action->id . ' not allow');
  36. }
  37. //游客可以访问的方法
  38. if (in_array($action->id, $this->withoutLogin)) {
  39. $this->validate = true;
  40. }
  41. if ($this->validate == false) {
  42. util::notLogin();
  43. }
  44. $admin = AdminService::getById($adminId);
  45. if (empty($admin)) {
  46. util::fail('没有找到管理员');
  47. }
  48. $merchantId = 12358;
  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 actionList()
  71. {
  72. $numargs = func_num_args();
  73. $select = $numargs >= 1 ? func_get_arg(0) : '*';
  74. $where = $numargs >= 2 ? func_get_arg(1) : null;
  75. $order = $numargs >= 3 ? func_get_arg(2) : '';
  76. $with = $numargs >= 4 ? func_get_arg(3) : '';
  77. $service = $this->service;
  78. $list = $service::getList($select, $where, $order, $with);
  79. util::success($list);
  80. }
  81. public function actionAdd()
  82. {
  83. $data = Yii::$app->request->post();
  84. $service = $this->service;
  85. $re = $service::add($data);
  86. util::success($re);
  87. }
  88. public function actionDetail()
  89. {
  90. $id = Yii::$app->request->get('id');
  91. $service = $this->service;
  92. $data = $service::getById($id);
  93. if(!empty($data)){
  94. util::success($data);
  95. }
  96. util::fail('');
  97. }
  98. public function actionUpdate()
  99. {
  100. $data = Yii::$app->request->post();
  101. $id = $data['id'];
  102. $service = $this->service;
  103. $re = $service::updateById($id, $data);
  104. if($re['status'] === true){
  105. util::success($re);
  106. }
  107. util::fail();
  108. }
  109. public function actionDelete()
  110. {
  111. $id = Yii::$app->request->get('id');
  112. $service = $this->service;
  113. $service::deleteById($id);
  114. util::success([],'删除成功');
  115. }
  116. }