From 15592ed2bd7db44a41f040f0fdf50f713a9b645b Mon Sep 17 00:00:00 2001 From: todaywindy Date: Thu, 31 Jul 2025 10:18:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/orders/Auditorder.php | 156 ++++++++++++------ .../admin/view/orders/auditorder/index.html | 3 + application/common/controller/Backend.php | 15 +- public/assets/js/backend/orders/auditorder.js | 26 +++ 4 files changed, 147 insertions(+), 53 deletions(-) diff --git a/application/admin/controller/orders/Auditorder.php b/application/admin/controller/orders/Auditorder.php index e064707..16ed8eb 100644 --- a/application/admin/controller/orders/Auditorder.php +++ b/application/admin/controller/orders/Auditorder.php @@ -48,55 +48,69 @@ class Auditorder extends Backend /** * 查看 */ - public function index() + public function index($getArray = false, $page = 0, $input_limit = 0) { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); - if ($this->request->isAjax()) { - //如果发送的来源是Selectpage,则转发到Selectpage - if ($this->request->request('keyField')) { - return $this->selectpage(); - } - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - $list = $this->model - ->scope('tab',Order::TAB_AUDIT) - ->alias('order') - ->with([ - 'user' => function ($q) { - $q->field('id,nickname'); - },'workerman','auditadmin' => function ($q) { - $q->field('id,nickname'); - }, 'source' => [ - 'parent' => function ($q) { - $q->field('id,title'); - } - ]]) - ->where($where) - ->order($sort, $order) - ->paginate($limit); - - foreach ($list as $item) { - 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 = array("total" => $list->total(), "rows" => $list->items()); - - return json($result); + if (false === $this->request->isAjax() && $getArray == false) { + $res = $this->getSource(); + $this->view->assign("sources", $res); + return $this->view->fetch(); } - $res = $this->getSource(); - $this->view->assign("sources", $res); - return $this->view->fetch(); - } + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + + $build = $this->model + ->scope('tab', Order::TAB_AUDIT) + ->alias('order') + ->with([ + 'user' => function ($q) { + $q->field('id,nickname'); + }, 'workerman', 'auditadmin' => function ($q) { + $q->field('id,nickname'); + }, 'source' => [ + 'parent' => function ($q) { + $q->field('id,title'); + } + ]]) + ->where($where) + ->order($sort, $order); + + + if ($getArray) { + $list = $build->paginate([ + 'list_rows' => $input_limit, + 'page' => $page + ]); + } else { + $list = $build->paginate($limit); + } + + foreach ($list as $item) { + 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 = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + + + } + /** * 编辑 @@ -108,12 +122,12 @@ class Auditorder extends Backend */ public function edit($ids = null) { - $row = $this->model->get($ids,['dispatch']); + $row = $this->model->get($ids, ['dispatch']); if (!$row) { $this->error(__('No Results were found')); } - if($row ->status != Order::STATUS_AUDITING){ + if ($row->status != Order::STATUS_AUDITING) { $this->error('订单状态不可审核'); } @@ -122,10 +136,10 @@ class Auditorder extends Backend $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { - $order = Order::where('id',$ids)->find(); + $order = Order::where('id', $ids)->find(); $this->view->assign('row', $row); $worker = Worker::withTrashed()->where('id', $order->worker_id)->find(); - $this->view->assign('worker',$worker); + $this->view->assign('worker', $worker); $this->view->assign('cdnurl', config('upload.cdnurl')); return $this->view->fetch(); } @@ -148,9 +162,9 @@ class Auditorder extends Backend } $txt = '审核通过'; - if($audit_status){ + if ($audit_status) { $params['status'] = Order::STATUS_FINISHED; - }else{ + } else { $params['status'] = Order::STATUS_CHECKONCE; $txt = '审核未通过'; } @@ -163,16 +177,16 @@ class Auditorder extends Backend $hookParams['order'] = $row; $hookParams['role'] = 1; $hookParams['auth'] = $this->auth; - $hookParams['remark'] = $txt.',审核备注:'.$params['audit_remark']; - Hook::listen('order_change',$hookParams); + $hookParams['remark'] = $txt . ',审核备注:' . $params['audit_remark']; + Hook::listen('order_change', $hookParams); - if($params['status'] == Order::STATUS_CHECKONCE){ + if ($params['status'] == Order::STATUS_CHECKONCE) { //未通过审核,通知派单员,重新配置 Message::create([ - 'to_id' => $row->dispatch_admin_id, - 'type' => 1, - 'title' => '订单结算审核未通过', - 'content' => '【订单结算未通过】订单编号:'.$row->order_no.',审核备注:'.$params['audit_remark'].',审核人:'.$this->auth->nickname + 'to_id' => $row->dispatch_admin_id, + 'type' => 1, + 'title' => '订单结算审核未通过', + 'content' => '【订单结算未通过】订单编号:' . $row->order_no . ',审核备注:' . $params['audit_remark'] . ',审核人:' . $this->auth->nickname ]); } @@ -188,4 +202,42 @@ class Auditorder extends Backend $this->success(); } + public function export() + { + $columns = json_decode($this->request->get('columns', ''), true); + if (!$columns) { + $sample = $this->index(true, 1, 1)->getData(); + + if (!isset($sample['rows'][0])) { + return json(['code' => 0, 'msg' => '无数据可导出']); + } + $columns = []; + foreach ($sample['rows'][0] as $key => $value) { + $columns[] = ['field' => $key, 'title' => $key]; + } + } + + $generator = function () use ($columns) { + $limit = 1000; + $page = 1; + $order = new \app\admin\model\Order(); + do { + $result = $this->index(true, $page, $limit); + $rows = $result->getData()['rows'] ?? []; + if (!$rows) break; + + foreach ($rows as $item) { + $item->status = $order->getStatusList()[$item->status] ?? ''; + $item->amount_images = $this->dealImages($item->amount_images); + $item->workerman->images = $this->dealImages($item->workerman->images); + yield $item->toArray(); + } + + $page++; + } while (count($rows) === $limit); + }; + + $this->streamCsv($columns, $generator(), '订单导出_' . date('Ymd_His') . '.csv'); + } + } diff --git a/application/admin/view/orders/auditorder/index.html b/application/admin/view/orders/auditorder/index.html index 0d233af..f6e662b 100644 --- a/application/admin/view/orders/auditorder/index.html +++ b/application/admin/view/orders/auditorder/index.html @@ -20,6 +20,9 @@