StoreController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 categorys()
  28. {
  29. $datas = StoreService::make()->getCategoryList();
  30. return showJson(1010, true, $datas);
  31. }
  32. /**
  33. * 详情
  34. * @return array
  35. */
  36. public function info()
  37. {
  38. $params = request()->all();
  39. $id = isset($params['id'])? $params['id'] : 0;
  40. try {
  41. if(!$result = StoreService::make()->getInfo($id)){
  42. return showJson(1009, false);
  43. }else{
  44. return showJson(1010, true, $result);
  45. }
  46. } catch (\Exception $exception) {
  47. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  48. return showJson(1046, false, $error);
  49. }
  50. }
  51. /**
  52. * 详情
  53. * @return array
  54. */
  55. public function applyInfo()
  56. {
  57. $params = request()->all();
  58. $uid = isset($params['uid'])? $params['uid'] : 0;
  59. $uid = $uid? $uid : $this->userId;
  60. try {
  61. if(!$result = StoreService::make()->getApplyInfo($uid)){
  62. return showJson(1009, false);
  63. }else{
  64. return showJson(1010, true, $result);
  65. }
  66. } catch (\Exception $exception) {
  67. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  68. return showJson(1046, false, $error);
  69. }
  70. }
  71. /**
  72. * 添加
  73. * @param StoreValidator $validator
  74. * @return array
  75. */
  76. public function apply(StoreValidator $validator)
  77. {
  78. $params = request()->all();
  79. $params = $validator->check($params, 'apply');
  80. if (!is_array($params)) {
  81. return showJson($params, false);
  82. }
  83. try {
  84. if(!$result = StoreService::make()->apply($this->userId, $params)){
  85. return showJson(StoreService::make()->getError(), false);
  86. }else{
  87. return showJson(StoreService::make()->getError(), true, $result);
  88. }
  89. } catch (\Exception $exception) {
  90. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  91. return showJson(1046, false, $error);
  92. }
  93. }
  94. /**
  95. * 删除
  96. * @return array|mixed
  97. */
  98. public function delete()
  99. {
  100. if(!StoreService::make()->delete()){
  101. return showJson(StoreService::make()->getError(), false);
  102. }else{
  103. return showJson(StoreService::make()->getError(), true);
  104. }
  105. }
  106. }