diff --git a/application/admin/controller/statistics/Aftersale.php b/application/admin/controller/statistics/Aftersale.php index e643a25..9163f45 100644 --- a/application/admin/controller/statistics/Aftersale.php +++ b/application/admin/controller/statistics/Aftersale.php @@ -6,6 +6,7 @@ namespace app\admin\controller\statistics; use app\admin\model\Admin; use app\admin\model\Order; use app\common\controller\Backend; +use think\Db; use think\Model; use function Symfony\Component\Clock\now; @@ -17,10 +18,23 @@ use function Symfony\Component\Clock\now; class Aftersale extends Backend { - protected $relationSearch = true; + protected $relationSearch = true,$items,$itemsformattedTree; public function _initialize() { + + $items = Db::name('item') + ->where('status', 1) + ->field(['id', 'title', 'key_word', 'pid']) + ->order('pid', 'asc') + ->order('sort', 'desc') + ->select(); + $tree = $this->buildTree($items); + $formattedTree = $this->formatTree($tree); + + $this->items = $items; + $this->itemsformattedTree = $formattedTree; + $this->view->assign("items", $formattedTree); parent::_initialize(); } @@ -39,15 +53,45 @@ class Aftersale extends Backend { $build = new Admin(); $build->alias('a') - ->join('order b','a.id = b.admin_id','right') - ->join('aftersale c','b.id = c.admin_id','left') - ->where('b.status',Order::STATUS_FINISHED); + ->join('order b', 'a.id = b.admin_id', 'right') + ->join('aftersale c', 'b.id = c.admin_id', 'left') + ->where('b.status', Order::STATUS_FINISHED); + + + $start = now()->modify('-30 days')->format('Y-m-d'); + $end_at = now()->format('Y-m-d 23:29:59'); + + + $filter = request()->get('range', ''); + if (!empty($filter)) { + $arr = explode(' - ', $filter); + if (trim($arr[0])) { + $start = trim($arr[0]); + } + if (trim($arr[1])) { + $end_at = trim($arr[1]) . ' 23:29:59'; + } + } + $keyword = request()->get('keyword'); + + + $build->where('audit_time', '>=', $start); + $build->where('audit_time', '<=', $end_at); + + if (!is_null($keyword)) { + $build->where(function ($q) use ($keyword) { + $q->where('nickname', 'like', '%' . $keyword . '%') + ->whereor('mobile', 'like', '%' . $keyword . '%'); + }); + } + $build->group('a.id'); $build->field( [ 'a.id', 'a.nickname', + 'a.mobile', 'count(b.id) order_total', 'count(c.id) after_total', ] @@ -57,31 +101,146 @@ class Aftersale extends Backend $total = $res->total(); $ress = $res->items(); // dd(Admin::getLastSql()); + $data = []; + foreach ($ress as $res) { + $item = $res->toArray(); + $item['rate'] = $this->mydiv($item['after_total'],$item['order_total']) . '%'; + $data [] = $item; + } return [ - 'rows' => $ress, - 'total' => $total - ]; + 'rows' => $data, + 'total' => $total + ]; + + + } + public function city() + { + $build = new Order(); + $build->alias('a') + ->join('aftersale c', 'a.id = c.order_id', 'left') + ->where('a.status', Order::STATUS_FINISHED); + + $start = now()->modify('-30 days')->format('Y-m-d'); + $end_at = now()->format('Y-m-d 23:29:59'); + $area_code = request()->get('area_id'); + $filter = request()->get('range', ''); + if (!empty($filter)) { + $arr = explode(' - ', $filter); + if (trim($arr[0])) { + $start = trim($arr[0]); + } + if (trim($arr[1])) { + $end_at = trim($arr[1]) . ' 23:29:59'; + } + } + $build->where('audit_time', '>=', $start); + $build->where('audit_time', '<=', $end_at); + $build->group('a.area_id'); + + + if ($area_code) { + $build->where('area_id', 'like', $this->getSelectAreaCode($area_code) . '%'); + } + + $build->field( + [ + 'a.area_id', + 'count(a.id) order_total', + 'count(c.id) after_total', + ] + )->with([ + 'area' => function ($q) { + $q->field('id,area_code,merge_name'); + } + ]); + + $res = $build->paginate(); + $total = $res->total(); + $ress = $res->items(); +// dd(Admin::getLastSql()); + $data = []; + foreach ($ress as $res) { + $item = $res->toArray(); + $item['rate'] = $this->mydiv($item['after_total'],$item['order_total']) . '%'; + $data [] = $item; + } + return [ + 'rows' => $data, + 'total' => $total + ]; + } + + public function item() + { + $build = new Order(); + $build->alias('a') + ->join('aftersale c', 'a.id = c.order_id', 'left') + ->where('a.status', Order::STATUS_FINISHED); + + $start = now()->modify('-30 days')->format('Y-m-d'); + $end_at = now()->format('Y-m-d 23:29:59'); + $area_code = request()->get('area_id'); + $filter = request()->get('range', ''); + if (!empty($filter)) { + $arr = explode(' - ', $filter); + if (trim($arr[0])) { + $start = trim($arr[0]); + } + if (trim($arr[1])) { + $end_at = trim($arr[1]) . ' 23:29:59'; + } + } + $build->where('audit_time', '>=', $start); + $build->where('audit_time', '<=', $end_at); + $build->group('a.item_title'); + + + if ($area_code) { + $build->where('area_id', 'like', $this->getSelectAreaCode($area_code) . '%'); + } + + $build->field( + [ + 'a.item_title', + 'count(a.id) order_total', + 'count(c.id) after_total', + ] + ); + + $res = $build->paginate(); + $total = $res->total(); + $ress = $res->items(); +// dd(Admin::getLastSql()); + $data = []; + foreach ($ress as $res) { + $item = $res->toArray(); + $item['rate'] = $this->mydiv($item['after_total'],$item['order_total']) . '%'; + $data [] = $item; + } + return [ + 'rows' => $data, + 'total' => $total + ]; + } + private function mydiv($a, $b, int $scale = 4, $is_percent = true): int|string + { + $val = $b > 0 ? bcdiv($a, $b, $scale) : 0; + if ($is_percent) { - - - - - - - - - - - + return bcmul($val, 100, 2); + } + return $val; + } } diff --git a/application/admin/controller/statistics/Item.php b/application/admin/controller/statistics/Item.php index bb266f6..641a550 100644 --- a/application/admin/controller/statistics/Item.php +++ b/application/admin/controller/statistics/Item.php @@ -206,8 +206,6 @@ class Item extends Backend ]; } - - return $result; } diff --git a/application/admin/view/order/add.html b/application/admin/view/order/add.html index cc297f1..7da2239 100644 --- a/application/admin/view/order/add.html +++ b/application/admin/view/order/add.html @@ -7,189 +7,193 @@