예제 #1
0
 public function insertData()
 {
     $taskPath = DATA_DIR . 'excel/task.k';
     if (!file_exists($taskPath)) {
         $this->errorOutput('任务文件不存在');
     }
     $task = file_get_contents($taskPath);
     $task = unserialize($task);
     if (!$task) {
         $this->errorOutput('没有任务要执行');
     }
     //执行任务
     foreach ($task as $_k => $_v) {
         $market_id = $_v['market_id'];
         if (!file_exists($_v['filename'])) {
             continue;
             //文件不存在就直接执行下一个
         }
         $userdata = file_get_contents($_v['filename']);
         $arr = json_decode($userdata, 1);
         foreach ($arr as $k => $v) {
             //验证卡号
             if (!$v[0]) {
                 continue;
             } else {
                 if ($this->mode->isExistsMember(" card_number = '" . $v[0] . "' AND market_id = '" . $market_id . "' ")) {
                     continue;
                 }
             }
             //名称
             if (!$v[1]) {
                 continue;
             }
             //验证生日
             if (!$v[2]) {
                 continue;
             }
             //验证手机号
             if (!$v[3]) {
                 continue;
             }
             //根据身份证号得到出生日期以及年龄并且保存起来
             $idCardInfo = new IdCard();
             $birthday = date('Y-m-d', strtotime($v[2]));
             $age = $idCardInfo->getAge($birthday);
             $month = intval(date('m', strtotime($birthday)));
             $day = intval(date('d', strtotime($birthday)));
             $constellation_id = $idCardInfo->getConstellation($birthday);
             $data = array('card_number' => $v[0], 'name' => $v[1], 'phone_number' => $v[3], 'age' => $age, 'month' => $month, 'day' => $day, 'birthday' => $birthday, 'constellation_id' => $constellation_id, 'market_id' => $market_id, 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'update_user_id' => $this->user['user_id'], 'update_user_name' => $this->user['user_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
             $this->mode->create($data);
         }
         //每导完一条任务就删掉这条数据
         unlink($_v['filename']);
     }
     //全部导完之后,删除锁文件
     unlink($taskPath);
     $this->addItem('success');
     $this->output();
 }
예제 #2
0
 public function importMemberData()
 {
     $market_id = $this->input['market_id'];
     if (!$market_id) {
         $this->errorOutput(NOID);
     }
     //首先将上传上来的excel文件放到data目录
     if (!$_FILES['excelfile']['tmp_name']) {
         $this->errorOutput(NO_FILE);
     }
     $original = urldecode($_FILES['excelfile']['name']);
     $filetype = strtolower(strrchr($original, '.'));
     if (!in_array($filetype, array('.xlsx', '.xls'))) {
         $this->errorOutput('此文件格式不支持');
     }
     $name = date('Y-m-d', TIMENOW) . '-' . TIMENOW . hg_rand_num(6);
     $filename = $name . $filetype;
     $filepath = DATA_DIR . 'excel/';
     if (!hg_mkdir($filepath) || !is_writeable($filepath)) {
         $this->errorOutput(NOWRITE);
     }
     if (!@move_uploaded_file($_FILES['excelfile']['tmp_name'], $filepath . $filename)) {
         $this->errorOutput(FAIL_MOVE);
     }
     //上传成功之后就初始化数据,将excel数据读入缓存文件中
     $PHPExcelInfo = new PHPExcelInfo($filepath . $filename);
     $memberInfo = $PHPExcelInfo->getData();
     if ($memberInfo) {
         foreach ($memberInfo as $k => $v) {
             //验证卡号
             if (!$v[0]) {
                 continue;
             } else {
                 if ($this->mode->isExistsMember(" card_number = '" . $v[0] . "' AND market_id = '" . $market_id . "' ")) {
                     continue;
                 }
             }
             //名称
             if (!$v[1]) {
                 continue;
             }
             //验证生日
             if (!$v[2]) {
                 continue;
             }
             //验证手机号
             if (!$v[3]) {
                 continue;
             }
             //根据身份证号得到出生日期以及年龄并且保存起来
             $idCardInfo = new IdCard();
             $birthday = date('Y-m-d', strtotime($v[2]));
             $age = $idCardInfo->getAge($birthday);
             $month = intval(date('m', strtotime($birthday)));
             $day = intval(date('d', strtotime($birthday)));
             $constellation_id = $idCardInfo->getConstellation($birthday);
             $data = array('card_number' => $v[0], 'name' => $v[1], 'phone_number' => $v[3], 'age' => $age, 'month' => $month, 'day' => $day, 'birthday' => $birthday, 'constellation_id' => $constellation_id, 'market_id' => $market_id, 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'update_user_id' => $this->user['user_id'], 'update_user_name' => $this->user['user_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip());
             $this->mode->create($data);
         }
     }
     $this->addItem('success');
     $this->output();
 }