Commit bab6b6aa by 朱继来

添加导入离职人员客户信息

parent 72342603
......@@ -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
......@@ -123,10 +123,11 @@ Route::group(['middleware' => 'web'], function () {
// 不需要登陆态
Route::group(['middleware' => 'api'], function () {
Route::get ('/api/check/sendsms', 'OrderController@checkOrderSendSms');
Route::get ('/api/check/cancelorder', 'OrderController@checkOrderCancel');
Route::get ('/api/check/histroyorder', 'OrderController@checkHistroyOrder');
Route::get ('/api/check/changeprice', 'SpecialController@changeOrderPrice');
Route::get ('/api/check/exportdimission', 'SpecialController@exportDimission');
Route::get ('/api/check/sendsms', 'OrderController@checkOrderSendSms');
Route::get ('/api/check/cancelorder', 'OrderController@checkOrderCancel');
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');
});
<!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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment