Orders.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\controller\product;
  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\product\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. $product_id = $this->request->param('ids');
  41. //显示该产品下,每个地址持有数量 用户地址 持有数量
  42. $list = $this->model->with('users')
  43. ->where($where)
  44. ->where('product_id', $product_id)->where('product_order.status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze])
  45. ->field('user_id, SUM(num) as total_num,users.address')
  46. ->group('user_id')
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. $result = ['total' => $list->total(), 'rows' => $list->items()];
  50. return json($result);
  51. }
  52. //获取产品总数量
  53. public function getTotalNum()
  54. {
  55. $product_id = $this->request->param('product_id');
  56. $count = $this->model
  57. ->where('product_id', $product_id)
  58. ->where('status', 'in', [$this->model::Paid, $this->model::Transferred, $this->model::Freeze])
  59. ->count();
  60. return json(['totalNum'=>$count]);
  61. }
  62. }