GoodsController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. $list = $this->service->getDataList($params, $pageSize);
  42. $message = array(
  43. "msg" => '操作成功',
  44. "code" => 0,
  45. "data" => isset($list['list']) ? $list['list'] : [],
  46. "count" => isset($list['total']) ? $list['total'] : 0,
  47. );
  48. return $message;
  49. }
  50. /**
  51. * 获取详情
  52. * @return array
  53. */
  54. public function info()
  55. {
  56. return $this->service->info($this->storeId);
  57. }
  58. /**
  59. * 添加商品
  60. * @return array
  61. */
  62. public function add()
  63. {
  64. return $this->service->add($this->storeId);
  65. }
  66. /**
  67. * 编辑商品
  68. * @return array
  69. */
  70. public function edit()
  71. {
  72. return $this->service->edit($this->storeId);
  73. }
  74. /**
  75. * 审核商品
  76. * @return array
  77. */
  78. public function confirm()
  79. {
  80. // 权限检查:只有总后台管理员才能审核,商户用户无法审核
  81. if ($this->storeId > 0) {
  82. return message('商户用户无权进行审核操作', false);
  83. }
  84. $params = request()->post();
  85. if ($this->service->confirm($this->userId, $params)) {
  86. return message($this->service->getError(), true);
  87. } else {
  88. return message($this->service->getError(), false);
  89. }
  90. }
  91. /**
  92. * 批量上下架
  93. * @return array
  94. */
  95. public function launch()
  96. {
  97. if ($this->storeId > 0) {
  98. return message('商户用户无权进行审核操作', false);
  99. }
  100. $params = request()->post();
  101. if ($this->service->launch($this->userId, $params)) {
  102. return message($this->service->getError(), true);
  103. } else {
  104. return message($this->service->getError(), false);
  105. }
  106. }
  107. /**
  108. * 删除数据
  109. * @return mixed
  110. * @since 2020/11/11
  111. * @author laravel开发员
  112. */
  113. public function delete()
  114. {
  115. $result = $this->service->delete($this->storeId);
  116. return $result;
  117. }
  118. /**
  119. * 选项列表(用于下拉选择)
  120. * @return array
  121. */
  122. public function options()
  123. {
  124. // 这里可以返回商品选项,如果需要的话
  125. return message('操作成功', true, []);
  126. }
  127. /**
  128. * 设置推荐
  129. * @return mixed
  130. * @since 2020/11/21
  131. * @author laravel开发员
  132. */
  133. public function setNew()
  134. {
  135. $result = $this->service->setNew();
  136. return $result;
  137. }
  138. }