function ajax_feedback($data = array()) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $mesobj = $json->decode($data); //反json ,返回值为对象 //以下字段对应评论的表单页面 一定要一致 $datas['comment_title'] = $mesobj->comment_title; $datas['goods_id'] = $mesobj->goods_id; $goods_id = $datas['goods_id']; $uid = $this->Session->read('User.uid'); $datas['user_id'] = !empty($uid) ? $uid : 0; $datas['status'] = 2; if (strlen($datas['comment_title']) < 12) { $result['error'] = 2; $result['message'] = '评论内容不能太少!'; die($json->encode($result)); } $datas['addtime'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_from'] = Import::ip()->ipCity($ip); if ($this->App->insert('message', $datas)) { $result['error'] = 0; $result['message'] = '提问成功!我们会很快回答你的问题!'; } else { $result['error'] = 1; $result['message'] = '提问失败,请通过在线联系客服吧!'; } unset($datas, $data); $page = 1; $list = 2; //每页显示多少个 $start = ($page - 1) * $list; $tt = $this->App->findvar("SELECT COUNT(mes_id) FROM `{$this->App->prefix()}message` WHERE user_id='{$uid}' AND (goods_id IS NULL OR goods_id='')"); $rt['notgoodmespage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_myquestion_notgoods_page_list'); $sql = "SELECT distinct tb1.*,tb2.avatar,tb2.nickname,tb2.user_name AS dbusername FROM `{$this->App->prefix()}message` AS tb1 LEFT JOIN `{$this->App->prefix()}user` AS tb2 ON tb1.user_id=tb2.user_id WHERE tb1.user_id='{$uid}' AND (tb1.goods_id IS NULL OR tb1.goods_id='') ORDER BY tb1.addtime DESC LIMIT {$start},{$list}"; $rt['notgoodsmeslist'] = $this->App->find($sql); $this->set('rt', $rt); $result['error'] = 0; $result['message'] = $this->fetch('ajax_userquestion_nogoods', true); die($json->encode($result)); }
</li> <li> <p>最后登录: </p> <span class="s_shuru_1"> <?php echo date('Y-m-d H:i:s', $rt['last_login']); ?> </span> </li> <li> <p>登录区域: </p> <span class="s_shuru_1"> <?php echo Import::ip()->ipCity($rt['last_ip']); ?> </span> </li> <li> <p>登录次数: </p> <span class="s_shuru_1"> <?php echo $rt['visit_count']; ?> </span> </li> </ul> </div>
function getcount() { //新闻 /*$sql = "SELECT COUNT(article_id) FROM `{$this->App->prefix()}article` AS tb1"; $sql .=" LEFT JOIN `{$this->App->prefix()}article_cate` AS tb2 ON tb1.cat_id = tb2.cat_id"; $sql .=" WHERE tb2.type='new'"; $rt['newcount'] = $this->App->findvar($sql); //客户列表 $sql = "SELECT COUNT(article_id) FROM `{$this->App->prefix()}article` AS tb1"; $sql .=" LEFT JOIN `{$this->App->prefix()}article_cate` AS tb2 ON tb1.cat_id = tb2.cat_id"; $sql .=" WHERE tb2.type='customer'"; $rt['customercount'] = $this->App->findvar($sql); //模板 $sql = "SELECT COUNT(article_id) FROM `{$this->App->prefix()}article` AS tb1"; $sql .=" LEFT JOIN `{$this->App->prefix()}article_cate` AS tb2 ON tb1.cat_id = tb2.cat_id"; $sql .=" WHERE tb2.type='case'"; $rt['casecount'] = $this->App->findvar($sql); //网站建设文章 $sql = "SELECT COUNT(article_id) FROM `{$this->App->prefix()}article` AS tb1"; $sql .=" LEFT JOIN `{$this->App->prefix()}article_cate` AS tb2 ON tb1.cat_id = tb2.cat_id"; $sql .=" WHERE tb2.type='web'"; $rt['webcount'] = $this->App->findvar($sql); */ //会员数量 $sql = "SELECT COUNT(user_id) FROM `{$this->App->prefix()}user`"; $rt['usercount']['zcount'] = $this->App->findvar($sql); $sql = "SELECT COUNT(user_id) FROM `{$this->App->prefix()}user` WHERE active='1'"; $rt['usercount']['yescount'] = $this->App->findvar($sql); $sql = "SELECT COUNT(user_id) FROM `{$this->App->prefix()}user` WHERE active='0'"; $rt['usercount']['nocount'] = $this->App->findvar($sql); //留言数 $sql = "SELECT COUNT(mes_id) AS mescount FROM `{$this->App->prefix()}message` WHERE parent_id='0' GROUP BY status ORDER BY status DESC"; $rt['mescount'] = $this->App->findcol($sql); //评论数 $sql = "SELECT COUNT(comment_id) AS comcount FROM `{$this->App->prefix()}comment` WHERE parent_id='0' GROUP BY status ORDER BY status DESC"; $rt['commentcount'] = $this->App->findcol($sql); //商品数 $sql = "SELECT COUNT(goods_id) FROM `{$this->App->prefix()}goods`"; $rt['goods']['zcount'] = $this->App->findvar($sql); $sql = "SELECT COUNT(goods_id) FROM `{$this->App->prefix()}goods` WHERE is_on_sale='1'"; $rt['goods']['sale'] = $this->App->findvar($sql); $sql = "SELECT COUNT(goods_id) FROM `{$this->App->prefix()}goods` WHERE is_on_sale='0'"; $rt['goods']['no_sale'] = $this->App->findvar($sql); $sql = "SELECT COUNT(goods_id) FROM `{$this->App->prefix()}goods` WHERE is_best='1' OR is_hot='1' OR is_new='1'"; $rt['goods']['promote'] = $this->App->findvar($sql); //订单数量 $sql = "SELECT COUNT(order_id) FROM `{$this->App->prefix()}goods_order_info`"; $rt['order']['zcount'] = $this->App->findvar($sql); $sql = "SELECT COUNT(order_id) FROM `{$this->App->prefix()}goods_order_info` WHERE pay_status='1'"; $rt['order']['yescount'] = $this->App->findvar($sql); $rt['os'] = Import::basic()->get_os(); $rt['browser'] = Import::basic()->get_user_browser(); $rt['bsip'] = Import::basic()->getip(); $rt['ip_from'] = Import::ip()->ipCity($rt['bsip']); $rt['csip'] = Import::basic()->serverIP(); return $rt; }
<td><img src="<?php echo $this->img($row['active'] == 1 ? 'yes.gif' : 'no.gif'); ?> " alt="<?php echo $row['active'] == 1 ? '0' : '1'; ?> " class="activeop" lang="active" id="<?php echo $row['user_id']; ?> "/></td> <td><?php echo !empty($row['reg_time']) ? date('Y-m-d H:i:s', $row['reg_time']) : '无知'; ?> </td> <td><?php echo !empty($row['last_login']) ? date('Y-m-d H:i:s', $row['last_login']) . '<br /><font color="#FF0000">[' . Import::ip()->ipCity($row['last_ip']) . ']</font>' : '无知'; ?> </td> <td><?php echo $row['reg_ip']; ?> <br /><font color="#FF0000">[<?php echo $row['reg_from'] ? $row['reg_from'] : '无知'; ?> ]</font></td> <td> <a href="user.php?type=dailiapplyinfo&id=<?php echo $row['user_id']; ?> &goto=suppliers" title="编辑"><img src="<?php echo $this->img('icon_edit.gif');
function goods_comment_info($id = 0) { if (empty($id)) { $this->jump('goods.php?type=comment_list'); exit; } $manager_mes = $this->action('manager', 'getuserinfo'); $rts['email'] = isset($manager_mes['email']) ? $manager_mes['email'] : ""; $rts['adminname'] = isset($manager_mes['adminname']) ? $manager_mes['adminname'] : ""; $rts['adminid'] = isset($manager_mes['adminid']) ? $manager_mes['adminid'] : ""; //管理员回复 if (!empty($_POST)) { if (isset($_POST['comment_id']) && !empty($_POST['comment_id'])) { //修改回复 $_POST['email'] = !empty($_POST['email']) ? $_POST['email'] : $rts['email']; if ($_POST['comment_id'] > 0) { $_POST['up_time'] = mktime(); $this->App->update('comment', $_POST, 'comment_id', $_POST['comment_id']); //更新状态 } $this->action('system', 'add_admin_log', '修改商品评论回复-商品ID:' . $_POST['id_value']); $this->action('common', 'showdiv', $this->getthisurl()); } else { //添加回复 $_POST['add_time'] = mktime(); $ip = Import::basic()->getip(); $_POST['ip_address'] = $ip ? $ip : '0.0.0.0'; $_POST['ip_form'] = Import::ip()->ipCity($ip); $_POST['parent_id'] = isset($_GET['id']) ? $_GET['id'] : 0; $_POST['user_id'] = $rts['adminid'] ? $rts['adminid'] : 0; $_POST['email'] = !empty($_POST['email']) ? $_POST['email'] : $rts['email']; $_POST['user_name'] = $rts['adminname'] ? $rts['adminname'] : ""; $this->App->insert('comment', $_POST); if ($_POST['parent_id'] > 0) { $this->App->update('comment', array('status' => 1), 'comment_id', $_POST['parent_id']); //更新状态 } $this->action('system', 'add_admin_log', '添加商品评论回复-商品ID:' . $_POST['id_value']); $this->action('common', 'showdiv', $this->getthisurl()); } } $sql = "SELECT c.content,c.comment_id, c.comment_rank,c.email,c.goods_rand,c.shopping_rand,c.saleafter_rand, c.add_time,c.status, c.id_value AS goods_id, g.goods_name, c.ip_address AS ip, c.ip_form, u.nickname AS user_name,rc.add_time AS rp_addtime, rc.content AS rp_conent,rc.ip_address AS rp_ip,rc.up_time, ad.adminname AS adname,ad.adminid, rc.comment_id AS rp_com_id FROM `{$this->App->prefix()}comment` AS c"; $sql .= " LEFT JOIN `{$this->App->prefix()}comment` AS rc ON rc.parent_id=c.comment_id AND rc.parent_id>0"; $sql .= " LEFT JOIN `{$this->App->prefix()}user` AS u ON c.user_id = u.user_id AND c.user_id>0"; $sql .= " LEFT JOIN `{$this->App->prefix()}goods` AS g ON g.goods_id = c.id_value"; $sql .= " LEFT JOIN `{$this->App->prefix()}admin` AS ad ON ad.adminid=rc.user_id AND rc.user_id>0"; $sql .= " WHERE c.comment_id='{$id}'"; $this->set('rt', $this->App->findrow($sql)); $this->set('rp_mes', $rts); unset($rts, $manager_mes); $this->template('goods_comment_info'); }
function ajax_comment($data = array(), $page = 0) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (!($page > 0)) { $page = 1; if (empty($data['comments'])) { $result['error'] = 1; $result['message'] = '意外错误,传送的数据为空!'; die($json->encode($result)); } $comments = $json->decode($data['comments']); //反json ,返回值为对象 $goods_id = $comments->goods_id; if (!(intval($goods_id) > 0)) { $result['error'] = 1; $result['message'] = '意外错误,传送的数据为空!'; die($json->encode($result)); } //以下字段对应评论的表单页面 一定要一致 $datas['id_value'] = $goods_id; //$datas['email'] = $comments->email; $username = $this->Session->read('User.username'); $uid = $this->Session->read('User.uid'); $error2 = false; $datas['user_name'] = !empty($username) ? $username : ""; if (empty($datas['user_name']) || !($uid > 0)) { //需要登录 $result['error'] = 4; $result['message'] = '你还没有登录!请你先登录!'; die($json->encode($result)); } //检查是否已经存在购买商品 $sql = "SELECT tb1.rec_id FROM `{$this->App->prefix()}goods_order` AS tb1"; $sql .= " LEFT JOIN `{$this->App->prefix()}goods_order_info` AS tb2 ON tb1.order_id=tb2.order_id"; $sql .= " WHERE tb1.goods_id='{$goods_id}' AND tb2.user_id='{$uid}' AND tb2.order_status='2' AND tb2.pay_status='1'"; $re_id = $this->App->findvar($sql); if (!($re_id > 0)) { //不存在该记录! $result['error'] = 1; $result['message'] = '抱歉,你还没有购买当前商品,不能评论哦!'; die($json->encode($result)); } //检查该商品是否已经评论过 $sql = "SELECT comment_id FROM `{$this->App->prefix()}comment` WHERE id_value='{$goods_id}' AND user_id='{$uid}' LIMIT 1"; $comment_id = $this->App->findvar($sql); if ($comment_id > 0) { //存在该记录! $result['error'] = 1; $result['message'] = '抱歉,你已经评论过该商品,不能再评论哦!'; die($json->encode($result)); } $datas['content'] = $comments->comment; if (empty($datas['content'])) { $result['error'] = 1; $result['message'] = '请填写评论内容!'; die($json->encode($result)); } if (strlen($datas['content']) < 12) { $result['error'] = 1; $result['message'] = '评论内容不能太少!'; die($json->encode($result)); } //限制用户不能重复提交评论,需要等待三分钟后才能评论 $read_time = $this->Session->read("Comment.{$goods_id}"); if (!empty($read_time)) { if (mktime() - $read_time < 200) { $result['error'] = 3; $result['message'] = '你刚才已经发表了评论,请你稍等下再发表!'; die($json->encode($result)); } } $this->Session->write("Comment.{$goods_id}", mktime()); $datas['comment_rank'] = $comments->comment_rank; $datas['goods_rand'] = $comments->goods_rand; $datas['goods_rand'] = empty($datas['goods_rand']) ? 5 : $datas['goods_rand']; $datas['shopping_rand'] = $comments->shopping_rand; $datas['shopping_rand'] = empty($datas['shopping_rand']) ? 5 : $datas['shopping_rand']; $datas['saleafter_rand'] = $comments->saleafter_rand; $datas['saleafter_rand'] = empty($datas['saleafter_rand']) ? 5 : $datas['saleafter_rand']; $datas['status'] = '1'; $datas['add_time'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_form'] = Import::ip()->ipCity($ip); $datas['user_id'] = intval($uid) > 0 ? intval($uid) : 0; $this->App->insert('comment', $datas); unset($datas, $data); } //查询评论 $list = 2; $start = ($page - 1) * $list; $tt = $this->get_comment_count($goods_id); $rt['comment_count'] = $tt; $rt['commentlist'] = $this->get_comment_list($goods_id, $start, $list); $rt['commentpage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_comment_page', array($goods_id)); $this->set('rt', $rt); $result['message'] = $this->fetch('ajax_comment', true); die($json->encode($result)); }
function ajax_user_register($data = array()) { $json = Import::json(); $result = array('error' => 2, 'message' => '传送的数据为空!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } $fromAttr = $json->decode($data['fromAttr']); //反json ,返回值为对象 unset($data); //以下字段对应评论的表单页面 一定要一致 $datas['user_rank'] = $fromAttr->user_rank; //用户级别 /* $datas['user_name'] = $fromAttr->mobile_phone; //用户名 if(empty($datas['user_name'])){ $result = array('error' => 2, 'message' => '请填入登录账户!'); if(empty($data['fromAttr'])) die($json->encode($result)); }*/ $datas['password'] = $fromAttr->password; if (empty($datas['password'])) { $result = array('error' => 2, 'message' => '用户密码不能为空!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } } $rp_pass = $fromAttr->rp_pass; if ($rp_pass != $datas['password']) { $result = array('error' => 2, 'message' => '两次密码不相同!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } } $datas['password'] = md5($datas['password']); $datas['mobile_phone'] = $fromAttr->mobile_phone; if (empty($datas['mobile_phone'])) { $result = array('error' => 2, 'message' => '请填上手机号码!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } } if (preg_match("/1[3458]{1}\\d{9}\$/", $datas['mobile_phone'])) { } else { $result = array('error' => 2, 'message' => '手机号码不合法,请重新输入!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } } //检查该手机是否已经使用了 $mobile_phone = $datas['mobile_phone']; $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE mobile_phone='{$mobile_phone}'"; $uuid = $this->App->findvar($sql); if ($uuid > 0) { $result = array('error' => 2, 'message' => '抱歉,该手机号码已经被使用了!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } } if (!($datas['user_rank'] > 0)) { $datas['user_rank'] = 1; } $datas['user_name'] = $fromAttr->mobile_phone; //用户名 /* $yyy = $fromAttr->yyy; $mmm = $fromAttr->mmm; $ddd = $fromAttr->ddd; $datas['birthday'] = $yyy.'-'.$mmm.'-'.$ddd; $datas['sex'] = $fromAttr->sex;*/ //$regcode = $fromAttr->regcode; $regcode = ''; if (!empty($regcode)) { //检查该注册码是否有效 $sql = "SELECT tb1.bonus_id FROM `{$this->App->prefix()}user_coupon_list` AS tb1 LEFT JOIN `{$this->App->prefix()}user_coupon_type` AS tb2 ON tb1.type_id = tb2.type_id WHERE tb1.bonus_sn='{$regcode}' AND tb1.is_used='0' LIMIT 1"; $uuid = $this->App->findvar($sql); if ($uuid > 0) { } else { $result = array('error' => 2, 'message' => '请检查该注册码是否有效!'); die($json->encode($result)); } } $uname = $datas['user_name']; $sql = "SELECT user_name FROM `{$this->App->prefix()}user` WHERE user_name='{$uname}'"; $dbname = $this->App->findvar($sql); if (!empty($dbname)) { $result = array('error' => 2, 'message' => '该用户名已经被注册了!'); die($json->encode($result)); } $emails = ''; if (!empty($emails)) { $sql = "SELECT email FROM `{$this->App->prefix()}user` WHERE email='{$emails}'"; $dbemail = $this->App->findvar($sql); if (!empty($dbemail)) { $result = array('error' => 2, 'message' => '该电子邮箱已经被使用了!'); die($json->encode($result)); } } $ip = Import::basic()->getip(); $datas['reg_ip'] = $ip ? $ip : '0.0.0.0'; $datas['reg_time'] = mktime(); $datas['reg_from'] = Import::ip()->ipCity($ip); $datas['last_login'] = mktime(); $datas['last_ip'] = $datas['reg_ip']; $datas['active'] = 1; $datas['wecha_id'] = ''; if ($this->App->insert('user', $datas)) { $uid = $this->App->iid(); $this->Session->write('User.username', $uname); $this->Session->write('User.uid', $uid); $this->Session->write('User.active', $datas['active']); $this->Session->write('User.rank', 1); $this->Session->write('User.lasttime', $datas['last_login']); $this->Session->write('User.lastip', $datas['last_ip']); //$datass['user_id'] = $uid; //$datass['is_own'] = '1'; //地址表 //$this->App->insert('user_address',$datass); //注册码表 /* if(!empty($regcode)){ $this->App->insert('user_regcode',array('code'=>$regcode,'uid'=>$uid,'addtime'=>mktime())); $this->App->update('user_coupon_list',array('is_used'=>'1','user_id'=>$uid,'used_time'=>mktime()),'bonus_sn',$regcode); }*/ $result = array('error' => 0, 'message' => '注册成功!'); unset($datas); } else { $result = array('error' => 2, 'message' => '注册失败!'); } die($json->encode($result)); }
function ajax_get_freecatalog($data = array()) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; echo $result['message'] = '传送的数据为空!'; exit; //die($json->encode($result)); } $mesobj = $json->decode($data); //反json ,返回值为对象 $is_freecatalog_time = $this->Session->read("User.is_freecatalog_time"); if (!empty($is_freecatalog_time) && mktime() - $is_freecatalog_time < 1000) { $result['error'] = 2; echo $result['message'] = '你已经提交过了,请歇歇吧 !'; exit; //die($json->encode($result)); } //以下字段对应评论的表单页面 一定要一致 $dir_ids = $mesobj->dir_ids; //$s = str_replace('++',"",$dir_ids); if (empty($dir_ids)) { $result['error'] = 2; echo $result['message'] = '请选择您想索取的目录 !'; exit; //die($json->encode($result)); } $fn = SYS_PATH . 'data/freecatalogdata.php'; file_exists($fn) ? require_once $fn : ($freecatalog = array()); if (empty($freecatalog)) { $result['error'] = 2; echo $result['message'] = '管理需要现在后台设置好提取目录在执行!'; exit; //die($json->encode($result)); } $dir_ids_rt = explode("--", $dir_ids); $dbids = array(); foreach ($dir_ids_rt as $k => $hh) { $hh = intval($hh) - 1; $dbids[] = $freecatalog[$hh]; } $datas['dir_ids'] = !empty($dbids) ? implode('、 ', $dbids) : ""; unset($dir_ids_rt, $dbids); $datas['user_name'] = $mesobj->username; if (empty($datas['user_name'])) { $result['error'] = 2; echo $result['message'] = '姓名不能为空 !'; exit; //die($json->encode($result)); } $datas['birthday'] = $mesobj->birthday; $datas['user_id'] = $mesobj->user_no; //顾客号 $datas['sex'] = $mesobj->sex; $datas['province'] = $mesobj->province; $datas['city'] = $mesobj->city; $datas['district'] = $mesobj->district; $datas['address'] = $mesobj->address; if (empty($datas['province']) || empty($datas['city']) || empty($datas['district']) || empty($datas['address'])) { $result['error'] = 2; echo $result['message'] = '请填写好完整的地址 !'; exit; //die($json->encode($result)); } $datas['postcode'] = $mesobj->postcode; $datas['dayphone'] = $mesobj->dayphone; $datas['nightphone'] = $mesobj->nightphone; $datas['mobile'] = $mesobj->mobile; if (empty($datas['mobile'])) { $result['error'] = 2; echo $result['message'] = '手机不能为空 !'; exit; //die($json->encode($result)); } $datas['email'] = $mesobj->email; $datas['addtime'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_from'] = Import::ip()->ipCity($ip); if ($this->App->insert('freecatalog', $datas)) { $result['error'] = 0; $result['message'] = '你已经提交,我们很快会联系你!'; $this->Session->write("User.is_freecatalog_time", mktime()); } else { $result['error'] = 1; $result['message'] = '提交失败,请通过在线联系客服吧!'; } unset($datas, $data); echo $result['message']; exit; die($json->encode($result)); }
function user_auto_login() { $rt = $this->_get_appid_appsecret(); if (is_weixin() == false || $rt['is_oauth'] == '0') { return; } //一下用于测试 /* if($GLOBALS['LANG']['is_cache']=='1'&&!isset($_GET['code'])){ session_destroy(); $this->Session->write('User',null); //$this->Session->write('Agent',null); setcookie(CFGH.'USER[TOOPENID]', "", mktime()-3600); setcookie(CFGH.'USER[UKEY]', "", mktime()-3600); setcookie(CFGH.'USER[PASS]', "", mktime()-3600); setcookie(CFGH.'USER[TID]', "", mktime()-3600); setcookie(CFGH.'USER[CODETIME]', "", mktime()-3600); setcookie(CFGH.'USER[ISOAUTH]', "", mktime()-3600); setcookie(CFGH.'USER[APPID]', "", mktime()-3600); setcookie(CFGH.'USER[APPSECRET]', "", mktime()-3600); die('这是测试阶段,缓存已经清空完成....'); }*/ //授权判断 $wecha_id = $this->Session->read('User.wecha_id'); if (empty($wecha_id)) { $wecha_id = isset($_COOKIE[CFGH . 'USER']['UKEY']) ? $_COOKIE[CFGH . 'USER']['UKEY'] : ''; } $appid = $rt['appid']; $appsecret = $rt['appsecret']; $codetime = $this->Session->read('User.codetime'); if (empty($codetime)) { $codetime = isset($_COOKIE[CFGH . 'USER']['CODETIME']) ? $_COOKIE[CFGH . 'USER']['CODETIME'] : 0; } if (empty($appid) || empty($appsecret)) { $sql = "SELECT appid,appsecret,is_oauth,winxintype FROM `{$this->App->prefix()}wxuserset` WHERE id='1'"; $rt = $this->App->findrow($sql); $appid = $rt['appid']; $appsecret = $rt['appsecret']; $this->Session->write('User.isoauth', $rt['is_oauth']); setcookie(CFGH . 'USER[ISOAUTH]', $rt['is_oauth'], mktime() + 3600 * 24); } if (empty($rt['is_oauth'])) { $rt['is_oauth'] = '1'; } if (empty($rt['winxintype'])) { $rt['winxintype'] = '3'; } //授权获取用户openid //if( (empty($wecha_id) || ((mktime() - intval($codetime)) > 10)) && $rt['is_oauth']=='1' && $rt['winxintype']=='3' ){ if (empty($wecha_id) && $rt['winxintype'] == '3') { //echo "run................1"; if (!isset($_GET['code'])) { $this->get_user_code(); //授权跳转 } $code = isset($_GET['code']) ? $_GET['code'] : ''; if (!empty($code)) { $access_token = $this->_get_access_token(); $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code'; $con = $this->curlGet($url); if (!empty($con)) { $json = json_decode($con); if (empty($access_token)) { $access_token = $json->access_token; } $wecha_id = $json->openid; $refresh_token = $json->refresh_token; //获取 refresh_token if (!empty($refresh_token) && !empty($access_token)) { if (empty($wecha_id)) { $url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=' . $appid . '&grant_type=refresh_token&refresh_token=' . $refresh_token; $con = $this->curlGet($url); $json = json_decode($con); $wecha_id = $json->openid; //获取 openid } $this->Session->write('User.wecha_id', $wecha_id); setcookie(CFGH . 'USER[UKEY]', $wecha_id, mktime() + 2592000); //获取缓存信息 $userinfo = $this->get_user_wecha_id_info($wecha_id); if (empty($userinfo) || empty($userinfo['nickname']) || empty($userinfo['city']) || empty($userinfo['province']) || empty($userinfo['headimgurl'])) { //获取用户信息 $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $access_token . '&openid=' . $wecha_id . '&lang=zh_CN'; $con = $this->curlGet($url); if (!empty($con)) { $json = json_decode($con); $subscribe = $json->subscribe; if ($subscribe == '1') { $this->Session->write('User.nickname', isset($json->nickname) ? $json->nickname : ''); $this->Session->write('User.sex', isset($json->sex) ? $json->sex : ''); $this->Session->write('User.city', isset($json->city) ? $json->city : ''); $this->Session->write('User.province', isset($json->province) ? $json->province : ''); $this->Session->write('User.headimgurl', isset($json->headimgurl) ? $json->headimgurl : ''); $this->Session->write('User.subscribe_time', isset($json->subscribe_time) ? $json->subscribe_time : ''); $nickname = $this->Session->read('User.nickname'); $sex = $this->Session->read('User.sex'); $city = $this->Session->read('User.city'); $province = $this->Session->read('User.province'); $headimgurl = $this->Session->read('User.headimgurl'); $subscribe_time = $this->Session->read('User.subscribe_time'); if (!empty($wecha_id)) { $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1"; $uid = $this->App->findvar($sql); if ($uid > 0) { $ddl = array(); if (!empty($nickname)) { $ddl['nickname'] = $nickname; } if (!empty($city)) { $ddl['cityname'] = $city; } if (!empty($province)) { $ddl['provincename'] = $province; } if (!empty($headimgurl)) { $ddl['headimgurl'] = $headimgurl; } if ($sex > 0) { $ddl['sex'] = $sex; } if (!empty($ddl)) { $this->App->update('user', $ddl, 'user_id', $uid); $this->Session->write('User.uid', $uid); setcookie(CFGH . 'USER[UID]', $uid, mktime() + 2592000); } } } else { //写入日记,获取openid为空 } } $this->Session->write('User.subscribe', $subscribe); setcookie(CFGH . 'USER[SUBSCRIBE]', $subscribe, mktime() + 2592000); } } } else { die("非法错误:获取refresh_token或者access_token为空,麻烦联系网站管理员解决,谢谢!"); } } } else { die("非法错误:获取code码为空,麻烦联系网站管理员解决,谢谢!"); } } $uid = $this->Session->read('User.uid'); if (empty($wecha_id)) { $wecha_id = isset($_COOKIE[CFGH . 'USER']['UKEY']) ? $_COOKIE[CFGH . 'USER']['UKEY'] : ''; if (empty($wecha_id)) { if ($uid > 0) { $sql = "SELECT wecha_id FROM `{$this->App->prefix()}user` WHERE user_id ='{$uid}' LIMIT 1"; $wecha_id = $this->App->findvar($sql); if (!empty($wecha_id)) { $this->Session->write('User.wecha_id', $wecha_id); setcookie(CFGH . 'USER[UKEY]', $wecha_id, mktime() + 2592000); } } } else { $this->Session->write('User.wecha_id', $wecha_id); } } //双重记录UID if (!($uid > 0)) { $uid = isset($_COOKIE[CFGH . 'USER']['UID']) ? $_COOKIE[CFGH . 'USER']['UID'] : '0'; if ($uid > 0) { $this->Session->write('User.uid', $uid); } else { if (!empty($wecha_id)) { $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id ='{$wecha_id}' LIMIT 1"; $uid = $this->App->findvar($sql); if ($uid > 0) { $this->Session->write('User.uid', $uid); setcookie(CFGH . 'USER[UID]', $uid, mktime() + 2592000); } else { //die("非法错误:初始化账户失败,麻烦联系网站管理员解决,谢谢!"); } } } } $tid = 0; if (!($uid > 0)) { $tid = isset($_GET['tid']) ? intval($_GET['tid']) : '0'; //用户入来的id if (empty($tid)) { $tid = isset($_COOKIE[CFGH . 'USER']['TID']) ? $_COOKIE[CFGH . 'USER']['TID'] : ''; } if (!($tid > 0)) { $tid = $this->Session->read('User.tid'); } } else { //清空 $this->Session->write('User.tid', null); setcookie(CFGH . 'USER[TID]', '', mktime() - 2592000); } $toid = 0; $userinfo = $this->get_user_wecha_id_info($wecha_id, 1); $is_subscribe = isset($userinfo['is_subscribe']) ? $userinfo['is_subscribe'] : '0'; if ($is_subscribe == '0') { $toid = isset($_GET['toid']) ? intval($_GET['toid']) : '0'; //这个是关注后转发的用户ID if (empty($toid)) { $toid = isset($_COOKIE[CFGH . 'USER']['TOOPENID']) ? $_COOKIE[CFGH . 'USER']['TOOPENID'] : ''; } if (!($toid > 0)) { $toid = $this->Session->read('User.to_wecha_id'); } if ($toid > 0) { //从新记录TID setcookie(CFGH . 'USER[TOOPENID]', $toid, mktime() + 2592000); $this->Session->write('User.to_wecha_id', $toid); } } else { //清空 $this->Session->write('User.to_wecha_id', null); setcookie(CFGH . 'USER[TOOPENID]', '', mktime() - 2592000); } //以后数据量大可去掉,前期方便调试 /* if($uid > 0){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id ='$uid' LIMIT 1"; $uid = $this->App->findvar($sql); }*/ //不是第一次进入 if ($uid > 0) { //不做处理 } else { //第一次进来或者已经超过缓存期 if (empty($wecha_id)) { $wecha_id = $this->Session->read('User.wecha_id'); if (empty($wecha_id)) { $wecha_id = isset($_COOKIE[CFGH . 'USER']['UKEY']) ? $_COOKIE[CFGH . 'USER']['UKEY'] : ''; if (empty($wecha_id)) { if ($rt['is_oauth'] == '1') { die("非法错误:获取微信用户openid为空,麻烦联系网站管理员解决,谢谢!"); } } } } $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id ='{$wecha_id}' ORDER BY user_id ASC LIMIT 1"; $uid = $this->App->findvar($sql); if ($uid > 0) { //暂不做处理 } else { //end if uid $rrL = $this->get_userconfig(); //重新创建账号 $thisurl = $this->Session->read('User.url'); //记录当前进入连接 if (empty($thisurl)) { $thisurl = isset($_COOKIE[CFGH . 'USER']['URL']) ? $_COOKIE[CFGH . 'USER']['URL'] : '0'; } if (empty($nickname)) { $nickname = $this->Session->read('User.nickname'); } if (empty($sex)) { $sex = $this->Session->read('User.sex'); } if (empty($city)) { $city = $this->Session->read('User.city'); } if (empty($province)) { $province = $this->Session->read('User.province'); } if (empty($headimgurl)) { $headimgurl = $this->Session->read('User.headimgurl'); } if (empty($subscribe_time)) { $subscribe_time = $this->Session->read('User.subscribe_time'); } $datas = array(); if (!empty($nickname)) { $datas['nickname'] = $nickname; } if (!empty($city)) { $datas['cityname'] = $city; } if (!empty($province)) { $datas['provincename'] = $province; } if (!empty($headimgurl)) { $datas['headimgurl'] = $headimgurl; } if ($sex > 0) { $datas['sex'] = $sex; } $datas['user_name'] = !empty($wecha_id) ? $wecha_id : 'GZSH' . $tid . mktime(); $datas['wecha_id'] = $datas['user_name']; $t = mktime(); $datas['password'] = md5('A123456'); //自动开通代理 if ($rrL['openfxauto'] == '1') { $datas['user_rank'] = 12; //普通分销商 } else { $datas['user_rank'] = 1; } $ip = Import::basic()->getip(); $datas['reg_ip'] = $ip ? $ip : '0.0.0.0'; $datas['reg_time'] = $t; $datas['reg_from'] = Import::ip()->ipCity($ip); $datas['last_login'] = mktime(); $datas['last_ip'] = $datas['reg_ip']; $datas['active'] = 1; $issubscribe = $this->Session->read('User.subscribe'); if (empty($issubscribe)) { $issubscribe = isset($_COOKIE[CFGH . 'USER']['SUBSCRIBE']) ? $_COOKIE[CFGH . 'USER']['SUBSCRIBE'] : '0'; } if ($issubscribe == '1') { $datas['is_subscribe'] = 1; } $uid = $this->Session->read('User.uid'); if ($uid > 0) { return true; } if ($this->App->insert('user', $datas)) { //添加账户 $uid = $this->App->iid(); $this->Session->write('User.uid', $uid); if ($tid != $uid) { //加入分享表 $dd = array(); $dd['share_uid'] = $tid; //分享者uid $dd['parent_uid'] = $toid > 0 ? $toid : $tid; //关注者分享ID $dd['uid'] = $uid; $puid = $dd['parent_uid']; $duid = 0; if ($puid > 0) { //检查是否是代理 $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$puid}' LIMIT 1"); if ($rank != '1') { $duid = $puid; } else { //检查推荐的代理ID /*+++++++++++++++++++++++++++++++++++++++++++=*/ $ds = $this->App->findvar("SELECT daili_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '{$puid}' LIMIT 1"); if ($ds > 0) { $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$ds}' LIMIT 1"); if ($rank != '1') { $duid = $ds; } else { $ds = $this->App->findvar("SELECT share_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '{$ds}' LIMIT 1"); if ($ds > 0) { $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$ds}' LIMIT 1"); if ($rank != '1') { $duid = $ds; } } } } else { $ds = $this->App->findvar("SELECT share_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '{$puid}' LIMIT 1"); if ($ds > 0) { $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$ds}' LIMIT 1"); if ($rank != '1') { $duid = $ds; } else { $ds = $this->App->findvar("SELECT daili_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '{$ds}' LIMIT 1"); if ($ds > 0) { $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$ds}' LIMIT 1"); if ($rank != '1') { $duid = $ds; } } } } } //end if /*+++++++++++++++++++++++++++++++++++++++++++=*/ } } $dd['daili_uid'] = $duid; $dd['url'] = $thisurl; $dd['addtime'] = mktime(); if ($this->App->insert('user_tuijian', $dd)) { //添加推荐用户 //统计分享 跟 关注数 if ($issubscribe == '1') { //当前用户关注了的 if ($dd['parent_uid'] == $dd['share_uid'] && $dd['share_uid'] > 0) { $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1,`guanzhu_ucount` = `guanzhu_ucount`+1 WHERE user_id = '{$tid}'"; $this->App->query($sql); } else { if ($dd['parent_uid'] > 0) { $id = $dd['parent_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `guanzhu_ucount` = `guanzhu_ucount`+1 WHERE user_id = '{$id}' AND is_subscribe='1'"; $this->App->query($sql); } if ($dd['share_uid'] > 0) { $id = $dd['share_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1 WHERE user_id = '{$id}'"; $this->App->query($sql); } } } else { //统计分享用户数 if ($dd['share_uid'] > 0) { $id = $dd['share_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1 WHERE user_id = '{$id}'"; $this->App->query($sql); } } //end if subscribe if ($tid > 0) { //发送推荐用户通知 $pwecha_id = $this->App->findvar("SELECT wecha_id FROM `{$this->App->prefix()}user` WHERE user_id='{$tid}' LIMIT 1"); $rr = $this->_get_appid_appsecret(); $appid = $rr['appid']; $appsecret = $rr['appsecret']; $na = !empty($nickname) ? $nickname : '(UID:' . $uid . ')'; //推荐用户 $this->action('api', 'send', array('openid' => $pwecha_id, 'appid' => $appid, 'appsecret' => $appsecret, 'nickname' => $na), 'share'); //代理用户 if ($duid > 0 && $duid != $tid) { $pwecha_id = $this->App->findvar("SELECT wecha_id FROM `{$this->App->prefix()}user` WHERE user_id='{$duid}' LIMIT 1"); $this->action('api', 'send', array('openid' => $pwecha_id, 'appid' => $appid, 'appsecret' => $appsecret, 'nickname' => $na), 'sharedaili'); } } } unset($dd); } //添加地址 if (!empty($city) && !empty($province)) { $sql = "SELECT region_id FROM `{$this->App->prefix()}region` WHERE region_name LIKE '%{$city}%' LIMIT 1"; $cityid = $this->App->findvar($sql); $sql = "SELECT region_id FROM `{$this->App->prefix()}region` WHERE region_name LIKE '%{$province}%' LIMIT 1"; $provinceid = $this->App->findvar($sql); if ($cityid > 0 && $provinceid > 0) { $dd = array(); $dd['consignee'] = $nickname; $dd['user_id'] = $uid; $dd['sex'] = $sex; $dd['city'] = $cityid; $dd['province'] = $provinceid; $dd['country'] = 1; $dd['is_own'] = 1; $this->App->insert('user_address', $dd); unset($dd); } } $this->Session->write('User.username', $datas['user_name']); $this->Session->write('User.uid', $uid); $this->Session->write('User.active', '1'); $this->Session->write('User.rank', '1'); $this->Session->write('User.ukey', $datas['wecha_id']); $this->Session->write('User.addtime', mktime()); //写入cookie setcookie(CFGH . 'USER[UKEY]', $datas['wecha_id'], mktime() + 2592000); setcookie(CFGH . 'USER[UID]', $uid, mktime() + 2592000); //开通分销 if ($rrL['openfxauto'] == '1') { $dd = array(); $ss = array(); $ss[] = $uid; $dd['uid'] = $uid; $dd['p1_uid'] = 0; $dd['p2_uid'] = 0; $dd['p3_uid'] = 0; $p1_uid = $this->return_daili_uid($uid); if ($p1_uid > 0 && !in_array($p1_uid, $ss)) { $dd['p1_uid'] = $p1_uid; $p2_uid = $this->return_daili_uid($p1_uid); $ss[] = $p1_uid; $ss[] = $uid; if ($p2_uid > 0 && !in_array($p2_uid, $ss)) { $dd['p2_uid'] = $p2_uid; $p3_uid = $this->return_daili_uid($p2_uid); $ss[] = $p2_uid; if ($p3_uid > 0 && !in_array($p3_uid, $ss)) { $dd['p3_uid'] = $p3_uid; } } } // $sql = "SELECT id FROM `{$this->App->prefix()}user_tuijian_fx` WHERE uid='{$uid}' LIMIT 1"; $id = $this->App->findvar($sql); if ($id > 0) { $this->App->update('user_tuijian_fx', $dd, 'id', $id); } else { $this->App->insert('user_tuijian_fx', $dd); } ////////// } } else { die('初始化帐号失败,请联系管理员解决这个问题,谢谢!'); } //end if insert } /******************************************/ } //end if }
private function reply($data) { //语音功能 if (isset($data['MsgType'])) { if ('voice' == $data['MsgType']) { $data['Content'] = $data['Recognition']; $this->data['Content'] = $data['Recognition']; } } //单文本回复 //return array('<a href="http://www.baidu.com">'.$this->token.$data['FromUserName'].'</a>', 'text'); //单图文回复 /* $data['title'] = "test"; $data['keyword'] = "keyword"; $data['picurl'] = 'http://www.wanyangok.com/theme/images/website04_img_left.jpg'; $data['url'] = "http://www.baidu.com";*/ //return array(array(array($data['title'], $data['keyword'], $data['picurl'], $data['url'])), 'news'); //多图文(1) /* $data['title'] = "test"; $data['keyword'] = "keyword"; $data['picurl'] = 'http://www.wanyangok.com/theme/images/website04_img_left.jpg'; $data['url'] = "http://www.baidu.com";*/ //return array(array(array($data['title'], $data['keyword'], $data['picurl'], $data['url']),array($data['title'], $data['keyword'], $data['picurl'], $data['url'])), 'news'); //多图文(2) /* $result = array(); $result[0][] = $data['title']; $result[0][] = $data['keyword']; $result[0][] = $data['picurl']; $result[0][] = $data['url']; $result[1][] = $data['title']; $result[1][] = $data['keyword']; $result[1][] = $data['picurl']; $result[1][] = $data['url']; $result[2][] = $data['title']; $result[2][] = $data['keyword']; $result[2][] = $data['picurl']; $result[2][] = $data['url'];*/ //return array($result, 'news'); //多图文(3) /* $row = array(); $row[] = $data['title']; $row[] = $data['keyword']; $row[] = $data['picurl']; $row[] = $data['url']; $result[] = $row; $result[] = array($data['title'], $data['keyword'], $data['picurl'], $data['url']); $result[] = array($data['title'], $data['keyword'], $data['picurl'], $data['url']);*/ //return array($result, 'news'); //判断关注 if (isset($data['Event'])) { if ('CLICK' == $data['Event']) { $data['Content'] = $data['EventKey']; $this->data['Content'] = $data['EventKey']; } if ($data['Event'] == 'SCAN') { //语音 $data['Content'] = $this->getRecognition($data['EventKey']); $this->data['Content'] = $data['Content']; } elseif ($data['Event'] == 'MASSSENDJOBFINISH') { } elseif ('subscribe' == $data['Event']) { //关注后 /***********************************************/ $wecha_id = $data['FromUserName']; //用户openid //1、更改关注标识 表user_tuijian,user //2、更改用户资料 //3、关注时间、关注排名等 $rr = $this->_get_appid_appsecret(); $appid = $rr['appid']; $appsecret = $rr['appsecret']; $access_token = $this->_get_access_token(); //获取用户信息 $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=' . $access_token . '&openid=' . $wecha_id; $json = json_decode($this->curlGet($url)); $subscribe = $json->subscribe; $nickname = isset($json->nickname) ? $json->nickname : ''; $sex = isset($json->sex) ? $json->sex : ''; $city = isset($json->city) ? $json->city : ''; $province = isset($json->province) ? $json->province : ''; $headimgurl = isset($json->headimgurl) ? $json->headimgurl : ''; $subscribe_time = isset($json->subscribe_time) ? $json->subscribe_time : ''; $this->Session->write('User.subscribe', '1'); setcookie(CFGH . 'USER[SUBSCRIBE]', '1', mktime() + 2592000); $dd = array(); $dd['is_subscribe'] = '1'; $dd['subscribe_time'] = mktime(); if (!empty($nickname)) { $dd['nickname'] = $nickname; } if (!empty($sex)) { $dd['sex'] = $sex; } if (!empty($city)) { $dd['cityname'] = $city; } if (!empty($province)) { $dd['provincename'] = $province; } if (!empty($headimgurl)) { $dd['headimgurl'] = $headimgurl; } if (!empty($subscribe_time)) { $dd['subscribe_time'] = $subscribe_time; } //检查是否存在该用户 $ukey = $this->Session->read('User.ukey'); if (empty($ukey)) { $ukey = isset($_COOKIE[CFGH . 'USER']['UKEY']) ? $_COOKIE[CFGH . 'USER']['UKEY'] : ''; } if (!empty($ukey) && $ukey != $wecha_id) { $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1"; $uid = $this->App->findvar($sql); } else { $uid = $this->Session->read('User.uid'); if (!($uid > 0)) { $uid = isset($_COOKIE[CFGH . 'USER']['UID']) ? $_COOKIE[CFGH . 'USER']['UID'] : '0'; if (!($uid > 0)) { $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1"; $uid = $this->App->findvar($sql); $this->Session->write('User.uid', $uid); setcookie(CFGH . 'USER[UID]', $uid, mktime() + 2592000); } } } if ($uid > 0) { $this->App->update('user', $dd, 'user_id', $uid); $counts = $this->App->findvar("SELECT COUNT(user_id) FROM `{$this->App->prefix()}user` WHERE is_subscribe='1'"); $this->App->update('user', array('subscribe_rank' => $counts), 'user_id', $uid); //更改排名 } else { //添加用户 $dd['user_name'] = $wecha_id; $dd['wecha_id'] = $wecha_id; $t = mktime(); $dd['password'] = md5('A123456'); $dd['user_rank'] = 1; $ip = Import::basic()->getip(); $dd['reg_ip'] = $ip ? $ip : '0.0.0.0'; $dd['reg_time'] = $t; $dd['reg_from'] = Import::ip()->ipCity($ip); $dd['last_login'] = mktime(); $dd['last_ip'] = $dd['reg_ip']; $dd['active'] = 1; if ($this->App->insert('user', $dd)) { $uid = $this->App->iid(); $counts = $this->App->findvar("SELECT COUNT(user_id) FROM `{$this->App->prefix()}user` WHERE is_subscribe='1'"); ${$counts} = $counts + 1; $this->App->update('user', array('subscribe_rank' => $counts), 'user_id', $uid); //更改排名 $this->Session->write('User.username', $dd['user_name']); $this->Session->write('User.uid', $uid); $this->Session->write('User.active', '1'); $this->Session->write('User.rank', '1'); $this->Session->write('User.ukey', $dd['wecha_id']); //$this->Session->write('User.pass',$dd['password']); $this->Session->write('User.addtime', mktime()); //写入cookie setcookie(CFGH . 'USER[UKEY]', $dd['wecha_id'], mktime() + 2592000); setcookie(CFGH . 'USER[UID]', $uid, mktime() + 2592000); $tid = $this->Session->read('User.tid'); if (!($tid > 0)) { $tid = isset($_COOKIE[CFGH . 'USER']['TID']) ? $_COOKIE[CFGH . 'USER']['TID'] : "0"; } //分享的来源ID $to_wecha_id = $this->Session->read('User.to_wecha_id'); //来源ID if (!($to_wecha_id > 0)) { $to_wecha_id = isset($_COOKIE[CFGH . 'USER']['TOOPENID']) ? $_COOKIE[CFGH . 'USER']['TOOPENID'] : "0"; } if ($tid != $uid) { //加入分享表 $dd = array(); //$url = $this->Session->read('User.url'); $dd['share_uid'] = $tid; //分享者uid $dd['parent_uid'] = $to_wecha_id > 0 ? $to_wecha_id : $tid; //关注者分享ID $dd['uid'] = $uid; $puid = $dd['parent_uid']; $duid = 0; //正常来说一下代理不会执行到 if ($puid > 0) { //检查是否是代理 $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$puid}' LIMIT 1"); if ($rank != '1') { $duid = $puid; } else { //检查推荐的代理ID $duid = $this->App->findvar("SELECT daili_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '{$puid}' LIMIT 1"); } } //$dd['url'] = $url; $dd['addtime'] = mktime(); if ($this->App->insert('user_tuijian', $dd)) { //添加推荐用户 if ($dd['share_uid'] > 0) { $id = $dd['share_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1 WHERE user_id = '{$id}'"; $this->App->query($sql); } } unset($dd); } //end if } //end insert } //end if uid>0 //添加地址 if (!empty($city) && !empty($province)) { $sql = "SELECT region_id FROM `{$this->App->prefix()}region` WHERE region_name LIKE '%{$city}%' LIMIT 1"; $cityid = $this->App->findvar($sql); $sql = "SELECT region_id FROM `{$this->App->prefix()}region` WHERE region_name LIKE '%{$province}%' LIMIT 1"; $provinceid = $this->App->findvar($sql); if ($cityid > 0 && $provinceid > 0) { $dd = array(); $dd['consignee'] = $nickname; $dd['user_id'] = $uid; $dd['sex'] = $sex; $dd['city'] = $cityid; $dd['province'] = $provinceid; $dd['country'] = 1; $dd['is_own'] = 1; $this->App->insert('user_address', $dd); unset($dd); } } //增加关注积分 $sql = "SELECT tuijiannum FROM `{$this->App->prefix()}userconfig` LIMIT 1"; //配置信息 $tuijiannum = $this->App->findvar($sql); if ($tuijiannum > 0) { //查找推荐用户人 $uid = $this->Session->read('User.uid'); if (!($uid > 0)) { $uid = isset($_COOKIE[CFGH . 'USER']['UID']) ? $_COOKIE[CFGH . 'USER']['UID'] : "0"; if (!($uid > 0)) { $uid = $this->App->findvar("SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1"); } } if ($uid > 0) { $purt = $this->App->findrow("SELECT ut.parent_uid,u.wecha_id FROM `{$this->App->prefix()}user_tuijian` AS ut LEFT JOIN `{$this->App->prefix()}user` AS u ON u.user_id = ut.parent_uid WHERE ut.uid='{$uid}' LIMIT 1"); $puid = isset($purt['parent_uid']) ? $purt['parent_uid'] : '0'; $pwecha_id = isset($purt['wecha_id']) ? $purt['wecha_id'] : ''; if ($puid > 0) { //派送积分 推荐的用户 $dd = array(); $dd['time'] = mktime(); $dd['points'] = $tuijiannum; $dd['uid'] = $puid; $dd['subuid'] = $uid; $dd['changedesc'] = '推荐关注送积分'; $dd['thismonth'] = date('Y-m-d', mktime()); $this->App->insert('user_point_change', $dd); //积分总计、关注数叠加 方便排序及查找 $tuijiannum = intval($tuijiannum); if (!($tuijiannum > 0)) { $tuijiannum = 1; } $sql = "UPDATE `{$this->App->prefix()}user` SET `mypoints` = `mypoints`+{$tuijiannum},`points_ucount` = `points_ucount`+{$tuijiannum},`guanzhu_ucount` = `guanzhu_ucount`+1 WHERE user_id = '{$puid}' AND is_subscribe='1'"; $this->App->query($sql); $this->send(array('openid' => $pwecha_id, 'appid' => $appid, 'appsecret' => $appsecret, 'nickname' => $nickname), 'guanzhu'); $duid = 0; if ($uid != $duid && $puid != $duid) { //检查是否是代理 $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '{$puid}' LIMIT 1"); if ($rank != '1') { $duid = $puid; } else { //检查推荐的代理ID $duid = $this->App->findvar("SELECT daili_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '{$puid}' LIMIT 1"); } if ($duid > 0 && $duid != $uid) { $pwecha_id = $this->App->findvar("SELECT wecha_id FROM `{$this->App->prefix()}user` WHERE user_id='{$duid}' LIMIT 1"); $this->send(array('openid' => $pwecha_id, 'appid' => $appid, 'appsecret' => $appsecret, 'nickname' => $nickname), 'guanzhudaili'); } } //信息推送 } } } /**********************************************/ $token = $this->token; /* $keyword = $this->App->findvar("SELECT keyword FROM `{$this->App->prefix()}wxkeyword` WHERE type='guanzhu' LIMIT 1"); if(!empty($keyword)){ //查找图文 $sql = "SELECT * FROM `{$this->App->prefix()}wx_article` WHERE keyword='$keyword' LIMIT 1"; $rts = $this->App->findrow($sql); if(empty($rts)){ return array('商家暂未有设置关注回复,请联系商家设置', 'text'); }else{ $type = $rts['type']; if($type=="txt"){ //文本信息 return array($rts['content'], 'text'); }else{ //回复图文信息 $url = $rts['art_url']; $id = $rts['article_id']; if(empty($url)) $url = SITE_URL.'m/art.php?id='.$id; $img = SITE_URL.$rts['article_img']; $about = $rts['about']; $title = $rts['article_title']; $data['title'] = $title; $data['keyword'] = $about; $data['picurl'] = $img; $data['url'] = $url; return array(array(array($data['title'], $data['keyword'], $data['picurl'], $data['url'])), 'news'); } } }else{ return array('商家暂未有设置关注回复,请联系商家设置', 'text'); } if ($follow_data['home'] == 1) { return $this->keyword($follow_data['keyword']); } else { return array(html_entity_decode($follow_data['content']), 'text'); }*/ //这是回复推荐人的信息 if ($uid > 0) { $gzcount = $this->App->findvar("SELECT COUNT(user_id) FROM `{$this->App->prefix()}user` LIMIT 1"); $gzcount = $gzcount * 5 + 750; if ($puid > 0) { $nickname = $this->App->findvar("SELECT nickname FROM `{$this->App->prefix()}user` WHERE user_id = '{$puid}' LIMIT 1"); if (empty($nickname)) { $nickname = '官网'; } $str = '来自好友【' . $nickname . '】的推荐成为第【' . $gzcount . '】位会员,立即关注,抢夺东家地盘!'; } else { $str = '来自【官网】的推荐成为第【' . $gzcount . '】位会员,立即关注,抢夺东家地盘!'; } return array($str, 'text'); } } elseif ('unsubscribe' == $data['Event']) { //取消关注 //$this->requestdata('unfollownum'); //释放cookie 释放session 更改关注标记 $wecha_id = $this->wecha_id; //用户openid $this->App->update('user', array('is_subscribe' => '0'), 'wecha_id', $wecha_id); //更改排名 $this->Session->write('User.subscribe', null); unset($_SESSION['User']['subscribe']); if (isset($_COOKIE[CFGH . 'USER']['SUBSCRIBE'])) { setcookie(CFGH . 'USER[SUBSCRIBE]', "", mktime() - 2592000); } unset($_COOKIE[CFGH . 'USER']['SUBSCRIBE']); //改变取消关注的数据 $sql = "SELECT tuijiannum FROM `{$this->App->prefix()}userconfig` LIMIT 1"; //配置信息 $tuijiannum = $this->App->findvar($sql); if ($tuijiannum > 0) { //查找推荐用户人 $uid = $this->Session->read('User.uid'); if (!($uid > 0)) { $uid = $this->App->findvar("SELECT user_id FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1"); } if ($uid > 0) { //父类UID $purt = $this->App->findrow("SELECT ut.parent_uid,u.wecha_id FROM `{$this->App->prefix()}user_tuijian` AS ut LEFT JOIN `{$this->App->prefix()}user` AS u ON u.user_id = ut.parent_uid WHERE ut.uid='{$uid}' LIMIT 1"); $puid = isset($purt['parent_uid']) ? $purt['parent_uid'] : '0'; $pwecha_id = isset($purt['wecha_id']) ? $purt['wecha_id'] : ''; if ($puid > 0) { //派送积分 $dd = array(); $dd['time'] = mktime(); $dd['points'] = -$tuijiannum; $dd['uid'] = $puid; $dd['subuid'] = $uid; $dd['changedesc'] = '用户取消关注减积分'; $dd['thismonth'] = date('Y-m-d', mktime()); $this->App->insert('user_point_change', $dd); //积分总计、关注数叠加 方便排序及查找 $tuijiannum = intval(-$tuijiannum); $sql = "UPDATE `{$this->App->prefix()}user` SET `mypoints` = `mypoints`+{$tuijiannum},`points_ucount` = `points_ucount`+{$tuijiannum},`guanzhu_ucount` = `guanzhu_ucount`-1 WHERE user_id = '{$puid}'"; $this->App->query($sql); //$this->send(array('openid'=>$pwecha_id),'guanzhu'); //信息推送 } } } } elseif ($data['Event'] == 'LOCATION') { //自动获取位置回复 //return array('LOCATION', 'text'); } } return $this->keyword($data['Content']); }
function ajax_feedback($data = array()) { $err = 0; $result = array('error' => $err, 'message' => ''); $json = Import::json(); if (empty($data)) { $result['error'] = 2; $result['message'] = '传送的数据为空!'; die($json->encode($result)); } $mesobj = $json->decode($data); //反json ,返回值为对象 //以下字段对应评论的表单页面 一定要一致 $datas['comment_title'] = $mesobj->comment_title; $datas['goods_id'] = $mesobj->goods_id; $goods_id = $datas['goods_id']; $uid = $this->Session->read('User.uid'); $datas['user_id'] = !empty($uid) ? $uid : 0; $datas['status'] = 2; if (strlen($datas['comment_title']) < 12) { $result['error'] = 2; $result['message'] = '评论内容不能太少!'; die($json->encode($result)); } //检查需要超过24小时候才能再次提问 //if(!empty($goods_id)){ $t = mktime() + 24 * 3600; $sql = "SELECT addtime FROM `{$this->App->prefix()}message` WHERE user_id='{$uid}' AND goods_id='{$goods_id}' ORDER BY addtime DESC LIMIT 1"; $dt = $this->App->findvar($sql); if (!empty($dt)) { if ($dt + 3600 * 24 > mktime()) { $result['error'] = 1; $result['message'] = '今天你已经发表过提问了,请你<font color=red>' . intval(($dt + 3600 * 24 - mktime()) / 3600) . '</font>小时之后再次提问吧!'; die($json->encode($result)); } } //} /*$datas['content'] = $mesobj->content;goods_id $datas['user_name'] = $mesobj->user_name; $datas['sex'] = $mesobj->sex; $datas['mobile'] = $mesobj->mobile; $datas['telephone'] = $mesobj->telephone; $datas['email'] = $mesobj->email; $datas['companyname'] = $mesobj->companyname; $datas['address'] = $mesobj->address; $datas['companyurl'] = $mesobj->companyurl; */ $datas['addtime'] = mktime(); $ip = Import::basic()->getip(); $datas['ip_address'] = $ip ? $ip : '0.0.0.0'; $datas['ip_from'] = Import::ip()->ipCity($ip); if ($this->App->insert('message', $datas)) { $rl = $this->action('user', 'add_user_jifen', 'comment'); $result['error'] = 0; $result['message'] = '提问成功,我们会很快回答你的问题!<br />恭喜你,本次提问所得积分:' . $rl['points'] . '分!'; } else { $result['error'] = 1; $result['message'] = '提问失败,请通过在线联系客服吧!'; } unset($datas, $data); //查询评论 if (!$page) { $page = 1; } $list = 2; $start = ($page - 1) * $list; $tt = $this->__get_message_count($goods_id); $rt['message_count'] = $tt; $rt['messagelist'] = $this->__get_message($goods_id, $start, $list); $rt['messagepage'] = Import::basic()->ajax_page($tt, $list, $page, 'get_message_page', array($goods_id)); $rt['goodsinfo']['goods_id'] = $goods_id; $this->set('rt', $rt); $result['message'] = $this->fetch('ajax_message', true); die($json->encode($result)); }
function ajax_user_register($data = array()) { $json = Import::json(); $result = array('error' => 2, 'message' => '传送的数据为空!'); if (empty($data['fromAttr'])) { die($json->encode($result)); } $fromAttr = $json->decode($data['fromAttr']); //反json ,返回值为对象 unset($data); //以下字段对应评论的表单页面 一定要一致 $datas['user_rank'] = $fromAttr->user_rank; //用户级别 $datas['user_name'] = $fromAttr->username; //用户名 $datas['email'] = $fromAttr->email; $datas['password'] = md5($fromAttr->password); if (!($datas['user_rank'] > 0)) { $datas['user_rank'] = 1; } if ($datas['user_rank'] != '1') { //供应商 || 配送店 || 企业会员 /** * look修改注释 $datass['consignee'] = $fromAttr->consignee; if(empty($datass['consignee'])){ $result = array('error' => 2, 'message' => '联系人姓名不能为空!'); if(empty($data['fromAttr'])) die($json->encode($result)); } $datass['tel'] = $fromAttr->tel; if(empty($datass['tel'])){ $result = array('error' => 2, 'message' => '固定电话不能为空!'); if(empty($data['fromAttr'])) die($json->encode($result)); } $datass['mobile'] = $fromAttr->mobile; $datass['province'] = $fromAttr->province; if(empty($datass['province'])){ $result = array('error' => 2, 'message' => '必须选择省份!'); if(empty($data['fromAttr'])) die($json->encode($result)); } $datass['city'] = $fromAttr->city; if(empty($datass['city'])){ $result = array('error' => 2, 'message' => '必须选择城市!'); if(empty($data['fromAttr'])) die($json->encode($result)); } $datass['district'] = $fromAttr->district; if(empty($datass['district'])){ $result = array('error' => 2, 'message' => '必须选择地区!'); if(empty($data['fromAttr'])) die($json->encode($result)); } $datass['address'] = $fromAttr->address; if(empty($datass['address'])){ $result = array('error' => 2, 'message' => '详细地址不能为空!'); if(empty($data['fromAttr'])) die($json->encode($result)); } */ $datass['email'] = $datas['email']; } $uname = $datas['user_name']; /****** look修改注释 取消注册时不能用户名一样的。 ************************ $sql = "SELECT user_name FROM `{$this->App->prefix()}user` WHERE user_name='$uname'"; $dbname = $this->App->findvar($sql); if(!empty($dbname)){ $result = array('error' => 2, 'message' => '该用户名已经被注册了!'); die($json->encode($result)); } */ $emails = $datas['email']; if (!empty($emails)) { $sql = "SELECT email FROM `{$this->App->prefix()}user` WHERE email='{$emails}'"; $dbemail = $this->App->findvar($sql); if (!empty($dbemail)) { $result = array('error' => 2, 'message' => '该电子邮箱已经被使用了!'); die($json->encode($result)); } } $ip = Import::basic()->getip(); $datas['reg_ip'] = $ip ? $ip : '0.0.0.0'; $datas['reg_time'] = mktime(); $datas['reg_from'] = Import::ip()->ipCity($ip); $datas['last_login'] = mktime(); $datas['last_ip'] = $datas['reg_ip']; $datas['active'] = 0; if ($this->App->insert('user', $datas)) { $uid = $this->App->iid(); $this->Session->write('User.username', $uname); $this->Session->write('User.uid', $uid); $this->Session->write('User.active', $datas['active']); $this->Session->write('User.rank', $datas['user_rank']); $this->Session->write('User.lasttime', $datas['last_login']); $this->Session->write('User.lastip', $datas['last_ip']); $datass['user_id'] = $uid; $datass['is_own'] = '1'; $this->App->insert('user_address', $datass); $result = array('error' => 0, 'message' => '注册成功!'); //注册成功后,发送mail if (!empty($emails) && $GLOBALS['LANG']['email_open_config']['register'] == '1') { $datas['uid'] = $uid; $this->action('email', 'send_register', $datas); } //$this->add_user_money('register',array()); //赠送12000 //释放cookie if (isset($_COOKIE['USER']['USERID'])) { setcookie('USER[USERID]', "", 0); } if (isset($_COOKIE['USER']['PASS'])) { setcookie('USER[PASS]', "", 0); } unset($datas, $datass); } else { $result = array('error' => 2, 'message' => '注册失败!'); } die($json->encode($result)); }
function _create_user(){ $uid = $this->Session->read('User.uid'); //处理第一次进来的推荐用户数据 $tid = $this->Session->read('User.tid'); if(!($tid>0)){ //SESSION记录为空 $tid = isset($_COOKIE[CFGH.'USER']['TID']) ? $_COOKIE[CFGH.'USER']['TID'] : '0'; if($tid>0){ //从新记录TID setcookie(CFGH.'USER[TID]', $tid, mktime() + 2592000); $this->Session->write('User.tid',$tid); }else{ //获取GET的TID $tid = isset($_GET['tid']) ? intval($_GET['tid']) : '0'; //用户入来的id $this->Session->write('User.url',(Import::basic()->thisurl())); //记录当前进入连接 //检查是否是有效用户ID if($tid >0){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id='$tid' LIMIT 1"; $uuid = $this->App->findvar($sql); if(!($uuid>0)){ $this->Session->write('User.tid',null); setcookie(CFGH.'USER[TID]', "", mktime() - 2592000); }else{ if($uid > 0 && $uid == $tid){ //认定了是当前用户 $this->Session->write('User.tid',null); setcookie(CFGH.'USER[TID]', "", mktime() - 2592000); }else{ setcookie(CFGH.'USER[TID]', $tid, mktime() + 2592000); $this->Session->write('User.tid',$tid); } } } } } $toid = $this->Session->read('User.to_wecha_id'); if(!($toid>0)){ //SESSION记录为空 $toid = isset($_COOKIE[CFGH.'USER']['TOOPENID']) ? $_COOKIE[CFGH.'USER']['TOOPENID'] : '0'; if($toid>0){ //从新记录TID setcookie(CFGH.'USER[TOOPENID]', $toid, mktime() + 2592000); $this->Session->write('User.to_wecha_id',$toid); }else{ //获取GET的TID $toid = isset($_GET['toid']) ? intval($_GET['toid']) : '0'; //用户入来的id //检查是否是有效用户ID if($toid >0){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id='$toid' LIMIT 1"; $uuid = $this->App->findvar($sql); if(!($uuid>0)){ $this->Session->write('User.to_wecha_id',null); setcookie(CFGH.'USER[TOOPENID]', "", mktime() - 2592000); }else{ if($uid > 0 && $uid == $toid){ //认定了是当前用户 $this->Session->write('User.to_wecha_id',null); setcookie(CFGH.'USER[TOOPENID]', "", mktime() - 2592000); }else{ setcookie(CFGH.'USER[TOOPENID]', $toid, mktime() + 2592000); $this->Session->write('User.to_wecha_id',$toid); } } } } } //添加新用户 $wecha_id = $this->Session->read('User.wecha_id'); $ukey = $this->Session->read('User.username'); $comd = array(); if(!empty($wecha_id)) $comd[] = "wecha_id = '$wecha_id'"; if(!empty($ukey)) $comd[] = "wecha_id = '$ukey'"; //检测数据库是否存在,不存在则创建 $usid = 0; if(!empty($comd)){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE ".implode(' OR ',$comd)." LIMIT 1"; $usid = $this->App->findvar($sql); } if(!($usid>0)){ //当前用户ID,判断数据库是否存在 $tid = $this->Session->read('User.tid'); if(!($tid>0)) $tid = isset($_COOKIE[CFGH.'USER']['TID']) ? $_COOKIE[CFGH.'USER']['TID'] : "0"; //分享的来源ID //2次检测该用户是否是有效ID /*$tid_ = isset($_GET['tid']) ? intval($_GET['tid']) : '0'; //用户入来的id if($tid_ > 0 && $tid_ != $tid){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id = '$tid' LIMIT 1"; $user_id = $this->App->findvar($sql); if(!($user_id>0)){ //不存在,则以当前ID为准 $tid = $tid_; setcookie('USER[TID]', $tid, mktime() + 2592000); $this->Session->write('User.tid',$tid); } }*/ //2次检测该推荐用户是否是有效ID $to_wecha_id = $this->Session->read('User.to_wecha_id'); //来源ID if(!($to_wecha_id>0)) $to_wecha_id = isset($_COOKIE[CFGH.'USER']['TOOPENID']) ? $_COOKIE[CFGH.'USER']['TOOPENID'] : "0"; /*$toid_ = isset($_GET['toid']) ? intval($_GET['toid']) : '0'; //用户入来的id if($toid_ > 0 && $toid_ != $to_wecha_id){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id = '$to_wecha_id' LIMIT 1"; $user_id = $this->App->findvar($sql); if(!($user_id>0)){ //不存在,则以当前ID为准 $to_wecha_id = $toid_; setcookie('USER[TOOPENID]', $to_wecha_id, mktime() + 2592000); $this->Session->write('User.to_wecha_id',$to_wecha_id); } }*/ $nickname = $this->Session->read('User.nickname'); $sex = $this->Session->read('User.sex'); $city = $this->Session->read('User.city'); $province = $this->Session->read('User.province'); $headimgurl = $this->Session->read('User.headimgurl'); $datas = array(); if(!empty($nickname)) $datas['nickname'] = $nickname; if(!empty($city)) $datas['cityname'] = $city; if(!empty($province)) $datas['provincename'] = $province; if(!empty($headimgurl)) $datas['headimgurl'] = $headimgurl; if($sex > 0) $datas['sex'] = $sex; if(empty($wecha_id)) $wecha_id = isset($_COOKIE[CFGH.'USER']['UKEY']) ? $_COOKIE[CFGH.'USER']['UKEY'] : ""; if(empty($wecha_id)){ //跳转首页 $is_oauth = $this->App->findvar("SELECT is_oauth FROM `{$this->App->prefix()}wxuserset` WHERE id='1'"); if($is_oauth=='1'){ //授权跳转首页 $this->Session->write('User',null); setcookie(CFGH.'USER[TOOPENID]', "", mktime()-3600); setcookie(CFGH.'USER[UKEY]', "", mktime()-3600); //setcookie('USER[PASS]', "", mktime()-3600); setcookie(CFGH.'USER[TID]', "", mktime()-3600); setcookie(CFGH.'USER[UID]', "", mktime()-3600); $this->jump(ADMIN_URL); exit; } } $datas['user_name'] = !empty($wecha_id) ? $wecha_id : 'GZSH'.$tid.mktime(); $datas['wecha_id'] = $datas['user_name']; $t = mktime(); $datas['password'] = md5('A123456'); $datas['user_rank'] = 1; $ip = Import::basic()->getip(); $datas['reg_ip'] = $ip ? $ip : '0.0.0.0'; $datas['reg_time'] = $t; $datas['reg_from'] = Import::ip()->ipCity($ip); $datas['last_login'] = mktime(); $datas['last_ip'] = $datas['reg_ip']; $datas['active'] = 1; $issubscribe = $this->Session->read('User.subscribe'); if(empty($issubscribe)) $isSUBSCRIBE = isset($_COOKIE[CFGH.'USER']['SUBSCRIBE']) ? $_COOKIE[CFGH.'USER']['SUBSCRIBE'] : '0'; if($issubscribe == '1'){ $datas['is_subscribe'] = 1; } if($this->App->insert('user',$datas)){ //添加账户 $uid = $this->App->iid(); if(/*$tid > 0 &&*/ $tid!=$uid){//加入分享表 $dd = array(); $url = $this->Session->read('User.url'); $dd['share_uid'] = $tid; //分享者uid $dd['parent_uid'] = $to_wecha_id > 0 ? $to_wecha_id : $tid; //关注者分享ID $dd['uid'] = $uid; $puid = $dd['parent_uid']; $duid = 0; if($puid > 0){ //检查是否是代理 $rank = $this->App->findvar("SELECT user_rank FROM `{$this->App->prefix()}user` WHERE user_id = '$puid' LIMIT 1"); if($rank=='10'){ $duid = $puid; }else{ //检查推荐的代理ID $duid = $this->App->findvar("SELECT daili_uid FROM `{$this->App->prefix()}user_tuijian` WHERE uid = '$puid' LIMIT 1"); } } $dd['daili_uid'] = $duid; $dd['url'] = $url; $dd['addtime'] = mktime(); if($this->App->insert('user_tuijian',$dd)){ //添加推荐用户 //统计分享 跟 关注数 if($issubscribe=='1'){ //当前用户关注了的 if($dd['parent_uid']==$dd['share_uid'] && $dd['share_uid'] > 0){ $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1,`guanzhu_ucount` = `guanzhu_ucount`+1 WHERE user_id = '$tid'"; $this->App->query($sql); }else{ if($dd['parent_uid'] > 0){ $id = $dd['parent_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `guanzhu_ucount` = `guanzhu_ucount`+1 WHERE user_id = '$id' AND is_subscribe='1'"; $this->App->query($sql); } if($dd['share_uid'] > 0){ $id = $dd['share_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1 WHERE user_id = '$id'"; $this->App->query($sql); } } }else{ //统计分享用户数 if($dd['share_uid'] > 0){ $id = $dd['share_uid']; $sql = "UPDATE `{$this->App->prefix()}user` SET `share_ucount` = `share_ucount`+1 WHERE user_id = '$id'"; $this->App->query($sql); } } //end if subscribe if($tid > 0){ //发送推荐用户通知 $pwecha_id = $this->App->findvar("SELECT wecha_id FROM `{$this->App->prefix()}user` WHERE user_id='$tid' LIMIT 1"); $appid = $this->Session->read('User.appid'); if(empty($appid)) $appid = isset($_COOKIE[CFGH.'USER']['APPID']) ? $_COOKIE[CFGH.'USER']['APPID'] : ''; $appsecret = $this->Session->read('User.appsecret'); if(empty($appsecret)) $appsecret = isset($_COOKIE[CFGH.'USER']['APPSECRET']) ? $_COOKIE[CFGH.'USER']['APPSECRET'] : ''; $na = !empty($nickname) ? $nickname : '(UID:'.$uid.')'; $this->action('api','send',array('openid'=>$pwecha_id,'appid'=>$appid,'appsecret'=>$appsecret,'nickname'=>$na),'share'); if($duid > 0 && $duid != $tid){ $pwecha_id = $this->App->findvar("SELECT wecha_id FROM `{$this->App->prefix()}user` WHERE user_id='$duid' LIMIT 1"); $this->action('api','send',array('openid'=>$pwecha_id,'appid'=>$appid,'appsecret'=>$appsecret,'nickname'=>$na),'sharedaili'); } } } unset($dd); } //添加地址 if(!empty($city) && !empty($province)){ $sql = "SELECT region_id FROM `{$this->App->prefix()}region` WHERE region_name LIKE '%$city%' LIMIT 1"; $cityid = $this->App->findvar($sql); $sql = "SELECT region_id FROM `{$this->App->prefix()}region` WHERE region_name LIKE '%$province%' LIMIT 1"; $provinceid = $this->App->findvar($sql); if($cityid > 0 && $provinceid>0){ $dd = array(); $dd['consignee'] = $nickname; $dd['user_id'] = $uid; $dd['sex'] = $sex; $dd['city'] = $cityid; $dd['province'] = $provinceid; $dd['country'] = 1; $dd['is_own'] = 1; $this->App->insert('user_address',$dd); unset($dd); } } $this->Session->write('User.username',$datas['user_name']); $this->Session->write('User.uid',$uid); $this->Session->write('User.active','1'); $this->Session->write('User.rank','1'); $this->Session->write('User.ukey',$datas['wecha_id']); //$this->Session->write('User.pass',$datas['password']); $this->Session->write('User.addtime',mktime()); //写入cookie setcookie(CFGH.'USER[UKEY]', $datas['wecha_id'], mktime() + 2592000); setcookie(CFGH.'USER[UID]', $uid, mktime() + 2592000); //setcookie('USER[PASS]', $datas['password'], mktime() + 2592000); }else{ die('初始化帐号失败,请联系管理员解决这个问题,谢谢!'); } }else{ $sql = "SELECT * FROM `{$this->App->prefix()}user` WHERE user_id = '$usid' LIMIT 1"; $rt = $this->App->findrow($sql); if(!empty($rt)){ //2次检测该用户是否是有效ID /*$tid = $this->Session->read('User.tid'); if(!($tid>0)) $tid = isset($_COOKIE['USER']['TID']) ? $_COOKIE['USER']['TID'] : "0"; //分享的来源ID $tid_ = isset($_GET['tid']) ? intval($_GET['tid']) : '0'; //用户入来的id if($tid_ > 0 && $tid_ != $tid){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id = '$tid' LIMIT 1"; $user_id = $this->App->findvar($sql); if(!($user_id>0)){ //不存在,则以当前ID为准 $tid = $tid_; setcookie('USER[TID]', $tid, mktime() + 2592000); $this->Session->write('User.tid',$tid); //检查推荐表 } }*/ //2次检测该用户是否是有效ID /*$to_wecha_id = $this->Session->read('User.to_wecha_id'); //来源ID if(!($to_wecha_id>0)) $to_wecha_id = isset($_COOKIE['USER']['TOOPENID']) ? $_COOKIE['USER']['TOOPENID'] : "0"; $toid_ = isset($_GET['toid']) ? intval($_GET['toid']) : '0'; //用户入来的id if($toid_ > 0 && $toid_ != $to_wecha_id){ $sql = "SELECT user_id FROM `{$this->App->prefix()}user` WHERE user_id = '$to_wecha_id' LIMIT 1"; $user_id = $this->App->findvar($sql); if(!($user_id>0)){ //不存在,则以当前ID为准 $to_wecha_id = $toid_; setcookie('USER[TOOPENID]', $to_wecha_id, mktime() + 2592000); $this->Session->write('User.to_wecha_id',$to_wecha_id); } }*/ $this->Session->write('User.username',$rt['user_name']); $this->Session->write('User.uid',$rt['user_id']); $this->Session->write('User.active',$rt['active']); $this->Session->write('User.rank',$rt['user_rank']); $this->Session->write('User.ukey',$rt['wecha_id']); //$this->Session->write('User.pass',$rt['password']); //写入cookie setcookie(CFGH.'USER[UKEY]', $rt['wecha_id'], mktime() + 2592000); setcookie(CFGH.'USER[UID]', $rt['user_id'], mktime() + 2592000); //setcookie('USER[PASS]', $rt['password'], mktime() + 2592000); }else{ $this->Session->write('User',null); if(isset($_COOKIE[CFGH.'USER']['UKEY'])) setcookie(CFGH.'USER[UKEY]',"",mktime()-3600); if(isset($_COOKIE[CFGH.'USER']['UID'])) setcookie(CFGH.'USER[UID]',"",mktime()-3600); //if(isset($_COOKIE['USER']['PASS'])) setcookie('USER[PASS]',"",mktime()-3600); $this->jump(ADMIN_URL); exit; } return true; } }