|
@@ -144,15 +144,16 @@ class Courier extends Controller
|
|
|
*/
|
|
|
public function import_table1()
|
|
|
{
|
|
|
- $query = "SHOW FULL COLUMNS FROM system_courier";
|
|
|
- $table = Db::query($query); //获取表所有字段
|
|
|
- $field = array_column($table,'Field'); //提取表字段,放到一维数组中
|
|
|
+// $query = "SHOW FULL COLUMNS FROM system_courier";
|
|
|
+// $table = Db::query($query); //获取表所有字段
|
|
|
+// $field = array_column($table,'Field'); //提取表字段,放到一维数组中
|
|
|
+
|
|
|
+ $username = $this->app->session->get('user')['username'];
|
|
|
|
|
|
- list($msec, $sec) = explode(' ', microtime());
|
|
|
- $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); //毫秒值
|
|
|
$get = $this->request->get();
|
|
|
$import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
|
|
|
$url = $get['url'];
|
|
|
+ $ordfilename = $get['ordfilename'];
|
|
|
if (getConfigValue('storage_type')=='oss'){
|
|
|
$save_dir = "./upload/excle/"; // 服务资源目录
|
|
|
$filename = date('Ymd').time().".xlsx"; // 自定义名称
|
|
@@ -160,90 +161,152 @@ class Courier extends Controller
|
|
|
$import_path = $_SERVER['DOCUMENT_ROOT'].'/upload/excle/'.$res;
|
|
|
}
|
|
|
|
|
|
- $num = 0;
|
|
|
try {
|
|
|
$objReader =\PHPExcel_IOFactory::createReader('Excel2007');
|
|
|
$objExcel = $objReader->load($import_path);
|
|
|
$list = $objExcel->getActiveSheet()->toArray();
|
|
|
- $success = 0;
|
|
|
- $number = 0;
|
|
|
$array = array();
|
|
|
+
|
|
|
+ $dates = array_filter(array_unique(array_column($list,'0')));
|
|
|
+ if (count($dates)>2){
|
|
|
+ $this->error('表中存在多个日期,无法导入',[],3);
|
|
|
+ }
|
|
|
+
|
|
|
+ $datee = date('Y-m-d',strtotime($dates[1]));
|
|
|
+ $info = Db::name('system_values')->where('date',$datee)->count();
|
|
|
+ if ($info){
|
|
|
+ $this->error('表中日期数据已存在,无法导入',[],3);
|
|
|
+ }
|
|
|
+
|
|
|
+ $import_log_id = Db::name('system_import_log')->insertGetId(
|
|
|
+ [
|
|
|
+ 'name'=>$ordfilename,
|
|
|
+ 'url'=>$url,
|
|
|
+ 'import_name'=>$username
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
foreach ($list as $k=>$v){
|
|
|
- echo $k."<br />";
|
|
|
- if($k>$num-1){
|
|
|
- if(array_filter($v)){
|
|
|
- $data=[];
|
|
|
- foreach ($v as $kk=>$vv){
|
|
|
- $data[IntToChr($kk)]=trim($vv);
|
|
|
- }
|
|
|
+ if ($k==0){
|
|
|
+ for ($i=9;$i<count($v);$i++){
|
|
|
+ $name = mb_substr($v[$i],0,2,"utf-8"); //截取前两个汉字
|
|
|
+ $array[$i] = $name;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (!$v[0]){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $date = date('Y-m-d',strtotime($v[0]));
|
|
|
+ $insert_array = array();
|
|
|
+ $site_id = Db::name('system_site')->where('code',$v[6])->value('id');
|
|
|
+ if (!$site_id){
|
|
|
+ $site_id = Db::name('system_site')->insertGetId(
|
|
|
+ [
|
|
|
+ 'code'=>$v[6],
|
|
|
+ 'name'=>$v[7]
|
|
|
+ ]
|
|
|
+ );
|
|
|
}
|
|
|
- dump($v);
|
|
|
+ for ($i=8;$i<count($v);$i++){
|
|
|
+ $a['site_id'] = $site_id;
|
|
|
+ $a['date'] = $date;
|
|
|
+ $a['import_log_id'] = $import_log_id;
|
|
|
+ $a['name'] = $i==8 ? "总签收" : $array[$i];
|
|
|
+ $a['value'] = $v[$i];
|
|
|
+ array_push($insert_array,$a);
|
|
|
+ }
|
|
|
+ Db::name('system_values')->insertAll($insert_array);
|
|
|
}
|
|
|
}
|
|
|
- die;
|
|
|
- $error = 0;
|
|
|
- $phone_error = array();
|
|
|
- foreach ($array as &$v) {
|
|
|
-
|
|
|
- if (!Validate::regex($v['phone'], "^1\d{10}$")) {
|
|
|
- $error = $error + 1;
|
|
|
- $phone_error[] = [
|
|
|
- 'phone' => $v['phone'],
|
|
|
- 'error' => '手机号格式不正确',
|
|
|
- ];
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $this->success('成功');
|
|
|
+ } catch (\think\exception\ValidateException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $user_phone_count = Db::name('system_member')->where('phone', $v['phone'])->where('is_del', 1)->count();
|
|
|
- if ($user_phone_count) {
|
|
|
- $error = $error + 1;
|
|
|
- $phone_error[] = [
|
|
|
- 'phone' => $v['phone'],
|
|
|
- 'error' => '手机已注册',
|
|
|
- ];
|
|
|
- continue;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 导入表二数据
|
|
|
+ * @auth true
|
|
|
+ * @menu true
|
|
|
+ * @throws \think\Exception
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
+ */
|
|
|
+ public function import_table2()
|
|
|
+ {
|
|
|
|
|
|
+ $username = $this->app->session->get('user')['username'];
|
|
|
|
|
|
- $user_name_count = Db::name('system_member')->where('user_name', $v['user_name'])->where('is_del', 1)->count();
|
|
|
- if ($user_name_count) {
|
|
|
- $error = $error + 1;
|
|
|
- $phone_error[] = [
|
|
|
- 'phone' => $v['phone'],
|
|
|
- 'error' => '用户名已被使用',
|
|
|
- ];
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $get = $this->request->get();
|
|
|
+ $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
|
|
|
+ $url = $get['url'];
|
|
|
+ $ordfilename = $get['ordfilename'];
|
|
|
+ if (getConfigValue('storage_type')=='oss'){
|
|
|
+ $save_dir = "./upload/excle/"; // 服务资源目录
|
|
|
+ $filename = date('Ymd').time().".xlsx"; // 自定义名称
|
|
|
+ $res = getFile($url,$save_dir,$filename,1);
|
|
|
+ $import_path = $_SERVER['DOCUMENT_ROOT'].'/upload/excle/'.$res;
|
|
|
+ }
|
|
|
|
|
|
- $id_card_count = Db::name('system_member')->where('id_card', $v['id_card'])->where('is_del', 1)->count();
|
|
|
- if ($id_card_count) {
|
|
|
- $error = $error + 1;
|
|
|
- $phone_error[] = [
|
|
|
- 'phone' => $v['phone'],
|
|
|
- 'error' => '身份证号已被使用',
|
|
|
- ];
|
|
|
- continue;
|
|
|
- }
|
|
|
+ try {
|
|
|
+ $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
|
|
|
+ $objExcel = $objReader->load($import_path);
|
|
|
+ dump($objExcel);die;
|
|
|
+ $list = $objExcel->getActiveSheet()->toArray();
|
|
|
+ $array = array();
|
|
|
|
|
|
- $result = Db::name($this->table)->insert($v);
|
|
|
|
|
|
- if ($result) {
|
|
|
- $success += 1;
|
|
|
- } else {
|
|
|
- $error = $error + 1;
|
|
|
- $phone_error[] = [
|
|
|
- 'phone' => $v['phone'],
|
|
|
- 'error' => '新增失败',
|
|
|
- ];
|
|
|
- }
|
|
|
+ $dates = array_filter(array_unique(array_column($list,'0')));
|
|
|
+ if (count($dates)>2){
|
|
|
+ $this->error('表中存在多个日期,无法导入',[],3);
|
|
|
}
|
|
|
|
|
|
- if ($error<1){
|
|
|
- $this->success('成功');
|
|
|
- }else{
|
|
|
- $this->error('失败',['error'=>$error,'success'=>$success,'phone_error'=>$phone_error],2);
|
|
|
+ $datee = date('Y-m-d',strtotime($dates[1]));
|
|
|
+ $info = Db::name('system_values')->where('date',$datee)->count();
|
|
|
+ if ($info){
|
|
|
+ $this->error('表中日期数据已存在,无法导入',[],3);
|
|
|
}
|
|
|
|
|
|
+ $import_log_id = Db::name('system_import_log')->insertGetId(
|
|
|
+ [
|
|
|
+ 'name'=>$ordfilename,
|
|
|
+ 'url'=>$url,
|
|
|
+ 'import_name'=>$username
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach ($list as $k=>$v){
|
|
|
+ if ($k==0){
|
|
|
+ for ($i=9;$i<count($v);$i++){
|
|
|
+ $name = mb_substr($v[$i],0,2,"utf-8"); //截取前两个汉字
|
|
|
+ $array[$i] = $name;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if (!$v[0]){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $date = date('Y-m-d',strtotime($v[0]));
|
|
|
+ $insert_array = array();
|
|
|
+ $site_id = Db::name('system_site')->where('code',$v[6])->value('id');
|
|
|
+ if (!$site_id){
|
|
|
+ $site_id = Db::name('system_site')->insertGetId(
|
|
|
+ [
|
|
|
+ 'code'=>$v[6],
|
|
|
+ 'name'=>$v[7]
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ for ($i=8;$i<count($v);$i++){
|
|
|
+ $a['site_id'] = $site_id;
|
|
|
+ $a['date'] = $date;
|
|
|
+ $a['import_log_id'] = $import_log_id;
|
|
|
+ $a['name'] = $i==8 ? "总签收" : $array[$i];
|
|
|
+ $a['value'] = $v[$i];
|
|
|
+ array_push($insert_array,$a);
|
|
|
+ }
|
|
|
+ Db::name('system_values')->insertAll($insert_array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->success('成功');
|
|
|
} catch (\think\exception\ValidateException $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
}
|