function Save($data)
 {
     //入库
     if (is_array($data['fields'])) {
         $data['fields'] = collect::array2string($data['fields']);
     }
     //数组转换为字符串
     if (empty($data['nid'])) {
         $data['lastdate'] = time();
     }
     if ($this->DB->create($data)) {
         if (!empty($data['nid'])) {
             $id = $this->DB->where('id=' . $data['nid'])->data($data)->save();
             $LastID = $data['nid'];
         } else {
             $id = $this->DB->add($data);
             $LastID = $id;
         }
         if ($id === 'false') {
             return false;
         }
         $this->ColMemcache();
         return $LastID;
         //return true;
     } else {
         //echo  $this->DB->getDbError();
         return false;
     }
 }
Example #2
0
 function Collecting(&$config)
 {
     $page = !empty($config['page']) ? intval($config['page']) : 1;
     $all = !empty($config['total']) ? intval($config['total']) : 0;
     $where = array('nid' => $config['id'], 'status' => '0');
     //$where=array('nid'=>$config['id']);
     $total = $this->ContDB->where($where)->count();
     if (empty($all)) {
         $all = $total;
     }
     $total_page = ceil($all / $config['pagesize']);
     $maxpage = get_cms_page_max($total, $config['pagesize'], $page);
     $list = $this->ContDB->where($where)->order('id desc')->limit($config['pagesize'])->page($maxpage)->select();
     if ($page <= 1) {
         $this->DB->where('id=' . $config['id'])->save(array('lastdate' => time()));
     }
     //$i = 0;
     if (!empty($list) && is_array($list)) {
         if ($total_page < $page) {
             //$this->DB->where('id='.$config['id'])->save(array('lastdate'=>time()));
             F('_gxcms/ColCache', NUll);
             $this->error = '采集完成!';
             return true;
         }
         //print_r($list);exit;
         foreach ($list as $v) {
             $html = $this->GetCon($v, $config);
             $msg = '<strong>' . $html['title'] . '</strong> ';
             if (!empty($html['cname'])) {
                 $cname = $this->CModel->GetCname($html['cname'], $v['nid']);
                 if (!$cname) {
                     $msg .= '分类<strong>' . $html['cname'] . '</strong>待绑定';
                     $html['cid'] = 999;
                     //===========================================//
                     //写入缓存
                     $cache = F('_gxcms/channel_999');
                     $cache[$v['id']] = array('id' => $v['id'], 'cname' => $html['cname'] . '_' . $v['nid']);
                     F('_gxcms/channel_999', $cache);
                 } else {
                     if ($cname != $html['cname']) {
                         $msg .= '<span>已自动将分类<strong>' . $html['cname'] . '</strong>';
                         $html['cname'] = $cname;
                         $msg .= '转换为<strong>' . $html['cname'] . '</strong></span>';
                     }
                 }
             }
             $stauts = 1;
             if ($config['direct'] && $html['cid'] != 999) {
                 //直接入库video
                 if (!$this->CModel->videoImport($v['url'], $html)) {
                     $msg .= $this->CModel->getError();
                     //continue;
                 } else {
                     $msg .= '影片入库保存成功.';
                     $stauts = 2;
                 }
             }
             $updata = array('status' => $stauts, 'data' => collect::array2string($html), 'addtime' => time());
             if (!empty($html['title'])) {
                 $updata['title'] = $html['title'];
             }
             $Update = $this->ContDB->where('id=' . $v['id'])->save($updata);
             if ($Update === 'false') {
                 //失败则跳过
                 $msg .= ' 采集入库失败!';
                 continue;
             } else {
                 $msg .= ' 采集成功.';
             }
             //$i++;
             if ($config['stime'] > 0) {
                 //间隔时间
                 sleep($config['stime']);
                 $msg .= '暂停' . $config['stime'] . '秒继续采集...';
             }
             $result = array('con' => $this->ConvShow($html), 'url' => $v['url'], 'msg' => $msg);
         }
         $StrUrl = '?s=Admin/CustomCollect/ColRun/action/real/type/content/nid/' . $config['id'] . '/page/' . ($page + 1) . '/total/' . $all . '/stime/' . $config['stime'];
         $result['StrUrl'] = $StrUrl;
         $result['total'] = $all;
         $result['already'] = $page * $config['pagesize'];
         $result['percent'] = $result['already'] / $result['total'] * 200;
         if ($total_page >= $page) {
             //添加缓存--续采
             $CacheUrl = '?s=Admin/CustomCollect/ColRun/action/real/type/content/nid/' . $config['id'] . '/page/' . $page . '/total/' . $all . '/stime/' . $config['stime'];
             F('_gxcms/ColCache', $CacheUrl);
         }
         return $result;
     } else {
         if (F('_gxcms/ColCache')) {
             F('_gxcms/ColCache', NUll);
         }
         $this->error = '没有要采集的影片';
         return false;
     }
 }