作者 景龙
1 个管道 的构建 通过 耗费 9 秒

修改分享下线规则

@@ -329,16 +329,19 @@ class Person extends Api @@ -329,16 +329,19 @@ class Person extends Api
329 * @return bool 329 * @return bool
330 */ 330 */
331 public function getScore($share_uid,$type){ 331 public function getScore($share_uid,$type){
  332 + $class = '';
332 if($type == 'share_purchase'){ 333 if($type == 'share_purchase'){
333 $scoreRule = Db::table('gc_sscore') 334 $scoreRule = Db::table('gc_sscore')
334 ->where('set_rule','like','%购买%') 335 ->where('set_rule','like','%购买%')
335 ->field('set_score') 336 ->field('set_score')
336 ->find(); 337 ->find();
  338 + $class = 1;
337 }else if($type == 'share_sell'){ 339 }else if($type == 'share_sell'){
338 $scoreRule = Db::table('gc_sscore') 340 $scoreRule = Db::table('gc_sscore')
339 ->where('set_rule','like','%卖废品%') 341 ->where('set_rule','like','%卖废品%')
340 ->field('set_score') 342 ->field('set_score')
341 ->find(); 343 ->find();
  344 + $class = 0;
342 } 345 }
343 // $score = config('site.'.$type); 346 // $score = config('site.'.$type);
344 $score = 0; 347 $score = 0;
@@ -346,16 +349,29 @@ class Person extends Api @@ -346,16 +349,29 @@ class Person extends Api
346 $score = $scoreRule['set_score']; 349 $score = $scoreRule['set_score'];
347 } 350 }
348 $offlineModel = new Line(); 351 $offlineModel = new Line();
349 - //此处判断不能相互成为下线(你成为我的下线,我就不能成为你的下线)  
350 - $offlineModel->where(['off_uid'=>$share_uid,'uid'=>$this->user_id])->find(); 352 + //此处判断分享用户否已有上线,如果有,则不能成为其他的下线
  353 + $each_other = $offlineModel->where(['off_uid'=>$share_uid])->select();
  354 + //判断本登录用户是否有上线
  355 + $other = $offlineModel->where(['off_uid'=>$this->user_id])->select();
351 //分享人是自己无效 356 //分享人是自己无效
352 if($share_uid != $this->user_id){ 357 if($share_uid != $this->user_id){
353 - if(!$offlineModel){ 358 + //分享用户有上线
  359 + if($each_other && !$other){
  360 + $on_uid = array_unique(array_column($each_other,'uid'))[0];
  361 + //给上线增加积分
  362 + $userModel = new \app\admin\model\User();
  363 + $userModel->where(['id'=>$on_uid,'status'=>'normal'])->setInc('score', $score);
  364 + //创建上线用户的积分记录
  365 + $offlineModel->create(['uid'=>$on_uid,'s_score'=>$score,'off_uid'=>$share_uid,'type'=>$class]);
  366 + }else{
  367 + //本登录用户没有上线
  368 + if(!$other){
354 //给分享用户增加积分 369 //给分享用户增加积分
355 $userModel = new \app\admin\model\User(); 370 $userModel = new \app\admin\model\User();
356 $userModel->where(['id'=>$share_uid,'status'=>'normal'])->setInc('score', $score); 371 $userModel->where(['id'=>$share_uid,'status'=>'normal'])->setInc('score', $score);
357 - //成为分享用户的下线  
358 - $offlineModel->create(['uid'=>$share_uid,'s_score'=>$score,'off_uid'=>$this->user_id]); 372 + //成为分享用户的下线并创建积分记录
  373 + $offlineModel->create(['uid'=>$share_uid,'s_score'=>$score,'off_uid'=>$this->user_id,'type'=>$class]);
  374 + }
359 } 375 }
360 } 376 }
361 } 377 }