yingzi пре 2 година
родитељ
комит
c7a0372064

+ 16 - 1
Controller/Commission/ApiCommissionBusinessman.Class.php

@@ -20,6 +20,9 @@ use JinDouYun\Controller\BaseController;
 
 use JinDouYun\Model\Commission\MCommissionBusinessman;
 
+use Util\Common\PartnerTools;
+use JinDouYun\Model\Customer\MCustomer;
+
 class ApiCommissionBusinessman extends BaseController
 {
     /**
@@ -31,6 +34,10 @@ class ApiCommissionBusinessman extends BaseController
      * @var MCommissionOrder
      */
     private $objMCommissionOrder;
+    
+    
+    private $customerData;
+    private $partnerTool;
 
     /**
      * ApiCommissionBusinessman constructor.
@@ -44,6 +51,9 @@ class ApiCommissionBusinessman extends BaseController
         parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
         $this->objMCommissionBusinessman = new MCommissionBusinessman($this->onlineEnterpriseId, $this->onlineUserId);
         $this->objMCommissionOrder = new MCommissionOrder($this->onlineEnterpriseId,$this->onlineUserId);
+        
+        $this->partnerTool = new PartnerTools($this->onlineEnterpriseId);
+        $this->customerData = $this->partnerTool->getCustomerDataByUserCenterId($this->onlineUserId);
     }
 
     /**
@@ -99,6 +109,11 @@ class ApiCommissionBusinessman extends BaseController
             'businessmanId' => getArrayItem($params, 'businessmanId'),
             'source' => getArrayItem($params, 'source'),
         ];
+        //新分销合伙人添加下级
+        if(!empty($data['businessmanId']) && !empty($this->customerData["id"])){
+            $this->partnerTool->setPushCustomer($data['businessmanId'], $this->customerData["id"]);
+        }
+        
         foreach($data as $key => $value){
             if(empty($value) && $value !== 0){
                 parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
@@ -111,7 +126,7 @@ class ApiCommissionBusinessman extends BaseController
         }
         parent::sendOutput($modelResult->getData());
     }
-
+    
     /**
      * 修改分销商
      * @throws Exception

+ 245 - 0
Controller/NewCommission/ApiNewCommissionPartner.Class.php

@@ -0,0 +1,245 @@
+<?php
+/**
+ * api新分销商合伙人Controller
+ * Created by PhpStorm.
+ * User: haoren
+ * Date: 2020/07/22
+ * Time: 15:00
+ */
+
+namespace JinDouYun\Controller\NewCommission;
+
+use Exception;
+use Mall\Framework\Core\ErrorCode;
+use Mall\Framework\Core\ResultWrapper;
+use Mall\Framework\Core\StatusCode;
+use JinDouYun\Controller\BaseController;
+
+use Util\Common\PartnerTools;
+use JinDouYun\Model\Customer\MCustomer;
+
+class ApiNewCommissionPartner extends BaseController
+{
+    
+    private $customerData;
+    private $partnerTool;
+
+    public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken=true)
+    {
+        parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
+        $this->partnerTool = new PartnerTools($this->onlineEnterpriseId);
+        $this->customerData = $this->partnerTool->getCustomerDataByUserCenterId($this->onlineUserId);
+
+    }
+    
+    
+    /**
+     * 获取账户信息
+     */
+    public function getCommissionPartnerData(){
+        if($this->customerData["isPartner"]==0){
+            parent::sendOutput('您还不是合伙人', ErrorCode::$paramError);
+        }
+        $data = $this->partnerTool->getPartnerData($this->customerData["id"],$this->onlineUserId);
+        if(empty($data)){
+            parent::sendOutput('数据不存在', ErrorCode::$paramError);
+        }
+        parent::sendOutput($data);
+    }
+    /**
+     * 获取分佣明细
+     */
+    public function getCommissionPartnerDetail(){
+        $params = $this->request->getRawJson();
+        if(empty($params)){
+            parent::sendOutput('参数为空', ErrorCode::$paramError);
+        }
+        $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
+        $selectParams['limit'] = $pageParams['limit'];
+        $selectParams['offset'] = $pageParams['offset'];
+        $data = $this->partnerTool->getCommissionDetail($this->customerData["id"],$selectParams);
+        parent::sendOutput($data);
+    }
+    /**
+     * 获取分佣账户余额明细
+     */
+    public function getCommissionPartnerBalanceDetail(){
+        $params = $this->request->getRawJson();
+        if(empty($params)){
+            parent::sendOutput('参数为空', ErrorCode::$paramError);
+        }
+        $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
+        $selectParams['limit'] = $pageParams['limit'];
+        $selectParams['offset'] = $pageParams['offset'];
+        $data = $this->partnerTool->getCommissionBalanceDetail($this->customerData["id"],$selectParams);
+        parent::sendOutput($data);
+    }
+    
+    public function partnerApplyCash(){
+//        $cache = Factory::cache('systask');
+        //        $key = "partnercashcache".'::'.$this->enterpriseId;
+//        $result = $this->cache->get($key);
+//        if(!empty($result)){
+//            return ["code"=>-1,"msg"=>"操作频繁"];
+//        }
+//        $this->cache->set($key,1,10);
+        
+        
+        
+//        [$money] = UtilService::getMore([
+//            ['money', 0, 'is_numeric', '请输入正确的提现金额'],
+//        ], $request, true);
+//        //缓存
+//        $redis = \think\facade\Cache::store('redis');
+//        $key   = 'user_tixian_' . $request->user['uid'];
+//        $bool  = $redis->handler()->exists($key);
+//        if ($bool) {
+//            return app('json')->fail('您的操作过于频繁,请稍等再重试!');
+//        }
+//        $redis->set($key,1,10);//30秒缓存
+//        $user = $request->user;
+//        if(empty($user["openid"])){
+//            return app('json')->fail('您还未绑定微信');
+//        }
+//        if(floatval($money)<=0){
+//            return app('json')->fail('请输入正确的提现金额');
+//        }
+//        if(floatval($money)>$user["money"]){
+//            return app('json')->fail('您的余额不足,无法提现');
+//        }
+//        if(empty($user["bank_type"]) || empty($user["bank_num"]) || empty($user["bank_name"])){
+//            return app('json')->fail('您还未绑定提现账户');
+//        }
+//        if($user["bank_type"]!="alipay" && empty($user["bank_ad"])){
+//            return app('json')->fail('您还未绑定提现开户行');
+//        }
+//        $sysData = (new SysModel)->where("id",1)->find();
+//        if(floatval($user["money"])<floatval($sysData["tx_limit_money"]) || floatval($money)<floatval($sysData["tx_limit_money"])){
+//            return app('json')->fail("满{$sysData['tx_limit_money']}元,才可提现");
+//        }
+//        //提现手续费
+//        $hand_money = $sysData["tx_process_per"] > 0 ? floatval($money) * $sysData["tx_process_per"] / 100 : 0;
+//        $hand_money = num_min_format($hand_money);
+//        $save=[];
+//        $save["uid"]        = $user["uid"];
+//        $save["bank_type"]  = $user["bank_type"];
+//        $save["bank_num"]   = $user["bank_num"];
+//        $save["bank_name"]  = $user["bank_name"];
+//        $save["bank_ad"]    = $user["bank_ad"];
+//        $save["money"]      = floatval($money);
+//        $save["hand_money"] = ($sysData["tx_process_max"] > 0 && $hand_money > $sysData["tx_process_max"]) ? $sysData["tx_process_max"] : $hand_money;
+//        $save["tx_money"]   = $save["money"] - $save["hand_money"];
+//        $save["status"]     = 0;
+//        $save["time"]       = time();
+//        try{
+//            Db::startTrans();
+//            //插入提现申请
+//            $tx_id = (new TxModel)->insertGetId($save);
+//            if(empty($tx_id)){
+//                return app('json')->fail('提交失败');
+//            }
+//            //更新提现账户余额并添加明细
+//            $r= (new UserDetailModel)->txApplyMoney($user["uid"],floatval($money),$tx_id);
+//            if(!$r){
+//                (new TxModel)->where("id",$tx_id)->delete();
+//                return app('json')->fail('提交失败');
+//            }
+//            Db::commit();
+//            $redis->delete($key);
+//            return app('json')->success('提交成功,等待客服处理');
+//        } catch (DbException $db){
+//            Db::rollback();
+//            return app('json')->fail("订单生成失败");
+//        }
+    }
+    
+    
+
+    
+
+    /**
+     * 添加上下级关系
+     * @throws Exception
+     */
+    public function relationshipBusinessman()
+    {
+        $params = $this->request->getRawJson();
+        if(empty($params)){
+            parent::sendOutput('参数为空', ErrorCode::$paramError);
+        }
+
+        $data = [
+            'businessmanId' => getArrayItem($params, 'businessmanId'),
+            'source' => getArrayItem($params, 'source'),
+        ];
+        foreach($data as $key => $value){
+            if(empty($value) && $value !== 0){
+                parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
+            }
+        }
+
+        $modelResult = $this->objMCommissionBusinessman->relationshipBusinessman($data);
+        if(!$modelResult->isSuccess()){
+            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
+        }
+        parent::sendOutput($modelResult->getData());
+    }
+
+    
+
+    /**
+     * 分销商详情
+     */
+    public function getInfoBusinessman()
+    {
+        $where['userCenterId'] = $this->onlineUserId;
+        $modelResult = $this->objMCommissionBusinessman->getInfoBusinessman($where);
+        if(!$modelResult->isSuccess()){
+            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
+        }
+        parent::sendOutput($modelResult->getData());
+    }
+
+    /**
+     * 查询分销商的所有下级
+     * @throws Exception
+     */
+    public function getAllSub()
+    {
+        $params = $this->request->getRawJson();
+        if(empty($params)){
+            parent::sendOutput('参数为空', ErrorCode::$paramError);
+        }
+        $data = [
+            'id' => isset($params['id']) ? $params['id'] : '',
+            'level' => isset($params['level']) ? $params['level'] : '',
+            'page' => isset($params['page']) ? $params['page'] : '',
+            'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : '',
+        ];
+        foreach($data as $key => $value){
+            if(empty($value) && $value !== 0){
+                parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
+            }
+        }
+        $pageParams = pageToOffset($params['page'],$params['pageSize']);
+        $data['limit'] = $pageParams['limit'];
+        $data['offset'] = $pageParams['offset'];
+
+        $modelResult = $this->objMCommissionBusinessman->getAllSub($data);
+        if(!$modelResult->isSuccess()){
+            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
+        }
+        $returnData = $modelResult->getData();
+
+        $pageData = [
+            'pageIndex' => $params['page'],
+            'pageSize' => $params['pageSize'],
+            'pageTotal' => $returnData['total'],
+            'subTotal' => $returnData['subTotal'],
+            'businessmanTotal' => $returnData['businessmanTotal'],
+            'subBusinessmanTotal' => $returnData['subBusinessmanTotal'],
+        ];
+        parent::sendOutput($returnData['data'], 0, $pageData);
+    }
+
+}

+ 80 - 0
Util/Common/PartnerTools.Class.php

@@ -154,6 +154,34 @@ class PartnerTools{
     }
     
     
+    public function getCustomerDataByUserCenterId($userCenterId){
+        if(empty($userCenterId)){
+            return false;
+        }
+        $data = $this->dbCustomer->get(["userCenterId"=>$userCenterId]);
+        if(empty($data)){
+            return false;
+        }
+        return $data;
+        
+    }
+    
+    public function setPushCustomerByUserCenterId($parentId=0,$childId=0){
+        //子级用户信息
+        $childData = $this->dbCustomer->get(["userCenterId"=>$childId]);
+        if (empty($childData) || $childData["parentId"]>0 || $childData["isPartner"]==1 || $childData["isParentHead"]==1) {
+            return ["code"=>-1,"msg"=>"用户不能被绑定","data"=>$childData];
+        }
+        //父级用户信息
+        $parentData = $this->dbCustomer->get(["userCenterId"=>$parentId]);
+        if(empty($parentData)){
+            return ["code"=>-1,"msg"=>"父级用户不存在","data"=>null];
+        }
+        var_dump($childData["id"]);
+        var_dump($parentData["id"]);
+        return false;
+        return $this->setPushCustomer($parentData["id"],$childData["id"]);
+    }
     
     /**
      * 设置推广用户
@@ -501,6 +529,58 @@ class PartnerTools{
         return $partnerData;
     }
     
+    /**
+     * 获取分佣明细
+     */
+    public function getCommissionDetail($customerId,$parms){
+        $where=[];
+        if(!empty($customerId)){
+            $where["customerId"] = $customerId;
+        }
+        $data = $this->dbNewCommissionDetail->select(["customerId"=>$customerId], "*", "id desc", $parms["limit"], $parms["offset"]);
+        $total = $this->dbNewCommissionDetail->count($where);
+        if(empty($data)){
+            $data = [];
+        }
+        $return = [
+            'data'   => $data,
+            'total'  => (isset($total)&&!empty($total)) ? intval($total) : 0,
+        ];
+        return $return;
+    }
+    /**
+     * 获取合伙人账户余额明细
+     */
+    public function getCommissionBalanceDetail($customerId,$parms){
+        $where=[];
+        if(!empty($customerId)){
+            $where["customerId"] = $customerId;
+        }
+        $data = $this->dbNewCommissionBalanceDetail->select(["customerId"=>$customerId], "*", "id desc", $parms["limit"], $parms["offset"]);
+        $total = $this->dbNewCommissionBalanceDetail->count($where);
+        if(empty($data)){
+            $data = [];
+        }
+        $return = [
+            'data'   => $data,
+            'total'  => (isset($total)&&!empty($total)) ? intval($total) : 0,
+        ];
+        return $return;
+    }
+    
+    /**
+     * 提现申请
+     */
+    public function applyCash($data){
+
+        
+        
+        
+    }
+    
+    
+    
+    
     
     /**
      * 删除用户缓存