|
@@ -270,22 +270,32 @@ class Custom extends Auth{
|
|
|
// 查询条件
|
|
|
$map = [];
|
|
|
// 编码ID
|
|
|
- if( $uid ) $map[] = ['uid','=',$uid];
|
|
|
- if( $phone ) $map[] = ['phone','=',$phone];
|
|
|
- if( $username ) $map[] = ['username','=',$username];
|
|
|
- if( $cityId ) $map[] = ['city_id','=',$cityId];
|
|
|
- if( $weibanId ) $map[] = ['weiban_extid','=',$weibanId];
|
|
|
- if( $startTime ) $map[] = ['insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
|
|
|
- if( $startTime ) $map[] = ['insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
|
|
|
- if( !is_null($status) ) $map[] = ['status','=',$status];
|
|
|
+ if( $uid ) $map[] = ['custom.uid','=',$uid];
|
|
|
+ if( $phone ) $map[] = ['custom.phone','=',$phone];
|
|
|
+ if( $username ) $map[] = ['custom.username','=',$username];
|
|
|
+ if( $cityId ) $map[] = ['custom.city_id','=',$cityId];
|
|
|
+ if( $weibanId ) $map[] = ['custom.weiban_extid','=',$weibanId];
|
|
|
+ if( $startTime ) $map[] = ['custom.insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
|
|
|
+ if( $startTime ) $map[] = ['custom.insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
|
|
|
+ if( !is_null($status) ) $map[] = ['custom.status','=',$status];
|
|
|
// 查询数据
|
|
|
- $list = $Model->query()->where($map)->orderByDesc('uid')->get()->toArray();
|
|
|
+ $list = $Model->query()
|
|
|
+ ->join('custom_score','custom.uid','=','custom_score.custom_uid','LEFT')
|
|
|
+ ->where($map)->orderByDesc('uid')
|
|
|
+ ->get(['custom.uid as custom_code','custom.username','custom.phone','custom_score.score','custom_score.use_score','custom.status','custom.weiban_extid','custom.city_id','custom.insert_time','custom.update_time'])
|
|
|
+ ->toArray();
|
|
|
// 循环处理数据
|
|
|
foreach ($list as $key => $value) {
|
|
|
- // 城市名
|
|
|
- $value['city_name'] = $value['city_id'] ? $City->getOne($value['city_id'],'name') : '';
|
|
|
// id转编号
|
|
|
- $value['custom_code'] = $Model->idToCode($value['uid']);
|
|
|
+ $value['custom_code'] = $Model->idToCode($value['custom_code']);
|
|
|
+ $value['username'] = $value['username'];
|
|
|
+ $value['phone'] = $value['phone'];
|
|
|
+ $value['status'] = $value['status']?'禁用':'正常';
|
|
|
+ $value['weiban_extid'] = $value['weiban_extid'];
|
|
|
+ $value['city_name'] = $value['city_id'] ? $City->getOne($value['city_id'],'name') : '';
|
|
|
+ $value['city_name'] = $value['city_name'];
|
|
|
+ $value['insert_time'] = date('Y-m-d H:i:s',$value['insert_time']);
|
|
|
+ $value['update_time'] = date('Y-m-d H:i:s',$value['update_time']);
|
|
|
// 重组
|
|
|
$list[$key] = $value;
|
|
|
}
|
|
@@ -301,18 +311,6 @@ class Custom extends Auth{
|
|
|
* 去下载
|
|
|
*/
|
|
|
private function toDown($data){
|
|
|
- $list = [];
|
|
|
- foreach ($data as $key=>$value) {
|
|
|
- // 单元格内容写入
|
|
|
- $list[$key]['custom_code'] = $value['custom_code'];
|
|
|
- $list[$key]['username'] = $value['username'];
|
|
|
- $list[$key]['phone'] = $value['phone'];
|
|
|
- $list[$key]['weiban_extid'] = $value['weiban_extid'];
|
|
|
- $list[$key]['city_name'] = $value['city_name'];
|
|
|
- $list[$key]['status'] = $value['status']?'禁用':'正常';
|
|
|
- $list[$key]['insert_time'] = date('Y-m-d H:i:s',$value['insert_time']);
|
|
|
- $list[$key]['update_time'] = date('Y-m-d H:i:s',$value['update_time']);
|
|
|
- }
|
|
|
try {
|
|
|
$config = [
|
|
|
'path' =>public_path().'/uploads/' // xlsx文件保存路径
|
|
@@ -322,20 +320,21 @@ class Custom extends Auth{
|
|
|
'客户编码',
|
|
|
'客户昵称',
|
|
|
'联系方式',
|
|
|
- '微伴ID',
|
|
|
- '客户城市',
|
|
|
+ '剩余积分',
|
|
|
+ '已用积分',
|
|
|
'客户状态',
|
|
|
+ '微伴ID',
|
|
|
+ '客户城市',
|
|
|
'创建时间',
|
|
|
'更新时间',
|
|
|
];
|
|
|
- $filePath = $excel->fileName('user01.xlsx', 'sheet1')
|
|
|
+ $filePath = $excel->fileName(uniqid().'.xlsx', 'sheet1')
|
|
|
->header($header)
|
|
|
- ->data($list)
|
|
|
+ ->data($data)
|
|
|
->output();
|
|
|
- $filename = '客户列表.xlsx';
|
|
|
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
- header('Content-Disposition: attachment;filename="' . $filename . '"');
|
|
|
- header('Content-Length: ' . filesize($filePath));
|
|
|
+ header('Content-Disposition: attachment;filename="客户列表.xlsx"');
|
|
|
+ header('Content-Length: '.filesize($filePath));
|
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
header('Cache-Control: must-revalidate');
|
|
|
header('Cache-Control: max-age=0');
|
|
@@ -352,40 +351,4 @@ class Custom extends Auth{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 设置表格样式
|
|
|
- *
|
|
|
- */
|
|
|
- private function setStyle(Spreadsheet $spreadsheet){
|
|
|
- // 选择当前活动的工作表
|
|
|
- $sheet = $spreadsheet->getActiveSheet();
|
|
|
- // 宽
|
|
|
- $sheet->getColumnDimension('A')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('B')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('C')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('D')->setWidth(30);
|
|
|
- $sheet->getColumnDimension('E')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('F')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('G')->setWidth(20);
|
|
|
- $sheet->getColumnDimension('H')->setWidth(20);
|
|
|
- // 默认高度
|
|
|
- $sheet->getDefaultRowDimension()->setRowHeight(18);
|
|
|
- // 加粗第一行
|
|
|
- $sheet->getStyle('A:H')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
|
|
|
- $sheet->getStyle('A1:H1')->getFont()->setBold(true);
|
|
|
- $sheet->getStyle('A1:H1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
|
|
|
- // 设置表格标题
|
|
|
- $sheet
|
|
|
- ->setCellValue('A1', '客户编码')
|
|
|
- ->setCellValue('B1', '客户昵称')
|
|
|
- ->setCellValue('C1', '联系方式')
|
|
|
- ->setCellValue('D1', '微伴ID')
|
|
|
- ->setCellValue('E1', '客户城市')
|
|
|
- ->setCellValue('F1', '客户状态')
|
|
|
- ->setCellValue('G1', '创建时间')
|
|
|
- ->setCellValue('H1', '更新时间');
|
|
|
- // 返回结果
|
|
|
- return $sheet;
|
|
|
- }
|
|
|
-
|
|
|
}
|