购物车分类
This commit is contained in:
parent
bb9bd68c7f
commit
df11660e6a
69
hyhproject/app/controller/UserLevel.php
Normal file
69
hyhproject/app/controller/UserLevel.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace wstmart\app\controller;
|
||||||
|
|
||||||
|
use wstmart\app\model\Users;
|
||||||
|
use wstmart\common\model\UserLevel as UL;
|
||||||
|
use wstmart\common\model\UserTrees as UT;
|
||||||
|
|
||||||
|
use think\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ============================================================================
|
||||||
|
* 用户控制器
|
||||||
|
*/
|
||||||
|
class UserLevel extends Base
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $beforeActionList = [
|
||||||
|
'checkAuth' => ['except'=>'']// 访问这些except下的方法不需要执行前置操作
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* index
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
* @author 倪苍华 <canghua.cc@gmail.com>
|
||||||
|
* 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 倪苍华 <canghua.cc@gmail.com>
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ use Think\Db;
|
|||||||
* ============================================================================
|
* ============================================================================
|
||||||
* 用户类
|
* 用户类
|
||||||
*/
|
*/
|
||||||
class Users extends CUsers{
|
class Usersx extends CUsers{
|
||||||
/**
|
/**
|
||||||
* 验证用户支付密码
|
* 验证用户支付密码
|
||||||
*/
|
*/
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use think\Db;
|
use think\Db;
|
||||||
|
use wstmart\app\model\Base;
|
||||||
use wstmart\common\model\Aliyunoss;
|
use wstmart\common\model\Aliyunoss;
|
||||||
|
|
||||||
const WST_ADDON_PATH = './addons/';
|
const WST_ADDON_PATH = './addons/';
|
||||||
@ -2077,3 +2078,20 @@ function WSTShopOrderMenus(){
|
|||||||
}
|
}
|
||||||
return $orderMenus;
|
return $orderMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_my_id(){
|
||||||
|
return (int)session('WST_USER.userId');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function pd(...$data){
|
||||||
|
echo "<pre>";
|
||||||
|
if(empty($data)){
|
||||||
|
print_r(1);
|
||||||
|
}else{
|
||||||
|
foreach ($data as $datum){
|
||||||
|
print_r($datum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
@ -18,6 +18,7 @@ class Carts extends Base{
|
|||||||
//goods_specs表的规格ID
|
//goods_specs表的规格ID
|
||||||
$goodsSpecId = (int)input('post.goodsSpecId');
|
$goodsSpecId = (int)input('post.goodsSpecId');
|
||||||
$type = (int)input('post.type');
|
$type = (int)input('post.type');
|
||||||
|
$goodsType = (int)input('post.from',1);
|
||||||
//mark 添加验证
|
//mark 添加验证
|
||||||
//$m = new \addons\hyhsale\model\Hyhsale();
|
//$m = new \addons\hyhsale\model\Hyhsale();
|
||||||
// if($type == 0 && model('\addons\hyhsale\model\Hyhsale')->getEffectiveGoods(['goodsId'=>$goodsId,'specsId'=>$goodsSpecId])){
|
// 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['userId'] = $userId;
|
||||||
$data['goodsId'] = $goodsId;
|
$data['goodsId'] = $goodsId;
|
||||||
$data['goodsSpecId'] = $goodsSpecId;
|
$data['goodsSpecId'] = $goodsSpecId;
|
||||||
|
$data['goodsType'] = $goodsType;
|
||||||
$data['isCheck'] = 1;
|
$data['isCheck'] = 1;
|
||||||
$data['cartNum'] = $cartNum;
|
$data['cartNum'] = $cartNum;
|
||||||
$rs = $this->save($data);
|
$rs = $this->save($data);
|
||||||
@ -187,7 +189,9 @@ class Carts extends Base{
|
|||||||
public function getCarts($isSettlement = false, $uId=0, $areaId2=0){//添加会员地址判断 mark hsf 20171116
|
public function getCarts($isSettlement = false, $uId=0, $areaId2=0){//添加会员地址判断 mark hsf 20171116
|
||||||
$userId = ($uId==0)?(int)session('WST_USER.userId'):$uId;
|
$userId = ($uId==0)?(int)session('WST_USER.userId'):$uId;
|
||||||
$where = [];
|
$where = [];
|
||||||
|
$goodsType = (int)input('post.from',1);
|
||||||
$where['c.userId'] = $userId;
|
$where['c.userId'] = $userId;
|
||||||
|
$where['c.goodsType'] = $goodsType;
|
||||||
$where['g.dataFlag'] = 1;
|
$where['g.dataFlag'] = 1;
|
||||||
$where['g.goodsStatus'] = 1;
|
$where['g.goodsStatus'] = 1;
|
||||||
$where['g.isSale'] = 1;
|
$where['g.isSale'] = 1;
|
||||||
|
16
hyhproject/common/model/UserLevel.php
Normal file
16
hyhproject/common/model/UserLevel.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
namespace wstmart\common\model;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class UserLevel 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 getInfo($where,$field='pid'){
|
||||||
|
return $this->where($where)->field($field)->find();
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,101 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace wstmart\common\model;
|
namespace wstmart\common\model;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class UserTrees extends Base{
|
class UserTrees extends Base
|
||||||
public function getShareNum($where){
|
{
|
||||||
|
public function getShareNum($where)
|
||||||
|
{
|
||||||
return $this->where($where)->count();
|
return $this->where($where)->count();
|
||||||
}
|
}
|
||||||
public function getField($where,$field='pid'){
|
|
||||||
|
public function getField($where, $field = 'pid')
|
||||||
|
{
|
||||||
return $this->where($where)->value($field);
|
return $this->where($where)->value($field);
|
||||||
}
|
}
|
||||||
public function getInfo($where,$field='pid'){
|
|
||||||
|
public function getInfo($where, $field = 'pid')
|
||||||
|
{
|
||||||
return $this->where($where)->field($field)->find();
|
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 => "第十层",
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user