AcceptorController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. $datas = AcceptorService::make()->getDataList($params, $pageSize);
  40. return showJson(1010, true, $datas);
  41. }
  42. /**
  43. * 申请入驻
  44. * @return array
  45. */
  46. public function apply(AcceptorValidator $validator)
  47. {
  48. $params = request()->all();
  49. $params = $validator->check($params, 'apply');
  50. if (!is_array($params)) {
  51. return showJson($params, false);
  52. }
  53. if(!$result = AcceptorService::make()->apply($this->userId, $params)){
  54. $error = AcceptorService::make()->getError();
  55. return showJson($error, false,'',$error==3011?'405':-1);
  56. }else{
  57. return showJson(AcceptorService::make()->getError(), true, $result);
  58. }
  59. }
  60. /**
  61. * 入驻信息
  62. * @return array
  63. */
  64. public function applyInfo()
  65. {
  66. $info = AcceptorService::make()->getApplyInfo($this->userId);
  67. if($info){
  68. return showJson(1010, true, $info);
  69. }else{
  70. return showJson(1009, false);
  71. }
  72. }
  73. /**
  74. * 修改账号信息
  75. * @param $userId
  76. * @param $params
  77. * @return bool
  78. */
  79. public function modify(MerchantValidator $validator)
  80. {
  81. $params = request()->all();
  82. $params = $validator->check($params, 'modify');
  83. if (!is_array($params)) {
  84. return showJson($params, false);
  85. }
  86. if(!MerchantService::make()->modify($this->userId, $params)){
  87. return showJson(MerchantService::make()->getError(),false);
  88. }else{
  89. return showJson(MerchantService::make()->getError(),true);
  90. }
  91. }
  92. /**
  93. * 修改店铺信息
  94. * @param $userId
  95. * @param $params
  96. * @return bool
  97. */
  98. public function saveInfo(MemberValidator $validator)
  99. {
  100. $params = request()->all();
  101. $params = $validator->check($params, 'info');
  102. if (!is_array($params)) {
  103. return showJson($params, false);
  104. }
  105. if(!MerchantService::make()->saveInfo($this->userId, $params)){
  106. return showJson(MerchantService::make()->getError(),false);
  107. }else{
  108. return showJson(MerchantService::make()->getError(),true);
  109. }
  110. }
  111. /**
  112. * 收藏点赞
  113. * @param MerchantValidator $validator
  114. * @return array
  115. */
  116. public function collect(MerchantValidator $validator)
  117. {
  118. $params = request()->all();
  119. $params = $validator->check($params, 'collect');
  120. if (!is_array($params)) {
  121. return showJson($params, false);
  122. }
  123. if(!$result = MerchantService::make()->collect($this->userId, $params)){
  124. return showJson(MerchantService::make()->getError(), false);
  125. }else{
  126. return showJson(MerchantService::make()->getError(), true, $result);
  127. }
  128. }
  129. /**
  130. * 缴纳保证金
  131. * @param MemberValidator $validator
  132. * @return array
  133. */
  134. public function deposit(MemberValidator $validator)
  135. {
  136. $params = request()->all();
  137. $params = $validator->check($params, 'deposit');
  138. if (!is_array($params)) {
  139. return showJson($params, false);
  140. }
  141. if(!$result = MerchantService::make()->deposit($this->userId, $params)){
  142. return showJson(MerchantService::make()->getError(),false);
  143. }else{
  144. return showJson(MerchantService::make()->getError(),true, $result);
  145. }
  146. }
  147. /**
  148. * 退还保证金
  149. * @param MemberValidator $validator
  150. * @return array
  151. */
  152. public function rebackDeposit(MemberValidator $validator)
  153. {
  154. $params = request()->all();
  155. $params = $validator->check($params, 'reback_deposit');
  156. if (!is_array($params)) {
  157. return showJson($params, false);
  158. }
  159. if(!$result = MerchantService::make()->rebackDeposit($this->userId, $params)){
  160. return showJson(MerchantService::make()->getError(),false);
  161. }else{
  162. return showJson(MerchantService::make()->getError(),true);
  163. }
  164. }
  165. /**
  166. * 提现
  167. * @param MemberValidator $validator
  168. * @return array
  169. */
  170. public function withdraw(MemberValidator $validator)
  171. {
  172. $params = request()->all();
  173. $scene = isset($params['scene'])? $params['scene'] : 'withdraw';
  174. $params = $validator->check($params, $scene);
  175. if (!is_array($params)) {
  176. return showJson($params, false);
  177. }
  178. $params['user_type'] = 3;
  179. if(!$result = AcceptorService::make()->withdraw($this->userId, $params)){
  180. $error = AcceptorService::make()->getError();
  181. return showJson($error,false,'',$error==2035?405:-1);
  182. }else{
  183. return showJson(AcceptorService::make()->getError(),true, $result);
  184. }
  185. }
  186. /**
  187. * C2C交易-购买星豆
  188. * @param MemberValidator $validator
  189. * @return array
  190. */
  191. public function buyxd(MemberValidator $validator)
  192. {
  193. $params = request()->all();
  194. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  195. $params = $validator->check($params, $scene);
  196. if (!is_array($params)) {
  197. return showJson($params, false);
  198. }
  199. if(!$result = AcceptorService::make()->buyxd($this->userId, $params)){
  200. $error = AcceptorService::make()->getError();
  201. return showJson($error,false, [],$error== 2035? 405:0);
  202. }else{
  203. return showJson(AcceptorService::make()->getError(),true, $result);
  204. }
  205. }
  206. /**
  207. * C2C交易-购买星豆
  208. * @param MemberValidator $validator
  209. * @return array
  210. */
  211. public function sellxd(MemberValidator $validator)
  212. {
  213. $params = request()->all();
  214. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  215. $params = $validator->check($params, $scene);
  216. if (!is_array($params)) {
  217. return showJson($params, false);
  218. }
  219. if(!$result = AcceptorService::make()->sellxd($this->userId, $params)){
  220. $error = AcceptorService::make()->getError();
  221. return showJson($error,false, [],$error== 2035? 405:0);
  222. }else{
  223. return showJson(AcceptorService::make()->getError(),true, $result);
  224. }
  225. }
  226. /**
  227. * 取消
  228. * @return array
  229. */
  230. public function cancel()
  231. {
  232. $params = request()->post();
  233. if(!$result = AcceptorService::make()->cancel($this->userId, $params)){
  234. $error = AcceptorService::make()->getError();
  235. return showJson($error,false, [],$error== 2035? 405:0);
  236. }else{
  237. return showJson(AcceptorService::make()->getError(),true, $result);
  238. }
  239. }
  240. }