MerchantController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\MemberValidator;
  5. use App\Http\Validator\MerchantValidator;
  6. use App\Services\Api\MemberService;
  7. use App\Services\Api\MerchantCategoryService;
  8. use App\Services\Api\MerchantService;
  9. /**
  10. * 商家商户管理
  11. * Class MerchantController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class MerchantController extends webApp
  15. {
  16. /**
  17. * 信息
  18. * @return array
  19. */
  20. public function info()
  21. {
  22. $type = request()->post('type', 'detail');
  23. $id = request()->post('id', 0);
  24. $info = MerchantService::make()->getInfoById($this->userId, $type, $id);
  25. if($info){
  26. return showJson(1010, true, $info);
  27. }else{
  28. return showJson(2216, false, [],'404');
  29. }
  30. }
  31. /**
  32. * 商家列表
  33. * @return array
  34. */
  35. public function index()
  36. {
  37. $params = request()->post();
  38. $pageSize = request()->post('pageSize', 6);
  39. $datas = MerchantService::make()->getDataList($params, $pageSize);
  40. return showJson(1010, true, $datas);
  41. }
  42. /**
  43. * 商户分类
  44. * @return array
  45. */
  46. public function category()
  47. {
  48. $params = request()->all();
  49. $type = isset($params['show_type'])? $params['show_type'] : 1;
  50. $data = MerchantCategoryService::make()->getOptions($type);
  51. return showJson(1010, true, $data);
  52. }
  53. /**
  54. * 列表数据
  55. * @return array
  56. */
  57. public function list()
  58. {
  59. $pageSize = request()->post('pageSize', 12);
  60. $params = request()->all();
  61. $datas = MerchantService::make()->getDataList($params, $pageSize);
  62. return showJson(1010, true, $datas);
  63. }
  64. /**
  65. * 申请入驻
  66. * @return array
  67. */
  68. public function apply(MerchantValidator $validator)
  69. {
  70. $params = request()->all();
  71. $params = $validator->check($params, 'apply');
  72. if (!is_array($params)) {
  73. return showJson($params, false);
  74. }
  75. if(!$result = MerchantService::make()->apply($this->userId, $params)){
  76. return showJson(MerchantService::make()->getError(), false);
  77. }else{
  78. return showJson(MerchantService::make()->getError(), true, $result);
  79. }
  80. }
  81. /**
  82. * 入驻信息
  83. * @return array
  84. */
  85. public function applyInfo()
  86. {
  87. $info = MerchantService::make()->getApplyInfo($this->userId);
  88. if($info){
  89. return showJson(1010, true, $info);
  90. }else{
  91. return showJson(1009, false);
  92. }
  93. }
  94. /**
  95. * 修改账号信息
  96. * @param $userId
  97. * @param $params
  98. * @return bool
  99. */
  100. public function modify(MerchantValidator $validator)
  101. {
  102. $params = request()->all();
  103. $params = $validator->check($params, 'modify');
  104. if (!is_array($params)) {
  105. return showJson($params, false);
  106. }
  107. if(!MerchantService::make()->modify($this->userId, $params)){
  108. return showJson(MerchantService::make()->getError(),false);
  109. }else{
  110. return showJson(MerchantService::make()->getError(),true);
  111. }
  112. }
  113. /**
  114. * 修改店铺信息
  115. * @param $userId
  116. * @param $params
  117. * @return bool
  118. */
  119. public function saveInfo(MemberValidator $validator)
  120. {
  121. $params = request()->all();
  122. $params = $validator->check($params, 'info');
  123. if (!is_array($params)) {
  124. return showJson($params, false);
  125. }
  126. if(!MerchantService::make()->saveInfo($this->userId, $params)){
  127. return showJson(MerchantService::make()->getError(),false);
  128. }else{
  129. return showJson(MerchantService::make()->getError(),true);
  130. }
  131. }
  132. /**
  133. * 收藏点赞
  134. * @param MerchantValidator $validator
  135. * @return array
  136. */
  137. public function collect(MerchantValidator $validator)
  138. {
  139. $params = request()->all();
  140. $params = $validator->check($params, 'collect');
  141. if (!is_array($params)) {
  142. return showJson($params, false);
  143. }
  144. if(!$result = MerchantService::make()->collect($this->userId, $params)){
  145. return showJson(MerchantService::make()->getError(), false);
  146. }else{
  147. return showJson(MerchantService::make()->getError(), true, $result);
  148. }
  149. }
  150. /**
  151. * 缴纳保证金
  152. * @param MemberValidator $validator
  153. * @return array
  154. */
  155. public function deposit(MemberValidator $validator)
  156. {
  157. $params = request()->all();
  158. $params = $validator->check($params, 'deposit');
  159. if (!is_array($params)) {
  160. return showJson($params, false);
  161. }
  162. if(!$result = MerchantService::make()->deposit($this->userId, $params)){
  163. return showJson(MerchantService::make()->getError(),false);
  164. }else{
  165. return showJson(MerchantService::make()->getError(),true, $result);
  166. }
  167. }
  168. /**
  169. * 退还保证金
  170. * @param MemberValidator $validator
  171. * @return array
  172. */
  173. public function rebackDeposit(MemberValidator $validator)
  174. {
  175. $params = request()->all();
  176. $params = $validator->check($params, 'reback_deposit');
  177. if (!is_array($params)) {
  178. return showJson($params, false);
  179. }
  180. if(!$result = MerchantService::make()->rebackDeposit($this->userId, $params)){
  181. return showJson(MerchantService::make()->getError(),false);
  182. }else{
  183. return showJson(MerchantService::make()->getError(),true);
  184. }
  185. }
  186. }