dever 3 years ago
parent
commit
6b9657f3f2
2 changed files with 105 additions and 12 deletions
  1. 104 11
      service/option/lib/Import.php
  2. 1 1
      service/option/src/Auth.php

+ 104 - 11
service/option/lib/Import.php

@@ -17,16 +17,16 @@ class Import
         $data = Dever::excelImport($file, 1, 5, 'excel');
 
         $table = array();
-        $table['head'] = array('账户类型', '待交付', '已交付总额', '已发放剩余', '未发放', '已兑付');
+        $table['head'] = array('序列号', '姓名', '手机号', '身份证号', '说明');
         $table['body'] = array();
-        $result['已导入'] = array
-        (
-            'type' => 'table',
-            'content' => $table,
-        );
-        $html = Dever::show('', $result, false, false);
-        echo $html;die;
 
+        $table_status = array();
+        $table_status['head'] = array('主账号', '子账号');
+        $table_status['body'] = array();
+        $table_status['body'][0][0] = 0;
+        $table_status['body'][0][1] = 0;
+
+        $check = array();
 
         if ($data) {
             $member = array();
@@ -49,7 +49,16 @@ class Import
                         $update['where_id'] = $info['id'];
                         $id = Dever::db('option/member')->update($update);
                     }
+                    if (!$id) {
+                        $table['body'][] = array($update['key'], $update['name'], $update['mobile'], $update['idcard'], '账户导入失败,请重新导入');
+                    } else {
+                        if ($update['main'] == 2) {
+                            $table_status['body'][0][1] += 1;
+                        }
+                    }
+                    $check[$key] = 2;
                     if ($id && $update['main'] == 1) {
+                        $check[$key] = 1;
                         if (!isset($member[$key])) {
                             $member[$key] = array();
                         }
@@ -59,6 +68,11 @@ class Import
                         } else {
                             $member[$key] = $account['id'];
                         }
+                        if (!$member[$key]) {
+                            $table['body'][] = array($update['key'], $update['name'], $update['mobile'], $update['idcard'], '生成主账户失败');
+                        } else {
+                            $table_status['body'][0][0] += 1;
+                        }
                     }
                 }
             }
@@ -68,12 +82,91 @@ class Import
                     $where = array();
                     $where['option_key'] = $k;
                     $where['set_aid'] = $v;
-                    Dever::db('option/member')->updates($where);
+                    $state = Dever::db('option/member')->updates($where);
                 }
             }
         }
-        $table = Dever::table($result);
-        return $table;
+        $result['导入状态'] = array
+        (
+            'type' => 'table',
+            'content' => $table_status,
+        );
+
+        $result['导入异常'] = array
+        (
+            'type' => 'table',
+            'content' => $table,
+        );
+        $html = Dever::show('', $result, false, false);
+        return $html;
+    }
+
+    # 检测文档
+    public function check_api()
+    {
+        Dever::config('base')->hook = true;
+        $file = Dever::data() . 'q.xlsx';
+
+        $data = Dever::excelImport($file, 1, 5, 'excel');
+
+        $table = array();
+        $table['head'] = array('序列号', '说明');
+        $table['body'] = array();
+
+        $table_status = array();
+        $table_status['head'] = array('主账号', '子账号');
+        $table_status['body'] = array();
+        $table_status['body'][0][0] = 0;
+        $table_status['body'][0][1] = 0;
+
+        $check = array();
+
+        if ($data) {
+            $member = array();
+            foreach ($data as $k => $v) {
+                $state = preg_match(Dever::rule('mobile'), $v['C']);
+                if ($state) {
+                    $key = $v['A'];
+                    $update = array();
+                    $update['main'] = $v['E'] == 1 ? 1 : 2;
+                    $check[$key] = 2;
+                    if ($update['main'] == 1) {
+                        $check[$key] = 1;
+                        $table_status['body'][0][0] += 1;
+                    } else {
+                        $table_status['body'][0][1] += 1;
+                    }
+                }
+            }
+
+            if ($member) {
+                foreach ($member as $k => $v) {
+                    $where = array();
+                    $where['option_key'] = $k;
+                    $where['set_aid'] = $v;
+                    $state = Dever::db('option/member')->updates($where);
+                }
+            }
+        }
+        $result['数据统计'] = array
+        (
+            'type' => 'table',
+            'content' => $table_status,
+        );
+
+        foreach ($check as $k => $v) {
+            if ($v == 2) {
+                $table[$k] => array($k, '无主账号');
+            }
+        }
+
+        $result['数据异常'] = array
+        (
+            'type' => 'table',
+            'content' => $table,
+        );
+        $html = Dever::show('', $result, false, false);
+        return $html;
     }
 
     # 导入交付记录

+ 1 - 1
service/option/src/Auth.php

@@ -66,7 +66,7 @@ class Auth
                     }
                     # 验证身份证是否验证过
                     $find = Dever::db('option/member')->find(array('idcard' => $idcard, 'idcard_bind' => 1));
-                    if ($find) {
+                    if ($find && $find['id'] != $user['id']) {
                         Dever::alert('身份证已被绑定');
                     }
                     Dever::db('option/member')->update(array('where_id' => $user['id'], 'idcard_bind' => 1));