NULL2017-12-07 13:35:24
static function GetUpUser($userId,$ShopPrice){//获取上级用户等级并提成,提成按照百分比方式提成,参数一为当前用户的ID,参数二为商品价格 $user = Db::table('user')->where(['id'=>$userId])->select();//查询当前用户详情 $UpUser = Db::table('user')->where(['id'=>$user[0]['up_id']])->select();//查询上级用户详情,up_ID为上级ID if(empty($UpUser)){ return;//如果上级信息为空,则结束方法 }else{ $Commission = Cache::get('Commission');//获取提成比例 if($Commission == '' || $Commission == null || !$Commission ){//如果没有则从数据库查询提成比例 $Commission = Db::table('commission')->where(['Id'=>1])->select(); $Commission = $Commission[0]['ticheng']; Cache::set('Commission',$Commission,0);//提成比例存入缓存 } //查看等级差,相差两级应该提成两级的利润 $money = ($user[0]['Grade'] - $UpUser[0]['Grade']) * $ShopPrice * $Commission;//计算提成金额 $money = floor($money*100)/100;//取小数点后两位 if($money != 0){ //给上级用户增加余额 Db::table('user')->where(['id'=>$UpUser[0]['id']])->update(['money' => ['exp',"money+$money"]]); } if($UpUser[0]['up_id'] == 0){ //如果上级ID是顶级则结束方法执行 return; } //把上级ID传入本方法继续执行提成操作, self::GetUpUser($UpUser[0]['id'],$ShopPrice); } return; }//提成function