AcceptorController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Http\Validator\AcceptorValidator;
  5. use App\Http\Validator\MemberValidator;
  6. use App\Http\Validator\MerchantValidator;
  7. use App\Services\Api\AcceptorService;
  8. use App\Services\Api\MemberService;
  9. use App\Services\Api\MerchantService;
  10. /**
  11. * 承兑商管理
  12. * @package App\Http\Controllers\Api
  13. */
  14. class AcceptorController extends webApp
  15. {
  16. /**
  17. * 信息
  18. * @return array
  19. */
  20. public function info()
  21. {
  22. $id = request()->post('id', 0);
  23. $userId = request()->post('user_id', 0);
  24. $info = AcceptorService::make()->getInfo($id,'', $userId?$userId:$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. $params = request()->post();
  38. $pageSize = request()->post('pageSize', 6);
  39. $params['user_id'] = $this->userId;
  40. $datas = AcceptorService::make()->getDataList($params, $pageSize);
  41. return showJson(1010, true, $datas);
  42. }
  43. /**
  44. * 申请入驻
  45. * @return array
  46. */
  47. public function apply(AcceptorValidator $validator)
  48. {
  49. $params = request()->all();
  50. $params = $validator->check($params, 'apply');
  51. if (!is_array($params)) {
  52. return showJson($params, false);
  53. }
  54. if(!$result = AcceptorService::make()->apply($this->userId, $params)){
  55. $error = AcceptorService::make()->getError();
  56. return showJson($error, false,'',$error==3011?'405':-1);
  57. }else{
  58. return showJson(AcceptorService::make()->getError(), true, $result);
  59. }
  60. }
  61. /**
  62. * 入驻信息
  63. * @return array
  64. */
  65. public function applyInfo()
  66. {
  67. $info = AcceptorService::make()->getApplyInfo($this->userId);
  68. if($info){
  69. return showJson(1010, true, $info);
  70. }else{
  71. return showJson(1009, false);
  72. }
  73. }
  74. /**
  75. * 修改账号信息
  76. * @param $userId
  77. * @param $params
  78. * @return bool
  79. */
  80. public function modify(MerchantValidator $validator)
  81. {
  82. $params = request()->all();
  83. $params = $validator->check($params, 'modify');
  84. if (!is_array($params)) {
  85. return showJson($params, false);
  86. }
  87. if(!MerchantService::make()->modify($this->userId, $params)){
  88. return showJson(MerchantService::make()->getError(),false);
  89. }else{
  90. return showJson(MerchantService::make()->getError(),true);
  91. }
  92. }
  93. /**
  94. * 修改店铺信息
  95. * @param $userId
  96. * @param $params
  97. * @return bool
  98. */
  99. public function saveInfo(MemberValidator $validator)
  100. {
  101. $params = request()->all();
  102. $params = $validator->check($params, 'info');
  103. if (!is_array($params)) {
  104. return showJson($params, false);
  105. }
  106. if(!MerchantService::make()->saveInfo($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 MerchantValidator $validator
  115. * @return array
  116. */
  117. public function collect(MerchantValidator $validator)
  118. {
  119. $params = request()->all();
  120. $params = $validator->check($params, 'collect');
  121. if (!is_array($params)) {
  122. return showJson($params, false);
  123. }
  124. if(!$result = MerchantService::make()->collect($this->userId, $params)){
  125. return showJson(MerchantService::make()->getError(), false);
  126. }else{
  127. return showJson(MerchantService::make()->getError(), true, $result);
  128. }
  129. }
  130. /**
  131. * 充值交易额度
  132. * @param AcceptorValidator $validator
  133. * @return array
  134. */
  135. public function recharge(AcceptorValidator $validator)
  136. {
  137. $params = request()->all();
  138. $params = $validator->check($params, 'recharge');
  139. if (!is_array($params)) {
  140. return showJson($params, false);
  141. }
  142. if(!$result = AcceptorService::make()->recharge($this->userId, $params)){
  143. $error = AcceptorService::make()->getError();
  144. return showJson($error,false,'',($error==2035?405:-1));
  145. }else{
  146. return showJson(AcceptorService::make()->getError(),true, $result);
  147. }
  148. }
  149. /**
  150. * 提现
  151. * @param MemberValidator $validator
  152. * @return array
  153. */
  154. public function withdraw(MemberValidator $validator)
  155. {
  156. $params = request()->all();
  157. $scene = isset($params['scene'])? $params['scene'] : 'withdraw';
  158. $params = $validator->check($params, $scene);
  159. if (!is_array($params)) {
  160. return showJson($params, false);
  161. }
  162. $params['user_type'] = 3;
  163. if(!$result = AcceptorService::make()->withdraw($this->userId, $params)){
  164. $error = AcceptorService::make()->getError();
  165. return showJson($error,false,'',$error==2035?405:-1);
  166. }else{
  167. return showJson(AcceptorService::make()->getError(),true, $result);
  168. }
  169. }
  170. /**
  171. * C2C交易-购买星豆
  172. * @param MemberValidator $validator
  173. * @return array
  174. */
  175. public function buyxd(MemberValidator $validator)
  176. {
  177. $params = request()->all();
  178. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  179. $params = $validator->check($params, $scene);
  180. if (!is_array($params)) {
  181. return showJson($params, false);
  182. }
  183. if(!$result = AcceptorService::make()->buyxd($this->userId, $params)){
  184. $error = AcceptorService::make()->getError();
  185. return showJson($error,false, [],$error== 2035? 405:-1);
  186. }else{
  187. return showJson(AcceptorService::make()->getError(),true, $result);
  188. }
  189. }
  190. /**
  191. * C2C交易-购买星豆
  192. * @param MemberValidator $validator
  193. * @return array
  194. */
  195. public function sellxd(MemberValidator $validator)
  196. {
  197. $params = request()->all();
  198. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  199. $params = $validator->check($params, $scene);
  200. if (!is_array($params)) {
  201. return showJson($params, false);
  202. }
  203. if(!$result = AcceptorService::make()->sellxd($this->userId, $params)){
  204. $error = AcceptorService::make()->getError();
  205. return showJson($error,false, [],$error== 2035? 405:0);
  206. }else{
  207. return showJson(AcceptorService::make()->getError(),true, $result);
  208. }
  209. }
  210. /**
  211. * 取消
  212. * @return array
  213. */
  214. public function cancel()
  215. {
  216. $params = request()->post();
  217. if(!$result = AcceptorService::make()->cancel($this->userId, $params)){
  218. $error = AcceptorService::make()->getError();
  219. return showJson($error,false, [],$error== 2035? 405:0);
  220. }else{
  221. return showJson(AcceptorService::make()->getError(),true, $result);
  222. }
  223. }
  224. }