843 lines
31 KiB
PHP
Executable File
843 lines
31 KiB
PHP
Executable File
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\common\model\CardLevel;
|
||
use app\common\model\Delivery;
|
||
use app\common\model\Order as OrderModel;
|
||
use app\common\model\OrderList;
|
||
use app\common\model\OrderListRecovery;
|
||
use app\common\model\OrderListSend;
|
||
use app\common\model\Shang;
|
||
use app\common\model\User;
|
||
use think\facade\View;
|
||
use think\Request;
|
||
use think\facade\Db;
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
use PhpOffice\PhpSpreadsheet\Writer\Xls;
|
||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||
use PhpOffice\PhpSpreadsheet\Style\Font;
|
||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||
|
||
|
||
class Order extends Base
|
||
{
|
||
|
||
/**
|
||
* 卡单列表
|
||
*/
|
||
public function kadan_order()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$order_num = trim(input('get.order_num'));
|
||
$addtime = trim(input('get.addtime'));
|
||
|
||
$whe = array();
|
||
$whe[] = ['status', '=', 0];
|
||
$whe[] = ['kd_is', '=', 1];
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($order_num) {
|
||
$whe[] = ['order_num', '=', $order_num];
|
||
}
|
||
if ($addtime) {
|
||
$time = explode(' - ', $addtime);
|
||
$start_time = strtotime($time[0]);
|
||
$end_time = strtotime($time[1]) - 1;
|
||
if ($start_time > $end_time) {
|
||
$this->err('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
||
}
|
||
$field = '*';
|
||
$order = 'id desc';
|
||
$data = OrderModel::getList($whe, $field, $order, $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
return View::fetch('Order/kadan_order');
|
||
}
|
||
|
||
/**
|
||
* 购买列表
|
||
*/
|
||
public function buy_order()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$order_num = trim(input('get.order_num'));
|
||
$addtime = trim(input('get.addtime'));
|
||
|
||
$whe = array();
|
||
$whe[] = ['status', '=', 1];
|
||
$whe[] = ['kd_is', '=', 0];
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($order_num) {
|
||
$whe[] = ['order_num', '=', $order_num];
|
||
}
|
||
if ($addtime) {
|
||
$time = explode(' - ', $addtime);
|
||
$start_time = strtotime($time[0]);
|
||
$end_time = strtotime($time[1]) - 1;
|
||
if ($start_time > $end_time) {
|
||
$this->err('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
||
$str_addtime = $start_time . '_' . $end_time;
|
||
} else {
|
||
$str_addtime = 0;
|
||
}
|
||
$field = '*';
|
||
$order = 'id desc';
|
||
$data = OrderModel::getList($whe, $field, $order, $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
View::assign('user_id', $user_id ? $user_id : 0);
|
||
View::assign('mobile', $mobile ? $mobile : 0);
|
||
View::assign('order_num', $order_num ? $order_num : 0);
|
||
View::assign('str_addtime', $str_addtime ? $str_addtime : 0);
|
||
return View::fetch('Order/buy_order');
|
||
}
|
||
|
||
/**
|
||
* 购买奖品详情
|
||
*/
|
||
public function buy_order_detail()
|
||
{
|
||
$id = request()->param('id/d', 0);
|
||
$info = OrderModel::field('id')->where(['id' => $id])->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
|
||
#数据
|
||
$data = OrderList::field('goodslist_title,goodslist_imgurl,goodslist_price,goodslist_money,shang_id,count(`id`) as num,order_type')
|
||
// ->append(['shang_title'])
|
||
->where('order_id', '=', $id)
|
||
->group('prize_code')
|
||
->order('id desc')
|
||
->select()->toArray();
|
||
foreach ($data as &$value) {
|
||
|
||
if ($value['order_type'] == 4) {
|
||
$shang_title = CardLevel::field('title')->where('id', $value['shang_id'])->value('title');
|
||
} else {
|
||
$shang_title = Shang::field('title')->where(['id' => $value['shang_id']])->value('title');
|
||
}
|
||
if (!$shang_title) {
|
||
$shang_title = '无';
|
||
}
|
||
$value['shang_title'] = $shang_title;
|
||
}
|
||
// dd($data);
|
||
View::assign('list', $data);
|
||
View::assign('count', count($data));
|
||
return View::fetch('Order/buy_order_detail');
|
||
}
|
||
|
||
/**
|
||
* 兑换列表
|
||
*/
|
||
public function recovery_order()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
|
||
$whe = array();
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($addtime) {
|
||
$time = explode(' - ', $addtime);
|
||
$start_time = strtotime($time[0]);
|
||
$end_time = strtotime($time[1]) - 1;
|
||
if ($start_time > $end_time) {
|
||
$this->err('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
||
$str_addtime = $start_time . '_' . $end_time;
|
||
} else {
|
||
$str_addtime = 0;
|
||
}
|
||
$field = '*';
|
||
$order = 'id desc';
|
||
$data = OrderListRecovery::getList($whe, $field, $order, $this->page);
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid')->where(['id' => $value['user_id']])->find();
|
||
if (empty($user_info)) {
|
||
$user_info['nickname'] = '';
|
||
$user_info['headimg'] = '';
|
||
$user_info['mobile'] = '';
|
||
$user_info['uid'] = '';
|
||
}
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
View::assign('user_id', $user_id ? $user_id : 0);
|
||
View::assign('mobile', $mobile ? $mobile : 0);
|
||
View::assign('str_addtime', $str_addtime ? $str_addtime : 0);
|
||
return View::fetch('Order/recovery_order');
|
||
}
|
||
|
||
/**
|
||
* 兑换奖品详情
|
||
*/
|
||
public function recovery_order_detail()
|
||
{
|
||
$id = request()->param('id/d', 0);
|
||
$info = OrderListRecovery::field('recovery_num,id')->where(['id' => $id])->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
#数据
|
||
$data = OrderList::field('goodslist_title,goodslist_imgurl,goodslist_price,goodslist_money,shang_id,count(`id`) as num')
|
||
->append(['shang_title'])
|
||
->where('recovery_num', '=', $info['recovery_num'])
|
||
->group('prize_code')
|
||
->order('id desc')
|
||
->select()->toArray();
|
||
View::assign('list', $data);
|
||
View::assign('count', count($data));
|
||
return View::fetch('Order/recovery_order_detail');
|
||
}
|
||
|
||
|
||
/**
|
||
* 发货订单
|
||
*/
|
||
public function send_order()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$send_num = trim(input('get.send_num'));
|
||
$status = trim(input('get.status'));
|
||
$addtime = trim(input('get.addtime'));
|
||
|
||
$whe = array();
|
||
$whe1 = array();
|
||
if ($status) {
|
||
$whe[] = ['status', '=', $status];
|
||
} else {
|
||
$whe[] = ['status', '>', 0];
|
||
}
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
$whe1[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::field('id')->where('mobile', '=', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
$whe1[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($send_num) {
|
||
$whe[] = ['send_num', '=', $send_num];
|
||
$whe1[] = ['send_num', '=', $send_num];
|
||
}
|
||
if ($addtime) {
|
||
$time = explode(' - ', $addtime);
|
||
$start_time = strtotime($time[0]);
|
||
$end_time = strtotime($time[1]) - 1;
|
||
if ($start_time > $end_time) {
|
||
$this->err('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
||
$whe1[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
||
$str_addtime = $start_time . '_' . $end_time;
|
||
} else {
|
||
$str_addtime = 0;
|
||
}
|
||
$field = '*';
|
||
$order = 'id desc';
|
||
$all_goodslist_money = 0;
|
||
|
||
// 获取测试用户ID列表
|
||
$userList = User::where('istest', 1)->column('id');
|
||
// 订单筛选条件
|
||
|
||
$data = OrderListSend::getList($whe, $field, $order, $this->page);
|
||
$all_goodslist_money_sum = OrderList::where('status', '=', 2)->where($whe)->sum('goodslist_money');
|
||
$whe[] = ['user_id', 'not in', $userList];
|
||
$all_goodslist_money_sum1 = OrderList::where('status', '=', 2)->where($whe)->sum('goodslist_money');
|
||
foreach ($data['list'] as &$value) {
|
||
$user_info = User::field('nickname,headimg,mobile,uid,istest')->where(['id' => $value['user_id']])->find();
|
||
if ($user_info) {
|
||
$value['nickname'] = $user_info['nickname'];
|
||
$value['headimg'] = $user_info['headimg'];
|
||
$value['mobile'] = $user_info['mobile'];
|
||
$value['istest'] = $user_info['istest'];
|
||
$value['uid'] = $user_info['uid'] ?: $value['user_id'];
|
||
} else {
|
||
$value['nickname'] = '';
|
||
$value['headimg'] = '';
|
||
$value['mobile'] = '';
|
||
$value['istest'] = '';
|
||
$value['uid'] = '';
|
||
}
|
||
$goodslist_money = OrderList::where('send_num', '=', $value['send_num'])->sum('goodslist_money');
|
||
$value['goodslist_money'] = $goodslist_money;
|
||
$all_goodslist_money += $goodslist_money;
|
||
}
|
||
View::assign('list', $data['list']);
|
||
View::assign('count', $data['count']);
|
||
View::assign('page', $data['page']);
|
||
View::assign('user_id', $user_id ? $user_id : 0);
|
||
View::assign('mobile', $mobile ? $mobile : 0);
|
||
View::assign('send_num', $send_num ? $send_num : 0);
|
||
View::assign('all_goodslist_money_sum1', $all_goodslist_money_sum1 ? $all_goodslist_money_sum1 : 0);
|
||
View::assign('all_goodslist_money_sum', $all_goodslist_money_sum ? $all_goodslist_money_sum : 0);
|
||
View::assign('all_goodslist_money', $all_goodslist_money ? $all_goodslist_money : 0);
|
||
View::assign('status', $status ? $status : 0);
|
||
View::assign('str_addtime', $str_addtime ? $str_addtime : 0);
|
||
return View::fetch('Order/send_order');
|
||
}
|
||
|
||
/**
|
||
* 订单详情
|
||
*/
|
||
public function send_order_detail()
|
||
{
|
||
$id = request()->param("id", '');
|
||
$info = OrderListSend::where('id', '=', $id)->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
if ($info['status'] != 1 && $info['status'] != 2 && $info['status'] != 3) {
|
||
return $this->renderError('请求参数错误1');
|
||
}
|
||
#数据
|
||
$data = OrderList::field('id,goodslist_title,goodslist_imgurl,goodslist_price,goodslist_money,shang_id,fh_status,fh_remarks,1 as num')
|
||
->append(['shang_title'])
|
||
->where('send_num', '=', $info['send_num'])
|
||
// ->group('prize_code')
|
||
->order('id desc')
|
||
->select()->toArray();
|
||
|
||
foreach ($data as $k => &$v) {
|
||
$v['goodslist_imgurl'] = imageUrl($v['goodslist_imgurl']);
|
||
}
|
||
|
||
View::assign('info', $info);
|
||
View::assign('list', $data);
|
||
View::assign('count', count($data));
|
||
return View::fetch("Order/send_order_detail");
|
||
}
|
||
|
||
|
||
/**
|
||
* 订单详情
|
||
*/
|
||
public function send_order_detail_fh()
|
||
{
|
||
$id = request()->param("id", '');
|
||
$id = request()->param("id", '');
|
||
$info = OrderListSend::where('id', '=', $id)->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
if ($info['status'] != 1 && $info['status'] != 2 && $info['status'] != 3) {
|
||
return $this->renderError('请求参数错误1');
|
||
}
|
||
#数据
|
||
$data = OrderList::field('goodslist_title,goodslist_imgurl,goodslist_price,goodslist_money,shang_id,fh_status,fh_remarks,1 as num')
|
||
->append(['shang_title'])
|
||
->where('send_num', '=', $info['send_num'])
|
||
// ->group('prize_code')
|
||
// ->order('id desc')
|
||
->order('goodslist_money desc')
|
||
->select()->toArray();
|
||
|
||
foreach ($data as $k => &$v) {
|
||
$v['goodslist_imgurl'] = imageUrl($v['goodslist_imgurl']);
|
||
}
|
||
|
||
View::assign('info', $info);
|
||
View::assign('list', $data);
|
||
View::assign('count', count($data));
|
||
return View::fetch("Order/send_order_detail");
|
||
}
|
||
|
||
|
||
/**
|
||
* 发货
|
||
*/
|
||
public function send_order_deliver(Request $request)
|
||
{
|
||
if (!$request->isPost()) {
|
||
$dandu = $request->param("dandu/d", 0);
|
||
$id = $request->param("id", '');
|
||
$info = OrderListSend::where('id', '=', $id)->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
$delivery = Delivery::select();
|
||
View::assign("id", $id);
|
||
View::assign("delivery", $delivery);
|
||
View::assign("dandu", $dandu);
|
||
return View::fetch('Order/send_order_deliver');
|
||
} else {
|
||
$id = $request->param("id", '');
|
||
$dandu = $request->param("dandu/d", 0);
|
||
$courier_name = $request->param("courier_name", '');
|
||
$courier_number = $request->param("courier_number", '');
|
||
$info = OrderListSend::where('id', '=', $id)->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
if ($info['status'] == 2) {
|
||
return $this->renderError("请勿重复操作");
|
||
}
|
||
if ($info['status'] !== 1) {
|
||
return $this->renderError("订单状态异常");
|
||
}
|
||
if (empty($courier_name)) {
|
||
return $this->renderError("请选择物流公司");
|
||
}
|
||
if (empty($courier_number)) {
|
||
return $this->renderError("请输入物流单号");
|
||
}
|
||
$delivery_info = Delivery::where(['id' => $courier_name])->find();
|
||
if (!$delivery_info) {
|
||
return $this->renderError("物流公司选择错误");
|
||
}
|
||
$res = OrderListSend::where(array("id" => $id))->update([
|
||
'status' => 2,
|
||
'courier_name' => $delivery_info['name'],
|
||
'courier_code' => $delivery_info['code'],
|
||
'courier_number' => $courier_number,
|
||
'send_time' => time(),
|
||
]);
|
||
#数据
|
||
if ($dandu == 0) {
|
||
OrderList::where('send_num', '=', $info['send_num'])->update(['fh_status' => 1]);
|
||
}
|
||
if ($res) {
|
||
return $this->renderSuccess("发货成功,请等待客户签收");
|
||
} else {
|
||
return $this->renderError("发货失败");
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public function send_order_dandufahuo(Request $request)
|
||
{
|
||
if (!$request->isPost()) {
|
||
|
||
return $this->renderError("发货失败");
|
||
} else {
|
||
$id = $request->param("id", '');
|
||
$remarks = $request->param("remarks", '');
|
||
$fh_status = $request->param("status/d", 1);
|
||
$res = OrderList::where('id', '=', $id)->update([
|
||
'fh_status' => $fh_status,
|
||
'fh_remarks' => $remarks,
|
||
]);
|
||
if ($res) {
|
||
return $this->renderSuccess("发货成功,请等待客户签收");
|
||
} else {
|
||
return $this->renderError("发货失败");
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发货订单取消
|
||
*/
|
||
public function cancel_order()
|
||
{
|
||
$id = request()->param('id/d', 0);
|
||
$info = OrderListSend::where('id', '=', $id)->find();
|
||
if (!$info) {
|
||
return $this->renderError('请求参数错误');
|
||
}
|
||
if ($info['status'] == 4) {
|
||
return $this->renderError('请勿重复操作');
|
||
}
|
||
if ($info['status'] == 1) {
|
||
return $this->renderError('该订单未发货');
|
||
}
|
||
if ($info['status'] != 2) {
|
||
return $this->renderError('请求参数错误1');
|
||
}
|
||
if ($info['freight'] > 0) {
|
||
$wxServer = new \app\common\server\WechatRefund($this->app);
|
||
$refund_res = $wxServer->OrderRefund($info);
|
||
Db::name('wxpay_log')->insert([
|
||
'order_no' => 'QX_' . $info['send_num'],
|
||
'content' => json_encode($refund_res['msg']),
|
||
'type' => 2,
|
||
]);
|
||
// if ($refund_res['status'] == 0) {
|
||
// return $this->renderError($refund_res['msg']);
|
||
// }
|
||
}
|
||
Db::startTrans();
|
||
$res = [];
|
||
#改变发货订单状态
|
||
$res[] = OrderListSend::field('status,cancel_time,admin_id')
|
||
->where(['id' => $info['id']])->update([
|
||
'status' => 4,
|
||
'cancel_time' => time(),
|
||
'admin_id' => $this->admin_id,
|
||
]);
|
||
#改变赏品信息
|
||
$res[] = OrderList::field('send_num,status,choice_time,fh_status')
|
||
->where('status', '=', 2)
|
||
->where('send_num', '=', $info['send_num'])
|
||
->update([
|
||
'send_num' => NULL,
|
||
'status' => 0,
|
||
'choice_time' => 0,
|
||
'fh_status' => 0,
|
||
]);
|
||
if (resCheck($res)) {
|
||
Db::commit();
|
||
return $this->renderSuccess('取消成功');
|
||
} else {
|
||
Db::rollback();
|
||
return $this->renderError('取消失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 购买订单导出
|
||
*/
|
||
public function buy_order_daochu()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$order_num = trim(input('get.order_num'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$whe = [['status', '=', 1], ['kd_is', '=', 0]];
|
||
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::where('mobile', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($order_num) {
|
||
$whe[] = ['order_num', '=', $order_num];
|
||
}
|
||
if ($addtime) {
|
||
$time = explode('_', $addtime);
|
||
if ($time[0] > $time[1]) {
|
||
return $this->renderError('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', [$time[0], $time[1]]];
|
||
}
|
||
|
||
$data = OrderModel::where($whe)->append(['user_info'])->order('id desc')->select()->toArray();
|
||
if (!$data) {
|
||
return $this->renderError('未找到数据');
|
||
}
|
||
|
||
$spreadsheet = new Spreadsheet();
|
||
$sheet = $spreadsheet->getActiveSheet();
|
||
|
||
// 设置表头
|
||
$headers = ['订单号', '用户信息', '盒子信息', '盒子类型', '订单金额', '折扣', '折扣金额', '微信支付', '余额抵扣', '吧唧币抵扣', '积分支付', '时间'];
|
||
foreach ($headers as $col => $text) {
|
||
$sheet->setCellValueByColumnAndRow($col + 1, 1, $text);
|
||
}
|
||
|
||
// 设置样式
|
||
$sheet->getStyle('A1:L1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||
$sheet->getStyle('A1:L1')->getFont()->setBold(true);
|
||
|
||
// 设置列宽
|
||
$widths = [40, 50, 50, 30, 30, 30, 30, 30, 30, 30, 30, 30];
|
||
foreach (range('A', 'L') as $i => $col) {
|
||
$sheet->getColumnDimension($col)->setWidth($widths[$i]);
|
||
}
|
||
|
||
// 填充数据
|
||
$line = 2;
|
||
foreach ($data as $value) {
|
||
try {
|
||
$sheet->setCellValue('A' . $line, $value['order_num']);
|
||
if ($value['user_info']) {
|
||
$sheet->setCellValue('B' . $line, 'ID:' . $value['user_id'] . ' UID:' . ($value['user_info']['uid'] ?: $value['user_id']) . ' 昵称:' . $value['user_info']['nickname'] . ' 手机号:' . $value['user_info']['mobile']);
|
||
} else {
|
||
$sheet->setCellValue('B' . $line, 'ID:' . $value['user_id'] . ' UID:' . $value['user_id'] . ' 昵称: 手机号:');
|
||
}
|
||
$sheet->setCellValue('C' . $line, '盒子名称:' . $value['goods_title'] . ($value['num'] ? ' 箱号:' . $value['num'] : ''));
|
||
$sheet->setCellValue('D' . $line, ['1' => '一番赏', '2' => '无限赏', '3' => '擂台赏', '4' => '抽卡机', '5' => '积分赏'][$value['order_type']] ?? '');
|
||
$sheet->setCellValue('E' . $line, $value['order_total']);
|
||
$sheet->setCellValue('F' . $line, $value['zhe']);
|
||
$sheet->setCellValue('G' . $line, $value['order_zhe_total']);
|
||
$sheet->setCellValue('H' . $line, $value['price']);
|
||
$sheet->setCellValue('I' . $line, $value['use_money']);
|
||
$sheet->setCellValue('J' . $line, $value['use_integral']);
|
||
$sheet->setCellValue('K' . $line, $value['use_score']);
|
||
$sheet->setCellValue('L' . $line, date('Y-m-d H:i:s', $value['addtime']));
|
||
} catch (\Throwable $th) {
|
||
//throw $th;
|
||
$c = $value;
|
||
}
|
||
$line++;
|
||
}
|
||
|
||
// 输出 Excel
|
||
$filename = '购买列表信息_' . date('Y-m-d_H-i-s') . '.xls';
|
||
header('Content-Type: application/vnd.ms-excel');
|
||
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
||
header('Cache-Control: max-age=0');
|
||
|
||
$writer = new Xls($spreadsheet);
|
||
$writer->save('php://output');
|
||
exit;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 兑换订单导出
|
||
*/
|
||
public function recovery_order_daochu()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$addtime = trim(input('get.addtime'));
|
||
$whe = [];
|
||
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::where('mobile', '=', $mobile)->value('id');
|
||
if ($mobile) {
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
}
|
||
if ($addtime) {
|
||
$time = explode('_', $addtime);
|
||
if (count($time) == 2) {
|
||
[$start_time, $end_time] = $time;
|
||
if ($start_time > $end_time) {
|
||
return $this->renderError('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', [$start_time, $end_time]];
|
||
}
|
||
}
|
||
|
||
$data = OrderListRecovery::where($whe)
|
||
->append(['user_info', 'status_name'])
|
||
->order('id desc')
|
||
->select()
|
||
->toArray();
|
||
|
||
if (!$data) {
|
||
return $this->renderError('未找到数据');
|
||
}
|
||
|
||
$spreadsheet = new Spreadsheet();
|
||
$sheet = $spreadsheet->getActiveSheet();
|
||
|
||
// 设置表头
|
||
$headers = ['用户信息', '兑换金额', '兑换数量', '兑换时间'];
|
||
$columns = ['A', 'B', 'C', 'D'];
|
||
|
||
foreach ($headers as $index => $header) {
|
||
$col = $columns[$index] . '1';
|
||
$sheet->setCellValue($col, $header);
|
||
$sheet->getColumnDimension($columns[$index])->setAutoSize(true);
|
||
}
|
||
|
||
$sheet->getStyle('A1:D1')->getFont()->setBold(true);
|
||
$sheet->getStyle('A1:D1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||
|
||
$line = 2;
|
||
foreach ($data as $value) {
|
||
$user_info = 'ID:' . ($value['user_id'] ?? '未知') . ' UID:' . ($value['user_info']['uid'] ?? $value['user_id']) . ' 昵称:' . ($value['user_info']['nickname'] ?? '未知') . ' 手机号:' . ($value['user_info']['mobile'] ?? '未知');
|
||
$addtime = date('Y-m-d H:i:s', $value['addtime']);
|
||
|
||
$sheet->setCellValue('A' . $line, $user_info);
|
||
$sheet->setCellValue('B' . $line, $value['money']);
|
||
$sheet->setCellValue('C' . $line, $value['count']);
|
||
$sheet->setCellValue('D' . $line, $addtime);
|
||
|
||
$line++;
|
||
}
|
||
|
||
$filename = '兑换列表信息_' . date('Y-m-d_H_i_s') . '.xls';
|
||
header('Content-Type: application/vnd.ms-excel');
|
||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||
header('Cache-Control: max-age=0');
|
||
|
||
$writer = new Xls($spreadsheet);
|
||
$writer->save('php://output');
|
||
exit;
|
||
}
|
||
|
||
|
||
/**
|
||
* 发货订单导出
|
||
*/
|
||
/**
|
||
* 发货订单导出
|
||
*/
|
||
public function send_order_daochu()
|
||
{
|
||
$user_id = trim(input('get.user_id'));
|
||
$mobile = trim(input('get.mobile'));
|
||
$send_num = trim(input('get.send_num'));
|
||
$status = trim(input('get.status'));
|
||
$addtime = trim(input('get.addtime'));
|
||
|
||
if ($status == 4) {
|
||
return $this->renderError('不可导出已取消状态');
|
||
}
|
||
|
||
$whe = [['status', 'in', [1, 2, 3]]];
|
||
if ($status) {
|
||
$whe = [['status', '=', $status]];
|
||
}
|
||
if ($user_id) {
|
||
// 将UID转换为用户ID
|
||
$user_id = $this->convertUidToUserId($user_id);
|
||
$whe[] = ['user_id', '=', $user_id];
|
||
}
|
||
if ($mobile) {
|
||
$mobile = User::where('mobile', $mobile)->value('id');
|
||
$whe[] = ['user_id', '=', $mobile];
|
||
}
|
||
if ($send_num) {
|
||
$whe[] = ['send_num', '=', $send_num];
|
||
}
|
||
if ($addtime) {
|
||
[$start_time, $end_time] = explode('_', $addtime);
|
||
if ($start_time > $end_time) {
|
||
return $this->renderError('开始时间不能大于结束时间');
|
||
}
|
||
$whe[] = ['addtime', 'BETWEEN', [$start_time, $end_time]];
|
||
}
|
||
|
||
// 获取数据
|
||
$data = OrderListSend::where($whe)
|
||
->append(['user_info', 'status_name'])
|
||
->order('id desc')
|
||
->select()
|
||
->toArray();
|
||
|
||
if (!$data) {
|
||
return $this->renderError('未找到数据');
|
||
}
|
||
|
||
// 创建 Spreadsheet
|
||
$spreadsheet = new Spreadsheet();
|
||
$sheet = $spreadsheet->getActiveSheet();
|
||
|
||
// 设置表头
|
||
$headers = ['订单号', '用户信息', '状态', '收货姓名', '收货电话', '收货地址', '奖品名称', '奖品价格', '奖品数量', '赠送编码', '奖品类型', '申请时间', '备注'];
|
||
foreach ($headers as $col => $header) {
|
||
$sheet->setCellValueByColumnAndRow($col + 1, 1, $header);
|
||
}
|
||
|
||
$sheet->getStyle("A1:M1")->getFont()->setBold(true);
|
||
$sheet->getStyle("A1:M1")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||
|
||
// 填充数据
|
||
$row = 2;
|
||
foreach ($data as $value) {
|
||
$user_info = 'ID:' . $value['user_id'] . " UID:" . ($value['user_info']['uid'] ?? $value['user_id']) . " 昵称:" . $value['user_info']['nickname'] . " 手机号:" . $value['user_info']['mobile'];
|
||
$addtime = date('Y-m-d H:i:s', $value['addtime']);
|
||
|
||
$goods = OrderList::where('send_num', $value['send_num'])
|
||
->append(['shang_title', 'card_no'])
|
||
->group('prize_code')
|
||
->order('id desc')
|
||
->select()
|
||
->toArray();
|
||
|
||
foreach ($goods as $goods_value) {
|
||
$sheet->fromArray([
|
||
$value['send_num'],
|
||
$user_info,
|
||
$value['status_name'],
|
||
$value['name'],
|
||
$value['mobile'],
|
||
$value['address'],
|
||
$goods_value['goodslist_title'],
|
||
$goods_value['goodslist_price'],
|
||
$goods_value['num'],
|
||
$goods_value['card_no'],
|
||
$goods_value['shang_title'],
|
||
$addtime,
|
||
$value['message']
|
||
], null, "A{$row}");
|
||
$row++;
|
||
}
|
||
}
|
||
|
||
// 自动调整列宽
|
||
foreach (range('A', 'M') as $columnID) {
|
||
$sheet->getColumnDimension($columnID)->setAutoSize(true);
|
||
}
|
||
|
||
// 生成 Excel 文件
|
||
$filename = '发货列表信息_' . date('Y-m-d_H_i_s') . '.xls';
|
||
header('Content-Type: application/vnd.ms-excel');
|
||
header('Content-Disposition: attachment;filename="' . $filename . '"');
|
||
header('Cache-Control: max-age=0');
|
||
|
||
$writer = new Xls($spreadsheet);
|
||
$writer->save('php://output');
|
||
exit;
|
||
}
|
||
|
||
|
||
} |