diff --git a/application/admin/controller/AutoDispatchLogic.php b/application/admin/controller/AutoDispatchLogic.php index 31484a6..390b37d 100644 --- a/application/admin/controller/AutoDispatchLogic.php +++ b/application/admin/controller/AutoDispatchLogic.php @@ -6,6 +6,7 @@ namespace app\admin\controller; use app\admin\controller\orders\DispatchLogic; use app\admin\model\Admin; +use app\admin\model\AuthGroupAccess; use app\admin\model\Message; use app\admin\model\OrderDispatch; use app\admin\model\Worker; @@ -26,8 +27,12 @@ class AutoDispatchLogic // dd($worker_id); if (!$worker_id) { $area_id = substr($order->area_id, 0, 4); - $res = Admin::where('area_ids', 'like', '%' . $area_id . '%') + $res_worker = Admin::where('area_ids', 'like', '%' . $area_id . '%') + ->column('id'); + $res_admin = AuthGroupAccess::whereIn('group_id', [1,11]) + ->column('uid'); + $res = array_values(array_unique(array_merge($res_worker,$res_admin))); $insert = []; foreach ($res as $re) { $insert [] = [ diff --git a/application/admin/controller/Dashboard.php b/application/admin/controller/Dashboard.php index 56e3bf2..735129f 100755 --- a/application/admin/controller/Dashboard.php +++ b/application/admin/controller/Dashboard.php @@ -28,84 +28,7 @@ class Dashboard extends Backend */ public function index() { - try { - \think\Db::execute("SET @@sql_mode='';"); - } catch (\Exception $e) { - - } - $column = []; - $starttime = Date::unixtime('day', -6); - $endtime = Date::unixtime('day', 0, 'end'); - $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime]) - ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date') - ->group('join_date') - ->select(); - for ($time = $starttime; $time <= $endtime;) { - $column[] = date("Y-m-d", $time); - $time += 86400; - } - $userlist = array_fill_keys($column, 0); - foreach ($joinlist as $k => $v) { - $userlist[$v['join_date']] = $v['nums']; - } - - $dbTableList = Db::query("SHOW TABLE STATUS"); - $addonList = get_addon_list(); - $totalworkingaddon = 0; - $totaladdon = count($addonList); - foreach ($addonList as $index => $item) { - if ($item['state']) { - $totalworkingaddon += 1; - } - } - - $today = [ - (new Carbon())->now()->startOfDay(), - (new Carbon())->now()->endOfDay(), - ]; - - $this->view->assign([ - 'totaluser' => User::count(), - 'totaladdon' => $totaladdon, - 'totaladmin' => Admin::count(), -// 'totalcategory' => \app\common\model\Category::count(), - 'todayusersignup' => User::whereTime('jointime', 'today')->count(), - 'todayuserlogin' => User::whereTime('logintime', 'today')->count(), - 'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(), - 'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(), - 'threednu' => User::whereTime('jointime', '-3 days')->count(), - 'sevendnu' => User::whereTime('jointime', '-7 days')->count(), - 'dbtablenums' => count($dbTableList), - 'dbsize' => array_sum(array_map(function ($item) { - return $item['Data_length'] + $item['Index_length']; - }, $dbTableList)), - 'totalworkingaddon' => $totalworkingaddon, - 'attachmentnums' => Attachment::count(), - 'attachmentsize' => Attachment::sum('filesize'), - 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(), - 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'), - - 'new_order_count' => model('order') - ->whereBetween('create_time',$today) - ->where('admin_id',$this->auth->id)->count(), - 'dispatch_order_count' => model('order_dispatch') - ->whereBetween('create_time',$today) - ->where('admin_id',$this->auth->id) - ->count(), - 'doing_order_count' => model('order_dispatch') - ->whereBetween('create_time',$today) - ->where('status','>=',\app\admin\model\Order::STATUS_DRAFT) - ->where('admin_id',$this->auth->id)->count(), - 'ending_order_count' => model('order_dispatch') - ->whereBetween('create_time',$today) - ->where('status','=',\app\admin\model\Order::STATUS_FINISHED) - ->where('admin_id',$this->auth->id)->count(), - - ]); - $this->assignconfig('column', array_keys($userlist)); - $this->assignconfig('userdata', array_values($userlist)); - - return $this->view->fetch(); + $this->redirect('orderplan/dashboard'); } public function task() diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 77c99be..55b692c 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -36,6 +36,7 @@ use function Symfony\Component\Clock\now; class Order extends Backend { use CustomerInfoExtractor; + /** * Order模型对象 * @var \app\admin\model\Order @@ -175,11 +176,11 @@ class Order extends Backend $build->whereIn('item_id', $item_ids); } if (!is_null($is_timeout)) { - if ($is_timeout == 1){ + 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{ + } else { $build->where('status', '>=', \app\admin\model\Order::STATUS_DISPATCHING) ->where('create_time', '>', (new Carbon())->subMinutes(20) ->format('Y-m-d H:i:s')); @@ -189,12 +190,12 @@ class Order extends Backend if ($type == 1) { $build->where('status', '>=', 0); - }elseif ($type == 2) { + } elseif ($type == 2) { $build->where('status', '<', 0); - }elseif ($type == 3){ + } 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')); + ->where('create_time', '<=', (new Carbon())->subMinutes(20) + ->format('Y-m-d H:i:s')); } if ($group == 2 || $group == 6) { // 生成 SQL 语句 @@ -216,22 +217,33 @@ class Order extends Backend $list = $build ->with(['user' => function ($q) { - $q->field('id,nickname'); - }, 'area' => function ($q) { - $q->field('id,area_code,merge_name'); - }, 'phone' => function ($q) { - $q->field('id,model'); - }, 'coupon' => function ($q) { - $q->field('id,code,description'); - }]) + $q->field('id,nickname'); + }, 'area' => function ($q) { + $q->field('id,area_code,merge_name'); + }, 'phone' => function ($q) { + $q->field('id,model'); + }, 'coupon' => function ($q) { + $q->field('id,code,description'); + }, 'source' => [ + 'parent' => function ($q) { + $q->field('id,title'); + } + ]] + ) ->order($sort, $order) ->paginate($limit); - foreach ($list as &$item) { + foreach ($list as $item) { $item->aftersale_btn = false; if ($item->aftersale_id == 0 && $this->auth->check('aftersales/aftersale/add') && $item->status == \app\admin\model\Order::STATUS_FINISHED) { //$item->status == \app\admin\model\Order::STATUS_FINISHED && $item->aftersale_btn = true; } + if (isset($item->getRelation('source')->parent->title)){ + $item->source_total_name = '【' . $item->getRelation('source')->parent->title . '】' . ($item->getRelation('source')->title??''); + }else{ + $item->source_total_name = ($item->getRelation('source')->title??''); + } + unset($item->source); } $result = ['total' => $list->total(), 'rows' => $list->items()]; @@ -283,7 +295,7 @@ class Order extends Backend $sources = array_column($sources, 'title', 'id'); $params['source_shop'] = $sources[$params['source']] ?? null; - $itemIds = explode(',', $params['item_id']?? ''); + $itemIds = explode(',', $params['item_id'] ?? ''); $params['item_id'] = end($itemIds); $params['item_title'] = $this->findElementByValue($this->itemsformattedTree, $params['item_id'] ?? null); @@ -301,11 +313,24 @@ class Order extends Backend $result = $this->model->allowField(true)->save($params); $auth = clone $this->auth; - $order = \app\admin\model\Order::get($this->model->id); + $order = \app\admin\model\Order::where('id',$this->model->id)->with(['source' => [ + 'parent' => function ($q) { + $q->field('id,title'); + } + ]] + )->find(); +// dd($order); + if (isset($order->getRelation('source')->parent->title)){ + $order->source_total_name = '【' . $order->getRelation('source')->parent->title . '】' . + ($order->getRelation('source')->title??''); + }else{ + $order->source_total_name = ($order->getRelation('source')->title??''); + } + unset($order->source); //日志 $hookparams['order'] = $order; $hookparams['role'] = 1; - $hookparams['auth'] = $auth; + $hookparams['auth'] = $auth; $hookparams['remark'] = '录入订单'; Hook::listen('order_change', $hookparams); @@ -313,14 +338,15 @@ class Order extends Backend AutoDispatchLogic::autoDispatch($this->model, $this->auth); } Db::commit(); - } catch (ValidateException | PDOException | Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); + throw $e; $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } - $this->success(data:$order); + $this->success(data: $order); } public function edit($ids = null) @@ -436,6 +462,7 @@ class Order extends Backend } use AmapTrait; + public function smart() { // $titles = Item::where('status',1)->column('title'); @@ -443,22 +470,22 @@ class Order extends Backend // dd($res); $data = Address::smart(request()->post('str')); - if ($data['item']['id'] ?? 0){ + if ($data['item']['id'] ?? 0) { $data['item']['item'] = $this->findElementByValue($this->itemsformattedTree, $data['item']['id'] ?? null); } - preg_match('/\b(1[3-9]\d{9})\b/',$data['mobile'],$match); + preg_match('/\b(1[3-9]\d{9})\b/', $data['mobile'], $match); // dd($data); $data['mobile'] = $match[0] ?? $data['mobile']; - if ($data['addr'] && $data['addr']!=''){ + if ($data['addr'] && $data['addr'] != '') { $address = $this->getAddressByKeyword($data['addr']); - if ($address){ + if ($address) { $data['area_id'] = $address['adcode']; - $location = explode(',',$address['location']); + $location = explode(',', $address['location']); $data['lng'] = $location[0]; $data['lat'] = $location[1]; - }else{ - $data['addr'] =''; + } else { + $data['addr'] = ''; } } // dd($data); @@ -629,7 +656,7 @@ class Order extends Backend $result = \model('order_abnormal')->insert($insert); Db::commit(); - } catch (ValidateException | PDOException | Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { throw $e; Db::rollback(); $this->error($e->getMessage()); @@ -651,7 +678,7 @@ class Order extends Backend $op[] = ['id' => $option->id, 'title' => $option->title]; } $order = model('order')->get($ids); - if (!$order){ + if (!$order) { $this->error('Not Find'); } return $this->fetch('delete', ['row' => $order, 'options' => $op]); @@ -682,15 +709,15 @@ class Order extends Backend if (!empty($order->dispatch->id)) { $orderLogic = new OrderLogic(); $orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false); - //日志 - $hookparams['order'] = $order; - $hookparams['role'] = 1; - $hookparams['auth'] = $this->auth; - $hookparams['remark'] = $params['remark'] ?? '取消订单'; - Hook::listen('order_change', $hookparams); } + //日志 + $hookparams['order'] = $order; + $hookparams['role'] = 1; + $hookparams['auth'] = $this->auth; + $hookparams['remark'] = $params['remark'] ?? '取消订单'; + Hook::listen('order_change', $hookparams); Db::commit(); - } catch (ValidateException | PDOException | Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -736,7 +763,7 @@ class Order extends Backend $params['status'] = \app\admin\model\Order::STATUS_CANCEL; $result = $order->allowField(true)->save($params); Db::commit(); - } catch (ValidateException | PDOException | Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -776,7 +803,7 @@ class Order extends Backend $params['invoice_method'] = 1; $result = (new Invoice())->allowField(true)->save($params); Db::commit(); - } catch (ValidateException | PDOException | Exception $e) { + } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } @@ -866,7 +893,7 @@ class Order extends Backend $index = 0; foreach ($filter as $k => $v) { - if ($k == 'user.nickname' || $k =='is_timeout') continue; + if ($k == 'user.nickname' || $k == 'is_timeout') continue; if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) { continue; } @@ -1012,10 +1039,10 @@ class Order extends Backend if (false === $this->request->isAjax()) { //page2变更日志 - $orderLogs = OrderLog::where('order_id',$ids)->order('id','desc')->select(); + $orderLogs = OrderLog::where('order_id', $ids)->order('id', 'desc')->select(); - $this->view->assign('logs',json_encode($orderLogs)); - $this->view->assign('cdnurl',config('upload.cdnurl')); + $this->view->assign('logs', json_encode($orderLogs)); + $this->view->assign('cdnurl', config('upload.cdnurl')); return $this->fetch('orders/dispatchlog/index'); } //如果发送的来源是 Selectpage,则转发到 Selectpage @@ -1025,7 +1052,7 @@ class Order extends Backend [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->where($where) - ->where('dispatch_id',$dispatch_id) + ->where('dispatch_id', $dispatch_id) ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; diff --git a/application/admin/model/Source.php b/application/admin/model/Source.php index 8c5d186..7c0f5ac 100644 --- a/application/admin/model/Source.php +++ b/application/admin/model/Source.php @@ -43,6 +43,11 @@ class Source extends Model return $list[$value] ?? ''; } + public function parent() + { + return $this->belongsTo(Source::class,'pid','id'); + } + diff --git a/application/admin/view/order/add.html b/application/admin/view/order/add.html index 69f8c17..221e82b 100644 --- a/application/admin/view/order/add.html +++ b/application/admin/view/order/add.html @@ -9,7 +9,7 @@
@@ -175,8 +175,8 @@
- - + +
diff --git a/application/admin/view/order/copy.html b/application/admin/view/order/copy.html index c985983..5368daf 100644 --- a/application/admin/view/order/copy.html +++ b/application/admin/view/order/copy.html @@ -9,7 +9,7 @@
diff --git a/application/admin/view/order/edit.html b/application/admin/view/order/edit.html index 9864556..9fdb0aa 100644 --- a/application/admin/view/order/edit.html +++ b/application/admin/view/order/edit.html @@ -8,7 +8,7 @@
diff --git a/application/admin/view/orders/dispatch/add.html b/application/admin/view/orders/dispatch/add.html index ceaef3b..5bf8a2f 100644 --- a/application/admin/view/orders/dispatch/add.html +++ b/application/admin/view/orders/dispatch/add.html @@ -65,12 +65,6 @@ - diff --git a/application/admin/view/orders/dispatchlog/index.html b/application/admin/view/orders/dispatchlog/index.html index 21f5b81..33c7021 100644 --- a/application/admin/view/orders/dispatchlog/index.html +++ b/application/admin/view/orders/dispatchlog/index.html @@ -112,7 +112,6 @@