|
@@ -4,13 +4,14 @@
|
|
|
namespace app\admin\service\consultant;
|
|
|
|
|
|
|
|
|
-use app\admin\service\member\MemberService;
|
|
|
use app\model\Consultant;
|
|
|
use app\model\MarketCustomer;
|
|
|
use app\model\MarketCustomerFollow;
|
|
|
use app\model\MarketCustomerLogs;
|
|
|
-use app\model\Member;
|
|
|
use app\model\SysDept;
|
|
|
+use PhpOffice\PhpSpreadsheet\Reader\Csv;
|
|
|
+use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
|
|
+use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
|
|
use support\Db;
|
|
|
use support\exception\BusinessException;
|
|
|
use support\Request;
|
|
@@ -18,7 +19,7 @@ use Tinywan\Jwt\JwtToken;
|
|
|
|
|
|
class CustomService
|
|
|
{
|
|
|
- const DIFF_TIME = (60 * 60 * 24 * 30);
|
|
|
+ const DIFF_TIME = (60 * 60 * 24 * 30); //调入团队公池 x4 = 调入集团公池
|
|
|
/**
|
|
|
* Notes: 返回选项配置信息
|
|
|
* User: yb
|
|
@@ -37,6 +38,7 @@ class CustomService
|
|
|
$currentTime = time();
|
|
|
$diffNums = self::DIFF_TIME;
|
|
|
$deptIds = TeamService::getIdsByUser();
|
|
|
+ $belongStatus = $params['belong_status'] ?? 1;
|
|
|
if (false === $deptIds) {
|
|
|
//无权限
|
|
|
$where[] = ['dept_id', '=', 0];
|
|
@@ -49,6 +51,13 @@ class CustomService
|
|
|
$where[] = [function($query) use ($deptIds) {
|
|
|
$query->whereIn('dept_id', $deptIds);
|
|
|
}];
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("check_status IN (-1, 1)")
|
|
|
+ ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
|
|
|
+ ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)")
|
|
|
+ ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
+ }];
|
|
|
+
|
|
|
} else {
|
|
|
if (!empty($params['dept_id'])) {
|
|
|
$deptId = end($params['dept_id']);
|
|
@@ -71,35 +80,20 @@ class CustomService
|
|
|
$query->where('mobile', 'like', "%{$mobile}%");
|
|
|
}];
|
|
|
}
|
|
|
- if (!empty($params['report_status'])) {
|
|
|
- $where[] = ['check_status', '=', $params['report_status']];
|
|
|
-// if ($params['report_status'] == -1) {
|
|
|
-// //待审核
|
|
|
-// $where[] = ['check_status', '=', 1];
|
|
|
-// } else {
|
|
|
-// $where[] = ['check_status', '=', 2];
|
|
|
-// }
|
|
|
-// if ($params['report_status'] == 1) {
|
|
|
-// //已报备
|
|
|
-// $where[] = [function($query) use ($diffNums, $currentTime) {
|
|
|
-// $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
|
|
|
-// }];
|
|
|
-// } else if ($params['report_status'] == 3) {
|
|
|
-// //已锁定
|
|
|
-// $where[] = [function($query) {
|
|
|
-// $query->whereIn('current_status', [2,3,4]);
|
|
|
-// }];
|
|
|
-// } else if ($params['report_status'] == 2) {
|
|
|
-// //已失效
|
|
|
-// $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
-// $query->orWhere('current_status', '=', -1)->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 1 AND check_status = 2)");
|
|
|
-// }];
|
|
|
-// }
|
|
|
- }
|
|
|
if (!empty($params['consultant_name'])) {
|
|
|
- $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")->pluck('id');
|
|
|
+ $consultantIds = Consultant::where('name', 'like', "%{$params['consultant_name']}%")
|
|
|
+ ->where('mobile', 'like', "%{$params['consultant_name']}%")
|
|
|
+ ->pluck('id')->toArray();
|
|
|
+ $where[] = [function($query) use ($consultantIds) {
|
|
|
+ $query->whereIn('consultant_id', $consultantIds);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ if (!empty($params['report_name'])) {
|
|
|
+ $consultantIds = Consultant::where('name', 'like', "%{$params['report_name']}%")
|
|
|
+ ->where('mobile', 'like', "%{$params['report_name']}%")
|
|
|
+ ->pluck('id')->toArray();
|
|
|
$where[] = [function($query) use ($consultantIds) {
|
|
|
- $query->orWhereIn('consultant_id', $consultantIds)->orWhereIn('report_consultant_id', $consultantIds);
|
|
|
+ $query->whereIn('report_consultant_id', $consultantIds);
|
|
|
}];
|
|
|
}
|
|
|
if (!empty($params['type'])) {
|
|
@@ -132,11 +126,17 @@ class CustomService
|
|
|
|
|
|
if (!empty($params['current_status'])) {
|
|
|
$currentStatus = $params['current_status'];
|
|
|
- if ($currentStatus == 1) {
|
|
|
- $where[] = ['current_status', '=', $currentStatus];
|
|
|
+ if ($currentStatus == -2) {
|
|
|
+ //检索公池状态
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)");
|
|
|
+ }];
|
|
|
} else {
|
|
|
- $where[] = [function($query) use ($currentStatus){
|
|
|
- $query->where('current_status', '=', $currentStatus)->where('check_status', '<>', 1);
|
|
|
+ $where[] = ['current_status', '=', $currentStatus];
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("check_status IN (-1, 1)")
|
|
|
+ ->orWhereRaw("check_status = 2 AND current_status IN (-1,3,4)")
|
|
|
+ ->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
|
|
|
}];
|
|
|
}
|
|
|
}
|
|
@@ -222,10 +222,35 @@ class CustomService
|
|
|
->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2)");
|
|
|
}];
|
|
|
} else {
|
|
|
- //已经流入公池
|
|
|
- $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
- $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
- }];
|
|
|
+ if (true === $deptIds) {
|
|
|
+ if (!empty($params['pub_status'])) {
|
|
|
+ if ($params['pub_status'] == 2) {
|
|
|
+ //仅检索团队公池
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
+ }];
|
|
|
+ } else {
|
|
|
+ //仅检索集团公池
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("((visit_time + ({$diffNums} * 4)) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //超管权限
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (is_array($deptIds)) {
|
|
|
+ //团队权限
|
|
|
+ $where[] = [function($query) use ($diffNums, $currentTime){
|
|
|
+ $query->orWhereRaw("((visit_time + {$diffNums}) - {$currentTime} <= 0 AND (visit_time + ({$diffNums} * 4)) - {$currentTime} > 0 AND current_status = 2 AND check_status = 2 AND belong_status = 1)")->whereOr('belong_status','<>', 1);
|
|
|
+ }];
|
|
|
+ } else {
|
|
|
+ //无权限
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -289,6 +314,15 @@ class CustomService
|
|
|
$visitTime = $item->visit_time;
|
|
|
$visitTimeStamp = strtotime($visitTime);
|
|
|
$diff = ($visitTimeStamp + $diffNums) - $currentTime;
|
|
|
+ if ($diff > 0) {
|
|
|
+ $item->belong_status = 1;
|
|
|
+ } else {
|
|
|
+ if (abs($diff) - (4*$diffNums) > 0) {
|
|
|
+ $item->belong_status = 3;
|
|
|
+ } else {
|
|
|
+ $item->belong_status = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
$item->diff_nums = ($diff > 0) ? $diff : 0;
|
|
|
$item->consultant_name = $consultantKeys[$item->consultant_id]['name'] ?? '';
|
|
|
$item->consultant_mobile = $consultantKeys[$item->consultant_id]['mobile'] ?? '';
|
|
@@ -455,13 +489,20 @@ class CustomService
|
|
|
if (!is_array($ids)) {
|
|
|
$ids = [$ids];
|
|
|
}
|
|
|
+ Db::beginTransaction();
|
|
|
try {
|
|
|
if (is_array($ids)) {
|
|
|
MarketCustomer::whereIn('id', $ids)->delete();
|
|
|
+ MarketCustomerFollow::whereIn('market_customer_id', $ids)->delete();//删除跟进记录
|
|
|
+ MarketCustomerLogs::whereIn('market_customer_id', $ids)->delete();//删除移交记录
|
|
|
} else {
|
|
|
MarketCustomer::where('id', $ids)->delete();
|
|
|
+ MarketCustomerFollow::where('market_customer_id', $ids)->delete();//删除跟进记录
|
|
|
+ MarketCustomerLogs::where('market_customer_id', $ids)->delete();//删除移交记录
|
|
|
}
|
|
|
+ Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
+ Db::rollBack();
|
|
|
return json_fail('删除失败');
|
|
|
}
|
|
|
|
|
@@ -606,7 +647,7 @@ class CustomService
|
|
|
$query->whereIn('consultant_id', $consultantIds);
|
|
|
}];
|
|
|
}
|
|
|
- $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id'])->get();
|
|
|
+ $customList = MarketCustomer::where($whereCustom)->select(['id','consultant_id','dept_id','visit_time','check_status','current_status'])->get();
|
|
|
if (!$customList->isEmpty()) {
|
|
|
foreach ($customList as$item) {
|
|
|
$logsInertData[] = [
|
|
@@ -627,13 +668,21 @@ class CustomService
|
|
|
if (empty($logsInertData)) {
|
|
|
return json_fail('移交记录不能为空');
|
|
|
}
|
|
|
+ $diffTime = self::DIFF_TIME;
|
|
|
Db::beginTransaction();
|
|
|
$result = false;
|
|
|
try {
|
|
|
foreach ($customList as $item) {
|
|
|
if ($currentConsultantId != 0) {
|
|
|
//移交至指定顾问
|
|
|
- $item->visit_time = time();
|
|
|
+ //判断一下是否到了到访的过期时间,如果过期了就更新到访时间,没过期时间就不变
|
|
|
+ if ($item->check_status == 2 && $item->current_status == 2) {
|
|
|
+ $visitTime = $item->visit_time;
|
|
|
+ $diff = strtotime($visitTime) + $diffTime - time();
|
|
|
+ if ($diff <= 0) {
|
|
|
+ $item->visit_time = time();
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
//移交至其他团队
|
|
|
$item->visit_time = time() - self::DIFF_TIME;
|
|
@@ -1064,13 +1113,6 @@ class CustomService
|
|
|
return substr_replace($val, '****', 3, 4);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Notes: 判客指定顾问
|
|
|
- * User: yb
|
|
|
- * Date: 2024/9/5
|
|
|
- * Time: 15:50
|
|
|
- * @param $params
|
|
|
- */
|
|
|
/**
|
|
|
* Notes: 指定顾问
|
|
|
* User: yb
|
|
@@ -1131,4 +1173,222 @@ class CustomService
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Notes: 导入客户
|
|
|
+ * User: yb
|
|
|
+ * Date: 2024/9/10
|
|
|
+ * Time: 10:30
|
|
|
+ * @param $params
|
|
|
+ */
|
|
|
+ public static function import($params)
|
|
|
+ {
|
|
|
+ if (empty($params['path'])) {
|
|
|
+ return json_fail('文件地址不能为空');
|
|
|
+ }
|
|
|
+ $path = 'public'.$params['path'];
|
|
|
+ if (is_file($path)) {
|
|
|
+ $teamKeys = [];
|
|
|
+ //查询顾问信息
|
|
|
+ $teamData = Db::table('consultant')
|
|
|
+ ->leftJoin('sys_dept', 'consultant.dept_id', '=', 'sys_dept.dept_id')
|
|
|
+ ->select(['consultant.id', 'consultant.name', 'sys_dept.dept_name', 'sys_dept.dept_id'])
|
|
|
+ ->whereNull('consultant.deleted_at')
|
|
|
+ ->get();
|
|
|
+ if (!($teamData->isEmpty())) {
|
|
|
+ foreach ($teamData as $item) {
|
|
|
+ $key = $item->name.'-'.$item->dept_name;
|
|
|
+ $teamKeys[$key] = [
|
|
|
+ 'consultant_id' => $item->id,
|
|
|
+ 'dept_id' => $item->dept_id,
|
|
|
+ 'name' => $item->name,
|
|
|
+ 'dept_name' => $item->dept_name
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data = self::readExcel($path);
|
|
|
+// $fields = ['到访时间', '客户姓名', '客户手机号', 'A类', 'B类', 'C类', 'D类', '健康顾问', '报备人', '团队'];
|
|
|
+ if (empty($data)) {
|
|
|
+ return json_fail('无可导入内容');
|
|
|
+ } else {
|
|
|
+ $sucNums = 0;
|
|
|
+ $errNums = 0;
|
|
|
+ $validate = '/^1\d{10}$/';
|
|
|
+ $errorData = [];
|
|
|
+ Db::beginTransaction();
|
|
|
+ try {
|
|
|
+ foreach ($data as $key => $val) {
|
|
|
+ if ($val[3] == 1) {$level = 1;} else if ($val[4] == 1) {$level = 2;} else if ($val[5] == 1) {$level = 3;} else if ($val[6] == 1) {$level = 4;}
|
|
|
+ $line = '姓名:'.$val[1].' 第'.($key + 2).'行:';
|
|
|
+ $mobile = $val[2] ?? '';
|
|
|
+ $mobile = trim($mobile);
|
|
|
+ $error = [];
|
|
|
+ $msg = '';
|
|
|
+ if (empty($val[7]) && empty($val[8])) {
|
|
|
+ $msg = $line.'报备人和顾问必须存在其中之一';
|
|
|
+ $val[10] = '报备人和顾问必须存在其中之一';
|
|
|
+// throw new \Exception($line.'报备人和顾问必须存在其中之一');
|
|
|
+ }
|
|
|
+ if (empty($val[9])) {
|
|
|
+ $msg = $line.'无团队信息';
|
|
|
+ $val[10] = '无团队信息';
|
|
|
+// throw new \Exception($line.'无团队信息');
|
|
|
+ }
|
|
|
+ if ($val[0] == '1970-01-01 08:00:00') {
|
|
|
+ $msg = $line.'日期格式错误';
|
|
|
+ $val[10] = '日期格式错误';
|
|
|
+// throw new \Exception($line.'日期格式错误');
|
|
|
+ }
|
|
|
+ if (empty($mobile)) {
|
|
|
+ $msg = $line.'手机号不能为空';
|
|
|
+ $val[10] = '手机号不能为空';
|
|
|
+// throw new \Exception($line.'手机号不能为空');
|
|
|
+ }
|
|
|
+ if (!preg_match($validate, $mobile)) {
|
|
|
+ $msg = $line.'手机号格式非法';
|
|
|
+ $val[10] = '手机号格式非法';
|
|
|
+// throw new \Exception($line.'手机号格式非法');
|
|
|
+ }
|
|
|
+ $consultantName = $val[7];
|
|
|
+ $reportName = $val[8];
|
|
|
+ $teamName = $val[9];
|
|
|
+ $consultantKey = $consultantName.'-'.$teamName;
|
|
|
+ $consultantId = $teamKeys[$consultantKey]['consultant_id'] ?? 0;
|
|
|
+ $reportKey = $reportName.'-'.$teamName;
|
|
|
+ $reportConsultantId = $teamKeys[$reportKey]['consultant_id'] ?? 0;
|
|
|
+ if ($consultantId <= 0 && $reportConsultantId <= 0) {
|
|
|
+ $msg = $line.'健康顾问或报备人都不存在';
|
|
|
+ $val[10] = '健康顾问或报备人都不存在';
|
|
|
+// throw new \Exception($line.'健康顾问或报备人都不存在');
|
|
|
+ }
|
|
|
+ if ($consultantId > 0) {
|
|
|
+ $deptId = $teamKeys[$consultantKey]['dept_id'] ?? 0;
|
|
|
+ }
|
|
|
+ if ($reportConsultantId > 0) {
|
|
|
+ $deptId = $teamKeys[$reportKey]['dept_id'] ?? 0;
|
|
|
+ } else {
|
|
|
+ if ($consultantId > 0) {
|
|
|
+ $reportConsultantId = $consultantId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($deptId)) {
|
|
|
+ $msg = $line.'健康顾问或报备人都不存在';
|
|
|
+ $val[10] = '健康顾问或报备人都不存在';
|
|
|
+// throw new \Exception($line.'团队不存在');
|
|
|
+ }
|
|
|
+ if (MarketCustomer::checkCustomExists($val[2])) {
|
|
|
+ $msg = $line.'客户已转到访,无法二次录入';
|
|
|
+ $val[10] = '客户已转到访,无法二次录入';
|
|
|
+// throw new \Exception($line.'客户已转到访,无法二次录入');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = false;
|
|
|
+ if (empty($msg)) {
|
|
|
+ //查看手机号是否存在
|
|
|
+ $insertData = [
|
|
|
+ 'name' => $val[1],
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ 'level' => $level ?? null,
|
|
|
+ 'consultant_id' => $consultantId,
|
|
|
+ 'report_consultant_id' => $reportConsultantId,
|
|
|
+ 'create_consultant_id' => $reportConsultantId,
|
|
|
+ 'dept_id' => $deptId ?? 0,
|
|
|
+ 'belong_status' => 1,
|
|
|
+ 'current_status' => 2,
|
|
|
+ 'check_status' => 2,
|
|
|
+ 'check_note' => '导入的客户信息,无审核人员',
|
|
|
+ 'type' => 1,
|
|
|
+ 'visit_time' => strtotime($val[0]),
|
|
|
+ 'created_at' => strtotime($val[0])
|
|
|
+ ];
|
|
|
+ $result = Db::table('market_customer')->insert($insertData);
|
|
|
+ } else {
|
|
|
+ $val[11] = $line;
|
|
|
+ $errorData[] = $val;
|
|
|
+ }
|
|
|
+ if ($result) {
|
|
|
+ $sucNums++;
|
|
|
+ } else {
|
|
|
+ $errNums++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ Db::rollBack();
|
|
|
+ return json_fail($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return json_fail('文件不存在');
|
|
|
+ }
|
|
|
+ $total = count($data);
|
|
|
+ return json_success("全部数据:{$total},成功:{$sucNums},失败:{$errNums}", ['data' => $errorData]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Notes: 读取excel文件
|
|
|
+ * User: yb
|
|
|
+ * Date: 2024/9/10
|
|
|
+ * Time: 10:41
|
|
|
+ * @param $filePath
|
|
|
+ */
|
|
|
+ public static function readExcel($filePath)
|
|
|
+ {
|
|
|
+ set_time_limit(0);
|
|
|
+ ini_set('memory_limit', '1024M');
|
|
|
+ $ext = pathinfo($filePath, PATHINFO_EXTENSION);
|
|
|
+ if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
|
|
|
+ return json_fail('未知的导入文件类型');
|
|
|
+ }
|
|
|
+ if ($ext === 'csv') {
|
|
|
+ $file = fopen($filePath, 'r');
|
|
|
+ $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
|
|
|
+ $fp = fopen($filePath, "w");
|
|
|
+ $n = 0;
|
|
|
+ while ($line = fgets($file)) {
|
|
|
+ $line = rtrim($line, "\n\r\0");
|
|
|
+ $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
|
|
|
+ if ($encoding != 'utf-8') {
|
|
|
+ $line = mb_convert_encoding($line, 'utf-8', $encoding);
|
|
|
+ }
|
|
|
+ if ($n == 0 || preg_match('/^".*"$/', $line)) {
|
|
|
+ fwrite($fp, $line . "\n");
|
|
|
+ } else {
|
|
|
+ fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
|
|
|
+ }
|
|
|
+ $n++;
|
|
|
+ }
|
|
|
+ fclose($file) || fclose($fp);
|
|
|
+ $reader = new Csv();
|
|
|
+ } else if ($ext === 'xls') {
|
|
|
+ $reader = new Xls();
|
|
|
+ } else {
|
|
|
+ $reader = new Xlsx();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (!$PHPExcel = $reader->load($filePath)) {
|
|
|
+ return json_fail('未知的导入文件类型');
|
|
|
+ }
|
|
|
+ $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
|
|
|
+ $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
|
|
|
+ $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
|
|
|
+ $maxColumnNumber = 10;
|
|
|
+ $insertData = [];
|
|
|
+ for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
|
|
|
+ $values = [];
|
|
|
+ for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
|
|
|
+ $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getFormattedValue();
|
|
|
+ if ($currentColumn == 1) {
|
|
|
+ $val = date('Y-m-d H:i:s', strtotime($val)); //时间
|
|
|
+ }
|
|
|
+ $values[] = is_null($val) ? '' : $val;
|
|
|
+ }
|
|
|
+ $insertData[] = $values;
|
|
|
+ }
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ return json_fail($e->getMessage());
|
|
|
+ }
|
|
|
+ return $insertData;
|
|
|
+ }
|
|
|
}
|