推广链接PHP
<?php
class Tuiguang extends pluginBase
{
public static function name(){
return "我的推广";
}
public static function description(){
return "点击推广吧";
}
public static function install(){
$tuiDb =new IModel("tuiguang");
if($tuiDb->exists())
{
return true;
}
$data = array(
"comment" => self::name(),
"column" => array(
"id" => array("type" => "int(11) unsigned",'auto_increment' => 1),
"selfs" => array("type" => "varchar(11)","comment" => "自己的id"),
"oth" => array("type" => "varchar(11)","comment" => "推广的id"),
),
"index" => array("primary" => "id"),
);
$tuiDb->setData($data);
$tuiDb->createTable();
$ticheng =new IModel("ticheng");
if($ticheng->exists())
{
return true;
}
$data = array(
"comment" => self::name(),
"column" => array(
"id" => array("type" => "int(11) unsigned",'auto_increment' => 1),
"self_id" => array("type" => "varchar(11)","comment" => "自己的id"),
"pid" => array("type" => "varchar(11)","comment" => "推广的id"),
"order_no" => array("type" => "varchar(50)","comment" => "订单order_no"),
"goods_name" => array("type" => "varchar(50)","comment" => "商品的名字"),
"ticheng" => array("type" => "varchar(11)","comment" => "订单order_no"),
),
"index" => array("primary" => "id"),
);
$ticheng->setData($data);
return $ticheng->createTable();
}
public static function uninstall(){
$ticheng = new IModel('tuiguang');
$ticheng->dropTable();
$onlineDB = new IModel('tuiguang');
return $onlineDB->dropTable();
}
public function reg(){
plugin::reg("onUcenterMenuCreate",function(){
MenuUcenter::$menu['我要推广']['/ucenter/tuiguang']="推广链接";
});
plugin::reg("onUcenterMenuCreate",function(){
MenuUcenter::$menu['我要推广']['/ucenter/shouming']="收入明细";
});
plugin::reg("onUcenterMenuCreate",function(){
MenuUcenter::$menu['我要推广']['/ucenter/shouzong']="收入汇总";
});
plugin::reg("onBeforeCreateAction@ucenter@tuiguang",function(){
self::controller()->tuiguang=function(){$this->showurl(self::controller());};
});
plugin::reg("onBeforeCreateAction@ucenter@orderlist",function(){
self::controller()->orderlist=function(){$this->orderlist(self::controller());};
});
plugin::reg("onFinishView@simple@reg",function(){
//接受id
$id=$_GET['id'];
echo <<<zhao
<script>
$("#tianjia").html("<input type='hidden' name='yao' value='{$id}' class='gray'>");
</script>
zhao;
});
//自定义yao请
plugin::reg("yaoqingren",$this,"add");
//自定义推广
plugin::reg("ticheng",$this,"ticheng_do");
plugin::reg("onBeforeCreateAction@ucenter@shouming",function(){
self::controller()->shouming=function(){$this->shouming(self::controller());};
});
plugin::reg("onBeforeCreateAction@ucenter@shouzong",function(){
self::controller()->shouzong=function(){$this->shouzong(self::controller());};
});
}
public static function configName()
{
return array(
"bili" => array("name" => "积分比例","type" => "text","value" =>"")
);
}
public function shouming($kong){
//查询当前用户下级带来的效益
$user_id=$kong->user['user_id'];
$tichengdb=new IQuery('ticheng');
$tichengdb->where="pid=$user_id";
$arr=$tichengdb->find();
$obj=new IQuery("user");
foreach ($arr as $key => $value) {
$id= $value['self_id'];
$obj->where="id='$id'";
$res=$obj->find();
$arr[$key]['username']=$res[0]['username'];
}
$data['arrs']=$arr;
$this->redirect("shouming",$data);
}
public function shouzong($kong){
//查询当前用户所有下级
$tuiguang=new IQuery('tuiguang');
$user_id=$kong->user['user_id'];
$tuiguang->where="selfs='$user_id'";
$arr=$tuiguang->find();
//循环查询每个下级给自己带来的收入
$tichengdb=new IQuery("ticheng");
foreach($arr as $k=>$v){
//下级id
$self_id=$v['oth'];
$tichengdb->where="self_id='$self_id'";
$res=$tichengdb->find();
$price=0;
foreach($res as $kk=>$vv){
$price+=$vv['ticheng'];
}
$newarr[$k]['self_id']=$self_id;
$newarr[$k]['price']=$price;
}
$obj=new IQuery("user");
foreach ($newarr as $key => $value) {
$id= $value['self_id'];
$obj->where="id='$id'";
$res=$obj->find();
$newarr[$key]['username']=$res[0]['username'];
}
$data['arrs']=$newarr;
$this->redirect("shouzong",$data);
}
public function ticheng_do($data){
//订单号
$order_no=$data['order_no'];
//查询订单
$orderdb=new IQuery("order");
$orderdb->where = "order_no='$order_no'";
$arr=$orderdb->find();
//订单拥有者id
$user_id=$arr[0]['user_id'];
//订单id
$order_id=$arr[0]['id'];
//商品的名字
$ordergoodsdb=new IQuery("order_goods");
$ordergoodsdb->where="order_id='$order_id'";
$goods=$ordergoodsdb->find();
$goods_name=json_decode($goods[0]['goods_array'],true)['name'];
//抽成
$ticheng=$arr[0]['real_amount']*0.1;
//上级id
$tuiguangdb=new IQuery("tuiguang");
$tuiguangdb->where="oth='$user_id'";
$res=$tuiguangdb->find();
$pid=$res[0]['selfs'];
//组装数据
$data['self_id']=$user_id;
$data['pid']=$pid;
$data['goods_name']=$goods_name;
$data['order_no']=$order_no;
$data['ticheng']=$ticheng;
//往提成表里边添加数据
$obj=new IModel("ticheng");
$obj->setData($data);
$obj->add();
}
public function ticheng($kong){
//操作者id
$user_id=$kong->user['user_id'];
$obj=new IQuery("jifen");
$obj->where="p_id='$user_id'";
$res=$obj->find();
$userdb=new IQuery("user");
$userdb->fields="username";
foreach ($res as $key => $value) {
$id= $value['self_id'];
$userdb->where="id=$id";
$rr=$userdb->find();
$res[$key]['username']=$rr[0]['username'];
}
$this->redirect("jifen",array("jf"=>$res));
}
public function showurl($kong){
//self id
$user_id=$kong->user['user_id'];
$obj=new IQuery("tuiguang");
$obj->where="selfs=$user_id";
$res=$obj->find();
if($res){
$newstr="";
foreach($res as $k=>$v){
$newstr=$newstr."id=".$v['oth']." or ";
}
$id = substr($newstr, 0,-3);
$db=new IQuery("user");
$db->fields="username,id";
$db->where="$id";
$arr=$db->find();
$orderdb = new IQuery("order");
foreach($arr as $kk=>$val){
$user_id=$val['id'];
$orderdb->fields = "order_no,create_time,user_id";
$orderdb->where="user_id=$user_id";
$a=$orderdb->find();
$arr[$kk]['order_num']=count($a);
// $arr[$kk]['order_list']=$a;
}
$u_id=$kong->user['user_id'];
$this->redirect("indexs",array("url"=>$u_id,"tui"=>$arr));
die;
}
$this->redirect("indexs",array("url"=>$user_id));
}
public function add($data){
$obj =new IModel("tuiguang");
$obj->setData($data);
$obj->add();
}
//当前会员订单列表
public function orderlist($kong){
//当前会员的id
$id=$_GET['id'];
$orderdb=new IQuery('order');
$orderdb->fields = "id,order_no,create_time,real_amount";
$orderdb->where="user_id=$id";
$arr=$orderdb->find();
//实例化商品订单表
$ordergoodsdb=new IQuery("order_goods");
$orderlist="";
foreach($arr as $k=>$v){
$order_id=$v['id'];
$ordergoodsdb->where="order_id=$order_id";
$res=$ordergoodsdb->find();
$orderlist[$k]['real_amount']=$v['real_amount'];
$orderlist[$k]['order_no']=$v['order_no'];
$orderlist[$k]['create_time']=$v['create_time'];
$orderlist[$k]['img']=$res[0]['img'];
$orderlist[$k]['name']=json_decode($res[0]['goods_array'],true)['name'];
$orderlist[$k]['goods_id']=$res[0]['goods_id'];
}
$data['orderlist']=$orderlist;
$this->redirect("orderlist",$data);
}
}
?>