diff --git a/application/admin/behavior/OrderDispatchLog.php b/application/admin/behavior/OrderDispatchLog.php index 9708c55..b152f5a 100644 --- a/application/admin/behavior/OrderDispatchLog.php +++ b/application/admin/behavior/OrderDispatchLog.php @@ -48,7 +48,8 @@ class OrderDispatchLog 'type' => 1, 'outid' => md5(time().rand(1000,9999).rand(1000,9999)), 'create_time' => date('Y-m-d H:i:s'), - 'status' => $alibaba_dyvms['sync']?1:0 + 'status' => $alibaba_dyvms['sync']?1:0, + 'mobile' => $dispatch->worker_tel, ]; $service = new NoticeLogic(); $service->dispatchNotice($dispatch); diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index 918f744..7fb1b9f 100755 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -374,6 +374,6 @@ class Ajax extends Backend public function getItems(){ - return $items = \app\admin\model\Item::where('level',1)->field('id,title as name')->select(); + return $items = \app\admin\model\Item::where('level',1)->field('id,title as name')->order('sort','desc')->select(); } } diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 63a35ab..ceed3d3 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -177,6 +177,11 @@ class Order extends Backend ]) ->where($where); $filter = (array)json_decode(input()['filter'] ?? '', true); + + if(isset($filter['audit_time'])){ + $build->where('status',\app\admin\model\Order::STATUS_FINISHED); + } + $admin_filter = $filter['user.nickname'] ?? false; $area_id = $filter['area_id'] ?? false; $item_id = $filter['item_id'] ?? false; @@ -252,6 +257,10 @@ class Order extends Backend }else{ $item->source_total_name = ($item->getRelation('source')->title??''); } + + if($item->status <60){ + $item->audit_time = null; + } unset($item->source); } $result = ['total' => $list->total(), 'rows' => $list->items()]; @@ -327,6 +336,7 @@ class Order extends Backend $params['create_time'] = date('Y-m-d H:i:s'); $params['update_time'] = date('Y-m-d H:i:s'); $params['receive_type'] = $params['receive_type']?: 1; + $params['audit_time'] = date('Y-m-d H:i:s'); $result = $this->model->allowField(true)->save($params); $auth = clone $this->auth; @@ -627,14 +637,16 @@ class Order extends Backend 'update_time' => now()->format('Y-m-d H:m:s'), ]; + $orderDispatch = OrderDispatch::where('order_id',$order->id)->whereBetween('status','>=',0)->find(); if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3) { $order->status = \app\admin\model\Order::STATUS_CANCEL; $order->save(); - if (!empty($order->dispatch->id)) { + + if (!empty($orderDispatch)) { $orderLogic = new OrderLogic(); - $orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false); + $orderLogic->cancelOrderDispatch($orderDispatch, $this->auth, '订单被取消', false); //日志 $hookparams['order'] = $order; $hookparams['role'] = 1; @@ -654,9 +666,9 @@ class Order extends Backend $order->status = \app\admin\model\Order::STATUS_DISPATCHING; $order->save(); - if (!empty($order->dispatch->id)) { + if (!empty($orderDispatch)) { $OrderLogic = new OrderLogic(); - $OrderLogic->noWorkerCanGetIt($order->dispatch, '系统取消' . $abnormal_title); + $OrderLogic->noWorkerCanGetIt($orderDispatch, '系统取消' . $abnormal_title); AutoDispatchLogic::autoDispatch($order); } @@ -679,7 +691,6 @@ class Order extends Backend $result = \model('order_abnormal')->insert($insert); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { - throw $e; Db::rollback(); $this->error($e->getMessage()); } diff --git a/application/admin/controller/Orderplan.php b/application/admin/controller/Orderplan.php index 97444e1..658442f 100644 --- a/application/admin/controller/Orderplan.php +++ b/application/admin/controller/Orderplan.php @@ -133,13 +133,13 @@ class Orderplan extends Backend } $build->field([ - 'DATE(create_time) day', + 'DATE(audit_time) day', 'sum(total) total', 'count(id) count', 'sum(performance) performance' ]) ->where('status',\app\admin\model\Order::STATUS_FINISHED) - ->group(' DATE(create_time)'); + ->group(' DATE(audit_time)'); $res = $this->buildDate($build)->select(); $data = []; @@ -300,17 +300,26 @@ class Orderplan extends Backend $start = now()->format('Y-m-d 00:00:00'); $end_at = now()->format('Y-m-d 23:59:59'); + $build = new \app\admin\model\Order(); + $build->whereBetween('audit_time', [$start, $end_at]) + ->where('status',\app\admin\model\Order::STATUS_FINISHED); + $data1 = $build->field([ + 'sum(total) total', + 'count(*) count', + ])->select(); + + $build = new \app\admin\model\Order(); $build->whereBetween('create_time', [$start, $end_at]); $data = $build->field([ - 'sum(total) total', - 'count(id) count', + /* 'sum(total) total', + 'count(id) count',*/ 'count(if(status=-10,1,null)) cancel' ])->select(); $today = [ - 'total' => $data[0]->total ?? 0, - 'count' => $data[0]->count ?? 0, + 'total' => $data1[0]->total ?? 0, + 'count' => $data1[0]->count ?? 0, 'cancel' => $data[0]->cancel ?? 0, ]; diff --git a/application/admin/controller/aftersales/Aftersale.php b/application/admin/controller/aftersales/Aftersale.php index 5a9cf39..3ec0905 100644 --- a/application/admin/controller/aftersales/Aftersale.php +++ b/application/admin/controller/aftersales/Aftersale.php @@ -264,6 +264,7 @@ class Aftersale extends Backend $this->error('订单不存在'); } $order->status = Order::STATUS_FINISHED; + $order->audit_time = date('Y-m-d H:i:s'); $order->save(); } diff --git a/application/admin/controller/aftersales/Aftersale2.php b/application/admin/controller/aftersales/Aftersale2.php index 341e8cb..a34707a 100644 --- a/application/admin/controller/aftersales/Aftersale2.php +++ b/application/admin/controller/aftersales/Aftersale2.php @@ -478,6 +478,7 @@ class Aftersale2 extends Backend $order = Order::get($row->order_id); //重新计算订单利润 $order->status = Order::STATUS_FINISHED; + $order->audit_time = date('Y-m-d H:i:s'); $order->save(); $orderLogic = new OrderLogic(); $orderLogic->recacle($order,$row); diff --git a/application/admin/controller/orders/Auditorder.php b/application/admin/controller/orders/Auditorder.php index 2979194..b5b37f0 100644 --- a/application/admin/controller/orders/Auditorder.php +++ b/application/admin/controller/orders/Auditorder.php @@ -124,7 +124,8 @@ class Auditorder extends Backend if (false === $this->request->isPost()) { $order = Order::where('id',$ids)->find(); $this->view->assign('row', $row); - $this->view->assign('worker',Worker::where('id',$order->worker_id)->find()); + $worker = Worker::withTrashed()->where('id', $order->worker_id)->find(); + $this->view->assign('worker',$worker); $this->view->assign('cdnurl', config('upload.cdnurl')); return $this->view->fetch(); } diff --git a/application/admin/controller/orders/Configorder.php b/application/admin/controller/orders/Configorder.php index 942ea8e..0dcc945 100644 --- a/application/admin/controller/orders/Configorder.php +++ b/application/admin/controller/orders/Configorder.php @@ -118,7 +118,8 @@ class Configorder extends Backend } if (false === $this->request->isPost()) { $this->view->assign('row', $row); - $worker = Worker::where('id',$row->worker_id)->find(); + //$worker = Worker::where('id',$row->worker_id)->find(); + $worker = Worker::withTrashed()->where('id', $row->worker_id)->find(); $this->view->assign('worker', $worker); return $this->view->fetch(); } @@ -143,6 +144,7 @@ class Configorder extends Backend $data = [ 'status' => Order::STATUS_AUDITING, + 'online_amount' => $params['online_amount'], 'online_amount_last' => $params['online_amount_last'], 'offline_amount' => $params['offline_amount'], // 'refund_amount' => $params['refund_amount'], @@ -160,7 +162,7 @@ class Configorder extends Backend $cost = bcadd($params['cost'],$params['material_cost'],2); - $data['total'] = bcadd($row->online_amount,$last_amount,2); + $data['total'] = bcadd($params['online_amount'],$last_amount,2); $data['real_amount'] = $data['total']; $data['performance'] = bcsub($data['real_amount'],$cost,2); $result = $row->allowField(true)->save($data); diff --git a/application/admin/controller/orders/Dispatch2.php b/application/admin/controller/orders/Dispatch2.php index ecd1363..840e4b2 100644 --- a/application/admin/controller/orders/Dispatch2.php +++ b/application/admin/controller/orders/Dispatch2.php @@ -323,6 +323,7 @@ class Dispatch2 extends Backend //计算价格 $data = [ + 'online_amount' => $orderParsms['online_amount'], //线上尾款 'online_amount_last' => $row->online_total, //线上尾款 'offline_amount' => $row->total, //线下尾款 'cost' => $orderParsms['cost'], @@ -340,7 +341,7 @@ class Dispatch2 extends Backend $cost = bcadd($data['cost'],$data['material_cost'],2); - $data['total'] = bcadd($order->online_amount,$last_amount,2); + $data['total'] = bcadd($data['online_amount'],$last_amount,2); $data['real_amount'] = $data['total']; $data['performance'] = bcsub($data['real_amount'],$cost,2); $order->allowField(true)->save($data); diff --git a/application/admin/controller/statistics/Dispatcher.php b/application/admin/controller/statistics/Dispatcher.php index 5d53698..2f59615 100644 --- a/application/admin/controller/statistics/Dispatcher.php +++ b/application/admin/controller/statistics/Dispatcher.php @@ -137,14 +137,17 @@ class Dispatcher extends Backend // 使用 IFNULL 确保结果为 null 时返回 0 "IFNULL(COUNT(CASE WHEN status = 60 THEN 1 END), 0) AS finish_num", //完成数 "IFNULL(COUNT(CASE WHEN status IN (".$orderValid.") THEN 1 END), 0) AS count_num", //总订单数 (排除取消 和草稿) - "IFNULL(COUNT(CASE WHEN is_overtime = 1 THEN 1 END), 0) AS overtime_num", //超时数 + "IFNULL(COUNT(CASE WHEN status = 60 AND is_overtime = 1 THEN 1 END), 0) AS overtime_num", //超时数 "IFNULL(SUM(CASE WHEN status = 60 THEN total END), 0) AS total", //成效额 "IFNULL(SUM(CASE WHEN status = 60 THEN performance END), 0) AS performance", //业绩 "IFNULL(SUM(CASE WHEN status = 60 THEN (cost + material_cost) END), 0) AS cost_total", //总成本 - "IFNULL(SUM(CASE WHEN status = 60 THEN (refund_amount + worker_refund_amount) END), 0) AS refund_total", //退款总数 - "IFNULL(COUNT(CASE WHEN refund_amount > 0 OR worker_refund_amount > 0 THEN 1 END), 0) AS refund_count", //退款订单数量 - "IFNULL(AVG(CASE WHEN status > 10 THEN UNIX_TIMESTAMP(dispatch_time) - UNIX_TIMESTAMP(create_time) END), 0) AS avg_time_diff", //派单时效 + //"IFNULL(SUM(CASE WHEN status = 60 THEN (refund_amount + worker_refund_amount) END), 0) AS refund_total", //退款总数 + "SUM( + CASE WHEN status = 60 THEN (refund_amount + worker_refund_amount) ELSE 0 END +) AS refund_total", + "IFNULL(COUNT(CASE WHEN status = 60 AND (refund_amount > 0 OR worker_refund_amount > 0) THEN 1 END), 0) AS refund_count", //退款订单数量 + "IFNULL(AVG(CASE WHEN status = 60 THEN UNIX_TIMESTAMP(dispatch_time) - UNIX_TIMESTAMP(create_time) END), 0) AS avg_time_diff", //派单时效 // "SUM(CASE WHEN status = 60 THEN (field1 + field2) END) AS performance", ]; diff --git a/application/admin/controller/statistics/Item.php b/application/admin/controller/statistics/Item.php index ec424fa..7396079 100644 --- a/application/admin/controller/statistics/Item.php +++ b/application/admin/controller/statistics/Item.php @@ -10,6 +10,7 @@ use app\admin\model\OrderReview; use app\common\controller\Backend; use PDOStatement; use think\Collection; +use think\Db; use think\Exception; use think\exception\DbException; use think\Loader; @@ -24,7 +25,7 @@ use function Symfony\Component\Clock\now; */ class Item extends Backend { - + protected $itemsformattedTree = null; protected $noNeedRight = ['list','chartData']; @@ -33,6 +34,43 @@ class Item extends Backend public function _initialize() { parent::_initialize(); + + $sources = Db::name('source') + ->where('status', 1) + ->field(['id', 'title', 'key_word', 'pid']) + ->order('pid', 'asc') + ->order('sort', 'desc') + ->select(); + $filtered = array_filter($sources, function ($item) { + return $item['pid'] == 0; + }); + + $pid_map = array_column($filtered, null, 'id'); + $res = []; + foreach ($sources as $item) { + if ($item['pid'] != 0 && isset($pid_map[$item['pid']])) { + $res [] = [ + ...$item, 'ptitle' => $pid_map[$item['pid']]['title'] + ]; + } + } + + /* $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;*/ + + $items = \app\admin\model\Item::where('level',1)->field('id,title')->order('sort','desc')->select(); + $this->view->assign("sources", $res); + $this->view->assign("items", $items); + } public function index() @@ -48,6 +86,8 @@ class Item extends Backend public function list() { $build = new Order(); + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $start = now()->modify('-7 days')->format('Y-m-d'); $end_at = now()->format('Y-m-d 23:29:59'); @@ -69,6 +109,21 @@ class Item extends Backend $build->where('area_id', 'like', $area_id . '%'); } + //来源 + if(!empty(request()->get('source',null))){ + $build->where('source',request()->get('source')); + } + //城市 + /* if(!empty(request()->post('area_id',null))){ + $build->where('area_id','LIKE',request()->post('source').'%'); + }*/ + + if(!empty(request()->get('item_id',null))){ + $item_id =request()->get('item_id'); + $item_ids = $this->getItemsById($item_id); + $item_ids [] = $item_id; + $build->whereIn('item_id', $item_ids); + } $build->whereBetween('create_time', [$start, $end_at]) ->field([ @@ -86,7 +141,7 @@ class Item extends Backend ])->group('item_title') ->order('count_num', 'desc'); // dd($total); - $res = $build->paginate(); + $res = $build->paginate($limit); $total = $res->total(); $ress = $res->items(); $data = []; @@ -103,7 +158,7 @@ class Item extends Backend $re['total_avg'] = $this->mydiv($re['total'],$re['count_num'],2,false); $re['performance_avg'] = $this->mydiv($re['performance'],$re['finish_num'],2,false); $re['avg_time_diff'] = $this->mydiv($re['avg_time_diff'],3600,2,false); - $re['cost_total'] = $cost_total; + $re['cost_total'] = number_format($cost_total,2,'.',''); // $re['id'] = $re['item_id']; $data [] = $re; } @@ -139,6 +194,8 @@ class Item extends Backend $filter ['daterange'] = request()->post('daterange'); + + if (!empty($filter['daterange'])) { $arr = explode(' - ', $filter['daterange']); if (trim($arr[0])) { @@ -149,9 +206,28 @@ class Item extends Backend } } - $res = $build - ->whereBetween('create_time', [$start, $end_at]) - ->field([ + $build = $build + ->whereBetween('create_time', [$start, $end_at]); + + //来源 + if(!empty(request()->post('source',null))){ + $build->where('source',request()->post('source')); + } + + //城市 + if(!empty(request()->post('area_id',null))){ + $build->where('area_id','LIKE',request()->post('source').'%'); + } + + if(!empty(request()->post('item_id',null))){ + $item_id =request()->post('item_id'); + $item_ids = $this->getItemsById($item_id); + $item_ids [] = $item_id; + $build->whereIn('item_id', $item_ids); + } + + + $res = $build->field([ 'item_title name', // 类型 'sum(total) total', // 营业额 'count(id) count', // 单量 diff --git a/application/admin/model/Order.php b/application/admin/model/Order.php index 1036f48..136fcef 100644 --- a/application/admin/model/Order.php +++ b/application/admin/model/Order.php @@ -167,7 +167,8 @@ class Order extends Model self::STATUS_CHECKING, self::STATUS_CHECKONCE, self::STATUS_AUDITING, - self::STATUS_FINISHED + self::STATUS_FINISHED, + self::STATUS_AFTERSALE ], ]; return $tabStatus[$tab] ?? []; diff --git a/application/admin/view/aftersales/aftersale/edit.html b/application/admin/view/aftersales/aftersale/edit.html index 0d508d2..939033c 100644 --- a/application/admin/view/aftersales/aftersale/edit.html +++ b/application/admin/view/aftersales/aftersale/edit.html @@ -3,14 +3,14 @@