diff --git a/application/admin/command/Test.php b/application/admin/command/Test.php index df65a22..a9190af 100644 --- a/application/admin/command/Test.php +++ b/application/admin/command/Test.php @@ -35,9 +35,8 @@ class Test extends Command protected function execute(Input $input, Output $output) { - $key = 'ae0ab397a2febfa1ce0a2c780f3f23a3'; - $res = $this->getAddressByKeyword('重庆武隆区凤山街道锦江竹苑6幢31-4'); - dd($res); + $order = Order::where('id',221)->select()[0]; + AutoDispatchLogic::autoDispatch($order); } diff --git a/application/admin/controller/AutoDispatchLogic.php b/application/admin/controller/AutoDispatchLogic.php index 9bbf842..617cabe 100644 --- a/application/admin/controller/AutoDispatchLogic.php +++ b/application/admin/controller/AutoDispatchLogic.php @@ -22,6 +22,7 @@ class AutoDispatchLogic $worker_id = (new DispatchLogic())->getMaxScoreWorker($order); +// dd($worker_id); if (!$worker_id) { $order->dispatch_type = 1; $order->save(); diff --git a/application/admin/controller/Message.php b/application/admin/controller/Message.php index f3eb501..a96235f 100644 --- a/application/admin/controller/Message.php +++ b/application/admin/controller/Message.php @@ -148,4 +148,33 @@ class Message extends Backend } + public function markallread(){ + $list = $this->model + ->where('type',1) + ->where('to_id',$this->auth->id) + //->auth($this->auth) + //->whereRaw("FIND_IN_SET(?, read_uid) = 0 OR read_uid IS NULL OR read_uid = ''", [$this->auth->id]) + ->whereRaw("FIND_IN_SET({$this->auth->id}, read_uid) = 0 OR read_uid = '' or read_uid is null") + ->whereTime('create_time', '>=', '-3 days') + ->select(); + $update = []; + foreach ($list as &$item){ + $readUids = explode(',',$item->read_uid??''); + $item->status = 1; + if(!in_array($this->auth->id,$readUids)){ + $readUids[] = $this->auth->id; + $update[] = [ + 'id' => $item->id, + 'read_uid' => implode(',',$readUids), + 'update_time' => date('Y-m-d H:i:s') + ]; + $item->status = 0; + } + } + if($update){ + $this->batchUpdateByIdSimple('fa_message',$update); + } + $this->success("全部已读"); + } + } diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index fec957d..be2967e 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -13,6 +13,8 @@ use app\admin\model\Worker; use app\admin\model\WorkerItem; use app\common\controller\Backend; use app\common\Logic\OrderLogic; +use Carbon\Carbon; +use Carbon\Traits\Creator; use fast\Tree; use think\Db; use think\Exception; @@ -146,6 +148,7 @@ class Order extends Backend 'receive_type', 'plan_time', 'coupon_id', + 'create_time', 'total', 'online_amount', 'aftersale_id' @@ -153,18 +156,33 @@ class Order extends Backend ->where($where); $filter = (array)json_decode(input()['filter'] ?? '', true); $admin_filter = $filter['user.nickname'] ?? false; - + $is_timeout = $filter['is_timeout'] ?? null; +// dd($create_time,$filter); if ($admin_filter) { $admin_ids = Admin::where('nickname', 'like', '%' . $admin_filter . '%')->column('id'); $build->whereIn('admin_id', $admin_ids); } + if (!is_null($is_timeout)) { + if ($is_timeout == 1){ + $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) + ->where('create_time', '<=', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); + }else{ + $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) + ->where('create_time', '>', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); + } + + } if ($type == 1) { $build->where('status', '>=', 0); - } - - if ($type == 2) { + }elseif ($type == 2) { $build->where('status', '<', 0); + }elseif ($type == 3){ + $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) + ->where('create_time', '<=', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); } if ($group == 2 || $group == 6) { // 生成 SQL 语句 @@ -449,7 +467,7 @@ class Order extends Backend $insert [] = [ 'to_id' => $re, 'type' => 1, - 'title' => '订单报错通知', + 'title' => '催单通知', 'content' => '【催单通知】您有一条订单号为' . $order->order_no . '的订单被催单,请立即派单!' ]; } @@ -616,6 +634,9 @@ class Order extends Backend $op[] = ['id' => $option->id, 'title' => $option->title]; } $order = model('order')->get($ids); + if ($order){ + $this->error('订单未找到,请重试'); + } return $this->fetch('delete', ['row' => $order, 'options' => $op]); } $params = $this->request->post('row/a'); @@ -648,7 +669,7 @@ class Order extends Backend $hookparams['order'] = $order; $hookparams['role'] = 1; $hookparams['auth'] = null; - $hookparams['remark'] = $params['remark'] ?? ''; + $hookparams['remark'] = $params['remark'] ?? '取消订单'; Hook::listen('order_change', $hookparams); } Db::commit(); @@ -846,7 +867,7 @@ class Order extends Backend $index = 0; foreach ($filter as $k => $v) { - if ($k == 'user.nickname') continue; + if ($k == 'user.nickname' || $k =='is_timeout') continue; if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) { continue; } diff --git a/application/admin/controller/orders/DispatchLogic.php b/application/admin/controller/orders/DispatchLogic.php index 4f47a5c..30b00d8 100644 --- a/application/admin/controller/orders/DispatchLogic.php +++ b/application/admin/controller/orders/DispatchLogic.php @@ -29,11 +29,13 @@ FROM ( point(lng, lat), point(?, ?) ) AS distance - FROM fa_worker where deletetime is null + FROM fa_worker where deletetime is null and type = 1 and status = 1 ) AS t WHERE distance < 40000 ORDER BY distance;",[$order->lng,$order->lat]); + + $worker_ids = array_column($worker_info,'id'); @@ -47,7 +49,7 @@ ORDER BY distance;",[$order->lng,$order->lat]); $out_worker_ids = array_intersect($worker_ids, $worker_items_ids); $out_worker_ids = array_values(array_diff($out_worker_ids, $out_worker)); - +// dd($out_worker_ids); $worker_doings = (new OrderDispatch()) ->whereIn('worker_id', $out_worker_ids) ->group('worker_id') diff --git a/application/admin/controller/workers/Worker.php b/application/admin/controller/workers/Worker.php index ed455b1..619a9a4 100644 --- a/application/admin/controller/workers/Worker.php +++ b/application/admin/controller/workers/Worker.php @@ -6,6 +6,7 @@ use app\admin\model\Area; use app\admin\model\AuthGroup; use app\admin\model\Item; use app\admin\model\Order; +use app\admin\model\WorkerItem; use app\common\controller\Backend; use fast\Tree; use think\Db; @@ -160,7 +161,7 @@ class Worker extends Backend } $params['admin_id'] = $this->auth->id; - if(!empty($params['area_id'])){ + if((!empty($params['area_id'])) && isset($params['lng'])){ $area = Area::getByCode($params['area_id']); if($area){ @@ -171,7 +172,9 @@ class Worker extends Backend } } } +// dd($params); $result = $this->model->allowField(true)->save($params); +// dd($result); $item_map = model('item')->getAll(); $item_map = array_column($item_map, 'level', 'id'); if ($result) { @@ -275,6 +278,7 @@ class Worker extends Backend public function dispatchList() { $area_id = request()->get('area_id'); + $item_id = request()->get('item_id'); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $build = model('worker') @@ -297,6 +301,10 @@ class Worker extends Backend $code = $this->getSelectAreaCode(substr_replace($area_id, '00', -2)); $build->where('area_id', 'like', $code . '%'); } + if ($item_id) { + $worker_ids = WorkerItem::where('item_id',$item_id)->column('worker_id'); + $build->whereIn('id',$worker_ids); + } $list = $build ->paginate($limit); $result = array("total" => $list->total(), "rows" => $list->items()); diff --git a/application/admin/view/message/index.html b/application/admin/view/message/index.html index 3468ab4..02174ee 100644 --- a/application/admin/view/message/index.html +++ b/application/admin/view/message/index.html @@ -7,11 +7,13 @@