|
@@ -117,36 +117,47 @@ class Demo extends Api
|
|
|
$user_id = 1;
|
|
|
|
|
|
//我直推商家的总数量。以后需要冗余到user表
|
|
|
- $count1 = Db::name('hotel')->where('invite_id',$user_id)->count();
|
|
|
- $count2 = Db::name('hotel_canteen')->where('invite_id',$user_id)->count();
|
|
|
- $count3 = Db::name('university_event')->where('invite_id',$user_id)->count();
|
|
|
- $count4 = Db::name('offline_shop')->where('invite_id',$user_id)->count();
|
|
|
-
|
|
|
- $invite_count = $count1 + $count2 + $count3 + $count4;
|
|
|
+ $invite_count = Db::name('offline_shop')->where('invite_id',$user_id)->count();
|
|
|
|
|
|
//我上个月直推商家的总数量
|
|
|
- $count1_mon = Db::name('hotel')->where('invite_id',$user_id)->whereTime('create_time','last month')->count();
|
|
|
- $count2_mon = Db::name('hotel_canteen')->where('invite_id',$user_id)->whereTime('create_time','last month')->count();
|
|
|
- $count3_mon = Db::name('university_event')->where('invite_id',$user_id)->whereTime('create_time','last month')->count();
|
|
|
- $count4_mon = Db::name('offline_shop')->where('invite_id',$user_id)->whereTime('create_time','last month')->count();
|
|
|
-
|
|
|
- $invite_count_mon = $count1_mon + $count2_mon + $count3_mon + $count4_mon;
|
|
|
+ $invite_count_mon = Db::name('offline_shop')->where('invite_id',$user_id)->whereTime('create_time','last month')->count();
|
|
|
|
|
|
//我的直推业绩
|
|
|
- $invite_amount = Db::name('bill')->field('sum(total_amount * back_rate / 100) as back_amount')
|
|
|
- ->where('shop_invite_id',$user_id)->whereTime('back_time','last month')->where('back_status',2)
|
|
|
- ->find();
|
|
|
+ $invite_amount = Db::name('bill')->where('shop_invite_id',$user_id)->where('table_name','offline_shop_order')->where('back_status','neq',0)
|
|
|
+ ->whereTime('createtime','last month')->sum('back_amount');
|
|
|
|
|
|
//我团队业绩
|
|
|
- $invite_uids = Db::name('user')->where('invite_id',$user_id)->column('id');
|
|
|
- $invite_amount_tuandui = Db::name('bill')->where('shop_invite_id','IN',$invite_uids)->field('sum(total_amount * back_rate / 100) as back_amount')->find();
|
|
|
-
|
|
|
+ $invite_uids = $this->get_all_down_uids();
|
|
|
+ $invite_amount_tuandui = Db::name('bill')->where('shop_invite_id','IN',$invite_uids)->where('table_name','offline_shop_order')->where('back_status','neq',0)
|
|
|
+ ->whereTime('createtime','last month')->sum('back_amount');
|
|
|
|
|
|
//补贴/提成
|
|
|
$butie = 0; //补贴
|
|
|
$ticheng_rate = 0; //个人业绩提成 比例
|
|
|
$ticheng = 0; //个人业绩提成
|
|
|
|
|
|
+ //各级的条件
|
|
|
+ $level_list = Db::name('yingxiao_level')->order('id asc')->select();
|
|
|
+ foreach($level_list as $level){
|
|
|
+ if($level['type'] == 1){
|
|
|
+ //营销经理
|
|
|
+ if($invite_amount_tuandui >= $level['invite_amount_tuandui'] && $invite_amount >= $level['invite_amount'] && $invite_count >= $level['invite_count']){
|
|
|
+ $butie = $level['butie'];
|
|
|
+ $ticheng_rate = $level['ticheng_rate'];
|
|
|
+
|
|
|
+ $ticheng = bcdiv(bcmul($invite_amount,$ticheng_rate,2),100,2);
|
|
|
+
|
|
|
+ //公司分红(a%评分,b%业绩加权)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //营销员
|
|
|
+ if($invite_amount >= 60000 && $invite_count_mon >= 5){
|
|
|
+ $butie = 5000;
|
|
|
+ $ticheng_rate = 5;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//高级营销经理
|
|
|
if($invite_amount_tuandui >= 800000 && $invite_amount >= 70000 && $invite_count >= 10){
|
|
|
$butie = 12000;
|