| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\admin\controller\product;
- use app\common\controller\Backend;
- /**
- * 订单管理
- *
- * @icon fa fa-circle-o
- */
- class Orders extends Backend
- {
- /**
- * Orders模型对象
- * @var \app\admin\model\product\Orders
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- $product_id = $this->request->param('ids');
- //显示该产品下,每个地址持有数量 用户地址 持有数量
- $list = $this->model->with('users')
- ->where($where)
- ->where('product_id', $product_id)->where('product_order.status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze])
- ->field('user_id, SUM(num) as total_num,users.address')
- ->group('user_id')
- ->order($sort, $order)
- ->paginate($limit);
-
-
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- //获取产品总数量
- public function getTotalNum()
- {
- $product_id = $this->request->param('product_id');
- $count = $this->model
- ->where('product_id', $product_id)
- ->where('status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze])
- ->count();
- return json(['totalNum'=>$count]);
- }
- }
|