Order.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Index.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: https://www.niushop.com
  9. * =========================================================
  10. * @author : niuteam
  11. * @date : 2022.8.8
  12. * @version : v5.0.0.1
  13. */
  14. namespace addon\pintuan\api\controller;
  15. use addon\pintuan\model\Pintuan;
  16. use addon\pintuan\model\PintuanOrder as PintuanOrderModel;
  17. use app\api\controller\BaseApi;
  18. /**
  19. * 拼团订单
  20. * @author Administrator
  21. *
  22. */
  23. class Order extends BaseApi
  24. {
  25. /**
  26. * 拼团订单详情
  27. * @return string
  28. */
  29. public function detail()
  30. {
  31. $token = $this->checkToken();
  32. if ($token[ 'code' ] < 0) return $this->response($token);
  33. $id = isset($this->params[ 'id' ]) ? $this->params[ 'id' ] : 0;//拼团订单主键id
  34. if (empty($id)) {
  35. return $this->response($this->error('', 'REQUEST_ID'));
  36. }
  37. $pintuan_order_model = new PintuanOrderModel();
  38. $res = $pintuan_order_model->getPintuanOrderDetail($id, $this->member_id, $this->site_id);
  39. return $this->response($res);
  40. }
  41. /**
  42. * 拼团列表
  43. * @return string
  44. */
  45. public function page()
  46. {
  47. $token = $this->checkToken();
  48. if ($token[ 'code' ] < 0) return $this->response($token);
  49. $pintuan_order_model = new PintuanOrderModel();
  50. $condition = array (
  51. [ "ppo.member_id", "=", $this->member_id ],
  52. [ "ppo.site_id", "=", $this->site_id ]
  53. );
  54. $pintuan_status = isset($this->params[ 'pintuan_status' ]) ? $this->params[ 'pintuan_status' ] : 'all';
  55. if ($pintuan_status != "all") {
  56. $condition[] = [ "ppo.pintuan_status", "=", $pintuan_status ];
  57. } else {
  58. $condition[] = [ "ppo.pintuan_status", "<>", "0" ];//不查询未支付的拼团
  59. }
  60. $page_index = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  61. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  62. $res = $pintuan_order_model->getPintuanOrderPageList($condition, $page_index, $page_size, "o.pay_time desc");
  63. if (!empty($res[ 'data' ][ 'list' ])) {
  64. foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
  65. $member_list = $pintuan_order_model->getPintuanOrderList([ [ "group_id", "=", $v[ "group_id" ] ], [ 'pintuan_status', 'in', '2,3' ] ], "member_img,nickname");
  66. $res[ 'data' ][ 'list' ][ $k ][ 'member_list' ] = $member_list[ 'data' ];
  67. }
  68. }
  69. return $this->response($res);
  70. }
  71. /**
  72. * 拼团会员
  73. * @return string
  74. */
  75. public function pintuanMember()
  76. {
  77. $token = $this->checkToken();
  78. $pintuan_order_model = new PintuanOrderModel();
  79. $pintuan = new Pintuan();
  80. $condition = array (
  81. [ "site_id", "=", $this->site_id ],
  82. [ "pintuan_status", "=", '3' ],
  83. );
  84. $limit = isset($this->params[ 'num' ]) ? $this->params[ 'num' ] : 5;
  85. $field = 'head_id,member_id,member_img,nickname';
  86. $pintuna_member_list = $pintuan_order_model->getPintuanOrderList($condition, $field, 'id desc', $limit, 'member_id')[ 'data' ] ?? [];
  87. $pintuna_member_count = $pintuan->getPintuanInfo([
  88. [ 'pp.site_id', '=', $this->site_id ],
  89. [ 'pp.status', '=', 1 ],
  90. ], '(sum(g.sale_num) + sum(g.virtual_sale)) as sale_num', 'pp', [
  91. [ 'goods g', 'g.goods_id=pp.goods_id', 'inner' ],
  92. ])[ 'data' ][ 'sale_num' ] ?? 0;
  93. $data = [
  94. 'member_list' => $pintuna_member_list,
  95. 'pintuan_count' => numberFormat($pintuna_member_count)
  96. ];
  97. return $this->response($this->success($data));
  98. }
  99. }