|
@@ -5,13 +5,7 @@ use App\Models\City;
|
|
|
use App\Models\Custom as Custom;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use App\Models\WeiBan\Follow as WeiBanFollow;
|
|
|
-use App\Models\FilesManager;
|
|
|
-use App\Models\WeiBan\External as WeiBanExternal;
|
|
|
use App\Models\CustomClockinRecord as Model;
|
|
|
-use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
-use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
-use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
-use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
|
|
|
|
/**
|
|
|
* 客户签到记录
|
|
@@ -31,7 +25,7 @@ class CustomClockinRecord extends Auth{
|
|
|
* 列表页
|
|
|
*
|
|
|
* */
|
|
|
- public function index(Model $Model,Custom $Custom,CustomScore $CustomScore,WeiBanFollow $WeiBanFollow,City $City){
|
|
|
+ public function index(Model $Model,Custom $Custom,WeiBanFollow $WeiBanFollow,City $City){
|
|
|
// 接受参数
|
|
|
$code = request('custom_code','');
|
|
|
$phone = request('phone','');
|
|
@@ -188,7 +182,7 @@ class CustomClockinRecord extends Auth{
|
|
|
* 导出表格
|
|
|
*
|
|
|
* */
|
|
|
- public function down_excel(Model $Model,Custom $Custom,CustomScore $CustomScore,WeiBanFollow $WeiBanFollow,City $City){
|
|
|
+ public function down_excel(Model $Model,Custom $Custom,WeiBanFollow $WeiBanFollow,City $City){
|
|
|
// 接受参数
|
|
|
$code = request('custom_code','');
|
|
|
$phone = request('phone','');
|
|
@@ -197,6 +191,7 @@ class CustomClockinRecord extends Auth{
|
|
|
$cityId = request('city_id',0);
|
|
|
$status = request('status');
|
|
|
$startTime = request('start_time','');
|
|
|
+ $endTime = request('end_time','');
|
|
|
// 编码转ID
|
|
|
$uid = $Custom->codeToId($code);
|
|
|
// 查询条件
|
|
@@ -208,17 +203,17 @@ class CustomClockinRecord extends Auth{
|
|
|
if( $cityId ) $map[] = ['custom.city_id','=',$cityId];
|
|
|
if( $activeName ) $map[] = ['score_clockin_active.name','=',$activeName];
|
|
|
if( $startTime ) $map[] = ['custom_clockin_record.insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
|
|
|
- if( $startTime ) $map[] = ['custom_clockin_record.nsert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
|
|
|
+ if( $endTime ) $map[] = ['custom_clockin_record.insert_time','<=',Carbon::createFromFormat('Y-m-d',$endTime)->endOfDay()->getTimestamp()];
|
|
|
if( !is_null($status) ) $map[] = ['custom_clockin_record.status','=',$status];
|
|
|
// 查询数据
|
|
|
$list = $Model->query()
|
|
|
- ->leftJoin('custom','custom.uid','=','custom_clockin_record.custom_uid')
|
|
|
- ->leftJoin('score_clockin_active','score_clockin_active.id','=','custom_clockin_record.active_id')
|
|
|
- ->where($map)
|
|
|
- ->select(['custom.*','score_clockin_active.name as active_name','custom_clockin_record.*'])
|
|
|
- ->orderByDesc('custom_clockin_record.id')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
+ ->leftJoin('custom','custom.uid','=','custom_clockin_record.custom_uid')
|
|
|
+ ->leftJoin('score_clockin_active','score_clockin_active.id','=','custom_clockin_record.active_id')
|
|
|
+ ->where($map)
|
|
|
+ ->select(['custom.*','score_clockin_active.name as active_name','custom_clockin_record.*'])
|
|
|
+ ->orderByDesc('custom_clockin_record.id')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
// 循环处理数据
|
|
|
foreach ($list as $key => $value) {
|
|
|
// 城市名
|
|
@@ -232,6 +227,19 @@ class CustomClockinRecord extends Auth{
|
|
|
// 如果存在的话,修正
|
|
|
if( $value['weiban_extid'] ) $Model->edit($value['uid'],['weiban_extid'=>$value['weiban_extid']]);
|
|
|
}
|
|
|
+ // 重构数据
|
|
|
+ $value = [
|
|
|
+ 'id'=>$value['id'],
|
|
|
+ 'active_id'=>$value['active_id'],
|
|
|
+ 'active_name'=>$value['active_name'],
|
|
|
+ 'custom_code'=>$value['custom_code'],
|
|
|
+ 'username'=>$value['username'],
|
|
|
+ 'phone'=>(string)$value['phone'],
|
|
|
+ 'clockin_day'=> $value['clockin_day'],
|
|
|
+ 'clockin_time'=>date('Y-m-d H:i:s',$value['clockin_time']),
|
|
|
+ 'city_name'=>$value['city_name'],
|
|
|
+ 'weiban_extid'=>$value['weiban_extid'],
|
|
|
+ ];
|
|
|
// 重组
|
|
|
$list[$key] = $value;
|
|
|
}
|
|
@@ -248,72 +256,19 @@ class CustomClockinRecord extends Auth{
|
|
|
* 去下载
|
|
|
*/
|
|
|
private function toDown($data){
|
|
|
- // 创建新的电子表格对象
|
|
|
- $spreadsheet = new Spreadsheet();
|
|
|
- // 设置合并单元格的行和列,例如合并A1到B2的单元格
|
|
|
- $sheet = $this->setStyle($spreadsheet);
|
|
|
- // 从第二行写入
|
|
|
- $row = 2;
|
|
|
- // 循环写入
|
|
|
- foreach ($data as $key => $value) {
|
|
|
-
|
|
|
- // 单元格内容写入
|
|
|
- $sheet->setCellValue('A'.$row, $value['id']);
|
|
|
- $sheet->setCellValue('B'.$row, $value['custom_code']);
|
|
|
- $sheet->setCellValue('C'.$row, $value['username']);
|
|
|
- $sheet->setCellValue('D'.$row, $value['active_name']);
|
|
|
- $sheet->setCellValue('E'.$row, $value['phone']);
|
|
|
- $sheet->setCellValue('F'.$row, $value['weiban_extid']);
|
|
|
- $sheet->setCellValue('G'.$row, $value['city_name']);
|
|
|
- $sheet->setCellValue('H'.$row, date('Y-m-d H:i:s',$value['clockin_time']));
|
|
|
- $sheet->setCellValue('I'.$row, $value['clockin_day']);
|
|
|
- $row++;
|
|
|
- }
|
|
|
- //
|
|
|
- // 创建内容
|
|
|
- $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
|
- header('Pragma: public');
|
|
|
- header('Content-type:application/vnd.ms-excel');
|
|
|
- header('Content-Disposition: inline;filename=下载打卡记录.xlsx');
|
|
|
- // 输出数据流
|
|
|
- return $writer->save('php://output');
|
|
|
- }
|
|
|
- /**
|
|
|
- * 设置表格样式
|
|
|
- *
|
|
|
- */
|
|
|
- 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(15);
|
|
|
- $sheet->getColumnDimension('E')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('F')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('G')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('H')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('I')->setWidth(15);
|
|
|
- $sheet->getColumnDimension('J')->setWidth(15);
|
|
|
- // 默认高度
|
|
|
- $sheet->getDefaultRowDimension()->setRowHeight(18);
|
|
|
- // 加粗第一行
|
|
|
- $sheet->getStyle('A:S')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
|
|
|
- $sheet->getStyle('A1:S1')->getFont()->setBold(true);
|
|
|
- $sheet->getStyle('A1:S1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00'); // ARGB颜色代码,例如绿色
|
|
|
- // 设置表格标题
|
|
|
- $sheet
|
|
|
- ->setCellValue('A1', '记录ID')
|
|
|
- ->setCellValue('B1', '客户编码')
|
|
|
- ->setCellValue('C1', '客户昵称')
|
|
|
- ->setCellValue('D1', '活动名称')
|
|
|
- ->setCellValue('E1', '联系方式')
|
|
|
- ->setCellValue('F1', '微伴ID')
|
|
|
- ->setCellValue('G1', '客户城市')
|
|
|
- ->setCellValue('H1', '打卡时间')
|
|
|
- ->setCellValue('I1', '连续打卡天数');
|
|
|
- // 返回结果
|
|
|
- return $sheet;
|
|
|
+ // xlsx文件保存路径
|
|
|
+ $excel = new \Vtiful\Kernel\Excel(['path' =>public_path().'/uploads/']);
|
|
|
+ $filePath = $excel->fileName(uniqid().'.xlsx', 'sheet1')->header(['记录ID','活动ID','活动名称','客户编码','客户昵称','联系方式','打卡天数','打卡时间','城市名称','微伴ID'])->data($data)->output();
|
|
|
+ header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ header('Content-Disposition: attachment;filename="打卡记录'.date('Y-m-d His').'.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);
|
|
|
}
|
|
|
}
|