MerchantController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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($id, $type, $this->userId);
  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. $info = MemberService::make()->getInfo($this->userId, 'home');
  38. if($info){
  39. return showJson(1010, true, $info);
  40. }else{
  41. return showJson(1004, false, [],'403');
  42. }
  43. }
  44. /**
  45. * 商户分类
  46. * @return array
  47. */
  48. public function category()
  49. {
  50. $params = request()->all();
  51. $type = isset($params['show_type'])? $params['show_type'] : 1;
  52. $data = MerchantCategoryService::make()->getOptions($type);
  53. return showJson(1010, true, $data);
  54. }
  55. /**
  56. * 列表数据
  57. * @return array
  58. */
  59. public function list()
  60. {
  61. $pageSize = request()->post('pageSize', 12);
  62. $params = request()->all();
  63. $datas = MerchantService::make()->getDataList($params, $pageSize);
  64. return showJson(1010, true, $datas);
  65. }
  66. /**
  67. * 申请入驻
  68. * @return array
  69. */
  70. public function apply(MerchantValidator $validator)
  71. {
  72. $params = request()->all();
  73. $params = $validator->check($params, 'apply');
  74. if (!is_array($params)) {
  75. return showJson($params, false);
  76. }
  77. if(!$result = MerchantService::make()->apply($this->userId, $params)){
  78. return showJson(MerchantService::make()->getError(), false);
  79. }else{
  80. return showJson(MerchantService::make()->getError(), true, $result);
  81. }
  82. }
  83. /**
  84. * 入驻信息
  85. * @return array
  86. */
  87. public function applyInfo()
  88. {
  89. $info = MerchantService::make()->getApplyInfo($this->userId);
  90. if($info){
  91. return showJson(1010, true, $info);
  92. }else{
  93. return showJson(1009, false);
  94. }
  95. }
  96. /**
  97. * 修改账号信息
  98. * @param $userId
  99. * @param $params
  100. * @return bool
  101. */
  102. public function modify(MemberValidator $validator)
  103. {
  104. $params = request()->all();
  105. $params = $validator->check($params, 'info');
  106. if (!is_array($params)) {
  107. return showJson($params, false);
  108. }
  109. if(!MerchantService::make()->modify($this->userId, $params)){
  110. return showJson(MerchantService::make()->getError(),false);
  111. }else{
  112. return showJson(MerchantService::make()->getError(),true);
  113. }
  114. }
  115. /**
  116. * 修改店铺信息
  117. * @param $userId
  118. * @param $params
  119. * @return bool
  120. */
  121. public function saveInfo(MemberValidator $validator)
  122. {
  123. $params = request()->all();
  124. $params = $validator->check($params, 'info');
  125. if (!is_array($params)) {
  126. return showJson($params, false);
  127. }
  128. if(!MerchantService::make()->saveInfo($this->userId, $params)){
  129. return showJson(MerchantService::make()->getError(),false);
  130. }else{
  131. return showJson(MerchantService::make()->getError(),true);
  132. }
  133. }
  134. /**
  135. * 收藏点赞
  136. * @param MerchantValidator $validator
  137. * @return array
  138. */
  139. public function collect(MerchantValidator $validator)
  140. {
  141. $params = request()->all();
  142. $params = $validator->check($params, 'collect');
  143. if (!is_array($params)) {
  144. return showJson($params, false);
  145. }
  146. if(!$result = MerchantService::make()->collect($this->userId, $params)){
  147. return showJson(MerchantService::make()->getError(), false);
  148. }else{
  149. return showJson(MerchantService::make()->getError(), true, $result);
  150. }
  151. }
  152. /**
  153. * 缴纳保证金
  154. * @param MemberValidator $validator
  155. * @return array
  156. */
  157. public function deposit(MemberValidator $validator)
  158. {
  159. $params = request()->all();
  160. $params = $validator->check($params, 'deposit');
  161. if (!is_array($params)) {
  162. return showJson($params, false);
  163. }
  164. if(!$result = MerchantService::make()->deposit($this->userId, $params)){
  165. return showJson(MerchantService::make()->getError(),false);
  166. }else{
  167. return showJson(MerchantService::make()->getError(),true, $result);
  168. }
  169. }
  170. /**
  171. * 退还保证金
  172. * @param MemberValidator $validator
  173. * @return array
  174. */
  175. public function rebackDeposit(MemberValidator $validator)
  176. {
  177. $params = request()->all();
  178. $params = $validator->check($params, 'reback_deposit');
  179. if (!is_array($params)) {
  180. return showJson($params, false);
  181. }
  182. if(!$result = MerchantService::make()->rebackDeposit($this->userId, $params)){
  183. return showJson(MerchantService::make()->getError(),false);
  184. }else{
  185. return showJson(MerchantService::make()->getError(),true);
  186. }
  187. }
  188. }