购物车分类

This commit is contained in:
Jerry Yan 2019-09-22 22:10:04 +08:00
parent bb9bd68c7f
commit df11660e6a
7 changed files with 206 additions and 14 deletions

View 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;
}
}

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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 "<pre>";
if(empty($data)){
print_r(1);
}else{
foreach ($data as $datum){
print_r($datum);
}
}
die;
}

View File

@ -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;

View 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();
}
}

View File

@ -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 => "第十层",
];
}