You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
229
hyhproject/home/model/Articles.php
Executable file
229
hyhproject/home/model/Articles.php
Executable file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 文章类
|
||||
*/
|
||||
use think\Db;
|
||||
class Articles extends Base{
|
||||
/**
|
||||
* 获取帮助左侧列表
|
||||
*/
|
||||
public function helpList(){
|
||||
$arts = cache('arts');
|
||||
if(!$arts){
|
||||
$rs = $this->alias('a')->join('article_cats ac','a.catId=ac.catId','inner')
|
||||
->field('a.articleId,a.catId,a.articleTitle,ac.catName')
|
||||
->where(['a.dataFlag'=>1,
|
||||
'a.isshow'=>1,
|
||||
'ac.dataFlag'=>1,
|
||||
'ac.isShow'=>1,
|
||||
'ac.parentId'=>7])
|
||||
->cache(true)
|
||||
->select();
|
||||
//同一分类下的文章放一起
|
||||
$catName = [];
|
||||
$arts = [];
|
||||
foreach($rs as $k=>$v){
|
||||
if(in_array($v['catName'],$catName)){
|
||||
$arts[$v['catName'].'-'.$v['catId']][] = $v;
|
||||
}else{
|
||||
$catName[] = $v['catName'];
|
||||
$arts[$v['catName'].'-'.$v['catId']][] = $v;
|
||||
}
|
||||
}
|
||||
cache('arts',$arts,86400);
|
||||
}
|
||||
return $arts;
|
||||
}
|
||||
/**
|
||||
* 根据id获取帮助文章
|
||||
*/
|
||||
public function getHelpById(){
|
||||
$id = (int)input('id');
|
||||
WSTArticleVisitorNum($id);// 统计文章访问量
|
||||
return $this->alias('a')->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')->where('ac.parentId=7 and a.dataFlag=1 and a.isShow=1')->cache(true)->find($id);
|
||||
}
|
||||
/**
|
||||
* 根据id获取资讯文章
|
||||
*/
|
||||
public function getNewsById($id = 0){
|
||||
$id = $id>0?$id:(int)input('id');
|
||||
WSTArticleVisitorNum($id);// 统计文章访问量
|
||||
return $this->alias('a')
|
||||
->field('a.*,ac.catName')
|
||||
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
|
||||
->where('a.catId<>7 and ac.parentId<>7 and a.dataFlag=1 and a.isShow=1')
|
||||
->cache(true)
|
||||
->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资讯列表【左侧分类】
|
||||
*/
|
||||
public function NewsList(){
|
||||
$list = $this->getTree();
|
||||
foreach($list as $k=>$v){
|
||||
if(!empty($v['children'])){
|
||||
foreach($v['children'] as $k1=>$v1){
|
||||
// 二级分类下的文章总条数
|
||||
$list[$k]['children'][$k1]['newsCount'] = $this->where(['catId'=>$v1['catId'],
|
||||
'dataFlag'=>1,'isShow'=>1])->cache(true)->count();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getTree(){
|
||||
$artTree = cache('artTree');
|
||||
if(!$artTree){
|
||||
$data = Db::name('article_cats')->field('catName,catId,parentId')->where('parentId <> 7 and catId <> 7 and dataFlag=1 and isShow=1')->cache(true)->select();
|
||||
$artTree = $this->_getTree($data, 0);
|
||||
cache('artTree',$artTree,86400);
|
||||
}
|
||||
return $artTree;
|
||||
}
|
||||
public function _getTree($data,$parentId){
|
||||
$tree = [];
|
||||
foreach($data as $k=>$v){
|
||||
if($v['parentId']==$parentId){
|
||||
// 再找其下级分类
|
||||
$v['children'] = $this->_getTree($data,$v['catId']);
|
||||
$tree[] = $v;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
/**
|
||||
* 根据分类id获取文章列表
|
||||
*/
|
||||
public function nList(){
|
||||
$catId = (int)input('catId');
|
||||
$rs = $this->alias('a')
|
||||
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
|
||||
->field('a.*')
|
||||
->where(['a.catId'=>$catId,
|
||||
'a.dataFlag'=>1,
|
||||
'a.isShow'=>1,
|
||||
'ac.dataFlag'=>1,
|
||||
'ac.isShow'=>1,
|
||||
'ac.parentId'=>['<>',7],
|
||||
])
|
||||
->cache(true)
|
||||
->paginate();
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 面包屑导航
|
||||
*/
|
||||
public function bcNav(){
|
||||
$catId = (int)input('catId'); //分类id
|
||||
$artId = (int)input('id'); //文章id
|
||||
$data = Db::name('article_cats')->field('catId,parentId,catName')->cache(true)->select();
|
||||
if($artId){
|
||||
$catId = $this->where('articleId',$artId)->value('catId');
|
||||
}
|
||||
$bcNav = $this->getParents($data,$catId,$isClear=true);
|
||||
return $bcNav;
|
||||
|
||||
}
|
||||
/**
|
||||
* 获取父级分类
|
||||
*/
|
||||
public function getParents($data, $catId,$isClear=false){
|
||||
static $bcNav = [];
|
||||
if($isClear)
|
||||
$bcNav = [];
|
||||
foreach($data as $k=>$v){
|
||||
if($catId == $v['catId']){
|
||||
if($catId!=0){
|
||||
$this->getParents($data, $v['parentId']);
|
||||
$bcNav[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $bcNav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录解决情况
|
||||
*/
|
||||
public function recordSolve(){
|
||||
$articleId = (int)input('id');
|
||||
$status = (int)input('status');
|
||||
if($status==1){
|
||||
$rs = $this->where('articleId',$articleId)->setInc('solve');
|
||||
}else{
|
||||
$rs = $this->where('articleId',$articleId)->setInc('unsolve');
|
||||
}
|
||||
if($rs!==false){
|
||||
return WSTReturn('操作成功',1);
|
||||
}else{
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资讯中心的子集分类id
|
||||
*/
|
||||
public function getChildIds(){
|
||||
$ids = [];
|
||||
$data = Db::name('article_cats')->cache(true)->select();
|
||||
foreach($data as $k=>$v){
|
||||
if($v['parentId']!=7 && $v['catId']!=7 && $v['parentId']!=0 ){
|
||||
$ids[] = $v['catId'];
|
||||
}
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取咨询中中心所有文章
|
||||
*/
|
||||
public function getArticles(){
|
||||
// 获取咨询中心下的所有分类id
|
||||
$ids = $this->getChildIds();
|
||||
$rs = $this->alias('a')
|
||||
->field('a.*')
|
||||
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
|
||||
->where(['a.catId'=>['in',$ids],
|
||||
'a.dataFlag'=>1,
|
||||
'a.isShow'=>1,
|
||||
'ac.dataFlag'=>1,
|
||||
'ac.isShow'=>1,
|
||||
'ac.parentId'=>['<>',7],
|
||||
])
|
||||
->distinct(true)
|
||||
->cache(true)
|
||||
->paginate(15);
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定分类下的文章
|
||||
*/
|
||||
public function getArticlesByCat($catId){
|
||||
$ids = $this->getChildIds();
|
||||
$rs = $this->alias('a')
|
||||
->field('a.*')
|
||||
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
|
||||
->where(['a.catId'=>['in',$ids],
|
||||
'a.dataFlag'=>1,
|
||||
'a.isShow'=>1,
|
||||
'ac.dataFlag'=>1,
|
||||
'ac.isShow'=>1,
|
||||
'ac.parentId'=>['<>',7],
|
||||
])
|
||||
->distinct(true)
|
||||
->cache(true)
|
||||
->select();
|
||||
$data = [];
|
||||
if(!empty($rs)){
|
||||
foreach($rs as $key =>$v){
|
||||
$data[$v['articleId']] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
61
hyhproject/home/model/Attributes.php
Executable file
61
hyhproject/home/model/Attributes.php
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use wstmart\common\model\GoodsCats as M;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 商品属性分类
|
||||
*/
|
||||
class Attributes extends Base{
|
||||
/**
|
||||
* 获取可供筛选的商品属性
|
||||
*/
|
||||
public function listQueryByFilter($catId){
|
||||
$m = new M();
|
||||
$ids = $m->getParentIs($catId);
|
||||
if(!empty($ids)){
|
||||
$catIds = [];
|
||||
foreach ($ids as $key =>$v){
|
||||
$catIds[] = $v;
|
||||
}
|
||||
/*$attrs = $this->alias('a')
|
||||
->join('__GOODS_ATTRIBUTES__ ga','ga.attrId=a.attrId','inner')
|
||||
->where(['a.goodsCatId'=>['in',$catIds],'a.isShow'=>1,'a.dataFlag'=>1,'a.attrType'=>['<>',0]])
|
||||
->field('a.attrId,a.attrName,a.attrVal')->order('a.attrSort asc')->select();*/
|
||||
|
||||
// 取出分类下有设置的属性。
|
||||
$attrs = $this->alias('a')
|
||||
->join('__GOODS_ATTRIBUTES__ ga','ga.attrId=a.attrId','inner')
|
||||
->field('ga.attrId,GROUP_CONCAT(distinct ga.attrVal) attrVal,a.attrName')
|
||||
->where(['a.goodsCatId'=>['in',$catIds],'a.isShow'=>1,'a.dataFlag'=>1,'a.attrType'=>['<>',0]])
|
||||
->group('ga.attrId')
|
||||
->order('a.attrSort asc')
|
||||
->select();
|
||||
foreach ($attrs as $key =>$v){
|
||||
$attrs[$key]['attrVal'] = explode(',',$v['attrVal']);
|
||||
}
|
||||
return $attrs;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
/**
|
||||
* 根据商品id获取可供选择的属性
|
||||
*/
|
||||
public function getAttribute($goodsId){
|
||||
if(empty($goodsId))return [];
|
||||
$attrs = $this->alias('a')
|
||||
->join('__GOODS_ATTRIBUTES__ ga','ga.attrId=a.attrId','inner')
|
||||
->field('ga.attrId,GROUP_CONCAT(distinct ga.attrVal) attrVal,a.attrName')
|
||||
->where(['ga.goodsId'=>['in',$goodsId],
|
||||
'a.isShow'=>1,
|
||||
'a.dataFlag'=>1,
|
||||
'a.attrType'=>['<>',0]])
|
||||
->group('ga.attrId')
|
||||
->order('a.attrSort asc')
|
||||
->select();
|
||||
if(empty($attrs))return [];
|
||||
foreach ($attrs as $key =>$v){
|
||||
$attrs[$key]['attrVal'] = explode(',',$v['attrVal']);
|
||||
}
|
||||
return $attrs;
|
||||
}
|
||||
}
|
9
hyhproject/home/model/Base.php
Executable file
9
hyhproject/home/model/Base.php
Executable file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use wstmart\common\model\Base as CBase;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 基础模型器
|
||||
*/
|
||||
|
||||
class Base extends CBase {}
|
1315
hyhproject/home/model/Goods.php
Executable file
1315
hyhproject/home/model/Goods.php
Executable file
File diff suppressed because it is too large
Load Diff
174
hyhproject/home/model/GoodsVirtuals.php
Executable file
174
hyhproject/home/model/GoodsVirtuals.php
Executable file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use wstmart\common\model\Goods as CGoodsVirtuals;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 虚拟商品卡券模型
|
||||
*/
|
||||
class GoodsVirtuals extends CGoodsVirtuals{
|
||||
/**
|
||||
* 导入
|
||||
*/
|
||||
public function importCards($data){
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objReader = \PHPExcel_IOFactory::load(WSTRootPath().json_decode($data)->route.json_decode($data)->name);
|
||||
$objReader->setActiveSheetIndex(0);
|
||||
$sheet = $objReader->getActiveSheet();
|
||||
$rows = $sheet->getHighestRow();
|
||||
$cells = $sheet->getHighestColumn();
|
||||
//数据集合
|
||||
$readData = [];
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$goodsId = (int)input('goodsId');
|
||||
$importNum = 0;
|
||||
//生成订单
|
||||
Db::startTrans();
|
||||
try{
|
||||
//读取现有的卡券
|
||||
$goodscards = Db::name('goods_virtuals')->where(['dataFlag'=>1,'goodsId'=>$goodsId])->field('cardNo')->select();
|
||||
$goodscardsMap = [];
|
||||
if(count($goodscards)>0){
|
||||
foreach($goodscards as $v){
|
||||
$goodscardsMap[] = $v['cardNo'];
|
||||
}
|
||||
}
|
||||
//循环读取每个单元格的数据
|
||||
for ($row = 2; $row <= $rows; $row++){//行数是以第2行开始
|
||||
$cards = [];
|
||||
$cards['shopId'] = $shopId;
|
||||
$cards['goodsId'] = $goodsId;
|
||||
$cardNo = trim($sheet->getCell("A".$row)->getValue());
|
||||
if($cardNo=='')break;//如果某一行第一列为空则停止导入
|
||||
$cards['cardNo'] = $cardNo;
|
||||
$cards['cardPwd'] = trim($sheet->getCell("B".$row)->getValue());
|
||||
$cards['createTime'] = date('Y-m-d H:i:s');
|
||||
if(in_array($cardNo,$goodscardsMap))continue;
|
||||
$goodscardsMap[] = $cardNo;
|
||||
$readData[] = $cards;
|
||||
$importNum++;
|
||||
}
|
||||
if(count($readData)>0){
|
||||
model('GoodsVirtuals')->saveAll($readData);
|
||||
$this->updateGoodsStock($goodsId);
|
||||
}
|
||||
Db::commit();
|
||||
return json_encode(['status'=>1,'importNum'=>$importNum]);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return json_encode(WSTReturn('导入商品卡券失败',-1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$ids = input('ids');
|
||||
$id = input('id');
|
||||
if($ids=='')return WSTReturn('请选择要删除的卡券号');
|
||||
try{
|
||||
$this->where(['shopId'=>$shopId,'id'=>['in',$ids],'goodsId'=>$id])->update(['dataFlag'=>-1]);
|
||||
$this->updateGoodsStock($id);
|
||||
Db::commit();
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('操作失败');
|
||||
}
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$id = (int)input('id');
|
||||
//判断卡券是否有效
|
||||
$rs = $this->where(['id'=>$id,'shopId'=>$shopId,'dataFlag'=>1,'isUse'=>0])->find();
|
||||
if(empty($rs))return WSTReturn('非法的卡券');
|
||||
$cardNo = input('cardNo');
|
||||
$cardPwd = input('cardPwd');
|
||||
if($cardNo=='' || $cardPwd=='')return WSTReturn('请输入完整卡券信息');
|
||||
$conts = $this->where(['shopId'=>$shopId,'dataFlag'=>1,'cardNo'=>$cardNo,'id'=>['<>',$id]])->Count();
|
||||
if($conts>0)return WSTReturn('该卡券号已存在,请重新输入');
|
||||
$rs->cardNo = $cardNo;
|
||||
$rs->cardPwd = $cardPwd;
|
||||
$rs->save();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取虚拟商品库存列表
|
||||
*/
|
||||
public function stockByPage(){
|
||||
$key = input('cardNo');
|
||||
$id = (int)input('id');
|
||||
$isUse = (int)input('isUse',-1);
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$where = ['shopId'=>$shopId,'goodsId'=>$id,'dataFlag'=>1];
|
||||
if($key !='')$where['cardNo'] = ['like','%'.$key.'%'];
|
||||
if(in_array($isUse,[0,1]))$where['isUse'] = $isUse;
|
||||
$page = $this->field('orderNo,orderId,cardNo,id,cardPwd,isUse')
|
||||
->where($where)->order('id desc')
|
||||
->paginate(20)->toArray();
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成卡券号
|
||||
*/
|
||||
public function getCardNo($shopId){
|
||||
$cardNo = date('Ymd').sprintf("%08d", rand(0,99999999));
|
||||
$conts = $this->where(['shopId'=>$shopId,'dataFlag'=>1,'cardNo'=>$cardNo])->Count();
|
||||
if($conts==0){
|
||||
return $cardNo;
|
||||
}else{
|
||||
return $this->getCardNo($shopId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成卡券
|
||||
*/
|
||||
public function add(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$goodsId = (int)input('goodsId');
|
||||
//判断商品是否有效
|
||||
$goods = model('goods')->where(['goodsId'=>$goodsId,'shopId'=>$shopId,'goodsType'=>1])->find();
|
||||
if(empty($goods))return WSTReturn('非法的卡券商品');
|
||||
$cardNo = input('cardNo');
|
||||
$cardPwd = input('cardPwd');
|
||||
if($cardNo=='' || $cardPwd=='')return WSTReturn('请输入完整卡券信息');
|
||||
$conts = $this->where(['shopId'=>$shopId,'dataFlag'=>1,'cardNo'=>$cardNo])->Count();
|
||||
if($conts>0)return WSTReturn('该卡券号已存在,请重新输入');
|
||||
$data = [];
|
||||
$data['cardNo'] = $cardNo;
|
||||
$data['cardPwd'] = $cardPwd;
|
||||
$data['dataFlag'] = 1;
|
||||
$data['shopId'] = $shopId;
|
||||
$data['goodsId'] = $goodsId;
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
Db::startTrans();
|
||||
try{
|
||||
$this->save($data);
|
||||
$this->updateGoodsStock($goodsId);
|
||||
Db::commit();
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('新增失败');
|
||||
}
|
||||
return WSTReturn('新增成功',1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品数量
|
||||
*/
|
||||
public function updateGoodsStock($id){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$counts = $this->where(['dataFlag'=>1,'goodsId'=>$id,'shopId'=>$shopId,'isUse'=>0])->Count();
|
||||
Db::name('goods')->where('goodsId',$id)->setField('goodsStock',$counts);
|
||||
}
|
||||
}
|
205
hyhproject/home/model/HomeMenus.php
Executable file
205
hyhproject/home/model/HomeMenus.php
Executable file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use wstmart\common\model\HomeMenus as CHomeMenus;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 菜单业务处理
|
||||
*/
|
||||
class HomeMenus extends CHomeMenus{
|
||||
/**
|
||||
* 获取菜单树
|
||||
*/
|
||||
public function getMenus(){
|
||||
$data = cache('WST_HOME_MENUS');
|
||||
if(!$data){
|
||||
$rs = $this->where(['isShow'=>1,'dataFlag'=>1])
|
||||
->field('menuId,parentId,menuName,menuUrl,menuType')->order('menuSort asc,menuId asc')->select();
|
||||
$m1 = ['0'=>[],'1'=>[]];
|
||||
$tmp = [];
|
||||
|
||||
//获取第一级
|
||||
foreach ($rs as $key => $v){
|
||||
if($v['parentId']==0){
|
||||
$m1[$v['menuType']][$v['menuId']] = ['menuId'=>$v['menuId'],'parentId'=>$v['parentId'],'menuName'=>$v['menuName'],'menuUrl'=>$v['menuUrl']];
|
||||
}else{
|
||||
$tmp[$v['parentId']][] = ['menuId'=>$v['menuId'],'parentId'=>$v['parentId'],'menuName'=>$v['menuName'],'menuUrl'=>$v['menuUrl']];
|
||||
}
|
||||
}
|
||||
//获取第二级
|
||||
foreach ($m1 as $key => $v){
|
||||
foreach ($v as $key1 => $v1){
|
||||
if(isset($tmp[$v1['menuId']]))$m1[$key][$key1]['list'] = $tmp[$v1['menuId']];
|
||||
}
|
||||
}
|
||||
//获取第三级
|
||||
foreach ($m1 as $key => $v){
|
||||
foreach ($v as $key1 => $v1){
|
||||
if(isset($v1['list'])){
|
||||
foreach ($v1['list'] as $key2 => $v2){
|
||||
if(isset($tmp[$v2['menuId']]))$m1[$key][$key1]['list'][$key2]['list'] = $tmp[$v2['menuId']];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cache('WST_HOME_MENUS',$m1,31536000);
|
||||
return $m1;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺菜单树
|
||||
*/
|
||||
public function getShopMenus(){
|
||||
$m1 = $this->getMenus();
|
||||
$userType = (int)session('WST_USER.userType');
|
||||
$menuUrls = array();
|
||||
if($userType==1){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$roleId = (int)session('WST_USER.roleId');
|
||||
if($roleId>0){
|
||||
$role = model("home/ShopRoles")->getById($roleId);
|
||||
$menuUrls = json_decode($role["privilegeUrls"],true);
|
||||
foreach ($m1[1] as $k1 => $menus1) {
|
||||
if(!array_key_exists($menus1["menuId"],$menuUrls)){
|
||||
unset($m1[1][$k1]);
|
||||
}else{
|
||||
if(isset($menus1["list"])){
|
||||
if(count($menus1["list"])>0){
|
||||
foreach ($menus1["list"] as $k2 => $menus2) {
|
||||
if(!array_key_exists($menus2["menuId"],$menuUrls[$menus1["menuId"]])){
|
||||
unset($m1[1][$k1]["list"][$k2]);
|
||||
}else{
|
||||
if(isset($menus2["list"])){
|
||||
if(count($menus2["list"])>0){
|
||||
foreach ($menus2["list"] as $k3 => $menus3) {
|
||||
$purls = $menuUrls[$menus1["menuId"]][$menus2["menuId"]];
|
||||
$urls = $purls["urls"];
|
||||
if(!in_array(strtolower($menus3["menuUrl"]),$urls)){
|
||||
unset($m1[1][$k1]["list"][$k2]["list"][$k3]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
unset($m1[1][$k1]["list"][$k2]);
|
||||
}
|
||||
}else{
|
||||
unset($m1[1][$k1]["list"][$k2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(count($m1[1][$k1]["list"])==0){
|
||||
unset($m1[1][$k1]);
|
||||
}
|
||||
}else{
|
||||
unset($m1[1][$k1]);
|
||||
}
|
||||
}else{
|
||||
unset($m1[1][$k1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $m1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单URL
|
||||
*/
|
||||
public function getMenusUrl(){
|
||||
$wst_user = session('WST_USER');
|
||||
$data = array();
|
||||
if(!empty($wst_user)){
|
||||
$data = cache('WST_PRO_MENUS');
|
||||
if(!$data){
|
||||
$list = $this->where('dataFlag',1)->order('menuType asc')->select();
|
||||
$menus = [];
|
||||
foreach($list as $key => $v){
|
||||
$menus[strtolower($v['menuUrl'])] = $v['menuType'];
|
||||
if($v['menuOtherUrl']!=''){
|
||||
$str = explode(',',$v['menuOtherUrl']);
|
||||
foreach ($str as $vkey => $vv){
|
||||
if($vv=='')continue;
|
||||
$menus[strtolower($vv)] = $v['menuType'];
|
||||
}
|
||||
}
|
||||
}
|
||||
cache('WST_PRO_MENUS',$menus,31536000);
|
||||
return $menus;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色可访问url
|
||||
*/
|
||||
public function getShopMenusUrl(){
|
||||
$wst_user = session('WST_USER');
|
||||
|
||||
if(!empty($wst_user)){
|
||||
$roleId = isset($wst_user["roleId"])?(int)$wst_user["roleId"]:0;
|
||||
if($roleId>0){
|
||||
$role = model("home/ShopRoles")->getById($roleId);
|
||||
$menuUrls = $role["menuUrls"];
|
||||
$menuOtherUrls = $role["menuOtherUrls"];
|
||||
$shopUrls = array_merge($menuUrls,$menuOtherUrls);
|
||||
}
|
||||
}
|
||||
$shopUrls[] = "home/shops/index";
|
||||
$shopUrls[] = "home/reports/getstatsales";
|
||||
return $shopUrls;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取菜单父ID
|
||||
*/
|
||||
public function getParentId($menuId){
|
||||
$data = cache('WST_HOME_MENUS_PARENT');
|
||||
if(!$data){
|
||||
$rs = $this->where(['isShow'=>1,'dataFlag'=>1])
|
||||
->field('menuId,parentId,menuType')->order('menuSort asc,menuId asc')->select();
|
||||
$tmp = [];
|
||||
foreach ($rs as $key => $v) {
|
||||
$tmp[$v['menuId']] = $v;
|
||||
}
|
||||
$data = [];
|
||||
foreach ($tmp as $key => $v) {
|
||||
if($v['parentId']==0){
|
||||
$data[$v['menuId']] = $v;
|
||||
}else{
|
||||
$data[$v['menuId']] = $tmp[$v['parentId']];
|
||||
}
|
||||
}
|
||||
cache('WST_HOME_MENUS_PARENT',$data,31536000);
|
||||
}
|
||||
return $data[$menuId];
|
||||
}
|
||||
/**
|
||||
* 获取店铺角色菜单
|
||||
*/
|
||||
public function getRoleMenus(){
|
||||
$data = cache('WST_HOME_MENUS_SHOPROLE');
|
||||
if(!$data){
|
||||
$rs = $this->alias('m1')
|
||||
->join("__HOME_MENUS__ m2","m1.parentId=m2.menuId")
|
||||
->where(['m1.isShow'=>1,'m1.dataFlag'=>1,"m1.menuType"=>1,"m2.parentId"=>[">",0]])
|
||||
->field('m1.menuId,m1.parentId,m2.parentId grandpaId,m1.menuName,m1.menuUrl,m1.menuOtherUrl,m1.menuType')
|
||||
->order('m1.menuSort asc,m1.menuId asc')
|
||||
->select();
|
||||
$m = array();
|
||||
//获取第一级
|
||||
foreach ($rs as $key => $v){
|
||||
$m[$v['menuId']] = ['menuId'=>$v['menuId'],'parentId'=>$v['parentId'],'grandpaId'=>$v['grandpaId'],'menuName'=>$v['menuName'],'menuUrl'=>$v['menuUrl'],'menuOtherUrl'=>$v['menuOtherUrl']];
|
||||
}
|
||||
cache('WST_HOME_MENUS_SHOPROLE',$m,31536000);
|
||||
return $m;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
148
hyhproject/home/model/Imports.php
Executable file
148
hyhproject/home/model/Imports.php
Executable file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 导入类
|
||||
*/
|
||||
class Imports{
|
||||
/**
|
||||
* 上传商品数据
|
||||
*/
|
||||
public function importGoods($data){
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objReader = \PHPExcel_IOFactory::load(WSTRootPath().json_decode($data)->route.json_decode($data)->name);
|
||||
$objReader->setActiveSheetIndex(0);
|
||||
$sheet = $objReader->getActiveSheet();
|
||||
$rows = $sheet->getHighestRow();
|
||||
$cells = $sheet->getHighestColumn();
|
||||
//数据集合
|
||||
$readData = [];
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$importNum = 0;
|
||||
$goodsCatMap = []; //记录最后一级商品分类
|
||||
$goodsCatPathMap = [];//记录商品分类路径
|
||||
$shopCatMap = [];//记录店铺分类
|
||||
$goodsCat1Map = [];//记录最后一级商品分类对应的一级分类
|
||||
$tmpGoodsCatId = 0;
|
||||
$goodsCatBrandMap = [];//商品分类和品牌的对应关系
|
||||
//生成订单
|
||||
Db::startTrans();
|
||||
try{
|
||||
//循环读取每个单元格的数据
|
||||
for ($row = 3; $row <= $rows; $row++){//行数是以第3行开始
|
||||
$tmpGoodsCatId = 0;
|
||||
$goods = [];
|
||||
$goods['shopId'] = $shopId;
|
||||
$goods['goodsName'] = trim($sheet->getCell("A".$row)->getValue());
|
||||
if($goods['goodsName']=='')break;//如果某一行第一列为空则停止导入
|
||||
$goods['goodsSn'] = trim($sheet->getCell("B".$row)->getValue());
|
||||
$goods['productNo'] = trim($sheet->getCell("C".$row)->getValue());
|
||||
$goods['marketPrice'] = trim($sheet->getCell("D".$row)->getValue());
|
||||
if(floatval($goods['marketPrice'])<0.01)$goods['marketPrice'] = 0.01;
|
||||
$goods['shopPrice'] = trim($sheet->getCell("E".$row)->getValue());
|
||||
if(floatval($goods['shopPrice'])<0.01)$goods['shopPrice'] = 0.01;
|
||||
$goods['goodsStock'] = trim($sheet->getCell("F".$row)->getValue());
|
||||
if(intval($goods['goodsStock'])<=0)$goods['goodsStock'] = 0;
|
||||
$goods['warnStock'] = trim($sheet->getCell("G".$row)->getValue());
|
||||
if(intval($goods['warnStock'])<=0)$goods['warnStock'] = 0;
|
||||
$goods['goodsImg'] = '';
|
||||
$goods['shopCatId1'] = 0;
|
||||
$goods['shopCatId2'] = 0;
|
||||
$goods['goodsUnit'] = trim($sheet->getCell("H".$row)->getValue());
|
||||
$goods['goodsSeoKeywords'] = trim($sheet->getCell("I".$row)->getValue());
|
||||
$goods['goodsTips'] = trim($sheet->getCell("J".$row)->getValue());
|
||||
$goods['isRecom'] = (trim($sheet->getCell("K".$row)->getValue())!='')?1:0;
|
||||
$goods['isBest'] = (trim($sheet->getCell("L".$row)->getValue())!='')?1:0;
|
||||
$goods['isNew'] = (trim($sheet->getCell("M".$row)->getValue())!='')?1:0;
|
||||
$goods['isHot'] = (trim($sheet->getCell("N".$row)->getValue())!='')?1:0;
|
||||
$goods['goodsCatId'] = 0;
|
||||
//查询商城分类
|
||||
$goodsCat = trim($sheet->getCell("O".$row)->getValue());
|
||||
if(!empty($goodsCat)){
|
||||
//先判断集合是否存在,不存在的时候才查数据库
|
||||
if(isset($goodsCatMap[$goodsCat])){
|
||||
$goods['goodsCatId'] = $goodsCatMap[$goodsCat];
|
||||
$goods['goodsCatIdPath'] = $goodsCatPathMap[$goodsCat];
|
||||
$tmpGoodsCatId = $goodsCat1Map[$goodsCat];
|
||||
}else{
|
||||
$goodsCatId = Db::name('goods_cats')->where(['catName'=>$goodsCat,'dataFlag'=>1])->field('catId')->find();
|
||||
if(!empty($goodsCatId['catId'])){
|
||||
$goodsCats = model('GoodsCats')->getParentIs($goodsCatId['catId']);
|
||||
$goods['goodsCatId'] = $goodsCatId['catId'];
|
||||
$goods['goodsCatIdPath'] = implode('_',$goodsCats)."_";
|
||||
//放入集合
|
||||
$goodsCatMap[$goodsCat] = $goodsCatId['catId'];
|
||||
$goodsCatPathMap[$goodsCat] = implode('_',$goodsCats)."_";
|
||||
$goodsCat1Map[$goodsCat] = $goodsCats[0];
|
||||
$tmpGoodsCatId = $goodsCats[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
//查询店铺分类
|
||||
$shopGoodsCat = trim($sheet->getCell("P".$row)->getValue());
|
||||
if(!empty($shopGoodsCat)){
|
||||
//先判断集合是否存在,不存在的时候才查数据库
|
||||
if(isset($shopCatMap[$shopGoodsCat])){
|
||||
$goods['shopCatId1'] = $shopCatMap[$shopGoodsCat]['s1'];
|
||||
$goods['shopCatId2'] = $shopCatMap[$shopGoodsCat]['s2'];
|
||||
}else{
|
||||
$shopCat= Db::name("shop_cats")->alias('sc1')
|
||||
->join('__SHOP_CATS__ sc2','sc2.parentId=sc1.catId','left')
|
||||
->field('sc1.catId catId1,sc2.catId catId2,sc2.catName')
|
||||
->where(['sc1.shopId'=> $shopId,'sc1.dataFlag'=>1,'sc2.catName'=>$shopGoodsCat])
|
||||
->find();
|
||||
if(!empty($shopCat)){
|
||||
$goods['shopCatId1'] = $shopCat['catId1'];
|
||||
$goods['shopCatId2'] = $shopCat['catId2'];
|
||||
//放入集合
|
||||
$shopCatMap[$shopGoodsCat] = [];
|
||||
$shopCatMap[$shopGoodsCat]['s1'] = $goods['shopCatId1'];
|
||||
$shopCatMap[$shopGoodsCat]['s2'] = $goods['shopCatId2'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//查询品牌
|
||||
$brand = trim($sheet->getCell("Q".$row)->getValue());
|
||||
if(!empty($brand)){
|
||||
if(isset($goodsCatBrandMap[$brand])){
|
||||
$goods['brandId'] = $goodsCatBrandMap[$brand];
|
||||
}else{
|
||||
$brands = Db::name('brands')->alias('a')->join('__CAT_BRANDS__ cb','a.brandId=cb.brandId','inner')
|
||||
->where(['catId'=>$tmpGoodsCatId,'brandName'=>$brand,'dataFlag'=>1])->field('a.brandId')->find();
|
||||
if(!empty($brands)){
|
||||
$goods['brandId'] = $brands['brandId'];
|
||||
$goodsCatBrandMap[$brand] = $brands['brandId'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$goods['goodsDesc'] = trim($sheet->getCell("R".$row)->getValue());
|
||||
$goods['isSale'] = 0;
|
||||
$goods['goodsStatus'] = (WSTConf("CONF.isGoodsVerify")==1)?0:1;
|
||||
$goods['dataFlag'] = 1;
|
||||
$goods['saleTime'] = date('Y-m-d H:i:s');
|
||||
$goods['createTime'] = date('Y-m-d H:i:s');
|
||||
$readData[] = $goods;
|
||||
$importNum++;
|
||||
}
|
||||
if(count($readData)>0){
|
||||
$list = model('Goods')->saveAll($readData);
|
||||
//建立商品评分记录
|
||||
$goodsScores = [];
|
||||
foreach ($list as $key =>$v){
|
||||
$gs = [];
|
||||
$gs['goodsId'] = $v['goodsId'];
|
||||
$gs['shopId'] = $shopId;
|
||||
$goodsScores[] = $gs;
|
||||
}
|
||||
if(count($goodsScores)>0)Db::name('goods_scores')->insertAll($goodsScores);
|
||||
}
|
||||
Db::commit();
|
||||
return json_encode(['status'=>1,'importNum'=>$importNum]);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return json_encode(WSTReturn('导入商品失败',-1));
|
||||
}
|
||||
}
|
||||
}
|
97
hyhproject/home/model/Reports.php
Executable file
97
hyhproject/home/model/Reports.php
Executable file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 报表模型类
|
||||
*/
|
||||
class Reports{
|
||||
/**
|
||||
* 获取商品销售排行
|
||||
*/
|
||||
public function getTopSaleGoods(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$rs = Db::field('og.goodsId,g.goodsName,goodsSn,sum(og.goodsNum) goodsNum,g.goodsImg')->name('order_goods')->alias('og')
|
||||
->join('__ORDERS__ o','og.orderId=o.orderId')
|
||||
->join('__GOODS__ g','og.goodsId=g.goodsId')
|
||||
->order('goodsNum desc')
|
||||
->whereTime('o.createTime','between',[$start,$end])
|
||||
->where('(payType=0 or (payType=1 and isPay=1)) and o.dataFlag=1 and o.shopId='.$shopId)->group('og.goodsId')
|
||||
->limit(10)->select();
|
||||
return WSTReturn('',1,$rs);
|
||||
}
|
||||
/**
|
||||
* 获取销售额统计
|
||||
*/
|
||||
public function getStatSales(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$payType = (int)input('payType',-1);
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$rs = Db::field('left(createTime,10) createTime,sum(totalMoney) totalMoney,count(orderId) orderNum')->name('orders')->whereTime('createTime','between',[$start,$end])
|
||||
->where('shopId',$shopId)
|
||||
->where('(payType=0 or (payType=1 and isPay=1)) and dataFlag=1 '.(in_array($payType,[0,1])?" and payType=".$payType:''))
|
||||
->order('createTime asc')
|
||||
->group('left(createTime,10)')->select();
|
||||
$rdata = [];
|
||||
if(count($rs)>0){
|
||||
$days = [];
|
||||
$tmp = [];
|
||||
foreach($rs as $key => $v){
|
||||
$days[] = $v['createTime'];
|
||||
$rdata['dayVals'][] = $v['totalMoney'];
|
||||
$rdata['list'][] = ['day'=>$v['createTime'],'val'=>$v['totalMoney'],'num'=>$v['orderNum']];
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
}
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商家订单情况
|
||||
*/
|
||||
public function getStatOrders(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$rs = Db::field('left(createTime,10) createTime,orderStatus,count(orderId) orderNum')->name('orders')->whereTime('createTime','between',[$start,$end])
|
||||
->where('shopId',$shopId)
|
||||
->order('createTime asc')
|
||||
->group('left(createTime,10),orderStatus')->select();
|
||||
$rdata = [];
|
||||
if(count($rs)>0){
|
||||
$days = [];
|
||||
$tmp = [];
|
||||
$map = ['-3'=>0,'-1'=>0,'1'=>0];
|
||||
foreach($rs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp[$v['orderStatus'].'_'.$v['createTime']] = $v['orderNum'];
|
||||
}
|
||||
foreach($days as $v){
|
||||
$total = 0;
|
||||
$ou = 0;
|
||||
$o_3 = isset($tmp['-3_'.$v])?$tmp['-3_'.$v]:0;
|
||||
$o_1 = isset($tmp['-1_'.$v])?$tmp['-1_'.$v]:0;
|
||||
if(isset($tmp['0_'.$v]))$ou += $tmp['0_'.$v];
|
||||
if(isset($tmp['1_'.$v]))$ou += $tmp['1_'.$v];
|
||||
if(isset($tmp['2_'.$v]))$ou += $tmp['2_'.$v];
|
||||
$rdata['-3'][] = $o_3;
|
||||
$rdata['-1'][] = $o_1;
|
||||
$rdata['1'][] = $ou;
|
||||
$map['-3'] += $o_3;
|
||||
$map['-1'] += $o_1;
|
||||
$map['1'] += $ou;
|
||||
$total += $o_3;
|
||||
$total += $o_1;
|
||||
$total += $ou;
|
||||
$rdata['total'][] = $total;
|
||||
$rdata['list'][] = ['day'=>$v,'o3'=>$o_3,'o1'=>$o_1,'ou'=>$ou];
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
$rdata['map'] = $map;
|
||||
}
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
}
|
246
hyhproject/home/model/Settlements.php
Executable file
246
hyhproject/home/model/Settlements.php
Executable file
@ -0,0 +1,246 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 结算类
|
||||
*/
|
||||
class Settlements extends Base{
|
||||
/**
|
||||
* 获取已结算的结算单列表
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$where = [];
|
||||
$where['shopId'] = $shopId;
|
||||
if(input('settlementNo')!='')$where['settlementNo'] = ['like','%'.input('settlementNo').'%'];
|
||||
if((int)input('isFinish')>=0)$where['settlementStatus'] = (int)input('isFinish');
|
||||
return Db::name('settlements')->alias('s')->where($where)->order('settlementId', 'desc')
|
||||
->paginate(input('pagesize/d'));
|
||||
}
|
||||
/**
|
||||
* 获取未结算订单列表
|
||||
*/
|
||||
public function pageUnSettledQuery(){
|
||||
$where = [];
|
||||
if(input('orderNo')!='')$where['orderNo'] = ['like','%'.input('orderNo').'%'];
|
||||
$where['dataFlag'] = 1;
|
||||
$where['orderStatus'] = 2;
|
||||
$where['settlementId'] = 0;
|
||||
$where['shopId'] = (int)session('WST_USER.shopId');
|
||||
$page = Db::name('orders')->where($where)->order('orderId', 'desc')
|
||||
->field('orderId,orderNo,createTime,payType,goodsMoney,deliverMoney,totalMoney,commissionFee,realTotalMoney')
|
||||
->paginate(input('pagesize/d'))->toArray();
|
||||
if(count($page['Rows'])){
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
$page['Rows'][$key]['payTypeNames'] = WSTLangPayType($v['payType']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 结算指定的订单
|
||||
*/
|
||||
public function settlement(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$ids = input('ids');
|
||||
$where['dataFlag'] = 1;
|
||||
$where['orderStatus'] = 2;
|
||||
$where['settlementId'] = 0;
|
||||
$where['orderId'] = ['in',$ids];
|
||||
$where['shopId'] = $shopId;
|
||||
$orders = Db::name('orders')->where($where)->field('orderId,payType,realTotalMoney,scoreMoney,commissionFee')->select();
|
||||
if(empty($orders))return WSTReturn('没有需要结算的订单,请刷新后再核对!');
|
||||
$settlementMoney = 0;
|
||||
$commissionFee = 0; //平台要收的佣金
|
||||
$ids = [];
|
||||
foreach ($orders as $key => $v) {
|
||||
$ids[] = $v['orderId'];
|
||||
if($v['payType']==1){
|
||||
$settlementMoney += $v['realTotalMoney']+$v['scoreMoney'];
|
||||
}else{
|
||||
$settlementMoney += $v['scoreMoney'];
|
||||
}
|
||||
$commissionFee += abs($v['commissionFee']);
|
||||
}
|
||||
|
||||
$shops = model('shops')->get($shopId);
|
||||
if(empty($shops))WSTReturn('无效的店铺结算账号!');
|
||||
Db::startTrans();
|
||||
try{
|
||||
$areaNames = model('areas')->getParentNames($shops['bankAreaId']);
|
||||
$data = [];
|
||||
$data['settlementType'] = 0;
|
||||
$data['shopId'] = $shopId;
|
||||
$data['settlementMoney'] = $settlementMoney;
|
||||
$data['commissionFee'] = $commissionFee;
|
||||
$data['backMoney'] = $settlementMoney-$commissionFee;
|
||||
$data['settlementStatus'] = 0;
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data['settlementNo'] = '';
|
||||
$result = $this->save($data);
|
||||
if(false !== $result){
|
||||
$this->settlementNo = $this->settlementId.(fmod($this->settlementId,7));
|
||||
$this->save();
|
||||
Db::name('orders')->where(['orderId'=>['in',$ids]])->update(['settlementId'=>$this->settlementId]);
|
||||
//修改商家订单情况
|
||||
$commissionFee = -1*$commissionFee;//平台要收的佣金就等于商家要付的钱
|
||||
$shops->noSettledOrderNum = $shops->noSettledOrderNum-count($orders);
|
||||
$shops->paymentMoney = $shops->paymentMoney + $commissionFee;
|
||||
$shops->noSettledOrderFee = $shops->noSettledOrderFee-$commissionFee;
|
||||
$shops->save();
|
||||
Db::commit();
|
||||
return WSTReturn('提交结算申请成功,请留意结算信息~',1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('提交结算申请失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已结算订单
|
||||
*/
|
||||
public function pageSettledQuery(){
|
||||
$where = [];
|
||||
if(input('settlementNo')!='')$where['settlementNo'] = ['like','%'.input('settlementNo').'%'];
|
||||
if(input('orderNo')!='')$where['orderNo'] = ['like','%'.input('orderNo').'%'];
|
||||
if((int)input('isFinish')>=0)$where['settlementStatus'] = (int)input('isFinish');
|
||||
$where['dataFlag'] = 1;
|
||||
$where['orderStatus'] = 2;
|
||||
$where['o.shopId'] = (int)session('WST_USER.shopId');
|
||||
$page = Db::name('orders')->alias('o')
|
||||
->join('__SETTLEMENTS__ s','o.settlementId=s.settlementId')
|
||||
->join('__PAYMENTS__ p','o.payFrom=p.payCode')->where($where)
|
||||
->field('orderId,orderNo,payType,goodsMoney,deliverMoney,totalMoney,o.commissionFee,realTotalMoney,s.settlementTime,s.settlementNo,p.payName')->order('s.settlementTime desc')->paginate(input('pagesize/d'))->toArray();
|
||||
if(count($page['Rows'])){
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
$page['Rows'][$key]['commissionFee'] = abs($v['commissionFee']);
|
||||
$page['Rows'][$key]['payTypeNames'] = WSTLangPayType($v['payType']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取结算订单详情
|
||||
*/
|
||||
public function getById(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$settlementId = (int)input('id');
|
||||
$object = Db::name('settlements')->alias('st')->where(['settlementId'=>$settlementId,'st.shopId'=>$shopId])->join('__SHOPS__ s','s.shopId=st.shopId','left')->field('s.shopName,st.*')->find();
|
||||
if(!empty($object)){
|
||||
$object['list'] = Db::name('orders')->where(['settlementId'=>$settlementId])
|
||||
->field('orderId,orderNo,payType,goodsMoney,deliverMoney,realTotalMoney,totalMoney,scoreMoney,commissionFee,createTime')
|
||||
->order('payType desc,orderId desc')->select();
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
/**
|
||||
* 导出订单
|
||||
*/
|
||||
public function toExport(){
|
||||
$name='已结算订单表';
|
||||
$where = [];
|
||||
if(input('settlementNo')!='')$where['settlementNo'] = ['like','%'.input('settlementNo').'%'];
|
||||
if(input('orderNo')!='')$where['orderNo'] = ['like','%'.input('orderNo').'%'];
|
||||
if((int)input('isFinish')>=0)$where['settlementStatus'] = (int)input('isFinish');
|
||||
$where['dataFlag'] = 1;
|
||||
$where['orderStatus'] = 2;
|
||||
$where['o.shopId'] = (int)session('WST_USER.shopId');
|
||||
$page = Db::name('orders')->alias('o')
|
||||
->join('__SETTLEMENTS__ s','o.settlementId=s.settlementId')
|
||||
->join('__PAYMENTS__ p','o.payFrom=p.payCode')->where($where)
|
||||
->field('orderId,orderNo,payType,goodsMoney,deliverMoney,totalMoney,o.commissionFee,realTotalMoney,s.settlementTime,s.settlementNo,p.payName')->order('s.settlementTime desc')->select();
|
||||
if(count($page)){
|
||||
foreach ($page as $key => $v) {
|
||||
$page[$key]['commissionFee'] = abs($v['commissionFee']);
|
||||
$page[$key]['payTypeNames'] = WSTLangPayType($v['payType']);
|
||||
}
|
||||
}
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("WSTMart")//创建人
|
||||
->setLastModifiedBy("WSTMart")//最后修改人
|
||||
->setTitle($name)//标题
|
||||
->setSubject($name)//题目
|
||||
->setDescription($name)//描述
|
||||
->setKeywords("订单")//关键字
|
||||
->setCategory("Test result file");//种类
|
||||
|
||||
// 开始操作excel表
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
// 设置工作薄名称
|
||||
$objPHPExcel->getActiveSheet()->setTitle(iconv('gbk', 'utf-8', 'Sheet'));
|
||||
// 设置默认字体和大小
|
||||
$objPHPExcel->getDefaultStyle()->getFont()->setName(iconv('gbk', 'utf-8', ''));
|
||||
$objPHPExcel->getDefaultStyle()->getFont()->setSize(11);
|
||||
$styleArray = array(
|
||||
'font' => array(
|
||||
'bold' => true,
|
||||
'color'=>array(
|
||||
'argb' => 'ffffffff',
|
||||
)
|
||||
),
|
||||
'borders' => array (
|
||||
'outline' => array (
|
||||
'style' => \PHPExcel_Style_Border::BORDER_THIN, //设置border样式
|
||||
'color' => array ('argb' => 'FF000000'), //设置border颜色
|
||||
)
|
||||
)
|
||||
);
|
||||
//设置宽
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:N1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:N1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', '订单编号')->setCellValue('B1', '支付方式')->setCellValue('C1', '商品总金额')->setCellValue('D1', '运费')->setCellValue('E1', '订单总金额')
|
||||
->setCellValue('F1', '实付金额')->setCellValue('G1', '应付佣金')->setCellValue('H1', '结算方式')->setCellValue('I1', '结算单号')->setCellValue('J1', '结算时间');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:J1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['orderNo'])
|
||||
->setCellValue('B'.$i, $page[$row]['payTypeNames'])
|
||||
->setCellValue('C'.$i, $page[$row]['goodsMoney'])
|
||||
->setCellValue('D'.$i, $page[$row]['deliverMoney'])
|
||||
->setCellValue('E'.$i, $page[$row]['totalMoney'])
|
||||
->setCellValue('F'.$i, $page[$row]['realTotalMoney'])
|
||||
->setCellValue('G'.$i, $page[$row]['commissionFee'])
|
||||
->setCellValue('H'.$i, $page[$row]['payName'])
|
||||
->setCellValue('I'.$i, $page[$row]['settlementNo'])
|
||||
->setCellValue('J'.$i, $page[$row]['settlementTime']);
|
||||
}
|
||||
|
||||
//输出EXCEL格式
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
||||
// 从浏览器直接输出$filename
|
||||
header('Content-Type:application/csv;charset=UTF-8');
|
||||
header("Pragma: public");
|
||||
header("Expires: 0");
|
||||
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
|
||||
header("Content-Type:application/force-download");
|
||||
header("Content-Type:application/vnd.ms-excel;");
|
||||
header("Content-Type:application/octet-stream");
|
||||
header("Content-Type:application/download");
|
||||
header('Content-Disposition: attachment;filename="'.$name.'.xls"');
|
||||
header("Content-Transfer-Encoding:binary");
|
||||
$objWriter->save('php://output');
|
||||
}
|
||||
}
|
62
hyhproject/home/model/ShopConfigs.php
Executable file
62
hyhproject/home/model/ShopConfigs.php
Executable file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 门店配置类
|
||||
*/
|
||||
use think\Db;
|
||||
class ShopConfigs extends Base{
|
||||
/**
|
||||
* 店铺设置
|
||||
*/
|
||||
public function getShopCfg($id){
|
||||
$rs = $this->where("shopId=".$id)->find();
|
||||
if($rs != ''){
|
||||
//图片
|
||||
$rs['shopAds'] = ($rs['shopAds']!='')?explode(',',$rs['shopAds']):null;
|
||||
//图片的广告地址
|
||||
$rs['shopAdsUrl'] = ($rs['shopAdsUrl']!='')?explode(',',$rs['shopAdsUrl']):null;
|
||||
return $rs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改店铺设置
|
||||
*/
|
||||
public function editShopCfg($shopId){
|
||||
$data = input('post.');
|
||||
//加载商店信息
|
||||
Db::startTrans();
|
||||
try{
|
||||
$shopcg = $this->where('shopId='.$shopId)->find();
|
||||
$scdata = array();
|
||||
$scdata["shopKeywords"] = Input("shopKeywords");
|
||||
$scdata["shopBanner"] = Input("shopBanner");
|
||||
$scdata["shopDesc"] = Input("shopDesc");
|
||||
$scdata["shopAds"] = Input("shopAds");
|
||||
$scdata["shopAdsUrl"] = Input("shopAdsUrl");
|
||||
$scdata["shopHotWords"] = Input("shopHotWords");
|
||||
$scdata["shopStreetImg"] = Input("shopStreetImg");
|
||||
WSTUseImages(0, $shopcg['configId'], $scdata['shopStreetImg'],'shop_configs','shopStreetImg');
|
||||
WSTUseImages(0, $shopcg['configId'], $scdata['shopBanner'],'shop_configs','shopBanner');
|
||||
WSTUseImages(0, $shopcg['configId'], $scdata['shopAds'],'shop_configs','shopAds');
|
||||
$rs = $this->where("shopId=".$shopId)->update($scdata);
|
||||
if($rs!==false){
|
||||
Db::commit();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
/**
|
||||
* 获取商城搜索关键字
|
||||
*/
|
||||
public function searchShopkey($shopId){
|
||||
$rs = $this->where('shopId='.$shopId)->field('configId,shopHotWords')->find();
|
||||
$keys = [];
|
||||
if($rs['shopHotWords']!='')$keys = explode(',',$rs['shopHotWords']);
|
||||
return $keys;
|
||||
}
|
||||
}
|
63
hyhproject/home/model/ShopFreights.php
Executable file
63
hyhproject/home/model/ShopFreights.php
Executable file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use think\Db;
|
||||
use wstmart\home\model\Shops;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 运费管理类
|
||||
*/
|
||||
class ShopFreights extends Base{
|
||||
/**
|
||||
* 运费列表
|
||||
*/
|
||||
public function listProvince(){
|
||||
$shopId = session('WST_USER.shopId');
|
||||
$listCity = Db::name('areas')->where(['isShow'=>1,'dataFlag'=>1,'areaType'=>0])->field('areaId,areaName')->order('areaKey desc')->select();
|
||||
for ($i = 0; $i < count($listCity); $i++) {
|
||||
$parentId = $listCity[$i]["areaId"];
|
||||
$listPro = Db::name('areas')->alias('a')
|
||||
->join('__SHOP_FREIGHTS__ s','a.areaId= s.areaId2 and s.shopId='.$shopId,'left')
|
||||
->where(['a.isShow'=>1,'a.dataFlag'=>1,'a.areaType'=>1,'a.parentId'=>$parentId])
|
||||
->field('a.areaId,a.areaName,a.parentId,s.freightId,s.freight')
|
||||
->order('a.areaKey desc')
|
||||
->select();
|
||||
$listCity[$i]['listProvince'] = $listPro;
|
||||
}
|
||||
return $listCity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$shopId = session('WST_USER.shopId');
|
||||
$info = input("post.");
|
||||
$areas = Db::name('areas')->where('isShow=1 AND dataFlag = 1 AND areaType=1')->field('areaId')->select();
|
||||
Db::startTrans();
|
||||
if(count($areas)==0)return WSTReturn('无效的城市');
|
||||
try{
|
||||
$dataList = [];
|
||||
foreach ($areas as $key => $v) {
|
||||
$m = model('ShopFreights')->where(['shopId'=>$shopId,'areaId2'=>$v['areaId']])->find();
|
||||
$freight = ((int)input('post.'.$v['areaId'])>0)?(int)input('post.'.$v['areaId']):0;
|
||||
if($m){
|
||||
$m->freight = $freight;
|
||||
$m->save();
|
||||
}else{
|
||||
$data = [];
|
||||
$data['shopId'] = $shopId;
|
||||
$data['areaId2'] = $v['areaId'];
|
||||
$data['freight'] = $freight;
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$dataList[] = $data;
|
||||
}
|
||||
}
|
||||
if(count($dataList)>0)model('ShopFreights')->saveAll($dataList);
|
||||
Db::commit();
|
||||
return WSTReturn("操作成功", 1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
}
|
||||
}
|
153
hyhproject/home/model/ShopRoles.php
Executable file
153
hyhproject/home/model/ShopRoles.php
Executable file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 门店色务类
|
||||
*/
|
||||
class ShopRoles extends Base{
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$roleName = input("roleName/s");
|
||||
$where = ["shopId"=>$shopId,"dataFlag"=>1];
|
||||
if($roleName != ""){
|
||||
$where["roleName"] = ["like","%".$roleName."%"];
|
||||
}
|
||||
$page = $this
|
||||
->field('id,shopId,roleName,createTime')
|
||||
->where($where)
|
||||
->paginate(input('pagesize/d'))->toArray();
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function listQuery(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$where = ["shopId"=>$shopId,"dataFlag"=>1];
|
||||
$list = $this
|
||||
->field('id,shopId,roleName,createTime')
|
||||
->where($where)
|
||||
->select();
|
||||
return $list;
|
||||
}
|
||||
/**
|
||||
* 根据id获取店铺角色
|
||||
*/
|
||||
public function getById($id){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$role = $this->field('id,shopId,roleName,createTime,privilegeUrls,privilegeMsgs')
|
||||
->where(["id"=>$id,"shopId"=>$shopId,"dataFlag"=>1])
|
||||
->find();
|
||||
$menuList = json_decode($role["privilegeUrls"],true);
|
||||
$menuUrls = array();
|
||||
$menuOtherUrls = array();
|
||||
foreach ($menuList as $k1 => $menus1) {
|
||||
foreach ($menus1 as $k2 => $menus2) {
|
||||
$menuUrls = array_merge($menuUrls,$menus2["urls"]);
|
||||
$otherUrls = $menus2["otherUrls"];
|
||||
foreach ($otherUrls as $ko => $ourls) {
|
||||
$othurls = explode(',',$ourls);
|
||||
$menuOtherUrls = array_merge($menuOtherUrls,$othurls);
|
||||
}
|
||||
}
|
||||
}
|
||||
$role["privilegeMsgs"] = explode(",",$role["privilegeMsgs"]);
|
||||
$role["menuUrls"] = array_filter($menuUrls);
|
||||
$role["menuOtherUrls"] = array_filter($menuOtherUrls);
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增店铺角色
|
||||
*/
|
||||
public function add(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$data["shopId"] = $shopId;
|
||||
$data["roleName"] = input('roleName/s');
|
||||
if($data["roleName"]==""){
|
||||
return WSTReturn('请输入角色名称',-1);
|
||||
}
|
||||
$data["privilegeMsgs"] = input('privilegeMsgs/s');
|
||||
$menuIds = input('menuIds/s');
|
||||
$urls = [];
|
||||
$otherUrls = [];
|
||||
if($menuIds==""){
|
||||
return WSTReturn('请选择权限',-1);
|
||||
}else{
|
||||
$roleMenus = model("HomeMenus")->getRoleMenus();
|
||||
$menuIds = explode(",",$menuIds);
|
||||
$menuList = array();
|
||||
for($i=0,$j=count($menuIds);$i<$j;$i++){
|
||||
$menu = $roleMenus[$menuIds[$i]];
|
||||
$menuList[$menu["grandpaId"]][$menu["parentId"]]["urls"][] = strtolower($menu["menuUrl"]);
|
||||
$menuList[$menu["grandpaId"]][$menu["parentId"]]["otherUrls"][] = strtolower($menu["menuOtherUrl"]);
|
||||
}
|
||||
}
|
||||
$data["privilegeUrls"] = json_encode($menuList);
|
||||
$data["createTime"] = date("Y-m-d H:i:s");
|
||||
$result = $this->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}
|
||||
return WSTReturn('新增失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改店铺角色
|
||||
*/
|
||||
public function edit(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$id = (int)input('id');
|
||||
$data["roleName"] = input('roleName/s');
|
||||
if($data["roleName"]==""){
|
||||
return WSTReturn('请输入角色名称',-1);
|
||||
}
|
||||
$data["privilegeMsgs"] = input('privilegeMsgs/s');
|
||||
$menuIds = input('menuIds/s');
|
||||
$urls = [];
|
||||
$otherUrls = [];
|
||||
if($menuIds==""){
|
||||
return WSTReturn('请选择权限',-1);
|
||||
}else{
|
||||
$roleMenus = model("HomeMenus")->getRoleMenus();
|
||||
$menuIds = explode(",",$menuIds);
|
||||
$menuList = array();
|
||||
for($i=0,$j=count($menuIds);$i<$j;$i++){
|
||||
$menu = $roleMenus[$menuIds[$i]];
|
||||
$menuList[$menu["grandpaId"]][$menu["parentId"]]["urls"][] = strtolower($menu["menuUrl"]);
|
||||
$menuList[$menu["grandpaId"]][$menu["parentId"]]["otherUrls"][] = strtolower($menu["menuOtherUrl"]);
|
||||
}
|
||||
}
|
||||
$data["privilegeUrls"] = json_encode($menuList);
|
||||
$result = $this->where(["id"=>$id,"shopId"=>$shopId])->update($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("修改成功", 1);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除店铺角色
|
||||
*/
|
||||
public function del(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$id = input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
Db::startTrans();
|
||||
try{
|
||||
$result = $this->where(["id"=>$id,"shopId"=>$shopId])->update($data);
|
||||
if(false !== $result){
|
||||
//删除关联记录
|
||||
Db::name("shop_users")->where(["roleId"=>$id,"shopId"=>$shopId])->update($data);
|
||||
Db::commit();
|
||||
return WSTReturn("删除成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
}
|
202
hyhproject/home/model/ShopUsers.php
Executable file
202
hyhproject/home/model/ShopUsers.php
Executable file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 门店管理员类
|
||||
*/
|
||||
class ShopUsers extends Base{
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$userName = input("userName/s");
|
||||
$where = ["s.shopId"=>$shopId,"s.dataFlag"=>1];
|
||||
if($userName != ""){
|
||||
$where["loginName"] = ["like","%".$userName."%"];
|
||||
}
|
||||
$page = $this->alias('s')
|
||||
->join("__SHOP_ROLES__ r","s.roleId=r.id","LEFT")
|
||||
->join("__USERS__ u", "u.userId=s.userId and u.dataFlag=1")
|
||||
->field('s.id,s.shopId,s.roleId,u.userName,u.loginName,u.createTime,u.userStatus,r.roleName')
|
||||
->where($where)
|
||||
->paginate(input('pagesize/d'))->toArray();
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取店铺用户
|
||||
*/
|
||||
public function getById(){
|
||||
$id = (int)input('id');
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$user = $this->alias('s')
|
||||
->join("__SHOP_ROLES__ r","s.roleId=r.id","LEFT")
|
||||
->join("__USERS__ u", "u.userId=s.userId and u.dataFlag=1")
|
||||
->field('s.id,s.shopId,s.roleId,u.userName,u.loginName,u.createTime,u.userStatus,r.roleName')
|
||||
->where(["s.id"=>$id,"s.shopId"=>$shopId,"s.dataFlag"=>1])
|
||||
->find();
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增店铺用户
|
||||
*/
|
||||
public function add(){
|
||||
$data = array();
|
||||
$roleId = (int)input("roleId");
|
||||
$data['loginName'] = input("post.loginName");
|
||||
$data['loginPwd'] = input("post.loginPwd");
|
||||
$data['reUserPwd'] = input("post.reUserPwd");
|
||||
$loginName = $data['loginName'];
|
||||
if($roleId<=0){
|
||||
return WSTReturn('非法操作');
|
||||
}
|
||||
//检测账号是否存在
|
||||
$crs = WSTCheckLoginKey($loginName);
|
||||
if($crs['status']!=1)return $crs;
|
||||
$decrypt_data = WSTRSA($data['loginPwd']);
|
||||
$decrypt_data2 = WSTRSA($data['reUserPwd']);
|
||||
if($decrypt_data['status']==1 && $decrypt_data2['status']==1){
|
||||
$data['loginPwd'] = $decrypt_data['data'];
|
||||
$data['reUserPwd'] = $decrypt_data2['data'];
|
||||
}else{
|
||||
return WSTReturn('新增失败');
|
||||
}
|
||||
if($data['loginPwd']!=$data['reUserPwd']){
|
||||
return WSTReturn("两次输入密码不一致!");
|
||||
}
|
||||
foreach ($data as $v){
|
||||
if($v ==''){
|
||||
return WSTReturn("信息不完整!");
|
||||
}
|
||||
}
|
||||
if($loginName=='')return WSTReturn("新增失败!");//分派不了登录名
|
||||
|
||||
unset($data['reUserPwd']);
|
||||
//检测账号,邮箱,手机是否存在
|
||||
$data["loginSecret"] = rand(1000,9999);
|
||||
$data['loginPwd'] = md5($data['loginPwd'].$data['loginSecret']);
|
||||
$data['userName'] = input("post.userName");
|
||||
$data['userQQ'] = "";
|
||||
$data['userScore'] = 0;
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data['dataFlag'] = 1;
|
||||
$data['userType'] = 1;
|
||||
Db::startTrans();
|
||||
try{
|
||||
$userId = Db::name("users")->insertGetId($data);
|
||||
if(false !== $userId){
|
||||
//添加门店用户
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$data = array();
|
||||
$data["shopId"] = $shopId;
|
||||
$data["userId"] = $userId;
|
||||
$data["roleId"] = (int)input("roleId");
|
||||
Db::name('shop_users')->insert($data);
|
||||
$user = model("common/Users")->get($userId);
|
||||
//注册成功后执行钩子
|
||||
hook('afterUserRegist',['user'=>$user]);
|
||||
//发送消息
|
||||
$tpl = WSTMsgTemplates('USER_REGISTER');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${LOGIN_NAME}','${MALL_NAME}'];
|
||||
$replace = [$user['loginName'],WSTConf('CONF.mallName')];
|
||||
WSTSendMsg($userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>0,'dataId'=>0]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return WSTReturn("新增成功",1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("新增失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改店铺用户
|
||||
*/
|
||||
public function edit(){
|
||||
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
Db::startTrans();
|
||||
try{
|
||||
$data = array();
|
||||
$roleId = (int)input("post.roleId");
|
||||
$id = (int)input("post.id");
|
||||
$newPass = input("post.newPass/s");
|
||||
if($newPass!=""){
|
||||
$decrypt_data = WSTRSA($newPass);
|
||||
if($decrypt_data['status']==1){
|
||||
$newPass = $decrypt_data['data'];
|
||||
}else{
|
||||
return WSTReturn('修改失败');
|
||||
}
|
||||
if(!$newPass){
|
||||
return WSTReturn('密码不能为空',-1);
|
||||
}
|
||||
$roleUser = $this->where(["id"=>$id,"shopId"=>$shopId])->find();
|
||||
$userId = $roleUser["userId"];
|
||||
$rs = model("users")->where(["userId"=>$userId])->find();
|
||||
//核对密码
|
||||
|
||||
$oldPass = input("post.oldPass");
|
||||
$decrypt_data2 = WSTRSA($oldPass);
|
||||
if($decrypt_data2['status']==1){
|
||||
$oldPass = $decrypt_data2['data'];
|
||||
}else{
|
||||
return WSTReturn('修改失败');
|
||||
}
|
||||
if($rs['loginPwd']==md5($oldPass.$rs['loginSecret'])){
|
||||
|
||||
$data["loginPwd"] = md5($newPass.$rs['loginSecret']);
|
||||
$rs = model("users")->update($data,['userId'=>$userId]);
|
||||
if(false !== $rs){
|
||||
$this->where(["id"=>$id,"shopId"=>$shopId,"roleId"=>[">",0]])->update(["roleId"=>$roleId]);
|
||||
hook("afterEditPass",["userId"=>$userId]);
|
||||
}else{
|
||||
return WSTReturn("修改失败", -1);
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}else{
|
||||
return WSTReturn('原始密码错误',-1);
|
||||
}
|
||||
}else{
|
||||
$this->where(["id"=>$id,"shopId"=>$shopId,"roleId"=>[">",0]])->update(["roleId"=>$roleId]);
|
||||
Db::commit();
|
||||
return WSTReturn("修改成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除店铺用户
|
||||
*/
|
||||
public function del(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$id = input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
Db::startTrans();
|
||||
try{
|
||||
$role = $this->where(["id"=>$id,"shopId"=>$shopId])->field("userId,id")->find();
|
||||
$result = $this->where(["id"=>$id,"shopId"=>$shopId,"roleId"=>[">",0]])->update($data);
|
||||
if(false !== $result){
|
||||
Db::name("users")->where(["userId"=>$role["userId"]])->update(["userType"=>0]);
|
||||
return WSTReturn("删除成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
}
|
561
hyhproject/home/model/Shops.php
Executable file
561
hyhproject/home/model/Shops.php
Executable file
@ -0,0 +1,561 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use wstmart\common\model\Shops as CShops;
|
||||
use wstmart\home\validate\Shops as VShop;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
use think\Validate;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 门店类
|
||||
*/
|
||||
class Shops extends CShops{
|
||||
/**
|
||||
* 获取店铺的默认运费
|
||||
*/
|
||||
public function getShopsFreight($shopId){
|
||||
return $this->where(["dataFlag"=>1,"shopId"=>$shopId])->field('freight')->find();
|
||||
}
|
||||
/**
|
||||
* 获取店铺公告
|
||||
*/
|
||||
public function getNotice(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
return model('shops')->where(['shopId'=>$shopId])->value('shopNotice');
|
||||
}
|
||||
/**
|
||||
* 修改店铺公告
|
||||
*/
|
||||
public function editNotice(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$shopNotice = input('shopNotice');
|
||||
if(strlen($shopNotice)>450){
|
||||
return WSTReturn('店铺公告不能超过150字');
|
||||
}
|
||||
$rs = $this->where("shopId=$shopId")->setField('shopNotice',$shopNotice);
|
||||
if($rs!==false)return WSTReturn('设置成功',1);
|
||||
return WSTReturn('设置失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺街列表
|
||||
*/
|
||||
public function pageQuery($pagesize){
|
||||
$catId = input("get.id/d");
|
||||
$keyword = input("keyword");
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$rs = $this->alias('s');
|
||||
$where = [];
|
||||
$where['s.dataFlag'] = 1;
|
||||
$where['s.shopStatus'] = 1;
|
||||
$where['s.applyStatus'] = 2;
|
||||
if($keyword!='')$where['s.shopName'] = ['like','%'.$keyword.'%'];
|
||||
if($catId>0){
|
||||
$rs->join('__CAT_SHOPS__ cs','cs.shopId = s.shopId','left');
|
||||
$where['cs.catId'] = $catId;
|
||||
}
|
||||
$page = $rs->join('__SHOP_SCORES__ ss','ss.shopId = s.shopId','left')
|
||||
->join('__USERS__ u','u.userId = s.userId','left')
|
||||
->join('__FAVORITES__ f','f.userId = '.$userId.' and f.favoriteType=1 and f.targetId=s.shopId','left')
|
||||
->where($where)
|
||||
->order('s.shopId asc')
|
||||
->field('s.shopId,s.shopImg,s.shopName,s.shopTel,s.shopQQ,s.shopWangWang,s.shopWangWangType,s.shopCompany,ss.totalScore,ss.totalUsers,ss.goodsScore,ss.goodsUsers,ss.serviceScore,ss.serviceUsers,ss.timeScore,ss.timeUsers,.u.loginName,f.favoriteId,s.areaIdPath')
|
||||
->paginate($pagesize)->toArray();
|
||||
if(empty($page['Rows']))return $page;
|
||||
$shopIds = [];
|
||||
$areaIds = [];
|
||||
foreach ($page['Rows'] as $key =>$v){
|
||||
$shopIds[] = $v['shopId'];
|
||||
$tmp = explode('_',$v['areaIdPath']);
|
||||
$areaIds[] = $tmp[1];
|
||||
$page['Rows'][$key]['areaId'] = $tmp[1];
|
||||
//总评分
|
||||
$page['Rows'][$key]['totalScore'] = WSTScore($v["totalScore"], $v["totalUsers"]);
|
||||
$page['Rows'][$key]['goodsScore'] = WSTScore($v['goodsScore'],$v['goodsUsers']);
|
||||
$page['Rows'][$key]['serviceScore'] = WSTScore($v['serviceScore'],$v['serviceUsers']);
|
||||
$page['Rows'][$key]['timeScore'] = WSTScore($v['timeScore'],$v['timeUsers']);
|
||||
//商品列表
|
||||
$goods = Db::name('goods')->alias('g')->join('store_recom sr','sr.goodsId=g.goodsId','left')
|
||||
->where(['dataFlag'=> 1,'goodsStatus'=>1,'isSale'=>1,'sr.storeStatus'=>1,'shopId'=> $v["shopId"]])->field('g.goodsId,goodsName,shopPrice,goodsImg')->limit(10)->order('saleTime desc')->select();
|
||||
if(count($goods)<=3){
|
||||
$goods = Db::name('goods')->alias('g')
|
||||
->where(['dataFlag'=> 1,'goodsStatus'=>1,'isSale'=>1,'shopId'=> $v["shopId"]])->field('g.goodsId,goodsName,shopPrice,goodsImg')->limit(10)->order('saleTime desc')->select();
|
||||
}
|
||||
$page['Rows'][$key]['goods'] = $goods;
|
||||
//店铺商品总数
|
||||
$page['Rows'][$key]['goodsTotal'] = count($goods);
|
||||
}
|
||||
$rccredMap = [];
|
||||
$goodsCatMap = [];
|
||||
$areaMap = [];
|
||||
//认证、地址、分类
|
||||
if(!empty($shopIds)){
|
||||
$rccreds = Db::name('shop_accreds')->alias('sac')->join('__ACCREDS__ a','a.accredId=sac.accredId and a.dataFlag=1','left')
|
||||
->where('shopId','in',$shopIds)->field('sac.shopId,accredName,accredImg')->select();
|
||||
foreach ($rccreds as $v){
|
||||
$rccredMap[$v['shopId']][] = $v;
|
||||
}
|
||||
$goodsCats = Db::name('cat_shops')->alias('cs')->join('__GOODS_CATS__ gc','cs.catId=gc.catId and gc.dataFlag=1','left')
|
||||
->where('shopId','in',$shopIds)->field('cs.shopId,gc.catName')->select();
|
||||
foreach ($goodsCats as $v){
|
||||
$goodsCatMap[$v['shopId']][] = $v['catName'];
|
||||
}
|
||||
$areas = Db::name('areas')->alias('a')->join('__AREAS__ a1','a1.areaId=a.parentId','left')
|
||||
->where('a.areaId','in',$areaIds)->field('a.areaId,a.areaName areaName2,a1.areaName areaName1')->select();
|
||||
foreach ($areas as $v){
|
||||
$areaMap[$v['areaId']] = $v;
|
||||
}
|
||||
}
|
||||
foreach ($page['Rows'] as $key =>$v){
|
||||
$page['Rows'][$key]['accreds'] = (isset($rccredMap[$v['shopId']]))?$rccredMap[$v['shopId']]:[];
|
||||
$page['Rows'][$key]['catshops'] = (isset($goodsCatMap[$v['shopId']]))?implode(',',$goodsCatMap[$v['shopId']]):'';
|
||||
$page['Rows'][$key]['areas']['areaName1'] = (isset($areaMap[$v['areaId']]['areaName1']))?$areaMap[$v['areaId']]['areaName1']:'';
|
||||
$page['Rows'][$key]['areas']['areaName2'] = (isset($areaMap[$v['areaId']]['areaName2']))?$areaMap[$v['areaId']]['areaName2']:'';
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 获取卖家中心信息
|
||||
*/
|
||||
public function getShopSummary($shopId){
|
||||
$shop = $this->alias('s')->join('__SHOP_SCORES__ cs','cs.shopId = s.shopId','left')
|
||||
->where(['s.shopId'=>$shopId,'dataFlag'=>1])
|
||||
->field('s.shopMoney,s.noSettledOrderFee,s.paymentMoney,s.shopId,shopImg,shopName,shopAddress,shopQQ,shopWangWang,shopTel,serviceStartTime,serviceEndTime,cs.*')
|
||||
->find();
|
||||
//评分
|
||||
$scores['totalScore'] = WSTScore($shop['totalScore'],$shop['totalUsers']);
|
||||
$scores['goodsScore'] = WSTScore($shop['goodsScore'],$shop['goodsUsers']);
|
||||
$scores['serviceScore'] = WSTScore($shop['serviceScore'],$shop['serviceUsers']);
|
||||
$scores['timeScore'] = WSTScore($shop['timeScore'],$shop['timeUsers']);
|
||||
WSTUnset($shop, 'totalUsers,goodsUsers,serviceUsers,timeUsers');
|
||||
$shop['scores'] = $scores;
|
||||
//认证
|
||||
$accreds = $this->shopAccreds($shopId);
|
||||
$shop['accreds'] = $accreds;
|
||||
//商家访问量
|
||||
$shop['view']=db('shop_view')->where('shopId',$shopId)->field('count(shopId)view,path')->group('path')->select();
|
||||
//查看商家钱包是否足够钱
|
||||
$USER = session('WST_USER');
|
||||
$USER['shopMoney'] = $shop['shopMoney'];
|
||||
$USER['noSettledOrderFee'] = $shop['noSettledOrderFee'];
|
||||
$USER['paymentMoney'] = $shop['paymentMoney'];
|
||||
session('WST_USER',$USER);
|
||||
$stat = array();
|
||||
$date = date("Y-m-d");
|
||||
$userId = session('WST_USER.userId');
|
||||
/**********今日动态**********/
|
||||
//待查看消息数
|
||||
$stat['messageCnt'] = Db::name('messages')->where(['receiveUserId'=>$userId,'msgStatus'=>0,'dataFlag'=>1])->count();
|
||||
//今日销售金额
|
||||
$stat['saleMoney'] = Db::name('orders')->where(['shopId'=>$shopId,'orderStatus'=>['egt',0],'dataFlag'=>1])->whereTime('createTime', 'between', [$date.' 00:00:00', $date.' 23:59:59'])->sum("goodsMoney");
|
||||
//今日订单数
|
||||
$stat['orderCnt'] = Db::name('orders')->where(['shopId'=>$shopId,'orderStatus'=>['egt',0],'dataFlag'=>1])->whereTime('createTime', 'between', [$date.' 00:00:00', $date.' 23:59:59'])->count();
|
||||
//待发货订单
|
||||
$stat['waitDeliveryCnt'] = Db::name('orders')->where(['shopId'=>$shopId,'orderStatus'=>0,'dataFlag'=>1])->count();
|
||||
//待收货订单
|
||||
$stat['waitReceiveCnt'] = Db::name('orders')->where(['shopId'=>$shopId,'orderStatus'=>1,'dataFlag'=>1])->count();
|
||||
//取消/拒收
|
||||
$stat['cancel'] = Db::name('orders')->where(['shopId'=>$shopId,'orderStatus'=>['in',[-1,-3]],'dataFlag'=>1])->count();
|
||||
//库存预警
|
||||
$goodsn = Db::name('goods')->where('shopId ='.$shopId.' and dataFlag = 1 and goodsStock <= warnStock and isSpec = 0 and warnStock>0')->cache('stockWarnCnt1'.$shopId,3600)->count();
|
||||
$specsn = Db::name('goods_specs')->where('shopId ='.$shopId.' and dataFlag = 1 and specStock <= warnStock and warnStock>0')->cache('stockWarnCnt2'.$shopId,3600)->count();
|
||||
$stat['stockWarnCnt'] = $goodsn+$specsn;
|
||||
|
||||
/**********商品信息**********/
|
||||
//商品总数
|
||||
$stat['goodsCnt'] = Db::name('goods')->where(['shopId'=>$shopId,'dataFlag'=>1])->cache('goodsCnt'.$shopId,3600)->count();
|
||||
//上架商品
|
||||
$stat['onSaleCnt'] = Db::name('goods')->where(['shopId'=>$shopId,'dataFlag'=>1,'goodsStatus'=>1,'isSale'=>1])->cache('onSaleCnt'.$shopId,3600)->count();
|
||||
//待审核商品
|
||||
$stat['waitAuditCnt'] = Db::name('goods')->where(['shopId'=>$shopId,'dataFlag'=>1,'goodsStatus'=>0])->cache('waitAuditCnt'.$shopId,3600)->count();
|
||||
//仓库中的商品
|
||||
$stat['unSaleCnt'] = Db::name('goods')->where(['shopId'=>$shopId,'dataFlag'=>1,'goodsStatus'=>1,'isSale'=>0])->cache('unSaleCnt'.$shopId,3600)->count();
|
||||
//违规商品
|
||||
$stat['illegalCnt'] = Db::name('goods')->where(['shopId'=>$shopId,'dataFlag'=>1,'goodsStatus'=>-1])->cache('illegalCnt'.$shopId,3600)->count();
|
||||
//今日新品
|
||||
$stat['newGoodsCnt'] = Db::name('goods')->where(['shopId'=>$shopId,'dataFlag'=>1,'goodsStatus'=>1,'isSale'=>1,'isNew'=>1])->cache('newGoodsCnt'.$shopId,3600)->count();
|
||||
|
||||
/**********订单信息**********/
|
||||
//待付款订单
|
||||
$stat['orderNeedpayCnt'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>-2,'dataFlag'=>1])->count();
|
||||
//待结束订单
|
||||
$stat['orderWaitCloseCnt'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>2,'dataFlag'=>1,'isClosed'=>0])->cache('orderWaitCloseCnt'.$shopId,3600)->count();
|
||||
//退货退款订单
|
||||
$stat['orderRefundCnt'] = Db::name('orders')->alias('o')->join('order_refunds orf','orf.orderId=o.orderId')->where(['shopId'=>$shopId,'refundStatus'=>0,'o.dataFlag'=>1])->count();
|
||||
//待评价订单
|
||||
$stat['orderWaitAppraisesCnt'] = Db::name('orders')->where(['shopId'=>$shopId,'orderStatus'=>2,'dataFlag'=>1,'isAppraise'=>0])->cache('orderWaitAppraisesCnt'.$shopId,3600)->count();
|
||||
// 投诉订单数
|
||||
$stat['complainNum'] = Db::name('order_complains')->where(['respondTargetId'=>$shopId,'complainStatus'=>1])->count();
|
||||
// 近七天销售排行
|
||||
$start = date('Y-m-d H:i:s',strtotime("-7 day"));
|
||||
$end = date('Y-m-d H:i:s');
|
||||
$stat['goodsTop'] = $rs = Db::field('og.goodsId,g.goodsName,goodsSn,sum(og.goodsNum) goodsNum,g.goodsImg')
|
||||
->name('order_goods')
|
||||
->alias('og')
|
||||
->join('__ORDERS__ o','og.orderId=o.orderId')
|
||||
->join('__GOODS__ g','og.goodsId=g.goodsId')
|
||||
->order('goodsNum desc')
|
||||
->whereTime('o.createTime','between',[$start,$end])
|
||||
->where('(payType=0 or (payType=1 and isPay=1)) and o.dataFlag=1 and o.shopId='.$shopId)->group('og.goodsId')
|
||||
->limit(10)->select();
|
||||
return ['shop'=>$shop,'stat'=>$stat];
|
||||
}
|
||||
/**
|
||||
* 获取店铺信息
|
||||
*/
|
||||
public function getByView($id){
|
||||
$shop = $this->alias('s')->join('__BANKS__ b','b.bankId=s.bankId','left')
|
||||
->where(['s.dataFlag'=>1,'shopId'=>$id])
|
||||
->field('s.*,b.bankName')->find();
|
||||
$areaIds = [];
|
||||
$areaMaps = [];
|
||||
$tmp = explode('_',$shop['areaIdPath']);
|
||||
foreach ($tmp as $vv){
|
||||
if($vv=='')continue;
|
||||
if(!in_array($vv,$areaIds))$areaIds[] = $vv;
|
||||
}
|
||||
if(!empty($areaIds)){
|
||||
$areas = Db::name('areas')->where(['dataFlag'=>1,'areaId'=>['in',$areaIds]])->field('areaId,areaName')->select();
|
||||
foreach ($areas as $v){
|
||||
$areaMaps[$v['areaId']] = $v['areaName'];
|
||||
}
|
||||
$tmp = explode('_',$shop['areaIdPath']);
|
||||
$areaNames = [];
|
||||
foreach ($tmp as $vv){
|
||||
if($vv=='')continue;
|
||||
$areaNames[] = @$areaMaps[$vv];
|
||||
$shop['areaName'] = implode('',$areaNames);
|
||||
}
|
||||
}
|
||||
|
||||
//获取经营范围
|
||||
$goodsCats = Db::name('goods_cats')->where(['parentId'=>0,'isShow'=>1,'dataFlag'=>1])->field('catId,catName')->select();
|
||||
$catshops = Db::name('cat_shops')->where('shopId',$id)->select();
|
||||
$catshopMaps = [];
|
||||
foreach ($goodsCats as $v){
|
||||
$catshopMaps[$v['catId']] = $v['catName'];
|
||||
}
|
||||
$catshopNames = [];
|
||||
foreach ($catshops as $key =>$v){
|
||||
if(isset($catshopMaps[$v['catId']]))$catshopNames[] = $catshopMaps[$v['catId']];
|
||||
}
|
||||
$shop['catshopNames'] = implode('、',$catshopNames);
|
||||
//获取认证类型
|
||||
$shop['accreds'] =Db::name('shop_accreds')->alias('sac')->join('__ACCREDS__ a','sac.accredId=a.accredId and a.dataFlag=1','inner')
|
||||
->where('sac.shopId',$id)->field('accredName,accredImg')->select();
|
||||
//开卡地址
|
||||
$areaNames = model('areas')->getParentNames($shop['bankAreaId']);
|
||||
$shop['bankAreaName'] = implode('',$areaNames);
|
||||
return $shop;
|
||||
}
|
||||
/**
|
||||
* 获取店铺指定字段
|
||||
*/
|
||||
public function getFieldsById($shopId,$fields){
|
||||
return $this->where(['shopId'=>$shopId,'dataFlag'=>1])->field($fields)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑店铺资料mark huang 20180312 限制银行卡信息只能修改一次
|
||||
*/
|
||||
public function editInfo(){
|
||||
//添加旺旺类型mark by cheng 20180314
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$shop_data['shopImg'] = input('post.shopImg');
|
||||
$shop_data['isInvoice'] = input('post.isInvoice');
|
||||
$shop_data['invoiceRemarks'] = input('post.invoiceRemarks');
|
||||
$shop_data['serviceStartTime'] = input('post.serviceStartTime');
|
||||
$shop_data['serviceEndTime'] = input('post.serviceEndTime');
|
||||
$shop_data['freight'] = input('post.freight');
|
||||
$shop_data['shopQQ'] = input('post.shopQQ');
|
||||
$shop_data['shopWangWang'] = input('post.shopWangWang');
|
||||
$shop_data['shopWangWangType'] = input('post.shopWangWangType');
|
||||
$result = $this->validate('Shops.editInfo')->allowField(['shopImg','isInvoice','invoiceRemarks','serviceStartTime','serviceEndTime','freight','shopQQ','shopWangWang','shopWangWangType'])->save($shop_data,['shopId'=>$shopId]);
|
||||
$bank_info = Db::name('shops')->where('shopId',$shopId)->field('bankNo,changeNum')->find();
|
||||
$bank_data['bankNo'] = input('post.bankNo');
|
||||
$result2 = true;
|
||||
if($bank_info['changeNum'] == 0 && $bank_data['bankNo'] != $bank_info['bankNo']){
|
||||
$bank_data['bankUserName'] = input('post.bankUserName');
|
||||
$bank_data['bankId'] = input('post.bankId');
|
||||
$bank_data['changeNum'] = $bank_info['changeNum'] + 1;
|
||||
$result2 = $this->allowField(['bankNo','bankUserName','shopId','bankId','changeNum'])->save($bank_data,['shopId'=>$shopId]);
|
||||
}elseif($bank_info['changeNum'] > 0){
|
||||
if($bank_data['bankNo'] != $bank_info['bankNo'] ){
|
||||
$result2 = false;
|
||||
}else{
|
||||
$result2 = true;
|
||||
}
|
||||
}
|
||||
if(false !== $result){
|
||||
if(false == $result2){
|
||||
$msg='银行卡修改失败!';
|
||||
}else{
|
||||
$msg='!';
|
||||
}
|
||||
return WSTReturn('店铺相关信息保存成功'.$msg,1);
|
||||
}else{
|
||||
return WSTReturn($this->getError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取店铺提现账号
|
||||
*/
|
||||
public function getShopAccount(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$shops = Db::name('shops')->alias('s')->join('banks b','b.bankId=s.bankId','inner')->where('s.shopId',$shopId)->field('b.bankName,s.bankAreaId,bankNo,bankUserName')->find();
|
||||
return $shops;
|
||||
}
|
||||
/**
|
||||
* 保存入驻资料
|
||||
*/
|
||||
public function saveStep2($data = []){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
//判断是否存在入驻申请
|
||||
$shops = $this->where('userId',$userId)->find();
|
||||
//新增入驻申请
|
||||
Db::startTrans();
|
||||
try{
|
||||
if(empty($shops)){
|
||||
$vshop = new VShop();
|
||||
$shop = ['userId'=>$userId,'applyStatus'=>0,'applyStep'=>2];
|
||||
$this->save($shop);
|
||||
WSTAllow($data,implode(',',$vshop->scene['applyStep1']));
|
||||
$data['shopId'] = $this->shopId;
|
||||
$result = Db::name('shop_extras')->insert($data);
|
||||
$shopId = $this->shopId;
|
||||
$WST_USER = session('WST_USER');
|
||||
$WST_USER['tempShopId'] = $shopId;
|
||||
session('WST_USER',$WST_USER);
|
||||
Db::commit();
|
||||
return WSTReturn('保存成功',1);
|
||||
}else{
|
||||
if($shops['applyStatus']>=1)return WSTReturn('请勿重复申请入驻');
|
||||
if($shops->applyStep<2){
|
||||
$shops->applyStep = 2;
|
||||
$shops->save();
|
||||
}
|
||||
$vshop = new VShop();
|
||||
WSTAllow($data,implode(',',$vshop->scene['applyStep1']));
|
||||
$result = Db::name('shop_extras')->where('shopId',$shops['shopId'])->update($data);
|
||||
if(false !== $result){
|
||||
Db::commit();
|
||||
return WSTReturn('保存成功',1);
|
||||
}else{
|
||||
return WSTReturn('保存失败');
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return WSTReturn('保存失败',-1);
|
||||
}
|
||||
}
|
||||
public function saveStep3($data = []){
|
||||
/*
|
||||
legalCertificateImg
|
||||
businessLicenceImg
|
||||
bankAccountPermitImg
|
||||
organizationCodeImg
|
||||
*/
|
||||
$auxiliary=explode(',',$data['shopAds']);
|
||||
$shopId = (int)session('WST_USER.tempShopId');
|
||||
if($shopId==0)return WSTReturn('非法的操作');
|
||||
$shops = model('shops')->get($shopId);
|
||||
if($shops['applyStatus']>=1)return WSTReturn('请勿重复申请入驻');
|
||||
//判断是否存在入驻申请
|
||||
$vshop = new VShop();
|
||||
WSTAllow($data,implode(',',$vshop->scene['applyStep2']));
|
||||
//获取地区
|
||||
$areaIds = model('Areas')->getParentIs($data['businessAreaPath0']);
|
||||
if(!empty($areaIds))$data['businessAreaPath'] = implode('_',$areaIds)."_";
|
||||
$areaIds = model('Areas')->getParentIs($data['areaIdPath0']);
|
||||
if(!empty($areaIds))$data['areaIdPath'] = implode('_',$areaIds)."_";
|
||||
//if($data['isLongbusinessDate']==1)unset($data['businessEndDate']);
|
||||
//if($data['isLonglegalCertificateDate']==1)unset($data['legalCertificateEndDate']);
|
||||
//if($data['isLongOrganizationCodeDate']==1)unset($data['organizationCodeEndDate']);
|
||||
Db::startTrans();
|
||||
try{
|
||||
if($shops->applyStep<3){
|
||||
$shops->applyStep = 3;
|
||||
$shops->save();
|
||||
}
|
||||
$validate = Loader::validate('Shops');
|
||||
if(!$validate->scene('applyStep2')->check($data))return WSTReturn($validate->getError());
|
||||
$seModel = model('ShopExtras');
|
||||
$seModel->allowField(true)->save($data,['shopId'=>$shopId]);
|
||||
$Id = $seModel->where(['shopId'=>$shopId])->value('id');// 获取主键
|
||||
//启用上传图片
|
||||
WSTUseImages(0, $Id, $data['legalCertificateImg'],'shopextras');
|
||||
WSTUseImages(0, $Id, $data['businessLicenceImg'],'shopextras');
|
||||
WSTUseImages(0, $Id, $data['bankAccountPermitImg'],'shopextras');
|
||||
WSTUseImages(0, $Id, $data['organizationCodeImg'],'shopextras');
|
||||
$auxiliary_data=[];
|
||||
$shopAuxiliary = Db::name('shop_auxiliary')->where('shopId='.$shopId)->find();
|
||||
WSTUseImages(0, $shopAuxiliary['id'], $auxiliary,'shopauxiliary');
|
||||
Db::name('shop_auxiliary')->where('shopId='.$shopId)->delete();
|
||||
foreach($auxiliary as $k=>$v){
|
||||
$auxiliary_data[$k]['shopId']=$shopId;
|
||||
$auxiliary_data[$k]['auxiliaryImg']=$v;
|
||||
}
|
||||
Db::name('shop_auxiliary')->insertAll($auxiliary_data);
|
||||
$this->allowField(true)->save($data,['shopId'=>$shopId]);
|
||||
Db::commit();
|
||||
return WSTReturn('保存成功',1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return WSTReturn('保存失败',-1);
|
||||
}
|
||||
}
|
||||
public function saveStep4($data = []){
|
||||
/*
|
||||
taxRegistrationCertificateImg
|
||||
taxpayerQualificationImg
|
||||
*/
|
||||
$shopId = (int)session('WST_USER.tempShopId');
|
||||
if($shopId==0)return WSTReturn('非法的操作');
|
||||
$shops = model('shops')->get($shopId);
|
||||
if($shops['applyStatus']>=1)return WSTReturn('请勿重复申请入驻');
|
||||
//判断是否存在入驻申请
|
||||
$vshop = new VShop();
|
||||
WSTAllow($data,implode(',',$vshop->scene['applyStep3']));
|
||||
$areaIds = model('Areas')->getParentIs($data['bankAreaId']);
|
||||
if(!empty($areaIds))$data['bankAreaIdPath'] = implode('_',$areaIds)."_";
|
||||
Db::startTrans();
|
||||
try{
|
||||
if($shops->applyStep<4){
|
||||
$shops->applyStep = 4;
|
||||
$shops->save();
|
||||
}
|
||||
$seModel = model('ShopExtras');
|
||||
$seModel->allowField(true)->save($data,['shopId'=>$shopId]);
|
||||
/*--------取消上传图片选项 mark hsf 20180104----------*/
|
||||
//$Id = $seModel->where(['shopId'=>$shopId])->value('id');
|
||||
//启用上传图片
|
||||
//WSTUseImages(0, $Id, $data['taxRegistrationCertificateImg'],'shopextras');
|
||||
// WSTUseImages(0, $Id, $data['taxpayerQualificationImg'],'shopextras');
|
||||
/*-------------------------end---------------------------*/
|
||||
$this->allowField(true)->save($data,['shopId'=>$shopId]);
|
||||
Db::commit();
|
||||
return WSTReturn('保存成功',1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return WSTReturn('保存失败',-1);
|
||||
}
|
||||
}
|
||||
public function saveStep5($data = []){
|
||||
$shopId = (int)session('WST_USER.tempShopId');
|
||||
if($shopId==0)return WSTReturn('非法的操作');
|
||||
$shops = model('shops')->get($shopId);
|
||||
if($shops['applyStatus']>=1)return WSTReturn('请勿重复申请入驻');
|
||||
//判断是否存在入驻申请
|
||||
$vshop = new VShop();
|
||||
$filters = $vshop->scene['applyStep4'];
|
||||
$filters[] = 'shopQQ';
|
||||
$filters[] = 'shopWangWang';
|
||||
WSTAllow($data,implode(',',$filters));
|
||||
$shopLicense=input('shopLicense');
|
||||
if((strpos($data['goodsCatIds'],'393')!==false)||$data['goodsCatIds']=='393'){
|
||||
if($shopLicense==""){
|
||||
|
||||
return WSTReturn('食品许可证不能为空');
|
||||
}
|
||||
}else{
|
||||
$shopLicense='';
|
||||
}
|
||||
Db::startTrans();
|
||||
try{
|
||||
$data['applyStatus'] = 1;
|
||||
$data['applyTime'] = date('Y-m-d H:i:s');
|
||||
$find=$this->where('shopName',$data['shopName'])->find();
|
||||
if($find) return WSTReturn('此商铺名称已存在,请重新填写');
|
||||
$result = $this->allowField(true)->save($data,['shopId'=>$shopId]);
|
||||
$row=db('shop_license')->insert(['shopId'=>$shopId,'shopLicense'=>$shopLicense]);
|
||||
// // // 启用图片
|
||||
WSTUseImages(0, $shopId, $data['shopImg'],'shops','shopImg');
|
||||
//WSTUseImages(0, $shopId, $shopLicense,'shoplicense','shopLicense');
|
||||
|
||||
if($shops->applyStep<5){
|
||||
$shops->applyStep = 5;
|
||||
$shops->save();
|
||||
}
|
||||
if(false !== $result){
|
||||
//经营范围
|
||||
$goodsCats = explode(',',$data['goodsCatIds']);
|
||||
foreach ($goodsCats as $v){
|
||||
if((int)$v>0)Db::name('cat_shops')->insert(['shopId'=>$shopId,'catId'=>$v]);
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn('保存成功',1);
|
||||
}else{
|
||||
return WSTReturn('保存失败');
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return WSTReturn('保存失败',-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商家入驻资料
|
||||
*/
|
||||
public function getShopApply(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$rs = $this->alias('s')
|
||||
->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','inner')
|
||||
->where('s.userId',$userId)
|
||||
->find();
|
||||
if(!empty($rs)){
|
||||
$rs = $rs->toArray();
|
||||
$goodscats = Db::name('cat_shops')->where('shopId',$rs['shopId'])->select();
|
||||
$rs['catshops'] = [];
|
||||
foreach ($goodscats as $v){
|
||||
$rs['catshops'][$v['catId']] = true;
|
||||
}
|
||||
$rs['taxRegistrationCertificateImgVO'] = ($rs['taxRegistrationCertificateImg']!='')?explode(',',$rs['taxRegistrationCertificateImg']):[];
|
||||
|
||||
}else{
|
||||
$rs = [];
|
||||
$data1 = $this->getEModel('shops');
|
||||
$data2 = $this->getEModel('shop_extras');
|
||||
$rs = array_merge($data1,$data2);
|
||||
$rs['taxRegistrationCertificateImgVO'] = [];
|
||||
}
|
||||
$rs['auxiliary']=db('shop_auxiliary')->where('shopId',$rs['shopId'])->select();
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否申请入驻过
|
||||
*/
|
||||
public function checkApply(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$rs = $this->where(['userId'=>$userId])->find();
|
||||
if(!empty($rs)){
|
||||
$WST_USER = session('WST_USER');
|
||||
$WST_USER['tempShopId'] = $rs->shopId;
|
||||
session('WST_USER',$WST_USER);
|
||||
session('apply_step',$rs['applyStep']);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 首页店铺街列表
|
||||
*/
|
||||
public function indexShopQuery($num=4){
|
||||
/** 添加返回店铺街商店 mark hsf 20180223 */
|
||||
$shop_list = model('common/Tags')->listShop(0,$num,0);
|
||||
foreach ($shop_list as &$v) {
|
||||
$v['shopAddress'] = Db::name('shops')->where(['shopId'=>$v['shopId']])->value('shopAddress');
|
||||
$v['shopStreetImg'] = Db::name('shop_configs')->where(['shopId'=>$v['shopId']])->value('shopStreetImg');
|
||||
}
|
||||
return $shop_list;
|
||||
/** end */
|
||||
$rs = $this->alias('s')
|
||||
->join('__SHOP_CONFIGS__ sc','s.shopId=sc.shopId','inner')
|
||||
->field('s.shopId,s.shopName,s.shopAddress,sc.shopStreetImg')
|
||||
->limit($num)
|
||||
->select();
|
||||
return $rs;
|
||||
}
|
||||
}
|
10
hyhproject/home/model/SpecItems.php
Executable file
10
hyhproject/home/model/SpecItems.php
Executable file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 商品规格值类
|
||||
*/
|
||||
use think\Db;
|
||||
class SpecItems extends Base{
|
||||
|
||||
}
|
33
hyhproject/home/model/Users.php
Executable file
33
hyhproject/home/model/Users.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace wstmart\home\model;
|
||||
use wstmart\common\model\Users as CUsers;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 用户类
|
||||
*/
|
||||
use think\Db;
|
||||
class Users extends CUsers{
|
||||
/**
|
||||
* 获取各订单状态数、未读消息数、账户安全等级
|
||||
*/
|
||||
function getStatusNum(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$data = [];
|
||||
// 用户消息
|
||||
$data['message'] = Db::name('messages')->where(['receiveUserId'=>$userId,'msgStatus'=>0,'dataFlag'=>1])->count();
|
||||
//获取用户订单状态
|
||||
$data['waitPay'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>-2,'dataFlag'=>1])->count();
|
||||
$data['waitReceive'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>['in',[0,1]],'dataFlag'=>1])->count();
|
||||
$data['received'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>2,'dataFlag'=>1])->count();
|
||||
$data['waitAppr'] = Db::name('orders')->where(['userId'=>$userId,'orderStatus'=>2,'isAppraise'=>0,'dataFlag'=>1])->count();
|
||||
// 账户安全等级
|
||||
$level = 1;
|
||||
$users = $this->field('userPhone,userEmail')->find($userId);
|
||||
if(!empty($users['userPhone']))++$level;
|
||||
if(!empty($users['userEmail']))++$level;
|
||||
$data['level'] = $level;
|
||||
//关注商品
|
||||
$data['gfavorite'] = Db::name('favorites')->where(['userId'=>$userId,'favoriteType'=>0])->count();
|
||||
return $data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user