GoodsController.php 2.0 KB

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