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