GoodsController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\GoodsValidator;
  5. use App\Services\Api\GoodsService;
  6. use App\Services\Api\GoodsCategoryService;
  7. use App\Services\RedisService;
  8. /**
  9. * 商品服务管理
  10. * @package App\Http\Controllers\Api
  11. */
  12. class GoodsController extends webApp
  13. {
  14. /**
  15. * 列表
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. try {
  21. $params = request()->post();
  22. $pageSize = request()->post('pageSize', 0);
  23. $datas = GoodsService::make()->getDataList($params, $pageSize,'', $this->userId);
  24. return showJson(1010, true, $datas);
  25. } catch (\Exception $exception){
  26. RedisService::set("caches:request:error_goods_index", ['trace'=>$exception->getTrace()], 7200);
  27. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  28. }
  29. }
  30. /**
  31. * 列表
  32. * @return array
  33. */
  34. public function list()
  35. {
  36. try {
  37. $params = request()->post();
  38. $pageSize = request()->post('pageSize', 0);
  39. $datas = GoodsService::make()->getDataList($params, $pageSize,'lev_a.*,lev_c.name as merch_name', $this->userId);
  40. return showJson(1010, true, $datas);
  41. } catch (\Exception $exception){
  42. RedisService::set("caches:request:error_goods_index", ['trace'=>$exception->getTrace()], 7200);
  43. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
  44. }
  45. }
  46. /**
  47. * 分类
  48. * @return array
  49. */
  50. public function category()
  51. {
  52. $params = request()->post();
  53. $pageSize = request()->post('pageSize', 99);
  54. $datas = GoodsCategoryService::make()->getDataList($params, $pageSize);
  55. return showJson(1010, true, $datas);
  56. }
  57. /**
  58. * 详情
  59. * @return array
  60. */
  61. public function info()
  62. {
  63. $id = request()->post('id', 0);
  64. $info = GoodsService::make()->getInfo($id, $this->userId);
  65. return showJson(1010, true, $info);
  66. }
  67. /**
  68. * 推荐
  69. * @return array
  70. */
  71. public function recommend()
  72. {
  73. try {
  74. $params = request()->post();
  75. $pageSize = request()->post('pageSize', 0);
  76. $lng = isset($params['lng'])? $params['lng'] : '';
  77. $lat = isset($params['lat'])? $params['lat'] : '';
  78. $params = [
  79. 'lat'=> $lat? $lat : (isset($this->userInfo['lat'])? $this->userInfo['lat'] : ''),
  80. 'lng'=> $lng? $lng : (isset($this->userInfo['lng'])? $this->userInfo['lng'] : ''),
  81. 'sort_type'=> 1,
  82. 'is_recommend'=> 1,
  83. 'type'=> isset($params['type'])? intval($params['type']) : 2,
  84. 'status'=> 2,
  85. ];
  86. $datas = GoodsService::make()->getDataList($params, $pageSize);
  87. return showJson(1010, true, $datas);
  88. } catch (\Exception $exception){
  89. RedisService::set("caches:request:error_goods_recommend", ['trace'=>$exception->getTrace()], 7200);
  90. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  91. }
  92. }
  93. /**
  94. * 发布
  95. * @param GoodsValidator $validator
  96. * @return array
  97. */
  98. public function submit(GoodsValidator $validator)
  99. {
  100. $params = request()->all();
  101. $params = $validator->check($params, 'submit');
  102. if (!is_array($params)) {
  103. return showJson($params, false);
  104. }
  105. if(!$result = GoodsService::make()->submit($this->userId, $params)){
  106. return showJson(GoodsService::make()->getError(), false);
  107. }else{
  108. return showJson(GoodsService::make()->getError(), true, $result);
  109. }
  110. }
  111. /**
  112. * 状态/上下架
  113. * @return array|mixed
  114. */
  115. public function status()
  116. {
  117. if(!$result = GoodsService::make()->status()){
  118. return showJson(GoodsService::make()->getError(), false);
  119. }else{
  120. return showJson(GoodsService::make()->getError(), true, $result);
  121. }
  122. }
  123. /**
  124. * 删除
  125. * @return array|mixed
  126. */
  127. public function delete()
  128. {
  129. return GoodsService::make()->delete();
  130. }
  131. }