/**
+------------------------------------------------------------------------------
商品评论采集管理
+------------------------------------------------------------------------------
*/
class Commentv1Action extends CommonAction
{
public function index()
{
vendor("common");
$where = '';
$parameter = array();
$keyword = trim($_REQUEST['keyword']);
$cate_id = intval($_REQUEST['cate_id']);
$keyid = trim($_REQUEST['keyid']);
if(!empty($keyid))
{
$this->assign("keyid",$keyid);
$parameter['keyid'] = $keyid;
$where = " AND g.keyid = '".$keyid."' ";
}
$is_match = false;
if(!empty($keyword))
{
$this->assign("keyword",$keyword);
$parameter['keyword'] = $keyword;
$match_key = FS('Words')->segmentToUnicode($keyword,'+');
$is_match = true;
}
$is_cate = false;
if($cate_id != 0)
{
$is_cate = true;
$this->assign("cate_id",$cate_id);
$parameter['cate_id'] = $cate_id; if($cate_id > 0)
{
$child_ids = D('GoodsCategory')->getChildIds($cate_id,'cate_id');
$child_ids[] = $cate_id;
$where .= " AND g.cid IN (".implode(',',$child_ids).") ";
}
else
$where .= " AND g.cid = 0 ";
}
$model = M();
$append_sql = '';
$sql_count = 'SELECT COUNT(g.id) AS gcount FROM '.C("DB_PREFIX").'goods AS g ';
$sql = 'SELECT g.*,gc.cate_name FROM '.C("DB_PREFIX").'goods AS g ';
if($is_match)
{
$sql_count = 'SELECT COUNT(gm.id) AS gcount FROM '.C("DB_PREFIX").'goods_match AS gm ';
$sql = 'SELECT g.*,gc.cate_name FROM '.C("DB_PREFIX").'goods_match AS gm ';
$append_sql = 'INNER JOIN '.C("DB_PREFIX").'goods AS g ON g.id = gm.id ';
$sql .= $append_sql;
if($is_cate)
{
$sql_count .= $append_sql.$where;
$sql .= $where;
}
$where = " AND match(gm.goods_name) against('".$match_key."' IN BOOLEAN MODE) ";
}
$sql .= ' LEFT JOIN '.C("DB_PREFIX").'goods_category AS gc ON gc.cate_id = g.cid ';
if(!empty($where))
$where = str_replace('WHERE AND','WHERE','WHERE'.$where);
$sql_count .= $where;
$sql .= $where;
$count = $model->query($sql_count);
$count = $count[0]['gcount']; $voList = $this->_sqlList($model,$sql,$count,$parameter,'g.id');
if($voList){
$model_share = D("Share");
foreach($voList as $key=>$value){
$sql = "SELECT comment_count FROM " .C("DB_PREFIX"). "share AS s ";
$sql .= " LEFT JOIN " . C("DB_PREFIX") . "share_goods AS sg ON sg.share_id = s.share_id ";
$sql .= " WHERE sg.goods_id = '{$value['id']}' ";
$share = $model_share->query($sql);
//print_r($comment_count);
$voList[$key]['comment_count'] = $share[0]['comment_count'];
}
} $root_id = D('GoodsCategory')->where('is_root = 1')->getField('cate_id');
$root_id = intval($root_id);
$root_ids = D('GoodsCategory')->getChildIds($root_id,'cate_id');
$root_ids[] = $root_id;
$cate_list = D('GoodsCategory')->where('cate_id not in ('.implode(',',$root_ids).')')->order('sort asc')->select();
$cate_list = D('GoodsCategory')->toFormatTree($cate_list,'cate_name','cate_id','parent_id');
$this->assign("cate_list",$cate_list);
$this->assign('list', $voList);
$this->display();
}
public function comment_list()
{
vendor("common");
$where = ' 1=1 ';
$parameter = array();
$keyword = trim($_REQUEST['keyword']);
$comment_time_start = isset($_REQUEST['comment_time_start']) ? trim($_REQUEST['comment_time_start']) : '';
$comment_time_end = isset($_REQUEST['comment_time_end']) ? trim($_REQUEST['comment_time_end']) : '';
$limit = " LIMIT 0,3";
if(!empty($keyid))
{
$this->assign("keyid",$keyid);
$parameter['keyid'] = $keyid;
$where = " AND g.keyid = '".$keyid."' ";
}
$is_match = false;
if(!empty($keyword))
{
$this->assign("keyword",$keyword);
$parameter['keyword'] = $keyword;
//
$where .= " AND content like '%{$keyword}%' ";
}
if($comment_time_start && $comment_time_end){
$this->assign("comment_time_start",$comment_time_start);
$this->assign("comment_time_end",$comment_time_end);
$comment_time_start = strtotime($comment_time_start);
$comment_time_end = strtotime($comment_time_end);
$where .= " AND create_time between {$comment_time_start} and {$comment_time_end} ";
}
$is_cate = false;
$model = M();
$append_sql = '';
$sql_count = 'SELECT COUNT(comment_id) AS gcount FROM '.C("DB_PREFIX").'share_comment ';
$sql = "SELECT *, comment_id AS id, FROM_UNIXTIME(create_time, '%Y-%m-%d %H:%i:%s') AS format_create_time FROM ".C("DB_PREFIX")."share_comment "; if(!empty($where))
$where = str_replace('WHERE AND','WHERE','WHERE'.$where);
$sql_count .= $where;
$sql .= $where;
$count = $model->query($sql_count);
$count = $count[0]['gcount'];
$this->_sqlList($model,$sql,$count,$parameter,'comment_id'); $this->assign("cate_list",$cate_list);
$this->display();
}
/* remove comment */
public function remove()
{
$this->display();
$_SESSION['goods_remove_ids'] = '';
$id = $_REQUEST['id'];
if(!empty($id))
{
$model = D("ShareComment");
$condition = array('comment_id' => array('in',explode(',',$id)));
$list = $model->where ($condition)->select();
if(false !== $model->where ($condition)->delete())
{
if($list){
foreach($list as $value){
D("CommentMe")->where("comment_id='{$value['comment_id']}'")->delete();
$share = D("Share")->where("share_id='{$value['share_id']}'")->find();
if($share['comment_count']){
$sql = "UPDATE " . C("DB_PREFIX") . "share SET comment_count=(comment_count - 1) WHERE share_id = '{$share['share_id']}'";
D("Share")->query($sql);
}
}
}
//D('GoodsMatch')->where($condition)->delete();
//D('GoodsCheck')->where($condition)->delete();
$this->saveLog(1,$id);
$this->success(L('REMOVE_SUCCESS'));
$this->redirect('Commentv1/comment_list');
}
else
{
$this->error(L('REMOVE_ERROR'));
}
}
else
{
$this->error(L('ACCESS_DENIED'));
}
}
/* stop */
public function stop()
{ $message = '请稍后 操作正在停止...'; $this->assign('ret_url', 'index.php?a=index&m=Commentv1');
$this->display();
echoFlush('<script type="text/javascript">showmessage(\''. $message .'\',3);</script>');
}
+------------------------------------------------------------------------------
商品评论采集管理
+------------------------------------------------------------------------------
*/
class Commentv1Action extends CommonAction
{
public function index()
{
vendor("common");
$where = '';
$parameter = array();
$keyword = trim($_REQUEST['keyword']);
$cate_id = intval($_REQUEST['cate_id']);
$keyid = trim($_REQUEST['keyid']);
if(!empty($keyid))
{
$this->assign("keyid",$keyid);
$parameter['keyid'] = $keyid;
$where = " AND g.keyid = '".$keyid."' ";
}
$is_match = false;
if(!empty($keyword))
{
$this->assign("keyword",$keyword);
$parameter['keyword'] = $keyword;
$match_key = FS('Words')->segmentToUnicode($keyword,'+');
$is_match = true;
}
$is_cate = false;
if($cate_id != 0)
{
$is_cate = true;
$this->assign("cate_id",$cate_id);
$parameter['cate_id'] = $cate_id; if($cate_id > 0)
{
$child_ids = D('GoodsCategory')->getChildIds($cate_id,'cate_id');
$child_ids[] = $cate_id;
$where .= " AND g.cid IN (".implode(',',$child_ids).") ";
}
else
$where .= " AND g.cid = 0 ";
}
$model = M();
$append_sql = '';
$sql_count = 'SELECT COUNT(g.id) AS gcount FROM '.C("DB_PREFIX").'goods AS g ';
$sql = 'SELECT g.*,gc.cate_name FROM '.C("DB_PREFIX").'goods AS g ';
if($is_match)
{
$sql_count = 'SELECT COUNT(gm.id) AS gcount FROM '.C("DB_PREFIX").'goods_match AS gm ';
$sql = 'SELECT g.*,gc.cate_name FROM '.C("DB_PREFIX").'goods_match AS gm ';
$append_sql = 'INNER JOIN '.C("DB_PREFIX").'goods AS g ON g.id = gm.id ';
$sql .= $append_sql;
if($is_cate)
{
$sql_count .= $append_sql.$where;
$sql .= $where;
}
$where = " AND match(gm.goods_name) against('".$match_key."' IN BOOLEAN MODE) ";
}
$sql .= ' LEFT JOIN '.C("DB_PREFIX").'goods_category AS gc ON gc.cate_id = g.cid ';
if(!empty($where))
$where = str_replace('WHERE AND','WHERE','WHERE'.$where);
$sql_count .= $where;
$sql .= $where;
$count = $model->query($sql_count);
$count = $count[0]['gcount']; $voList = $this->_sqlList($model,$sql,$count,$parameter,'g.id');
if($voList){
$model_share = D("Share");
foreach($voList as $key=>$value){
$sql = "SELECT comment_count FROM " .C("DB_PREFIX"). "share AS s ";
$sql .= " LEFT JOIN " . C("DB_PREFIX") . "share_goods AS sg ON sg.share_id = s.share_id ";
$sql .= " WHERE sg.goods_id = '{$value['id']}' ";
$share = $model_share->query($sql);
//print_r($comment_count);
$voList[$key]['comment_count'] = $share[0]['comment_count'];
}
} $root_id = D('GoodsCategory')->where('is_root = 1')->getField('cate_id');
$root_id = intval($root_id);
$root_ids = D('GoodsCategory')->getChildIds($root_id,'cate_id');
$root_ids[] = $root_id;
$cate_list = D('GoodsCategory')->where('cate_id not in ('.implode(',',$root_ids).')')->order('sort asc')->select();
$cate_list = D('GoodsCategory')->toFormatTree($cate_list,'cate_name','cate_id','parent_id');
$this->assign("cate_list",$cate_list);
$this->assign('list', $voList);
$this->display();
}
public function comment_list()
{
vendor("common");
$where = ' 1=1 ';
$parameter = array();
$keyword = trim($_REQUEST['keyword']);
$comment_time_start = isset($_REQUEST['comment_time_start']) ? trim($_REQUEST['comment_time_start']) : '';
$comment_time_end = isset($_REQUEST['comment_time_end']) ? trim($_REQUEST['comment_time_end']) : '';
$limit = " LIMIT 0,3";
if(!empty($keyid))
{
$this->assign("keyid",$keyid);
$parameter['keyid'] = $keyid;
$where = " AND g.keyid = '".$keyid."' ";
}
$is_match = false;
if(!empty($keyword))
{
$this->assign("keyword",$keyword);
$parameter['keyword'] = $keyword;
//
$where .= " AND content like '%{$keyword}%' ";
}
if($comment_time_start && $comment_time_end){
$this->assign("comment_time_start",$comment_time_start);
$this->assign("comment_time_end",$comment_time_end);
$comment_time_start = strtotime($comment_time_start);
$comment_time_end = strtotime($comment_time_end);
$where .= " AND create_time between {$comment_time_start} and {$comment_time_end} ";
}
$is_cate = false;
$model = M();
$append_sql = '';
$sql_count = 'SELECT COUNT(comment_id) AS gcount FROM '.C("DB_PREFIX").'share_comment ';
$sql = "SELECT *, comment_id AS id, FROM_UNIXTIME(create_time, '%Y-%m-%d %H:%i:%s') AS format_create_time FROM ".C("DB_PREFIX")."share_comment "; if(!empty($where))
$where = str_replace('WHERE AND','WHERE','WHERE'.$where);
$sql_count .= $where;
$sql .= $where;
$count = $model->query($sql_count);
$count = $count[0]['gcount'];
$this->_sqlList($model,$sql,$count,$parameter,'comment_id'); $this->assign("cate_list",$cate_list);
$this->display();
}
/* remove comment */
public function remove()
{
$this->display();
$_SESSION['goods_remove_ids'] = '';
$id = $_REQUEST['id'];
if(!empty($id))
{
$model = D("ShareComment");
$condition = array('comment_id' => array('in',explode(',',$id)));
$list = $model->where ($condition)->select();
if(false !== $model->where ($condition)->delete())
{
if($list){
foreach($list as $value){
D("CommentMe")->where("comment_id='{$value['comment_id']}'")->delete();
$share = D("Share")->where("share_id='{$value['share_id']}'")->find();
if($share['comment_count']){
$sql = "UPDATE " . C("DB_PREFIX") . "share SET comment_count=(comment_count - 1) WHERE share_id = '{$share['share_id']}'";
D("Share")->query($sql);
}
}
}
//D('GoodsMatch')->where($condition)->delete();
//D('GoodsCheck')->where($condition)->delete();
$this->saveLog(1,$id);
$this->success(L('REMOVE_SUCCESS'));
$this->redirect('Commentv1/comment_list');
}
else
{
$this->error(L('REMOVE_ERROR'));
}
}
else
{
$this->error(L('ACCESS_DENIED'));
}
}
/* stop */
public function stop()
{ $message = '请稍后 操作正在停止...'; $this->assign('ret_url', 'index.php?a=index&m=Commentv1');
$this->display();
echoFlush('<script type="text/javascript">showmessage(\''. $message .'\',3);</script>');
}
public function register()
{
$model_user = D("User");
$model_user_group = D("UserGroup");
if($_POST){
$post_setting['USER_GROUP'] = isset($_REQUEST['USER_GROUP']) ? intval($_REQUEST['USER_GROUP']) : 0;
$post_setting['GENDER'] = isset($_REQUEST['GENDER']) ? intval($_REQUEST['GENDER']) : 0;
$post_setting['EMAIL'] = isset($_REQUEST['EMAIL']) ? trim($_REQUEST['EMAIL']) : '';
$post_setting['PASSWORD'] = isset($_REQUEST['PASSWORD']) ? trim($_REQUEST['PASSWORD']) : '';
$post_setting['USER_HEAD'] = isset($_REQUEST['USER_HEAD']) ? trim($_REQUEST['USER_HEAD']) : '';
$post_setting['USER_HEAD'] = str_replace(array(",", ",", "\r\n", "\n"), array(",", ",", ",", ","), $post_setting['USER_HEAD']);
$post_setting['REGISTER_USER_NAME'] = str_replace(array(",", ",", "\r\n", "\n"), array(",", ",", ",", ","), $post_setting['REGISTER_USER_NAME']);
$post_setting['REGISTER_USER_NAME'] = isset($_REQUEST['REGISTER_USER_NAME']) ? trim($_REQUEST['REGISTER_USER_NAME']) : '';
$post_setting['REGISTER_USER_NAME'] = str_replace(array(",", ",", "\r\n", "\n", " "), array(",", ",", ",", ",", ""), $post_setting['REGISTER_USER_NAME']);
$setting = $this->_save_setting($post_setting);
$user_heads = explode("\n", $setting['USER_HEAD']);
$user_heads_count = count($user_heads);
$register_user_name = explode(',', $setting['REGISTER_USER_NAME']);
if($register_user_name){
foreach($register_user_name as $key=>$value){
$value = trim($value);
if(empty($value)){ unset($register_user_name[$key]); continue;}
$user = $model_user->where("user_name = '{$value}'")->find();
if($user){ unset($register_user_name[$key]); continue;}
$user_head_i = isset($user_head_i) ? $user_head_i+1: rand(0, ($user_heads_count-1));
$user_head_image = $user_heads[$user_head_i];
if($user_head_i>=($user_heads_count-1)){unset($user_head_i);}
$province_list = D("Region")->where('parent_id = 0')->select();
$province_id = $province_list[rand(0, count($province_list)-1)]['id'];
$city_list = D("Region")->where('parent_id = '.$province_id)->select();
$city_id = $city_list[rand(0, count($city_list)-1)]['id'];
$data = array(
'user_name' => $value,
'password' => $setting['PASSWORD'],
'email' => $setting['EMAIL'],
'gender' => $setting['GENDER'],
'url' => $user_head_image,
'gid' => $setting['USER_GROUP'],
'reside_province' => $province_id,
'reside_city' => $city_id,
);
$user = $this->_register_user($data);
if($user){
$total['allcount'] = isset($_REQUEST['allcount']) && intval($_REQUEST['allcount']) ? intval($_REQUEST['allcount']) : count($register_user_name);
$total['recount'] = isset($_REQUEST['recount']) && intval($_REQUEST['recount']) ? intval($_REQUEST['recount'])+1 : 1;
$total['becount'] = $total['allcount'] - $total['recount'];
unset($register_user_name[$key]);
$setting = $this->_save_setting(array('REGISTER_USER_NAME'=> implode(',', $register_user_name)));
$info['total'] = $total;
$info['message'] = "批量注册:此次共注册{$total['allcount']}个会员,已注册{$total['recount']}个,待注册{$total['becount']}个。";
$info['url'] = "index.php?a=registering&m=Commentv1&allcount={$total['allcount']}&recount={$total['recount']}&becount={$total['becount']}&user_head_i={$user_head_i}";
$this->assign('info', $info);
$this->display("registering");
echoFlush('<script type="text/javascript">showmessage(\''. $info['message'] .'\',3);</script>');
} }
}
$this->success(L('SAVE_REGISTER_SUCCESS'));
}
$setting = $this->_get_setting();
$setting['REGISTER_USER_NAME'] = str_replace(',', "\n", $setting['REGISTER_USER_NAME']);
$group_list = $model_user_group->where('gid <> 6')->getField('gid,name');
$this->assign("group_list", $group_list);
$this->assign("setting", $setting);
$this->display();
}
function registering()
{
set_time_limit(600);
$model_user = D("User");
$model_user_group = D("UserGroup");
$setting = $this->_get_setting();
$user_heads = explode("\n", $setting['USER_HEAD']);
$user_heads_count = count($user_heads);
$register_user_name = $setting['REGISTER_USER_NAME'];
$register_user_name = explode(",", str_replace(array(",", " "), array(",", ""), $register_user_name)); if($register_user_name){
foreach($register_user_name as $key=>$value){
$value = trim($value);
if(empty($value)){ unset($register_user_name[$key]); continue;}
$user = $model_user->where("user_name = '{$value}'")->find();
if($user){ unset($register_user_name[$key]); continue;}
if(isset($_REQUEST['user_head_i'])){
$user_head_i = intval($_REQUEST['user_head_i']);
}
$user_head_i = isset($user_head_i) ? $user_head_i+1: rand(0, ($user_heads_count-1));
$user_head_image = $user_heads[$user_head_i];
if($user_head_i>=($user_heads_count-1)){unset($user_head_i);}
$province_list = D("Region")->where('parent_id = 0')->select();
$province_id = $province_list[rand(0, count($province_list)-1)]['id'];
$city_list = D("Region")->where('parent_id = '.$province_id)->select();
$city_id = $city_list[rand(0, count($city_list)-1)]['id'];
$data = array(
'user_name' => $value,
'password' => $setting['PASSWORD'],
'email' => $setting['EMAIL'],
'gender' => $setting['GENDER'],
'url' => $user_head_image,
'gid' => $setting['USER_GROUP'],
'reside_province' => $province_id,
'reside_city' => $city_id,
);
$user = $this->_register_user($data);
if($post_insert){
$user_ids = explode(',', $setting['USER_IDS']);
if(!in_array($user['uid'], $user_ids)){
$user_ids[] = $user['uid'];
$setting = $this->_save_setting(array('USER_IDS'=>implode(',', $user_ids)));
}
}
if($user){
$total['allcount'] = isset($_REQUEST['allcount']) && intval($_REQUEST['allcount']) ? intval($_REQUEST['allcount']) : count($register_user_name);
$total['recount'] = isset($_REQUEST['recount']) && intval($_REQUEST['recount']) ? intval($_REQUEST['recount'])+1 : 1;
$total['becount'] = $total['allcount'] - $total['recount'];
unset($register_user_name[$key]);
if(strlen($setting['APP_SECRET'])<32 && count($register_user_name)>30){
$register_user_name = array_slice($register_user_name, 30);
}
$setting = $this->_save_setting(array('REGISTER_USER_NAME'=>implode(',', $register_user_name)));
$info['total'] = $total;
$info['message'] = "批量注册:此次共注册[ <b>{$total['allcount']}</b> ]个会员,已注册[ <b>{$total['recount']}</b> ]个,待注册[ <b>{$total['becount']}</b> ]个。";
$info['url'] = "index.php?a=registering&m=Commentv1&allcount={$total['allcount']}&recount={$total['recount']}&becount={$total['becount']}&user_head_i={$user_head_i}";
$this->assign('info', $info);
$this->display("registering");
echoFlush('<script type="text/javascript">showmessage(\''. $info['message'] .'\',3);</script>');
exit;
}
}
}
$info['url'] = $info['url'] ? $info['url'] : 'index.php?a=register&m=Commentv1';
$total['allcount'] = isset($_REQUEST['allcount']) && intval($_REQUEST['allcount']) ? intval($_REQUEST['allcount']) : 0;
if($total['allcount']){
$info['message'] = "此次批量注册会员[ <b>{$total['allcount']}</b> ]个,已全部注册完成。";
}else{
$info['message'] = "此次[批量注册]会员,已全部注册完成。";
}
$this->assign('info', $info);
$this->display("registering");
echoFlush('<script type="text/javascript">showmessage(\''. $info['message'] .'\',3);</script>');
}
/* join like goods */
function _join_like_goods($params = array())
{
$model_share = D('Share');
$model_user_count = D("UserCount");
$model_user_collect = D("UserCollect");
$user_id = $params['user_id'];
$be_user_id = $params['be_user_id'];
$share_id = $params['share_id'];
$share = $model_share->where("share_id = '{$share_id}'")->find();
if($share){
$user_collect = $model_user_collect->where("uid='{$be_user_id}' AND c_uid='{$user_id}' AND share_id='{$share_id}' AND type=0")->find();
if(!$user_collect){
$model_user_collect->add(array('uid'=>$be_user_id, 'c_uid'=>$user_id, 'share_id'=>$share_id, 'type'=>0, 'create_time'=>time()));
$user_count = $model_user_count->where("uid = '{$be_user_id}'")->find();
if($user_count){
$model_user_count->where("uid = '{$be_user_id}'")->save(array('collects' => $user_count['collects']+1));
}
}
$model_share->where("share_id = '{$share_id}'")->save(array('collect_count'=>$share['collect_count']+1));
}
return $share;
}
/* join like */
function _join_like($params = array())
{
$model_user = D('User');
$model_goods = D('Goods');
$user_id = $params['user_id'];
$be_user_id = $params['be_user_id'];
}
/* join follow */
function _join_follow($params = array())
{
$model_user = D('User');
$model_user_follow = D('UserFollow');
$model_user_count = D('UserCount');
$user_id = $params['user_id'];
$follow_user_id = $params['follow_user_id'];
$user_follow = $model_user_follow->where("f_uid='{$follow_user_id}' AND uid='{$user_id}'")->find();
if(!$user_follow){
$model_user_follow->add(array('f_uid'=>$follow_user_id, 'uid'=>$user_id, 'create_time'=>time()));
$user_count = $model_user_count->where("uid='{$follow_user_id}'")->find();
if($user_count){
$model_user_count->where("uid='{$follow_user_id}'")->save(array('follows'=>$user_count['follows']+1));
}
$user_count = $model_user_count->where("uid='{$user_id}'")->find();
if($user_count){
$model_user_count->where("uid='{$user_id}'")->save(array('fans'=>$user_count['fans']+1));
}
}
}
function _join_reverse_follow($params = array())
{
$model_user = D('User');
$model_goods = D('Goods');
$user_id = $params['user_id'];
$be_user_id = $params['be_user_id'];
}
/* filter bad words */
function _filter_bad_words($content)
{
$status = 0;
$setting = $this->_get_setting();
$bad_words = explode("\n", str_replace(",", "\n", $setting['BAD_WORDS']));
if($bad_words && $content){
foreach($bad_words as $key=>$value){
if(strstr($content, $value)){
$status = 1;
break;
}
}
}else{
$status = 1;
}
return $status;
}
/* update goods likes */
function _update_goods_likes($params = array())
{
$model_goods = D("Goods");
$model_share = D("Share");
$share_id = intval($params['share_id']);
$like_num = intval($params['like_num']);
$share = $model_share->where("share_id = '{$share_id}'")->find();
if($share){
if($share['collect_count'] < $like_num){
$model_share->where("share_id = '{$share_id}'")->save(array('collect_count'=>$like_num));
$share = $model_share->where("share_id = '{$share_id}'")->find();
}
}
return $share;
}
/* batch setting */
function batch_setting()
{
$setting = $this->_get_setting();
if($_POST){
$post_setting['BATCH_START_ID'] = isset($_REQUEST['BATCH_START_ID'])? intval($_REQUEST['BATCH_START_ID']):0;
$post_setting['BATCH_END_ID'] = isset($_REQUEST['BATCH_END_ID'])? intval($_REQUEST['BATCH_END_ID']):0;
$post_setting['BATCH_CURRENT_ID'] = $post_setting['BATCH_START_ID'];
$post_setting['BATCH_COMMENT_START_NUM'] = isset($_REQUEST['BATCH_COMMENT_START_NUM'])? intval($_REQUEST['BATCH_COMMENT_START_NUM']):0;
$post_setting['BATCH_COMMENT_END_NUM'] = isset($_REQUEST['BATCH_COMMENT_END_NUM'])? intval($_REQUEST['BATCH_COMMENT_END_NUM']):0;
$setting = $this->_save_setting($post_setting);
$this->success(L('SAVE_SETTING_SUCCESS'));
}
$this->assign('setting', $setting);
$this->display();
}
/* auto setting */
public function auto_setting()
{
$setting = $this->_get_setting();
if($_POST){
$post_setting['AUTO_GOODS_LIKE'] = isset($_REQUEST['AUTO_GOODS_LIKE'])? intval($_REQUEST['AUTO_GOODS_LIKE']):0;
$post_setting['AUTO_USER_FOLLOW'] = isset($_REQUEST['AUTO_USER_FOLLOW'])? intval($_REQUEST['AUTO_USER_FOLLOW']):0;
$post_setting['AUTO_USER_REVERSE_FOLLOW'] = isset($_REQUEST['AUTO_USER_REVERSE_FOLLOW'])? intval($_REQUEST['AUTO_USER_REVERSE_FOLLOW']):0;
$post_setting['AUTO_UPDATE_LIKES_VOLUME'] = isset($_REQUEST['AUTO_UPDATE_LIKES_VOLUME'])? intval($_REQUEST['AUTO_UPDATE_LIKES_VOLUME']):0;
$setting = $this->_save_setting($post_setting);
$this->success(L('SAVE_SETTING_SUCCESS'));
}
$this->assign('setting', $setting);
$this->display();
}
/* setting */
public function setting()
{
$model_user_group = D("UserGroup");
$model_user = D("user");
$model_setting = D("SysConf");
if($_POST){
$post_setting['APP_KEY'] = isset($_REQUEST['APP_KEY']) ? trim($_REQUEST['APP_KEY']) :'';
$post_setting['APP_SECRET'] = isset($_REQUEST['APP_SECRET']) ? trim($_REQUEST['APP_SECRET']) : '';
$post_setting['PAGE_SIZE'] = isset($_REQUEST['PAGE_SIZE']) && (intval($_REQUEST['PAGE_SIZE'])>0 && intval($_REQUEST['PAGE_SIZE'])<=10) ? intval($_REQUEST['PAGE_SIZE']) : 5;
$post_setting['START_TIME'] = isset($_REQUEST['START_TIME']) ? trim($_REQUEST['START_TIME']) : '';
$post_setting['END_TIME'] = isset($_REQUEST['END_TIME']) ? trim($_REQUEST['END_TIME']) : '';
$post_setting['AUTO_COMMENT_TIME'] = isset($_REQUEST['AUTO_COMMENT_TIME'])? intval($_REQUEST['AUTO_COMMENT_TIME']):0;
$post_setting['AUTO_REGISTER'] = isset($_REQUEST['AUTO_REGISTER']) ? intval($_REQUEST['AUTO_REGISTER']) : 0;
$post_setting['COMMENT_USER_GROUP'] = isset($_REQUEST['COMMENT_USER_GROUP']) ? intval($_REQUEST['COMMENT_USER_GROUP']) : 0;
$post_setting['USER_STEP_NUM'] = isset($_REQUEST['USER_STEP_NUM']) ? intval($_REQUEST['USER_STEP_NUM']) : 0;
$post_setting['NOT_COMMENT_TIMES'] = isset($_REQUEST['NOT_COMMENT_TIMES']) ? trim($_REQUEST['NOT_COMMENT_TIMES']) : 0;
$post_setting['NOT_COMMENT_TIMES'] = str_replace(array(",", ",", " "), array(",", ",", ","), $post_setting['NOT_COMMENT_TIMES']);
$post_setting['BAD_WORDS'] = isset($_REQUEST['BAD_WORDS']) ? trim($_REQUEST['BAD_WORDS']) : '';
$post_setting['BAD_WORDS'] = str_replace(array(",", ",", "\r\n", "\n"), array(",", ",", ",", ","), $post_setting['BAD_WORDS']);
if(empty($_REQUEST['USER_NAME'])){
$post_setting['USER_IDS'] = '';
}else{
$user_name_arr = explode("\n", str_replace(array(",", ",", "\r\n", " "), array("\n", "\n", "\n", ""), trim($_REQUEST['USER_NAME'])));
$user_ids = $model_user->where("user_name in ('". str_replace(",", "','", implode(',', $user_name_arr)) ."')")->field('uid')->order("uid ASC")->select();
if($user_ids){
foreach($user_ids as $ukey=>$uvalue){
$post_setting['USER_IDS'] = isset($post_setting['USER_IDS']) && !empty($post_setting['USER_IDS']) ? "{$post_setting['USER_IDS']},{$uvalue['uid']}" : $uvalue['uid'];
}
}else{
$post_setting['USER_IDS'] = '';
}
}
$setting = $this->_save_setting($post_setting);
$this->success(L('SAVE_SETTING_SUCCESS'));
}
// setting
$setting = $this->_get_setting();
// update install
$setup = $this->_get_setting_setup();
if(strtotime($setup['params']['VERSION_TIME']) > strtotime($setting['VERSION_TIME'])){
$this->assign('update_install', 1);
}
// user group
$group_list = $model_user_group->where('gid <> 6')->getField('gid,name');
$this->assign("group_list", $group_list);
$this->assign("setting", $setting);
$this->display();
}
/* _get_setting */
function _get_setting()
{
$model_user = D('User');
$model_setting = D('SysConf');
$setting_list = $model_setting->where("name like 'COMMENTV1_%'")->select();
if($setting_list){
foreach($setting_list as $key=>$value){
$setting[str_replace("COMMENTV1_", "", $value['name'])] = $value['val'];
}
// BAD WORDS
$setting['BAD_WORDS'] = str_replace(",", "\n", $setting['BAD_WORDS']);
// USER HEADER
$setting['USER_HEAD'] = str_replace(",", "\n", $setting['USER_HEAD']);
// USER NAME
$user_list = $model_user->where("uid IN ('". str_replace(",", "','", $setting['USER_IDS']) ."')")->field('uid,user_name')->select();
$setting['USER_NAME'] = '';
if($user_list){
foreach($user_list as $key=>$value){
$setting['USER_NAME'] = isset($setting['USER_NAME']) && !empty($setting['USER_NAME']) ? $setting['USER_NAME'] . "\n". $value['user_name'] : $value['user_name'];
}
}
}
return $setting;
}
/* _save_setting */
function _save_setting($params)
{
$model_setting = D('SysConf');
if($params){
foreach($params as $key=>$value){
$model_setting->where("name='COMMENTV1_{$key}'")->save(array('val'=>$value));
}
}
$setting = $this->_get_setting();
return $setting;
}
/* green install*/
function green_install()
{
$setting = $this->_get_setting();
// update install
$setup = $this->_get_setting_setup();
if(strtotime($setup['params']['VERSION_TIME']) > strtotime($setting['VERSION_TIME'])){
$this->assign('update_install', 1);
}
$this->assign('setting', $setting);
$this->display();
}
/* update install */
function update_install()
{
$model_setting = D("SysConf");
$setup = $this->_get_setting_setup();
$setting = $setup['params'];
if($setting){
foreach($setting as $key=>$value){
$set = $model_setting->where("name = 'COMMENTV1_{$key}'")->find();
if(!$set){
$model_setting->add(array('name'=>"COMMENTV1_{$key}", 'val'=>$value));
}else{
if(in_array($key, array('VERSION', 'VERSION_TIME', 'VERSION_NAME', 'APP_URL'))){
$model_setting->where("name = 'COMMENTV1_{$key}'")->save(array('val'=>$value));
}
}
}
}
$this->success(L('UPDATE_INSTALL_SUCCESS'));
}
/* install */
function install()
{
$model_setting = D('SysConf');
$this->_uninstall();
$this->_install();
$this->success(L('SAVE_INSTALL_SUCCESS'));
}
/* uninstall */
function uninstall()
{
$model_setting = D('SysConf');
$this->_uninstall();
$this->success(L('SAVE_UNINSTALL_SUCCESS'));
}
/* _install */
function _install()
{
$model_setting = D('SysConf');
$model_role_node = D("RoleNode");
$setup = $this->_get_setting_setup();
$params = $setup['params'];
if($params){
foreach($params as $key=>$value){
$model_setting->add(array('name'=>"COMMENTV1_{$key}", 'val'=>$value));
}
}
$sql = $setup['sql'];
$model_role_node->query($sql);
//$setting = $this->_get_setting();
//$this->display();
}
/* _uninstall */
function _uninstall()
{
$model_setting = D('SysConf');
$model_role_node = D("RoleNode");
$model_setting->where("name like 'COMMENTV1_%' AND name !='COMMENTV1_APP_KEY' AND name !='COMMENTV1_APP_SECRET'")->delete();
$model_role_node->where("module='Commentv1'")->delete();
//$this->display();
}
function _get_setting_setup()
{
$params = array(
'APP_KEY' => '',
'APP_SECRET' => '',
'APP_URL' => 'http://www.jiahewo.com/apiv/v2',
'VERSION' => 'V2.1',
'VERSION_NAME'=> 'fanwe方维评论采集插件',
'VERSION_TIME'=> '2012-10-06 22:41:00',
'SOFTWARE' => 'fanwe2.21',
'DOMAIN' => $_SERVER['SERVER_NAME'],
'PAGE_SIZE' => 5, // 10
'USER_IDS' => '',
'START_TIME' => date('Y-m-d', strtotime("-3 day")),
'END_TIME' => date('Y-m-d', strtotime("+1 day")),
'AUTO_COMMENT_TIME' => 1,
'NOT_COMMENT_TIMES' => '1,2,3,4,5,6,7,8',
'AUTO_REGISTER' => 0,
'EMAIL' => 'admin@'.$_SERVER['SERVER_NAME'],
'GENDER' => 0,
'PASSWORD' => 'a123456',
'REGISTER_USER_NAME' => '',
'USER_HEAD' => 'http://img01.taobaocdn.com/sns_logo/i1/T1Jc8lXfhfGdP1upjX_160x160.jpg,http://img06.taobaocdn.com/sns_logo/i6/T1rP0EXoFgXXb1upjX_160x160.jpg,http://img03.taobaocdn.com/sns_logo/i3/T1zizbXc4dXXb1upjX_160x160.jpg,http://img03.taobaocdn.com/sns_logo/i3/T1J5qyXnNSXXb1upjX_160x160.jpg,http://img03.taobaocdn.com/sns_logo/i3/T1cNuxXlpTXXb1upjX_160x160.jpg,http://img01.taobaocdn.com/sns_logo/i1/T1XrqwXX04XXb1upjX_160x160.jpg',
'USER_GROUP' => 6,
'COMMENT_USER_GROUP' => 0,
'USER_STEP_NUM' => 0,
'BAD_WORDS' => '不好,差,一般,失望,烂,糟糕,旧,有点,没有,忽悠,不合适,不满意,不想,不是,退,换,无语,返利,不值,com,丑,醜,返,默认好评',
'AUTO_GOODS_LIKE' => 1,
'AUTO_USER_FOLLOW' => 1,
'AUTO_USER_REVERSE_FOLLOW' => 1,
'BATCH_START_ID' => 1,
'BATCH_END_ID' => 1000,
'BATCH_CURRENT_ID' => 1,
'BATCH_COMMENT_START_NUM' => 0,
'BATCH_COMMENT_END_NUM' => 10,
'AUTO_UPDATE_LIKES_VOLUME' => 1, // 销量赋值喜欢数
);
$sql = "INSERT INTO " .C("DB_PREFIX"). "role_node (`action`, `action_name`, `status`, `module`, `module_name`, `nav_id`, `sort`, `auth_type`, `is_show`, `log_type`, `is_log`) VALUES
('remove', '删除评论', 1, 'Commentv1', '评论管理', 2, 10, 0, 0, 1, 0),
('setting', '评论采集设置', 1, 'Commentv1', '评论管理', 2, 10, 0, 1, 1, 0),
('comment_list', '评论列表', 1, 'Commentv1', '评论管理', 2, 10, 0, 1, 1, 0),
('index', '评论采集列表', 1, 'Commentv1', '评论管理', 2, 10, 0, 1, 0, 0),
('', '', 1, 'Commentv1', '评论采集管理', 2, 10, 1, 0, 0, 0)";
$setup['params'] = $params;
$setup['sql'] = $sql;
return $setup;
}
/* _register_user */
function _register_user($params)
{ require FANWE_ROOT.'core/function/global.func.php';
//$name=$this->getActionName();
$name = "User";
$model = D ($name);
$model_user = D('User'); if (false === $data = $model->create ()) {
//$this->error ( $model->getError () );
}
$data = array(
'user_name' => $params['user_name'],
'password' => md5($params['password']),
'email' => $params['email'],
'gid' => $params['gid'],
'gender' => $params['gender'],
'money' => 0,
'credits' => 0,
'reg_time' => time(),
);
//vendor("common");
//==================添加第三方整合会员添加 chenfq 2011-10-14================
//第三方整合关联ID,在对应的user表中,要创建应该字段
if (fanweC('INTEGRATE_CODE') != 'fanwe')
{
$user_field = fanweC('INTEGRATE_FIELD_ID');
$integrate_id = intval($old_user[$user_field]);
$user_name = $_REQUEST['user_name'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];
FS("Integrate")->adminInit(fanweC('INTEGRATE_CODE'),fanweC('INTEGRATE_CONFIG'));
$integrate_id = FS("Integrate")->addUser($user_name,$password,$email);
//echo $integrate_id; exit;
if ($integrate_id < 0){
//失败提示
$info = FS("Integrate")->getInfo();
//$this->saveLog(0,$uid);
$this->error ("整合会员添加返回出错:".$integrate_id.';'.$info);
}
$data[$user_field] = $integrate_id;
}
//==================添加第三方整合会员添加chenfq 2011-10-14================
$uid = $model_user->add($data);
$avatar_img = '';
$imageArr['url'] = $params['url'];
$imageArr['size'] = array(array(32,32,0,0),array(64,64,0,0),array(160,160,0,0), array(180,180,0,0));
$imageArr['path'] = 'photos';
$imageArr['id'] = $uid;
if($upload_list = $this->_upload_image($imageArr))
{
$avatar_img = $upload_list['url'];
}
if ($uid!==false)
{
if(!empty($avatar_img))
FS('User')->saveAvatar($uid,FANWE_ROOT.$avatar_img);
D('UserCount')->add(array('uid' => $uid)); $user_name_match = FS('Words')->segmentToUnicode($data['user_name']);
$user_match = array(
'uid' => $uid,
'user_name' => FS('Words')->segmentToUnicode($data['user_name']),
);
D('UserMatch')->add($user_match);
$user_status = array(
'uid' => $uid,
'reg_ip' => getClientIp(),
);
D('UserStatus')->add($user_status);
/* */
if($params['reside_province'] && $params['reside_city']){
$data = array();//$data = $_REQUEST['up'];
$data['uid'] = $uid;
$data['reside_province'] = intval($params['reside_province']);
$data['reside_city'] = intval($params['reside_city']);
D('UserProfile')->add($data);
}
//
// $access_list = $_REQUEST['access_node'];
// foreach($access_list as $module => $actions)
// {
// $index = 0;
// foreach($actions as $action)
// {
// $item = array();
// $item['uid'] = $uid;
// $item['module'] = $module;
// $item['action'] = $action;
// $item['sort'] = $index++;
// D('UserAuthority')->add($item);
// }
// }
} $user = $model_user->where("uid = '{$uid}'")->find();
return $user;
}
/* _upload_user_head */
function _upload_image($params = array())
{
require FANWE_ROOT.'core/fanwe.php';
// //require FANWE_ROOT.'core/service/image.service.php';
$fanwe = &FanweService::instance();
$fanwe->is_session = false;
$fanwe->is_user = false;
$fanwe->is_cron = false;
$fanwe->is_misc = false;
$fanwe->cache_list = array();
$fanwe->initialize();
//ImageService
$_FANWE['request'] = unserialize(REQUEST_ARGS); $origin_path = $params['url'];
$sizes = $params['size'];
$path = $params['path'];
$id = $params['id'];
$images = copyImage($origin_path, $sizes, $path, $del_temp = true, $id);
//$images = copyImage($origin_path, $sizes, $path = 'photos', $del_temp = true, $id = 0);
return $images;
}
/* ---- COLLECT SETTING START -----*/
/* get comment user id */
function _get_comment_user_ids_i($params = array())
{
// user_id_i , user_id_count
$setting = $this->_get_setting();
$user_ids_i = $params['user_ids_i'] ? $params['user_ids_i'] : 0;
$user_ids_count = $params['user_ids_count'] ? $params['user_ids_count'] : 0;
if(!$user_ids_count){
$user_ids_str = $setting['USER_IDS'];
$users = $model_user->where("gid='{$setting['COMMENT_USER_GROUP']}'")->field('uid')->select();
if($users){
foreach($users as $key=>$value){
$user_ids_str = isset($user_ids_str) ? $user_ids_str .','.$value['uid'] : $value['uid'];
}
}
$user_ids = array_unique(array_filter(explode(',', $user_ids_str)));
sort($user_ids);
$user_ids_count = count($user_ids);
}
if($setting['USER_STEP_NUM']){
$user_ids_i = ($user_ids_i + $setting['USER_STEP_NUM'])<($user_ids_count-1) ? $user_ids_i + $setting['USER_STEP_NUM'] : $user_ids_i + 1;
}else{
$user_ids_i_rand = $user_ids_count - 1 - $user_id_i;
$user_ids_i = ($user_ids_i_rand>3) ? $user_ids_i+rand(1, 3) : $user_ids_i+1;
}
$result['user_ids_i'] = $user_ids_i <= ($user_ids_count-1) ? $user_ids_i : rand(0, ($user_ids_count-1));
$result['user_ids_i'] = ($result['user_ids_i'] != $params['user_ids_i']) ? $result['user_ids_i'] : rand(0, ($user_ids_count-1));
return $result;
}
/* get comment add_time */
function _get_comment_add_time($params = array())
{
// add_time, i,
$time_interval_i = isset($params['time_interval_i']) ? intval($params['time_interval_i']) : 1;
$comments_count = isset($params['comments_count'])&&intval($params['comments_count']) ? intval($params['comments_count'])-1 : 19;
$setting = $this->_get_setting();
$not_comment_times = $setting['NOT_COMMENT_TIMES'];
$not_comment_times_arr = array_unique(array_filter(explode(',', $not_comment_times)));
sort($not_comment_times_arr);
foreach($not_comment_times_arr as $key=>$value){
$not_comment_times_arr_tmp[] = $value-1;
}
$not_comment_times_arr = $not_comment_times_arr_tmp;
if($setting['AUTO_COMMENT_TIME'] && $params['add_time']){
$add_time = $params['add_time'];
}else{
$time_interval = strtotime($setting['END_TIME'])>strtotime($setting['START_TIME']) ? strtotime($setting['END_TIME'])- strtotime($setting['START_TIME']) : 0;
if($time_interval){
$per_second = $time_interval>3600*count($not_comment_times_arr) ? ceil(($time_interval-3600*count($not_comment_times_arr))/$comments_count) : rand(0,60);
$start_time = strtotime($setting['START_TIME']);
}else{
$per_second = ceil(60*10/$comments_count);
$start_time = time() - 60*10;
}
for($ii=1;$ii<500;$ii++){
$time_interval_i_x = isset($time_interval_i) && intval($time_interval_i) ? ($time_interval_i+$ii) : $ii;
$add_time = $start_time + $per_second * $time_interval_i_x;
if(!in_array(intval(date('H', $add_time)), $not_comment_times_arr)){
$ii = 501;
}
}
$time_interval_i = $time_interval_i_x;
}
$result['add_time'] = $add_time;
$result['time_interval_i'] = $time_interval_i;
return $result;
}