ShopDelivery.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 think\facade\Db;
  9. use app\common\model\ShopDelivery as ShopDeliveryModel;
  10. #[Group("shop/shop_delivery")]
  11. class ShopDelivery extends Backend
  12. {
  13. use Actions;
  14. protected function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->model = new ShopDeliveryModel();
  18. $this->assign('platformList', site_config('addonsd.platform_list'));
  19. //,'shops', 'variety', 'specs'
  20. $this->relationField=['customer','user'];
  21. }
  22. /**
  23. * 查看
  24. */
  25. #[Route('GET,JSON','index')]
  26. public function index()
  27. {
  28. if (false === $this->request->isAjax()) {
  29. return $this->fetch();
  30. }
  31. if($this->request->post('selectpage')){
  32. return $this->selectpage();
  33. }
  34. [$where, $order, $limit, $with] = $this->buildparams();
  35. $list = $this->model
  36. ->withJoin($with,'left')
  37. //如果没有使用operate filter过滤的情况下,推荐使用with关联,可以提高查询效率
  38. //->with($with)
  39. ->where($where)
  40. ->order($order)
  41. ->paginate($limit);
  42. //表格底部要有汇总:发货数量汇总 重量汇总 总价汇总
  43. $count = $this->model
  44. ->withJoin($with,'left')
  45. ->where($where)
  46. ->field('sum(num) total_num, sum(weigh) total_weigh, sum(total_price) total_price')
  47. ->group('shop_delivery.id')
  48. ->select()
  49. ->toArray();
  50. $result = ['total' => $list->total(), 'rows' => $list->items(),
  51. 'total_num' => $count[0]['total_num']??0,
  52. 'total_weigh' => $count[0]['total_weigh']??0,
  53. 'total_price' => $count[0]['total_price']??0];
  54. return json($result);
  55. }
  56. /**
  57. * 结算
  58. */
  59. #[Route('GET,POST','settlement')]
  60. public function settlement()
  61. {
  62. $ids =$this->request->post('ids/a', []);
  63. if(empty($ids)) return resp_json(0, '请选着要结算记录');
  64. $result = false;
  65. Db::startTrans();
  66. try {
  67. $result = $this->model->whereIn('id', $ids)->save(['status'=>$this->model::StatusSettlement]);
  68. if($this->callback){
  69. $callback=$this->callback;
  70. $callback($this->model);
  71. }
  72. Db::commit();
  73. } catch (\Exception $e) {
  74. Db::rollback();
  75. $this->error($e->getMessage());
  76. }
  77. if ($result === false) {
  78. $this->error(__('没有新增任何数据'));
  79. }
  80. return resp_json(200,'操作成功');
  81. }
  82. }