Personal.php where("f_id",session("index_id"))-field("user_id")-select(); $two=0; //二级 foreach($first as $v){ $two+=Db("insert")-where("f_id",$v["user_id"])-count(); } //邀请 $yaoq=Db("consumption") -where(["class_type"=3,"user_id"=se
where("f_id",session("index_id"))->field("user_id")->select();
$two=0;
//二级
foreach($first as $v){
$two+=Db("insert")->where("f_id",$v["user_id"])->count();
}
//邀请
$yaoq=Db("consumption")
->where(["class_type"=>3,"user_id"=>session("index_id")])
->sum("tootel");
$money2=Db("consumption")->where("describe","like","%参加%")
->where(["class_type"=>3,"user_id"=>session("index_id")])
->sum("tootel");
//现金
$this->assign("jb",$yaoq);
$this->assign("xj",$money2);
$this->assign("yiji",count($first));
$this->assign("erji",$two);
return view();
}
//人脉
Public function renmai(){
$first=Db("insert")->where("f_id",session("index_id"))->field("user_id,creat_time")->select();
$arr=[];
foreach($first as $v){
$att=Db("insert")->where("f_id",$v["user_id"])->field("user_id,creat_time")->select();
if(!empty($att)){
foreach($att as $k){
$arr[]=$k;
}
}
}
if(input("type/d")==1){
$this->assign("list",$first);
}else{
$this->assign("list",$arr);
}
return view();
}
public function rul(){
return view();
}
public function helppage(){
return view();
}
//通过二维码加入
Public function insert_qrcode(){
$pid=input("pid/d");
if(getuser_info($pid,"vip")==0){
return ["sta"=>0,"msg"=>"您的朋友(".getuser_info($pid,"nickname").")没有开通权限,您不能加入到他的部队"];
exit;
}
if(getuser_info(session("index_id"),"vip")==0){
return ["sta"=>300,"msg"=>"您没有开通权限,不能加入到朋友的部队"];
exit;
}
$arr=Db("insert")->field("user_id,f_id")->where("user_id",session("index_id"))->find();
if(!empty($arr)) {
return ["sta"=>0,"msg"=>"您已加入其他好友(".getuser_info($arr["f_id"],"nickname").")的部队,不能再加入其他部队"];
exit;
}
if (Db("insert")->insert([
"user_id" => session("index_id"),
"f_id" => $pid,
"creat_time" => time(),
])
) {
//消费记录
consumption(
$pid,
session("index_id"),
"+2000",
"邀请《".getuser_info(session("index_id"),"nickname")."》获得2000根金条",
2
);
if(Db("user")->where("id",$pid)->setInc("votes",2000)) {
//发送给加入人
return ["sta"=>1,"msg"=>"加入好友(".getuser_info($pid,"nickname").")的部队成功"];
}
}else{
exit;
}
}
//个人详情
Public function details(){
if(Db("user")->where("id",session("index_id"))->count()==0){
Session::clear();
$this->redirect('login/index');
}
Vendor("share.Jssdk");//分享类
$appid= weixinconfig("appid");
$appsecret=weixinconfig("secret");
$jssdk = new \Jssdk($appid,$appsecret);
$signPackage = $jssdk->GetSignPackage();
$this->assign('signPackage',$signPackage);//分享数据
$id=input("token/d");
$is_usis=getuser_info($id,"id");
if(empty($is_usis)){
$this->redirect("index/index");
}
cookie("history_id",$id);//记录id
cookie("history",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//判断有没有加入
$ins=Db("insert")->where("user_id",session('index_id'))->count();
$this->assign("ins",$ins);
if(!filter_get($id)){
$this->error("页面错误");
}
return view();
}
//数据
Public function dataclass(){
$id=input("post.id/d");
//转盘根金条
$zhuan=Db("consumption")->where(["class_type"=>4,"user_id"=>$id])->sum("tootel");
//邀请根金条
$yq=Db("insert")->where("f_id",$id)->count();
//礼物根金条
$liwu=Db("weixinorder")->where(["f_id"=>$id,"return_code"=>"SUCCESS"])->sum("total_fee");
//金币兑换
$dh=Db("consumption")->where(["class_type"=>5,"user_id"=>$id])->sum("tootel");
//挖到的数量
$wd=intval(Db("vote")->where("f_id",$id)->sum("jintnum"));
//帮朋友淘金数据
$tao=Db("vote")->where("user_id",$id)->count();
$glj=Db("consumption")->where("user_id",$id)->where("class_type",3)->sum("tootel");
return [
"zp"=>intval($zhuan),
"yq"=>intval($yq),
"lw"=>intval($liwu),
"dh"=>intval($dh),
"wd"=>intval($wd),
"vip"=>getuser_info($id,'vip'),
"touxiang"=>getuser_info($id,'avatar'),
"nickname"=>getuser_info($id,"nickname"),
"glj"=>intval($glj),
"renshu"=>getsumrs($id),
"tao"=>$tao,
];
}
//记录数据 //记录各种根金条,金币列表
Public function getdata(){
$id=input("id/d");
$list_ty=input("post.list_type/d");
switch($list_ty){
case 1:
$ty=2;
break;
case 2:
$ty='3,5';
break;
case 3:
$ty=4;
break;
}
$ass=Db("consumption")->where("user_id",$id)->where("class_type","in",$ty)->field("describe,x_userid,tootel,creat_time")->order("creat_time desc")->select();
$agg=[];
foreach($ass as $v){
$touxiang=getuser_info($v["x_userid"],"avatar");
$agg[]=array_merge($v,["touxiang"=>$touxiang]);
}
return $agg;
}
//加入到朋友
Public function insert_l(){
$f_id=input("f_id");
$hmd=Db("user")->where("id",$f_id)->find();
if($hmd["level"]==5){
return ["sta" => 0, "msg" => "该用户已被系统限制,关闭所有权限"];
exit;
}
if($f_id==session("index_id")){
return ["sta" => 0, "msg" => "只能好友互相帮忙淘金"];
exit;
}
$ins_us=Db("user")->where("id",$f_id)->field("vip")->find();
if($ins_us["vip"]==0){
return ["sta" => 0, "msg" => "您的朋友没有加入淘金部队,暂时不能为TA淘金"];
exit;
}
//已加入情况下投根金条,1天只能投5根金条,不能给同一个人投根金条
if(!Db("vote")
->where("to_days(FROM_UNIXTIME(creat_time)) = to_days(now())")
->where(["user_id"=>session("index_id"),"f_id"=>$f_id])->find()){
$jint=rand(1,12);
/*$pj=Db("user")->where("id",$f_id)->field("votes,level")->find();
if($pj["votes"]>pingjun($pj["level"])-1000){
$jint=rand(10,12);
}*/
switch (intval($jint)){
case 1:
$ty_b="金条";
break;
case 2:
$ty_b="紫宝石";
break;
case 3:
$ty_b="蓝宝石";
break;
case 4:
$ty_b="绿宝石";
break;
case 5:
$ty_b="黄钻";
break;
case 6:
$ty_b="红钻";
break;
case 7:
$ty_b="红宝石";
break;
case 8:
$ty_b="海洋之星";
break;
case 9:
$ty_b="屁";
break;
case 10:
$ty_b="砖头";
break;
case 11:
$ty_b="石头";
break;
case 12:
$ty_b="炸弹";
break;
}
if($jint==9){
$jint=0;
}
if($jint==10){
$jint=-3;
}
if($jint==11){
$jint=-7;
}
if($jint==12){
$jint=-10;
}
if(Db("vote")
->insert([
"user_id"=>session("index_id"),
"jintnum"=>$jint*100,
"f_id"=>$f_id,
"ip_address"=>getIp(),
"creat_time"=>time()
])){
Db("user")->where("id",$f_id)->setInc("votes",intval($jint*100));
consumption(
$f_id,
session("index_id"),
$jint*100,
"好友《".getuser_info(session("index_id"),"nickname")."》为你挖到了(".$ty_b.")".($jint*100)."根金条",
2
);
return ["sta" => 1, "msg" => "金条","jt"=>$jint];
}
}else {
return ["sta" => 0, "msg" => "已帮TA挖过,请帮其他好友继续淘金"];
}
}
//赠送礼物
Public function songli(){
$id_is=input("f_id/d");
if(!empty($id_is)){
if(getuser_info(input("f_id/d"),"vip")==0){
return ["sta" => 0, "msg" => "您的朋友没有加入淘金部队,您不能给他送礼"];
exit;
}
}
$openid=getuser_info(session("index_id"),"openid");
$num=intval(input("num"));
$shul=input("shul/d");
$da=[
"out_trade_no"=>date("Ymdhis",time()).'_'.rand(1000,9999),
"remark"=>"赠送礼物",
"total_fee"=>$num,
"pay_type"=>2,
"num"=>$shul,
"user_id"=>session("index_id"),
"f_id"=>input("f_id")
];
if(Db("weixinorder")->insert($da)) {
return [wx_pay($openid, $da["out_trade_no"], $da["total_fee"]*$shul*100)];
}else{
return ["sta"=>0,'msg'=>'发起支付失败'];
}
}
//动态
Public function dongtai(){
$arr=Db("dynamic")->select();
$this->assign("abb",$arr);
return view();
}
//个人编辑
Public function gerenxinxi(){
return view();
}
//个人钱包
Public function getsummoney(){
$qb=Db("consumption")->where(["user_id"=>session("index_id"),"class_type"=>3])->select();
$this->assign("qb",$qb);
return view();
}
//总根金条数
Public function zongpiaoshu(){
$num=Db("insert")->where("f_id",session("index_id"))->count();//邀请数
$liwu=Db("weixinorder")->where(["result_code"=>"SUCCESS","return_code"=>"SUCCESS"])->where("f_id",session("index_id"))->sum("total_fee"); //赠送根金条数
$tp=Db("vote")->where("f_id",session("index_id"))->sum("jintnum");
$zp=Db("consumption")->where(["user_id"=>session('index_id'),"class_type"=>4])->sum("tootel");
$dh=Db("consumption")->where(["user_id"=>session('index_id'),"class_type"=>5])->sum("tootel");
$this->assign("zp",intval($zp));
$this->assign("yq",$num*2000);
$this->assign("liwu",$liwu*10);
$this->assign("tp",$tp);
$this->assign("dh",intval($dh));
return view();
}
//金币
Public function zongjifen(){
//Db("consumption")->where("tootel",0)->delete();
$zjf=Db("consumption")->where(["user_id"=>session('index_id'),"class_type"=>1])->select();
$this->assign("zjf",$zjf);
return view();
}
//金币兑换现金
Public function moneyc(){
if(time()-Db("consumption")->where("class_type",3)->max("creat_time")<2){
return ["sta" => 0, "msg" => "当前兑换已关闭,请稍后兑换"];
exit;
}
if(\think\Request::instance()->post()){
$arr=Db("consumption")->where("uuid",session("index_id").date("Ymd"))->field("id,tootel,uuid")->select();
if(empty($arr)){
return ["sta" => 0, "msg" => "没有兑换的金币"];
exit;
}
$money=0;
for($i=0;$i
getuser_info(session("index_id"),"openid"),
"money"=>$money,
"out_trade_no"=>$arr[0]["uuid"],
];
$res =wxbuild($dam, '');
if(isset($res["result_code"])){
if($res["result_code"]=="success"){
Db("consumption")->where("user_id",session("index_id"))->update(["describe"=>"金币已经兑换到个人钱包","class_type"=>3]);
Db("user")->where("id", session('index_id'))->setInc('money', intval($money/100));
Db("user")->where("id", session('index_id'))->setDec('score', $money);
return ["sta" => 1, "msg" => '兑换成功'];
}else{
return ["sta" => 0, "msg" => "系统繁忙"];
}
}else{
return ["sta" => 0, "msg" =>"系统繁忙,稍后兑换"];
}
}
}
//金币兑换根金条
Public function vote(){
if(\think\Request::instance()->post()){
$id=filter_sql(input("selmon"));
if(empty($id)){
return ["sta" => 0, "msg" => "没有兑换的金币"];
exit;
}
$sql=\think\Db::query("select id,`describe`,tootel from xl_consumption where class_type=1 and id in (".$id.")");
if(!empty($sql)) {
$jifen = 0;
for ($i = 0; $i < count($sql); $i++) {
$jifen += $sql[$i]['tootel'];
$up[] = ["id" => $sql[$i]["id"],"tootel"=>$sql[$i]['tootel']/10, "describe" => $sql[$i]["describe"] . "=>兑换成" . $sql[$i]['tootel']/10 . "根金条", "class_type" => 5];
}
$user = new con;
if ($user->saveAll($up)) {
Db("user")->where("id", session('index_id'))->setInc('votes', $jifen/10);
Db("user")->where("id", session('index_id'))->setDec('score', $jifen);
return ["sta" => 1, "msg" => '兑换成功'];
} else {
return ["sta" => 0, "msg" => "兑换错误"];
}
}
}
}
//转盘
Public function zhuan(){
return view();
}
//处理转盘
Public function zhpanc(){
$attko=Db("user")->where("id",session("index_id"))->field("vip")->find();
if($attko["vip"]==0){
return ["sta"=>300,"msg"=>"您没加入淘金部队,快加入和好友一起淘金","con"=>'加入'];
exit;
}
if(time()-Db("adventures")->where("user_id",session("index_id"))->max("creat_time")<4){
return ["sta"=>0,"msg"=>"速度太快,稍等一下"];
exit;
}
$azz=rand(4,8);
$attu=Db("adventures")->field("FROM_UNIXTIME(creat_time,'%m%d') as date")
->where("user_id",session("index_id"))
->select();
$result=[];
foreach ($attu as $l){
if($l["date"]!=date("md",time())) {
$result[$l["date"]][] = $l;
}
}
$k=0;
foreach ($result as $j){
if(count($j)>3){
$k+=(count($j)-3);
}
}
$znum=Db("adventures")
->where("user_id",session("index_id"))
->where("to_days(FROM_UNIXTIME(creat_time)) = to_days(now())")
->count(); //今天转了多少次
$yqr=Db("insert")
->where("f_id",session("index_id"))->count(); //统计邀请人
$sycs=((($yqr*3)-$k)+3)-$znum;
if($sycs>0){
$da=["user_id"=>session('index_id'),"position"=>$azz,"ticket"=>$azz*100,"creat_time"=>time()];
if(Db("adventures")->insert($da)){
consumption(
session("index_id"),
session("index_id"),
"+".$azz*100,
"大转盘获得".($azz*100)."根金条",
4);
Db("user")->where("id",session("index_id"))->setInc("votes",$azz*100);
return ["sta"=>1,"ind"=>$azz];
}else{
return ["sta"=>0,"msg"=>"系统错误"];
}
}else{
return ["sta"=>400,"msg"=>"今天次数已经用完,每邀请一个朋友加入可以再获得三次免费转盘,以此类推!","con"=>'邀请'];
}
}
//更换手机号
public function phonebangding(){
return view();
}
//根金条数详情
Public function yaoqingpiaoshu(){
$yq=Db("insert")->field("user_id,creat_time")->where("f_id",session("index_id"))->select();
$this->assign("yq",$yq);
return view();
}
//礼物根金条数
Public function liwupiaoshu(){
$liwu=Db("weixinorder")->field("user_id,total_fee,time_end")
->where(["f_id"=>session("index_id"),"return_code"=>"SUCCESS"])
->select();
$zliwu=Db("weixinorder")
->where(["f_id"=>session("index_id"),"return_code"=>"SUCCESS"])->sum("total_fee");
$this->assign("liwu",$liwu);
$this->assign("zlw",$zliwu);
return view();
}
//金币兑换根金条数
Public function jifenduihuanpiao(){
$dh=Db("consumption")->field("tootel,creat_time,describe")
->where(["user_id"=>session("index_id"),"class_type"=>5])->select();
$this->assign('dh',$dh);
$zdh=Db("consumption")->where(["user_id"=>session("index_id"),"class_type"=>5])->sum("tootel");
$this->assign("zdh",intval($zdh));
return view();
}
//投根金条数
Public function toupiaoshu(){
$tp=Db("vote")->where("f_id",session("index_id"))->select();
$ayyh=Db("vote")->where("f_id",session("index_id"))->sum("jintnum");
$this->assign("sum_t",$ayyh);
$this->assign("tp",$tp);
return view();
}
//动态发布
Public function donogtaifabu(){
Vendor("share.Jssdk");//分享类
$appid= weixinconfig("appid");
$appsecret=weixinconfig("secret");
$jssdk = new \Jssdk($appid,$appsecret);
$signPackage = $jssdk->GetSignPackage();
$this->assign('signPackage',$signPackage);//分享数据
return view();
}
//动态发布提交
Public function dongth(){
$serverid=input("serverId");
if(!empty($serverid)){
$tokenis=Cache("access_token");
if(empty($tokenis)) {
//请求获取access_token
$get_user_info_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . weixinconfig("appid") . "&secret=" . weixinconfig('secret');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $get_user_info_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
//解析json
$user_obj = json_decode($output, true);
Cache('access_token', $user_obj["access_token"], 3600);
}
$targetName = './Uploads/'.date('YmdHis').rand(1,1000).'.jpg';
$ch = curl_init("http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=".Cache('access_token')."&media_id=".$serverid);
$fp = fopen($targetName, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
if($imgid=Db('picture')->insertGetId(["imgurl"=>$targetName,"creat_time"=>time()])){
return ["sta"=>1,"msg"=>"图片上传成功","id"=>$imgid,"imgurl"=>$_SERVER['SERVER_NAME'].$targetName];
}else{
return ["sta"=>0,"msg"=>"系统繁忙"];
}
}
}
Public function fabuh(){
$contem=input('post.contend');
if(empty($contem)){
return ["sta"=>0,"msg"=>"内容不能为空"];
exit;
}
$imgidis=input("post.imgid/a");
if(!empty($imgidis)){
$imgids=implode(',',input('post.imgid/a'));
if(Db("dynamic")->where("imgId",$imgids)->count()>0){
return ["sta"=>0,"msg"=>"请不要重复发布"];
exit;
}
if(Db("dynamic")->insert([
"contend"=>filter_get_post(input("contend")),
"imgId"=>$imgids,
"user_id"=>session("index_id"),
"creat_time"=>time(),
])){
return ["sta"=>1,"msg"=>"发布成功"];
}else{
return ["sta"=>0,"msg"=>"提交错误"];
}
}else{
return ["sta"=>0,"msg"=>"没有添加图片"];
}
}
//发送邀请二维码
Public function putqrcode(){
vendor ( "phpqrcode.phpqrcode");
$url = "http://".$_SERVER['HTTP_HOST']."/home/personal/details/token/".session("index_id");
\QRcode::png ($url,false,0,6);
exit;
}
//发送通知给邀请人
Public function yq_msg(){
$pid=input("pid/d");
//发送模板消息给邀请人
$arr=[
"first"=>['value'=>"您的好友(".getuser_info(session("index_id"),"nickname").")通知你加入淘金部队来淘金", 'color'=>"#FF0000"],
'keyword1'=>["value"=>getuser_info(session("index_id"),"nickname"),"color"=>"#0000FF"],
"keyword2"=>["value"=>date("Y-m-d H:i:s",time()),"color"=>"#0000FF"],
"remark"=>["value"=>"查看详细信息","color"=>"#000000"]
];
template_home(
"cskQduX3pl53q_JNRd196BaS-Xqcn8144Eo0A4dvcug",
getuser_info($pid,"openid"),
"http://".$_SERVER['HTTP_HOST']."/home/personal/details/token/".$pid,
$arr
);
return ["sta"=>1,"msg"=>"通知成功"];
//成功发送模板消息
}
//投诉
public function toushu(){
return view();
}
}
