Commit 2c00c1f7 by 朱继来

调整导出

parent e512d37c
......@@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Redis;
use Request;
use Excel;
use DB;
use App\Model\OrderPriceModel;
use App\Model\UserMainModel;
class OrderModel extends Model
{
......@@ -36,7 +38,7 @@ class OrderModel extends Model
// ->leftJoin('lie_order_shipping as s', function($join) {
// $join->on('o.order_id', '=', 's.order_id')->where('s.shipping_type', '=', 1);
// })
->leftJoin('lie_user_main as u', 'o.user_id', '=', 'u.user_id')
// ->leftJoin('lie_user_main as u', 'o.user_id', '=', 'u.user_id')
// ->leftJoin('lie_user_company as c', 'o.user_id', '=', 'c.user_id')
->where(function ($query) use ($map) {
// 查询类型
......@@ -46,11 +48,16 @@ class OrderModel extends Model
} else if($map['order_type'] == 4) { // 会员ID
$query->where('o.user_id', '=', $map['order_contain']);
} else { // 会员账号
$user_map = [];
if (preg_match('/@/', $map['order_contain'])) {
$query->where('u.email', '=', $map['order_contain']);
$user_map['email'] = $map['order_contain'];
} else {
$query->where('u.mobile', '=', $map['order_contain']);
$user_map['mobile'] = $map['order_contain'];
}
$user_id = UserMainModel::where($user_map)->value('user_id');
$query->where('o.user_id', '=', $user_id);
}
}
})
......@@ -235,12 +242,12 @@ class OrderModel extends Model
$query->where('i.inv_type', '=', $map['order_invoice_status']);
}
})
->where(function ($query) use ($map) {
// 是否为新用户
if ($map['is_new'] != '') {
$query->where('u.is_new', '=', $map['is_new']);
}
})
// ->where(function ($query) use ($map) {
// // 是否为新用户
// if ($map['is_new'] != '') {
// $query->where('u.is_new', '=', $map['is_new']);
// }
// })
->where(function ($query) use ($map) {
// 是否新订单
if ($map['is_new_order'] != '') {
......@@ -261,7 +268,7 @@ class OrderModel extends Model
})
->where('it.status', 1)
->where('o.order_goods_type', '=', $map['order_goods_type'])
->select('o.order_id', 'o.order_sn', 'o.order_type', 'o.order_pay_type', 'o.order_goods_type', 'o.order_source', 'o.create_time', 'o.status', 'o.order_amount', 'o.sale_type', 'o.currency', 'o.sale_id', 'o.cancel_reason', 'o.advance_pay_time', 'o.pay_time', 'it.goods_id', 'it.goods_name', 'it.goods_number', 'it.goods_price', 'it.single_pre_price', 'it.brand_name', 'it.supplier_name', 'it.goods_class', 'it.self_supplier_type', 'it.extra_price', 'it.goods_discount_amount', 'i.tax_title', 'i.inv_type', 'i.invoice_status', 'i.tax_title', 'i.company_address', 'i.company_phone', 'i.tax_no', 'i.bank_name', 'i.bank_account', 'u.user_id', 'u.mobile', 'u.email', 'u.client_source', 'u.is_new', 'u.is_test', 'oe.erp_sn', 'oe.order_type as extend_order_type', 'oe.send_remark', 'oe.is_new as is_new_order', 'oe.business_type', 'oe.jd_order_id', 'oe.exchange_rate', 'oe.sample_demand_desc')
->select('o.order_id', 'o.order_sn', 'o.user_id', 'o.order_type', 'o.order_pay_type', 'o.order_goods_type', 'o.order_source', 'o.create_time', 'o.status', 'o.order_amount', 'o.sale_type', 'o.currency', 'o.sale_id', 'o.cancel_reason', 'o.advance_pay_time', 'o.pay_time', 'it.goods_id', 'it.goods_name', 'it.goods_number', 'it.goods_price', 'it.single_pre_price', 'it.brand_name', 'it.supplier_name', 'it.goods_class', 'it.self_supplier_type', 'it.extra_price', 'it.goods_discount_amount', 'i.tax_title', 'i.inv_type', 'i.invoice_status', 'i.tax_title', 'i.company_address', 'i.company_phone', 'i.tax_no', 'i.bank_name', 'i.bank_account', 'oe.erp_sn', 'oe.order_type as extend_order_type', 'oe.send_remark', 'oe.is_new as is_new_order', 'oe.business_type', 'oe.jd_order_id', 'oe.exchange_rate', 'oe.sample_demand_desc')
->groupBy('it.rec_id')
->orderBy('o.create_time', 'DESC')
// ->get()
......@@ -272,6 +279,8 @@ class OrderModel extends Model
$list['data'] = $this->exportList($list['data']); // 订单数据处理
}
// 'u.user_id', 'u.mobile', 'u.email', 'u.client_source', 'u.is_new', 'u.is_test',
return $list;
// dump($list->getBindings());
// dump($list->toSql());
......@@ -365,6 +374,10 @@ class OrderModel extends Model
$order_price = $OrderPriceModel->whereIn('order_id', $all_order_id)->select('order_id', 'price_type', 'price')->get()->keyBy(function ($item) {
return strtoupper($item['order_id'].'.'.$item['price_type']);
})->toArray();
// 获取用户信息
$UserMainModel = new UserMainModel();
$user_info = $UserMainModel->whereIn('user_id', $all_user_id)->select('mobile', 'email', 'client_source', 'is_new', 'is_test', 'user_id')->get()->keyBy('user_id')->toArray();
// 获取用户公司名称
$UserCompanyModel = new UserCompanyModel();
......@@ -379,15 +392,25 @@ class OrderModel extends Model
$order_shipping = $OrderShippingModel->where('shipping_type', 1)->whereIn('order_id', $all_order_id)->select('order_id', 'status')->get()->keyBy('order_id')->toArray();
for ($i = 0; $i < count($order); $i++) {
$current_com_name = isset($company_info[$order[$i]['user_id']]) ? $company_info[$order[$i]['user_id']] : ''; // 当前公司
$current_order_addr = isset($order_address[$order[$i]['order_id']]) ? $order_address[$order[$i]['order_id']] : ''; // 当前订单收货地址
$user = isset($user_info[$order[$i]['user_id']]) ? $user_info[$order[$i]['user_id']] : '';
if (!$user) {
$user['mobile'] = '';
$user['email'] = '';
$user['client_source'] = '';
$user['is_new'] = '';
$user['is_test'] = '';
}
$current_com_name = isset($company_info[$order[$i]['user_id']]) ? $company_info[$order[$i]['user_id']] : ''; // 当前公司
$current_order_addr = isset($order_address[$order[$i]['order_id']]) ? $order_address[$order[$i]['order_id']] : ''; // 当前订单收货地址
$current_order_shipping = isset($order_shipping[$order[$i]['order_id']]) ? $order_shipping[$order[$i]['order_id']] : ''; // 当前订单物流
$tmp[$i]['order_id'] = $order[$i]['order_id'];
$tmp[$i]['order_sn'] = "\t".$order[$i]['order_sn']."\t";
$tmp[$i]['erp_sn'] = "\t".$order[$i]['erp_sn']."\t";
$tmp[$i]['jd_order_id'] = "\t".$order[$i]['jd_order_id']."\t";
$tmp[$i]['user_account'] = $order[$i]['mobile'] ? $order[$i]['mobile'] : $order[$i]['email'];
$tmp[$i]['user_account'] = isset($user['mobile']) ? $user['mobile'] : $user['email'];
// $tmp[$i]['is_new'] = $order[$i]['is_new'] == 1 ? '是' : '否'; // 是否为新用户
$tmp[$i]['consignee'] = isset($current_order_addr['consignee']) ? $current_order_addr['consignee']."\t" : '';
......@@ -463,12 +486,12 @@ class OrderModel extends Model
$tmp[$i]['send_remark'] = '';
} else {
$tmp[$i]['adtags'] = $order[$i]['order_source'];
$tmp[$i]['client_source'] = $order[$i]['client_source'];
$tmp[$i]['client_source'] = $user['client_source'];
$tmp[$i]['cancel_reason'] = $order[$i]['cancel_reason'];
$tmp[$i]['send_remark'] = $order[$i]['send_remark'];
}
$tmp[$i]['is_test'] = $order[$i]['is_test'] == 1 ? '是' : '否';
$tmp[$i]['is_test'] = $user['is_test'] == 1 ? '是' : '否';
if ($order[$i]['order_goods_type'] == 2) {
$tmp[$i]['sale_type'] = $order[$i]['sale_type'] == 1 ? '现卖' : '预售';
......@@ -559,9 +582,6 @@ class OrderModel extends Model
}
return $result[0]['region_name'].$suffix;
}
// 获取自营商品型号
......@@ -575,9 +595,9 @@ class OrderModel extends Model
// 订单金额展示
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();
$price = OrderPriceModel::where('order_id', '=', $order_id)->where('price_type', '=', $type)->value('price');
return $price ? $price->price : 0;
return $price ? $price : 0;
}
// 获取订单来源
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;
use Request;
use Excel;
use DB;
class OrderReturnModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_order_return';
protected $primaryKey = 'return_id';
public $timestamps = false;
// 获取退货单明细
public function hasManyReturnItems()
{
return $this->hasMany('App\Model\OrderReturnItemsModel', 'return_id', 'return_id');
}
// 获取退货单记录
public function hasManyReturnLog()
{
return $this->hasMany('App\Model\OrderReturnLogModel', 'return_id', 'return_id')->orderBy('create_time', 'desc');
}
// 退货导出
public function export($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', '');
$map['order_goods_type'] = $request->input('order_goods_type', 1);
$list = $this->from('lie_order_return as r')
->leftJoin('lie_pay_log as p', 'r.order_id', '=', 'p.order_id')
->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);
}
})
->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();
if (!empty($list)) {
// 订单数据处理
$cellData = $this->exportList($list);
// 标题
$headerCell = ['退货单ID', '退货单号', '订单ID', '订单编号', '出库单号', '会员账号', '公司名称', '币种', '支付金额', '退货总额', '退货原因', '退货方式', '快递名称', '快递单号', '银行账号', '银行名称', '银行支行名称', '银行开户人', '取消原因', '驳回原因', '创建人', '创建时间', '审核人', '退货处理状态', '审核时间', '退货入库时间'];
array_unshift($cellData, $headerCell);
$fileName = $map['order_goods_type'] == 1 ? '联营退货单导出' : '自营退货单导出'.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 exportList($return)
{
$tmp = array();
$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 getShippingName($shipping_id)
{
$shipping = DB::connection('order')->table('lie_shipping')->where('shipping_id', $shipping_id)->select('shipping_name')->first();
return $shipping ? $shipping->shipping_name : '';
}
// 审核
public function check($request)
{
$return_id = $request->input('return_id');
$type = $request->input('type');
$operator_id = $request->user->userId;
if ($type == 2) {
$event = '审核通过退货单';
} else {
$update['refuse_reason'] = $request->input('refuse_reason');
$event = '驳回退货单,原因:'.$update['refuse_reason'];
}
$update['status'] = $type;
$update['audit_uid'] = $operator_id;
$update['audit_time'] = time();
try {
DB::connection('order')->beginTransaction(); // 开启事务
$OrderReturnLogModel = new OrderReturnLogModel();
$this->where('return_id', $return_id)->update($update);
$OrderReturnLogModel->addLog($return_id, $operator_id, $event);
DB::connection('order')->commit(); // 提交事务
return ['err_code'=>0, 'err_msg'=>'操作成功'];
} catch(Exception $e) {
DB::connection('order')->rollback(); // 回滚
return ['err_code'=>1, 'err_msg'=>'操作失败,原因:'.$e->getMessage()];
}
}
// 物流信息
public function shipping($request)
{
$return_id = $request->input('return_id');
$operator_id = $request->user->userId;
$data['shipping_id'] = $request->input('shipping_id');
$data['shipping_sn'] = $request->input('shipping_sn');
$data['status'] = 7; // 待收货
$data['syn_sign'] = 1; // 标记wms同步
try {
DB::connection('order')->beginTransaction(); // 开启事务
$OrderReturnLogModel = new OrderReturnLogModel();
$this->where('return_id', $return_id)->update($data);
$OrderReturnLogModel->addLog($return_id, $operator_id, '填写物流信息,快递名称:'.$this->getShippingName($data['shipping_id']).',快递单号:'.$data['shipping_sn']);
DB::connection('order')->commit(); // 提交事务
return ['err_code'=>0, 'err_msg'=>'操作成功'];
} catch(Exception $e) {
DB::connection('order')->rollback(); // 回滚
return ['err_code'=>1, 'err_msg'=>'操作失败,原因:'.$e->getMessage()];
}
}
// 获取活动期间已完成退款的用户金额
public function getSelfReturnAmount($user_id, $start_time, $end_time)
{
return $this->where('user_id', $user_id)
->where('status', 10)
->whereBetween('putaway_time', [$start_time, $end_time])
->select('user_id', 'currency', 'return_amount')
->get()
->toArray();
}
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;
use Request;
use Excel;
use DB;
use App\Model\ShippingModel;
class OrderReturnModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_order_return';
protected $primaryKey = 'return_id';
public $timestamps = false;
// 获取退货单明细
public function hasManyReturnItems()
{
return $this->hasMany('App\Model\OrderReturnItemsModel', 'return_id', 'return_id');
}
// 获取退货单记录
public function hasManyReturnLog()
{
return $this->hasMany('App\Model\OrderReturnLogModel', 'return_id', 'return_id')->orderBy('create_time', 'desc');
}
// 退货导出
public function export($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', '');
$map['order_goods_type'] = $request->input('order_goods_type', 1);
$list = $this->from('lie_order_return as r')
->leftJoin('lie_pay_log as p', 'r.order_id', '=', 'p.order_id')
->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);
}
})
->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();
if (!empty($list)) {
// 订单数据处理
$cellData = $this->exportList($list);
// 标题
$headerCell = ['退货单ID', '退货单号', '订单ID', '订单编号', '出库单号', '会员账号', '公司名称', '币种', '支付金额', '退货总额', '退货原因', '退货方式', '快递名称', '快递单号', '银行账号', '银行名称', '银行支行名称', '银行开户人', '取消原因', '驳回原因', '创建人', '创建时间', '审核人', '退货处理状态', '审核时间', '退货入库时间'];
array_unshift($cellData, $headerCell);
$fileName = $map['order_goods_type'] == 1 ? '联营退货单导出' : '自营退货单导出'.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 exportList($return)
{
$tmp = array();
$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 getShippingName($shipping_id)
{
return ShippingModel::where('shipping_id', $shipping_id)->value('shipping_name');
}
// 审核
public function check($request)
{
$return_id = $request->input('return_id');
$type = $request->input('type');
$operator_id = $request->user->userId;
if ($type == 2) {
$event = '审核通过退货单';
} else {
$update['refuse_reason'] = $request->input('refuse_reason');
$event = '驳回退货单,原因:'.$update['refuse_reason'];
}
$update['status'] = $type;
$update['audit_uid'] = $operator_id;
$update['audit_time'] = time();
try {
DB::connection('order')->beginTransaction(); // 开启事务
$OrderReturnLogModel = new OrderReturnLogModel();
$this->where('return_id', $return_id)->update($update);
$OrderReturnLogModel->addLog($return_id, $operator_id, $event);
DB::connection('order')->commit(); // 提交事务
return ['err_code'=>0, 'err_msg'=>'操作成功'];
} catch(Exception $e) {
DB::connection('order')->rollback(); // 回滚
return ['err_code'=>1, 'err_msg'=>'操作失败,原因:'.$e->getMessage()];
}
}
// 物流信息
public function shipping($request)
{
$return_id = $request->input('return_id');
$operator_id = $request->user->userId;
$data['shipping_id'] = $request->input('shipping_id');
$data['shipping_sn'] = $request->input('shipping_sn');
$data['status'] = 7; // 待收货
$data['syn_sign'] = 1; // 标记wms同步
try {
DB::connection('order')->beginTransaction(); // 开启事务
$OrderReturnLogModel = new OrderReturnLogModel();
$this->where('return_id', $return_id)->update($data);
$OrderReturnLogModel->addLog($return_id, $operator_id, '填写物流信息,快递名称:'.$this->getShippingName($data['shipping_id']).',快递单号:'.$data['shipping_sn']);
DB::connection('order')->commit(); // 提交事务
return ['err_code'=>0, 'err_msg'=>'操作成功'];
} catch(Exception $e) {
DB::connection('order')->rollback(); // 回滚
return ['err_code'=>1, 'err_msg'=>'操作失败,原因:'.$e->getMessage()];
}
}
// 获取活动期间已完成退款的用户金额
public function getSelfReturnAmount($user_id, $start_time, $end_time)
{
return $this->where('user_id', $user_id)
->where('status', 10)
->whereBetween('putaway_time', [$start_time, $end_time])
->select('user_id', 'currency', 'return_amount')
->get()
->toArray();
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
class PaymentDaysModel extends Model
{
protected $connection='order';
protected $table='lie_payment_days';
public $timestamps = false;
public function ApiPaymentDaysList(){
$collert=Request::only('user_id','ac_id','status','limit','p','Export');
$limit=!empty($collert['limit'])?$collert['limit']:10;
$p=!empty($collert['p'])?$collert['p']:1;
$Select=['id','auth_cause','lie_payment_days.user_id','add_time','com_name','lie_payment_days.mobile','ac_id','lie_payment_days.status','lie_user_main.mobile as usmobile','email'];
$list=$this->where(function($query) use ($collert){
if(!empty($collert['ac_id'])) $query->where('ac_id','=',$collert['ac_id']);
if(!empty($collert['status'])) $query->whereIn('lie_payment_days.status',explode(',',rtrim($collert['status'],',')));
})->join('lie_user_main',function($join) use($collert){
if(!empty($collert['user_id'])){
$join->on('lie_payment_days.user_id','=','lie_user_main.user_id')
->where('lie_user_main.mobile','=',$collert['user_id'])->orWhere('lie_user_main.email','=',$collert['user_id']);
}else{
$join->on('lie_payment_days.user_id','=','lie_user_main.user_id');
}
})->select($Select)->paginate($limit,['*'],'p',$p)->toArray();
if(!empty($collert['Export']) && $collert['Export']==true){
$cellData = [
['ID','会员账号','公司名称','联系方式','活动ID','申请时间','申请状态','审核原因']
];
$Status=[1=>'待审核',2=>'审核通过',3=>'审核不通过'];
foreach ($list['data'] as $k=>$v){
$v['status_name']=empty($Status[$v['status']])?'未知':$Status[$v['status']];
$info=[$v['id'],empty($v['usmobile'])?$v['email']:$v['usmobile'],$v['com_name'],$v['mobile'],$v['ac_id'],date('Y-m-d H:i',$v['add_time']),$v['status_name'],$v['auth_cause']];
array_push($cellData,$info);
}
Excel::create("账期搜索结果",function ($excel) use ($cellData){
$excel->sheet('账期搜索结果',function ($sheet) use ($cellData) {
$sheet->rows($cellData);
});
})->export('xls');
}
return [0,'成功',$list['data'],$list['total'],$limit];
}
public function AuthPaymentDays(){
$collert=Request::only('id');
$Select=['lie_payment_days.id','lie_payment_days.status','lie_payment_days.com_name','lie_payment_days.user_id','lie_payment_days.mobile','add_time',
'lie_user_main.mobile as usmobile','email','company_id','com_telphone','tax_no','bank_name','com_area_id','com_address',
'com_city_id','com_province_id','auth_cause'];
$info=$this->where('id','=',$collert['id'])
->leftJoin('lie_user_main','lie_payment_days.user_id','=','lie_user_main.user_id')
->leftJoin('lie_user_company','lie_user_main.company_id','=','lie_user_company.com_id')
->leftJoin('lie_taxinfo',function($join){
$join->on('lie_payment_days.user_id','=','lie_taxinfo.user_id')->where('is_default','=',1);
})
->select($Select)->first()->toArray();
if(!$info) return false;
$address=DB::connection('order')->table('lie_region')->whereIn('region_id',[$info['com_area_id'],$info['com_city_id'],$info['com_province_id']])->lists('region_name','region_id');
$info['address']=$address;
return $info;
}
public function ApiAuthPaymentDays($AdminId){
$collert=Request::only('id','status','auth_cause');
if(empty($collert['id']) || empty($collert['status'])) return [10002,'审核失败'];
$result=$this->where('id','=',$collert['id'])->update(['auth_cause'=>$collert['auth_cause'],'status'=>$collert['status'],'auth_id'=>$AdminId,'update_time'=>time()]);
if(!$result) return [10001,'审核失败'];
return [0,'审核成功'];
}
}
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Request;
use Excel;
use DB;
use App\Model\RegionModel;
class PaymentDaysModel extends Model
{
protected $connection='order';
protected $table='lie_payment_days';
public $timestamps = false;
public function ApiPaymentDaysList(){
$collert=Request::only('user_id','ac_id','status','limit','p','Export');
$limit=!empty($collert['limit'])?$collert['limit']:10;
$p=!empty($collert['p'])?$collert['p']:1;
$Select=['id','auth_cause','lie_payment_days.user_id','add_time','com_name','lie_payment_days.mobile','ac_id','lie_payment_days.status','lie_user_main.mobile as usmobile','email'];
$list=$this->where(function($query) use ($collert){
if(!empty($collert['ac_id'])) $query->where('ac_id','=',$collert['ac_id']);
if(!empty($collert['status'])) $query->whereIn('lie_payment_days.status',explode(',',rtrim($collert['status'],',')));
})->join('lie_user_main',function($join) use($collert){
if(!empty($collert['user_id'])){
$join->on('lie_payment_days.user_id','=','lie_user_main.user_id')
->where('lie_user_main.mobile','=',$collert['user_id'])->orWhere('lie_user_main.email','=',$collert['user_id']);
}else{
$join->on('lie_payment_days.user_id','=','lie_user_main.user_id');
}
})->select($Select)->paginate($limit,['*'],'p',$p)->toArray();
if(!empty($collert['Export']) && $collert['Export']==true){
$cellData = [
['ID','会员账号','公司名称','联系方式','活动ID','申请时间','申请状态','审核原因']
];
$Status=[1=>'待审核',2=>'审核通过',3=>'审核不通过'];
foreach ($list['data'] as $k=>$v){
$v['status_name']=empty($Status[$v['status']])?'未知':$Status[$v['status']];
$info=[$v['id'],empty($v['usmobile'])?$v['email']:$v['usmobile'],$v['com_name'],$v['mobile'],$v['ac_id'],date('Y-m-d H:i',$v['add_time']),$v['status_name'],$v['auth_cause']];
array_push($cellData,$info);
}
Excel::create("账期搜索结果",function ($excel) use ($cellData){
$excel->sheet('账期搜索结果',function ($sheet) use ($cellData) {
$sheet->rows($cellData);
});
})->export('xls');
}
return [0,'成功',$list['data'],$list['total'],$limit];
}
public function AuthPaymentDays(){
$collert=Request::only('id');
$Select=['lie_payment_days.id','lie_payment_days.status','lie_payment_days.com_name','lie_payment_days.user_id','lie_payment_days.mobile','add_time',
'lie_user_main.mobile as usmobile','email','company_id','com_telphone','tax_no','bank_name','com_area_id','com_address',
'com_city_id','com_province_id','auth_cause'];
$info=$this->where('id','=',$collert['id'])
->leftJoin('lie_user_main','lie_payment_days.user_id','=','lie_user_main.user_id')
->leftJoin('lie_user_company','lie_user_main.company_id','=','lie_user_company.com_id')
->leftJoin('lie_taxinfo',function($join){
$join->on('lie_payment_days.user_id','=','lie_taxinfo.user_id')->where('is_default','=',1);
})
->select($Select)->first()->toArray();
if(!$info) return false;
$address=RegionModel::whereIn('region_id',[$info['com_area_id'],$info['com_city_id'],$info['com_province_id']])->lists('region_name','region_id');
$info['address']=$address;
return $info;
}
public function ApiAuthPaymentDays($AdminId){
$collert=Request::only('id','status','auth_cause');
if(empty($collert['id']) || empty($collert['status'])) return [10002,'审核失败'];
$result=$this->where('id','=',$collert['id'])->update(['auth_cause'=>$collert['auth_cause'],'status'=>$collert['status'],'auth_id'=>$AdminId,'update_time'=>time()]);
if(!$result) return [10001,'审核失败'];
return [0,'审核成功'];
}
}
<?php
namespace App\Model\Pcb;
use App\Map\PcbOrderMap;
use App\Model\UserMainModel;
use Illuminate\Database\Eloquent\Model;
use Request;
use DB;
class PcbOrderModel extends Model
{
protected $connection='pcb';
protected $table='order';
protected $primaryKey='id';
public $timestamps = false;
//列表
public function getList($type =1)
{
$arr = ['p', 'limit','self','start_time','end_time','status',"user_account","order_sn","purchase_sn","order_type","adtag","ptag","test_order"];
$input = Request::only($arr);
$input=TrimX($input,true,$arr);
//查询数据\
$list = $this->where(function ($query) use ($input) {
$PcbPurchaseModel = new PcbPurchaseModel();
foreach ($input as $k => $v){
$v = trim($v);
switch ($k){
case "p":
case "limit":
case "_url":
case "test_order":
continue;
break;
case "start_time":
$query->where('create_time', '>=', strtotime($v));
break;
case "end_time":
$query->where('create_time', '<=',strtotime($v));
break;
case "end_time":
$query->where('create_time', '<=',strtotime($v));
break;
case "purchase_sn":
$items = $PcbPurchaseModel->select("order_id")->where("purchase_sn","like","%".$v."%")->get();
if ($items->count()){
$orderIds = arrayToCommaStr($items->toArray(),'order_id',1);
$query->whereIn("order_id",$orderIds);
}else{
$query->where("order_id",0);
}
break;
default:
$query->whereIn($k, explode(',',trim($v,',')));
break;
}
}
})->orderBy('order_id','desc');
if (empty($input['test_order'])){ //排除测试账号
$testMobile = (new UserMainModel())->testMobile();
$list->whereNotIn('user_id', $testMobile);
}
//getSql();
if ($type == 1){
$input['limit'] = 10;
$input['p'] = isset($input['p']) ? $input['p'] : 1;
$list = $list->paginate($input['limit'], ['*'], 'p', $input['p'])->toArray();
if (!$list) return [20001, '没有数据'];
$data = $this->clearData($list['data']);
return [0, '成功', $data, $list['total']];
}else{
return $this->clearData($list->get()->toArray());
}
}
//清洗列表数据
private function clearData($data){
if (!is_array($data) || count($data) == 0 || $data == ""){
return [];
}
$PcbPurchaseModel = new PcbPurchaseModel();
$PcbPublicModel = new PcbPublicModel();
$con = DB::connection("pcb");
foreach ($data as $k=>&$v){
//查询采购
$purchase = $PcbPurchaseModel->where("order_id",$v['order_id'])->first();
$v['tiaojia']=$v['purchase_amount'] = $v['purchase_sn'] = "";
if ($purchase){
if ( $purchase['purchase_amount'] > 0 && $purchase['purchase_amount'] != $v['order_amount']){
$v['tiaojia'] = "是";
}elseif($purchase['purchase_amount'] == 0){
$v['tiaojia'] = "";
}else{
$v['tiaojia'] = "否";
}
$v['purchase_amount'] = $purchase['purchase_amount'] > 0 ? $purchase['purchase_amount'] : "";
$v['purchase_sn'] = $purchase['purchase_sn'];
}
//查询支付
$v['order_pay_type'] = $PcbPublicModel->getPay($v['order_id']);
$v['order_type'] = PcbOrderMap::$order_type[$v['order_type']];
$v['status_name'] = PcbOrderMap::$status[$v['status']];
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
$v['pay_time'] = $v['pay_time'] > 0 ? date('Y-m-d H:i:s',$v['pay_time']) : "";
$shipping = $con->table('shipping')->where(['relevance_id' => $v['order_id'],'shipping_type'=>1])->first();
$v['shipping_no'] = $shipping ? $shipping->shipping_no : "";
$v['shipping_name'] = $shipping ? $shipping->shipping_name : "";
$userCompany = DB::connection('order')->table("lie_user_company")->where("user_id",$v['user_id'])->first();
$v['company_name'] = $userCompany ? $userCompany->com_name : "" ;
}
return $data;
}
//导出
public function export()
{
$data = $this->getList(2);
$column = array('ID','会员账号','交易订单编号','采购订单编号','是否调价','订单金额','调整后订单金额','订单状态','订单类型','支付方式','下单时间'); // 表头
$fileName = 'PCB交易订单列表导出'.date('YmdHis', time()).'.csv';
$temp = [];
foreach ($data as $k=>$v){
array_push($temp,[
'order_id'=>$v['order_id'],
'user_account' =>$v['user_account']."\n",
'order_sn' =>$v['order_sn']."\n",
'purchase_sn' =>@$v['purchase_sn']."\n",
'tiaojia' =>$v['tiaojia'],
'order_amount' =>$v['order_amount'],
'purchase_amount' =>$v['purchase_amount'],
'status_name' =>$v['status_name'],
'order_type' =>$v['order_type'],
'order_pay_type' =>$v['order_pay_type'],
'create_time' =>$v['create_time'],
]);
}
export_csv($temp, $column, $fileName);
}
<?php
namespace App\Model\Pcb;
use App\Map\PcbOrderMap;
use App\Model\UserMainModel;
use App\Model\UserCompanyModel;
use Illuminate\Database\Eloquent\Model;
use Request;
use DB;
class PcbOrderModel extends Model
{
protected $connection='pcb';
protected $table='order';
protected $primaryKey='id';
public $timestamps = false;
//列表
public function getList($type =1)
{
$arr = ['p', 'limit','self','start_time','end_time','status',"user_account","order_sn","purchase_sn","order_type","adtag","ptag","test_order"];
$input = Request::only($arr);
$input=TrimX($input,true,$arr);
//查询数据\
$list = $this->where(function ($query) use ($input) {
$PcbPurchaseModel = new PcbPurchaseModel();
foreach ($input as $k => $v){
$v = trim($v);
switch ($k){
case "p":
case "limit":
case "_url":
case "test_order":
continue;
break;
case "start_time":
$query->where('create_time', '>=', strtotime($v));
break;
case "end_time":
$query->where('create_time', '<=',strtotime($v));
break;
case "end_time":
$query->where('create_time', '<=',strtotime($v));
break;
case "purchase_sn":
$items = $PcbPurchaseModel->select("order_id")->where("purchase_sn","like","%".$v."%")->get();
if ($items->count()){
$orderIds = arrayToCommaStr($items->toArray(),'order_id',1);
$query->whereIn("order_id",$orderIds);
}else{
$query->where("order_id",0);
}
break;
default:
$query->whereIn($k, explode(',',trim($v,',')));
break;
}
}
})->orderBy('order_id','desc');
if (empty($input['test_order'])){ //排除测试账号
$testMobile = (new UserMainModel())->testMobile();
$list->whereNotIn('user_id', $testMobile);
}
//getSql();
if ($type == 1){
$input['limit'] = 10;
$input['p'] = isset($input['p']) ? $input['p'] : 1;
$list = $list->paginate($input['limit'], ['*'], 'p', $input['p'])->toArray();
if (!$list) return [20001, '没有数据'];
$data = $this->clearData($list['data']);
return [0, '成功', $data, $list['total']];
}else{
return $this->clearData($list->get()->toArray());
}
}
//清洗列表数据
private function clearData($data){
if (!is_array($data) || count($data) == 0 || $data == ""){
return [];
}
$PcbPurchaseModel = new PcbPurchaseModel();
$PcbPublicModel = new PcbPublicModel();
$con = DB::connection("pcb");
foreach ($data as $k=>&$v){
//查询采购
$purchase = $PcbPurchaseModel->where("order_id",$v['order_id'])->first();
$v['tiaojia']=$v['purchase_amount'] = $v['purchase_sn'] = "";
if ($purchase){
if ( $purchase['purchase_amount'] > 0 && $purchase['purchase_amount'] != $v['order_amount']){
$v['tiaojia'] = "是";
}elseif($purchase['purchase_amount'] == 0){
$v['tiaojia'] = "";
}else{
$v['tiaojia'] = "否";
}
$v['purchase_amount'] = $purchase['purchase_amount'] > 0 ? $purchase['purchase_amount'] : "";
$v['purchase_sn'] = $purchase['purchase_sn'];
}
//查询支付
$v['order_pay_type'] = $PcbPublicModel->getPay($v['order_id']);
$v['order_type'] = PcbOrderMap::$order_type[$v['order_type']];
$v['status_name'] = PcbOrderMap::$status[$v['status']];
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
$v['pay_time'] = $v['pay_time'] > 0 ? date('Y-m-d H:i:s',$v['pay_time']) : "";
$shipping = $con->table('shipping')->where(['relevance_id' => $v['order_id'],'shipping_type'=>1])->first();
$v['shipping_no'] = $shipping ? $shipping->shipping_no : "";
$v['shipping_name'] = $shipping ? $shipping->shipping_name : "";
$userCompany = UserCompanyModel::where("user_id",$v['user_id'])->first();
$v['company_name'] = $userCompany ? $userCompany->com_name : "" ;
}
return $data;
}
//导出
public function export()
{
$data = $this->getList(2);
$column = array('ID','会员账号','交易订单编号','采购订单编号','是否调价','订单金额','调整后订单金额','订单状态','订单类型','支付方式','下单时间'); // 表头
$fileName = 'PCB交易订单列表导出'.date('YmdHis', time()).'.csv';
$temp = [];
foreach ($data as $k=>$v){
array_push($temp,[
'order_id'=>$v['order_id'],
'user_account' =>$v['user_account']."\n",
'order_sn' =>$v['order_sn']."\n",
'purchase_sn' =>@$v['purchase_sn']."\n",
'tiaojia' =>$v['tiaojia'],
'order_amount' =>$v['order_amount'],
'purchase_amount' =>$v['purchase_amount'],
'status_name' =>$v['status_name'],
'order_type' =>$v['order_type'],
'order_pay_type' =>$v['order_pay_type'],
'create_time' =>$v['create_time'],
]);
}
export_csv($temp, $column, $fileName);
}
}
\ No newline at end of file
......@@ -209,7 +209,7 @@
</dd>
</dl>
@endif
<dl>
<!-- <dl>
<dt>用户标签:</dt>
<dd>
<select id="is_new" name="is_new" class="form-control is_new selectpicker" title="全部">
......@@ -219,7 +219,7 @@
<option value="2">老客户</option>
</select>
</dd>
</dl>
</dl> -->
@endif
<dl>
......
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