Forráskód Böngészése

打卡记录的下载

jun 6 hónapja
szülő
commit
ea34b12803

+ 137 - 49
app/Http/Controllers/Admin/CustomClockinRecord.php

@@ -8,6 +8,10 @@ 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;
 
 /**
  * 客户签到记录
@@ -32,7 +36,7 @@ class CustomClockinRecord extends Auth{
 		$code					= request('custom_code','');
 		$phone					= request('phone','');
 		$username				= request('username','');
-		$weibanId				= request('weiban_extid','');
+		$activeName				= request('active_name','');
 		$cityId					= request('city_id',0);
 		$status					= request('status');
 		$startTime				= request('start_time','');
@@ -45,7 +49,7 @@ class CustomClockinRecord extends Auth{
 		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( $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( !is_null($status) )	$map[] = ['custom_clockin_record.status','=',$status];
@@ -179,52 +183,136 @@ class CustomClockinRecord extends Auth{
 		return 				json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
 	}
 
-	/**
-	 * 表格导入
-	 * 
-	 * */
-	public function import_execl( Request $request,Model $Model,FilesManager $FilesManager,City $City,CustomAddr $CustomAddr,WeiBanExternal $WeiBanExternal){
-		// 验证参数
-		$request->scene('import_execl')->validate();
-		// 获取表格信息
-		$file								= request()->file('custom_file');
-		// 返回结果
-		$sheetList							= $FilesManager->excelToCustom($file);
-		// 如果不存在结果
-		if( isset($sheetList['error']) )	return json_send(['code'=>'error','msg'=>$sheetList['error']]);
-		// 循环表格数据
-		foreach ($sheetList as $value) 		{
-			// 获取城市ID
-			$value['city_id']				= 0;
-			// 存在城市名称,查询城市ID
-			if( $value['contact_city'] )	{
-				// 获取城市ID
-				$value['city_id']			= (int) $City->getIdByName($value['contact_city']);
-				// 如果城市不存在的话
-				if ( !$value['city_id'] )	return json_send(['code'=>'error','msg'=>$value['contact_city'].' => 未找到匹配的城市,请核对城市全称']);
-			}
-			// 获取手机号,查询是否用客户
-			$custom							= $Model->getOneByPhone($value['phone']);
-			// 组装数据
-			$data							= ['weiban_extid'=>$value['weiban_extid'],'username'=>$value['username']];
-			// 如果客户不存在
-			if( !$custom )					$data['phone'] = $value['phone'];
-			// 如果存在城市ID,才修改城市
-			if( $value['city_id'] )			$data['city_id'] = $value['city_id'];
-			// 如果存在手机号
-			$uid							= $custom ? $Model->edit($custom['uid'],$data) : $Model->add($data);
-			// 如果客户存在
-			if( !$uid )						return json_send(['code'=>'error','msg'=>$value['username'].'【'.$value['phone'].'】'.'用户创建或者更新失败']);
-			// 存在详细地址,才创建地址库
-			if( $value['contact_name'] && $value['contact_phone'] && $value['contact_province'] && $value['contact_city'] && $value['contact_area'] && $value['contact_addr'] )	{
-				// 收件地址是否存在
-				$oldAddr					= $CustomAddr->query()->where([['custom_uid','=',$uid]])->first();
-				// 如果不存在地址
-				if( !$oldAddr )				$CustomAddr->add(['custom_uid'=>$uid,'contact_name'=>$value['contact_name'],'contact_shop'=>$value['contact_shop'],'contact_phone'=>$value['contact_phone'],'contact_province'=>$value['contact_province'],'contact_city'=>$value['contact_city'],'contact_area'=>$value['contact_area'],'contact_addr'=>$value['contact_addr']]);
-			}
-		}
-		// 提示成功
-		return								json_send(['code'=>'success','msg'=>'批量导入成功','path'=>'']);
-	}
+    /**
+     * 导出表格
+     *
+     * */
+    public function down_excel(Model $Model,Custom $Custom,CustomScore $CustomScore,WeiBanFollow $WeiBanFollow,City $City){
+        // 接受参数
+        $code					= request('custom_code','');
+        $phone					= request('phone','');
+        $username				= request('username','');
+        $activeName				= request('active_name','');
+        $cityId					= request('city_id',0);
+        $status					= request('status');
+        $startTime				= request('start_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( $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( !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();
+        // 循环处理数据
+        foreach ($list as $key => $value) {
+            // 城市名
+            $value['city_name'] 	= $value['city_id'] ? $City->getOne($value['city_id'],'name') : '';
+            // id转编号
+            $value['custom_code'] 	= $Custom->idToCode($value['uid']);
+            // 如果不存在微伴ID
+            if( !$value['weiban_extid'] )	{
+                // 通过手机号查询注册的账号
+                $value['weiban_extid'] 	= (string) $WeiBanFollow->query()->where([['phone_number','=',$value['phone']]])->value('weiban_extid');
+                // 如果存在的话,修正
+                if( $value['weiban_extid'] ) $Model->edit($value['uid'],['weiban_extid'=>$value['weiban_extid']]);
+            }
+            // 重组
+            $list[$key]				= $value;
+        }
 
+        try {
+            // 去下载
+            $this->toDown($list);
+        } catch (\Throwable $th) {
+            echo $th->getMessage();
+        }
+
+    }
+    /**
+     * 去下载
+     */
+    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;
+    }
 }

+ 1 - 1
app/Http/Controllers/Admin/Orders.php

@@ -60,7 +60,7 @@ class Orders extends Auth{
 		if( $id )				$map[] = ['orders_product.order_id','=',$id];
 		if( $uid )				$map[] = ['custom.uid','=',$uid];
 		if( $productId )		$map[] = ['orders_product.product_id','=',$productId];
-		if( $productName )		$map[] = ['orders_product.product_name','=',$productName];
+		if( $productName )		$map[] = ['orders_product.product_name','LIKE','%'.$productName.'%'];
 		if( $phone )			$map[] = ['orders_addr.contact_phone','=',$phone];
 		if( $province )			$map[] = ['orders_addr.contact_province','LIKE','%'.$province.'%'];
 		if( $city )				$map[] = ['orders_addr.contact_city','LIKE','%'.$city.'%'];

+ 1 - 1
app/Http/Controllers/Admin/Product.php

@@ -670,7 +670,7 @@ class Product extends Auth{
 					// 转成好存储的数据
 					$value['product_id']= $id;
 					// 转成好存储的数据
-					$value['sku_thumb']  = $value['sku_thumb'];
+                    $value['sku_thumb']  = (string) $value['sku_thumb'];
 					// 转成好存储的数据
 					$value['stock_total']= $value['stock'];
 					// 转成好存储的数据

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

@@ -228,6 +228,8 @@ class ScoreClockinActive extends Auth{
         DB::beginTransaction();
         try {
             unset($data['id']);
+            $data['status'] = 1;
+            $data['name'] = $data['name'].'复制';
             //复制活动
             $newId          = $Model->add($data);
             if (!$newId){

+ 3 - 3
app/Models/Orders.php

@@ -26,8 +26,8 @@ class Orders extends Model
     public function add($data)
     {
         // 时间
-        $data['insert_time']				= time();
-        $data['update_time']				= time();
+        if( empty($data['insert_time']) )   $data['insert_time'] = time();
+        if( empty($data['update_time']) )   $data['update_time'] = time();
         // 写入数据表
         $id						            = $this->query()->insertGetId($data);
         // 返回结果
@@ -41,7 +41,7 @@ class Orders extends Model
     public function edit($id,$data)
     {
         // 更新时间
-        $data['update_time']                = time();
+        if( empty($data['update_time']) )   $data['update_time'] = time();
         // 写入数据表
         $result						        = $this->query()->where([['id','=',$id]])->update($data);
         // 返回结果

+ 56 - 99
resources/views/admin/custom_clockin_record/index.blade.php

@@ -3,7 +3,10 @@
 style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 @endsection
 @section('content')
-<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-lg-2 col-md-2 col-sm-2 col-xs-2" style="margin-right: 2px;">
+		<input type="text" class="form-control" name="active_name" value="{{request('active_name','')}}" placeholder="请输入活动名称" />
+	</div>
 	<div class="form-group col col-lg-2 col-md-2 col-sm-2 col-xs-2" style="margin-right: 2px;">
 		<input type="text" class="form-control" name="custom_code" value="{{request('custom_code','')}}" placeholder="请输入客户编码查询" />
 	</div>
@@ -25,7 +28,10 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 		<input type="date" class="form-control" name="start_time" value="{{request('start_time','')}}" placeholder="请输入创建时间查询" />
 	</div>
 	<input type="submit" class="btn btn-sm btn-primary" value="查询"/>
-	<a href="{{url('admin/custom/index')}}" class="btn btn-sm btn-default" >重置</a>
+	<a href="{{url('admin/custom_clockin_record/index')}}" class="btn btn-sm btn-default" >重置</a>
+	@if( check_auth('admin/custom_clockin_record/down_excel') )
+		<button type="button" onclick="alter_from_attr({'method':'get','action':`{{url('admin/custom_clockin_record/down_excel')}}`})" class="btn btn-sm btn-primary"> 下载</button>
+	@endif
 </form>
 
 <div class="row">
@@ -76,104 +82,55 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 </div>
 @endsection
 @section('javascript')
-<script src="/static/fileupload/jquery.ui.widget.js"></script>
-<script src="/static/fileupload/jquery.fileupload.js"></script>
-<script type="text/javascript">
- $(function(){
-	$('.upload').on('click', function() {
-		$('#form-upload').remove();
-		$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_file" type="file" name="custom_file" multiple="multiple" /></form>');
-		$('#form-upload input[name=\'custom_file\']').trigger('click');
-		$('[osctype="btn_upload_file"]').fileupload({
-			dataType: 'json',
-			url: "{{url('admin/custom/import_execl')}}",
-			singleFileUploads: false,
-			beforeSend: function() {
-				art.dialog({
-					id: 'loading',
-					lock: true,
-					title: '文件上传中'
-				});
-			},
-			done: function(e, data) {
-				art.dialog.list['loading'].close();
-				var result = data.result;
-				if (result.code == 'error') {
-					art.dialog({
-						content: result.msg,
-						lock: true,
-						ok: function() {}
-					});
-				}
-				if (result.code == 'success') {
-					art.dialog({
-						content: result.msg,
-						lock: true,
-						ok: function() {
-							location.reload();
+	<script src="/static/fileupload/jquery.ui.widget.js"></script>
+	<script src="/static/fileupload/jquery.fileupload.js"></script>
+	<script type="text/javascript">
+		$(function(){
+			$('.upload').on('click', function() {
+				$('#form-upload').remove();
+				$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_file" type="file" name="order_file" multiple="multiple" /></form>');
+				$('#form-upload input[name=\'clockin_record_file\']').trigger('click');
+				$('[osctype="btn_upload_file"]').fileupload({
+					dataType: 'json',
+					url: "{{url('admin/custom_clockin_record/import_execl')}}",
+					singleFileUploads: false,
+					beforeSend: function() {
+						art.dialog({
+							id: 'loading',
+							lock: true,
+							title: '文件上传中'
+						});
+					},
+					done: function(e, data) {
+						art.dialog.list['loading'].close();
+						var result = data.result;
+						if (result.code == 'error') {
+							art.dialog({
+								content: result.msg,
+								lock: true,
+								ok: function() {}
+							});
 						}
-					});
-				}
-			},
-			fail: function(e,c) {
-				art.dialog.list['loading'].close();
-				art.dialog({
-					content: '<p>'+c.jqXHR.status+'=>'+c.jqXHR.statusText+'</p>',
-					lock: true,
-					ok: function() {}
-				});
-			}
-		});
-	});
- })
-</script>
-<script type="text/javascript">
- $(function(){
-	$('.upload_score').on('click', function() {
-		$('#form-upload').remove();
-		$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_file" type="file" name="score_file" multiple="multiple" /></form>');
-		$('#form-upload input[name=\'score_file\']').trigger('click');
-		$('[osctype="btn_upload_file"]').fileupload({
-			dataType: 'json',
-			url: "{{url('admin/custom_score/import_execl')}}",
-			singleFileUploads: false,
-			beforeSend: function() {
-				art.dialog({
-					id: 'loading',
-					lock: true,
-					title: '文件上传中'
-				});
-			},
-			done: function(e, data) {
-				art.dialog.list['loading'].close();
-				var result = data.result;
-				if (result.code == 'error') {
-					art.dialog({
-						content: result.msg,
-						lock: true,
-						ok: function() {}
-					});
-				}
-				if (result.code == 'success') {
-					art.dialog({
-						content: result.msg,
-						lock: true,
-						ok: function() {
-							location.reload();
+						if (result.code == 'success') {
+							art.dialog({
+								content: result.msg,
+								lock: true,
+								ok: function() {
+									location.reload();
+								}
+							});
 						}
-					});
-				}
-			},
-			fail: function(e,c) {
-				art.dialog.list['loading'].close();
-				art.dialog({
-					content: '<p>'+c.jqXHR.status+'=>'+c.jqXHR.statusText+'</p>',
-					lock: true,
-					ok: function() {}
+					},
+					fail: function(e,c) {
+						art.dialog.list['loading'].close();
+						art.dialog({
+							content: '<p>'+c.jqXHR.status+'=>'+c.jqXHR.statusText+'</p>',
+							lock: true,
+							ok: function() {}
+						});
+					}
 				});
-			}
-		});
-	});
- })
-</script>
+			});
+		})
+	</script>
 @endsection

+ 8 - 0
resources/views/admin/product/copy.blade.php

@@ -90,6 +90,14 @@ style="margin: 0 auto;width: 96%;padding: 30px 0px;"
 		<label class="control-label">限购结束</label>
 		<input class="form-control" type="datetime-local" placeholder="限购结束时间" name="quota_end" value="{{date('Y-m-d H:i',$oldData['quota_end'])}}" />
 	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">上架时间</label>
+		<input class="form-control" type="datetime-local" placeholder="上架时间"  name="puton_time" value="{{$oldData['puton_time']?date('Y-m-d H:i',$oldData['puton_time']):''}}" />
+	</div>
+	<div class="form-group col-sm-2">
+		<label class="control-label">下架时间</label>
+		<input class="form-control" type="datetime-local" placeholder="下架时间" name="putoff_time" value="{{$oldData['putoff_time']?date('Y-m-d H:i',$oldData['putoff_time']):''}}" />
+	</div>
 	<div class="form-group col-sm-2">
 		<label class="control-label">服务城市</label>
 		<select name="city_ids[]" class="form-control selectpicker" data-max-options="20" data-live-search="true" data-live-search-placeholder="搜索城市" data-none-results-text="未搜索到 {0}" title="选择城市" multiple>

+ 2 - 0
routes/web.php

@@ -430,6 +430,8 @@ Route::middleware('admin')->prefix('admin')->group(function(){
 
     //打卡记录
     Route::any('custom_clockin_record/index',[App\Http\Controllers\Admin\CustomClockinRecord::class,'index']);
+    //打卡记录下载
+    Route::any('custom_clockin_record/down_excel',[App\Http\Controllers\Admin\CustomClockinRecord::class,'down_excel']);
 
     /* 下单抽奖-商品范围 */
     // 列表