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