StoreController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\StoreValidator;
  5. use App\Services\Api\StoreService;
  6. /**
  7. * 商家
  8. * @package App\Http\Controllers\Api
  9. */
  10. class StoreController extends webApp
  11. {
  12. /**
  13. * 列表
  14. * @return array
  15. */
  16. public function index()
  17. {
  18. $params =request()->post();
  19. $pageSize = request()->post('pageSize', 15);
  20. $datas = StoreService::make()->getDataList($params, $pageSize);
  21. return showJson(1010, true, $datas);
  22. }
  23. /**
  24. * 主页店铺商品
  25. * @return array
  26. */
  27. public function goods()
  28. {
  29. $params =request()->post();
  30. try {
  31. $params['user_id'] = $this->userId;
  32. $datas = StoreService::make()->getGoodsList($params);
  33. return showJson(1010, true, $datas);
  34. }catch (\Exception $exception) {
  35. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  36. return showJson(1046, false, $error);
  37. }
  38. }
  39. /**
  40. * 行业分类
  41. * @return array
  42. */
  43. public function categorys()
  44. {
  45. $datas = StoreService::make()->getCategoryList();
  46. return showJson(1010, true, $datas);
  47. }
  48. /**
  49. * 详情
  50. * @return array
  51. */
  52. public function info()
  53. {
  54. $params = request()->all();
  55. $id = isset($params['id'])? $params['id'] : 0;
  56. try {
  57. if(!$result = StoreService::make()->getInfo($id)){
  58. return showJson(1009, false);
  59. }else{
  60. return showJson(1010, true, $result);
  61. }
  62. } catch (\Exception $exception) {
  63. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  64. return showJson(1046, false, $error);
  65. }
  66. }
  67. /**
  68. * 详情
  69. * @return array
  70. */
  71. public function applyInfo()
  72. {
  73. $params = request()->all();
  74. $uid = isset($params['uid'])? $params['uid'] : 0;
  75. $uid = $uid? $uid : $this->userId;
  76. try {
  77. if(!$result = StoreService::make()->getApplyInfo($uid)){
  78. return showJson(1009, false);
  79. }else{
  80. return showJson(1010, true, $result);
  81. }
  82. } catch (\Exception $exception) {
  83. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  84. return showJson(1046, false, $error);
  85. }
  86. }
  87. /**
  88. * 添加
  89. * @param StoreValidator $validator
  90. * @return array
  91. */
  92. public function apply(StoreValidator $validator)
  93. {
  94. $params = request()->all();
  95. $params = $validator->check($params, 'apply');
  96. if (!is_array($params)) {
  97. return showJson($params, false);
  98. }
  99. try {
  100. if(!$result = StoreService::make()->apply($this->userId, $params)){
  101. return showJson(StoreService::make()->getError(), false);
  102. }else{
  103. return showJson(StoreService::make()->getError(), true, $result);
  104. }
  105. } catch (\Exception $exception) {
  106. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  107. return showJson(1046, false, $error);
  108. }
  109. }
  110. /**
  111. * 删除
  112. * @return array|mixed
  113. */
  114. public function delete()
  115. {
  116. if(!StoreService::make()->delete()){
  117. return showJson(StoreService::make()->getError(), false);
  118. }else{
  119. return showJson(StoreService::make()->getError(), true);
  120. }
  121. }
  122. }