MerchantController.php 6.3 KB

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