diff --git a/application/admin/command/Test.php b/application/admin/command/Test.php
index a9190af..4ad4148 100644
--- a/application/admin/command/Test.php
+++ b/application/admin/command/Test.php
@@ -2,26 +2,13 @@
namespace app\admin\command;
-use app\admin\addresmart\Address;
-use app\admin\controller\AutoDispatchLogic;
-use app\admin\controller\orders\DispatchLogic;
-use app\admin\controller\SendMailLogic;
-use app\admin\model\Order;
-use app\admin\model\OrderDispatch;
-use app\admin\model\OrderReview;
-use app\admin\model\Worker;
-use app\admin\model\WorkerItem;
use app\admin\controller\AmapTrait;
-use think\Collection;
+use app\admin\controller\AutoDispatchLogic;
+use app\admin\model\Order;
use think\console\Command;
use think\console\Input;
use think\console\Output;
-use think\Db;
-use think\exception\DbException;
-use think\Hook;
-use think\Lang;
-use think\Model;
-use function Symfony\Component\Clock\now;
+use think\Exception;
class Test extends Command
{
@@ -35,8 +22,18 @@ class Test extends Command
protected function execute(Input $input, Output $output)
{
- $order = Order::where('id',221)->select()[0];
- AutoDispatchLogic::autoDispatch($order);
+// $order = Order::where('id','>=',694)->select();
+ try {
+ $order = Order::get(5126);
+ AutoDispatchLogic::autoDispatch($order,null,true);
+ }catch (Exception $e){
+ $output->writeln('' . $e->getMessage() . '');
+ $output->writeln('' . $e->getFile() . ':' . $e->getLine() . '');
+ $output->writeln($e->getTraceAsString());
+ }
+
+ dd(1);
+
}
diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php
index 70f3205..d160404 100644
--- a/application/admin/controller/Order.php
+++ b/application/admin/controller/Order.php
@@ -14,11 +14,16 @@ use app\admin\model\OrderLog;
use app\admin\model\orders\Dispatchlog;
use app\admin\model\Worker;
use app\admin\model\WorkerItem;
+use app\common\cache\SimpleFileCache;
+use app\common\cache\ThinkphpCacheAdapter;
use app\common\controller\Backend;
use app\common\Logic\OrderLogic;
use Carbon\Carbon;
use Carbon\Traits\Creator;
use fast\Tree;
+use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
+use PhpOffice\PhpSpreadsheet\Settings;
+use think\Cache;
use think\Db;
use think\Exception;
use think\exception\DbException;
@@ -28,6 +33,9 @@ use think\Hook;
use think\Loader;
use think\Model;
use function Symfony\Component\Clock\now;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+
/**
* 订单列管理
@@ -127,12 +135,11 @@ class Order extends Backend
*/
- public function index()
+ public function index($getArray = false, $page = 0, $input_limit = 0)
{
$this->request->filter(['strip_tags', 'trim']);
$group = \model('auth_group_access')->where('uid', $this->auth->id)->find()->group_id ?? 0;
$user = \model('admin')->find($this->auth->id);
-
$this->assignconfig('permissions', [
'add' => $this->auth->check('order/add'),
'edit' => $this->auth->check('order/edit'),
@@ -149,8 +156,7 @@ class Order extends Backend
]);
- if (false === $this->request->isAjax()) {
-
+ if (false === $this->request->isAjax() && $getArray == false) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage,则转发到 Selectpage
@@ -177,8 +183,8 @@ 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);
+ if (isset($filter['audit_time'])) {
+ $build->where('status', \app\admin\model\Order::STATUS_FINISHED);
}
$admin_filter = $filter['user.nickname'] ?? false;
@@ -199,13 +205,13 @@ class Order extends Backend
$build->whereIn('item_id', $item_ids);
}
if (!is_null($is_timeout)) {
- $build->where('is_overtime',$is_timeout);
+ $build->where('is_overtime', $is_timeout);
}
- if ($group == 2 ) { // 录单员
- $build->where('admin_id',$user->id);
- }elseif ($group == 6){ // 派单员
+ if ($group == 2) { // 录单员
+ $build->where('admin_id', $user->id);
+ } elseif ($group == 6) { // 派单员
// 生成 SQL 语句
$ids = $user->area_ids ?? '';
if ($ids == '') {
@@ -221,7 +227,7 @@ class Order extends Backend
});
}
- $list = $build
+ $build
->with(['user' => function ($q) {
$q->field('id,nickname');
}, 'area' => function ($q) {
@@ -236,26 +242,32 @@ class Order extends Backend
}
]]
)
- ->order($sort, $order)
- ->paginate($limit);
+ ->order($sort, $order);
+ if ($getArray) {
+ $list = $build->paginate([
+ 'list_rows' => $input_limit,
+ 'page' => $page
+ ]);
+ } else {
+ $list = $build->paginate($limit);
+ }
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??'');
+ 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 ?? '');
}
- if($item->status <60){
+ if ($item->status < 60) {
$item->audit_time = null;
}
unset($item->source);
}
-
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
@@ -307,7 +319,7 @@ class Order extends Backend
$sources = array_column($sources, null, 'id');
- if (!in_array($sources[$params['source']]['pid'],[3,8])&& empty($params['customer'])){
+ if (!in_array($sources[$params['source']]['pid'], [3, 8]) && empty($params['customer'])) {
$this->error('请输入客户名称');
}
$params['source_shop'] = $sources[$params['source']]['title'] ?? null;
@@ -328,23 +340,23 @@ class Order extends Backend
$params['order_no'] = $this->generateOrderNumber();
$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');
+ $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;
- $order = \app\admin\model\Order::where('id',$this->model->id)->with(['source' => [
+ $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)){
+ 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??'');
+ ($order->getRelation('source')->title ?? '');
+ } else {
+ $order->source_total_name = ($order->getRelation('source')->title ?? '');
}
unset($order->source);
//日志
@@ -426,11 +438,11 @@ 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['receive_type'] = $params['receive_type'] ?: 1;
- if($order->receive_type != $params['receive_type']){
+ if ($order->receive_type != $params['receive_type']) {
//修改派单表
- OrderDispatch::where('order_id',$order->id)->whereBetween('status',[0,30])->update(['is_receipt' => $params['receive_type']== 1? 1:0]);
+ OrderDispatch::where('order_id', $order->id)->whereBetween('status', [0, 30])->update(['is_receipt' => $params['receive_type'] == 1 ? 1 : 0]);
}
// 更新订单信息
@@ -571,11 +583,11 @@ class Order extends Backend
$dispatch_admin = AuthGroupAccess::where('group_id', 6)
->column('uid');
- $res = array_values(array_intersect($res,$dispatch_admin));
+ $res = array_values(array_intersect($res, $dispatch_admin));
$message = $params['detail'] ?? '';
$abnormals = model('abnormal')->where('type', 3)
- ->where('id',$params['abnormal_id'])->find();
+ ->where('id', $params['abnormal_id'])->find();
$insert = [];
foreach ($res as $re) {
@@ -583,7 +595,7 @@ class Order extends Backend
'to_id' => $re,
'type' => 1,
'title' => '订单内容变更',
- 'content' => '【订单内容变更】您有一条订单'.$order->order_no.'信息被修改,异常类型【'.$abnormals->title.'】,备注:【' . $message . '】,请注意查收。'
+ 'content' => '【订单内容变更】您有一条订单' . $order->order_no . '信息被修改,异常类型【' . $abnormals->title . '】,备注:【' . $message . '】,请注意查收。'
];
}
$build = new Message();
@@ -630,7 +642,7 @@ 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();
+ $orderDispatch = OrderDispatch::where('order_id', $order->id)->whereBetween('status', '>=', 0)->find();
if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3) {
@@ -732,7 +744,7 @@ class Order extends Backend
$result = $order->allowField(true)->save($params);
- $dispatch = OrderDispatch::where('order_id', $order->id)->where('status','>=',0)->find();
+ $dispatch = OrderDispatch::where('order_id', $order->id)->where('status', '>=', 0)->find();
if (!empty($dispatch)) {
$orderLogic = new OrderLogic();
$orderLogic->cancelOrderDispatch($dispatch, $this->auth, '订单被取消', false);
@@ -1087,4 +1099,48 @@ class Order extends Backend
return json($result);
}
+
+ public function export()
+ {
+ // 表头结构(可从参数获取或手动定义)
+ $columns = json_decode($this->request->get('columns', ''), true);
+// dd($columns);
+ 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];
+ }
+ }
+
+ // 数据获取函数:分页获取数据(支持返回 array)
+ $fetchData = function ($page, $limit) {
+ $result = $this->index(true, $page, $limit);
+ $order = new \app\admin\model\Order();
+ foreach ($result->getData()['rows'] as $item){
+ $item->status = $order->getStatusList()[$item->status] ?? '';
+ $item->dispatch_type = $item->dispatch_type == 1 ? '手动派单' : '自动派单';
+ $item->is_overtime = $item->is_overtime ? '超时' : '未超时';
+ $item->receive_type = $item->receive_type == 1 ? '已收定金' : '已收全款';
+ $images = explode(',',$item->images ?? '');
+ $url = '';
+ if ($images){
+ foreach ($images as $img){
+ if($img == '')continue;
+ $url .= cdnurl($img) . ',';
+ }
+ }
+ $item->images = $url;
+ }
+ return $result->getData()['rows'] ?? [];
+ };
+
+ $this->exportExcelByStream($columns, $fetchData, '订单导出_' . date('Ymd_His') . '.xlsx');
+ }
+
+
}
diff --git a/application/admin/view/order/index.html b/application/admin/view/order/index.html
index 2b4db2e..1af2926 100644
--- a/application/admin/view/order/index.html
+++ b/application/admin/view/order/index.html
@@ -24,6 +24,9 @@