|
|
@@ -5,6 +5,7 @@ namespace App\Servers;
|
|
|
|
|
|
use App\Jobs\MemberShareJob;
|
|
|
use App\Models\Member;
|
|
|
+use App\Models\MemberBoth;
|
|
|
use App\Models\MemberClan;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
@@ -108,7 +109,6 @@ class MemberClanServer
|
|
|
$p_clans = MemberClan::where('m_id', $p_member->{'id'})->select(['id', 'm_ids', 'p_ids'])->first();
|
|
|
$new_p_ids_str = $p_clans->{'p_ids'} . ',' . $p_member->{'id'};
|
|
|
$new_p_ids = array_filter(explode(',', $new_p_ids_str));
|
|
|
-
|
|
|
foreach ($new_p_ids as $new_p_id) {
|
|
|
$new_m_ids = MemberClan::where('m_id', $new_p_id)->value('m_ids');
|
|
|
$new_m_ids = explode(',', $new_m_ids);
|
|
|
@@ -133,5 +133,64 @@ class MemberClanServer
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 双线关系绑定
|
|
|
+ * @param $mId
|
|
|
+ * @param $pId
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ function creatBoth($mId,$pId){
|
|
|
+ $num=MemberBoth::where('m_id',$mId)->count();
|
|
|
+ if($num>0){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ $bothData=[
|
|
|
+ 'm_id'=>$mId,
|
|
|
+ 'direct_id'=>$pId,
|
|
|
+ 'left_id'=>0,
|
|
|
+ 'right_id'=>0,
|
|
|
+ ];
|
|
|
+ $pBothData=MemberBoth::where('m_id',$pId)->first();
|
|
|
+ if(empty($pBothData)){
|
|
|
+ CommonServer::creatServer()->addErrorRecord('层级关系错误',$bothData);
|
|
|
+ }else{
|
|
|
+ if($pBothData->{'is_end'}!=0){
|
|
|
+ //直推人已满就检查下面人员
|
|
|
+ $childIds=array_filter(explode(',',$pBothData->{'child_ids'}));
|
|
|
+ //重新获取
|
|
|
+ $pBothData=MemberBoth::whereIn('m_id',$childIds)->where('is_end',0)->orderBy('tier_num' ,'asc')->orderBy('id','asc')->first();
|
|
|
+ if(empty($pBothData)){
|
|
|
+ CommonServer::creatServer()->addErrorRecord('子节点层级关系错误',$bothData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($pBothData->{'left_id'}){
|
|
|
+ $pBothData->{'right_id'}=$mId;
|
|
|
+ }else{
|
|
|
+ $pBothData->{'left_id'}=$mId;
|
|
|
+ }
|
|
|
+ $pBothData->{'child_ids'}.=(($pBothData->{'child_ids'}?',':'').$mId);
|
|
|
+ $bothData['tier_num']=$pBothData->{'tier_num'}+1;
|
|
|
+ $bothData['parent_id']=$pBothData->{'id'};
|
|
|
+ $bothData['parent_ids']=$pBothData->{'parent_ids'}.','.$pBothData->{'id'};
|
|
|
+ $bothData['child_ids']='';
|
|
|
+ $bothData['is_end']='0';
|
|
|
+ $bothData=MemberBoth::create($bothData);
|
|
|
+ if($pBothData->{'left_id'} && $pBothData->{'right_id'}){
|
|
|
+ $pBothData->{'is_end'}=1;
|
|
|
+ }
|
|
|
+ $pBothData->save();
|
|
|
+ $parentIds=array_filter(explode(',',$bothData['parent_ids']));
|
|
|
+ foreach ($parentIds as $parentId){
|
|
|
+ if($parentId!=$pBothData->{'id'}){
|
|
|
+ $childIds=MemberBoth::where('id',$parentId)->value('child_ids');
|
|
|
+ $childIds=explode(',', $childIds);
|
|
|
+ $childIds[]=$bothData->{'id'};
|
|
|
+ MemberBoth::where('id',$parentId)->update(['child_ids'=>implode(',',$childIds)]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|