From df11660e6a9a0e095496ffc694d17ec5a3422777 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 22 Sep 2019 22:10:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hyhproject/app/controller/UserLevel.php | 69 +++++++++++++ hyhproject/app/model/Users - ╕▒▒╛.php | 6 +- hyhproject/app/model/Users.php | 6 +- hyhproject/common/common/function.php | 18 ++++ hyhproject/common/model/Carts.php | 6 +- hyhproject/common/model/UserLevel.php | 16 +++ hyhproject/common/model/UserTrees.php | 99 +++++++++++++++++-- 7 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 hyhproject/app/controller/UserLevel.php create mode 100644 hyhproject/common/model/UserLevel.php diff --git a/hyhproject/app/controller/UserLevel.php b/hyhproject/app/controller/UserLevel.php new file mode 100644 index 0000000..ae5b1f8 --- /dev/null +++ b/hyhproject/app/controller/UserLevel.php @@ -0,0 +1,69 @@ + ['except'=>'']// 访问这些except下的方法不需要执行前置操作 + ]; + + /** + * index + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @author 倪苍华 + * Date 2019/9/10 10:37 + */ + public function index() + { + $userId = get_my_id(); + $User = UT::getMyLevel($userId); + return $User; + } + + /** + * TreeList + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @author 倪苍华 + * Date 2019/9/10 11:18 + */ + public function TreeList() + { + $userId = get_my_id(); + $count = UL::where(['uid' => $userId])->group("level")->count(); + $treeArr = []; + $newLevel = 1; + do { + if ($newLevel > 10) break; + $treeArr[$newLevel]['level'] = UT::$level[$newLevel]; + $ptree = UT::where(['uid' => $userId])->find();// 找到我的层级 + $userId = $ptree->pid;// 上级uid + if ($userId == 0) $userId = 1;// 上级uid + $plevel = UL::where(['uid' => $userId, 'level' => $newLevel])->find();// 查看上级是否有权限助购 + if ($plevel) {// 如果有,则使用上级信息 + $treeArr[$newLevel]['userId'] = $userId; + $user = Users::where(['userId' => $plevel->uid])->find(); + $treeArr[$newLevel]['userName'] = $user->userName ?: $user->loginName; + $newLevel++; + } + // 如果没有,则递归查询上级信息 + } while ($newLevel < ($count + 2)); +// pd($treeArr); + return $treeArr; + } +} diff --git a/hyhproject/app/model/Users - ╕▒▒╛.php b/hyhproject/app/model/Users - ╕▒▒╛.php index 0f24fff..08db33e 100755 --- a/hyhproject/app/model/Users - ╕▒▒╛.php +++ b/hyhproject/app/model/Users - ╕▒▒╛.php @@ -6,10 +6,10 @@ use Think\Db; * ============================================================================ * 用户类 */ -class Users extends CUsers{ +class Usersx extends CUsers{ /** * 验证用户支付密码 - */ + */ function checkPayPwd(){ $payPwd = input('payPwd'); $decrypt_data = WSTRSA($payPwd); @@ -31,7 +31,7 @@ class Users extends CUsers{ * @return [type] [description] */ function getIndex($userId){ - + } function getUserInfo($userId,$field){ return $this->where(['userId'=>$userId])->field($field)->find(); diff --git a/hyhproject/app/model/Users.php b/hyhproject/app/model/Users.php index b9567fc..7fd0eee 100755 --- a/hyhproject/app/model/Users.php +++ b/hyhproject/app/model/Users.php @@ -10,7 +10,7 @@ use Think\Db; class Users extends CUsers{ /** * 验证用户支付密码 - */ + */ function checkPayPwd(){ $payPwd = input('payPwd'); $decrypt_data = WSTRSA($payPwd); @@ -32,7 +32,7 @@ class Users extends CUsers{ * @return [type] [description] */ function getIndex($userId){ - + } function getUserInfo($userId,$field){ return $this->where(['userId'=>$userId])->field($field)->find(); @@ -43,6 +43,6 @@ class Users extends CUsers{ //setcookie("loginPwd", null); session('WST_MO_WlADDRESS',null); } - + } diff --git a/hyhproject/common/common/function.php b/hyhproject/common/common/function.php index bffe81a..45eda9b 100755 --- a/hyhproject/common/common/function.php +++ b/hyhproject/common/common/function.php @@ -4,6 +4,7 @@ */ use think\Db; +use wstmart\app\model\Base; use wstmart\common\model\Aliyunoss; const WST_ADDON_PATH = './addons/'; @@ -2077,3 +2078,20 @@ function WSTShopOrderMenus(){ } return $orderMenus; } + +function get_my_id(){ + return (int)session('WST_USER.userId'); +} + + +function pd(...$data){ + echo "
";
+    if(empty($data)){
+        print_r(1);
+    }else{
+        foreach ($data as $datum){
+            print_r($datum);
+        }
+    }
+    die;
+}
diff --git a/hyhproject/common/model/Carts.php b/hyhproject/common/model/Carts.php
index 70889dc..42d2f05 100755
--- a/hyhproject/common/model/Carts.php
+++ b/hyhproject/common/model/Carts.php
@@ -18,6 +18,7 @@ class Carts extends Base{
 		//goods_specs表的规格ID
 		$goodsSpecId = (int)input('post.goodsSpecId');
 		$type = (int)input('post.type');
+		$goodsType = (int)input('post.from',1);
 		//mark 添加验证
 		//$m = new \addons\hyhsale\model\Hyhsale();
 		// if($type == 0 && model('\addons\hyhsale\model\Hyhsale')->getEffectiveGoods(['goodsId'=>$goodsId,'specsId'=>$goodsSpecId])){
@@ -43,6 +44,7 @@ class Carts extends Base{
 				$data['userId'] = $userId;
 				$data['goodsId'] = $goodsId;
 				$data['goodsSpecId'] = $goodsSpecId;
+				$data['goodsType'] = $goodsType;
 				$data['isCheck'] = 1;
 				$data['cartNum'] = $cartNum;
 				$rs = $this->save($data);
@@ -187,7 +189,9 @@ class Carts extends Base{
 	public function getCarts($isSettlement = false, $uId=0, $areaId2=0){//添加会员地址判断 mark hsf 20171116 
 		$userId = ($uId==0)?(int)session('WST_USER.userId'):$uId;
 		$where = [];
-		$where['c.userId'] = $userId;
+        $goodsType = (int)input('post.from',1);
+        $where['c.userId'] = $userId;
+		$where['c.goodsType'] = $goodsType;
 		$where['g.dataFlag'] = 1;
 		$where['g.goodsStatus'] = 1;	
 		$where['g.isSale'] = 1;
diff --git a/hyhproject/common/model/UserLevel.php b/hyhproject/common/model/UserLevel.php
new file mode 100644
index 0000000..b6b55b8
--- /dev/null
+++ b/hyhproject/common/model/UserLevel.php
@@ -0,0 +1,16 @@
+where($where)->count();
+    }
+    public function getField($where,$field='pid'){
+    	return $this->where($where)->value($field);
+    }
+    public function getInfo($where,$field='pid'){
+    	return $this->where($where)->field($field)->find();
+    }
+}
diff --git a/hyhproject/common/model/UserTrees.php b/hyhproject/common/model/UserTrees.php
index 50efb16..3328581 100755
--- a/hyhproject/common/model/UserTrees.php
+++ b/hyhproject/common/model/UserTrees.php
@@ -1,16 +1,101 @@
 where($where)->count();
+class UserTrees extends Base
+{
+    public function getShareNum($where)
+    {
+        return $this->where($where)->count();
     }
-    public function getField($where,$field='pid'){
-    	return $this->where($where)->value($field);
+
+    public function getField($where, $field = 'pid')
+    {
+        return $this->where($where)->value($field);
     }
-    public function getInfo($where,$field='pid'){
-    	return $this->where($where)->field($field)->find();
+
+    public function getInfo($where, $field = 'pid')
+    {
+        return $this->where($where)->field($field)->find();
     }
+
+    /**
+     * getMyLevel
+     * @RequestMapping("getMyLevel")
+     * @param       $userId
+     * @param int   $level
+     * @param array $levelArr
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @author 倪苍华 
+     * Date 2019/9/10 10:35
+     */
+    public static function getMyLevel($userId, $level = 1, $levelArr = [])
+    {
+        $myChildren = [];
+        if ($userId) {
+            $myChildren = self::where("pid in($userId)")->select();
+        }
+        $ids = [];
+        $key = 0;
+        foreach ($myChildren as $key => $v) {
+            $ids[] = $v['uid'];
+        }
+        $levelArr[$level]['count'] = $key + 1;
+        $levelArr[$level]['total'] = 0;
+        $level++;
+
+        if ($level <= 10) {
+            return self::getMyLevel(implode(',', $ids), $level, $levelArr);
+        } else {
+            return self::getMyProductNum($levelArr);
+        }
+    }
+
+    /**
+     * getMyProductNum
+     * @RequestMapping("getMyProductNum")
+     * @param $levelArr
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @author 倪苍华 
+     * Date 2019/9/10 11:02
+     */
+    public static function getMyProductNum($levelArr)
+    {
+        foreach ($levelArr as $key => $v){
+            $levels = UserLevel::where(['uid'=>get_my_id(),'level' => $key])->select();
+            $ids = [];
+            foreach ($levels as $lvk => $lvv){
+                $ids[] = $lvv->pid;
+            }
+            $ids = implode(',',$ids);
+            if(!$ids){
+                $ids = 0;
+            }
+            $levelArr[$key]['total'] += \wstmart\app\model\Users::where("userId in($ids)")->sum("productNum");
+            $levelArr[$key]['level'] = self::$level[$key];
+        }
+        return $levelArr;
+    }
+
+    public static $level = [
+        1 => "第一层",
+        2 => "第二层",
+        3 => "第三层",
+        4 => "第四层",
+        5 => "第五层",
+        6 => "第六层",
+        7 => "第七层",
+        8 => "第八层",
+        9 => "第九层",
+        10 => "第十层",
+    ];
+
 }