GoodsController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\GoodsService;
  5. /**
  6. * 商品管理
  7. * @package App\Http\Controllers\Api
  8. */
  9. class GoodsController extends webApp
  10. {
  11. /**
  12. * 列表
  13. * @return array
  14. */
  15. public function index()
  16. {
  17. $params =request()->post();
  18. $pageSize = request()->post('pageSize', 12);
  19. $datas = GoodsService::make()->getDataList($params, $pageSize);
  20. return message(1010, true, $datas);
  21. }
  22. /**
  23. * 购买商品列表
  24. * @return array
  25. */
  26. public function buyGoods()
  27. {
  28. $params =request()->post();
  29. $goods = isset($params['goods']) && $params['goods'] ? $params['goods'] : [];
  30. $ids = $goods ? array_column($goods, 'id') : [];
  31. $datas = GoodsService::make()->getOrderGoods($ids, $goods, '', $this->userId);
  32. return message(1010, true, $datas);
  33. }
  34. /**
  35. * 分类
  36. * @return array
  37. */
  38. public function categorys()
  39. {
  40. $datas = GoodsService::make()->getCategoryList();
  41. return message(1010, true, $datas);
  42. }
  43. /**
  44. * 详情
  45. */
  46. public function info()
  47. {
  48. $params = request()->all();
  49. $id = isset($params['id'])? intval($params['id']) : 0;
  50. if(empty($id)){
  51. return message(1036, false);
  52. }
  53. if($info = GoodsService::make()->getInfo($id, $this->userId)){
  54. return message(1010, true, $info);
  55. }else{
  56. return message(1009, false);
  57. }
  58. }
  59. /**
  60. * 收藏
  61. */
  62. public function collect()
  63. {
  64. $params = request()->all();
  65. $id = isset($params['id']) ? intval($params['id']) : 0;
  66. if (empty($id)) {
  67. return message(1036, false);
  68. }
  69. try {
  70. if ($result = GoodsService::make()->collect($this->userId, $id)) {
  71. return message(GoodsService::make()->getError(), true, $result);
  72. } else {
  73. return message(GoodsService::make()->getError(), false);
  74. }
  75. } catch (\Exception $exception) {
  76. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  77. return showJson(1046, false, $error);
  78. }
  79. }
  80. }