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 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,'审核成功'];
}
}
......@@ -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