AcceptorController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. var_dump($userId);
  25. $info = AcceptorService::make()->getInfo($id,'', $userId?$userId:$this->userId);
  26. if($info){
  27. return showJson(1010, true, $info);
  28. }else{
  29. return showJson(2216, false, [],'404');
  30. }
  31. }
  32. /**
  33. * 商家列表
  34. * @return array
  35. */
  36. public function index()
  37. {
  38. $params = request()->post();
  39. $pageSize = request()->post('pageSize', 6);
  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 MemberValidator $validator
  133. * @return array
  134. */
  135. public function deposit(MemberValidator $validator)
  136. {
  137. $params = request()->all();
  138. $params = $validator->check($params, 'deposit');
  139. if (!is_array($params)) {
  140. return showJson($params, false);
  141. }
  142. if(!$result = MerchantService::make()->deposit($this->userId, $params)){
  143. return showJson(MerchantService::make()->getError(),false);
  144. }else{
  145. return showJson(MerchantService::make()->getError(),true, $result);
  146. }
  147. }
  148. /**
  149. * 退还保证金
  150. * @param MemberValidator $validator
  151. * @return array
  152. */
  153. public function rebackDeposit(MemberValidator $validator)
  154. {
  155. $params = request()->all();
  156. $params = $validator->check($params, 'reback_deposit');
  157. if (!is_array($params)) {
  158. return showJson($params, false);
  159. }
  160. if(!$result = MerchantService::make()->rebackDeposit($this->userId, $params)){
  161. return showJson(MerchantService::make()->getError(),false);
  162. }else{
  163. return showJson(MerchantService::make()->getError(),true);
  164. }
  165. }
  166. /**
  167. * 提现
  168. * @param MemberValidator $validator
  169. * @return array
  170. */
  171. public function withdraw(MemberValidator $validator)
  172. {
  173. $params = request()->all();
  174. $scene = isset($params['scene'])? $params['scene'] : 'withdraw';
  175. $params = $validator->check($params, $scene);
  176. if (!is_array($params)) {
  177. return showJson($params, false);
  178. }
  179. $params['user_type'] = 3;
  180. if(!$result = AcceptorService::make()->withdraw($this->userId, $params)){
  181. $error = AcceptorService::make()->getError();
  182. return showJson($error,false,'',$error==2035?405:-1);
  183. }else{
  184. return showJson(AcceptorService::make()->getError(),true, $result);
  185. }
  186. }
  187. /**
  188. * C2C交易-购买星豆
  189. * @param MemberValidator $validator
  190. * @return array
  191. */
  192. public function buyxd(MemberValidator $validator)
  193. {
  194. $params = request()->all();
  195. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  196. $params = $validator->check($params, $scene);
  197. if (!is_array($params)) {
  198. return showJson($params, false);
  199. }
  200. if(!$result = AcceptorService::make()->buyxd($this->userId, $params)){
  201. $error = AcceptorService::make()->getError();
  202. return showJson($error,false, [],$error== 2035? 405:0);
  203. }else{
  204. return showJson(AcceptorService::make()->getError(),true, $result);
  205. }
  206. }
  207. /**
  208. * C2C交易-购买星豆
  209. * @param MemberValidator $validator
  210. * @return array
  211. */
  212. public function sellxd(MemberValidator $validator)
  213. {
  214. $params = request()->all();
  215. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  216. $params = $validator->check($params, $scene);
  217. if (!is_array($params)) {
  218. return showJson($params, false);
  219. }
  220. if(!$result = AcceptorService::make()->sellxd($this->userId, $params)){
  221. $error = AcceptorService::make()->getError();
  222. return showJson($error,false, [],$error== 2035? 405:0);
  223. }else{
  224. return showJson(AcceptorService::make()->getError(),true, $result);
  225. }
  226. }
  227. /**
  228. * 取消
  229. * @return array
  230. */
  231. public function cancel()
  232. {
  233. $params = request()->post();
  234. if(!$result = AcceptorService::make()->cancel($this->userId, $params)){
  235. $error = AcceptorService::make()->getError();
  236. return showJson($error,false, [],$error== 2035? 405:0);
  237. }else{
  238. return showJson(AcceptorService::make()->getError(),true, $result);
  239. }
  240. }
  241. }