Commit 68931965 by 朱继来

退货单导出

parent dd356d7b
......@@ -137,18 +137,18 @@ class ReturnController extends Controller
return $info;
}
// 联营退导出
// 联营退货单导出
public function returnExport(Request $request)
{
$ReturnModel = new OrderReturnModel();
return $ReturnModel->jointExport($request);
return $ReturnModel->export($request);
}
// 自营退导出
public function returnSelfExport(Request $request)
// 自营退货单导出
public function selfReturnExport(Request $request)
{
$ReturnModel = new OrderReturnModel();
return $ReturnModel->selfExport($request);
return $ReturnModel->export($request);
}
// 退货详情
......
......@@ -128,6 +128,7 @@ Route::group(['middleware' => 'web'], function () {
Route::get('/self_return_list', 'ReturnController@selfReturnList');
Route::get('/return_details/{id}', 'ReturnController@returnDetails');
Route::post('/ajax/returnCheck', 'ReturnController@returnCheck');
Route::get('/self_return_export', 'ReturnController@selfReturnExport');
});
// 不需要登陆态
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class CmsModel extends Model
{
protected $table = 'user_info';
protected $primaryKey = 'userId';
public $timestamps = false;
// 获取用户名称
public function getUserName($userId)
{
$user = $this->where(['userId' => $userId])->select('name')->first();
return $user ? $user->name : '';
}
}
\ No newline at end of file
......@@ -26,28 +26,24 @@ class OrderReturnModel extends Model
return $this->hasMany('App\Model\OrderReturnLogModel', 'return_id', 'return_id')->orderBy('create_time', 'desc');
}
// 联营订单导出
public function jointExport($request)
{
// 退货导出
public function export($request)
{
set_time_limit(0);
ini_set('memory_limit', '512M');
$map = array();
$map = array();
// 页面参数
$map['order_sn'] = $request->input('order_sn', '');
$map['sku_name'] = $request->input('sku_name', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$map['order_goods_type'] = $request->input('order_goods_type', 1);
$list = $this->from('lie_order_refund_items as it')
->leftJoin('lie_order_refund as r', function($join) {
$join->on('it.refund_id', '=', 'r.refund_id')->where('r.refund_type', '=', 2)->where('r.order_goods_type', '=', 1);
})
$list = $this->from('lie_order_return as r')
->leftJoin('lie_pay_log as p', 'r.order_id', '=', 'p.order_id')
->leftJoin('lie_user_main as u', 'r.user_id', '=', 'u.user_id')
->where(function ($query) use ($map) {
// 订单编号
if (!empty($map['order_sn'])) {
......@@ -55,12 +51,6 @@ class OrderReturnModel extends Model
}
})
->where(function ($query) use ($map) {
// sku名称
if (!empty($map['sku_name'])) {
$query->where('it.sku_name', '=', $map['sku_name']);
}
})
->where(function ($query) use ($map) {
// 创建时间
if (!empty($map['time_start']) && !empty($map['time_end'])) {
$query->whereBetween('r.create_time', [$map['time_start'], $map['time_end']]);
......@@ -99,8 +89,8 @@ class OrderReturnModel extends Model
$query->whereIn('p.pay_name', $order_payment_mode);
}
})
->select('it.refund_rec_id', 'it.refund_id', 'it.rec_id', 'it.goods_id', 'it.goods_name', 'it.brand_id', 'it.brand_name', 'it.supplier_id', 'it.supplier_name', 'it.sku_name', 'it.goods_price', 'it.single_pre_price', 'it.refund_num', 'r.order_id', 'r.order_sn', 'r.order_goods_type', 'r.currency', 'r.pay_amount', 'r.price_fall', 'r.create_uid', 'r.status', 'r.refund_reason', 'r.create_time', 'r.refund_time', 'u.mobile', 'u.email')
->groupBy('it.refund_rec_id')
->where('r.order_goods_type', $map['order_goods_type'])
->select('r.return_id', 'r.return_sn', 'r.order_id', 'r.order_sn', 'r.removal_sn', 'r.user_id', 'r.mobile', 'r.email', 'r.company_name', 'r.order_goods_type', 'r.currency', 'r.return_way', 'r.pay_amount', 'r.return_amount', 'r.return_reason', 'r.bank_account', 'r.bank_name', 'r.bank_sub_name', 'r.bank_user', 'r.shipping_id', 'r.shipping_sn', 'r.status', 'r.cancel_reason', 'r.refuse_reason', 'r.create_uid', 'r.audit_uid', 'r.create_time', 'r.audit_time', 'r.putaway_time')
->orderBy('r.create_time', 'DESC')
->get()
->toArray();
......@@ -110,215 +100,70 @@ class OrderReturnModel extends Model
$cellData = $this->exportList($list);
// 标题
$headerCell = ['订单ID', '订单编号', '会员账号', '商品型号', '制造商', '供应商', '币种', '退货数量', '原始单价', '均摊后单价', '小计', '退货总额', '手动差价', '实际退货总额', '退货原因', '后台操作人', '创建时间', '退货处理状态', '退货处理时间'];
$headerCell = ['退货单ID', '退货单号', '订单ID', '订单编号', '出库单号', '会员账号', '公司名称', '币种', '支付金额', '退货总额', '退货原因', '退货方式', '快递名称', '快递单号', '银行账号', '银行名称', '银行支行名称', '银行开户人', '取消原因', '驳回原因', '创建人', '创建时间', '审核人', '退货处理状态', '审核时间', '退货入库时间'];
array_unshift($cellData, $headerCell);
$fileName = '联营退货订单导出'.date('_YmdHis');
$fileName = $map['order_goods_type'] == 1 ? '联营退货单导出' : '自营退货单导出'.date('_YmdHis');
Excel::create($fileName, function($excel) use ($cellData){
$excel->sheet('退货单导出', function($sheet) use ($cellData){
$excel->sheet('退货单导出', function($sheet) use ($cellData){
$sheet->rows($cellData);
});
})->export('xls');
} else {
return redirect('/prompt')->with(['message'=>"数据为空无法导出!",'url'=>$_SERVER['HTTP_REFERER'], 'jumpTime'=>3,'status'=>false]);
}
}
}
/**
/**
* 导出数据处理
* @param [type] $order [查询出的单数据]
* @param [type] $order [查询出的退货单数据]
* @return [type] [description]
*/
public function exportList($order)
public function exportList($return)
{
// 订单类型
$apply_status = array(
'-1' => '已拒绝',
'1' => '待处理',
'10' => '已处理',
);
$tmp = array();
for ($i = 0; $i < count($order); $i++) {
// 推送人
if ($order[$i]['create_uid']) {
$sales = DB::table('user_info')->where(['userId' => $order[$i]['create_uid']])->select('name')->first();
}
$tmp[$i]['order_id'] = $order[$i]['order_id'];
$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]['goods_name'] = $order[$i]['order_goods_type'] == 1 ? $order[$i]['goods_name'] : $this->getGoodsName($order[$i]['goods_id']);
$tmp[$i]['brand_name'] = $order[$i]['brand_name'];
$tmp[$i]['supplier_name'] = $order[$i]['supplier_name'];
$tmp[$i]['currency'] = $order[$i]['currency'] == 1 ? 'RMB' : 'USD';
$tmp[$i]['refund_num'] = $order[$i]['refund_num'];
$tmp[$i]['goods_price'] = $order[$i]['goods_price'];
$tmp[$i]['single_pre_price'] = $order[$i]['single_pre_price'];
$tmp[$i]['goods_amount'] = $order[$i]['refund_num'] * $order[$i]['single_pre_price'];
if ($i > 0 && $tmp[$i]['order_id'] == $tmp[$i-1]['order_id']) {
$tmp[$i]['pay_amount'] = $order[$i]['pay_amount'];
$tmp[$i]['price_fall'] = $order[$i]['price_fall'];
$tmp[$i]['final_amount'] = $order[$i]['pay_amount'] - $order[$i]['price_fall'];
} else {
$tmp[$i]['pay_amount'] = '';
$tmp[$i]['price_fall'] = '';
$tmp[$i]['final_amount'] = '';
}
$tmp[$i]['refund_reason'] = $order[$i]['refund_reason'];
$tmp[$i]['sale_name'] = isset($sales) ? $sales->name : ''; // 推送业务员
$tmp[$i]['create_time'] = date('Y-m-d H:i:s', $order[$i]['create_time']);
$tmp[$i]['status'] = $apply_status[$order[$i]['status']];
$tmp[$i]['refund_time'] = $order[$i]['refund_time'] ? date('Y-m-d H:i:s', $order[$i]['refund_time']) : '';
unset($sales);
$CmsModel = new CmsModel();
for ($i = 0; $i < count($return); $i++) {
$tmp[$i]['return_id'] = $return[$i]['return_id'];
$tmp[$i]['return_sn'] = "\t".$return[$i]['return_sn']."\t";
$tmp[$i]['order_id'] = $return[$i]['order_id'];
$tmp[$i]['order_sn'] = "\t".$return[$i]['order_sn']."\t";
$tmp[$i]['removal_sn'] = "\t".$return[$i]['removal_sn']."\t";
$tmp[$i]['user_account'] = $return[$i]['mobile'] ? $return[$i]['mobile'] : $return[$i]['email'];
$tmp[$i]['company_name'] = $return[$i]['company_name'];
$tmp[$i]['currency'] = $return[$i]['currency'] == 1 ? '人民币' : '美元';
$tmp[$i]['pay_amount'] = $return[$i]['pay_amount'];
$tmp[$i]['return_amount'] = $return[$i]['return_amount'];
$tmp[$i]['return_reason'] = $return[$i]['return_reason'];
$tmp[$i]['return_way'] = $return[$i]['return_way'] == 1 ? '快递' : '自送';
$tmp[$i]['shipping_id'] = $this->getShippingName($return[$i]['shipping_id']);
$tmp[$i]['shipping_sn'] = $return[$i]['shipping_sn'];
$tmp[$i]['bank_account'] = $return[$i]['bank_account'];
$tmp[$i]['bank_name'] = $return[$i]['bank_name'];
$tmp[$i]['bank_sub_name'] = $return[$i]['bank_sub_name'];
$tmp[$i]['bank_user'] = $return[$i]['bank_user'];
$tmp[$i]['cancel_reason'] = $return[$i]['cancel_reason'];
$tmp[$i]['refuse_reason'] = $return[$i]['refuse_reason'];
$tmp[$i]['create_uid'] = $CmsModel->getUserName($return[$i]['create_uid']);
$tmp[$i]['create_time'] = date('Y-m-d H:i:s', $return[$i]['create_time']);
$tmp[$i]['audit_uid'] = $CmsModel->getUserName($return[$i]['audit_uid']);
$tmp[$i]['status'] = Config('params.return_status')[$return[$i]['status']];
$tmp[$i]['audit_time'] = $return[$i]['audit_time'] ? date('Y-m-d H:i:s', $return[$i]['audit_time']) : '';
$tmp[$i]['putaway_time'] = $return[$i]['putaway_time'] ? date('Y-m-d H:i:s', $return[$i]['putaway_time']) : '';
}
return $tmp;
}
// 获取自营商品型号
public function getGoodsName($goods_id)
{
$goods_info = json_decode(Redis::hget('Self_SelfGoods', $goods_id), true);
return $goods_info['goods_name'];
}
// 自营订单导出
public function selfExport($request)
{
set_time_limit(0);
ini_set('memory_limit', '512M');
$map = array();
// 页面参数
$map['order_sn'] = $request->input('order_sn', '');
$map['time_start'] = $request->input('time_start', '');
$map['time_end'] = $request->input('time_end', '');
$map['apply_status'] = $request->input('apply_status', '');
$map['order_payment_mode'] = $request->input('order_payment_mode', '');
$list = $this->from('lie_order_refund as r')
->leftJoin('lie_pay_log as p', 'r.order_id', '=', 'p.order_id')
->leftJoin('lie_user_main as u', 'r.user_id', '=', 'u.user_id')
->where('r.refund_type', '=', 1)
->where('r.order_goods_type', '=', 2)
->where(function ($query) use ($map) {
// 订单编号
if (!empty($map['order_sn'])) {
$query->where('r.order_sn', '=', $map['order_sn']);
}
})
->where(function ($query) use ($map) {
// 创建时间
if (!empty($map['time_start']) && !empty($map['time_end'])) {
$query->whereBetween('r.create_time', [$map['time_start'], $map['time_end']]);
} else if (!empty($map['time_start'])) {
$query->where('r.create_time', '>', $map['time_start']);
} else if (!empty($map['time_end'])) {
$query->where('r.create_time', '<', $map['time_end']);
}
})
->where(function ($query) use ($map) {
// 订单状态
if (!empty($map['apply_status'])) {
$query->whereIn('r.status', explode(',', $map['apply_status']));
}
})
->where(function ($query) use ($map) {
// 支付方式
if (!empty($map['order_payment_mode'])) {
$pay_name = explode(',', $map['order_payment_mode']);
$order_payment_mode = [];
foreach ($pay_name as $v) {
switch ($v) {
case '1': $order_payment_mode[] = '微信支付';break;
case '2': $order_payment_mode[] = '支付宝';break;
case '3': $order_payment_mode[] = '银联支付(B2B)';break;
case '4': $order_payment_mode[] = '银联支付(B2C)';break;
case '5': $order_payment_mode[] = '账期支付';break;
case '6': $order_payment_mode[] = '京东支付';break;
case '7': $order_payment_mode[] = '交通银行';break;
case '8': $order_payment_mode[] = '恒生银行';break;
case '9': $order_payment_mode[] = '钱包支付';break;
}
}
$query->whereIn('p.pay_name', $order_payment_mode);
}
})
->select('r.order_id', 'r.order_sn', 'r.order_goods_type', 'r.currency', 'r.pay_amount', 'r.price_fall', 'r.create_uid', 'r.status', 'r.refund_reason', 'r.create_time', 'r.refund_time', 'u.mobile', 'u.email')
->orderBy('r.create_time', 'DESC')
->get()
->toArray();
if (!empty($list)) {
// 订单数据处理
$cellData = $this->selfExportList($list);
// 标题
$headerCell = ['订单ID', '订单编号', '会员账号', '退货原因', '后台操作人', '创建时间', '退货处理状态', '退货处理时间'];
array_unshift($cellData, $headerCell);
$fileName = '自营退货订单导出'.date('_YmdHis');
Excel::create($fileName, function($excel) use ($cellData){
$excel->sheet('退货订单导出', function($sheet) use ($cellData){
$sheet->rows($cellData);
});
})->export('xls');
} else {
return redirect('/prompt')->with(['message'=>"数据为空无法导出!",'url'=>$_SERVER['HTTP_REFERER'], 'jumpTime'=>3,'status'=>false]);
}
}
/**
* 导出数据处理
* @param [type] $order [查询出的订单数据]
* @return [type] [description]
*/
public function selfExportList($order)
// 获取物流名称
public function getShippingName($shipping_id)
{
// 订单类型
$apply_status = array(
'-1' => '已拒绝',
'1' => '待处理',
'10' => '已处理',
);
$shipping = DB::connection('order')->table('lie_shipping')->where('shipping_id', $shipping_id)->select('shipping_name')->first();
$tmp = array();
for ($i = 0; $i < count($order); $i++) {
// 推送人
if ($order[$i]['create_uid']) {
$sales = DB::table('user_info')->where(['userId' => $order[$i]['create_uid']])->select('name')->first();
}
$tmp[$i]['order_id'] = $order[$i]['order_id'];
$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]['refund_reason'] = $order[$i]['refund_reason'];
$tmp[$i]['sale_name'] = isset($sales) ? $sales->name : ''; // 推送业务员
$tmp[$i]['create_time'] = date('Y-m-d H:i:s', $order[$i]['create_time']);
$tmp[$i]['status'] = $apply_status[$order[$i]['status']];
$tmp[$i]['refund_time'] = $order[$i]['refund_time'] ? date('Y-m-d H:i:s', $order[$i]['refund_time']) : '';
unset($sales);
}
return $tmp;
return $shipping ? $shipping->shipping_name : '';
}
// 审核
......@@ -332,7 +177,7 @@ class OrderReturnModel extends Model
$update['syn_sign'] = 1; // 标记wms同步
$event = '审核通过退货单';
} else {
$update['refund_reason'] = $request->input('refund_reason');
$update['refuse_reason'] = $request->input('refuse_reason');
$event = '驳回退货单,原因:'.$refund_reason;
}
......
......@@ -132,31 +132,6 @@
}
})
// // 钱包退款
// $('.wallet-refund').click(function(){
// var order_id = $(this).data('oid');
// var amount = $(this).data('amount');
// $.ajax({
// url : 'ajax/wallet_refund',
// type: 'post',
// data: {order_id: order_id, amount: amount},
// dataType: 'json',
// success: function (resp) {
// if (resp.errcode == 0) {
// window.href =
// return false;
// }
// layer.msg(resp.errmsg);
// },
// error: function (err) {
// console.log(err)
// }
// })
// })
// 自营退款列表取消申请
$('.cancel-refund').click(function() {
var rid = $(this).data('rid');
......@@ -192,6 +167,140 @@
},
index_new:function(){
$.lie.droplist($('.droplist'));
// 特殊字符编码
function specialCode(chr)
{
switch (chr) {
case '!': return '%21'; break;
case '"': return '%22'; break;
case '#': return '%23'; break;
case '$': return '%24'; break;
case '%': return '%25'; break;
case '&': return '%26'; break;
case '\'': return '%27'; break;
case '(': return '%28'; break;
case ')': return '%29'; break;
case '*': return '%2A'; break;
case '+': return '%2B'; break;
case ',': return '%2C'; break;
case '/': return '%2F'; break;
case ':': return '%3A'; break;
case ';': return '%3B'; break;
case '<': return '%3C'; break;
case '=': return '%3D'; break;
case '>': return '%3E'; break;
case '?': return '%3F'; break;
case '@': return '%40'; break;
case '[': return '%5B'; break;
case ']': return '%5D'; break;
case '\\': return '%5C'; break;
case '|': return '%7C'; break;
default: return ''; break;
}
}
// 查找特殊字符
function specialStr(str)
{
var reg = new RegExp("[!\"#$%&'()*+,/:;<=>?@\\[\\]\\|]");
var len = str.length;
var rs = '';
for (var i = 0; i < len; i++) {
var val = str.substr(i, 1);
if (reg.test(val)) {
rs = rs + specialCode(val);;
} else {
rs = rs + val;
}
}
return rs;
}
// 搜索、导出条件
function refundCommon(url) {
var order_sn = $('input[name="order_sn"]').val(),
sku_name = $('input[name="sku_name"]').val(),
apply_status = $('#apply_status').val() ? $('#apply_status').val() : '',
order_payment_mode = $('#order_payment_mode').val() ? $('#order_payment_mode').val() : '',
time_start = $('input[name="time_start"]').val(),
time_end = $('input[name="time_end"]').val(),
order_goods_type = $('input[name="order_goods_type"]').val();
if (url == '/return_export' || url == '/self_return_export') {
if (!order_sn && !sku_name && !apply_status && !order_payment_mode && !time_start && !time_end) {
layer.msg('请选择筛选条件,再导出!');
return false;
}
}
if (!order_sn && !sku_name && !apply_status && !order_payment_mode && !time_start && !time_end) {
location.href = url;
}
var listUrl = url;
listUrl += '?order_sn=' + order_sn;
if (sku_name) {
listUrl += '&sku_name=' + specialStr(sku_name);
}
if (order_payment_mode) {
listUrl += '&order_payment_mode=' + order_payment_mode;
}
if (apply_status) {
listUrl += '&apply_status=' + apply_status;
}
if(time_start){
time_start = Date.parse(time_start) / 1000;
listUrl += '&time_start='+time_start;
}
if(time_end){
time_end = Date.parse(time_end) / 1000 + (24*60*60-1);
listUrl += '&time_end='+time_end;
}
listUrl += '&order_goods_type='+order_goods_type;
location.href = listUrl;
}
// 搜索
$('.search_return_order').click(function(){
var order_goods_type = $('input[name="order_goods_type"]').val();
if (order_goods_type == 1) {
refundCommon('/return_list');
} else {
refundCommon('/self_return_list');
}
})
// 导出订单
$('.export_return_order').click(function() {
var order_goods_type = $('input[name="order_goods_type"]').val();
if (order_goods_type == 1) {
refundCommon('/return_export');
} else {
refundCommon('/self_return_export');
}
})
},
refund:function() {
// 正整数输入框限制
$('.int_num').off().on('keyup', function(){
......
......@@ -66,8 +66,8 @@
<div class="text-center" style="margin-top: 10px;">
<input type="hidden" name="order_goods_type" value="{{$condition['order_goods_type']}}">
<div class="search-btn">
<button class="nbtn search_refund_order">搜索</button>
<button class="nbtn refund_order_export" style="margin-left: 20px; background: #23c6c8 !important;">导出</button>
<button class="nbtn search_return_order">搜索</button>
<button class="nbtn export_return_order" style="margin-left: 20px; background: #23c6c8 !important;">导出</button>
</div>
</div>
</div>
......@@ -160,5 +160,5 @@
$('.apply_status').selectpicker('val', apply_status.split(',')).trigger("change");
$('.order_payment_mode').selectpicker('val', order_payment_mode.split(',')).trigger("change");
$.lie.refund.index();
$.lie.refund.index_new();
</script>
\ No newline at end of file
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