|
@@ -155,11 +155,11 @@ class AgentTools{
|
|
|
return ["code"=>1,"msg"=>"绑定成功","data"=>null];
|
|
|
}
|
|
|
/**
|
|
|
- * 更新父级门店等级
|
|
|
+ * 【新】更新父级门店等级
|
|
|
* @param type $shopId
|
|
|
- * @param type $type 0表示只算两级
|
|
|
+ * @param type $type 0表示只算两级,1表示算无限极
|
|
|
*/
|
|
|
- public function updateParentShopLevel($shopId,$type=0){
|
|
|
+ public function updateParentShopLevel($shopId,$type=1){
|
|
|
//子级门店
|
|
|
$shopData = $this->dbShop->get($shopId);
|
|
|
if(empty($shopData) || empty($shopData["parentPath"])){
|
|
@@ -167,24 +167,51 @@ class AgentTools{
|
|
|
}
|
|
|
//从最底层开始更新等级
|
|
|
$pathData = array_reverse(explode(",", trim($shopData["parentPath"])));
|
|
|
+ $shopList = $this->dbShop->select([["id","in",$pathData]]);
|
|
|
+ $shopTableName = "qianniao_shop_1";
|
|
|
for($i=0;$i<count($pathData);$i++){
|
|
|
if(empty($pathData[$i])){
|
|
|
- break;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $pData=null;
|
|
|
+// $pData = $this->dbShop->get((int)$pathData[$i]);
|
|
|
+ foreach($shopList as $k=>$v){
|
|
|
+ if($v["id"]==(int)$pathData[$i]){
|
|
|
+ $pData = $v;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- $pData = $this->dbShop->get((int)$pathData[$i]);
|
|
|
if(empty($pData)){
|
|
|
continue;
|
|
|
}
|
|
|
if($pData["level"]>=3){
|
|
|
- break;
|
|
|
+ continue;
|
|
|
}
|
|
|
$level = 1;
|
|
|
- $levelCount_1 = $this->dbShop->count([["level","=",1],["pOneShopId|pTwoShopId","=",$pData["id"]]]);
|
|
|
- if($levelCount_1 && $levelCount_1>=$this->agentSettingData["oneToTwoNum"]){
|
|
|
+ $levelCount_1 = 0;
|
|
|
+ $levelCount_2 = 0;
|
|
|
+ //查询数据
|
|
|
+ if($type==1){
|
|
|
+ //无限级查询
|
|
|
+ $sql1 = "select count(*) as count from {$shopTableName} where level = 1 and FIND_IN_SET(". intval($pData["id"]).",parentPath)";
|
|
|
+ $countData1 = $this->dbShop->query($sql1);
|
|
|
+ if(!empty($countData1)){
|
|
|
+ $levelCount_1 =array_shift($countData1)['count'];//子级社区门店数
|
|
|
+ }
|
|
|
+ $sql2 = "select count(*) as count from {$shopTableName} where level = 2 and FIND_IN_SET(". intval($pData["id"]).",parentPath)";
|
|
|
+ $countData2 = $this->dbShop->query($sql2);
|
|
|
+ if(!empty($countData2)){
|
|
|
+ $levelCount_2 =array_shift($countData2)['count'];//子级代理门店数
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //只查两级
|
|
|
+ $levelCount_1 = $this->dbShop->count([["level","=",1],["pOneShopId|pTwoShopId","=",$pData["id"]]]);//子级社区门店数
|
|
|
+ $levelCount_2 = $this->dbShop->count([["level","=",2],["pOneShopId|pTwoShopId","=",$pData["id"]]]);//子级代理门店数
|
|
|
+ }
|
|
|
+ if($levelCount_1 && $this->agentSettingData["oneToTwoNum"]>0 && $levelCount_1>=$this->agentSettingData["oneToTwoNum"]){
|
|
|
$level = 2;//5个升级为代理
|
|
|
}
|
|
|
- $levelCount_2 = $this->dbShop->count([["level","=",2],["pOneShopId|pTwoShopId","=",$pData["id"]]]);
|
|
|
- if($levelCount_2 && $levelCount_2>=$this->agentSettingData["twoToThreeNum"]){
|
|
|
+ if($levelCount_2 && $this->agentSettingData["twoToThreeNum"]>0 && $levelCount_2>=$this->agentSettingData["twoToThreeNum"]){
|
|
|
$level = 3;//5个代理升级为董事
|
|
|
}
|
|
|
if($level<=$pData["level"]){
|
|
@@ -244,7 +271,7 @@ class AgentTools{
|
|
|
//获取配置
|
|
|
$dbSetting = new DNewAgentSetting('default');
|
|
|
$settingData = $dbSetting->get(["enterpriseId"=>$enterpriseId]);
|
|
|
- if(empty($settingData) || empty($settingData["is_open"]) || $settingData["oneOnePer"]<=0){
|
|
|
+ if(empty($settingData) || empty($settingData["is_open"])){
|
|
|
return ["code"=>-1,"msg"=>"还未进行分佣配置"];
|
|
|
}
|
|
|
//获取采购单信息
|
|
@@ -725,6 +752,69 @@ class AgentTools{
|
|
|
$data=[];
|
|
|
$nowTime = time();
|
|
|
$levelAr = ["xxxx","one","two"];
|
|
|
+
|
|
|
+
|
|
|
+ //获取门店父级列表
|
|
|
+ if(empty($shopData["parentPath"])){
|
|
|
+ return ["code"=>-1,"msg"=>"门店没有父级门店"];
|
|
|
+ }
|
|
|
+ //从最底层开始更新等级
|
|
|
+ $pathData = array_reverse(explode(",", trim($shopData["parentPath"])));
|
|
|
+ $perData=[];
|
|
|
+ for($i=0;$i<count($pathData);$i++){
|
|
|
+ if(empty($pathData[$i])){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $pData = $this->dbShop->get(["id"=>(int)$pathData[$i],"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
|
|
|
+ if(empty($pData) || empty($pData["agentId"])){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $per = 0;
|
|
|
+ if($pData["level"]==3){
|
|
|
+ $per = empty($this->agentSettingData["threePer"])?0:$this->agentSettingData["threePer"];
|
|
|
+ }else{
|
|
|
+ $perKey = $levelAr[(int)$pData["level"]].ucfirst($levelAr[(int)$shopData["level"]])."Per";
|
|
|
+ if(!empty($perKey)){
|
|
|
+ $per = empty($this->agentSettingData[$perKey]) ? 0 : $this->agentSettingData[$perKey];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($per>0){
|
|
|
+ $pmoney = bcmul($purchaseMoney,$per,2);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//先计算父级门店
|
|
|
$twoShopData = $this->dbShop->get(["id"=>$shopData["pTwoShopId"],"enterpriseId"=>$this->enterpriseId,"deleteStatus"=>5]);
|
|
|
if(!empty($twoShopData) && !empty($twoShopData["agentId"])){
|