Orders.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. /**
  5. * 订单管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Orders extends Backend
  10. {
  11. /**
  12. * Orders模型对象
  13. * @var \app\admin\model\user\Orders
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\common\model\ProductOrder;
  20. $this->assignconfig('ids', $this->request->param('ids'));
  21. }
  22. /**
  23. * 查看
  24. * @return string|Json
  25. * @throws \think\Exception
  26. * @throws DbException
  27. */
  28. public function index()
  29. {
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags', 'trim']);
  32. if (false === $this->request->isAjax()) {
  33. return $this->view->fetch();
  34. }
  35. //如果发送的来源是 Selectpage,则转发到 Selectpage
  36. if ($this->request->request('keyField')) {
  37. return $this->selectpage();
  38. }
  39. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  40. $user_id = $this->request->param('ids');
  41. //持有产品中每个产品的持有总量
  42. $list = $this->model->with('products')
  43. ->where($where)
  44. ->where('user_id', $user_id)->where('product_order.status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze])
  45. ->field('user_id, SUM(num) as total_num,products.zh_name')
  46. ->group('product_id')
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. $result = ['total' => $list->total(), 'rows' => $list->items()];
  50. return json($result);
  51. }
  52. }