Browse Source

【Add】下载用户表增加积分字段

liuxiangxin 2 tháng trước cách đây
mục cha
commit
4a94424e77

+ 30 - 67
app/Http/Controllers/Admin/Custom.php

@@ -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;
-	}
-
 }

+ 0 - 2
resources/views/admin/custom/index.blade.php

@@ -3,7 +3,6 @@
 style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 @endsection
 @section('content')
-@if( check_auth('admin/orders/import_execl') )
 <div class="page-header">
 	@if( check_auth('admin/custom/import_execl') )
 	<a href="javascript:;" class="btn btn-primary upload"> <span class="fa fa-upload"></span> 导入客户信息</a>
@@ -18,7 +17,6 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	<a href="/uploads/weiban_score_tpl.xlsx" class="btn btn-primary" download="积分批量导入模版"> <span class="fa fa-download"></span> 微伴模版</a>
 	@endif
 </div>
-@endif
 <form action="" method="get" name="thisform" class="form-horizontal form-line">
 	<div class="form-group col col-lg-2 col-md-4 col-sm-6 col-xs-12" style="margin-right: 2px;">
 		<input type="text" class="form-control" name="custom_code" value="{{request('custom_code','')}}" placeholder="请输入客户编码查询" />