浏览代码

【Add】红包余额记录的下载功能

liuxiangxin 4 月之前
父节点
当前提交
ff69ab3e1b

+ 87 - 9
app/Http/Controllers/Admin/AmountRecord.php

@@ -52,8 +52,9 @@ class AmountRecord extends Auth{
 		// 循环处理数据
 		foreach ($list as $key => $value) {
 			// id转编号
-			$value['custom_code'] 	= $Custom->idToCode($value['custom_uid']);
-            $value['buy_type']      = $Model->getBuyType($value['buy_type'],'name');
+			$value['custom_code'] 	= (string) $Custom->idToCode($value['custom_uid']);
+			$value['custom_name'] 	= (string) $Custom->getValue($value['custom_uid'],'username');
+            $value['buy_type']      = (string) $Model->getBuyType($value['buy_type'],'name');
 			// 重组
 			$list[$key]				= $value;
 		}
@@ -64,12 +65,89 @@ class AmountRecord extends Auth{
 		return 						$this->fetch();
     }
 
-    /**
-     * 导出表格
-     *
-     * */
-    public function down_excel(Model $Model,Custom $Custom){
-        
 
-    }
+	/**
+	 * 导出表格
+	 * 
+	 * */
+	public function down_excel(Model $Model,Custom $Custom){
+		// 接受参数
+		$code					= request('custom_code','');
+		$phone					= request('phone','');
+		$username				= request('username','');
+		$status					= request('status');
+		$startTime				= request('start_time','');
+		$endTime				= request('end_time','');
+		// 编码转ID
+		$uid					= $Custom->codeToId($code);
+		// 查询条件
+		$map 					= [];
+		// 编码ID
+		if( $uid )				$map[] = ['custom.uid','=',$uid];
+		if( $phone )			$map[] = ['custom.phone','=',$phone];
+		if( $username )			$map[] = ['custom.username','=',$username];
+		if( $startTime )		$map[] = ['amount_record.insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
+		if( $endTime )		    $map[] = ['amount_record.insert_time','<=',Carbon::createFromFormat('Y-m-d',$endTime)->endOfDay()->getTimestamp()];
+		if( !is_null($status) )	$map[] = ['amount_record.status','=',$status];
+		// 查询数据
+		$list					= $Model->query()
+                                    ->leftJoin('custom','custom.uid','=','amount_record.custom_uid')
+                                    ->where($map)
+                                    ->select([
+										'amount_record.id',
+										'amount_record.out_bill_no',
+										'amount_record.transfer_bill_no',
+										'amount_record.prefix',
+										'amount_record.amount',
+										'amount_record.balance',
+										'amount_record.description',
+										'amount_record.buy_type',
+										'amount_record.status',
+										'amount_record.payment_time',
+										'amount_record.insert_time',
+										'amount_record.custom_uid',
+										'custom.username as custom_name',
+									])
+                                    ->orderByDesc('amount_record.id')
+                                    ->limit(10000)->get()->toArray();
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// 加减
+			$value['amount'] 		= "'".($value['prefix'] == 1 ? '+'  : '-').$value['amount'];
+			// id转编号
+			$value['custom_uid'] 	= (string) $Custom->idToCode($value['custom_uid']);
+			// id转编号
+            $value['buy_type']      = (string) $Model->getBuyType($value['buy_type'],'name');
+			// 时间
+			$value['payment_time'] 	= $value['payment_time'] ? date('Y-m-d H:i:s',$value['payment_time']) : '';
+			// id转编号
+			$value['insert_time'] 	= $value['insert_time'] ? date('Y-m-d H:i:s',$value['insert_time']) : '';
+			// 删除符号字段
+			unset($value['prefix']);
+			// 重组
+			$list[$key]				= $value;
+		}
+		// 去下载
+		$this->toDown($list);
+	}
+
+	/**
+	 * 去下载
+	 */
+	private function  toDown($data){
+		// xlsx文件保存路径
+		$excel      		= new \Vtiful\Kernel\Excel(['path' =>public_path().'/uploads/']);
+		$filePath 			= $excel->fileName('tutorial01.xlsx', 'sheet1')->header(['记录ID','系统编号','第三方编号','变动金额','剩余金额','交易描述','交易类型','交易状态','支付时间','交易时间','客户编码','客户昵称'])->data($data)->output();
+		header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+		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');
+		header('Pragma: public');
+		ob_clean();
+		flush();
+		// 输出文件,成功删除文件路径
+		if ( copy($filePath, 'php://output') )  @unlink($filePath);
+	}
 }

+ 80 - 3
app/Http/Controllers/Admin/CustomRedpacket.php

@@ -26,7 +26,7 @@ class CustomRedpacket extends Auth{
 	 * */
     public function index(Model $Model,Custom $Custom,AdminUser $AdminUser){
 		// 接受参数
-		$redpacketId			= request('redpacket_id','');
+		$name					= request('name','');
 		$customCode				= request('custom_code','');
 		$startTime				= request('start_time','');
 		$endTime				= request('end_time','');
@@ -36,7 +36,7 @@ class CustomRedpacket extends Auth{
 		// 查询条件
 		$map 					= [];
 		// 编码ID
-		if( $redpacketId )		$map[] = ['redpacket.id','=',$redpacketId];
+		if( $name )				$map[] = ['redpacket.name','=',$name];
 		if( $customUid )		$map[] = ['custom_redpacket.custom_uid','=',$customUid];
 		if( $startTime )		$map[] = ['custom_redpacket.insert_time','>=',strtotime($startTime)];
 		if( $endTime )			$map[] = ['custom_redpacket.insert_time','<=',strtotime($endTime)];
@@ -171,6 +171,83 @@ class CustomRedpacket extends Auth{
 		return			json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
 	}
 	
-	
+	/**
+	 * 导出表格
+	 * 
+	 * */
+	public function down_excel(Model $Model,Custom $Custom,AdminUser $AdminUser){
+		// 接受参数
+		$name					= request('name','');
+		$customCode				= request('custom_code','');
+		$startTime				= request('start_time','');
+		$endTime				= request('end_time','');
+		$status					= request('status');
+		// 编码转ID
+		$customUid				= $customCode ? $Custom->codeToId($customCode) : 0;
+		// 查询条件
+		$map 					= [];
+		// 编码ID
+		if( $name )				$map[] = ['redpacket.name','=',$name];
+		if( $customUid )		$map[] = ['custom_redpacket.custom_uid','=',$customUid];
+		if( $startTime )		$map[] = ['custom_redpacket.insert_time','>=',strtotime($startTime)];
+		if( $endTime )			$map[] = ['custom_redpacket.insert_time','<=',strtotime($endTime)];
+		if( !is_null($status) )	$map[] = ['custom_redpacket.status','=',$status];
+		// 查询数据
+		$list					= $Model->query()->join('redpacket','custom_redpacket.redpacket_id','=','redpacket.id')->where($map)
+									->orderBy('custom_redpacket.status')
+									->orderByDesc('custom_redpacket.id')
+									->select([
+										'custom_redpacket.id',
+										'custom_redpacket.redpacket_id',
+										'custom_redpacket.money',
+										'custom_redpacket.status',
+										'custom_redpacket.get_time',
+										'redpacket.name as redpacket_name',
+										'redpacket.start_time',
+										'redpacket.end_time',
+										'custom_redpacket.admin_uid',
+										'custom_redpacket.custom_uid',
+										])
+									->limit(10000)->get()->toArray();
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// id转编号
+			$value['custom_code'] 	= (string)$Custom->idToCode($value['custom_uid']);
+			// id转编号
+			$value['custom_uid'] 	= (string)$Custom->getValue($value['custom_uid'],'username');
+			// 操作人员
+			$value['admin_uid']  	= (string)$AdminUser->getOne($value['admin_uid'],'username');
+			// 时间
+			$value['get_time'] 		= $value['get_time'] ? date('Y-m-d H:i:s',$value['get_time']) : '';
+			// id转编号
+			$value['start_time'] 	= $value['start_time'] ? date('Y-m-d H:i:s',$value['start_time']) : '';
+			// id转编号
+			$value['end_time']  	= $value['end_time'] ? date('Y-m-d H:i:s',$value['end_time']) : '';
+			// 重组
+			$list[$key]				= $value;
+		}
+		// 去下载
+		$this->toDown($list);
+	}
+
+	/**
+	 * 去下载
+	 */
+	private function  toDown($data){
+		// xlsx文件保存路径
+		$excel      		= new \Vtiful\Kernel\Excel(['path' =>public_path().'/uploads/']);
+		$filePath 			= $excel->fileName('tutorial01.xlsx', 'sheet1')->header(['记录ID','活动ID','红包金额','领取状态','领取时间','活动名称','开始时间','结束时间','操作人员','客户昵称','客户编码'])->data($data)->output();
+		header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+		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');
+		header('Pragma: public');
+		ob_clean();
+		flush();
+		// 输出文件,成功删除文件路径
+		if ( copy($filePath, 'php://output') )  @unlink($filePath);
+	}
 
 }

+ 2 - 0
app/Http/Controllers/Admin/Product.php

@@ -738,6 +738,8 @@ class Product extends Auth{
 			$cityIds				= $cityIds ? $cityIds : [1];
 			$data['quota_start']	= $data['quota_start'] ? strtotime($data['quota_start']) : 0;
 			$data['quota_end']		= $data['quota_end'] ? strtotime($data['quota_end']) : 0;
+			$data['puton_time']		= $data['puton_time'] ? strtotime($data['puton_time']) : 0;
+			$data['putoff_time']	= $data['putoff_time'] ? strtotime($data['putoff_time']) : 0;
 			// 限购提示
 			if( !$data['thumb'] ) 	return json_send(['code'=>'error','msg'=>'请上传产品主图','data'=>['error'=>'请上传产品主图']]);
 			// 限购提示

+ 2 - 2
resources/views/admin/amount_record/index.blade.php

@@ -48,10 +48,10 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 							<th>{{$a['id']}}</th>
 							<th>{{$a['custom_code']}}</th>
 							<th>{{$a['custom_name']}}</th>
-							<th>{{$a['amount']}}</th>
+							<th> {{$a['prefix']==1?'+':'-'}} {{$a['amount']}}</th>
 							<td>{{$a['balance']}}</td>
-							<td>{{$a['status']}}</td>
 							<td>{{$a['buy_type']}}</td>
+							<td>{{$a['status']}}</td>
 							<td> {{date('Y/m/d H:i:s',$a['update_time'])}}</td>
 							<td></td>
 						</tr>  

+ 9 - 4
resources/views/admin/custom_redpacket/index.blade.php

@@ -8,9 +8,9 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	<!-- <a href="{{url('admin/custom_redpacket/add')}}" class="btn btn-primary">新增</a> -->
 	@endif
 </div>
-<form action="" method="get" class="form-horizontal form-line">
+<form action="" method="get" class="form-horizontal form-line" name="thisform" >
 	<div class="form-group col col-md-1" style="margin-right: 2px;">
-		<input type="text" class="form-control" name="redpacket_name" value="{{request('redpacket_name','')}}" placeholder="请输入活动名称查询" />
+		<input type="text" class="form-control" name="name" value="{{request('name','')}}" placeholder="请输入活动名称查询" />
 	</div>
 	<div class="form-group col col-md-1" style="margin-right: 2px;">
 		<input type="text" class="form-control" name="custom_code" value="{{request('custom_code','')}}" placeholder="请输入客户编码查询" />
@@ -31,8 +31,13 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 	<div class="form-group col col-md-1" style="margin-right: 2px;">
 		<input type="text" class="form-control" name="end_time" value="{{request('end_time','')}}" placeholder="请输入结束时间查询" />
 	</div>
-	<input type="submit" class="btn btn-sm btn-primary" value="查询"/>
-	<a href="{{url('admin/custom_redpacket/index')}}" class="btn btn-sm btn-default" >重置</a>
+	<div class="form-group col col-xs-4 col-md-2" style="margin-right: 2px;">
+		<button type="button" onclick="alter_from_attr({'method':'get','action':''})" class="btn btn-sm btn-primary" style="margin-right: 20px;"> 查询</button>
+		<a href="{{url('admin/custom_redpacket/index')}}" class="btn btn-sm btn-default" style="margin-right: 20px;" >重置</a>
+		@if( check_auth('admin/custom_redpacket/down_excel') )
+		<button type="button" onclick="alter_from_attr({'method':'get','action':`{{url('admin/custom_redpacket/down_excel')}}`})" class="btn btn-sm btn-primary"> 下载表格</button>
+		@endif
+	</div>
 </form>
 <div class="row">
 	<div class="col-xs-12">

+ 4 - 2
routes/web.php

@@ -560,10 +560,12 @@ Route::middleware('admin')->prefix('admin')->group(function(){
     Route::any('custom_redpacket/edit',[App\Http\Controllers\Admin\CustomRedpacket::class,'edit']);
     // 状态
     Route::any('custom_redpacket/set_status',[App\Http\Controllers\Admin\CustomRedpacket::class,'set_status']);
-
+    // 状态
+    Route::any('custom_redpacket/down_excel',[App\Http\Controllers\Admin\CustomRedpacket::class,'down_excel']);
 
     /* 余额记录 */
     // 余额
     Route::any('amount_record/index',[App\Http\Controllers\Admin\AmountRecord::class,'index']);
-
+    // 状态
+    Route::any('amount_record/down_excel',[App\Http\Controllers\Admin\AmountRecord::class,'down_excel']);
 });