You've already forked qlg.tsgz.moe
							
							购物车分类
This commit is contained in:
		| @@ -1,16 +1,101 @@ | ||||
| <?php | ||||
|  | ||||
| namespace wstmart\common\model; | ||||
| /** | ||||
|  * | ||||
|  */ | ||||
| class UserTrees extends Base{ | ||||
|     public function getShareNum($where){ | ||||
|     	return $this->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 倪苍华 <canghua.cc@gmail.com> | ||||
|      * 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 倪苍华 <canghua.cc@gmail.com> | ||||
|      * 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 => "第十层", | ||||
|     ]; | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user