|
@@ -36,6 +36,7 @@ class PartnerTools{
|
|
|
private $levPer = 0.05;//升级佣金比例
|
|
private $levPer = 0.05;//升级佣金比例
|
|
|
private $incomePer = 0.1;//佣金比例
|
|
private $incomePer = 0.1;//佣金比例
|
|
|
private $errorMsg = "";
|
|
private $errorMsg = "";
|
|
|
|
|
+ private $childrenData = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
private $codeAr = [
|
|
private $codeAr = [
|
|
@@ -269,7 +270,135 @@ class PartnerTools{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 【新】新升级合伙人
|
|
|
|
|
+ */
|
|
|
|
|
+ public function apiSetPartner($parms){
|
|
|
|
|
+ if(empty($parms)){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $where=[];
|
|
|
|
|
+ if(!empty($parms["customerId"])){
|
|
|
|
|
+ $where["id"] = $parms["customerId"];
|
|
|
|
|
+ }else if(!empty($parms["userCenterId"])){
|
|
|
|
|
+ $where["userCenterId"] = $parms["userCenterId"];
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $userData = $this->dbCustomer->get($where);
|
|
|
|
|
+ if(empty($userData) || empty($userData["id"])){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if($userData["isPartner"]==1){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->dbNewCommissionPartner->beginTransaction();
|
|
|
|
|
+
|
|
|
|
|
+ $save=["isPartner"=>1];
|
|
|
|
|
+ $res = $this->dbCustomer->update($save,["id"=>$userData["id"]]);
|
|
|
|
|
+ if(empty($res)){
|
|
|
|
|
+ $this->dbNewCommissionPartner->rollBack();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ //添加合伙人账号
|
|
|
|
|
+ $partnerData = $this->dbNewCommissionPartner->get(["customerId"=>$userData["id"]]);
|
|
|
|
|
+ if(empty($partnerData)){
|
|
|
|
|
+ $nowTime = time();
|
|
|
|
|
+ $partnerId = $this->dbNewCommissionPartner->insert([
|
|
|
|
|
+ "customerId"=>$userData["userCenterId"],
|
|
|
|
|
+ "userCenterId"=>$userData["id"],
|
|
|
|
|
+ "balance"=>0,
|
|
|
|
|
+ "waitMoney"=>0,
|
|
|
|
|
+ "withdraw"=>0,
|
|
|
|
|
+ "totalMoney"=>0,
|
|
|
|
|
+ "deleteStatus"=>5,
|
|
|
|
|
+ "createTime"=>$nowTime,
|
|
|
|
|
+ "updateTime"=>$nowTime,
|
|
|
|
|
+ "expand"=>"",
|
|
|
|
|
+ ]);
|
|
|
|
|
+ if(empty($partnerId)){
|
|
|
|
|
+ $this->dbNewCommissionPartner->rollBack();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $partnerData["id"] = $partnerId;
|
|
|
|
|
+ }
|
|
|
|
|
+ //更新子级的父合伙人id
|
|
|
|
|
+// $partnerId = intval($partnerData["id"]);
|
|
|
|
|
+// $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
|
|
|
|
|
+// $sql = "select * from {$customerTableName} where FIND_IN_SET(". intval($userData["id"]).",parentPath)";
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 【新】对外查询接口
|
|
|
|
|
+ * @param type $parentId
|
|
|
|
|
+ * @return type
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getApiChildrenTree($parentId){
|
|
|
|
|
+ $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
|
|
|
|
|
+ $sql = "select count(*) as count from {$customerTableName} where FIND_IN_SET(". intval($parentId).",`parentPath`)";
|
|
|
|
|
+ $count = $this->dbCustomer->query($sql);
|
|
|
|
|
+ if(empty($count) || empty($count[0]) || empty($count[0]["count"])){
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ $type = 1;
|
|
|
|
|
+ if(intval($count[0]["count"])<=100){
|
|
|
|
|
+ $type = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ $res = $this->getChildrenTree($parentId,0,$type);
|
|
|
|
|
+ return empty($res) ? [] : $res;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 【新】获取子级
|
|
|
|
|
+ * @param type $parentId
|
|
|
|
|
+ * @param type $lev
|
|
|
|
|
+ * @return type
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getChildrenTree($parentId,$lev=0,$type=1){
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ if($type==2){
|
|
|
|
|
+ $data = $this->getChildrenData($parentId);//第二种方法:适和子级数量少
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $data = $this->dbCustomer->select(["parentId"=>$parentId],"id,name,parentPath,parentId,isPartner");//第一种方法:适合子级一次性数据比较多
|
|
|
|
|
+ }
|
|
|
|
|
+ if(empty($data)){
|
|
|
|
|
+ $data=[];
|
|
|
|
|
+ }
|
|
|
|
|
+ $childData = [];
|
|
|
|
|
+ foreach($data as $k=>$v){
|
|
|
|
|
+ $data[$k]["lev"] = $lev;
|
|
|
|
|
+ if($v["isPartner"]==0){
|
|
|
|
|
+ $itemChildData = $this->getChildrenTree($v["id"],$lev+1,$type);
|
|
|
|
|
+ $childData = array_merge($childData,$itemChildData);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $allData = array_merge($data,$childData);
|
|
|
|
|
+ return $allData;
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 【新】获取子级数据表数据
|
|
|
|
|
+ * @param type $parentId
|
|
|
|
|
+ * @return type
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getChildrenData($parentId){
|
|
|
|
|
+ if(empty($this->childrenData)){
|
|
|
|
|
+ $customerTableName = 'qianniao_customer_'.$this->enterpriseId;
|
|
|
|
|
+ $sql = "select id,name,parentPath,parentId,isPartner from {$customerTableName} where FIND_IN_SET(". intval($parentId).",parentPath)";
|
|
|
|
|
+ $res = $this->dbCustomer->query($sql);
|
|
|
|
|
+ $this->childrenData = empty($res) ? [] : $res;
|
|
|
|
|
+ }
|
|
|
|
|
+ $data=[];
|
|
|
|
|
+ foreach($this->childrenData as $k=>$v){
|
|
|
|
|
+ if($v["parentId"] == $parentId){
|
|
|
|
|
+ $data[]=$v;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $data;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取用户父级合伙人
|
|
* 获取用户父级合伙人
|