Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
朱继来
/
后台订单管理
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6cedab08
authored
Apr 02, 2019
by
朱继来
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'zjl_discount_20190322' into development
parents
6ea85e94
bab6b6aa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
0 deletions
app/Http/Controllers/SpecialController.php
app/Http/routes.php
resources/views/importDimission.blade.php
app/Http/Controllers/SpecialController.php
View file @
6cedab08
...
...
@@ -5,9 +5,11 @@ namespace App\Http\Controllers;
use
Illuminate\Http\Request
;
use
App\Http\Controllers\Controller
;
use
App\Model\OrderModel
;
use
App\Model\UserMainModel
;
use
App\Model\OrderActionLogModel
;
use
DB
;
use
Excel
;
use
Log
;
class
SpecialController
extends
Controller
{
...
...
@@ -116,4 +118,88 @@ class SpecialController extends Controller
});
})
->
export
(
'xls'
);
}
// 导入离职业务客户
public
function
importDimission
(
Request
$request
)
{
if
(
$request
->
isMethod
(
'post'
))
{
$file
=
$_FILES
[
'file'
];
// $request->file('file')
$filePath
=
$file
[
'tmp_name'
];
// 临时路径
// 获取导入内容
$excel
=
[];
Excel
::
load
(
$filePath
,
function
(
$reader
)
use
(
&
$excel
){
$data
=
$reader
->
getSheet
(
0
);
// 读取第二个sheet
$excel
=
$data
->
toArray
();
});
if
(
!
$excel
)
{
echo
'导入文件为空'
;
die
;
}
array_shift
(
$excel
);
// 删除第一行
$OrderModel
=
new
OrderModel
();
foreach
(
$excel
as
$k
=>
$v
)
{
// 1. 根据手机或邮箱查找客户最近的订单
$order_id
=
$this
->
getLastOrderId
(
$v
[
0
]);
if
(
$order_id
===
false
)
continue
;
// 2. 根据企业邮箱查找sale_id
$sale_id
=
$this
->
getSaleId
(
strtolower
(
$v
[
1
]));
if
(
$sale_id
===
false
)
continue
;
// 3. 替换第一步的订单sale_id
$OrderModel
->
where
(
'order_id'
,
$order_id
)
->
update
([
'sale_id'
=>
$sale_id
]);
// 记录到日志
$monolog
=
Log
::
getMonolog
();
$monolog
->
popHandler
();
Log
::
useDailyFiles
(
storage_path
(
'logs/updateOrder.log'
));
Log
::
info
(
'替换已离职人员的订单,订单ID:'
.
$order_id
.
',之前的SALE ID:'
.
$sale_id
);
}
echo
'替换sale_id完成'
;
die
;
}
return
view
(
'importDimission'
);
}
// 获取客户最近的订单
public
function
getLastOrderId
(
$account
)
{
$UserMainModel
=
new
UserMainModel
();
$OrderModel
=
new
OrderModel
();
if
(
strpos
(
$account
,
'@'
)
===
false
)
{
$where
[
'mobile'
]
=
$account
;
}
else
{
$where
[
'email'
]
=
strtolower
(
$account
);
}
$user
=
$UserMainModel
->
where
(
$where
)
->
select
(
'user_id'
)
->
first
();
if
(
!
$user
)
return
false
;
// 查找最近的订单
$order
=
$OrderModel
->
where
(
'user_id'
,
$user
[
'user_id'
])
->
select
(
'order_id'
)
->
orderBy
(
'order_id'
,
'desc'
)
->
first
();
if
(
!
$order
)
return
false
;
return
$order
[
'order_id'
];
}
// 获取后台业务ID
public
function
getSaleId
(
$email
)
{
$user
=
DB
::
table
(
'user_info'
)
->
where
(
'email'
,
$email
)
->
select
(
'userId'
)
->
first
();
if
(
!
$user
)
return
false
;
return
$user
->
userId
;
}
}
\ No newline at end of file
app/Http/routes.php
View file @
6cedab08
...
...
@@ -129,5 +129,6 @@ Route::group(['middleware' => 'api'], function () {
Route
::
get
(
'/api/check/histroyorder'
,
'OrderController@checkHistroyOrder'
);
Route
::
get
(
'/api/check/changeprice'
,
'SpecialController@changeOrderPrice'
);
Route
::
get
(
'/api/check/exportdimission'
,
'SpecialController@exportDimission'
);
Route
::
match
([
'get'
,
'post'
],
'/api/check/importdimission'
,
'SpecialController@importDimission'
);
});
resources/views/importDimission.blade.php
0 → 100644
View file @
6cedab08
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
离职人员客户
</title>
<link
href=
"/css/bootstrap.min.css"
rel=
"stylesheet"
>
<link
href=
"/font-awesome/css/font-awesome.css"
rel=
"stylesheet"
>
<link
href=
"/css/animate.css"
rel=
"stylesheet"
>
<link
href=
"/css/style.css"
rel=
"stylesheet"
>
</head>
<body
class=
"gray-bg"
>
<div
class=
"middle-box text-center animated fadeInDown"
>
<h1></h1>
<h2
class=
"font-bold"
>
导入离职人员客户
</h2>
<div
class=
"error-desc"
>
<form
id=
"formUpload"
action=
"/api/check/importdimission"
method=
"post"
enctype=
"multipart/form-data"
style=
"margin-top: 40px;"
>
<input
type=
"file"
name=
"file"
id=
"fileInput"
accept=
"application/vnd.ms-excel, application/x-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
style=
"float:left;"
>
<button
type=
"submit"
>
提交
</button>
</form>
</div>
</div>
</body>
</html>
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