Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aic_duty_strategy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yinxiaoling
aic_duty_strategy
Commits
5a92d9a3
Commit
5a92d9a3
authored
May 13, 2020
by
yinxiaoling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
跨域
parent
c8a1185e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
146 additions
and
47 deletions
+146
-47
StrategySetController.php
app/Http/Controllers/strategy/StrategySetController.php
+12
-47
StrategyService.php
app/Service/StrategyService.php
+73
-0
cors.php
config/cors.php
+60
-0
DatabaseSeeder.php
database/seeds/DatabaseSeeder.php
+1
-0
20200512185101.xlsx
storage/import/20200512185101.xlsx
+0
-0
20200512192329.xlsx
storage/import/20200512192329.xlsx
+0
-0
20200512192650.xlsx
storage/import/20200512192650.xlsx
+0
-0
20200512192952.xlsx
storage/import/20200512192952.xlsx
+0
-0
20200512193627.xlsx
storage/import/20200512193627.xlsx
+0
-0
20200512193819.xlsx
storage/import/20200512193819.xlsx
+0
-0
No files found.
app/Http/Controllers/strategy/StrategySetController.php
View file @
5a92d9a3
...
...
@@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
use
Illuminate\Foundation\Validation\ValidatesRequests
;
use
Illuminate\Support\Facades\Validator
;
use
App\Http\Controllers\Tool
;
use
Maatwebsite\Excel\Facades\Excel
;
use
App\Service\StrategyService
;
//use App\Http\Requests\StrategySetCreateRequest;
class
StrategySetController
extends
Controller
...
...
@@ -19,7 +19,7 @@ class StrategySetController extends Controller
dd
(
'策略列表'
);
}
public
function
store
(
Request
$request
){
public
function
store
(
Request
$request
,
StrategyService
$StrategyService
){
$validator
=
Validator
::
make
(
$request
->
all
(),
[
'name'
=>
'required|max:30'
,
'user_sn'
=>
'required'
,
...
...
@@ -27,59 +27,24 @@ class StrategySetController extends Controller
'day_type'
=>
'required'
,
'frequency_type'
=>
'required'
,
'call_time_set'
=>
'required'
,
'project_sn'
=>
'required'
,
'upload'
=>
'size:'
//上传文件限制不超过8M
'project_sn'
=>
'required'
]);
/* if ($validator->fails()) {
return $this->errorWithInfo('表单验证失败', 401);
} */
$excelReturn
=
$this
->
validUploadExcel
(
$request
,
'upload'
,
8388608
);
//限制最大上传文件8M
if
(
isset
(
$excelReturn
[
'code'
])
&&
$excelReturn
[
'code'
]
==
'401'
){
return
$this
->
errorWithInfo
(
$excelReturn
[
'msg'
],
401
);
if
(
isset
(
$request
->
all
()[
'upload'
])){
//excel文件上传
$excelData
=
$StrategyService
->
validUploadExcel
(
$request
,
'upload'
,
8388608
);
//限制最大上传文件8M
if
(
isset
(
$excelData
[
'code'
])){
return
$this
->
errorWithInfo
(
$excelData
[
'msg'
],
401
);
}
//验证excel数据格式及不合格数据原因
$StrategyService
->
validExcelData
(
$excelData
,
$request
->
day_type
);
}
dd
(
$excel
Return
);
dd
(
$excel
Data
);
dd
(
'策略添加'
);
}
public
function
validUploadExcel
(
$request
,
$inputName
,
$maxUploadSize
=
''
){
$path
=
storage_path
()
.
"/import/"
;
$path
=
str_replace
(
'\\'
,
'/'
,
$path
);
$extension
=
$request
->
file
(
$inputName
)
->
getClientOriginalExtension
();
if
(
$extension
!=
'xlsx'
&&
$extension
!=
'xls'
){
return
[
'msg'
=>
'非xls及xlsx格式文件'
,
'code'
=>
401
];
}
if
(
!
empty
(
$maxUploadSize
)){
//限制最大上传文件(字节)
$size
=
$request
->
file
(
$inputName
)
->
getClientSize
();
if
(
$size
>
$maxUploadSize
){
return
[
'msg'
=>
'上传文件过大'
,
'code'
=>
401
];
}
}
$fileName
=
date
(
'YmdHis'
,
time
())
.
'.xlsx'
;
if
(
$request
->
hasFile
(
$inputName
)){
if
(
$request
->
file
(
$inputName
)
->
isValid
()){
$upr
=
$request
->
file
(
$inputName
)
->
move
(
$path
,
$fileName
);
if
(
!
$upr
){
return
[
'msg'
=>
'文件上传失败'
,
'code'
=>
401
];
}
else
{
$res
=
[];
Excel
::
load
(
$path
.
'/'
.
$fileName
,
function
(
$reader
)
use
(
&
$res
){
$reader
=
$reader
->
getSheet
(
0
);
$res
=
$reader
->
toArray
();
});
$data
=
array_filter
(
$res
);
if
(
count
(
$data
)
>
1001
){
return
[
'msg'
=>
'条数超过1000条'
,
'code'
=>
401
];
}
return
$data
;
}
}
}
return
[
'msg'
=>
'excel处理失败'
,
'code'
=>
401
];
}
}
app/Service/StrategyService.php
0 → 100644
View file @
5a92d9a3
<?php
namespace
App\Service
;
use
Maatwebsite\Excel\Facades\Excel
;
class
StrategyService
{
//验证上传的excel
public
function
validUploadExcel
(
$request
,
$inputName
,
$maxUploadSize
=
''
){
$path
=
storage_path
()
.
"/import/"
;
$path
=
str_replace
(
'\\'
,
'/'
,
$path
);
$extension
=
$request
->
file
(
$inputName
)
->
getClientOriginalExtension
();
if
(
$extension
!=
'xlsx'
&&
$extension
!=
'xls'
){
return
[
'msg'
=>
'非xls及xlsx格式文件'
,
'code'
=>
401
];
}
if
(
!
empty
(
$maxUploadSize
)){
//限制最大上传文件(字节)
$size
=
$request
->
file
(
$inputName
)
->
getClientSize
();
if
(
$size
>
$maxUploadSize
){
return
[
'msg'
=>
'上传文件过大'
,
'code'
=>
401
];
}
}
$fileName
=
date
(
'YmdHis'
,
time
())
.
'.xlsx'
;
if
(
$request
->
hasFile
(
$inputName
)){
if
(
$request
->
file
(
$inputName
)
->
isValid
()){
$upr
=
$request
->
file
(
$inputName
)
->
move
(
$path
,
$fileName
);
if
(
!
$upr
){
return
[
'msg'
=>
'文件上传失败'
,
'code'
=>
401
];
}
else
{
$res
=
[];
Excel
::
load
(
$path
.
'/'
.
$fileName
,
function
(
$reader
)
use
(
&
$res
){
$reader
=
$reader
->
getSheet
(
0
);
$res
=
$reader
->
toArray
();
});
$data
=
array_filter
(
$res
);
if
(
count
(
$data
)
>
1001
){
return
[
'msg'
=>
'条数超过1000条'
,
'code'
=>
401
];
}
//验证excel表头格式
$title
=
array_shift
(
$data
);
if
(
$title
!=
[
'姓名'
,
'*手机号码'
,
'值班日期'
]){
//匹配excel表头
return
[
'msg'
=>
'导入失败,excel表头不一致'
,
'code'
=>
401
];
}
return
$data
;
}
}
}
return
[
'msg'
=>
'excel处理失败'
,
'code'
=>
401
];
}
//判断excel数据问题,$day_type//外呼日期类型 0每天 1日期前一天和当天 1需要验证值班日期必填
public
function
validExcelData
(
$data
,
$day_type
){
$failData
=
[[
'姓名'
,
'*手机号码'
,
'值班日期'
,
'失败原因'
]];
foreach
(
$data
as
$k
=>
$v
){
if
(
strlen
(
$v
[
0
])
>
20
){
//姓名最大20个字符,中文处理,放入失败数据中
$failData
[]
=
array_push
(
$v
,
"姓名过长"
);
}
if
(
$v
[
1
]){
//手机号格式验证,不能为空
$failData
[]
=
array_push
(
$v
,
"手机号格式不正确"
);
}
if
(
$day_type
==
1
){
//验证必填且为日期格式
/* if (empty($v[2])){
$failData[] = array_push($v, "值班日期必填");
}elseif (){
$failData[] = array_push($v, "值班日期格式错误");
} */
}
}
}
}
config/cors.php
0 → 100644
View file @
5a92d9a3
<?php
return
[
/*
|--------------------------------------------------------------------------
| Laravel CORS Options
|--------------------------------------------------------------------------
|
| The allowed_methods and allowed_headers options are case-insensitive.
|
| You don't need to provide both allowed_origins and allowed_origins_patterns.
| If one of the strings passed matches, it is considered a valid origin.
|
| If array('*') is provided to allowed_methods, allowed_origins or allowed_headers
| all methods / origins / headers are allowed.
|
*/
/*
* You can enable CORS for 1 or multiple paths.
* Example: ['api/*']
*/
'paths'
=>
[
'api/*'
],
/*
* Matches the request method. `[*]` allows all methods.
*/
'allowed_methods'
=>
[
'*'
],
/*
* Matches the request origin. `[*]` allows all origins. Wildcards can be used, eg `*.mydomain.com`
*/
'allowed_origins'
=>
[
'*'
],
/*
* Patterns that can be used with `preg_match` to match the origin.
*/
'allowed_origins_patterns'
=>
[],
/*
* Sets the Access-Control-Allow-Headers response header. `[*]` allows all headers.
*/
'allowed_headers'
=>
[
'*'
],
/*
* Sets the Access-Control-Expose-Headers response header with these headers.
*/
'exposed_headers'
=>
[],
/*
* Sets the Access-Control-Max-Age response header when > 0.
*/
'max_age'
=>
0
,
/*
* Sets the Access-Control-Allow-Credentials header.
*/
'supports_credentials'
=>
false
,
];
database/seeds/DatabaseSeeder.php
View file @
5a92d9a3
...
...
@@ -32,6 +32,7 @@ class DatabaseSeeder extends Seeder
$table
->
integer
(
'disabled'
)
->
default
(
1
);
//是否不可用 0启用 1停用
$table
->
integer
(
'total'
)
->
default
(
0
);
//excel导入号码总数量
$table
->
integer
(
'latest_total'
)
->
default
(
0
);
//最新一次导入excel号码数量
$table
->
char
(
'call_time_set'
,
50
);
//呼叫设置时间点,两个用#号分割
$table
->
timestamp
(
'created_at'
)
->
nullable
();
});
...
...
storage/import/20200512185101.xlsx
0 → 100644
View file @
5a92d9a3
File added
storage/import/20200512192329.xlsx
0 → 100644
View file @
5a92d9a3
File added
storage/import/20200512192650.xlsx
0 → 100644
View file @
5a92d9a3
File added
storage/import/20200512192952.xlsx
0 → 100644
View file @
5a92d9a3
File added
storage/import/20200512193627.xlsx
0 → 100644
View file @
5a92d9a3
File added
storage/import/20200512193819.xlsx
0 → 100644
View file @
5a92d9a3
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment