<?php
/**
* 志汇-同城微圈小程序模块小程序接口定义
*
* @author 武汉志汇科技
* @url
//tid3
*/
defined('IN_IA') or exit('Access Denied');
class Zh_tcwqModuleWxapp extends WeModuleWxapp {
//获取openid
public function doPageOpenid(){
global $_W, $_GPC;
$res=pdo_get('zhtc_system',array('uniacid'=>$_W['uniacid']));
$code=$_GPC['code'];
$appid=$res['appid'];
$secret=$res['appsecret'];
$url="https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$code."&grant_type=authorization_code";
function httpRequest($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
$res=httpRequest($url);
print_r($res);
}
//登录用户信息
public function doPageLogin(){
global $_GPC, $_W;
$openid=$_GPC['openid'];
$res=pdo_get('zhtc_user',array('openid'=>$openid,'uniacid'=>$_W['uniacid']));
if($openid and $openid!='undefined'){
if($res){
$user_id=$res['id'];
if($_GPC['openid']){
$data['openid']=$_GPC['openid'];
}
if($_GPC['img']){
$data['img']=$_GPC['img'];
}
if($_GPC['name']){
$data['name']=$_GPC['name'];
}
$res = pdo_update('zhtc_user', $data, array('id' =>$user_id));
$user=pdo_get('zhtc_user',array('openid'=>$openid,'uniacid'=>$_W['uniacid']));
echo json_encode($user);
}else{
$data['openid']=$_GPC['openid'];
$data['img']=$_GPC['img'];
$data['name']=$_GPC['name'];
$data['uniacid']=$_W['uniacid'];
$data['time']=time();
$res2=pdo_insert('zhtc_user',$data);
$user=pdo_get('zhtc_user',array('openid'=>$openid,'uniacid'=>$_W['uniacid']));
echo json_encode($user);
}
}
}
//轮播图
public function doPageAd(){
global $_GPC, $_W;
$where=" where uniacid=:uniacid and status=1";
if($_GPC['cityname']){
$where.=" and (cityname LIKE concat('%', :name,'%') or cityname='全国版')";
$data[':name']=$_GPC['cityname'];
}
$data[':uniacid']=$_W['uniacid'];
$sql="select * from ".tablename('zhtc_ad').$where." order by orderby asc";
$res=pdo_fetchall($sql,$data);
echo json_encode($res);
}
public function doPageUrl(){
global $_GPC, $_W;
echo $_W['attachurl'];
}
//url
public function doPageUrl2(){
global $_W, $_GPC;
echo $_W['siteroot'];
}
//主分类
public function doPageType(){
global $_GPC, $_W;
$res=pdo_getall('zhtc_type',array('uniacid'=>$_W['uniacid'],'state'=>1),array(),'','num asc');
echo json_encode($res);
}
//子分类
public function doPageType2(){
global $_GPC, $_W;
$res=pdo_getall('zhtc_type2',array('type_id'=>$_GPC['id']),array(),'','num asc');
echo json_encode($res);
}
//发帖
public function doPagePosting(){
global $_GPC, $_W;
$system=pdo_get('zhtc_system',array('uniacid'=>$_W['uniacid']));
// $data['details']=base64_encode($_GPC['details']);//帖子内容
$data['details']=$_GPC['details'];//帖子内容
$data['img']=$_GPC['img'];//帖子图片
$data['user_id']=$_GPC['user_id'];//用户id
$data['user_name']=$_GPC['user_name'];//姓名
$data['user_tel']=$_GPC['user_tel'];//电话
$data['type2_id']=$_GPC['type2_id'];//子分类id
$data['type_id']=$_GPC['type_id'];//主分类id
$data['money']=$_GPC['money'];//价格
$data['top_type']=$_GPC['type'];//置顶类型
$data['address']=$_GPC['address'];//帖子地址
$data['store_id']=$_GPC['store_id'];
$data['cityname']=$_GPC['cityname'];
if($_GPC['type']){
$data['top']=1;
}else{
$data['top']=2;
}
$data['time']=time();
$data['uniacid']=$_W['uniacid'];
if($system['tz_audit']==2){
$data['sh_time']=time();
if($_GPC['type']==1){
$data['dq_time']=$data['sh_time']+24*60*60;
}elseif($_GPC['type']==2){
$data['dq_time']=$data['sh_time']+24*60*60*7;
}elseif($_GPC['type']==3){
$data['dq_time']=$data['sh_time']+24*60*60*30;
}
$data['state']=2;
}else{
$data['state']=1;
}
$data['hb_money']=$_GPC['hb_money'];//红包金额
$data['hb_num']=$_GPC['hb_num'];//红包个数
$data['hb_type']=$_GPC['hb_type'];//红包类型1.普通 2.口令
$data['hb_keyword']=$_GPC['hb_keyword'];//红包口令
$data['hb_random']=$_GPC['hb_random'];//随机1.是 2否
if($_GPC['hb_random']==1){
function sendRandBonus($total=0, $count=3){
$input = range(0.01, $total, 0.01);
if($count>1){
$rand_keys = (array) array_rand($input, $count-1);
$last = 0;
foreach($rand_keys as $i=>$key){
$current = $input[$key]-$last;
$items[] = $current;
$last = $input[$key];
}
}
$items[] = $total-array_sum($items);
return $items;
}
$hong=json_encode(sendRandBonus($_GPC['hb_money'],$_GPC['hb_num']));
$data['hong']= $hong;
}
$res=pdo_insert('zhtc_information',$data);
$tz_id=pdo_insertid();
$post_id=pdo_insertid();
$a=json_decode(html_entity_decode($_GPC['sz']));
$sz=json_decode(json_encode($a),true);
// print_r($sz);die;
if($res){
for($i=0;$i<count($sz);$i++){
$data2['label_id']=$sz[$i]['label_id'];
$data2['information_id']=$post_id ;
$res2=pdo_insert('zhtc_mylabel',$data2);
}
//echo '1';
echo $tz_id;
}else{
echo '2';
}
}
//发帖加积分
public function doPageAddScore(){
global $_GPC, $_W;
$user_id=$_GPC['user_id'];
$system=pdo_get('zhtc_system',array('uniacid'=>$_W['uniacid']));
if($system['is_jf']==1 and $system['integral']>0){
$res= pdo_update('zhtc_user',array('total_score +='=>$system['integral']),array('id'=>$user_id));
if($res){
$data3['score']=$system['integral'];
$data3['user_id']=$user_id;
$data3['note']='发帖';
$data3['type']=1;
$data3['cerated_time']=date('Y-m-d H:i:s');
$data3['uniacid']=$_W['uniacid'];//小程序id
pdo_insert('zhtc_integral',$data3);//添加积分明细
}
}
}
//修改帖子
public function doPageUpdPost(){
global $_GPC, $_W;
$system=pdo_get('zhtc_system',array('uniacid'=>$_W['uniacid']));
$tz=pdo_get('zhtc_information',array('id'=>$_GPC['id']));
if($tz['details']!=$_GPC['details']){
$data['details']=$_GPC['details'];//帖子内容
}
if($tz['img']!=$_GPC['img']){
$data['img']=$_GPC['img'];//帖子图片
}
if($tz['user_name']!=$_GPC['user_name']){
$data['user_name']=$_GPC['user_name'];//姓名
}
if($tz['user_tel']!=$_GPC['user_tel']){
$data['user_tel']=$_GPC['user_tel'];//电话
}
if($tz['address']!=$_GPC['address']){
$data['address']=$_GPC['address'];//帖子地址
}
if($tz['cityname']!=$_GPC['cityname']){
$data['cityname']=$_GPC['cityname'];//帖子地址
}
$data['uniacid']=$_W['uniacid'];
if($system['tz_audit']==2){
$data['state']=2;
}else{
$data['state']=1;
}
$res=pdo_update('zhtc_information',$data,array('id'=>$_GPC['id']));
pdo_delete('zhtc_mylabel',array('information_id'=>$_GPC['id']));
// $a=json_decode(html_entity_decode($_GPC['sz']));
// $sz=json_decode(json_encode($a),true);
// // print_r($sz);die;
if($res){
// for($i=0;$i<count($sz);$i++){
// $data2['label_id']=$sz[$i]['label_id'];
// $data