/**
  * 文章推送
  */
 public function push()
 {
     if (IS_POST) {
         $id = $this->_post("id");
         $modelid = $this->_post('modelid');
         $catid = $this->_post("catid");
         $action = $this->_get("action");
         if (!$id || !$action || !$modelid || !$catid) {
             $this->error("参数不正确");
         }
         switch ($action) {
             //推荐位
             case "position_list":
                 $posid = $_POST['posid'];
                 if ($posid && is_array($posid)) {
                     $position_data_db = D('Position');
                     $fields = F("Model_field_" . $modelid);
                     $tablename = ucwords($this->Model[$modelid]['tablename']);
                     if (!$tablename) {
                         $this->error("模型不能为空!");
                     }
                     $ids = explode("|", $id);
                     $Content = new ContentModel($tablename);
                     foreach ($ids as $k => $aid) {
                         //取得信息
                         $re = $Content->relation(true)->where(array("id" => $aid))->find();
                         if ($re) {
                             //文章信息
                             $r = array_merge($re, $re[$tablename . '_data']);
                             unset($r[$tablename . '_data']);
                             //推送数据
                             $textcontent = array();
                             foreach ($fields as $_key => $_value) {
                                 //判断字段是否入库到推荐位字段
                                 if ($_value['isposition']) {
                                     $textcontent[$_key] = $r[$_key];
                                 }
                             }
                             //推送到推荐位
                             $status = $position_data_db->position_update($id, $modelid, $catid, $posid, $textcontent);
                             if ($status) {
                                 //更新信息推荐位标识
                                 $Content->relation(true)->where(array("id" => $aid))->save(array("posids" => 1));
                             }
                         }
                     }
                     $this->success("推送到推荐位成功!");
                 } else {
                     $this->error("请选择推荐位!");
                 }
                 break;
                 //同步发布到其他栏目
             //同步发布到其他栏目
             case "push_to_category":
                 $ids = explode("|", $id);
                 $relation = $this->_post("relation");
                 if (!$relation) {
                     $this->error("请选择需要推送的栏目!");
                 }
                 $relation = explode("|", $relation);
                 if (is_array($relation)) {
                     //过滤相同栏目和自身栏目
                     foreach ($relation as $k => $classid) {
                         if ($classid == $catid) {
                             unset($relation[$k]);
                         }
                     }
                     //去除重复
                     $relation = array_unique($relation);
                     if (count($relation) < 1) {
                         $this->error("请选择需要推送的栏目!");
                     }
                     $tablename = ucwords($this->Model[$modelid]['tablename']);
                     if (!$tablename) {
                         $this->error("模型不能为空!");
                     }
                     $Content = new ContentModel($tablename);
                     import('Content');
                     $ContentAPI = new Content();
                     foreach ($ids as $k => $aid) {
                         //取得信息
                         $r = $Content->relation(true)->where(array("id" => $aid))->find();
                         $linkurl = $r['url'];
                         if ($r) {
                             $ContentAPI->othor_catid($relation, $linkurl, $r, $modelid);
                         }
                     }
                     $this->success("推送其他栏目成功!");
                 } else {
                     $this->error("请选择需要推送的栏目!");
                 }
                 break;
             default:
                 $this->error("请选择操作!");
                 break;
         }
     } else {
         $id = $this->_get("id");
         $action = $this->_get("action");
         $modelid = $this->_get('modelid');
         $catid = $this->_get("catid");
         if (!$id || !$action || !$modelid || !$catid) {
             $this->error("参数不正确!");
         }
         $tpl = $action == "position_list" ? "push_list" : "push_to_category";
         switch ($action) {
             //推荐位
             case "position_list":
                 $position = F("Position");
                 if (!empty($position)) {
                     $array = array();
                     foreach ($position as $_key => $_value) {
                         if ($_value['modelid'] && $_value['modelid'] != $modelid || $_value['catid'] && strpos(',' . $this->categorys[$_value['catid']]['arrchildid'] . ',', ',' . $catid . ',') === false) {
                             continue;
                         }
                         $array[$_key] = $_value['name'];
                     }
                     $this->assign("Position", $array);
                 }
                 break;
                 //同步发布到其他栏目
             //同步发布到其他栏目
             case "push_to_category":
                 break;
             default:
                 $this->error("请选择操作!");
                 break;
         }
         $this->assign("id", $id);
         $this->assign("action", $action);
         $this->assign("modelid", $modelid);
         $this->assign("catid", $catid);
         $this->assign("show_header", true);
         $this->display($tpl);
     }
 }
 public function create()
 {
     unset($_GET['_URL_']);
     if (isset($_GET['start'])) {
         //每轮更新数
         $pagesize = (int) $this->_get("pagesize");
         $_GET['pagesize'] = $pagesize = $pagesize > 1 ? $pagesize : 100;
         //模型
         $_GET['modelid'] = $modelid = (int) $this->_get("modelid");
         //第几轮更新
         $page = $_GET['start'] = (int) $this->_get("start");
         //总共几轮
         $pages = (int) $this->_get("pages");
         //信息总数
         $total = (int) $this->_get("total");
         $model = F("Model");
         //如果是重建所有模型
         if ($modelid) {
             $table_name = ucwords($model[$modelid]['tablename']);
             if (!$table_name) {
                 $this->error("该模型不存在!");
             }
             $ContentDb = new ContentModel($table_name);
             if (!in_array($modelid, $this->config['modelid'])) {
                 $this->error("该模型无需重建!");
             }
             //取得总数
             if (!isset($_GET['total'])) {
                 $count = $ContentDb->where(array("status" => 99))->count();
                 //信息总数
                 $total = $_GET['total'] = $count;
                 //总共几轮
                 $pages = $_GET['pages'] = ceil($_GET['total'] / $pagesize);
                 //初始第一轮更新
                 $page = $_GET['start'] = 1;
             }
             $page = max(intval($page), 1);
             $offset = $pagesize * ($page - 1);
             $data = $ContentDb->relation(true)->where(array("status" => 99))->order(array("id" => "ASC"))->limit($offset . "," . $pagesize)->select();
             if (!$data) {
                 $data = array();
             }
             //数据处理
             foreach ($data as $r) {
                 //组合数据
                 $inputinfo = array();
                 $inputinfo['system'] = $r;
                 $inputinfo['model'] = $r[$table_name . "_data"];
                 $id = $r['id'];
                 $this->db->search_api($id, $inputinfo, $modelid);
             }
             if ($pages == $page || $page > $pages) {
                 $this->success("更新完成! ...", U("Search/create"));
                 exit;
             }
             if ($pages > $page) {
                 $page++;
                 $_GET['start'] = $page;
                 $creatednum = $offset + count($data);
                 $percent = round($creatednum / $total, 2) * 100;
                 $message = "有 <font color=\"red\">{$total}</font> 条信息 - 已完成 <font color=\"red\">{$creatednum}</font> 条(<font color=\"red\">{$percent}%</font>)";
                 $forward = U("Search/create", $_GET);
                 $this->assign("waitSecond", 200);
                 $this->success($message, $forward);
                 exit;
             }
         } else {
             //当没有选择模型更新时,进行全部可用模型数据更新
             $modelArr = $this->config['modelid'];
             $autoid = $this->_get("autoid");
             $autoid = $_GET['autoid'] ? intval($_GET['autoid']) : 0;
             if (!isset($modelArr[$autoid])) {
                 $this->success("更新完成! ...", U("Search/create"));
                 exit;
             }
             $modelid = $modelArr[$autoid];
             $table_name = ucwords($model[$modelid]['tablename']);
             if (!$table_name) {
                 $this->error("该模型不存在!");
             }
             $ContentDb = new ContentModel($table_name);
             //取得总数
             if (!isset($_GET['total'])) {
                 $count = $ContentDb->where(array("status" => 99))->count();
                 //信息总数
                 $total = $_GET['total'] = $count;
                 //总共几轮
                 $pages = $_GET['pages'] = ceil($_GET['total'] / $pagesize);
                 //初始第一轮更新
                 $page = $_GET['start'] = 1;
             }
             $page = max(intval($page), 1);
             $offset = $pagesize * ($page - 1);
             $data = $ContentDb->relation(true)->where(array("status" => 99))->order(array("id" => "ASC"))->limit($offset . "," . $pagesize)->select();
             if (!$data) {
                 $data = array();
             }
             //数据处理
             foreach ($data as $r) {
                 //组合数据
                 $inputinfo = array();
                 $inputinfo['system'] = $r;
                 $inputinfo['model'] = $r[$table_name . "_data"];
                 $id = $r['id'];
                 $this->db->search_api($id, $inputinfo, $modelid);
             }
             if ($pages == $page || $page > $pages) {
                 $autoid++;
                 $_GET['autoid'] = $autoid;
                 unset($_GET['total']);
                 $this->assign("waitSecond", 200);
                 $this->success("模型【" . $model[$modelid]['name'] . "】更新完成 ...", U("Search/create", $_GET));
                 exit;
             }
             if ($pages > $page) {
                 $page++;
                 $_GET['start'] = $page;
                 $creatednum = $offset + count($data);
                 $percent = round($creatednum / $total, 2) * 100;
                 $message = "【" . $model[$modelid]['name'] . "】有 <font color=\"red\">{$total}</font> 条信息 - 已完成 <font color=\"red\">{$creatednum}</font> 条(<font color=\"red\">{$percent}%</font>)";
                 $forward = U("Search/create", $_GET);
                 $this->assign("waitSecond", 200);
                 $this->success($message, $forward);
                 exit;
             }
         }
     } else {
         if (IS_POST) {
             //每轮更新数
             $pagesize = (int) $this->_post("pagesize");
             $pagesize = $pagesize > 1 ? $pagesize : 100;
             //模型
             $modelid = (int) $this->_post("modelid");
             if ($modelid) {
                 //删除旧的搜索数据
                 $this->db->where(array("modelid" => $modelid))->delete();
             } else {
                 //删除旧的搜索数据
                 $this->db->emptyTable();
             }
             $this->success("开始进行索引重建...", U("Search/create", array("start" => 1, "pagesize" => $pagesize, "modelid" => $modelid)));
         } else {
             $model = F("Model");
             $this->assign("models", $model);
             $this->assign("config", $this->config);
             $this->display();
         }
     }
 }