TradeController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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\Services\Api\AcceptorService;
  6. use App\Services\Api\TradeService;
  7. use App\Services\Api\VideoCollectService;
  8. use App\Services\Api\VideoService;
  9. use App\Services\RedisService;
  10. use Illuminate\Http\Request;
  11. /**
  12. * 承兑商交易
  13. * @package App\Http\Controllers\Api
  14. */
  15. class TradeController extends webApp
  16. {
  17. /**
  18. * 订单
  19. * @return array
  20. */
  21. public function index()
  22. {
  23. try {
  24. $params = request()->post();
  25. $pageSize = request()->post('pageSize', 0);
  26. $userId = isset($params['user_id']) && $params['user_id']? $params['user_id'] : $this->userId;
  27. $datas = TradeService::make()->getDataList($params, $pageSize,'', $this->userId);
  28. return showJson(1010, true, $datas);
  29. } catch (\Exception $exception){
  30. RedisService::set("caches:request:error_trade_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  31. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  32. }
  33. }
  34. /**
  35. * 记录
  36. * @return array
  37. */
  38. public function list()
  39. {
  40. try {
  41. $params = request()->post();
  42. $pageSize = request()->post('pageSize', 0);
  43. $params['acceptor_uid'] = isset($params['user_id']) && $params['user_id']? $params['user_id'] : $this->userId;
  44. $datas = TradeService::make()->getDataList($params, $pageSize,'', $this->userId);
  45. return showJson(1010, true, $datas);
  46. } catch (\Exception $exception){
  47. RedisService::set("caches:request:error_trade_list", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  48. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  49. }
  50. }
  51. /**
  52. * 详情
  53. * @return array
  54. */
  55. public function info()
  56. {
  57. $id = request()->post('id', 0);
  58. $info = TradeService::make()->getInfo($id, $this->userId);
  59. if($info){
  60. return showJson(1010, true, $info);
  61. }else{
  62. return showJson(1009, false);
  63. }
  64. }
  65. /**
  66. * 卖出
  67. * @return array
  68. */
  69. public function sell(Request $request)
  70. {
  71. $params = request()->all();
  72. if(!$result = TradeService::make()->sell($this->userId, $params, $request)){
  73. return showJson(VideoService::make()->getError(), false);
  74. }else{
  75. return showJson(VideoService::make()->getError(), true, $result);
  76. }
  77. }
  78. /**
  79. * 点赞
  80. * @return array|mixed
  81. */
  82. public function like()
  83. {
  84. $params = request()->post();
  85. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  86. return showJson(VideoCollectService::make()->getError(), false);
  87. }else{
  88. return showJson(VideoCollectService::make()->getError(), true, $result);
  89. }
  90. }
  91. /**
  92. * 收藏
  93. * @return array|mixed
  94. */
  95. public function collect()
  96. {
  97. $params = request()->post();
  98. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  99. return showJson(VideoCollectService::make()->getError(), false);
  100. }else{
  101. return showJson(VideoCollectService::make()->getError(), true, $result);
  102. }
  103. }
  104. /**
  105. * 状态
  106. * @return array|mixed
  107. */
  108. public function status()
  109. {
  110. if(!$result = VideoService::make()->status()){
  111. return showJson(VideoService::make()->getError(), false);
  112. }else{
  113. return showJson(VideoService::make()->getError(), true, $result);
  114. }
  115. }
  116. /**
  117. * 删除
  118. * @return array|mixed
  119. */
  120. public function delete()
  121. {
  122. if(!$result = VideoService::make()->delete()){
  123. return showJson(VideoService::make()->getError(), false);
  124. }else{
  125. return showJson(VideoService::make()->getError(), true);
  126. }
  127. }
  128. /**
  129. * C2C交易-确认
  130. * @param MemberValidator $validator
  131. * @return array
  132. */
  133. public function confirm(MemberValidator $validator)
  134. {
  135. $params = request()->all();
  136. $scene = isset($params['scene'])? $params['scene'] : 'recharge';
  137. $params = $validator->check($params, $scene);
  138. if (!is_array($params)) {
  139. return showJson($params, false);
  140. }
  141. if(!$result = TradeService::make()->confirm($this->userId, $params)){
  142. $error = TradeService::make()->getError();
  143. return showJson($error,false, [],$error== 2035? 405:0);
  144. }else{
  145. return showJson(TradeService::make()->getError(),true, $result);
  146. }
  147. }
  148. }