TradeController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Common\MemberService;
  5. use App\Services\Common\TradeService;
  6. /**
  7. * 交易
  8. * Class TradeController
  9. * @package App\Http\Controllers\Api
  10. */
  11. class TradeController extends webApp
  12. {
  13. public function index()
  14. {
  15. $params = request()->all();
  16. $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
  17. $type = isset($params['type'])? $params['type'] : 1;
  18. $status = isset($params['status'])? $params['status'] : 0;
  19. // 我的订单
  20. if($type == 1){
  21. $params['user_id'] = $this->userId;
  22. $params['sell_uid'] = $this->userId;
  23. }
  24. // 推广订单
  25. else if($type == 2){
  26. $params['parent_id'] = $this->userId;
  27. }
  28. // 店铺订单
  29. else if($type == 3){
  30. $params['shop_id'] = $this->shopId;
  31. }
  32. $params['goods_status'] = 1;
  33. $params['time'] = strtotime(date('Y-m-d'));
  34. $datas = TradeService::make()->getDataList($params, $pageSize);
  35. return message(1010, true, $datas);
  36. }
  37. // 转商品列表
  38. public function switchGoods()
  39. {
  40. $params = request()->all();
  41. $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
  42. $params['shop_id'] = $this->shopId;
  43. $params['time'] = strtotime(date('Y-m-d'));
  44. $datas = TradeService::make()->getSwitchGoods($params, $pageSize);
  45. return message(1010, true, $datas);
  46. }
  47. /**
  48. * 详情
  49. * @return array|mixed
  50. */
  51. public function info()
  52. {
  53. $id = request()->post('id', 0);
  54. $info = TradeService::make()->getInfo($id);
  55. return message(1010, true, $info);
  56. }
  57. /**
  58. * 统计
  59. * @return array
  60. */
  61. public function counts()
  62. {
  63. $params = request()->all();
  64. $type = isset($params['type'])? $params['type'] : 1;
  65. $status = isset($params['status'])? $params['status'] : 0;
  66. // 我的订单
  67. if($type == 1){
  68. if($status==2){
  69. $params['sell_uid'] = $this->userId;
  70. }else{
  71. $params['user_id'] = $this->userId;
  72. }
  73. }
  74. // 推广订单
  75. else if($type == 2){
  76. $params['parent_id'] = $this->userId;
  77. }
  78. // 店铺订单
  79. else if($type == 3){
  80. $params['shop_id'] = $this->shopId;
  81. }
  82. $params['time'] = strtotime(date('Y-m-d'))-86400*7;
  83. $counts = TradeService::make()->getCounts($params);
  84. return message(1010, true, $counts);
  85. }
  86. /**
  87. * 抢拍
  88. * @return array
  89. */
  90. public function buy()
  91. {
  92. if(TradeService::make()->buy(request()->all(), $this->userId, $this->shopId)){
  93. return message(TradeService::make()->getError(), true);
  94. }else{
  95. return message(TradeService::make()->getError(), false);
  96. }
  97. }
  98. /**
  99. * 付款
  100. * @return array
  101. */
  102. public function pay()
  103. {
  104. if(TradeService::make()->pay(request()->all(), $this->userId, $this->shopId)){
  105. return message(TradeService::make()->getError(), true);
  106. }else{
  107. return message(TradeService::make()->getError(), false);
  108. }
  109. }
  110. /**
  111. * 确认收款
  112. * @return array
  113. */
  114. public function confirm()
  115. {
  116. if(TradeService::make()->confirm(request()->all(), $this->userId)){
  117. return message(TradeService::make()->getError(), true);
  118. }else{
  119. return message(TradeService::make()->getError(), false);
  120. }
  121. }
  122. /**
  123. * 上架
  124. * @return array
  125. */
  126. public function sell()
  127. {
  128. if(TradeService::make()->sell(request()->all(), $this->userId)){
  129. return message(TradeService::make()->getError(), true);
  130. }else{
  131. return message(TradeService::make()->getError(), false);
  132. }
  133. }
  134. /**
  135. * 上架审核
  136. * @return array
  137. */
  138. public function sellConfirm()
  139. {
  140. if(TradeService::make()->sellConfirm(request()->all())){
  141. return message(TradeService::make()->getError(), true);
  142. }else{
  143. return message(TradeService::make()->getError(), false);
  144. }
  145. }
  146. /**
  147. * 修改订单
  148. * @return array
  149. */
  150. public function modify()
  151. {
  152. if(TradeService::make()->modify(request()->all())){
  153. return message(TradeService::make()->getError(), true);
  154. }else{
  155. return message(TradeService::make()->getError(), false);
  156. }
  157. }
  158. /**
  159. * 取消订单
  160. * @return array
  161. */
  162. public function cancel()
  163. {
  164. if(TradeService::make()->cancel(request()->all())){
  165. return message(TradeService::make()->getError(), true);
  166. }else{
  167. return message(TradeService::make()->getError(), false);
  168. }
  169. }
  170. }