model = new \app\common\model\ProductOrder; $this->assignconfig('ids', $this->request->param('ids')); } /** * 查看 * @return string|Json * @throws \think\Exception * @throws DbException */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $user_id = $this->request->param('ids'); //持有产品中每个产品的持有总量 $list = $this->model->with('products') ->where($where) ->where('user_id', $user_id)->where('product_order.status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze]) ->field('user_id, SUM(num) as total_num,products.zh_name') ->group('product_id') ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } }