BaseLikeShopController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. declare(strict_types=1);
  20. namespace app\common\controller;
  21. use app\BaseController;
  22. use app\common\lists\BaseDataLists;
  23. use app\common\service\JsonService;
  24. use think\facade\App;
  25. class BaseLikeShopController extends BaseController
  26. {
  27. public array $notNeedLogin = [];
  28. /**
  29. * @notes 操作成功
  30. * @param string $msg
  31. * @param array $data
  32. * @param int $code
  33. * @param int $show
  34. * @return \think\response\Json
  35. * @author 令狐冲
  36. * @date 2021/7/8 00:39
  37. */
  38. protected function success(string $msg = 'success', array $data = [], int $code = 1, int $show = 0)
  39. {
  40. return JsonService::success($msg, $data, $code, $show);
  41. }
  42. /**
  43. * @notes 数据返回
  44. * @param $data
  45. * @return \think\response\Json
  46. * @author 令狐冲
  47. * @date 2021/7/8 11:13
  48. */
  49. protected function data($data)
  50. {
  51. return JsonService::data($data);
  52. }
  53. /**
  54. * @notes 列表数据返回
  55. * @param \app\common\lists\BaseDataLists|null $lists
  56. * @return \think\response\Json
  57. * @author 令狐冲
  58. * @date 2021/7/8 00:40
  59. */
  60. protected function dataLists(BaseDataLists $lists = null)
  61. {
  62. //列表类和控制器一一对应,"app/应用/controller/控制器的方法" =》"app\应用\lists\"目录下
  63. //(例如:"app/adminapi/controller/auth/AdminController.php的lists()方法" =》 "app/adminapi/lists/auth/AminLists.php")
  64. //当对象为空时,自动创建列表对象
  65. if (is_null($lists)) {
  66. $listName = str_replace('.', '\\', App::getNamespace() . '\\lists\\' . $this->request->controller() . ucwords($this->request->action()));
  67. $lists = invoke($listName);
  68. }
  69. return JsonService::dataLists($lists);
  70. }
  71. /**
  72. * @notes 操作失败
  73. * @param string $msg
  74. * @param array $data
  75. * @param int $code
  76. * @param int $show
  77. * @return \think\response\Json
  78. * @author 令狐冲
  79. * @date 2021/7/8 00:39
  80. */
  81. protected function fail(string $msg = 'fail', array $data = [], int $code = 0, int $show = 1)
  82. {
  83. return JsonService::fail($msg, $data, $code, $show);
  84. }
  85. /**
  86. * @notes 是否免登录验证
  87. * @return bool
  88. * @author 令狐冲
  89. * @date 2021/8/3 14:36
  90. */
  91. public function isNotNeedLogin()
  92. {
  93. $notNeedLogin = $this->notNeedLogin;
  94. if (empty($notNeedLogin)) {
  95. return false;
  96. }
  97. $action = $this->request->action();
  98. if (!in_array(trim($action), $notNeedLogin)) {
  99. return false;
  100. }
  101. return true;
  102. }
  103. }