ShopDelivery.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller\shop;
  4. use app\common\controller\Backend;
  5. use think\annotation\route\Group;
  6. use app\admin\traits\Actions;
  7. use think\annotation\route\Route;
  8. use app\common\model\ShopDelivery as ShopDeliveryModel;
  9. #[Group("shop/shop_delivery")]
  10. class ShopDelivery extends Backend
  11. {
  12. use Actions;
  13. protected function _initialize()
  14. {
  15. parent::_initialize();
  16. $this->model = new ShopDeliveryModel();
  17. $this->assign('platformList', site_config('addonsd.platform_list'));
  18. $this->relationField=['customer','user','shops', 'variety', 'specs'];
  19. }
  20. /**
  21. * 查看
  22. */
  23. #[Route('GET,JSON','index')]
  24. public function index()
  25. {
  26. if (false === $this->request->isAjax()) {
  27. return $this->fetch();
  28. }
  29. if($this->request->post('selectpage')){
  30. return $this->selectpage();
  31. }
  32. [$where, $order, $limit, $with] = $this->buildparams();
  33. $list = $this->model
  34. ->withJoin($with,'left')
  35. //如果没有使用operate filter过滤的情况下,推荐使用with关联,可以提高查询效率
  36. //->with($with)
  37. ->where($where)
  38. ->order($order)
  39. ->paginate($limit);
  40. //表格底部要有汇总:发货数量汇总 重量汇总 总价汇总
  41. $count = $this->model->field('sum(num) total_num, sum(weigh) total_weigh, sum(total_price) total_price')->select()->toArray();
  42. $result = ['total' => $list->total(), 'rows' => $list->items(),
  43. 'total_num' => $count[0]['total_num']??0,
  44. 'total_weigh' => $count[0]['total_weigh']??0,
  45. 'total_price' => $count[0]['total_price']??0];
  46. return json($result);
  47. }
  48. }