hzd 4 月之前
父節點
當前提交
44c1c0806d
共有 1 個文件被更改,包括 136 次插入0 次删除
  1. 136 0
      application/index/controller/Index.php

+ 136 - 0
application/index/controller/Index.php

@@ -22,6 +22,7 @@ class Index extends Controller
         set_time_limit(0);
         ini_set("memory_limit","512M");
 
+        exit();
         $file = "./1.xls";
         $orgId = 100;
         $cate1 = 22; //灭火器
@@ -59,6 +60,141 @@ class Index extends Controller
         halt($data);
     }
 
+    public function device2(){
+        set_time_limit(0);
+        ini_set("memory_limit","2048M");
+
+        $file = "./2.xls";
+        $orgId = 100;
+        $cate1 = 24; //月度
+        $cate2 = 25; //季度
+        $cate3 = 26; //年度
+        $cate4 = 27; //半年度
+
+        $form1 = "20,21,22,23";
+        $form2 = "24,25,26,27";
+
+        $userId = 3139;
+
+        $data = ExcelUtil::read($file,['num','title','sn','spec','content','area','forms','cate']);
+//        halt($data);
+
+        $forms = [];
+
+        $i = 0;
+        foreach ($data as $k=>$v){
+            $forms = array_merge($forms,explode(";",$v['forms']));
+            if($i >= 228){
+                $device = [
+                    'org_id' => $orgId,
+                    'title' => $v['title'],
+                    'cate_id' => 0,
+                    'enable' => 1,
+                    'del' => 0,
+                    'create_time' => getTime(),
+                    'sn' => $v['sn'],
+                    'spec' => $v['spec'],
+                    'area' => $v['area'],
+                    'content' => $v['content']
+                ];
+                $cateId = 0;
+                if($v['cate'] == "1年/次"){
+                    $cateId = $cate3;
+                    //$data[$k]['device_form'] = $form1;
+                }if($v['cate'] == "1季度/次"){
+                    $cateId = $cate2;
+                    //$data[$k]['device_form'] = $form1;
+                }if($v['cate'] == "1月/次"){
+                    $cateId = $cate1;
+                    //$data[$k]['device_form'] = $form1;
+                }else{
+                    $cateId = $cate4;
+//                    $data[$k]['device_form'] = $form2;
+                }
+                $device['cate_id'] = $cateId;
+                $farr = $this->formatForms(explode(";",$v['forms']));
+                $formIds = [];
+                foreach ($farr as $kk=>$vv){
+                    // 检查是否已存在
+                    $forminfo = Db::name("device_form")->where('org_id',$orgId)->where('cate_id',$cateId)->where('title',$vv)->find();
+                    if($forminfo){
+                        $formIds[] = $forminfo['id'];
+                    }else{
+                        $fid = Db::name("device_form")->insertGetId([
+                            'org_id' => $orgId,
+                            'cate_id' => $cateId,
+                            'title' => $vv,
+                            'sort' => 50,
+                            'del' => 0,
+                            'enable' => 1,
+                            'create_time' => getTime()
+                        ]);
+                        $formIds[] = $fid;
+                    }
+                }
+                $device['device_form'] = implode(",",$formIds);
+
+                $deivceId = Db::name('device')->insertGetId($device);
+                if($deivceId){
+                    Db::name('device_user')->insert([
+                        "device_id" => $deivceId,
+                        "user_id" => $userId,
+                    ]);
+                }
+            }
+
+            $i++;
+        }
+
+
+//        $forms = array_unique($forms);
+//        $nforms = [];
+//        foreach ($forms as $k=>$v){
+//            if(!empty(trim($v))){
+//                $nforms[] = $this->format($v);
+//            }
+//        }
+//
+//        $farr = [];
+//        foreach ($nforms as $k=>$v){
+//            $farr[] = [
+//                "org_id" => $orgId,
+//                "title" => $v,
+//                "sort" => 50,
+//                "del" => 0,
+//                "enable" => 1,
+//                "create_time" => getTime(),
+//            ];
+//        }
+//
+//        $ids = [20,21,22,23,24,25,26,27];
+
+//        dump($nforms);
+        halt($data);
+    }
+
+    public function formatForms($lists){
+        $forms = array_unique($lists);
+        $nforms = [];
+        foreach ($forms as $k=>$v){
+            if(!empty(trim($v))){
+                $nforms[] = $this->format($v);
+            }
+        }
+        return $nforms;
+    }
+
+    public function format($val){
+        $ff = [
+            '1.','2.','3.','4.','5.','6.','7.','8.','9.',
+            '5、','6、','7,'
+        ];
+        foreach ($ff as $k=>$v){
+            $val = str_ireplace($v,"",$val);
+        }
+        return trim($val);
+    }
+
     public function tt(){
         $orgId = 28;
         $mode = 3;