Commit 56c21d74 by 朱继来

Merge branch 'zjl_export_20181030'

parents 2166b088 b7e7692b
Showing with 14 additions and 374 deletions
......@@ -11,6 +11,9 @@ use App\Http\Page;
use App\Http\Controllers\PermController;
use Illuminate\Support\Facades\Redis;
use App\Http\Error;
use Excel;
use App\Model\OrderModel;
use App\Model\UserMainModel;
function CheckActive($menus, &$arr, $url)
{
......@@ -561,375 +564,9 @@ Class OrderController extends Controller
{
$info = $this->getPageInfo($request);
$map = array();
// 页面参数
if ($request->isMethod('get')) {
$map['order_type'] = $request->input('order_type', '');
$map['order_contain'] = $request->input('order_contain', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['order_status'] = $request->input('order_status', '');
$map['shipping_name'] = $request->input('shipping_name', '');
$map['order_send'] = $request->input('order_send', '');
$map['test_order'] = $request->input('test_order', '');
$map['order_pay_type'] = $request->input('order_pay_type', '');
$map['order_type_a'] = $request->input('order_type_a', '');
$map['order_source_pf'] = $request->input('order_source_pf', '');
$map['order_source_adtag'] = $request->input('order_source_adtag', '');
$map['order_source_ptag'] = $request->input('order_source_ptag', '');
$map['erp_order_id'] = $request->input('erp_order_id', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['order_invoice_status'] = $request->input('order_invoice_status', '');
$map['order_goods_type'] = $request->input('order_goods_type', '');
}
// 若没有'查看线下订单'权限,则仅查看线上订单
if (!in_array('check_offline_order', $info['userPerms'])) {
$map['online_order'] = 1;
}
/* 临时添加 所有人只能查看线上订单 */
$map['online_order'] = 1;
if ($map['order_goods_type'] == 1) {
$sale_name = '推送业务员';
} else {
$sale_name = '客服';
}
// 格式
$xlsCell = array(
array('order_id', '订单ID'),
array('order_sn', '订单编号'),
array('user_account', '会员账号'),
array('consignee', '收货人'),
array('create_time_date', '下单日期'),
array('create_time_sec', '下单时间'),
array('com_name', '公司名称'),
array('goods_name', '商品型号'),
array('brand_name', '制造商'),
array('goods_number', '数量'),
array('goods_price', '单价'),
array('single_pre_price', '均摊后单价'),
array('goods_amount', '商品小计'),
array('goods_sum', '商品总额'),
array('shipping_fee', '运费'),
array('extra_fee', '附加费'),
array('coupon', '优惠券'),
array('order_amount', '订单总额'),
array('currency', '币种'),
array('order_type', '订单类型'),
array('order_status', '订单状态'),
array('shipping_status','发货状态'),
array('inv_type', '发票类型'),
array('invoice_status', '发票状态'),
array('sale_name', $sale_name),
array('adtags', 'adtags来源'),
array('client_source', '新用户来源'),
array('cancel_reason', '取消原因'),
array('send_remark', '推送备注'),
);
// 非竞调账号,则查看真实数据
if ($info['username'] != 'vpadmin@ichunt.com') {
$map['is_fake'] = 0;
}
$list = DB::connection('order')
->table('lie_order_items as it')
->leftJoin('lie_order as o', 'it.order_id', '=', 'o.order_id')
->leftJoin('lie_pay_log as p', 'it.order_id', '=', 'p.order_id')
->leftJoin('lie_order_invoice as i', 'it.order_id', '=', 'i.order_id')
->leftJoin('lie_order_extend as oe', 'oe.order_id', '=', 'i.order_id')
->leftJoin('lie_order_address as a', function($join) {
$join->on('it.order_id', '=', 'a.order_id')->where('a.address_type', '=', 1);
})
->leftJoin('lie_order_shipping as s', function($join) {
$join->on('it.order_id', '=', 's.order_id')->where('s.shipping_type', '=', 1);
})
->leftJoin('lie_user_main as u', 'it.user_id', '=', 'u.user_id')
->leftJoin('lie_user_company as c', 'it.user_id', '=', 'c.user_id')
->where(function ($query) use ($map) {
// 查询类型
if (!empty($map['order_contain'])) {
if ($map['order_type'] == 1) { // 订单编号
$query->where('o.order_sn', '=', $map['order_contain']);
} else if ($map['order_type'] == 2) { // 型号名称
$query->whereIn('it.goods_name', '=', $map['order_contain']);
} else { // 会员账号
if (preg_match('/@/', $map['order_contain'])) {
$query->where('u.email', '=', $map['order_contain']);
} else {
$query->where('u.mobile', '=', $map['order_contain']);
}
}
}
})
->where(function ($query) use ($map) {
// 创建时间
if (!empty($map['time_start']) && !empty($map['time_end'])) {
$query->whereBetween('o.create_time', [$map['time_start'], $map['time_end']]);
} else if (!empty($map['time_start'])) {
$query->where('o.create_time', '>', $map['time_start']);
} else if (!empty($map['time_end'])) {
$query->where('o.create_time', '<', $map['time_end']);
}
})
->where(function ($query) use ($map) {
// 订单状态
if (!empty($map['order_status'])) {
$query->whereIn('o.status', explode(',', $map['order_status']));
}
})
->where(function ($query) use ($map) {
// 配送方式
if (!empty($map['shipping_name'])) {
$query->where('o.order_shipping_type', '=', $map['shipping_name']);
}
})
->where(function ($query) use ($map) {
// 订单推送业务员
if (!empty($map['order_send'])) {
$query->where('o.sale_id', '=', $map['order_send']);
}
})
->where(function ($query) use ($map) {
// 订单类型
if (!empty($map['order_pay_type'])) {
$query->where('o.order_pay_type', '=', $map['order_pay_type']);
}
})
->where(function ($query) use ($map) {
// 测试订单
if (empty($map['test_order'])) {
$query->whereNotIn('o.user_id', $this->testMobile());
}
})
->where(function ($query) use ($map) {
// 订单来源
if (!empty($map['order_source_pf'])) {
if ($map['order_source_pf'] == 1) {
$query->whereRaw("FIND_IN_SET('pf=1', o.order_source)");
} else {
$query->whereRaw("FIND_IN_SET('pf=2', o.order_source)");
}
}
})
// ->where(function ($query) use ($map) {
// // adtags来源
// if (!empty($map['order_source_adtag'])) {
// $query->whereRaw('FIND_IN_SET("adtag='.$map['order_source_adtag'].'", o.order_source)');
// }
// })
->where(function ($query) use ($map) {
// adtags来源
if (!empty($map['order_source_adtag'])) {
$query->where('o.order_source', 'like', '%adtag='.$map['order_source_adtag'].'%');
}
})
->where(function ($query) use ($map) {
// ptag来源
if (!empty($map['order_source_ptag'])) {
$query->where('o.order_source', 'like', '%ptag='.$map['order_source_ptag'].'%');
}
})
->where(function ($query) use ($map) {
// 线上订单
if (isset($map['online_order'])) {
$query->where('o.order_type', '=', $map['online_order']);
}
})
->where(function ($query) use ($map) {
// 同步状态
if (!empty($map['erp_order_id'])) {
$query->where('o.erp_order_id', '<>', '');
}
})
->where(function ($query) use ($map) {
// 竞调数据
if (isset($map['is_fake'])) {
$query->where('o.is_type', '=', $map['is_fake']);
}
})
->where(function ($query) use ($map) {
// 支付方式
if (!empty($map['order_payment_mode'])) {
switch ($map['order_payment_mode']) {
case '1': $order_payment_mode = '微信';break;
case '2': $order_payment_mode = '支付宝';break;
case '3': $order_payment_mode = '银联';break;
}
$query->where('p.pay_name', '=', $order_payment_mode);
}
})
->where(function ($query) use ($map) {
// 发票类型
if (!empty($map['order_invoice_status'])) {
$query->where('i.inv_type', '=', $map['order_invoice_status']);
}
})
->where('it.status', '<>', -1)
->where('o.order_goods_type', '=', $map['order_goods_type'])
->select('it.goods_id', 'it.goods_name', 'it.goods_number', 'it.goods_price', 'it.single_pre_price', 'it.brand_name', 'o.order_id', 'o.order_sn', 'o.order_pay_type', 'o.order_goods_type', 'o.order_source', 'o.create_time', 'o.status', 'o.order_amount', 'o.currency', 'o.sale_id', 'o.cancel_reason', 'i.tax_title', 'i.inv_type', 'i.invoice_status', 'a.consignee', 's.status as shipping_status', 'u.user_id', 'u.mobile', 'u.email', 'u.client_source', 'c.com_name', 'oe.send_remark')
->groupBy('it.rec_id')
->orderBy('o.create_time', 'DESC')
->get();
if (!empty($list)) {
// 订单数据处理
$export = $this->exportList($list);
$xlsName = '订单数据导出';
$xlslist = exportExcel($xlsName, $xlsCell, $export);
$this->$xlslist;
} else {
errorLog(Error::E_NOT_EXISTS, '数据为空无法导出');
return redirect('/prompt')->with(['message'=>"数据为空无法导出!",'url' =>$_SERVER['HTTP_REFERER'], 'jumpTime'=>3,'status'=>false]);
}
}
// 测试帐号
public function testMobile()
{
$testId = array();
$user = DB::connection('order')->table('lie_user_main')->select('user_id')->where(['is_test' => 1])->get();
foreach ($user as $k => $v) {
$testId[$k] = $v->user_id;
}
return $testId;
}
/**
* 导出到Excel
* @param [type] $order [查询出的订单数据]
* @return [type] [description]
*/
public function exportList($order)
{
// 订单类型
$order_type = array(
'1' => '全款',
'2' => '预付款',
'3' => '账期支付',
);
// 订单状态
$order_status = array(
'-1' => '已取消',
'1' => '待审核',
'2' => '待付款',
'3' => '待付尾款',
'4' => '待发货',
'7' => '部分发货',
'8' => '待收货',
'10' => '交易成功',
);
// 订单发货状态
$shipping_status = array(
'-1' => '未配送',
'1' => '配送中',
'2' => '已签',
);
// 发票类型
$inv_type = array(
'1' => '不开发票',
'2' => '普通发票',
'3' => '增值税专用发票',
'4' => '增值税普通发票',
);
// 发票状态
$invoice_status = array(
'-1' => '待确认',
'1' => '已开票',
'2' => '已发货',
'3' => '已签收',
);
$tmp = array();
for ($i = 0; $i < count($order); $i++) {
// 推送人
if ($order[$i]->sale_id) {
$sales = DB::table('user_info')->where(['userId' => $order[$i]->sale_id])->select('name')->first();
}
$orderModel = new OrderModel();
$tmp[$i]['order_id'] = $order[$i]->order_id;
// 自营商品名称换成商品型号
$tmp[$i]['goods_name'] = $order[$i]->order_goods_type == 1 ? $order[$i]->goods_name : getGoodsName($order[$i]->goods_id);
$tmp[$i]['goods_number'] = $order[$i]->goods_number;
$tmp[$i]['goods_price'] = $order[$i]->goods_price;
$tmp[$i]['single_pre_price'] = $order[$i]->single_pre_price;
$tmp[$i]['goods_amount'] = $order[$i]->goods_number*$order[$i]->goods_price;
$tmp[$i]['brand_name'] = $order[$i]->brand_name;
if ($i > 0 && $order[$i]->order_id == $order[$i-1]->order_id) {
$tmp[$i]['order_sn'] = '';
$tmp[$i]['user_account'] = '';
$tmp[$i]['consignee'] = '';
$tmp[$i]['create_time_date'] = '';
$tmp[$i]['create_time_sec'] = '';
$tmp[$i]['com_name'] = '';
$tmp[$i]['goods_sum'] = '';
$tmp[$i]['shipping_fee'] = '';
$tmp[$i]['extra_fee'] = '';
$tmp[$i]['coupon'] = '';
$tmp[$i]['order_amount'] = '';
$tmp[$i]['currency'] = '';
$tmp[$i]['order_type'] = '';
$tmp[$i]['order_status'] = '';
$tmp[$i]['shipping_status'] = ''; // 发货状态
$tmp[$i]['inv_type'] = ''; // 发票类型
$tmp[$i]['invoice_status'] = ''; // 发票状态
$tmp[$i]['sale_name'] = ''; // 推送业务员
$tmp[$i]['adtags'] = '';
$tmp[$i]['client_source'] = '';
$tmp[$i]['cancel_reason'] = '';
$tmp[$i]['send_remark'] = '';
} else {
$tmp[$i]['order_sn'] = "\t".$order[$i]->order_sn."\t";
$tmp[$i]['user_account'] = $order[$i]->mobile ? $order[$i]->mobile : $order[$i]->email;
$tmp[$i]['consignee'] = isset($order[$i]->consignee) ? $order[$i]->consignee : '';
$tmp[$i]['create_time_date'] = date('Y-m-d', $order[$i]->create_time);
$tmp[$i]['create_time_sec'] = date('H:i:s', $order[$i]->create_time);
$tmp[$i]['com_name'] = isset($order[$i]->tax_title) ? $order[$i]->tax_title : '';
$tmp[$i]['goods_sum'] = $this->getOrderPrice($order[$i]->order_id, 1);
$tmp[$i]['shipping_fee'] = $this->getOrderPrice($order[$i]->order_id, 3);
$tmp[$i]['extra_fee'] = $this->getOrderPrice($order[$i]->order_id, 2);
$tmp[$i]['coupon'] = $this->getOrderPrice($order[$i]->order_id, -4);
$tmp[$i]['order_amount'] = $order[$i]->order_amount;
$tmp[$i]['currency'] = $order[$i]->currency == 1 ? 'RMB' : 'USD';
$tmp[$i]['order_type'] = !empty($order[$i]->order_pay_type) ? $order_type[$order[$i]->order_pay_type] : '未知';
$tmp[$i]['order_status'] = !empty($order[$i]->status) ? $order_status[$order[$i]->status] : '未知';
$tmp[$i]['shipping_status'] = !empty($order[$i]->shipping_status) ? $shipping_status[$order[$i]->shipping_status] : '无发货信息'; // 发货状态
$tmp[$i]['inv_type'] = $order[$i]->inv_type ? $inv_type[$order[$i]->inv_type] : '未知'; // 发票类型
$tmp[$i]['invoice_status'] = !empty($order[$i]->invoice_status) ? $invoice_status[$order[$i]->invoice_status] : '无发票信息'; // 发票状态
$tmp[$i]['sale_name'] = isset($sales) ? $sales->name : ''; // 推送业务员
$tmp[$i]['adtags'] = $order[$i]->order_source;
$tmp[$i]['client_source'] = $order[$i]->client_source;
$tmp[$i]['cancel_reason'] = $order[$i]->cancel_reason;
$tmp[$i]['send_remark'] = $order[$i]->send_remark;
}
unset($sales);
}
return $tmp;
}
// 订单金额展示
public function getOrderPrice($order_id, $type)
{
$price = DB::connection('order')->table('lie_order_price')->where('order_id', '=', $order_id)->where('price_type', '=', $type)->select('price')->first();
return $price ? $price->price : 0;
return $orderModel->orderExport($request, $info);
}
// 下载合同
......@@ -1994,18 +1631,21 @@ Class OrderController extends Controller
$year = strtotime('2017-05-28'); // 一年
$userMainModel = new UserMainModel();
$testMobile = $userMainModel->testMobile();
// 订单数量
$halfCount = DB::connection('order')->table('lie_order')
// ->where('order_goods_type', 1)
// ->where('order_type', 1)
->whereNotIn('user_id', $this->testMobile())
->whereNotIn('user_id', $testMobile)
->where('is_type', 0)
->whereBetween('create_time', [$half, $current])
->count();
echo '半年订单数:'.$halfCount.'<br>';
$yearCount = DB::connection('order')->table('lie_order')
->whereNotIn('user_id', $this->testMobile())
->whereNotIn('user_id', $testMobile)
->where('is_type', 0)
->whereBetween('create_time', [$year, $current])
->count();
......@@ -2015,7 +1655,7 @@ Class OrderController extends Controller
$halfInvoice = DB::connection('order')
->table('lie_order as o')
->leftJoin('lie_order_invoice as i', 'o.order_id', '=', 'i.order_id')
->whereNotIn('o.user_id', $this->testMobile())
->whereNotIn('o.user_id', $testMobile)
->where('o.is_type', 0)
->where('i.inv_type', 2)
->whereBetween('o.create_time', [$half, $current])
......@@ -2025,7 +1665,7 @@ Class OrderController extends Controller
$yearInvoice = DB::connection('order')
->table('lie_order as o')
->leftJoin('lie_order_invoice as i', 'o.order_id', '=', 'i.order_id')
->whereNotIn('o.user_id', $this->testMobile())
->whereNotIn('o.user_id', $testMobile)
->where('o.is_type', 0)
->where('i.inv_type', 2)
->whereBetween('o.create_time', [$year, $current])
......@@ -2036,7 +1676,7 @@ Class OrderController extends Controller
$halfAddInvoice = DB::connection('order')
->table('lie_order as o')
->leftJoin('lie_order_invoice as i', 'o.order_id', '=', 'i.order_id')
->whereNotIn('o.user_id', $this->testMobile())
->whereNotIn('o.user_id', $testMobile)
->where('o.is_type', 0)
->where('i.inv_type', 3)
->whereBetween('o.create_time', [$half, $current])
......@@ -2046,7 +1686,7 @@ Class OrderController extends Controller
$yearAddInvoice = DB::connection('order')
->table('lie_order as o')
->leftJoin('lie_order_invoice as i', 'o.order_id', '=', 'i.order_id')
->whereNotIn('o.user_id', $this->testMobile())
->whereNotIn('o.user_id', $testMobile)
->where('o.is_type', 0)
->where('i.inv_type', 3)
->whereBetween('o.create_time', [$year, $current])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment