GoodsController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Http\Controllers\Admin;
  12. use App\Services\Common\GoodsService;
  13. /**
  14. * 商品管理-控制器
  15. * @author laravel开发员
  16. * @since 2020/11/11
  17. * Class GoodsController
  18. * @package App\Http\Controllers
  19. */
  20. class GoodsController extends Backend
  21. {
  22. /**
  23. * 构造函数
  24. * @author laravel开发员
  25. * @since 2020/11/11
  26. * GoodsController constructor.
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. $this->service = new GoodsService();
  32. }
  33. /**
  34. * 列表(商品审核列表)
  35. * @return array
  36. */
  37. public function index()
  38. {
  39. $pageSize = request()->get('limit', 15);
  40. $params = request()->all();
  41. $params['store_id'] = $this->storeId;
  42. $list = $this->service->getDataList($params, $pageSize);
  43. $message = array(
  44. "msg" => '操作成功',
  45. "code" => 0,
  46. "data" => isset($list['list']) ? $list['list'] : [],
  47. "count" => isset($list['total']) ? $list['total'] : 0,
  48. );
  49. return $message;
  50. }
  51. /**
  52. * 获取详情
  53. * @return array
  54. */
  55. public function info()
  56. {
  57. return $this->service->info($this->storeId);
  58. }
  59. /**
  60. * 添加商品
  61. * @return array
  62. */
  63. public function add()
  64. {
  65. return $this->service->add($this->storeId);
  66. }
  67. /**
  68. * 编辑商品
  69. * @return array
  70. */
  71. public function edit()
  72. {
  73. return $this->service->edit($this->storeId);
  74. }
  75. /**
  76. * 审核商品
  77. * @return array
  78. */
  79. public function confirm()
  80. {
  81. // 权限检查:只有总后台管理员才能审核,商户用户无法审核
  82. if ($this->storeId > 0) {
  83. return message('商户用户无权进行审核操作', false);
  84. }
  85. $params = request()->post();
  86. if ($this->service->confirm($this->userId, $params)) {
  87. return message($this->service->getError(), true);
  88. } else {
  89. return message($this->service->getError(), false);
  90. }
  91. }
  92. /**
  93. * 删除数据
  94. * @return mixed
  95. * @since 2020/11/11
  96. * @author laravel开发员
  97. */
  98. public function delete()
  99. {
  100. $result = $this->service->delete($this->storeId);
  101. return $result;
  102. }
  103. /**
  104. * 选项列表(用于下拉选择)
  105. * @return array
  106. */
  107. public function options()
  108. {
  109. // 这里可以返回商品选项,如果需要的话
  110. return message('操作成功', true, []);
  111. }
  112. }