diff --git a/application/admin/controller/orders/Dispatch.php b/application/admin/controller/orders/Dispatch.php index 17325c7..c1a6bb6 100644 --- a/application/admin/controller/orders/Dispatch.php +++ b/application/admin/controller/orders/Dispatch.php @@ -67,16 +67,16 @@ class Dispatch extends Backend list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model - ->with(['order']) - ->where($where) - ->order($sort, $order) - ->paginate($limit); + ->with(['order']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); foreach ($list as $row) { - $row->btn_edit = (in_array($row->status,$this->model->btnActiveStatusList('btn_edit'))) ? true:false; - $row->btn_cancel = (in_array($row->status,$this->model->btnActiveStatusList('btn_cancel'))) ? true:false; - $row->btn_abnormal = (in_array($row->status,$this->model->btnActiveStatusList('btn_abnormal'))) ? true:false; - $row->btn_income = (in_array($row->status,$this->model->btnActiveStatusList('btn_income')) && in_array($row->order->status,$orderModel->incomeBtnStatus()) ) ? true:false; + $row->btn_edit = (in_array($row->status, $this->model->btnActiveStatusList('btn_edit'))) ? true : false; + $row->btn_cancel = (in_array($row->status, $this->model->btnActiveStatusList('btn_cancel'))) ? true : false; + $row->btn_abnormal = (in_array($row->status, $this->model->btnActiveStatusList('btn_abnormal'))) ? true : false; + $row->btn_income = (in_array($row->status, $this->model->btnActiveStatusList('btn_income')) && in_array($row->order->status, $orderModel->incomeBtnStatus())) ? true : false; } $result = array("total" => $list->total(), "rows" => $list->items()); @@ -95,7 +95,26 @@ class Dispatch extends Backend public function add() { if (false === $this->request->isPost()) { - $this->assign('order_id',$this->request->param('order_id')); + $id = $this->request->param('order_id'); + $order = model('order')->where('id', $id)->find(); + if (!$order) { + $this->error(__('No results were found')); + } + $code = $this->getSelectAreaCode(substr_replace($order->area_id, '00', -2)); + $workers = model('worker') + ->where('area_id','like', $code.'%') + ->where('status',1) + ->field(['id','name','tel','area_id','lng','lat']) + ->select(); + + + $area_name = model('area')->getNameByCode($order->area_id); + $order->area_name = str_replace(',','/',$area_name); + + $workers = $this->getWorkers($workers); + $this->view->assign('workers', $workers); + $this->view->assign('row', $order); + return $this->view->fetch(); } $params = $this->request->post('row/a'); @@ -116,9 +135,28 @@ class Dispatch extends Backend $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException()->validate($validate); } - $result = $this->model->allowField(true)->save($params); + $order = model('order')->where('id',$params['order_id'])->find(); + if (!$order){ + $this->error(__('No results were found')); + } + $insert = [ + 'admin_id' => $this->auth->id, + 'admin_user' => $this->auth->nickname, + 'order_id' => $params['order_id'], + 'type' => 1, + 'worker_id' => $params['worker_id'], + 'plan_time' => $params['plan_time'], + ]; + + $worker = model('worker')->where('id',$params['worker_id'])->find(); + $insert ['worker_name'] = $worker->name; + $insert ['worker_tel'] = $worker->tel; + + $result = $this->model->allowField(true)->save($insert); + $order->status = Order::STATUS_DISPATCHED; + $order->save(); Db::commit(); - } catch (ValidateException|PDOException|Exception $e) { + } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -166,7 +204,7 @@ class Dispatch extends Backend } $result = $row->allowField(true)->save($params); Db::commit(); - } catch (ValidateException|PDOException|Exception $e) { + } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -199,42 +237,50 @@ class Dispatch extends Backend if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } - $list = $this->model->where($pk, 'in', $ids)->whereIn('status',$this->model->deleteStatusList())->select(); + $list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select(); - $remark = $this->request->param('remark',''); + $remark = $this->request->param('remark', ''); $count = 0; Db::startTrans(); try { foreach ($list as $item) { //$count += $item->delete(); - $order = Order::where('id',$item->order_id)->where('status',Order::STATUS_DISPATCHED)->find(); - if(!$order){ + $order = Order::where('id', $item->order_id)->where('status', Order::STATUS_DISPATCHED)->find(); + if (!$order) { $this->error('订单状态已变更,请刷新后操作'); } //取消 - $item->update(['status'=>OrderDispatch::STATUS_CANCEL,'remark'=>$remark]); + $item->update(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]); //回退订单状态 - $order->update(['status'=>Order::STATUS_DISPATCHING]); + $order->update(['status' => Order::STATUS_DISPATCHING]); $params['order'] = $order; $params['role'] = 1; $params['auth'] = $this->auth; - $params['remark'] = '派单被取消[ID:'.$item->id.'],订单状态回退'; - if(!empty($remark)){ - $params['remark'] .= ',操作备注:'.$remark; + $params['remark'] = '派单被取消[ID:' . $item->id . '],订单状态回退'; + if (!empty($remark)) { + $params['remark'] .= ',操作备注:' . $remark; } - Hook::listen('order_change',$params); + Hook::listen('order_change', $params); } Db::commit(); - } catch (PDOException|Exception $e) { + } catch (PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } - /* if ($count) { - $this->success(); - }*/ + /* if ($count) { + $this->success(); + }*/ $this->error(__('取消成功')); } + private function getWorkers($workers) + { + foreach ($workers as $worker){ + $worker->dist = '100m'; + } + return $workers; + } + } diff --git a/application/admin/view/orders/dispatch/add.html b/application/admin/view/orders/dispatch/add.html index f7cfca4..75b37ee 100644 --- a/application/admin/view/orders/dispatch/add.html +++ b/application/admin/view/orders/dispatch/add.html @@ -1,24 +1,69 @@
diff --git a/application/admin/view/workers/worker/index.html b/application/admin/view/workers/worker/index.html index 87d4ae8..da077cb 100644 --- a/application/admin/view/workers/worker/index.html +++ b/application/admin/view/workers/worker/index.html @@ -33,12 +33,12 @@ {:__('Recycle bin')}