You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
172
hyhproject/admin/model/Accreds.php
Executable file
172
hyhproject/admin/model/Accreds.php
Executable file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商家认证业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Accreds extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
return $this->where('dataFlag',1)->field(true)->order('accredId desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery(){
|
||||
|
||||
return $this->where('dataFlag',1)->field(true)->select();
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['accredId'=>$id,'dataFlag'=>1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
WSTUnset($data,'accredId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('Accreds.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !==$result){
|
||||
|
||||
$id = $this->accredId;
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $data['accredImg']);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, (int)$data['accredId'], $data['accredImg'], 'accreds', 'accredImg');
|
||||
|
||||
$result = $this->validate('Accreds.edit')->allowField(true)->save($data,['accredId'=>(int)$data['accredId']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('post.id/d');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->setField(['dataFlag'=>-1,'accredId'=>$id]);
|
||||
|
||||
WSTUnuseImage('accreds','accredImg',$id);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
68
hyhproject/admin/model/AdPositions.php
Executable file
68
hyhproject/admin/model/AdPositions.php
Executable file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 广告位置业务处理
|
||||
*/
|
||||
class AdPositions extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$positionType = (int)input('positionType');
|
||||
$key = input('key');
|
||||
$where = [];
|
||||
$where['dataFlag'] = 1;
|
||||
if($positionType>0)$where['positionType'] = $positionType;
|
||||
if($key !='')$where['positionCode'] = ['like','%'.$key.'%'];
|
||||
return $this->where($where)->field(true)->order('apSort asc,positionId desc')->paginate(input('limit/d'));
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->get(['positionId'=>$id,'dataFlag'=>1]);
|
||||
}
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'positionId');
|
||||
$result = $this->validate('AdPositions.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = (int)input('post.positionId');
|
||||
$result = $this->validate('AdPositions.edit')->allowField(true)->save(input('post.'),['positionId'=>$Id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = (int)input('post.id/d');
|
||||
$result = $this->setField(['positionId'=>$id,'dataFlag'=>-1]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取广告位置
|
||||
*/
|
||||
public function getPositon($typeId){
|
||||
return $this->where(['positionType'=>$typeId,'dataFlag'=>1])->order('apSort asc,positionId asc')->select();
|
||||
}
|
||||
|
||||
}
|
139
hyhproject/admin/model/Addons.php
Executable file
139
hyhproject/admin/model/Addons.php
Executable file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 插件业务处理
|
||||
*/
|
||||
class Addons extends Base{
|
||||
|
||||
/**
|
||||
* 获取插件列表
|
||||
* @param string $addon_dir
|
||||
*/
|
||||
public function pageQuery($addon_dir = ''){
|
||||
if(!$addon_dir)
|
||||
$addon_dir = WST_ADDON_PATH;
|
||||
$dirs = array_map('basename',glob($addon_dir.'*', GLOB_ONLYDIR));
|
||||
if($dirs === FALSE || !file_exists($addon_dir)){
|
||||
$this->error = '插件目录不可读或者不存在';
|
||||
return FALSE;
|
||||
}
|
||||
$addons = array();
|
||||
$where['dataFlag'] = 1;
|
||||
$where['name'] = array('not in',$dirs);
|
||||
$this->where($where)->delete();
|
||||
|
||||
$names = $this->column("name");
|
||||
$names = array_map('strtolower', $names);
|
||||
$list = array();
|
||||
foreach ($dirs as $value) {
|
||||
if(!in_array($value,$names)){
|
||||
$class = get_addon_class($value);
|
||||
if(!class_exists($class)){ // 实例化插件失败忽略执行
|
||||
\Think\Log::record('插件'.$value.'的入口文件不存在!');
|
||||
continue;
|
||||
}
|
||||
$obj = new $class;
|
||||
$data = $obj->info;
|
||||
$config = $obj->getConfig();
|
||||
$data["isConfig"] = count($config)?1:0;
|
||||
$data["createTime"] = date("Y-m-d H:i:s");
|
||||
$data["updateTime"] = date("Y-m-d H:i:s");
|
||||
$data["dataFlag"] = 1;
|
||||
$list[] = $data;
|
||||
}
|
||||
}
|
||||
$this->saveAll($list);
|
||||
$keyWords = input("keyWords");
|
||||
$parentId = input('get.parentId/d',0);
|
||||
$sort = input('sort');
|
||||
$where = array();
|
||||
$where["dataFlag"] = 1;
|
||||
$where["name|title"] = array("like","%$keyWords%");
|
||||
$order = 'addonId desc';
|
||||
if($sort){
|
||||
$sort = str_replace('.',' ',$sort);
|
||||
$order = $sort;
|
||||
}
|
||||
$page = $this->where($where)->order($order)->paginate(input('post.limit/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
$page['Rows'][$key]['statusName'] = WSTLangAddonStatus($v['status']);
|
||||
$page['Rows'][$key]['hasConf'] = ($v['isConfig']!='')?1:0;
|
||||
}
|
||||
}
|
||||
cache('WST_ADDONS_MAPS',null);
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存插件设置
|
||||
*/
|
||||
public function saveConfig(){
|
||||
$id = input("id/d",0);
|
||||
$config = isset($_POST['config'])?$_POST['config']:array();
|
||||
$data["config"] = json_encode($config);
|
||||
$data["updateTime"] = date('Y-m-d H:i:s');
|
||||
$flag = $this->save($data,['addonId'=>$id]);
|
||||
if($flag !== false){
|
||||
return WSTReturn("保存成功", 1);
|
||||
}else{
|
||||
return WSTReturn('保存失败',-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定记录
|
||||
*/
|
||||
public function getById(){
|
||||
$id = input("id/d",0);
|
||||
return $this->get(['addonId'=>$id,'dataFlag'=>1])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = (int)input('post.id/d');
|
||||
$result = $this->where(["addonId"=>$id,'dataFlag'=>1])->delete();
|
||||
if($result!==false){
|
||||
cache('WST_ADDONS_MAPS',null);
|
||||
return WSTReturn("卸载成功", 1);
|
||||
}
|
||||
return WSTReturn('卸载失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改插件状态
|
||||
*/
|
||||
public function editStatus($status){
|
||||
$id = (int)input('post.id/d');
|
||||
$data = array();
|
||||
$data["status"] = $status;
|
||||
$data["updateTime"] = date('Y-m-d H:i:s');
|
||||
$result = $this->save($data,['addonId'=>$id]);
|
||||
if($result!==false){
|
||||
return WSTReturn("操作成功", 1);
|
||||
}
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
|
||||
|
||||
}
|
224
hyhproject/admin/model/Adgoods.php
Executable file
224
hyhproject/admin/model/Adgoods.php
Executable file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 广告业务处理
|
||||
|
||||
*/
|
||||
|
||||
class adgoods extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$where = [];
|
||||
|
||||
$apId = (int)input('adId');
|
||||
|
||||
if($apId>0)$where['a.adId'] = $apId;
|
||||
|
||||
return Db::name('adgoods')->alias('a')
|
||||
|
||||
->join('ads ap','a.adId=ap.adId','left')
|
||||
|
||||
->join('goods g','g.goodsId=a.goodsId')
|
||||
|
||||
->field('a.adId,adName,g.goodsId,goodsName,a.startDate,a.endDate,adGoodsImg,a.adGoodsStatus,a.adGoodsId')
|
||||
|
||||
->where($where)->order('a.adId desc')
|
||||
|
||||
->order('a.goodsId','asc')
|
||||
|
||||
->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
$result= $this->get(['adGoodsId'=>$id]);
|
||||
|
||||
//$result['adName']=db('ads')->where('adId',$result['adId'])->value('adName');
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['createTime'] = time();
|
||||
|
||||
WSTUnset($data,'adGoodsId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$goods=db('goods')->where(['goodsId'=>$data['goodsId'],'dataFlag'=>1,'isSale'=>1,'goodsStatus'=>1])->find();
|
||||
|
||||
if(!$goods) return WSTReturn('无此商品,请重新选择商品');
|
||||
|
||||
$result = $this->validate('adgoods.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
$id = $this->adId;
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $data['adGoodsImg']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
//WSTUseImages(1, (int)$data['adId'], $data['adFile'], 'ads-pic', 'adFile');
|
||||
|
||||
$result = $this->validate('adgoods.edit')->allowField(true)->save($data,['adGoodsId'=>(int)$data['adGoodsId']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('post.id/d');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where(['adGoodsId'=>$id])->delete();
|
||||
|
||||
WSTUnuseImage('adgoods','adGoodsImg',$id);
|
||||
|
||||
if($result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改广告排序
|
||||
|
||||
*/
|
||||
|
||||
public function changeSort(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$adSort = (int)input('adSort');
|
||||
|
||||
$result = $this->setField(['adId'=>$id,'adSort'=>$adSort]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
228
hyhproject/admin/model/Ads.php
Executable file
228
hyhproject/admin/model/Ads.php
Executable file
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 广告业务处理
|
||||
|
||||
*/
|
||||
|
||||
class ads extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['a.dataFlag'] = 1;
|
||||
|
||||
$pt = (int)input('positionType');
|
||||
|
||||
$apId = (int)input('adPositionId');
|
||||
|
||||
if($pt>0)$where['a.positionType'] = $pt;
|
||||
|
||||
if($apId!=0)$where['a.adPositionId'] = $apId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return Db::name('ads')->alias('a')
|
||||
|
||||
->join('ad_positions ap','a.positionType=ap.positionType AND a.adPositionId=ap.positionId AND ap.dataFlag=1','left')
|
||||
|
||||
->field('adId,adName,adPositionId,adURL,adStartDate,adEndDate,adPositionId,adFile,adClickNum,ap.positionName,a.adSort')
|
||||
|
||||
->where($where)->order('adId desc')
|
||||
|
||||
->order('adSort','asc')
|
||||
|
||||
->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['adId'=>$id,'dataFlag'=>1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$data['adSort'] = (int)$data['adSort'];
|
||||
|
||||
WSTUnset($data,'adId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('ads.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
$id = $this->adId;
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $data['adFile']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['adSort'] = (int)$data['adSort'];
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, (int)$data['adId'], $data['adFile'], 'ads-pic', 'adFile');
|
||||
|
||||
$result = $this->validate('ads.edit')->allowField(true)->save($data,['adId'=>(int)$data['adId']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('post.id/d');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->setField(['adId'=>$id,'dataFlag'=>-1]);
|
||||
|
||||
WSTUnuseImage('ads','adFile',$id);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改广告排序
|
||||
|
||||
*/
|
||||
|
||||
public function changeSort(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$adSort = (int)input('adSort');
|
||||
|
||||
$result = $this->setField(['adId'=>$id,'adSort'=>$adSort]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
69
hyhproject/admin/model/Alipays.php
Executable file
69
hyhproject/admin/model/Alipays.php
Executable file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Loader;
|
||||
use think\Db;
|
||||
use Env;
|
||||
use wstmart\common\model\Payments as M;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 阿里支付控制器
|
||||
*/
|
||||
class Alipays extends Base{
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
public function orderRefund($refund,$order){
|
||||
|
||||
$content = input('post.content');
|
||||
$refundId = (int)input('post.id');
|
||||
$request_no = $order['orderNo'].$order['userId'];
|
||||
$backMoney = $refund["backMoney"];
|
||||
$tradeNo = $order['tradeNo'];
|
||||
$refund_reason = "订单【".$order['orderNo']."】退款";
|
||||
|
||||
require Env::get('root_path') . 'extend/alipay/aop/AopClient.php';
|
||||
require Env::get('root_path') . 'extend/alipay/aop/request/AlipayTradeRefundRequest.php';
|
||||
$m = new M();
|
||||
$payment = $m->getPayment("alipays");
|
||||
$aop = new \AopClient ();
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
$aop->appId = $payment["appId"];
|
||||
$aop->rsaPrivateKey = $payment["rsaPrivateKey"];
|
||||
$aop->alipayrsaPublicKey=$payment["alipayrsaPublicKey"];
|
||||
$aop->apiVersion = '1.0';
|
||||
$aop->signType = 'RSA2';
|
||||
$aop->postCharset='UTF-8';
|
||||
$aop->format='json';
|
||||
$request = new \AlipayTradeRefundRequest ();
|
||||
|
||||
$request->setBizContent("{" .
|
||||
"\"trade_no\":\"$tradeNo\"," .
|
||||
"\"refund_amount\":\"$backMoney\"," .
|
||||
"\"refund_reason\":\"$refund_reason\"," .
|
||||
"\"out_request_no\":\"$request_no\"" .
|
||||
" }");
|
||||
|
||||
$result = $aop->execute ( $request);
|
||||
|
||||
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
||||
$resultCode = $result->$responseNode->code;
|
||||
if(!empty($resultCode) && $resultCode == 10000){
|
||||
if($result->$responseNode->fund_change=="Y"){
|
||||
$obj = array();
|
||||
$obj['refundTradeNo'] = $request_no;//退款单号
|
||||
$obj['content'] = $content;
|
||||
$obj['refundId'] = $refundId;
|
||||
$rs = model('admin/OrderRefunds')->complateOrderRefund($obj);
|
||||
if($rs['status']==1){
|
||||
return WSTReturn("退款成功",1);
|
||||
}else{
|
||||
return WSTReturn("退款失败",1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$msg = $result->$responseNode->sub_msg;
|
||||
return WSTReturn($msg,-1);
|
||||
}
|
||||
}
|
||||
}
|
169
hyhproject/admin/model/Areas.php
Executable file
169
hyhproject/admin/model/Areas.php
Executable file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 地区业务处理
|
||||
*/
|
||||
class Areas extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$parentId = input('get.parentId/d',0);
|
||||
return $this->where(['dataFlag'=>1,'parentId'=>$parentId])->order('areaId desc')->paginate(input('post.limit/d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定对象
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['dataFlag'=>1,'areaId'=>$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地区
|
||||
*/
|
||||
public function getFieldsById($id,$fileds){
|
||||
return $this->where(['dataFlag'=>1,'areaId'=>$id])->field($fileds)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示是否显示/隐藏
|
||||
*/
|
||||
public function editiIsShow(){
|
||||
//获取子集
|
||||
$ids = array();
|
||||
$ids[] = input('post.id/d',0);
|
||||
$ids = $this->getChild($ids,$ids);
|
||||
$isShow = input('post.isShow/d',0)?0:1;
|
||||
$result = $this->where("areaId in(".implode(',',$ids).")")->update(['isShow' => $isShow]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("操作成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 迭代获取下级
|
||||
*/
|
||||
public function getChild($ids = array(),$pids = array()){
|
||||
$result = $this->where("dataFlag=1 and parentId in(".implode(',',$pids).")")->select();
|
||||
if(count($result)>0){
|
||||
$cids = array();
|
||||
foreach ($result as $key =>$v){
|
||||
$cids[] = $v['areaId'];
|
||||
}
|
||||
$ids = array_merge($ids,$cids);
|
||||
return $this->getChild($ids,$cids);
|
||||
}else{
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据子分类获取其父级分类
|
||||
*/
|
||||
public function getParentIs($id,$data = array()){
|
||||
$data[] = $id;
|
||||
$parentId = $this->where('areaId',$id)->value('parentId');
|
||||
if($parentId==0){
|
||||
krsort($data);
|
||||
return $data;
|
||||
}else{
|
||||
return $this->getParentIs($parentId, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自己以及父级的地区名称
|
||||
*/
|
||||
public function getParentNames($id,$data = array()){
|
||||
$areas = $this->where('areaId',$id)->field('parentId,areaName')->find();
|
||||
$data[] = $areas['areaName'];
|
||||
if((int)$areas['parentId']==0){
|
||||
krsort($data);
|
||||
return $data;
|
||||
}else{
|
||||
return $this->getParentNames((int)$areas['parentId'], $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 排序字母
|
||||
*/
|
||||
public function letterObtain(){
|
||||
$areaName = input('code');
|
||||
if($areaName =='')return WSTReturn("", 1);
|
||||
$areaName = WSTGetFirstCharter($areaName);
|
||||
if($areaName){
|
||||
return WSTReturn($areaName, 1);
|
||||
}else{
|
||||
return WSTReturn("", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$areaType = 0;
|
||||
$parentId = input('post.parentId/d',0);
|
||||
if($parentId>0){
|
||||
$prs = $this->getFieldsById($parentId,['areaType']);
|
||||
$areaType = $prs['areaType']+1;
|
||||
}
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'areaId,dataFlag');
|
||||
$data['areaType'] = $areaType;
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$result = $this->validate('Areas.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$areaId = input('post.areaId/d');
|
||||
$result = $this->validate('Areas.edit')->allowField(['areaName','isShow','areaSort','areaKey'])->save(input('post.'),['areaId'=>$areaId]);
|
||||
$ids = array();
|
||||
$ids[] = $areaId;
|
||||
$ids = $this->getChild($ids,$ids);
|
||||
$this->where("areaId in(".implode(',',$ids).")")->update(['isShow' => input('post.')['isShow']]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("修改成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$ids = array();
|
||||
$ids[] = input('post.id/d');
|
||||
$ids = $this->getChild($ids,$ids);
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->where("areaId in(".implode(',',$ids).")")->update($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地区列表
|
||||
*/
|
||||
public function listQuery($parentId){
|
||||
return $this->where(['dataFlag'=>1,'parentId'=>$parentId,'isShow'=>1])->field('areaId,areaName,parentId')->order('areaSort desc')->select();
|
||||
}
|
||||
}
|
337
hyhproject/admin/model/ArticleCats.php
Executable file
337
hyhproject/admin/model/ArticleCats.php
Executable file
@ -0,0 +1,337 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 文章分类业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class ArticleCats extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取树形分类
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$parentId = input('catId/d',0);
|
||||
|
||||
$data = $this->where(['dataFlag'=>1,'parentId'=>$parentId])->order('catId desc')->paginate(1000)->toArray();
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery($parentId){
|
||||
|
||||
$rs = $this->where(['dataFlag'=>1,'parentId'=>$parentId])->order('catSort asc,catName asc')->select();
|
||||
|
||||
if(count($rs)>0){
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
$rs[$key]['childrenurl'] = url('admin/articlecats/listQuery',array('parentId'=>$v['catId']));
|
||||
|
||||
$rs[$key]['children'] = [];
|
||||
|
||||
$rs[$key]['isextend'] = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['dataFlag'=>1,'catId'=>$id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取文章分类列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery2(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
return $this->where(['dataFlag'=>1,'isShow'=>1,'parentId'=>$id])->field('catId as id,catName as name,parentId as pId, 1 as isParent')->order('catSort desc')->select();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改分类名称
|
||||
|
||||
*/
|
||||
|
||||
public function editName(){
|
||||
|
||||
if(input('catName')=='')return WSTReturn("操作失败,商品分类名称不能为空");
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$result = $this->where("catId = ".$id)->update(['catName' => input('catName')]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 显示是否显示/隐藏
|
||||
|
||||
*/
|
||||
|
||||
public function editiIsShow(){
|
||||
|
||||
$ids = array();
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$ids = $this->getChild($id);
|
||||
|
||||
$isShow = input('post.isShow/d')?1:0;
|
||||
|
||||
$result = $this->where("catId in(".implode(',',$ids).")")->update(['isShow' => $isShow]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 迭代获取下级
|
||||
|
||||
* 获取一个分类下的所有子级分类id
|
||||
|
||||
*/
|
||||
|
||||
public function getChild($pid=1){
|
||||
|
||||
$data = $this->where("dataFlag=1")->select();
|
||||
|
||||
//获取该分类id下的所有子级分类id
|
||||
|
||||
$ids = $this->_getChild($data, $pid, true);//每次调用都清空一次数组
|
||||
|
||||
//把自己也放进来
|
||||
|
||||
array_unshift($ids, $pid);
|
||||
|
||||
return $ids;
|
||||
|
||||
}
|
||||
|
||||
public function _getChild($data, $pid, $isClear=false){
|
||||
|
||||
static $ids = array();
|
||||
|
||||
if($isClear)//是否清空数组
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach($data as $k=>$v)
|
||||
|
||||
{
|
||||
|
||||
if($v['parentId']==$pid && $v['dataFlag']==1)
|
||||
|
||||
{
|
||||
|
||||
$ids[] = $v['catId'];//将找到的下级分类id放入静态数组
|
||||
|
||||
//再找下当前id是否还存在下级id
|
||||
|
||||
$this->_getChild($data, $v['catId']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ids;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$parentId = input('post.parentId/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'catId,catType,dataFlag');
|
||||
|
||||
$data['parentId'] = $parentId;
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$result = $this->validate('ArticleCats.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$catId = input('post.id/d');
|
||||
|
||||
$result = $this->validate('ArticleCats.edit')->allowField(['catName','isShow','catSort'])->save(input('post.'),['catId'=>$catId]);
|
||||
|
||||
$ids = array();
|
||||
|
||||
$ids = $this->getChild($catId);
|
||||
|
||||
$this->where("catId in(".implode(',',$ids).")")->update(['isShow' => input('post.')['isShow']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$ids = array();
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$ids = $this->getChild($id);
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
$rs = $this->getById($id);
|
||||
|
||||
if($rs['catType']==1){
|
||||
|
||||
return WSTReturn("不能删除该分类", -1);
|
||||
|
||||
}else{
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where("catId in(".implode(',',$ids).")")->update($data);
|
||||
|
||||
if(false !==$result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::name('articles')->where(['catId'=>['in',$ids]])->update(['dataFlag'=>-1]);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
349
hyhproject/admin/model/Articles.php
Executable file
349
hyhproject/admin/model/Articles.php
Executable file
@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 文章业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Articles extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$key = input('key');
|
||||
|
||||
$catId = (int)input('catId');
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$catIds = [];
|
||||
|
||||
if($catId>0){
|
||||
|
||||
$catIds = model('ArticleCats')->getChild($catId);
|
||||
|
||||
}
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['a.dataFlag'] = 1;
|
||||
|
||||
if(count($catIds)>0)$where['a.catId'] = ['in',$catIds];
|
||||
|
||||
if($key!='')$where['a.articleTitle'] = ['like','%'.$key.'%'];
|
||||
|
||||
$order = 'a.articleId desc';
|
||||
|
||||
if($sort){
|
||||
|
||||
$sort = str_replace('.',' ',$sort);
|
||||
|
||||
$order = $sort;
|
||||
|
||||
}
|
||||
|
||||
$page = Db::name('articles')->alias('a')
|
||||
|
||||
->join('__ARTICLE_CATS__ ac','a.catId= ac.catId','left')
|
||||
|
||||
->join('__STAFFS__ s','a.staffId= s.staffId','left')
|
||||
|
||||
->where($where)
|
||||
|
||||
->field('a.articleId,a.catId,a.articleTitle,a.isShow,a.articleContent,a.articleKey,a.createTime,ac.catName,s.staffName')
|
||||
|
||||
->order($order)
|
||||
|
||||
->paginate(input('post.limit/d'))->toArray();
|
||||
|
||||
if(count($page['Rows'])>0){
|
||||
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
|
||||
$page['Rows'][$key]['articleContent'] = strip_tags(htmlspecialchars_decode($v['articleContent']));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 显示是否显示/隐藏
|
||||
|
||||
*/
|
||||
|
||||
public function editiIsShow(){
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$isShow = (input('post.isShow/d')==1)?1:0;
|
||||
|
||||
$result = $this->where(['articleId'=>$id])->update(['isShow' => $isShow]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getById($id){
|
||||
|
||||
$single = $this->where(['articleId'=>$id,'dataFlag'=>1])->find();
|
||||
|
||||
$singlec = Db::name('article_cats')->where(['catId'=>$single['catId'],'dataFlag'=>1])->field('catName')->find();
|
||||
|
||||
$single['catName']=$singlec['catName'];
|
||||
|
||||
$single['articleContent'] = htmlspecialchars_decode($single['articleContent']);
|
||||
|
||||
return $single;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'articleId,dataFlag');
|
||||
|
||||
$data["staffId"] = (int)session('WST_STAFF.staffId');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('Articles.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
// 预览图
|
||||
|
||||
WSTUseImages(1, $this->articleId, $data['coverImg']);
|
||||
|
||||
//文章描述图片
|
||||
|
||||
WSTEditorImageRocord(1, $this->articleId, '',$data['articleContent']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$articleId = input('post.id/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'articleId,dataFlag,createTime');
|
||||
|
||||
$data["staffId"] = (int)session('WST_STAFF.staffId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
// 预览图
|
||||
|
||||
WSTUseImages(0, $articleId, $data['coverImg'],'articles','coverImg');
|
||||
|
||||
//文章描述图片
|
||||
|
||||
$oldArticleContent = $this->where('articleId',$articleId)->value('articleContent');// 旧描述
|
||||
|
||||
WSTEditorImageRocord(1, $articleId, $oldArticleContent,$data['articleContent']);
|
||||
|
||||
$result = $this->validate('Articles.edit')->allowField(true)->save($data,['articleId'=>$articleId]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where(['articleId'=>$id])->update($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
// 预览图
|
||||
|
||||
WSTUnuseImage('articles','coverImg',$id);
|
||||
|
||||
//文章描述图片
|
||||
|
||||
$oldArticleContent = $this->where('articleId',$id)->value('articleContent');// 旧描述
|
||||
|
||||
WSTEditorImageRocord(1, $id, $oldArticleContent,'');
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 批量删除
|
||||
|
||||
*/
|
||||
|
||||
public function delByBatch(){
|
||||
|
||||
$ids = input('post.ids');
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where(['articleId'=>['in',$ids]])->update($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
$oldArticleContent = $this->field('articleId,articleContent')->where(['articleId'=>['in',$ids]])->select();// 旧描述
|
||||
|
||||
foreach($oldArticleContent as $k=>$v){
|
||||
|
||||
// 预览图
|
||||
|
||||
WSTUnuseImage('articles','coverImg',$v['articleId']);
|
||||
|
||||
//文章描述图片
|
||||
|
||||
WSTEditorImageRocord(1, $v['articleId'], $v['articleContent'],'');
|
||||
|
||||
}
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
132
hyhproject/admin/model/Attributes.php
Executable file
132
hyhproject/admin/model/Attributes.php
Executable file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 规格业务处理
|
||||
*/
|
||||
class Attributes extends Base{
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
WSTUnset($data, 'attrId,dataFlag');
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data['attrVal'] = str_replace(',',',',$data['attrVal']);
|
||||
$data["dataFlag"] = 1;
|
||||
$data["attrSort"] = (int)$data["attrSort"];
|
||||
$goodsCats = model('GoodsCats')->getParentIs($data['goodsCatId']);
|
||||
krsort($goodsCats);
|
||||
if(!empty($goodsCats))$data['goodsCatPath'] = implode('_',$goodsCats)."_";
|
||||
$result = $this->validate('Attributes.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$attrId = input('post.attrId/d');
|
||||
$data = input('post.');
|
||||
$data["attrSort"] = (int)$data["attrSort"];
|
||||
WSTUnset($data, 'attrId,dataFlag,createTime');
|
||||
$data['attrVal'] = str_replace(',',',',$data['attrVal']);
|
||||
$goodsCats = model('GoodsCats')->getParentIs($data['goodsCatId']);
|
||||
krsort($goodsCats);
|
||||
if(!empty($goodsCats))$data['goodsCatPath'] = implode('_',$goodsCats)."_";
|
||||
$result = $this->validate('Attributes.edit')->allowField(true)->save($data,['attrId'=>$attrId]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$attrId = input('post.attrId/d');
|
||||
$data["dataFlag"] = -1;
|
||||
$result = $this->save($data,['attrId'=>$attrId]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 根据ID获取
|
||||
*/
|
||||
public function getById($attrId){
|
||||
$obj = null;
|
||||
if($attrId>0){
|
||||
$obj = $this->get(['attrId'=>$attrId,'dataFlag'=>1]);
|
||||
}else{
|
||||
$obj = self::getEModel("attributes");
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示隐藏
|
||||
*/
|
||||
public function setToggle(){
|
||||
$attrId = input('post.attrId/d');
|
||||
$isShow = input('post.isShow/d');
|
||||
$result = $this->where(['attrId'=>$attrId,"dataFlag"=>1])->setField("isShow", $isShow);
|
||||
if(false !== $result){
|
||||
return WSTReturn("设置成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$keyName = input('keyName');
|
||||
$goodsCatPath = input('goodsCatPath');
|
||||
$dbo = $this->field(true);
|
||||
$map = array();
|
||||
$map['dataFlag'] = 1;
|
||||
if($keyName!="")$map['attrName'] = ["like","%".$keyName."%"];
|
||||
if($goodsCatPath!='')$map['goodsCatPath'] = ["like",$goodsCatPath."_%"];
|
||||
$page = $dbo->field(true)->where($map)->paginate(input('limit/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
$goodsCatPath = $page['Rows'][$key]['goodsCatPath'];
|
||||
$page['Rows'][$key]['goodsCatNames'] = self::getGoodsCatNames($goodsCatPath,$keyCats);
|
||||
$page['Rows'][$key]['children'] = [];
|
||||
$page['Rows'][$key]['isextend'] = false;
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getGoodsCatNames($goodsCatPath, $keyCats){
|
||||
$catIds = explode("_",$goodsCatPath);
|
||||
$catNames = array();
|
||||
for($i=0,$k=count($catIds);$i<$k;$i++){
|
||||
if($catIds[$i]=='')continue;
|
||||
if(isset($keyCats[$catIds[$i]]))$catNames[] = $keyCats[$catIds[$i]];
|
||||
}
|
||||
return implode("→",$catNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function listQuery(){
|
||||
$catId = input("post.catId/d");
|
||||
$rs = $this->field("attrId id, attrId, catId, attrName name, '' goodsCatNames")->where(["dataFlag"=>1,"catId"=>$catId])->sort('attrSort asc,attrId asc')->select();
|
||||
return $rs;
|
||||
}
|
||||
}
|
67
hyhproject/admin/model/Banks.php
Executable file
67
hyhproject/admin/model/Banks.php
Executable file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 银行业务处理
|
||||
*/
|
||||
class Banks extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
return $this->where('dataFlag',1)->field('bankId,bankName')->order('bankId desc')->paginate(input('limit/d'));
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->get(['bankId'=>$id,'dataFlag'=>1]);
|
||||
}
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function listQuery(){
|
||||
return $this->where('dataFlag',1)->field('bankId,bankName')->select();
|
||||
}
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = ['bankName'=>input('post.bankName'),
|
||||
'createTime'=>date('Y-m-d H:i:s'),];
|
||||
$result = $this->validate('Banks.add')->allowField(['bankName','createTime'])->save($data);
|
||||
if(false !== $result){
|
||||
cache('WST_BANKS',null);
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$bankId = input('post.bankId/d',0);
|
||||
$result = $this->validate('Banks.edit')->allowField(['bankName'])->save(['bankName'=>input('post.bankName')],['bankId'=>$bankId]);
|
||||
|
||||
if(false !== $result){
|
||||
cache('WST_BANKS',null);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d',0);
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['bankId'=>$id]);
|
||||
if(false !== $result){
|
||||
cache('WST_BANKS',null);
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
24
hyhproject/admin/model/Base.php
Executable file
24
hyhproject/admin/model/Base.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 基础控业务处理
|
||||
*/
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
class Base extends Model {
|
||||
/**
|
||||
* 获取空模型
|
||||
*/
|
||||
public function getEModel($tables){
|
||||
$rs = Db::query('show columns FROM `'.config('database.prefix').$tables."`");
|
||||
$obj = [];
|
||||
if($rs){
|
||||
foreach($rs as $key => $v) {
|
||||
$obj[$v['Field']] = $v['Default'];
|
||||
if($v['Key'] == 'PRI')$obj[$v['Field']] = 0;
|
||||
}
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
}
|
407
hyhproject/admin/model/Brands.php
Executable file
407
hyhproject/admin/model/Brands.php
Executable file
@ -0,0 +1,407 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 品牌业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Brands extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$key = input('key');
|
||||
|
||||
$id = input('id/d');
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['b.dataFlag'] = 1;
|
||||
|
||||
if($key!='')$where['b.brandName'] = ['like','%'.$key.'%'];
|
||||
|
||||
if($id>0)$where['gcb.catId'] = $id;
|
||||
|
||||
$total = Db::name('brands')->alias('b');
|
||||
|
||||
if($id>0){
|
||||
|
||||
$total->join('__CAT_BRANDS__ gcb','b.brandId = gcb.brandId','left');
|
||||
|
||||
}
|
||||
|
||||
$page = $total->where($where)
|
||||
|
||||
->join('shops s','s.shopId=b.shopId','left')
|
||||
|
||||
->join('cat_brands cb','cb.brandId=b.brandId','left')
|
||||
|
||||
->join('goods_cats gc','gc.catId=cb.catId','left')
|
||||
|
||||
->where('b.dataFlag=1 and s.dataFlag=1 and s.shopStatus=1')
|
||||
|
||||
->field('b.brandId,b.brandName,b.brandImg,b.brandDesc,b.sortNo,s.shopName,gc.catName')
|
||||
|
||||
->order('b.brandId', 'desc')
|
||||
|
||||
->group('b.brandId')
|
||||
|
||||
->paginate(input('post.limit/d'))->toArray();
|
||||
|
||||
if(count($page['Rows'])>0){
|
||||
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
|
||||
$page['Rows'][$key]['brandDesc'] = strip_tags(htmlspecialchars_decode($v['brandDesc']));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getById($id){
|
||||
|
||||
$result = $this->where(['brandId'=>$id])->find();
|
||||
|
||||
//获取关联的分类
|
||||
|
||||
$result['catIds'] = Db::name('cat_brands')->where(['brandId'=>$id])->column('catId');
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$shop=db('shops')->where(['shopId'=>$data['shopId'],'dataFlag'=>1,'shopStatus'=>1])->find();
|
||||
|
||||
if(!$shop) return WSTReturn('无效的店铺,请重新输入');
|
||||
|
||||
WSTUnset($data,'brandId,dataFlag');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$idsStr = explode(',',$data['catId']);
|
||||
|
||||
if($idsStr!=''){
|
||||
|
||||
foreach ($idsStr as $v){
|
||||
|
||||
if((int)$v>0)$ids[] = (int)$v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('Brands.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $this->brandId, $data['brandImg']);
|
||||
|
||||
//商品描述图片
|
||||
|
||||
WSTEditorImageRocord(1, $this->brandId, '',$data['brandDesc']);
|
||||
|
||||
foreach ($ids as $key =>$v){
|
||||
|
||||
$d = array();
|
||||
|
||||
$d['catId'] = $v;
|
||||
|
||||
$d['brandId'] = $this->brandId;
|
||||
|
||||
Db::name('cat_brands')->insert($d);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$brandId = input('post.id/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$idsStr = explode(',',$data['catId']);
|
||||
|
||||
if($idsStr!=''){
|
||||
|
||||
foreach ($idsStr as $v){
|
||||
|
||||
if((int)$v>0)$ids[] = (int)$v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$filter = array();
|
||||
|
||||
//获取品牌的关联分类
|
||||
|
||||
$catBrands = Db::name('cat_brands')->where(['brandId'=>$brandId])->select();
|
||||
|
||||
foreach ($catBrands as $key =>$v){
|
||||
|
||||
if(!in_array($v['catId'],$ids))$filter[] = $v['catId'];
|
||||
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, $brandId, $data['brandImg'], 'brands', 'brandImg');
|
||||
|
||||
// 品牌描述图片
|
||||
|
||||
$desc = $this->where('brandId',$brandId)->value('brandDesc');
|
||||
|
||||
WSTEditorImageRocord(1, $brandId, $desc, $data['brandDesc']);
|
||||
|
||||
$result = $this->validate('Brands.edit')->allowField(['brandName','brandImg','brandDesc','sortNo','shopId'])->save(input('post.'),['brandId'=>$brandId]);//添加shopId mark cheng 20180207
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
foreach ($catBrands as $key =>$v){
|
||||
|
||||
Db::name('cat_brands')->where('brandId',$brandId)->delete();
|
||||
|
||||
}
|
||||
|
||||
foreach ($ids as $key =>$v){
|
||||
|
||||
$d = array();
|
||||
|
||||
$d['catId'] = $v;
|
||||
|
||||
$d['brandId'] = $brandId;
|
||||
|
||||
Db::name('cat_brands')->insert($d);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('修改失败',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where(['brandId'=>$id])->update($data);
|
||||
|
||||
WSTUnuseImage('brands','brandImg',$id);
|
||||
|
||||
// 品牌描述图片
|
||||
|
||||
$desc = $this->where('brandId',$id)->value('brandDesc');
|
||||
|
||||
WSTEditorImageRocord(1, $id, $desc,'');
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
//删除推荐品牌
|
||||
|
||||
Db::name('recommends')->where(['dataSrc'=>2,'dataId'=>$id])->delete();
|
||||
|
||||
//删除品牌和分类的关系
|
||||
|
||||
Db::name('cat_brands')->where(['brandId'=>$id])->delete();
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取品牌
|
||||
|
||||
*/
|
||||
|
||||
public function searchBrands(){
|
||||
|
||||
$goodsCatatId = (int)input('post.goodsCatId');
|
||||
|
||||
if($goodsCatatId<=0)return [];
|
||||
|
||||
$key = input('post.key');
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['dataFlag'] = 1;
|
||||
|
||||
$where['catId'] = $goodsCatatId;
|
||||
|
||||
if($key!='')$where['brandName'] = ['like','%'.$key.'%'];
|
||||
|
||||
return $this->alias('s')->join('__CAT_BRANDS__ cb','s.brandId=cb.brandId','inner')
|
||||
|
||||
->where($where)->field('brandName,s.brandId')->select();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 排序字母
|
||||
|
||||
*/
|
||||
|
||||
public function letterObtain(){
|
||||
|
||||
$areaName = input('code');
|
||||
|
||||
if($areaName =='')return WSTReturn("", 1);
|
||||
|
||||
$areaName = WSTGetFirstCharter($areaName);
|
||||
|
||||
if($areaName){
|
||||
|
||||
return WSTReturn($areaName, 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn("", 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 修改品牌排序
|
||||
|
||||
*/
|
||||
|
||||
public function changeSort(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$sortNo = (int)input('sortNo');
|
||||
|
||||
$result = $this->setField(['brandId'=>$id,'sortNo'=>$sortNo]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
158
hyhproject/admin/model/Carts.php
Executable file
158
hyhproject/admin/model/Carts.php
Executable file
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 商品类
|
||||
*/
|
||||
class Carts extends Base{
|
||||
/**
|
||||
* 购物车列表
|
||||
*/
|
||||
public function cartsByPage(){
|
||||
$shopName=input('shopName');
|
||||
$loginName=input('loginName');
|
||||
$goodsName=input('goodsName');
|
||||
$where = [];
|
||||
$where['g.goodsStatus'] = 1;
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['g.isSale'] = 1;
|
||||
if($shopName!="")$where['shopName']=['like',"%$shopName%"];
|
||||
if($loginName!="")$where['loginName']=['like',"%$loginName%"];
|
||||
if($goodsName!="")$where['goodsName']=['like',"%$goodsName%"];
|
||||
$result=$this->alias('c')
|
||||
->join('__USERS__ u','u.userId=c.userId','left')
|
||||
->join('__GOODS__ g','g.goodsId=c.goodsId','left')
|
||||
->join('__SHOPS__ s','s.shopId=g.shopId','left')
|
||||
->where($where)
|
||||
->field('u.loginName,shopPrice,sum(cartNum)cartNum,goodsName,shopName,goodsImg,goodsCatIdPath,g.goodsId')
|
||||
->order('cartNum desc')
|
||||
->group('u.userId,g.goodsId')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
foreach ($result['Rows'] as $key => $v){
|
||||
$result['Rows'][$key]['totalPrice']=$v['cartNum']*$v['shopPrice'];
|
||||
$result['Rows'][$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function getGoodsCatNames($goodsCatPath, $keyCats){
|
||||
$catIds = explode("_",$goodsCatPath);
|
||||
$catNames = array();
|
||||
for($i=0,$k=count($catIds);$i<$k;$i++){
|
||||
if($catIds[$i]=='')continue;
|
||||
if(isset($keyCats[$catIds[$i]]))$catNames[] = $keyCats[$catIds[$i]];
|
||||
}
|
||||
return implode("→",$catNames);
|
||||
}
|
||||
//导出数据
|
||||
public function toExport(){
|
||||
$name='购物车数据';
|
||||
$shopName=input('shopName');
|
||||
$loginName=input('loginName');
|
||||
$goodsName=input('goodsName');
|
||||
$where = [];
|
||||
$where['g.goodsStatus'] = 1;
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['g.isSale'] = 1;
|
||||
if($shopName!="")$where['shopName']=['like',"%$shopName%"];
|
||||
if($loginName!="")$where['loginName']=['like',"%$loginName%"];
|
||||
if($goodsName!="")$where['goodsName']=['like',"%$goodsName%"];
|
||||
$page=$this->alias('c')
|
||||
->join('__USERS__ u','u.userId=c.userId','left')
|
||||
->join('__GOODS__ g','g.goodsId=c.goodsId','left')
|
||||
->join('__SHOPS__ s','s.shopId=g.shopId','left')
|
||||
->where($where)
|
||||
->field('u.loginName,shopPrice,sum(cartNum)cartNum,goodsName,shopName,goodsImg,goodsCatIdPath,g.goodsId')
|
||||
->order('cartNum desc')
|
||||
->group('u.userId,g.goodsId')
|
||||
->select();
|
||||
// dump($page);
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
foreach ($page as $key => $v){
|
||||
$page[$key]['totalPrice']=$v['cartNum']*$v['shopPrice'];
|
||||
$page[$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(55);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(40);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A1', '用户名称')
|
||||
->setCellValue('B1', '商品名称')
|
||||
->setCellValue('C1', '购物车数量')
|
||||
->setCellValue('D1', '单品价格')
|
||||
->setCellValue('E1', '总价')
|
||||
->setCellValue('F1', '所属店铺')
|
||||
->setCellValue('G1', '所属分类');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:G1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['loginName'])
|
||||
->setCellValue('B'.$i, $page[$row]['goodsName'])
|
||||
->setCellValue('C'.$i, $page[$row]['cartNum'])
|
||||
->setCellValue('D'.$i, $page[$row]['shopPrice'])
|
||||
->setCellValue('E'.$i, $page[$row]['totalPrice'])
|
||||
->setCellValue('F'.$i, $page[$row]['shopName'])
|
||||
->setCellValue('G'.$i, $page[$row]['goodsCatName']);
|
||||
|
||||
}
|
||||
//输出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');
|
||||
}
|
||||
}
|
771
hyhproject/admin/model/CashDraws.php
Executable file
771
hyhproject/admin/model/CashDraws.php
Executable file
@ -0,0 +1,771 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
use think\Loader;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 提现分类业务处理
|
||||
|
||||
*/
|
||||
|
||||
class CashDraws extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$targetType = input('targetType',-1);
|
||||
|
||||
$cashNo = input('cashNo');
|
||||
|
||||
$cashSatus = input('cashSatus',-1);
|
||||
|
||||
$where = [];
|
||||
|
||||
if(in_array($targetType,[0,1]))$where['targetType'] = $targetType;
|
||||
|
||||
if(in_array($cashSatus,[0,1]))$where['cashSatus'] = $cashSatus;
|
||||
|
||||
if($cashNo!='')$where['cashNo'] = ['like','%'.$cashNo.'%'];
|
||||
|
||||
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$order = [];
|
||||
|
||||
if($sort!=''){
|
||||
|
||||
$sortArr = explode('.',$sort);
|
||||
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
|
||||
if($sortArr[0]=='cashNo'){
|
||||
|
||||
$order = $sortArr[0].'+0 '.$sortArr[1];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//mark by cheng 只显示超过一天的提现数据
|
||||
|
||||
//$page = $this->where($where)->whereTime('createTime','<=', date('Y-m-d'))->order($order)->order('createTime desc')->paginate(input('limit/d'))->toArray();
|
||||
$page = $this->where($where)->order($order)->order('createTime desc')->paginate(input('limit/d'))->toArray();
|
||||
|
||||
if(count($page['Rows'])>0){
|
||||
|
||||
$userIds = [];
|
||||
|
||||
$shopIds = [];
|
||||
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
|
||||
if($v['targetType']==0)$userIds[] = $v['targetId'];
|
||||
|
||||
if($v['targetType']==1)$shopIds[] = $v['targetId'];
|
||||
|
||||
}
|
||||
|
||||
$userMap = [];
|
||||
|
||||
if(count($userIds)>0){
|
||||
|
||||
$user = Db::name('users')->where(['userId'=>['in',$userIds]])->field('userId,loginName,userName')->select();
|
||||
|
||||
foreach ($user as $key => $v) {
|
||||
|
||||
$userMap["0_".$v['userId']] = $v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(count($shopIds)>0){
|
||||
|
||||
$user = Db::name('shops')->alias('s')
|
||||
|
||||
->join('__USERS__ u','u.userId=s.userId')
|
||||
|
||||
->where(['shopId'=>['in',$shopIds]])
|
||||
|
||||
->field('s.shopId,u.loginName,s.shopName as userName')
|
||||
|
||||
->select();
|
||||
|
||||
foreach ($user as $key => $v) {
|
||||
|
||||
$userMap["1_".$v['shopId']] = $v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
|
||||
$page['Rows'][$key]['loginName'] = $userMap[$v['targetType']."_".$v['targetId']]['loginName'];
|
||||
|
||||
$page['Rows'][$key]['userName'] = $userMap[$v['targetType']."_".$v['targetId']]['userName'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
/**
|
||||
* 查看报表
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function viewReport($date,$isSave=0){
|
||||
|
||||
$orders['list'] = Db::name('orders')
|
||||
->where('orderStatus=2 AND dataFlag=1')
|
||||
->whereTime('receiveTime',[$date,date('Y-m-d',strtotime('+1 day',strtotime($date)))])
|
||||
->field('orderId,shopId,userId,productTaxFee,productHandlingFee,couponsHandlingFee,couponsTaxFee,realTotalMoney,receiveTime,payable')
|
||||
->select();
|
||||
//dump(Db::getlastsql());
|
||||
$discountMoney = 0;
|
||||
$m = Model('common/Table');
|
||||
$orders['allPaySum']=0;//消费总额
|
||||
$orders['coupousEarningsSum'] = 0;//优惠款总收益
|
||||
$orders['hasVouchersEearningsSum'] = 0;//已获券总收益
|
||||
$orders['taxFeeSum'] = 0;//税费总收益
|
||||
$orders['collectionPaySum']=0;//公司需付商家,即商家已获旺旺券总额
|
||||
$orders['collectionGatheringSum']=0;//商家需付公司总额
|
||||
$orders['collection']=[];
|
||||
$orders['yesterdayMoney']=0;
|
||||
$orders['todayMoney']=0;
|
||||
$m->setTable('log_day_money');
|
||||
$orders['yesterdayMoney'] = $m->getSum('setTime < '.strtotime($date),'money');
|
||||
foreach ($orders['list'] as &$v) {
|
||||
$orders['allPaySum'] += $v['realTotalMoney'];
|
||||
$m->setTable('order_goods');
|
||||
$orderGoodsList = $m->getList(['orderId'=>$v['orderId']],'goodsPrice,goodsNum,freight,discountRate');
|
||||
$discountMoney = 0;//优惠款
|
||||
foreach ($orderGoodsList as &$val) {
|
||||
$discountMoney += ($val['goodsPrice']*$val['goodsNum'] + $val['freight']) * ($val['discountRate']*0.01);//优惠款
|
||||
}
|
||||
$v['discountMoney'] = $discountMoney;
|
||||
$v['coupousEarnings'] = $discountMoney * 0.1;//优惠款收益
|
||||
$orders['coupousEarningsSum']+=$v['coupousEarnings'];
|
||||
|
||||
$v['hasVouchersEearnings'] = $v['productHandlingFee'] + $v['couponsHandlingFee'];//已获券收益
|
||||
$orders['hasVouchersEearningsSum']+=$v['hasVouchersEearnings'];
|
||||
|
||||
$v['taxFee'] = $v['productTaxFee']+$v['couponsTaxFee'];//税费
|
||||
$orders['taxFeeSum']+=$v['taxFee'];
|
||||
|
||||
$m->setTable('shops');
|
||||
$shopUserId = $m->getField(['shopId'=>$v['shopId']],'userId');
|
||||
$m->setTable('users');
|
||||
$v['loginName'] = $m->getField(['userId'=>$v['userId']],'loginName');
|
||||
$v['shopLoginName'] = $m->getField(['userId'=>$shopUserId],'loginName');
|
||||
if(!isset($orders['collection'][$shopUserId]['gathering'])) $orders['collection'][$shopUserId]['gathering']=0;
|
||||
if(!isset($orders['collection'][$shopUserId]['pay'])) $orders['collection'][$shopUserId]['pay']=0;
|
||||
$orders['collection'][$shopUserId]['shopLoginName'] = $v['shopLoginName'];
|
||||
|
||||
if($v['payable']>0){
|
||||
//公司需付商家,即提现
|
||||
$orders['collection'][$shopUserId]['pay']+=$v['payable'];//代付款
|
||||
$orders['collectionPaySum'] += $v['payable'];
|
||||
}else{
|
||||
//商家需付公司
|
||||
$orders['collection'][$shopUserId]['gathering'] += abs($v['payable']);//代收款
|
||||
$orders['collectionGatheringSum'] += abs($v['payable']);
|
||||
}
|
||||
}
|
||||
$allMoney = $orders['collectionGatheringSum']-($orders['coupousEarningsSum']+$orders['hasVouchersEearningsSum']+$orders['taxFeeSum']+$orders['collectionPaySum']);
|
||||
$orders['todayMoney'] = $orders['yesterdayMoney'] + $allMoney;
|
||||
if(1 == $isSave && $allMoney != 0){
|
||||
$data['money'] = $allMoney;//充值/扣除数量
|
||||
if($allMoney >= 0 ){
|
||||
$reTypeName = '充值';
|
||||
}else{
|
||||
$reTypeName = '扣除';
|
||||
}
|
||||
$data['adminId'] = 0;
|
||||
$data['logContent'] = '系统'.$reTypeName;
|
||||
$data['setTime'] = time();
|
||||
$data['createTime'] = time();
|
||||
$m->setTable('log_day_money');
|
||||
$m->insertInfo($data);
|
||||
echo $allMoney;
|
||||
return true;
|
||||
}
|
||||
//$orders['collection'] = Db::name('orders')->where();
|
||||
return $orders;
|
||||
}
|
||||
/**
|
||||
|
||||
* 获取提现详情
|
||||
|
||||
*/
|
||||
|
||||
public function getById(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$rs = $this->get($id);
|
||||
|
||||
$user = [];
|
||||
|
||||
if($rs['targetType']==1){
|
||||
|
||||
$user = Db::name('shops')->alias('s')
|
||||
|
||||
->join('__USERS__ u','u.userId=s.userId')
|
||||
|
||||
->where('shopId',$rs['targetId'])
|
||||
|
||||
->field('s.shopId,u.loginName,s.shopName as userName')
|
||||
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$user = Db::name('users')->where('userId',$rs['targetId'])->field('userId,loginName,userName')->find();
|
||||
|
||||
}
|
||||
|
||||
$rs['userName'] = $user['userName'];
|
||||
|
||||
$rs['loginName'] = $user['loginName'];
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 处理提现成功
|
||||
|
||||
*/
|
||||
|
||||
public function handle(){
|
||||
|
||||
$id = (int)input('cashId');
|
||||
|
||||
$cash = $this->get($id);
|
||||
|
||||
if(empty($cash))return WSTReturn('无效的提现申请记录');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
|
||||
|
||||
if($cash->targetType==0){
|
||||
|
||||
$user = model('users')->get($cash->targetId);
|
||||
|
||||
// if($user->lockMoney<$cash->money)return WSTReturn('操作失败,被冻结的金额小于提现金额');
|
||||
|
||||
// $user->lockMoney = $user->lockMoney-$cash->money;
|
||||
|
||||
// $user->save();
|
||||
|
||||
$targetId = $user->userId;
|
||||
|
||||
}else{
|
||||
|
||||
$shop = model('shops')->get($cash->targetId);
|
||||
|
||||
// if($shop->lockMoney<$cash->money)return WSTReturn('操作失败,被冻结的金额小于提现金额');
|
||||
|
||||
// $shop->lockMoney = $shop->lockMoney-$cash->money;
|
||||
|
||||
// $shop->save();
|
||||
|
||||
$targetId = $shop->userId;
|
||||
|
||||
}
|
||||
|
||||
$cash->cashSatus = 1;
|
||||
|
||||
$cash->cashRemarks = input('cashRemarks');
|
||||
|
||||
$result = $cash->save();
|
||||
|
||||
|
||||
|
||||
if(false != $result){
|
||||
|
||||
//创建一条流水记录
|
||||
|
||||
$lm = [];
|
||||
|
||||
$lm['targetType'] = $cash->targetType;
|
||||
|
||||
$lm['targetId'] = $targetId;
|
||||
|
||||
$lm['dataId'] = $id;
|
||||
|
||||
$lm['dataSrc'] = 3;
|
||||
|
||||
$lm['remark'] = '提现申请单【'.$cash->cashNo.'】申请提现¥'.$cash->money.'。'.(($cash->cashRemarks!='')?"【操作备注】:".$cash->cashRemarks:'');
|
||||
|
||||
$lm['moneyType'] = 0;
|
||||
|
||||
$lm['money'] = $cash->money;
|
||||
|
||||
$lm['payType'] = 0;
|
||||
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
model('LogMoneys')->insert($lm);
|
||||
|
||||
//发送信息信息
|
||||
|
||||
$tpl = WSTMsgTemplates('CASH_DRAW_SUCCESS');
|
||||
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
|
||||
$find = ['${CASH_NO}'];
|
||||
|
||||
$replace = [$cash->cashNo];
|
||||
|
||||
WSTSendMsg($targetId,str_replace($find,$replace,$tpl['tplContent']),['from'=>5,'dataId'=>$id]);
|
||||
|
||||
}
|
||||
|
||||
//微信消息
|
||||
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
|
||||
$params = [];
|
||||
|
||||
$params['CASH_NO'] = $cash->cashNo;
|
||||
|
||||
$params['MONEY'] = $cash->money;
|
||||
|
||||
$params['CASH_TYPE'] = '银行提现';
|
||||
|
||||
$params['CASH_TIME'] = $cash['createTime'];
|
||||
|
||||
$params['CASH_RESULT'] = "审核通过。【备注:".((input('cashRemarks')=='')?"无":input('cashRemarks'))."】";
|
||||
|
||||
$params['EXAMINE_TIME'] = date('Y-m-d H:i:s');
|
||||
|
||||
WSTWxMessage(['CODE'=>'WX_CASH_DRAW_SUCCESS','userId'=>$targetId,'params'=>$params]);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功!',1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('操作失败!',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 处理提现失败
|
||||
|
||||
*/
|
||||
|
||||
public function handleFail(){
|
||||
|
||||
$id = (int)input('cashId');
|
||||
|
||||
$cash = $this->get($id);
|
||||
|
||||
if(empty($cash))return WSTReturn('无效的提现申请记录');
|
||||
|
||||
if(input('cashRemarks')=='')return WSTReturn('请输入提现失败原因');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
|
||||
|
||||
if($cash->targetType==0){
|
||||
|
||||
$user = model('users')->get($cash->targetId);
|
||||
|
||||
if($user->lockMoney<$cash->money)return WSTReturn('操作失败,无效的冻结的金额');
|
||||
|
||||
$user->userMoney = $user->userMoney + $cash->money;
|
||||
|
||||
$user->lockMoney = $user->lockMoney-$cash->money;
|
||||
|
||||
$user->save();
|
||||
|
||||
$targetId = $user->userId;
|
||||
|
||||
}else{
|
||||
|
||||
$shop = model('shops')->get($cash->targetId);
|
||||
|
||||
if($shop->lockMoney<$cash->money)return WSTReturn('操作失败,无效的冻结的金额');
|
||||
|
||||
$shop->shopMoney = $shop->shopMoney + $cash->money;
|
||||
|
||||
$shop->lockMoney = $shop->lockMoney-$cash->money;
|
||||
|
||||
$shop->save();
|
||||
|
||||
$targetId = $shop->userId;
|
||||
|
||||
}
|
||||
|
||||
$cash->cashSatus = -1;
|
||||
|
||||
$cash->cashRemarks = input('cashRemarks');
|
||||
|
||||
$result = $cash->save();
|
||||
|
||||
|
||||
|
||||
if(false != $result){
|
||||
|
||||
//发送信息信息
|
||||
|
||||
$tpl = WSTMsgTemplates('CASH_DRAW_FAIL');
|
||||
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
|
||||
$find = ['${CASH_NO}','${CASH_RESULT}'];
|
||||
|
||||
$replace = [$cash->cashNo,input('cashRemarks')];
|
||||
|
||||
WSTSendMsg($targetId,str_replace($find,$replace,$tpl['tplContent']),['from'=>5,'dataId'=>$id]);
|
||||
|
||||
}
|
||||
|
||||
//微信消息
|
||||
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
|
||||
$params = [];
|
||||
|
||||
$params['CASH_NO'] = $cash->cashNo;
|
||||
|
||||
$params['MONEY'] = $cash->money;
|
||||
|
||||
$params['CASH_TYPE'] = '银行提现';
|
||||
|
||||
$params['CASH_TIME'] = $cash['createTime'];
|
||||
|
||||
$params['CASH_RESULT'] = "审核不通过。【备注:".((input('cashRemarks')=='')?"无":input('cashRemarks'))."】";
|
||||
|
||||
$params['EXAMINE_TIME'] = date('Y-m-d H:i:s');
|
||||
|
||||
WSTWxMessage(['CODE'=>'WX_CASH_DRAW_FAIL','userId'=>$targetId,'params'=>$params]);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功!',1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('操作失败!',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 导出提现申请
|
||||
|
||||
*/
|
||||
|
||||
public function toExport(){
|
||||
|
||||
$name='提现申请表';
|
||||
|
||||
$targetType = input('targetType',-1);
|
||||
|
||||
$cashNo = input('cashNo');
|
||||
|
||||
$cashSatus = input('cashSatus',-1);
|
||||
|
||||
$where = [];
|
||||
|
||||
if(in_array($targetType,[0,1]))$where['targetType'] = $targetType;
|
||||
|
||||
if(in_array($cashSatus,[0,1]))$where['cashSatus'] = $cashSatus;
|
||||
|
||||
if($cashNo!='')$where['cashNo'] = ['like','%'.$cashNo.'%'];
|
||||
|
||||
// 排序
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$order = [];
|
||||
|
||||
if($sort!=''){
|
||||
|
||||
$sortArr = explode('.',$sort);
|
||||
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
|
||||
if($sortArr[0]=='cashNo'){
|
||||
|
||||
$order = $sortArr[0].'+0 '.$sortArr[1];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$page = $this->where($where)->order($order)->order('createTime desc')->select();
|
||||
|
||||
if(count($page)>0){
|
||||
|
||||
$userIds = [];
|
||||
|
||||
$shopIds = [];
|
||||
|
||||
foreach ($page as $key => $v) {
|
||||
|
||||
if($v['targetType']==0)$userIds[] = $v['targetId'];
|
||||
|
||||
if($v['targetType']==1)$shopIds[] = $v['targetId'];
|
||||
|
||||
}
|
||||
|
||||
$userMap = [];
|
||||
|
||||
if(count($userIds)>0){
|
||||
|
||||
$user = Db::name('users')->where(['userId'=>['in',$userIds]])->field('userId,loginName,userName')->select();
|
||||
|
||||
foreach ($user as $key => $v) {
|
||||
|
||||
$userMap["0_".$v['userId']] = $v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(count($shopIds)>0){
|
||||
|
||||
$user = Db::name('shops')->alias('s')
|
||||
|
||||
->join('__USERS__ u','u.userId=s.userId')
|
||||
|
||||
->where(['shopId'=>['in',$shopIds]])
|
||||
|
||||
->field('s.shopId,u.loginName,s.shopName as userName')
|
||||
|
||||
->select();
|
||||
|
||||
foreach ($user as $key => $v) {
|
||||
|
||||
$userMap["1_".$v['shopId']] = $v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ($page as $key => $v) {
|
||||
|
||||
$page[$key]['userType'] = ($v['targetType']==1)?"【商家】":"【会员】";
|
||||
|
||||
$page[$key]['loginName'] = $userMap[$v['targetType']."_".$v['targetId']]['loginName'];
|
||||
|
||||
$page[$key]['userName'] = $userMap[$v['targetType']."_".$v['targetId']]['userName'];
|
||||
|
||||
$page[$key]['cashSatus'] = ($page[$key]['cashSatus']==1)?'提现成功':(($page[$key]['cashSatus']==-1)?'提现失败':'待处理');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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(12);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', '提现单号')
|
||||
|
||||
->setCellValue('B1', '会员类型')->setCellValue('C1', '会员名称')
|
||||
|
||||
->setCellValue('D1', '提现银行')->setCellValue('E1', '银行卡号')
|
||||
|
||||
->setCellValue('F1', '持卡人')->setCellValue('G1', '提现金额')
|
||||
|
||||
->setCellValue('H1', '提现时间')->setCellValue('I1', '状态');
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->applyFromArray($styleArray);
|
||||
|
||||
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
|
||||
$i = $row+2;
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $page[$row]['cashNo'])
|
||||
|
||||
->setCellValue('B'.$i, $page[$row]['userType'])->setCellValue('C'.$i, $page[$row]['userName'].'('.$page[$row]['loginName'].')' )
|
||||
|
||||
->setCellValue('D'.$i, $page[$row]['accTargetName'])->setCellValue('E'.$i, $page[$row]['accNo'])
|
||||
|
||||
->setCellValue('F'.$i, $page[$row]['accUser'])->setCellValue('G'.$i, '¥'.$page[$row]['money'])
|
||||
|
||||
->setCellValue('H'.$i, $page[$row]['createTime'])->setCellValue('I'.$i, $page[$row]['cashSatus']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//输出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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
60
hyhproject/admin/model/ChargeItems.php
Executable file
60
hyhproject/admin/model/ChargeItems.php
Executable file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 充值项业务处理
|
||||
*/
|
||||
class ChargeItems extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$where = [];
|
||||
$where['dataFlag'] = 1;
|
||||
return $this->where($where)->field(true)->order('itemSort asc,id asc')->paginate(input('limit/d'));
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->get(['id'=>$id,'dataFlag'=>1]);
|
||||
}
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
$data["createTime"] = date("Y-m-d H:i:s");
|
||||
WSTUnset($data,'positionId');
|
||||
$result = $this->validate('ChargeItems.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = (int)input('post.id');
|
||||
$result = $this->validate('ChargeItems.edit')->allowField(true)->save(input('post.'),['id'=>$Id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = (int)input('post.id/d');
|
||||
$result = $this->setField(['id'=>$id,'dataFlag'=>-1]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
1368
hyhproject/admin/model/CronJobs.php
Executable file
1368
hyhproject/admin/model/CronJobs.php
Executable file
File diff suppressed because it is too large
Load Diff
166
hyhproject/admin/model/DataCats.php
Executable file
166
hyhproject/admin/model/DataCats.php
Executable file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 系统数据分类业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class DataCats extends Base{
|
||||
|
||||
protected $insert = ['dataFlag'=>1];
|
||||
|
||||
/**
|
||||
|
||||
* 获取数据分类列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery($catId = -1){
|
||||
|
||||
if($catId==-1)return ['id'=>0,'name'=>'系统数据','isParent'=>true,'open'=>true];
|
||||
|
||||
$rs = Db::name('data_cats')->where(['dataFlag'=>1])->field('catId id,catName name')->select();
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取数据分类
|
||||
|
||||
*/
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['dataFlag'=>1,'catId'=>$id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增数据分类
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
// 验证数据代码
|
||||
|
||||
$catCode = input('catCode');
|
||||
|
||||
$hasCode = $this->where(['catCode'=>$catCode,'dataFlag'=>1])->find();
|
||||
|
||||
if(!empty($hasCode))return WSTReturn('数据分类代码已存在');
|
||||
|
||||
// 执行新增
|
||||
|
||||
$result = $this->validate('DataCats.add')->save(input('post.'));
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑数据分类
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$id = input('post.catId/d');
|
||||
|
||||
|
||||
|
||||
// 验证数据代码
|
||||
|
||||
$catCode = input('catCode');
|
||||
|
||||
$hasCode = $this->where(['catCode'=>$catCode,'dataFlag'=>1,'catId'=>['<>',$id]])->find();
|
||||
|
||||
if(!empty($hasCode))return WSTReturn('数据分类代码已存在');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$result = $this->validate('DataCats.edit')->allowField(['catName','catCode'])->save(input('post.'),['catId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除数据分类
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->update($data,['catId'=>$id]);// 删除该数据分类
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
// 删除该数据分类下所有子数据
|
||||
|
||||
Db::name('datas')->where(['catId'=>$id])->setField('dataFlag',-1);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn("删除失败",-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
79
hyhproject/admin/model/Datas.php
Executable file
79
hyhproject/admin/model/Datas.php
Executable file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 经营范围业务处理
|
||||
*/
|
||||
use think\Db;
|
||||
class Datas extends Base{
|
||||
protected $insert = ['dataFlag'=>1];
|
||||
/**
|
||||
* 获取指定分类的列表
|
||||
*/
|
||||
public function listQuery($catId){
|
||||
return Db::name('datas')->where('catId',$catId)->field('dataName,dataVal')->select();
|
||||
}
|
||||
/**
|
||||
* 根据catId获取子数据
|
||||
*/
|
||||
public function childQuery(){
|
||||
$catId = (int)input('post.id');
|
||||
return $this->where(['dataFlag'=>1,'catId'=>$catId])->paginate(input('limit/d'));
|
||||
}
|
||||
/**
|
||||
* 获取菜单列表
|
||||
*/
|
||||
public function dataQuery($catId = -1){
|
||||
if($catId==-1)return ['id'=>0,'name'=>'系统数据','isParent'=>true,'open'=>true];
|
||||
$rs = Db::name('data_cats')->where(['dataFlag'=>1])->field('catId id,catName name')->select();
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 获取菜单
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['dataFlag'=>1,'id'=>$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
*/
|
||||
public function add(){
|
||||
$result = $this->validate('Datas.add')->save(input('post.'));
|
||||
if(false !== $result){
|
||||
cache('WST_DATAS',null);
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑菜单
|
||||
*/
|
||||
public function edit(){
|
||||
$id = input('post.id/d');
|
||||
$result = $this->validate('Datas.edit')->allowField(['dataName','dataVal','dataSort'])->save(input('post.'),['id'=>$id]);
|
||||
if(false !== $result){
|
||||
cache('WST_DATAS',null);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['id'=>$id]);
|
||||
if(false !== $result){
|
||||
cache('WST_DATAS',null);
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
163
hyhproject/admin/model/EctDay.php
Executable file
163
hyhproject/admin/model/EctDay.php
Executable file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 提现分类业务处理
|
||||
*/
|
||||
class EctDay extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$loginName = input('loginName');
|
||||
$where = [];
|
||||
if($loginName!='')$where['b.loginName'] = ['like','%'.$loginName.'%'];
|
||||
if($startDate && $endDate){
|
||||
$where['a.giveTime'] =['between',[strtotime($startDate.' 00:00:00'),strtotime($endDate.' 23:59:59')]];
|
||||
}elseif($startDate){
|
||||
$where['a.giveTime'] = [">=",strtotime($startDate)];
|
||||
}elseif($endDate){
|
||||
$where['a.giveTime'] = ["<=",strtotime($endDate)];
|
||||
}
|
||||
//mark by cheng 只显示超过一天的提现数据
|
||||
$page = Db::name('user_everyday_ect_log')->alias('a')
|
||||
->join('users b','b.userId=a.userId','left')
|
||||
->where($where)
|
||||
->order('a.giveTime desc')
|
||||
->field('a.ectNum,giveTime,b.loginName')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 获取提现详情
|
||||
*/
|
||||
public function getById(){
|
||||
$id = (int)input('id');
|
||||
$rs = $this->get($id);
|
||||
$user = [];
|
||||
if($rs['targetType']==1){
|
||||
$user = Db::name('shops')->alias('s')
|
||||
->join('__USERS__ u','u.userId=s.userId')
|
||||
->where('shopId',$rs['targetId'])
|
||||
->field('s.shopId,u.loginName,s.shopName as userName')
|
||||
->find();
|
||||
|
||||
}else{
|
||||
$user = Db::name('users')->where('userId',$rs['targetId'])->field('userId,loginName,userName')->find();
|
||||
}
|
||||
$rs['userName'] = $user['userName'];
|
||||
$rs['loginName'] = $user['loginName'];
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 导出提现申请
|
||||
*/
|
||||
public function toExport(){
|
||||
$name='ECT提现管理表';
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$ectNo = input('ectNo');
|
||||
$where = [];
|
||||
if($ectNo!='')$where['ectNum'] = ['like','%'.$ectNo.'%'];
|
||||
if($startDate && $endDate){
|
||||
$where['a.giveTime'] =['between',[strtotime($startDate.' 00:00:00'),strtotime($endDate.' 23:59:59')]];
|
||||
}elseif($startDate){
|
||||
$where['a.giveTime'] = [">=",strtotime($startDate)];
|
||||
}elseif($endDate){
|
||||
$where['a.giveTime'] = ["<=",strtotime($endDate)];
|
||||
}
|
||||
//mark by cheng 只显示超过一天的提现数据
|
||||
$page = Db::name('user_ect_cash_log')->alias('a')
|
||||
->join('users b','b.userId=a.userId','left')
|
||||
->where($where)
|
||||
->order('a.giveTime desc')
|
||||
->field('a.giveTime,ectNum,b.loginName')
|
||||
->select();
|
||||
|
||||
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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
|
||||
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'ECT交易ID')
|
||||
->setCellValue('B1', '会员名称')
|
||||
->setCellValue('C1', 'ECT发送方')
|
||||
->setCellValue('D1', 'ECT接收方')
|
||||
->setCellValue('E1', '备注')
|
||||
->setCellValue('F1', 'ECT提现数量')
|
||||
->setCellValue('G1', '创建时间');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $page[$row]['transactionId'])
|
||||
->setCellValue('B'.$i, $page[$row]['loginName'])
|
||||
->setCellValue('C'.$i, $page[$row]['fromAccount'])
|
||||
->setCellValue('D'.$i, $page[$row]['toAccount'])
|
||||
->setCellValue('E'.$i, $page[$row]['dataRemarks'])
|
||||
->setCellValue('F'.$i, $page[$row]['ectNum'])
|
||||
->setCellValue('G'.$i, $page[$row]['createTime']);
|
||||
}
|
||||
|
||||
//输出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');
|
||||
}
|
||||
}
|
71
hyhproject/admin/model/EctDeal.php
Executable file
71
hyhproject/admin/model/EctDeal.php
Executable file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 提现分类业务处理
|
||||
*/
|
||||
class EctDeal extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$loginName = trim(input('loginName'));
|
||||
$where = [];
|
||||
|
||||
if($loginName!=''){
|
||||
$userInfo = getUserByName($loginName);
|
||||
if(!$userInfo) return [];
|
||||
$where['b.userId'] = $userInfo['userId'];
|
||||
}
|
||||
$sort = input('sort');
|
||||
$order = [];
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
if($sortArr[0]=='ectNo'){
|
||||
$order = $sortArr[0].'+0 '.$sortArr[1];
|
||||
}
|
||||
}else{
|
||||
$order = ('ectId DESC');
|
||||
}
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$startDate=strtotime($startDate.' 00:00:00');
|
||||
$endDate=strtotime($endDate.' 23:59:59');
|
||||
$where['a.createTime'] = ['between',[$startDate,$endDate]];
|
||||
}else if($startDate!=''){
|
||||
$startDate=strtotime($startDate.' 00:00:00');
|
||||
$where['a.createTime'] = ['>=',$startDate];
|
||||
}else if($endDate!=''){
|
||||
$endDate=strtotime($endDate.' 23:59:59');
|
||||
$where['a.createTime'] = ['<=',$endDate];
|
||||
}
|
||||
$page = Db::name('user_ect_log')->alias('a')->join('users b','b.userId=a.userId','inner')
|
||||
->where($where)
|
||||
->order($order)
|
||||
->field('a.ectId,dataSrc,dataRemarks,a.createTime,ectNum,b.loginName,a.userId')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
if($loginName!=''){
|
||||
foreach ($page['Rows'] as $key => $value) {
|
||||
$page['Rows'][$key]['sumEct']=db('user_ect_log')->where(['userId'=>$value['userId'],'dataSrc'=>12])->sum('ectNum');
|
||||
$page['Rows'][$key]['sumCashEct']=db('user_ect_cash_log')->where(['userId'=>$value['userId'],'status'=>1])->sum('ectNum');
|
||||
$page['Rows'][$key]['sumCashChong']=db('user_ect_log')->where(['userId'=>$value['userId'],'dataSrc'=>14])->sum('ectNum');
|
||||
}
|
||||
}
|
||||
if(count($page['Rows'])>0){
|
||||
$userIds = [];
|
||||
$shopIds = [];
|
||||
$userMap = [];
|
||||
if(count($userIds)>0){
|
||||
$user = Db::name('users')->where(['userId'=>['in',$userIds]])->field('userId,loginName,userName')->select();
|
||||
foreach ($user as $key => $v) {
|
||||
$userMap["0_".$v['userId']] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
}
|
400
hyhproject/admin/model/EctTarget.php
Executable file
400
hyhproject/admin/model/EctTarget.php
Executable file
@ -0,0 +1,400 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
use think\Loader;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 提现分类业务处理
|
||||
|
||||
*/
|
||||
|
||||
class EctTarget extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$startDate = input('startDate');
|
||||
|
||||
$endDate = input('endDate');
|
||||
|
||||
$ectNo = input('ectNo');
|
||||
|
||||
$loginName = input('loginName');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($ectNo!='')$where['ectNum'] = ['like','%'.$ectNo.'%'];
|
||||
|
||||
if($loginName!='')$where['b.loginName'] = ['like','%'.$loginName.'%'];
|
||||
|
||||
if($startDate && $endDate){
|
||||
|
||||
$where['a.createTime'] =['between',[strtotime($startDate.' 00:00:00'),strtotime($endDate.' 23:59:59')]];
|
||||
|
||||
}elseif($startDate){
|
||||
|
||||
$where['a.createTime'] = [">=",strtotime($startDate)];
|
||||
|
||||
}elseif($endDate){
|
||||
|
||||
$where['a.createTime'] = ["<=",strtotime($endDate)];
|
||||
|
||||
}
|
||||
|
||||
//mark by cheng 只显示超过一天的提现数据
|
||||
|
||||
$page = Db::name('user_ect_cash_log')->alias('a')
|
||||
|
||||
->join('users b','b.userId=a.userId','left')
|
||||
|
||||
->where($where)
|
||||
|
||||
->order('a.status asc,a.id desc')
|
||||
|
||||
->field('a.transactionId,fromAccount,toAccount,dataRemarks,a.createTime,ectNum,b.loginName,a.userId,a.status,a.id')
|
||||
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
|
||||
if($loginName!=''){
|
||||
|
||||
foreach ($page['Rows'] as $key => $value) {
|
||||
|
||||
$page['Rows'][$key]['sumEct']=db('user_ect_cash_log')->where(['userId'=>$value['userId'],'status'=>1])->sum('ectNum');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
//根据ID获取提现详情
|
||||
|
||||
public function toHandle(){
|
||||
|
||||
$id=input('id');
|
||||
|
||||
$result=Db::name('user_ect_cash_log')->alias('a')
|
||||
|
||||
->join('users b','b.userId=a.userId','left')
|
||||
|
||||
->where('id',$id)
|
||||
|
||||
->order('a.createTime desc')
|
||||
|
||||
->field('a.transactionId,fromAccount,toAccount,dataRemarks,a.createTime,ectNum,b.loginName,a.userId,a.status,a.id')
|
||||
|
||||
->find();
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
//对审核结果进行操作
|
||||
|
||||
public function ectTarget(){
|
||||
|
||||
$id=input('id');
|
||||
|
||||
$status=input('status');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = db('user_ect_cash_log')->where('id',$id)->update(['status'=>$status]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
//标记删除购物车
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('修改失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取提现详情
|
||||
|
||||
*/
|
||||
|
||||
public function getById(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$rs = $this->get($id);
|
||||
|
||||
$user = [];
|
||||
|
||||
if($rs['targetType']==1){
|
||||
|
||||
$user = Db::name('shops')->alias('s')
|
||||
|
||||
->join('__USERS__ u','u.userId=s.userId')
|
||||
|
||||
->where('shopId',$rs['targetId'])
|
||||
|
||||
->field('s.shopId,u.loginName,s.shopName as userName')
|
||||
|
||||
->find();
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$user = Db::name('users')->where('userId',$rs['targetId'])->field('userId,loginName,userName')->find();
|
||||
|
||||
}
|
||||
|
||||
$rs['userName'] = $user['userName'];
|
||||
|
||||
$rs['loginName'] = $user['loginName'];
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 导出提现申请
|
||||
|
||||
*/
|
||||
|
||||
public function toExport(){
|
||||
|
||||
$name='ECT提现管理表';
|
||||
|
||||
$startDate = input('startDate');
|
||||
|
||||
$endDate = input('endDate');
|
||||
|
||||
$ectNo = input('ectNo');
|
||||
|
||||
$loginName = input('loginName');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($ectNo!='')$where['ectNum'] = ['like','%'.$ectNo.'%'];
|
||||
|
||||
if($loginName!='')$where['b.loginName'] = ['like','%'.$loginName.'%'];
|
||||
|
||||
if($startDate && $endDate){
|
||||
|
||||
$where['a.createTime'] =['between',[strtotime($startDate.' 00:00:00'),strtotime($endDate.' 23:59:59')]];
|
||||
|
||||
}elseif($startDate){
|
||||
|
||||
$where['a.createTime'] = [">=",strtotime($startDate)];
|
||||
|
||||
}elseif($endDate){
|
||||
|
||||
$where['a.createTime'] = ["<=",strtotime($endDate)];
|
||||
|
||||
}
|
||||
|
||||
//mark by cheng 只显示超过一天的提现数据
|
||||
|
||||
$page = Db::name('user_ect_cash_log')->alias('a')
|
||||
|
||||
->join('users b','b.userId=a.userId','left')
|
||||
|
||||
->where($where)
|
||||
|
||||
->order('a.createTime desc')
|
||||
|
||||
->field('a.transactionId,fromAccount,toAccount,dataRemarks,a.createTime,from_unixtime(a.createTime) dateTime, ectNum,b.loginName,a.status')
|
||||
|
||||
->select();
|
||||
|
||||
|
||||
|
||||
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(25);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'ECT交易ID')
|
||||
|
||||
->setCellValue('B1', '会员名称')
|
||||
|
||||
->setCellValue('C1', 'ECT发送方')
|
||||
|
||||
->setCellValue('D1', 'ECT接收方')
|
||||
|
||||
->setCellValue('E1', '备注')
|
||||
|
||||
->setCellValue('F1', 'ECT提现数量')
|
||||
|
||||
->setCellValue('G1', '创建时间')
|
||||
|
||||
->setCellValue('H1', '状态(0.未审核1.同意2.拒绝)');
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->applyFromArray($styleArray);
|
||||
|
||||
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
|
||||
$i = $row+2;
|
||||
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $page[$row]['transactionId'])
|
||||
|
||||
->setCellValue('B'.$i, $page[$row]['loginName'])
|
||||
|
||||
->setCellValue('C'.$i, $page[$row]['fromAccount'])
|
||||
|
||||
->setCellValue('D'.$i, $page[$row]['toAccount'])
|
||||
|
||||
->setCellValue('E'.$i, $page[$row]['dataRemarks'])
|
||||
|
||||
->setCellValue('F'.$i, $page[$row]['ectNum'])
|
||||
|
||||
->setCellValue('G'.$i, $page[$row]['dateTime'])
|
||||
|
||||
->setCellValue('H'.$i, $page[$row]['status']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//输出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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
150
hyhproject/admin/model/Express.php
Executable file
150
hyhproject/admin/model/Express.php
Executable file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 快递业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Express extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
return $this->where('dataFlag',1)->field('expressId,expressName,expressCode,expressImg')->order('expressId desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['expressId'=>$id,'dataFlag'=>1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
// $data = ['expressName'=>input('post.expressName'),'expressCode'=>input('post.expressCode')];
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'expressId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('Express.add')->allowField(true)->save($data);
|
||||
|
||||
if (false !==$result){
|
||||
|
||||
$id = $this->expressId;
|
||||
|
||||
//启用文件上传
|
||||
|
||||
WSTUseImages(1,$id,$data['expressImg']);
|
||||
|
||||
if(false !==$result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功",1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, (int)$data['expressId'], $data['expressImg'], 'express', 'expressImg');
|
||||
|
||||
$result = $this->validate('Express.edit')->allowField(true)->save($data,['expressId'=>(int)$data['expressId']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('post.id/d',0);
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
$result = $this->update($data,['expressId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
172
hyhproject/admin/model/Friendlinks.php
Executable file
172
hyhproject/admin/model/Friendlinks.php
Executable file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 友情链接业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class friendlinks extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
return $this->where('dataFlag',1)->field('friendlinkId,friendlinkName,friendlinkIco,friendlinkSort,friendlinkUrl')->order('friendlinkId desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['friendlinkId'=>$id,'dataFlag'=>1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$data['friendlinkSort'] = (int)$data['friendlinkSort'];
|
||||
|
||||
WSTUnset($data,'friendlinkId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('friendlinks.add')->allowField(true)->save($data);
|
||||
|
||||
$id = $this->friendlinkId;
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('TAG_FRIENDLINK',null);
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $data['friendlinkIco']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$id = (int)input('post.friendlinkId');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['friendlinkSort'] = (int)$data['friendlinkSort'];
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, $id, $data['friendlinkIco'], 'friendlinks', 'friendlinkIco');
|
||||
|
||||
$result = $this->validate('friendlinks.edit')->allowField(true)->save($data,['friendlinkId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('TAG_FRIENDLINK',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
$result = $this->update($data,['friendlinkId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('TAG_FRIENDLINK',null);
|
||||
|
||||
WSTUnuseImage('friendlinks','friendlinkIco',$id);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
627
hyhproject/admin/model/Goods.php
Executable file
627
hyhproject/admin/model/Goods.php
Executable file
@ -0,0 +1,627 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 商品类
|
||||
*/
|
||||
class Goods extends Base{
|
||||
/**
|
||||
* 上架商品列表
|
||||
*/
|
||||
public function saleByPage(){
|
||||
$where = [];
|
||||
$where['g.goodsStatus'] = 1;
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['g.isSale'] = 1;
|
||||
$areaIdPath = input('areaIdPath');
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
$goodsName = input('goodsName');
|
||||
$shopName = input('shopName');
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['saleTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['saleTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['saleTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||||
if($goodsCatIdPath !='')$where['goodsCatIdPath'] = ['like',$goodsCatIdPath."%"];
|
||||
if($goodsName != '')$where['goodsName|goodsSn'] = ['like',"%$goodsName%"];
|
||||
if($shopName != '')$where['shopName|shopSn'] = ['like',"%$shopName%"];
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = 'saleTime desc';
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
}
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
$rs = $this->alias('g')
|
||||
->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->where($where)
|
||||
->field('g.goodsId,g.goodsName,g.goodsSn,g.saleNum,g.shopPrice,g.discountRate,g.shopId,goodsImg,s.shopName,s.phone,goodsCatIdPath,g.createTime,g.saleTime,g.isSale')
|
||||
->order($order)
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
|
||||
foreach ($rs['Rows'] as $key => $v){
|
||||
$rs['Rows'][$key]['verfiycode'] = WSTShopEncrypt($v['shopId']);
|
||||
$rs['Rows'][$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
// dump($rs);die;
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 下架商品列表
|
||||
*/
|
||||
public function shelvesByPage(){
|
||||
$where = [];
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['g.isSale'] = 0;
|
||||
$areaIdPath = input('areaIdPath');
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
$goodsName = input('goodsName');
|
||||
$shopName = input('shopName');
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['saleTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['saleTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['saleTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||||
if($goodsCatIdPath !='')$where['goodsCatIdPath'] = ['like',$goodsCatIdPath."%"];
|
||||
if($goodsName != '')$where['goodsName|goodsSn'] = ['like',"%$goodsName%"];
|
||||
if($shopName != '')$where['shopName|shopSn'] = ['like',"%$shopName%"];
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = 'saleTime desc';
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
}
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
$rs = $this->alias('g')
|
||||
->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->where($where)
|
||||
->field('goodsId,goodsName,goodsSn,saleNum,shopPrice,g.shopId,goodsImg,s.shopName,goodsCatIdPath,g.createTime,saleTime,isSale')
|
||||
->order($order)
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
foreach ($rs['Rows'] as $key => $v){
|
||||
$rs['Rows'][$key]['verfiycode'] = WSTShopEncrypt($v['shopId']);
|
||||
$rs['Rows'][$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
public function getGoodsCatNames($goodsCatPath, $keyCats){
|
||||
$catIds = explode("_",$goodsCatPath);
|
||||
$catNames = array();
|
||||
for($i=0,$k=count($catIds);$i<$k;$i++){
|
||||
if($catIds[$i]=='')continue;
|
||||
if(isset($keyCats[$catIds[$i]]))$catNames[] = $keyCats[$catIds[$i]];
|
||||
}
|
||||
return implode("→",$catNames);
|
||||
}
|
||||
/**
|
||||
* 审核中的商品
|
||||
*/
|
||||
public function auditByPage(){
|
||||
$where['goodsStatus'] = 0;
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['isSale'] = 1;
|
||||
$areaIdPath = input('areaIdPath');
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
$goodsName = input('goodsName');
|
||||
$shopName = input('shopName');
|
||||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||||
if($goodsCatIdPath !='')$where['goodsCatIdPath'] = ['like',$goodsCatIdPath."%"];
|
||||
if($goodsName != '')$where['goodsName|goodsSn'] = ['like',"%$goodsName%"];
|
||||
if($shopName != '')$where['shopName|shopSn'] = ['like',"%$shopName%"];
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = 'saleTime desc';
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
}
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
$rs = $this->alias('g')->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->where($where)
|
||||
->field('g.goodsId,g.discountRate,g.goodsName,g.goodsSn,g.saleNum,g.shopPrice,g.goodsImg,s.shopName,s.shopId,s.phone,goodsCatIdPath')
|
||||
->order($order)
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
foreach ($rs['Rows'] as $key => $v){
|
||||
$rs['Rows'][$key]['verfiycode'] = WSTShopEncrypt($v['shopId']);
|
||||
$rs['Rows'][$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 违规的商品
|
||||
*/
|
||||
public function illegalByPage(){
|
||||
$where['goodsStatus'] = -1;
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['isSale'] = 1;
|
||||
$areaIdPath = input('areaIdPath');
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
$goodsName = input('goodsName');
|
||||
$shopName = input('shopName');
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['saleTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['saleTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['saleTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||||
if($goodsCatIdPath !='')$where['goodsCatIdPath'] = ['like',$goodsCatIdPath."%"];
|
||||
if($goodsName != '')$where['goodsName|goodsSn'] = ['like',"%$goodsName%"];
|
||||
if($shopName != '')$where['shopName|shopSn'] = ['like',"%$shopName%"];
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = 'saleTime desc';
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
}
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
$rs = $this->alias('g')->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->where($where)
|
||||
->field('goodsId,goodsName,goodsSn,goodsImg,s.shopName,s.shopId,illegalRemarks,goodsCatIdPath')
|
||||
->order($order)
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
foreach ($rs['Rows'] as $key => $v){
|
||||
$rs['Rows'][$key]['verfiycode'] = WSTShopEncrypt($v['shopId']);
|
||||
$rs['Rows'][$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$data['isSale'] = 0;
|
||||
Db::startTrans();
|
||||
try{
|
||||
$result = $this->update($data,['goodsId'=>$id]);
|
||||
if(false !== $result){
|
||||
hook('afterChangeGoodsStatus',['goodsId'=>$id]);
|
||||
Db::name('carts')->where('goodsId',$id)->delete();
|
||||
WSTUnuseImage('goods','goodsImg',$id);
|
||||
WSTUnuseImage('goods','gallery',$id);
|
||||
Db::commit();
|
||||
//标记删除购物车
|
||||
return WSTReturn("删除成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
/**
|
||||
* 批量删除商品
|
||||
*/
|
||||
public function batchDel(){
|
||||
$shopId = (int)session('WST_USER.shopId');
|
||||
$ids = input('post.ids/a');
|
||||
Db::startTrans();
|
||||
try{
|
||||
$rs = $this->where(['goodsId'=>['in',$ids],
|
||||
'shopId'=>$shopId])->setField(['dataFlag'=>-1,'isSale'=>0]);
|
||||
if(false !== $rs){
|
||||
Db::name('carts')->where(['goodsId'=>['in',$ids]])->delete();
|
||||
//标记删除购物车
|
||||
foreach ($ids as $v){
|
||||
WSTUnuseImage('goods','goodsImg',(int)$v);
|
||||
WSTUnuseImage('goods','gallery',(int)$v);
|
||||
hook('afterChangeGoodsStatus',['goodsId'=>$v]);
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("删除成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置商品违规状态
|
||||
*/
|
||||
public function illegal($goodsId=0,$from=0){
|
||||
$illegalRemarks = input('post.illegalRemarks');
|
||||
$id = ($goodsId==0)?(int)input('post.id'):$goodsId;
|
||||
if($illegalRemarks==''){
|
||||
return WSTReturn("请输入原因");
|
||||
}else if($from == 1){
|
||||
$id = ($goodsId==0)?(int)input('post.id'):$goodsId;
|
||||
$illegalRemarks = '该商品因被用户举报,现已下架';
|
||||
}
|
||||
//判断商品状态
|
||||
$rs = $this->alias('g')->join('__SHOPS__ s','g.shopId=s.shopId','left')->where('goodsId',$id)
|
||||
->field('s.userId,g.goodsName,g.goodsSn,g.goodsStatus,g.goodsId,g.shopId')->find();
|
||||
if((int)$rs['goodsId']==0)return WSTReturn("无效的商品");
|
||||
if((int)$rs['goodsStatus']<0)return WSTReturn("操作失败,商品状态已发生改变,请刷新后再尝试");
|
||||
Db::startTrans();
|
||||
try{
|
||||
$res = $this->where('goodsId',$id)->setField(['goodsStatus'=>-1,'illegalRemarks'=>$illegalRemarks]);
|
||||
if($res!==false){
|
||||
|
||||
Db::name('carts')->where(['goodsId'=>$id])->delete();
|
||||
//发送一条商家信息
|
||||
$shopId = $rs["shopId"];
|
||||
$tpl = WSTMsgTemplates('GOODS_REJECT');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${GOODS}','${GOODS_SN}','${TIME}','${REASON}'];
|
||||
$replace = [$rs['goodsName'],$rs['goodsSn'],date('Y-m-d H:i:s'),$illegalRemarks];
|
||||
|
||||
$msg = array();
|
||||
$msg["shopId"] = $shopId;
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
$msg["msgType"] = 1;
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']);
|
||||
$msg["msgJson"] = ['from'=>2,'dataId'=>$id];
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$params = [];
|
||||
$params['GOODS'] = $rs['goodsName'];
|
||||
$params['GOODS_SN'] = $rs['goodsSn'];
|
||||
$params['TIME'] = date('Y-m-d H:i:s');
|
||||
$params['REASON'] = $illegalRemarks;
|
||||
|
||||
$msg = array();
|
||||
$tplCode = "WX_GOODS_REJECT";
|
||||
$msg["shopId"] = $shopId;
|
||||
$msg["tplCode"] = $tplCode;
|
||||
$msg["msgType"] = 4;
|
||||
$msg["paramJson"] = ['CODE'=>$tplCode,'params'=>$params] ;
|
||||
$msg["msgJson"] = "";
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
hook('afterChangeGoodsStatus',['goodsId'=>$id]);
|
||||
Db::commit();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
/**
|
||||
* 批量商品审核不通过
|
||||
*/
|
||||
public function batchIllegal(){
|
||||
$ids = input('ids');
|
||||
if(empty($ids))return WSTReturn('请选择商品');
|
||||
$ids = explode(',' , $ids);
|
||||
foreach($ids as $k=>$v){
|
||||
$rs = $this->illegal($v);
|
||||
}
|
||||
return WSTReturn('操作成功',1);
|
||||
|
||||
}
|
||||
/**
|
||||
* 通过商品审核通过
|
||||
*/
|
||||
public function allow($goodsId=0){
|
||||
$id = ($goodsId==0)?(int)input('post.id'):$goodsId;
|
||||
//判断商品状态
|
||||
$rs = $this->alias('g')->join('__SHOPS__ s','g.shopId=s.shopId','left')->where('goodsId',$id)
|
||||
->field('s.userId,g.goodsName,g.goodsSn,g.goodsStatus,g.goodsId,g.shopId')->find();
|
||||
if((int)$rs['goodsId']==0)return WSTReturn("无效的商品");
|
||||
if((int)$rs['goodsStatus']==1)return WSTReturn("操作失败,商品状态已发生改变,请刷新后再尝试");
|
||||
Db::startTrans();
|
||||
try{
|
||||
$res = $this->setField(['goodsId'=>$id,'goodsStatus'=>1]);
|
||||
if($res!==false){
|
||||
//发送一条商家信息
|
||||
$shopId = $rs["shopId"];
|
||||
$tpl = WSTMsgTemplates('GOODS_ALLOW');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${GOODS}','${GOODS_SN}','${TIME}'];
|
||||
$replace = [$rs['goodsName'],$rs['goodsSn'],date('Y-m-d H:i:s')];
|
||||
|
||||
$msg = array();
|
||||
$msg["shopId"] = $shopId;
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
$msg["msgType"] = 1;
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
$msg["msgJson"] = ['from'=>2,'dataId'=>$id];
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$params = [];
|
||||
$params['GOODS'] = $rs['goodsName'];
|
||||
$params['GOODS_SN'] = $rs['goodsSn'];
|
||||
$params['TIME'] = date('Y-m-d H:i:s');
|
||||
|
||||
$msg = array();
|
||||
$tplCode = "WX_GOODS_ALLOW";
|
||||
$msg["shopId"] = $shopId;
|
||||
$msg["tplCode"] = $tplCode;
|
||||
$msg["msgType"] = 4;
|
||||
$msg["paramJson"] = ['CODE'=>$tplCode,'params'=>$params] ;
|
||||
$msg["msgJson"] = "";
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
hook('afterChangeGoodsStatus',['goodsId'=>$id]);
|
||||
Db::commit();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
/**
|
||||
* 批量商品审核
|
||||
*/
|
||||
public function batchAllow(){
|
||||
$ids = input('ids');
|
||||
if(empty($ids))return WSTReturn('请选择商品');
|
||||
$ids = explode(',' , $ids);
|
||||
$count = 0;// 记录上架不成功的商品数
|
||||
foreach($ids as $k=>$v){
|
||||
$rs = $this->allow($v);
|
||||
if($rs['status']==-1){
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
if($count==0)return WSTReturn('操作成功',1);
|
||||
$msg = "成功上架".(count($ids)-$count)."件商品,其中{$count}件商品上架失败.";
|
||||
return WSTReturn($msg,1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询商品
|
||||
*/
|
||||
public function searchQuery(){
|
||||
$goodsCatatId = (int)input('post.goodsCatId');
|
||||
if($goodsCatatId<=0)return [];
|
||||
$goodsCatIds = WSTGoodsCatPath($goodsCatatId);
|
||||
$key = input('post.key');
|
||||
$where = [];
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['g.isSale'] = 1;
|
||||
$where['g.goodsStatus'] = 1;
|
||||
$where['goodsCatIdPath'] = ['like',implode('_',$goodsCatIds).'_%'];
|
||||
if($key!='')$where['goodsName|shopName'] = ['like','%'.$key.'%'];
|
||||
return $this->alias('g')->join('__SHOPS__ s','g.shopId=s.shopId','inner')
|
||||
->where($where)->field('g.goodsName,s.shopName,g.goodsId')->limit(50)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据下架指定店铺下的所有商品
|
||||
*/
|
||||
public function unsaleByshopId($shopId){
|
||||
//下架商品
|
||||
$data = [];
|
||||
$data['isSale'] = 0;
|
||||
$goodsIds = [];
|
||||
$goods = $this->where(['shopId'=>$shopId,'isSale'=>1])->field('goodsId')->select();
|
||||
if(!empty($goods)){
|
||||
foreach ($goods as $key => $v) {
|
||||
$goodsIds[] = $v['goodsId'];
|
||||
}
|
||||
}
|
||||
$result = $this->where(['shopId'=>$shopId])->update($data);
|
||||
if(false !== $result){
|
||||
//删除推荐商品,删除购物车里的商品
|
||||
if(count($goodsIds)>0){
|
||||
//执行钩子事件
|
||||
foreach ($goodsIds as $key => $v) {
|
||||
hook('afterChangeGoodsStatus',['goodsId'=>$v]);
|
||||
}
|
||||
Db::name('recommends')->where(['dataSrc'=>0,'dataId'=>['in',$goodsIds]])->delete();
|
||||
Db::name('carts')->where(['goodsId'=>['in',$goodsIds]])->delete();
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据下架指定店铺下的所有商品
|
||||
*/
|
||||
public function delByshopId($shopId){
|
||||
//下架商品
|
||||
$data = [];
|
||||
$data['isSale'] = 0;
|
||||
$data['dataFlag'] = -1;
|
||||
$goodsIds = [];
|
||||
$goods = $this->where(['shopId'=>$shopId])->field('goodsId')->select();
|
||||
if(!empty($goods)){
|
||||
foreach ($goods as $key => $v) {
|
||||
$goodsIds[] = $v['goodsId'];
|
||||
}
|
||||
}
|
||||
$result = $this->where(['shopId'=>$shopId])->update($data);
|
||||
if(false !== $result){
|
||||
//删除推荐商品,删除购物车里的商品
|
||||
if(count($goodsIds)>0){
|
||||
//执行钩子事件
|
||||
foreach ($goodsIds as $key => $v) {
|
||||
hook('afterChangeGoodsStatus',['goodsId'=>$v]);
|
||||
}
|
||||
Db::name('recommends')->where(['dataSrc'=>0,'dataId'=>['in',$goodsIds]])->delete();
|
||||
Db::name('carts')->where(['goodsId'=>['in',$goodsIds]])->delete();
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品ECT支付状态
|
||||
*/
|
||||
public function goodsEct(){
|
||||
$goodsId = input('post.id/d');
|
||||
$pay = Db::name('goods_pay')->where(['goodsId'=>$goodsId])->select();//查询支付方式表是否已有该商品
|
||||
if($pay){
|
||||
return WSTReturn('此商品已添加ECT支付');
|
||||
}
|
||||
$arr =[];
|
||||
$arr['goodsId'] = $goodsId;
|
||||
$arr['ectPay'] = 1;
|
||||
// dump($arr);die;
|
||||
$result = Db::name('goods_pay')->insert($arr);
|
||||
if($result){
|
||||
return WSTReturn('添加成功',1);
|
||||
}else{
|
||||
return WSTReturn('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
//上架商品导出
|
||||
public function toExportSale(){
|
||||
$name="上架商品列表";
|
||||
$where = [];
|
||||
$where['g.goodsStatus'] = 1;
|
||||
$where['g.dataFlag'] = 1;
|
||||
$where['g.isSale'] = 1;
|
||||
$areaIdPath = input('areaIdPath');
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
$goodsName = input('goodsName');
|
||||
$shopName = input('shopName');
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['saleTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['saleTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['saleTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||||
if($goodsCatIdPath !='')$where['goodsCatIdPath'] = ['like',$goodsCatIdPath."%"];
|
||||
if($goodsName != '')$where['goodsName|goodsSn'] = ['like',"%$goodsName%"];
|
||||
if($shopName != '')$where['shopName|shopSn'] = ['like',"%$shopName%"];
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = 'saleTime desc';
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
}
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
$page = $this->alias('g')
|
||||
->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->where($where)
|
||||
->field('goodsId,goodsName,goodsSn,saleNum,shopPrice,g.shopId,goodsImg,s.shopName,goodsCatIdPath,g.createTime,saleTime,isSale')
|
||||
->order($order)
|
||||
->select();
|
||||
foreach ($page as $key => $v){
|
||||
$page[$key]['verfiycode'] = WSTShopEncrypt($v['shopId']);
|
||||
$page[$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
}
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(40);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(25);
|
||||
$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', '商品ID')
|
||||
->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]['goodsId'])
|
||||
->setCellValue('B'.$i, $page[$row]['goodsName'])
|
||||
->setCellValue('C'.$i, chunk_split($page[$row]['goodsSn']))
|
||||
->setCellValue('D'.$i, $page[$row]['shopPrice'])
|
||||
->setCellValue('E'.$i, $page[$row]['shopName'])
|
||||
->setCellValue('F'.$i, $page[$row]['saleTime'])
|
||||
->setCellValue('G'.$i, $page[$row]['createTime'])
|
||||
->setCellValue('H'.$i, $page[$row]['goodsCatName'])
|
||||
->setCellValue('I'.$i, $page[$row]['saleNum'])
|
||||
->setCellValue('J'.$i, $page[$row]['isSale']);
|
||||
|
||||
}
|
||||
//输出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');
|
||||
}
|
||||
}
|
286
hyhproject/admin/model/GoodsAppraises.php
Executable file
286
hyhproject/admin/model/GoodsAppraises.php
Executable file
@ -0,0 +1,286 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商品评价业务处理
|
||||
|
||||
*/
|
||||
|
||||
class GoodsAppraises extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$where = 'p.shopId=g.shopId and gp.goodsId=g.goodsId and o.orderId=gp.orderId and gp.dataFlag=1';
|
||||
|
||||
$shopName = input('shopName');
|
||||
|
||||
$goodsName = input('goodsName');
|
||||
|
||||
|
||||
|
||||
$areaId1 = (int)input('areaId1');
|
||||
|
||||
if($areaId1>0){
|
||||
|
||||
$where.=" and p.areaIdPath like '".$areaId1."%'";
|
||||
|
||||
|
||||
|
||||
$areaId2 = (int)input("areaId1_".$areaId1);
|
||||
|
||||
if($areaId2>0)
|
||||
|
||||
$where.=" and p.areaIdPath like '".$areaId1."_".$areaId2."%'";
|
||||
|
||||
|
||||
|
||||
$areaId3 = (int)input("areaId1_".$areaId1."_".$areaId2);
|
||||
|
||||
if($areaId3>0)
|
||||
|
||||
$where.=" and p.areaId = $areaId3";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if($shopName!='')
|
||||
|
||||
$where.=" and (p.shopName like '%".$shopName."%' or p.shopSn like '%".$shopName."%')";
|
||||
|
||||
if($goodsName!='')
|
||||
|
||||
$where.=" and (g.goodsName like '%".$goodsName."%' or g.goodsSn like '%".$goodsName."%')";
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$order = [];
|
||||
|
||||
if($sort!=''){
|
||||
|
||||
$sortArr = explode('.',$sort);
|
||||
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
|
||||
}
|
||||
|
||||
$rs = $this->alias('gp')->field('gp.*,g.goodsName,g.goodsImg,o.orderNo,u.loginName')
|
||||
|
||||
->join('__GOODS__ g ','gp.goodsId=g.goodsId','left')
|
||||
|
||||
->join('__ORDERS__ o','gp.orderId=o.orderId','left')
|
||||
|
||||
->join('__USERS__ u','u.userId=gp.userId','left')
|
||||
|
||||
->join('__SHOPS__ p','p.shopId=gp.shopId','left')
|
||||
|
||||
->where($where)
|
||||
|
||||
->order($order)
|
||||
|
||||
->order('id desc')
|
||||
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->alias('gp')->field('gp.*,o.orderNo,u.loginName,g.goodsName,g.goodsImg')
|
||||
|
||||
->join('__GOODS__ g ','gp.goodsId=g.goodsId','left')
|
||||
|
||||
->join('__ORDERS__ o','gp.orderId=o.orderId','left')
|
||||
|
||||
->join('__USERS__ u','u.userId=gp.userId','left')
|
||||
|
||||
->where('gp.id',$id)->find();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$Id = input('post.id/d',0);
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['isShow'] = ((int)$data['isShow']==1)?1:0;
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('GoodsAppraises.edit')->allowField(true)->save($data,['id'=>$Id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
$goodsAppraises = $this->get($Id);
|
||||
|
||||
$this->statGoodsAppraises($goodsAppraises->goodsId,$goodsAppraises->shopId);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
print_r($e);
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("编辑失败");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.id/d',0);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$goodsAppraises = $this->get($id);
|
||||
|
||||
$goodsAppraises->dataFlag = -1;
|
||||
|
||||
$result = $goodsAppraises->save();
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
$this->statGoodsAppraises($goodsAppraises->goodsId,$goodsAppraises->shopId);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("删除失败");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 重新统计商品
|
||||
|
||||
*/
|
||||
|
||||
public function statGoodsAppraises($goodsId,$shopId){
|
||||
|
||||
$rs = Db::name('goods_appraises')->where(['goodsId'=>$goodsId,'isShow'=>1,'dataFlag'=>1])
|
||||
|
||||
->field('count(userId) userNum,sum(goodsScore) goodsScore,sum(serviceScore) serviceScore, sum(timeScore) timeScore')
|
||||
|
||||
->find();
|
||||
|
||||
$data = [];
|
||||
|
||||
//商品评价数
|
||||
|
||||
Db::name('goods')->where('goodsId',$goodsId)->update(['appraiseNum'=>$rs['userNum']]);
|
||||
|
||||
//商品评价统计
|
||||
|
||||
$data['totalScore'] = (int)$rs['goodsScore']+$rs['serviceScore']+$rs['timeScore'];
|
||||
|
||||
$data['totalUsers'] = (int)$rs['userNum'];
|
||||
|
||||
$data['goodsScore'] = (int)$rs['goodsScore'];
|
||||
|
||||
$data['goodsUsers'] = (int)$rs['userNum'];
|
||||
|
||||
$data['serviceScore'] = (int)$rs['serviceScore'];
|
||||
|
||||
$data['serviceUsers'] = (int)$rs['userNum'];
|
||||
|
||||
$data['timeScore'] = (int)$rs['serviceScore'];
|
||||
|
||||
$data['timeUsers'] = (int)$rs['userNum'];
|
||||
|
||||
Db::name('goods_scores')->where('goodsId',$goodsId)->update($data);
|
||||
|
||||
//商家评价
|
||||
|
||||
$rs = Db::name('goods_appraises')->where(['shopId'=>$shopId,'isShow'=>1,'dataFlag'=>1])
|
||||
|
||||
->field('count(userId) userNum,sum(goodsScore) goodsScore,sum(serviceScore) serviceScore, sum(timeScore) timeScore')
|
||||
|
||||
->find();
|
||||
|
||||
$data['totalScore'] = $rs['goodsScore']+$rs['serviceScore']+$rs['timeScore'];
|
||||
|
||||
$data['totalUsers'] = $rs['userNum'];
|
||||
|
||||
$data['goodsScore'] = $rs['goodsScore'];
|
||||
|
||||
$data['goodsUsers'] = $rs['userNum'];
|
||||
|
||||
$data['serviceScore'] = $rs['serviceScore'];
|
||||
|
||||
$data['serviceUsers'] = $rs['userNum'];
|
||||
|
||||
$data['timeScore'] = $rs['serviceScore'];
|
||||
|
||||
$data['timeUsers'] = $rs['userNum'];
|
||||
|
||||
Db::name('shop_scores')->where('shopId',$shopId)->update($data);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
619
hyhproject/admin/model/GoodsCats.php
Executable file
619
hyhproject/admin/model/GoodsCats.php
Executable file
@ -0,0 +1,619 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商品分类业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class GoodsCats extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取树形分类
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
return $this->where(['dataFlag'=>1,'parentId'=>input('catId/d',0)])->order('catSort asc,catId desc')->paginate(1000)->toArray();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery($parentId){
|
||||
|
||||
return $this->where(['dataFlag'=>1,'parentId'=>$parentId])->order('catSort asc,catName asc')->select();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
*获取商品分类名值对
|
||||
|
||||
*/
|
||||
|
||||
public function listKeyAll(){
|
||||
|
||||
$rs = $this->field("catId,catName")->where(['dataFlag'=>1])->order('catSort asc,catName asc')->select();
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ($rs as $key => $cat) {
|
||||
|
||||
$data[$cat["catId"]] = $cat["catName"];
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取树形分类
|
||||
|
||||
*/
|
||||
|
||||
public function getTree($data, $parentId=0){
|
||||
|
||||
$arr = array();
|
||||
|
||||
foreach($data as $k=>$v)
|
||||
|
||||
{
|
||||
|
||||
if($v['parentId']==$parentId && $v['dataFlag']==1)
|
||||
|
||||
{
|
||||
|
||||
//再查找该分类下是否还有子分类
|
||||
|
||||
$v['child'] = $this->getTree($data, $v['catId']);
|
||||
|
||||
//统计child
|
||||
|
||||
$v['childNum'] = count($v['child']);
|
||||
|
||||
//将找到的分类放回该数组中
|
||||
|
||||
$arr[]=$v;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $arr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 迭代获取下级
|
||||
|
||||
* 获取一个分类下的所有子级分类id
|
||||
|
||||
*/
|
||||
|
||||
public function getChild($pid){
|
||||
|
||||
$data = $this->where("dataFlag=1")->select();
|
||||
|
||||
//获取该分类id下的所有子级分类id
|
||||
|
||||
$ids = $this->_getChild($data, $pid, true);//每次调用都清空一次数组
|
||||
|
||||
//把自己也放进来
|
||||
|
||||
array_unshift($ids, $pid);
|
||||
|
||||
return $ids;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function _getChild($data, $pid, $isClear=false){
|
||||
|
||||
static $ids = array();
|
||||
|
||||
if($isClear)//是否清空数组
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach($data as $k=>$v)
|
||||
|
||||
{
|
||||
|
||||
if($v['parentId']==$pid && $v['dataFlag']==1)
|
||||
|
||||
{
|
||||
|
||||
$ids[] = $v['catId'];//将找到的下级分类id放入静态数组
|
||||
|
||||
//再找下当前id是否还存在下级id
|
||||
|
||||
$this->_getChild($data, $v['catId']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $ids;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getGoodscats($id){
|
||||
|
||||
return $this->where(['catId'=>$id])->find();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 显示是否推荐/不推荐
|
||||
|
||||
*/
|
||||
|
||||
public function editiIsFloor(){
|
||||
|
||||
$ids = array();
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$ids = $this->getChild($id);
|
||||
|
||||
$isFloor = input('post.isFloor/d')?1:0;
|
||||
|
||||
$result = $this->where("catId in(".implode(',',$ids).")")->update(['isFloor' => $isFloor]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 修改分类名称
|
||||
|
||||
*/
|
||||
|
||||
public function editName(){
|
||||
|
||||
$catName = input('catName');
|
||||
|
||||
if($catName=='')return WSTReturn("操作失败,商品分类名称不能为空");
|
||||
|
||||
if(mb_strlen($catName)>20)return WSTReturn('商品分类名称不能超过20个字'.mb_strlen($catName));
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$result = $this->where("catId = ".$id)->update(['catName' => $catName]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改分类排序
|
||||
|
||||
*/
|
||||
|
||||
public function editOrder(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$result = $this->where("catId = ".$id)->update(['catSort' => (int)input('catSort')]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 显示是否自营显示/隐藏
|
||||
|
||||
*/
|
||||
|
||||
public function editiIsSelfShow(){
|
||||
|
||||
$ids = array();
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$ids = $this->getChild($id);
|
||||
|
||||
$isSelfShow = input('post.isSelfShow/d')?1:0;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where("catId in(".implode(',',$ids).")")->update(['isSelfShow' => $isSelfShow]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
if($isSelfShow==0){
|
||||
|
||||
//删除购物车里的相关商
|
||||
|
||||
$goods = Db::name('goods g')->join('shops s','s.shopId=g.shopId')->where(["goodsCatId"=>['in',$ids],'isSale'=>1,'shopStatus'=>1,'s.isSelf'=>1])->field('goodsId')->select();
|
||||
|
||||
if(count($goods)>0){
|
||||
|
||||
$goodsIds = [];
|
||||
|
||||
foreach ($goods as $key =>$v){
|
||||
|
||||
$goodsIds[] = $v['goodsId'];
|
||||
|
||||
}
|
||||
|
||||
Db::name('carts')->where(['goodsId'=>['in',$goodsIds]])->delete();
|
||||
|
||||
}
|
||||
|
||||
//把相关的商品下架了
|
||||
|
||||
Db::name('goods g')->join('shops s','s.shopId=g.shopId')->where("goodsCatId in(".implode(',',$ids).") and s.isSelf=1")->update(['g.isSale' => 0]);
|
||||
|
||||
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 显示是否显示/隐藏
|
||||
|
||||
*/
|
||||
|
||||
public function editiIsShow(){
|
||||
|
||||
$ids = array();
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$ids = $this->getChild($id);
|
||||
|
||||
$isShow = input('post.isShow/d')?1:0;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->where("catId in(".implode(',',$ids).")")->update(['isShow' => $isShow]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
if($isShow==0){
|
||||
|
||||
//删除购物车里的相关商品
|
||||
|
||||
$goods = Db::name('goods g')->join('shops s','s.shopId=g.shopId')->where(["goodsCatId"=>['in',$ids],'isSale'=>1,'s.isSelf'=>0])->field('goodsId')->select();
|
||||
|
||||
if(count($goods)>0){
|
||||
|
||||
$goodsIds = [];
|
||||
|
||||
foreach ($goods as $key =>$v){
|
||||
|
||||
$goodsIds[] = $v['goodsId'];
|
||||
|
||||
}
|
||||
|
||||
Db::name('carts')->where(['goodsId'=>['in',$goodsIds]])->delete();
|
||||
|
||||
}
|
||||
|
||||
//把相关的商品下架了
|
||||
|
||||
Db::name('goods g')->join('shops s','s.shopId=g.shopId')->where("goodsCatId in(".implode(',',$ids).") and s.isSelf=0")->update(['g.isSale' => 0]);
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$parentId = input('post.parentId/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'catId,dataFlag');
|
||||
|
||||
$data['parentId'] = $parentId;
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$result = $this->validate('GoodsCats.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$catId = input('post.id/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data,'catId,dataFlag,createTime');
|
||||
|
||||
$result = $this->validate('GoodsCats.edit')->allowField(true)->save($data,['catId'=>$catId]);
|
||||
|
||||
$ids = array();
|
||||
|
||||
$ids = $this->getChild($catId);
|
||||
|
||||
$this->where("catId in(".implode(',',$ids).")")->update(['isShow' => (int)$data['isShow'],'isFloor'=> $data['isFloor'],'commissionRate'=>(float)$data['commissionRate'],'payDeposit'=>(float)$data['payDeposit']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
if($data['isShow']==0){
|
||||
|
||||
//删除购物车里的相关商品
|
||||
|
||||
$goods = Db::name('goods')->where(["goodsCatId"=>['in',$ids],'isSale'=>1])->field('goodsId')->select();
|
||||
|
||||
if(count($goods)>0){
|
||||
|
||||
$goodsIds = [];
|
||||
|
||||
foreach ($goods as $key =>$v){
|
||||
|
||||
$goodsIds[] = $v['goodsId'];
|
||||
|
||||
}
|
||||
|
||||
Db::name('carts')->where(['goodsId'=>['in',$goodsIds]])->delete();
|
||||
|
||||
}
|
||||
|
||||
//把相关的商品下架了
|
||||
|
||||
Db::name('goods')->where("goodsCatId in(".implode(',',$ids).")")->update(['isSale' => 0]);
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$ids = array();
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$ids = $this->getChild($id);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
$result = $this->where(['catId'=>['in',$ids]])->update($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
//删除购物车里的相关商品
|
||||
|
||||
$goods = Db::name('goods')->where(["goodsCatId"=>['in',$ids],'isSale'=>1])->field('goodsId')->select();
|
||||
|
||||
if(count($goods)>0){
|
||||
|
||||
$goodsIds = [];
|
||||
|
||||
foreach ($goods as $key =>$v){
|
||||
|
||||
$goodsIds[] = $v['goodsId'];
|
||||
|
||||
}
|
||||
|
||||
Db::name('carts')->where(['goodsId'=>['in',$goodsIds]])->delete();
|
||||
|
||||
}
|
||||
|
||||
//删除商品属性
|
||||
|
||||
Db::name('attributes')->where("goodsCatId in(".implode(',',$ids).")")->update(['dataFlag'=>-1]);
|
||||
|
||||
//删除商品规格
|
||||
|
||||
Db::name('spec_cats')->where("goodsCatId in(".implode(',',$ids).")")->update(['dataFlag'=>-1]);
|
||||
|
||||
//把相关的商品下架了
|
||||
|
||||
Db::name('goods')->where("goodsCatId in(".implode(',',$ids).")")->update(['isSale' => 0]);
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 根据子分类获取其父级分类
|
||||
|
||||
*/
|
||||
|
||||
public function getParentIs($id,$data = array()){
|
||||
|
||||
$data[] = $id;
|
||||
|
||||
$parentId = $this->where('catId',$id)->value('parentId');
|
||||
|
||||
if($parentId==0){
|
||||
|
||||
krsort($data);
|
||||
|
||||
return $data;
|
||||
|
||||
}else{
|
||||
|
||||
return $this->getParentIs($parentId, $data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
877
hyhproject/admin/model/GoodsClassify.php
Executable file
877
hyhproject/admin/model/GoodsClassify.php
Executable file
@ -0,0 +1,877 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商品分类业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class GoodsClassify extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取树形分类
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
return Db::name('goods_classify')->order('orderby desc')->paginate(15)->toArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getById($goodsclassifyId){
|
||||
|
||||
$obj = null;
|
||||
|
||||
if($goodsclassifyId>0){
|
||||
|
||||
$obj = Db::name('goods_classify')->where(['goodsclassifyId'=>$goodsclassifyId])->find();
|
||||
|
||||
}else{
|
||||
|
||||
$obj = self::getEModel("goods_classify");
|
||||
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['create_time'] = date('Y-m-d H:i:s');
|
||||
|
||||
$validate = Validate::make([
|
||||
|
||||
'goodsclassifyName' => 'require',
|
||||
|
||||
]);
|
||||
|
||||
$msg = [
|
||||
|
||||
'goodsclassifyName.require' => '商品总名称不能为空',
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
$info = [
|
||||
|
||||
'goodsclassifyName' => $data['goodsclassifyName'],
|
||||
|
||||
];
|
||||
|
||||
if (!$validate->check($info)) {
|
||||
|
||||
return WSTReturn ($validate->getError());
|
||||
|
||||
}
|
||||
|
||||
$find=$this->where('goodsclassifyName',$data['goodsclassifyName'])->find();
|
||||
|
||||
if($find) return WSTReturn('此总分类名称已存在');
|
||||
|
||||
$result = $this->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$goodsclassifyId = input('post.goodsclassifyId/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$result=$this->allowField(true)->save($data,['goodsclassifyId'=>$goodsclassifyId]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.goodsclassifyId/d');
|
||||
|
||||
$see=db('cat_classify')->where('classifyId',$id)->find();
|
||||
|
||||
$recom=db('recom_classify')->where('classifyId',$id)->find();
|
||||
|
||||
if($see!==NUll) return WSTReturn ('商品有子分类,不能删除');
|
||||
|
||||
if($recom) return WSTReturn ('此商品分类有活动,不能删除');
|
||||
|
||||
$result=$this->where('goodsclassifyId',$id)->delete();
|
||||
|
||||
if($result!=false){
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getByIds($catId){
|
||||
|
||||
$obj = null;
|
||||
|
||||
if($catId>0){
|
||||
|
||||
$obj = Db::name('cat_classify')->where(['catId'=>$catId])->find();
|
||||
|
||||
}else{
|
||||
|
||||
$obj = self::getEModel("cat_classify");
|
||||
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
// 添加商品分类
|
||||
|
||||
public function add_cat(){
|
||||
|
||||
$data=input('post.');
|
||||
|
||||
$result = db('cat_classify')->insert($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn("新增失败",-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//获取商品分类
|
||||
|
||||
public function catdetail(){
|
||||
|
||||
$id=input('goodsclassifyId');
|
||||
|
||||
$result=db('cat_classify')->where('classifyId',$id)->field('catId')->select();
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
//获取商品分类列表
|
||||
|
||||
public function catdetailPage(){
|
||||
|
||||
$id=input('classifyId');
|
||||
|
||||
$pagesize = input('limit/d');
|
||||
|
||||
$result=db('cat_classify')->alias('a')
|
||||
|
||||
->join('goods_cats g','g.catId=a.catId','left')
|
||||
|
||||
->where('classifyId',$id)->field('g.catName,createTime,a.catId')
|
||||
|
||||
->paginate($pagesize)->toArray();
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除商品分类
|
||||
|
||||
*/
|
||||
|
||||
public function catdel(){
|
||||
|
||||
$catId = input('catId');
|
||||
|
||||
$classifyId = input('classifyId');
|
||||
|
||||
$result=db('cat_classify')->where(['catId'=>$catId,'classifyId'=>$classifyId])->delete();
|
||||
|
||||
if($result!=false){
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
详情
|
||||
|
||||
*/
|
||||
|
||||
public function detail(){
|
||||
|
||||
$id=input('catId');
|
||||
|
||||
$result=db('cat_classify')->where('catId',$id)->field('catId')->select();
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
//详情分页
|
||||
|
||||
public function detailByPage(){
|
||||
|
||||
$catId=input('catId');
|
||||
|
||||
$pagesize = input('limit/d');
|
||||
|
||||
$get_child=$this->getChild('',$catId);
|
||||
|
||||
$goods_result=db('goods')->alias('a')->join('shops s','s.shopId=a.shopId','left')
|
||||
|
||||
->whereIn('goodsCatId',$get_child)->order('saleNum desc')
|
||||
|
||||
->where(['isSale'=>1,'a.dataFlag'=>1,'a.goodsStatus'=>1,'isHot'=>1])
|
||||
|
||||
->field('goodsId,goodsName,goodsImg,shopPrice,saleNum,goodsSn,s.shopName,a.shopId,goodsCatIdPath')
|
||||
|
||||
->paginate($pagesize)->toArray();
|
||||
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
|
||||
foreach ($goods_result['Rows'] as $key => $v){
|
||||
|
||||
$goods_result['Rows'][$key]['verfiycode'] = WSTShopEncrypt($v['shopId']);
|
||||
|
||||
$goods_result['Rows'][$key]['goodsCatName'] = self::getGoodsCatNames($v['goodsCatIdPath'],$keyCats);
|
||||
|
||||
}
|
||||
|
||||
return $goods_result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getGoodsCatNames($goodsCatPath, $keyCats){
|
||||
|
||||
$catIds = explode("_",$goodsCatPath);
|
||||
|
||||
$catNames = array();
|
||||
|
||||
for($i=0,$k=count($catIds);$i<$k;$i++){
|
||||
|
||||
if($catIds[$i]=='')continue;
|
||||
|
||||
if(isset($keyCats[$catIds[$i]]))$catNames[] = $keyCats[$catIds[$i]];
|
||||
|
||||
}
|
||||
|
||||
return implode("→",$catNames);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 迭代获取下级
|
||||
|
||||
* 获取一个分类下的所有子级分类id
|
||||
|
||||
*/
|
||||
|
||||
public function getChild($data,$pid){
|
||||
|
||||
$childId = db('goods_cats')->where("dataFlag=1")->where('parentId',$pid)->field('catId,parentId')->select();
|
||||
|
||||
//获取该分类id下的所有子级分类id
|
||||
|
||||
foreach($childId as $key=>$value){
|
||||
|
||||
$child[]=$value['catId'];
|
||||
|
||||
}
|
||||
|
||||
static $ids = array();
|
||||
|
||||
foreach($childId as $k=>$v){
|
||||
|
||||
//dump($childId);
|
||||
|
||||
$ids[] = $v['catId'];//将找到的下级分类id放入静态数组
|
||||
|
||||
//再找下当前id是否还存在下级id
|
||||
|
||||
$this->getChild($childId, $v['catId']);
|
||||
|
||||
}
|
||||
|
||||
return $ids;
|
||||
|
||||
}
|
||||
|
||||
//活动详情分页
|
||||
|
||||
public function setdetailPage(){
|
||||
|
||||
$recomId=input('recomId');
|
||||
|
||||
$goodsId=input('goodsId');
|
||||
|
||||
$where=[];
|
||||
|
||||
//dump($recomId);
|
||||
|
||||
if($recomId)$where['rg.recomId'] = $recomId;
|
||||
|
||||
if($goodsId)$where['rg.goodsId'] = ['like','%'.$goodsId.'%'];
|
||||
|
||||
$classifyId=input('classifyId');
|
||||
|
||||
$pagesize = input('limit/d');
|
||||
|
||||
$goods_result=db('recom_classify')->alias('rc')
|
||||
|
||||
->join('recom_goods rg','rg.recomId =rc.recomId','left')
|
||||
|
||||
->join('goods a','a.goodsId=rg.goodsId','left')
|
||||
|
||||
->where(['isSale'=>1,'a.dataFlag'=>1,'a.goodsStatus'=>1,'rc.classifyId'=>$classifyId])->where($where)
|
||||
|
||||
->field('recomGoodsId,a.goodsId,a.goodsName,goodsImg,rc.recomId,rc.recomName,rg.goodsOrder,from_unixtime(rg.createTime)createTime,a.shopPrice')
|
||||
|
||||
->order('goodsOrder desc')
|
||||
|
||||
->paginate($pagesize)->toArray();
|
||||
|
||||
return $goods_result;
|
||||
|
||||
}
|
||||
|
||||
//更改活动商品的排序号
|
||||
|
||||
public function changeSet(){
|
||||
|
||||
$id=(int)input('id');
|
||||
|
||||
$goodsOrder=(int)input('goodsOrder');
|
||||
|
||||
$result=db('recom_goods')->where('recomGoodsId',$id)->update(['goodsOrder'=>$goodsOrder]);
|
||||
|
||||
if($result!==false){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn("新增失败",-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//活动详情分页
|
||||
|
||||
public function recomPage(){
|
||||
|
||||
$classifyId=input('classifyId');
|
||||
|
||||
$goodsId=(int)input('goodsId');
|
||||
|
||||
$where=[];
|
||||
|
||||
if($goodsId)$where['ra.goodsId'] = ['like','%'.$goodsId.'%'];
|
||||
|
||||
$pagesize = input('limit/d');
|
||||
|
||||
$goods_result=db('recom_active')->alias('ra')
|
||||
|
||||
->join('goods a','a.goodsId=ra.goodsId','left')
|
||||
|
||||
->where(['isSale'=>1,'a.dataFlag'=>1,'a.goodsStatus'=>1,'ra.classifyId'=>$classifyId])->where($where)
|
||||
|
||||
->field('recomActiveId,a.goodsId,a.goodsName,goodsImg,ra.goodsOrder,from_unixtime(ra.createTime)createTime,a.shopPrice')
|
||||
|
||||
->order('goodsOrder desc')
|
||||
|
||||
->paginate($pagesize)->toArray();
|
||||
|
||||
return $goods_result;
|
||||
|
||||
}
|
||||
|
||||
//更改活动商品的排序号
|
||||
|
||||
public function changeRecom(){
|
||||
|
||||
$id=(int)input('id');
|
||||
|
||||
$goodsOrder=(int)input('goodsOrder');
|
||||
|
||||
$result=db('recom_active')->where('recomActiveId',$id)->update(['goodsOrder'=>$goodsOrder]);
|
||||
|
||||
if($result!==false){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn("新增失败",-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除推荐商品
|
||||
|
||||
public function recomActiveDel(){
|
||||
|
||||
$recomGoodsId=input('recomActiveId');
|
||||
|
||||
$result=db('recom_active')->where('recomActiveId',$recomGoodsId)->delete();
|
||||
|
||||
if($result!=false){
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getrecomActiveId($recomActiveId){
|
||||
|
||||
$obj = null;
|
||||
|
||||
if($recomActiveId>0){
|
||||
|
||||
$obj = Db::name('recom_active')->where(['recomActiveId'=>$recomActiveId])->find();
|
||||
|
||||
}else{
|
||||
|
||||
$obj = self::getEModel("recom_active");
|
||||
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function addrecomActive(){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$data=input('post.');
|
||||
|
||||
$data['createTime']=time();
|
||||
|
||||
$goodsId = trim(input('goodsId'));
|
||||
|
||||
$product_id = explode(',',$goodsId);
|
||||
|
||||
$arr=[];
|
||||
|
||||
foreach ($product_id as $k=>$value) {
|
||||
|
||||
$goods=db('goods')->where('goodsId',$value)->where('dataFlag=1 and isSale=1 and goodsStatus=1')->find();
|
||||
|
||||
if(!$goods) return WSTReturn('无效商品 '.$value);
|
||||
|
||||
$arr[$k]['goodsId'] = $value;
|
||||
|
||||
$arr[$k]['classifyId'] = $data['classifyId'];
|
||||
|
||||
$arr[$k]['createTime'] = $data['createTime'];
|
||||
|
||||
if($arr[$k]['goodsId']=="," || $arr[$k]['goodsId']==""){
|
||||
|
||||
unset($arr[$k]);
|
||||
|
||||
}
|
||||
|
||||
$find=db('recom_active')->where(['goodsId'=>$arr[$k]['goodsId']])->find();
|
||||
|
||||
if($find) return WSTReturn('此商品已存在 '.$arr[$k]['goodsId']);
|
||||
|
||||
}
|
||||
|
||||
$result=Db::name('recom_active')->insertAll($arr);
|
||||
|
||||
Db::commit();
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch(\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("添加失败",-1);
|
||||
|
||||
}
|
||||
|
||||
//查看活动页活动分类
|
||||
|
||||
public function catsPage(){
|
||||
|
||||
$classifyId=input('classifyId');
|
||||
|
||||
$goods_result=db('recom_classify')->alias('rc')
|
||||
|
||||
->join('goods_classify gc','gc.goodsclassifyId=rc.classifyId','left')
|
||||
|
||||
->where('classifyId',$classifyId)
|
||||
|
||||
->field('recomId,recomName,classifyId,goodsclassifyName,recomOrder,from_unixtime(startTime) startTime,from_unixtime(endTime)endTime')
|
||||
|
||||
->order('recomOrder desc')
|
||||
|
||||
->paginate()->toArray();
|
||||
|
||||
return $goods_result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getCatsId($recomId){
|
||||
|
||||
$obj = null;
|
||||
|
||||
if($recomId>0){
|
||||
|
||||
$obj = Db::name('recom_classify')->where(['recomId'=>$recomId])->find();
|
||||
|
||||
$obj['startTime']=date('Y-m-d H:i:s',$obj['startTime']);
|
||||
|
||||
$obj['endTime']=date('Y-m-d H:i:s',$obj['endTime']);
|
||||
|
||||
}else{
|
||||
|
||||
$obj = self::getEModel("recom_classify");
|
||||
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
// 添加商品活动分类
|
||||
|
||||
public function addCats(){
|
||||
|
||||
$data=input('post.');
|
||||
|
||||
$data['startTime']=strtotime(input('startTime'));
|
||||
|
||||
$data['endTime']=strtotime(input('endTime'));
|
||||
|
||||
$find=db('recom_classify')->where('recomName',$data['recomName'])->find();
|
||||
|
||||
if($find) return WSTReturn('此分类名称已存在');
|
||||
|
||||
$result = db('recom_classify')->insert($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn("新增失败",-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 修改商品活动分类
|
||||
|
||||
public function editCats(){
|
||||
|
||||
$data=input('post.');
|
||||
|
||||
$data['startTime']=strtotime(input('startTime'));
|
||||
|
||||
$data['endTime']=strtotime(input('endTime'));
|
||||
|
||||
$result = db('recom_classify')->where('recomId',$data['recomId'])->update($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn("操作失败",-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除分类活动
|
||||
|
||||
public function catsDel(){
|
||||
|
||||
$recomId=input('recomId');
|
||||
|
||||
$m=input('m');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
if($m==2){
|
||||
|
||||
db('recom_goods')->where('recomId',$recomId)->delete();
|
||||
|
||||
db('recom_classify')->where('recomId',$recomId)->delete();
|
||||
|
||||
}else{
|
||||
|
||||
$find_goods=db('recom_goods')->where('recomId',$recomId)->find();
|
||||
|
||||
if($find_goods) return WSTReturn('此分类有活动商品',2);
|
||||
|
||||
db('recom_classify')->where('recomId',$recomId)->delete();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取指定对象
|
||||
|
||||
*/
|
||||
|
||||
public function getGoodsId($recomId){
|
||||
|
||||
$obj = null;
|
||||
|
||||
if($recomId>0){
|
||||
|
||||
$obj = Db::name('recom_goods')->where(['id'=>$recomId])->find();
|
||||
|
||||
}else{
|
||||
|
||||
$obj = self::getEModel("recom_goods");
|
||||
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
// 添加活动商品
|
||||
|
||||
public function addGoods(){
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$data=input('post.');
|
||||
|
||||
$data['createTime']=time();
|
||||
|
||||
$goodsId = trim(input('goodsId'));
|
||||
|
||||
$product_id = explode(',',$goodsId);
|
||||
|
||||
$arr=[];
|
||||
|
||||
foreach ($product_id as $k=>$value) {
|
||||
|
||||
$goods=db('goods')->where('goodsId',$value)->where('dataFlag=1 and isSale=1 and goodsStatus=1')->find();
|
||||
|
||||
if(!$goods) return WSTReturn('无效商品 '.$value);
|
||||
|
||||
$arr[$k]['goodsId'] = $value;
|
||||
|
||||
$arr[$k]['recomId'] = $data['recomId'];
|
||||
|
||||
$arr[$k]['createTime'] = $data['createTime'];
|
||||
|
||||
if($arr[$k]['goodsId']=="," || $arr[$k]['goodsId']==""){
|
||||
|
||||
unset($arr[$k]);
|
||||
|
||||
}
|
||||
|
||||
$find=db('recom_goods')->where(['goodsId'=>$arr[$k]['goodsId'],'recomId'=>$arr[$k]['recomId']])->find();
|
||||
|
||||
if($find) return WSTReturn('此商品已存在 '.$arr[$k]['goodsId']);
|
||||
|
||||
}
|
||||
|
||||
$result=Db::name('recom_goods')->insertAll($arr);
|
||||
|
||||
Db::commit();
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
return WSTReturn("添加成功", 1);
|
||||
|
||||
}
|
||||
|
||||
catch(\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("添加失败",-1);
|
||||
|
||||
}
|
||||
|
||||
//删除分类活动商品
|
||||
|
||||
public function goodsDel(){
|
||||
|
||||
$recomGoodsId=input('recomGoodsId');
|
||||
|
||||
$result=db('recom_goods')->where('recomGoodsId',$recomGoodsId)->delete();
|
||||
|
||||
if($result!=false){
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
72
hyhproject/admin/model/GoodsConsult.php
Executable file
72
hyhproject/admin/model/GoodsConsult.php
Executable file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 商品咨询业务处理
|
||||
*/
|
||||
class GoodsConsult extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$type = (int)input('type');
|
||||
$consultKey = input('consultKey');
|
||||
$where = [];
|
||||
$where['gc.dataFlag'] = 1;
|
||||
// 筛选类别
|
||||
if($type>0){$where['gc.consultType'] = $type;}
|
||||
// 关键字搜索
|
||||
if($consultKey!=''){$where['gc.consultContent'] = ['like',"%$consultKey%"];}
|
||||
$rs = $this->alias('gc')
|
||||
->join('__GOODS__ g','g.goodsId=gc.goodsId')
|
||||
->join('__USERS__ u','u.userId=gc.userId','left')
|
||||
->field('gc.*,u.loginName,g.goodsId,g.goodsImg,g.goodsName')
|
||||
->where($where)
|
||||
->order('gc.createTime desc')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
if(!empty($rs['Rows'])){
|
||||
foreach($rs['Rows'] as $k=>&$v){
|
||||
// 解义
|
||||
$v['consultContent'] = htmlspecialchars_decode($v['consultContent']);
|
||||
}
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->alias('gc')
|
||||
->join('__GOODS__ g','gc.goodsId=g.goodsId')
|
||||
->join('__USERS__ u','gc.userId=u.userId','left')
|
||||
->field('gc.*,g.goodsImg,g.goodsId,g.goodsName,u.loginName')
|
||||
->where(['id'=>$id])
|
||||
->find();
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = input('post.id/d',0);
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'createTime');
|
||||
$result = $this->validate('GoodsConsult.edit')->allowField(true)->save($data,['id'=>$Id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d',0);
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['id'=>$id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
154
hyhproject/admin/model/HomeMenus.php
Executable file
154
hyhproject/admin/model/HomeMenus.php
Executable file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 前台菜单业务处理
|
||||
*/
|
||||
class HomeMenus extends Base{
|
||||
protected $insert = ['dataFlag'=>1];
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['dataFlag'=>1,'menuId'=>$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data["dataFlag"] = 1;
|
||||
$result = $this->validate('HomeMenus.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
cache('WST_HOME_MENUS',null);
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑菜单
|
||||
*/
|
||||
public function edit(){
|
||||
$menuId = input('post.menuId/d',0);
|
||||
$result = $this->validate('HomeMenus.edit')->allowField(['menuName','menuSort','menuType','isShow','menuUrl','menuOtherUrl'])->save(input('post.'),['menuId'=>$menuId]);
|
||||
if(false !== $result){
|
||||
cache('WST_HOME_MENUS',null);
|
||||
$parentId = input('post.parentId');
|
||||
if($parentId==0){
|
||||
// 获取其子集id
|
||||
$ids = $this->getChildId($menuId);
|
||||
$menuType = input('post.menuType/d');
|
||||
$result = $this->where(['menuId'=>['in',$ids],"dataFlag"=>1])->setField("menuType", $menuType);
|
||||
}
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
public function del(){
|
||||
$menuId = input('post.menuId/d',0);
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['menuId'=>$menuId]);
|
||||
$this->update($data,['parentId'=>$menuId]);
|
||||
if(false !== $result){
|
||||
cache('WST_HOME_MENUS',null);
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$where = [];
|
||||
$menuType = (int)input('menuType',-1);
|
||||
if($menuType!=-1)$where['a.menuType'] = $menuType;
|
||||
$where['a.parentId'] = (int)input('menuId',0);
|
||||
$where['a.dataFlag'] = 1;
|
||||
$rs = $this->alias('a')->join('__HOME_MENUS__ b','a.parentId = b.menuId','left')
|
||||
->field("a.menuId,a.menuType, a.parentId, a.menuName, a.menuUrl, a.menuOtherUrl, a.isShow, a.menuSort, b.menuName parentName")
|
||||
->where($where)
|
||||
->order('a.menuSort asc')
|
||||
->paginate(1000);
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示隐藏
|
||||
*/
|
||||
public function setToggle(){
|
||||
$menuId = input('post.menuId',0);
|
||||
// 获取其子集id
|
||||
$ids = $this->getChildId($menuId);
|
||||
$isShow = input('post.isShow/d');
|
||||
$result = $this->where(['menuId'=>['in',$ids],"dataFlag"=>1])->setField("isShow", $isShow);
|
||||
if(false !== $result){
|
||||
cache('WST_HOME_MENUS',null);
|
||||
return WSTReturn("设置成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取子集id
|
||||
*/
|
||||
private function getChildId($mId){
|
||||
$data = $this->field('menuId,parentId')->where('dataFlag=1')->select();
|
||||
$ids = $this->_getChildId($data,$mId,true);
|
||||
$ids[]=(int)$mId;
|
||||
return $ids;
|
||||
}
|
||||
private function _getChildId($data,$pId,$isClear=false){
|
||||
static $ids = [];
|
||||
if($isClear)$ids=[];
|
||||
foreach($data as $k=>$v){
|
||||
if($v['parentId']==$pId){
|
||||
$ids[] = $v['menuId'];
|
||||
$this->_getChildId($data,$v['menuId']);
|
||||
}
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取菜单列表
|
||||
*/
|
||||
public function getMenus($parentId = -1){
|
||||
$rs = $this->where(['parentId'=>$parentId,'dataFlag'=>1])->field('menuId, parentId, menuName, menuUrl,menuOtherUrl')->order('menuSort', 'asc')->select();
|
||||
if(count($rs)>0){
|
||||
foreach ($rs as $key =>$v){
|
||||
$children = self::getMenus($rs[$key]['menuId']);
|
||||
if(!empty($children)){
|
||||
$rs[$key]["children"] = $children;
|
||||
}
|
||||
}
|
||||
};
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改排序
|
||||
*/
|
||||
public function changeSort(){
|
||||
$id = (int)input('id');
|
||||
$menuSort = (int)input('menuSort');
|
||||
$rs = $this->where('menuId',$id)->setField('menuSort',$menuSort);
|
||||
if($rs!==false){
|
||||
cache('WST_HOME_MENUS',null);
|
||||
return WSTReturn('修改成功',1);
|
||||
}
|
||||
return WSTReturn('修改失败',-1);
|
||||
}
|
||||
}
|
43
hyhproject/admin/model/Hooks.php
Executable file
43
hyhproject/admin/model/Hooks.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 钩子业务处理
|
||||
*/
|
||||
class Hooks extends Base{
|
||||
|
||||
/**
|
||||
* 获取插件列表
|
||||
* @param string $addon_dir
|
||||
*/
|
||||
public function pageQuery(){
|
||||
|
||||
$keyWords = input("keyWords");
|
||||
$parentId = input('parentId/d',0);
|
||||
$where = array();
|
||||
$where["name"] = array("like","%$keyWords%");
|
||||
$page = $this->where($where)->order('`name` asc')->paginate(input('post.limit/d'))->toArray();
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存插件设置
|
||||
*/
|
||||
public function saveConfig(){
|
||||
$id = input("id/d",0);
|
||||
$config = $_POST['config'];
|
||||
$flag = $this->where(["addonId"=>$id])->setField('config',json_encode($config));
|
||||
if($flag !== false){
|
||||
return WSTReturn("保存成功", 1);
|
||||
}else{
|
||||
return WSTReturn('保存失败',-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
228
hyhproject/admin/model/Images.php
Executable file
228
hyhproject/admin/model/Images.php
Executable file
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 图片空间业务处理
|
||||
|
||||
*/
|
||||
|
||||
use wstmart\common\model\Aliyunoss;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Images extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取图片空间概况
|
||||
|
||||
*/
|
||||
|
||||
public function summary(){
|
||||
|
||||
$rs = Db::name('images')->where(['dataFlag'=>1])->field('fromTable,isUse,sum(imgSize) imgSize')->group('fromTable,isUse')
|
||||
|
||||
->order('fromTable asc')->select();
|
||||
|
||||
//获取目录名称
|
||||
|
||||
$rs2 = Db::name('datas')->where(['catId'=>3])->field('dataName,dataVal')->select();
|
||||
|
||||
$imagesMap = [];
|
||||
|
||||
foreach ($rs2 as $key =>$v){
|
||||
|
||||
$imagesMap[$v['dataVal']] = $v['dataName'];
|
||||
|
||||
}
|
||||
|
||||
$images = [];
|
||||
|
||||
foreach ($rs as $key =>$v){
|
||||
|
||||
if(!isset($images[$v['fromTable']]))$images[$v['fromTable']] = ['directory'=>'','data'=>['0'=>0,'1'=>0]];
|
||||
|
||||
if(isset($imagesMap[$v['fromTable']]))$images[$v['fromTable']]['directory'] = $imagesMap[$v['fromTable']];
|
||||
|
||||
$images[$v['fromTable']]['data'][$v['isUse']] = round($v['imgSize']/1024/1024,2);
|
||||
|
||||
}
|
||||
|
||||
$maxSize = 0;
|
||||
|
||||
foreach ($images as $key =>$v){
|
||||
|
||||
$size = (float)$v['data']['0']+(float)$v['data']['1'];
|
||||
|
||||
if($maxSize<$size)$maxSize = $size;
|
||||
|
||||
}
|
||||
|
||||
$images['_WSTSummary_'] = $maxSize;
|
||||
|
||||
return $images;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取记录
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$key = input('keyword');
|
||||
|
||||
$isUse = (int)input('isUse');
|
||||
|
||||
$where = ['fromTable'=>$key,'a.dataFlag'=>1];
|
||||
|
||||
if($isUse !=-1)$where['isUse'] = $isUse;
|
||||
|
||||
$page = $this->alias('a')->join('__USERS__ u','a.ownId=u.userId and fromType=0','left')
|
||||
|
||||
->join('__SHOPS__ s','s.userId=u.userId','left')
|
||||
|
||||
->join('__STAFFS__ sf','sf.staffId=a.ownId','left')
|
||||
|
||||
->where($where)->field('a.imgId,u.loginName,u.userType,fromType,sf.loginName loginName2,s.shopName,imgPath,imgSize,isUse,a.createTime')
|
||||
|
||||
->order('a.imgId desc')->paginate(input('post.limit/d'))->toArray();
|
||||
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
|
||||
if($v['fromType']==1){
|
||||
|
||||
$page['Rows'][$key]['loginName'] = $v['loginName2'];
|
||||
|
||||
}
|
||||
|
||||
$page['Rows'][$key]['imgSize'] = round($v['imgSize']/1024/1024,2);
|
||||
|
||||
unset($page['Rows'][$key]['loginName2']);
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除图片
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
$image = $this->where('imgId',$id)->find();
|
||||
|
||||
$rs = $this->where('imgId',$id)->update(['dataFlag'=>-1]);
|
||||
|
||||
if(false !== $rs){
|
||||
|
||||
$m = WSTConf('CONF.wstMobileImgSuffix');
|
||||
|
||||
$timgPath = str_replace('.','_thumb.',$image['imgPath']);
|
||||
|
||||
$mimgPath = str_replace('.',$m.'.',$image['imgPath']);
|
||||
|
||||
$mtimgPath = str_replace('.',$m.'_thumb.',$image['imgPath']);
|
||||
|
||||
|
||||
|
||||
if(file_exists(WSTRootPath()."/".$image['imgPath']))unlink(WSTRootPath()."/".$image['imgPath']);
|
||||
|
||||
if(file_exists(WSTRootPath()."/".$timgPath))unlink(WSTRootPath()."/".$timgPath);
|
||||
|
||||
if(file_exists(WSTRootPath()."/".$mimgPath))unlink(WSTRootPath()."/".$mimgPath);
|
||||
|
||||
if(file_exists(WSTRootPath()."/".$mtimgPath))unlink(WSTRootPath()."/".$mtimgPath);
|
||||
|
||||
//添加删除oss上的图片 mark 20180608
|
||||
|
||||
$imgurl = getImgUrl().$image['imgPath'];
|
||||
|
||||
if(file_exists_oss($image['imgPath']))model('Aliyunoss')->del($image['imgPath']);
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("删除失败");
|
||||
|
||||
}
|
||||
|
||||
//添加判断文件是否存在 mark 20180608 by zl
|
||||
|
||||
// public function file_exists_oss($object){
|
||||
|
||||
// $imgurl = getImgUrl().$object;
|
||||
|
||||
// $ch = curl_init();
|
||||
|
||||
// $timeout = 10;
|
||||
|
||||
// curl_setopt ($ch, CURLOPT_URL, $imgurl);
|
||||
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
|
||||
// curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
// curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
|
||||
|
||||
|
||||
// $contents = curl_exec($ch);
|
||||
|
||||
// if (preg_match("/404/", $contents)){
|
||||
|
||||
// return false;
|
||||
|
||||
// }else{
|
||||
|
||||
// return true;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// //说是在windows下可以,LINUX下无论图片在不在都返加TRUE
|
||||
|
||||
// // if(file_get_contents($imgurl,0,null,0,1)){
|
||||
|
||||
// // return true;
|
||||
|
||||
// // }else{
|
||||
|
||||
// // return false;
|
||||
|
||||
// // }
|
||||
|
||||
|
||||
|
||||
// // if(@fopen( $imgurl, 'r' )){
|
||||
|
||||
// // return true;
|
||||
|
||||
// // }else{
|
||||
|
||||
// // return false;
|
||||
|
||||
// // }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
109
hyhproject/admin/model/Index.php
Executable file
109
hyhproject/admin/model/Index.php
Executable file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 系统业务处理
|
||||
*/
|
||||
class Index extends Base{
|
||||
/**
|
||||
* 获取基础统计信息
|
||||
*/
|
||||
public function summary(){
|
||||
$data = [];
|
||||
$m = Model('common/Table');
|
||||
|
||||
$m->setTable('sys_summary');
|
||||
$toPayInfo = $m->getInfo(['id'=>1],'toPayFast,toPaySlow');
|
||||
$data['qlg']['fastPay'] = $toPayInfo['toPayFast'];
|
||||
$data['qlg']['slowPay'] = $toPayInfo['toPaySlow'];
|
||||
//预代付值
|
||||
$m->setTable('user_vouchers_summary');
|
||||
$data['qlg']['vouchersSummarySum'] = $m->getSum(['isDisabled'=>0],'expectedProductNum+expectedCouponsNum');
|
||||
//个体认证数
|
||||
$m->setTable('users');
|
||||
$data['qlg']['personalCount'] = $m->getCount(['authType'=>1]);
|
||||
//合作认证数
|
||||
$data['qlg']['companyCount'] = $m->getCount(['authType'=>2]);
|
||||
//合作商数
|
||||
$m->setTable('user_update');
|
||||
$data['qlg']['updateCount'] = $m->getCount(['status'=>1]);
|
||||
//已上线店铺数
|
||||
$m->setTable('shops');
|
||||
$data['qlg']['shopCount'] = $m->getCount(['status'=>1,'dataFlag'=>1]);
|
||||
//已消费用户数
|
||||
$data['qlg']['payCount'] = Db::name('orders')->where(['orderStatus'=>['BETWEEN','0,2']])->group('userId')->count();
|
||||
//已完成订单总额
|
||||
$m->setTable('orders');
|
||||
//$data['qlg']['orderSum'] = $m->getSum(['orderStatus'=>['BETWEEN','0,2']],'realTotalMoney');
|
||||
$data['qlg']['orderSum'] = $m->getSum(['orderStatus'=>2],'realTotalMoney');
|
||||
//个体待审核
|
||||
$m->setTable('auth_personal');
|
||||
$data['qlg']['personalWaitCount'] = $m->getCount(['status'=>0]);
|
||||
//合作待审核
|
||||
$m->setTable('auth_company');
|
||||
$data['qlg']['companyWaitCount'] = $m->getCount(['status'=>0]);
|
||||
//合作商待审核
|
||||
$m->setTable('user_update');
|
||||
$data['qlg']['updateWaitCount'] = $m->getCount(['status'=>0]);
|
||||
//产品券抵现
|
||||
$m->setTable('orders');
|
||||
$data['qlg']['productSum'] = $m->getSum(['orderStatus'=>['BETWEEN','0,2']],'productNum-productHandlingFee-productTaxFee');
|
||||
//优惠券抵现
|
||||
$data['qlg']['couponsSum'] = $m->getSum(['orderStatus'=>['BETWEEN','0,2']],'couponsNum-couponsHandlingFee-couponsTaxFee');
|
||||
//旺旺券抵现
|
||||
$data['qlg']['wangSum'] = $m->getSum(['orderStatus'=>['BETWEEN','0,2']],'wangNum');
|
||||
|
||||
//今日统计
|
||||
$data['tody'] = ['userType0'=>0,'userType1'=>0];
|
||||
$rs = Db::name('users')->where(['createTime'=>['like',date('Y-m-d').'%'],'dataFlag'=>1])->group('userType')->field('userType,count(userId) counts')->select();
|
||||
$tmp = [];
|
||||
if(!empty($rs)){
|
||||
foreach ($rs as $key => $v){
|
||||
$tmp[$v['userType']] = $v['counts'];
|
||||
}
|
||||
}
|
||||
if(isset($tmp['0']))$data['tody']['userType0'] = $tmp['0'];
|
||||
if(isset($tmp['1']))$data['tody']['userType1'] = $tmp['1'];
|
||||
$data['tody']['shopApplys'] = Db::name('shops')->whereTime('createTime','today')->where(['dataFlag'=>1,'status'=>0])->count();
|
||||
$data['tody']['compalins'] = Db::name('order_complains')->where(['complainTime'=>['like',date('Y-m-d').'%']])->count();
|
||||
$data['tody']['saleGoods'] = Db::name('goods')->where(['dataFlag'=>1,'goodsStatus'=>1,'isSale'=>1,'createTime'=>['like',date('Y-m-d').'%']])->count();
|
||||
$data['tody']['auditGoods'] = Db::name('goods')->where(['dataFlag'=>1,'goodsStatus'=>0,'isSale'=>1,'createTime'=>['like',date('Y-m-d').'%']])->count();
|
||||
$data['tody']['order'] = Db::name('orders')->where(['dataFlag'=>1,'createTime'=>['like',date('Y-m-d').'%']])->count();
|
||||
//商城统计
|
||||
$data['mall'] = ['userType0'=>1,'userType1'=>0];
|
||||
$rs = Db::name('users')->where(['dataFlag'=>1])->group('userType')->field('userType,count(userId) counts')->select();
|
||||
$tmp = [];
|
||||
if(!empty($rs)){
|
||||
foreach ($rs as $key => $v){
|
||||
$tmp[$v['userType']] = $v['counts'];
|
||||
}
|
||||
}
|
||||
if(isset($tmp['0']))$data['mall']['userType0'] = $tmp['0'];
|
||||
if(isset($tmp['1']))$data['mall']['userType1'] = $tmp['1'];
|
||||
$data['mall']['saleGoods'] = Db::name('goods')->where(['dataFlag'=>1,'goodsStatus'=>1,'isSale'=>1])->count();
|
||||
$data['mall']['auditGoods'] = Db::name('goods')->where(['dataFlag'=>1,'goodsStatus'=>0,'isSale'=>1])->count();
|
||||
$data['mall']['order'] = Db::name('orders')->where(['dataFlag'=>1])->count();
|
||||
$data['mall']['brands'] = Db::name('brands')->where(['dataFlag'=>1])->count();
|
||||
$data['mall']['appraise'] = Db::name('goods_appraises')->where(['dataFlag'=>1])->count();
|
||||
$rs = Db::query('select VERSION() as sqlversion');
|
||||
$data['MySQL_Version'] = $rs[0]['sqlversion'];
|
||||
$data['time']['startDate'] = date('Y-m-d',strtotime("-1month"));
|
||||
$data['time']['endDate'] = date('Y-m-d');
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存授权码
|
||||
*/
|
||||
public function saveLicense(){
|
||||
$data = [];
|
||||
$data['fieldValue'] = input('license');
|
||||
$result = model('SysConfigs')->where('fieldCode','mallLicense')->update($data);
|
||||
if(false !== $result){
|
||||
cache('WST_CONF',null);
|
||||
return WSTReturn("操作成功",1);
|
||||
}
|
||||
return WSTReturn("操作失败");
|
||||
}
|
||||
}
|
270
hyhproject/admin/model/Informs.php
Executable file
270
hyhproject/admin/model/Informs.php
Executable file
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use wstmart\admin\model\Goods as M;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 订单投诉业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Informs extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取举报列表
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$informStatus = (int)Input('informStatus',-1);
|
||||
|
||||
if($informStatus>-1)$where['o.informStatus']=$informStatus;
|
||||
|
||||
$where['o.dataFlag']=1;
|
||||
|
||||
$order = [];
|
||||
|
||||
$rs = Db::name('informs')->alias('o')
|
||||
|
||||
->field('o.*,s.shopId,s.shopName,u.userName,u.loginName,oc.goodsImg,oc.goodsId,oc.goodsName')
|
||||
|
||||
->join('__SHOPS__ s','o.shopId=s.shopId','inner','left')
|
||||
|
||||
->join('__USERS__ u','o.informTargetId=u.userId','inner')
|
||||
|
||||
->join('__GOODS__ oc','oc.goodsId=o.goodId','inner')
|
||||
|
||||
->where($where)
|
||||
|
||||
->order('informId desc')
|
||||
|
||||
->paginate()
|
||||
|
||||
->toArray();
|
||||
|
||||
$reason = WSTDatas('INFORMS_TYPE');
|
||||
|
||||
for($i=1;$i<=count($reason);$i++){
|
||||
|
||||
for($j=0;$j<count($rs['Rows']);$j++)
|
||||
|
||||
if($rs['Rows'][$j]['informType'] == $i){
|
||||
|
||||
$rs['Rows'][$j]['informType'] = $reason[$i]['dataName'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取举报信息
|
||||
|
||||
*/
|
||||
|
||||
public function getDetail(){
|
||||
|
||||
$informId = (int)Input('cid');
|
||||
|
||||
$data = $this->alias('oc')
|
||||
|
||||
->join('__SHOPS__ s','oc.shopId=s.shopId','inner','left')
|
||||
|
||||
->join('__USERS__ u','oc.informTargetId=u.userId','inner')
|
||||
|
||||
->where("oc.informId=$informId")
|
||||
|
||||
->find();
|
||||
|
||||
if($data){
|
||||
|
||||
if($data['informAnnex']!='')$data['informAnnex'] = explode(',',$data['informAnnex']);
|
||||
|
||||
$data['userName'] = ($data['userName']=='')?$data['loginName']:$data['userName'];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 处理
|
||||
|
||||
*/
|
||||
|
||||
public function finalHandle(){
|
||||
|
||||
$rd = array('status'=>-1,'msg'=>'无效的举报信息');
|
||||
|
||||
$informId = (int)Input('cid');
|
||||
|
||||
$finalResult = Input('finalResult');
|
||||
|
||||
$informStatus = Input('informStatus');
|
||||
|
||||
if($informId==0){
|
||||
|
||||
return WSTReturn('无效的举报信息',-1);
|
||||
|
||||
}
|
||||
|
||||
//判断是否已经处理过了
|
||||
|
||||
$rs = Db::name('informs')->alias('oc')
|
||||
|
||||
->field('oc.informTargetId,oc.informStatus,oc.goodId,oc.shopId,oc.informTargetId')
|
||||
|
||||
->where("oc.informId=$informId")
|
||||
|
||||
->find();
|
||||
|
||||
if($informStatus == 3){
|
||||
|
||||
try{
|
||||
|
||||
$data['isInform'] = 0;
|
||||
|
||||
$ers = Db::name('informs')->where('informTargetId='.$rs['informTargetId'])->delete();
|
||||
|
||||
$res = Db::name('users')->where('userId='.$rs['informTargetId'])->update($data);
|
||||
|
||||
if($ers!==false){
|
||||
|
||||
//发站内用户信息提醒
|
||||
|
||||
WSTSendMsg($rs['informTargetId'],"由于您被检验出恶意举报,您所有未处理举报商品已被取消并且已被禁止举报!",['from'=>3,'dataId'=>$informId]);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功',2);
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($rs['informStatus']!=1 && $rs['informStatus']!=2){
|
||||
|
||||
if($informStatus == 2){
|
||||
|
||||
$m = new M();
|
||||
|
||||
$m->illegal($rs['goodId'],1);
|
||||
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['finalHandleStaffId'] = session('WST_STAFF.staffId');
|
||||
|
||||
$data['informStatus'] = $informStatus;
|
||||
|
||||
$data['respondContent'] = Input('finalResult');
|
||||
|
||||
$data['finalHandleTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$ers = Db::name('informs')->where('informId='.$informId)->update($data);
|
||||
|
||||
if($ers!==false){
|
||||
|
||||
//发站内商家信息提醒
|
||||
|
||||
$shopId = $rs["shopId"];
|
||||
|
||||
$tpl = WSTMsgTemplates('SHOP_GOODS_INFORM');
|
||||
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
|
||||
$goodId = $rs['goodId'];
|
||||
|
||||
$goods = Db::name("goods")->where(["goodsId"=>$goodId])->field("goodsName")->find();
|
||||
|
||||
$find = ['${GOODS}'];
|
||||
|
||||
$replace = [$goods['goodsName']];
|
||||
|
||||
|
||||
|
||||
$msg = array();
|
||||
|
||||
$msg["shopId"] = $shopId;
|
||||
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
|
||||
$msg["msgType"] = 1;
|
||||
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']);
|
||||
|
||||
$msg["msgJson"] = ['from'=>3,'dataId'=>$informId];
|
||||
|
||||
model("common/MessageQueues")->add($msg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//发站内用户信息提醒
|
||||
|
||||
WSTSendMsg($rs['informTargetId'],"您举报的商品已有回复,请查看违规举报详情。",['from'=>3,'dataId'=>$informId]);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功',1);
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('操作失败,该举报状态已发生改变,请刷新后重试!',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
108
hyhproject/admin/model/LogMoneys.php
Executable file
108
hyhproject/admin/model/LogMoneys.php
Executable file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 资金流水日志业务处理
|
||||
*/
|
||||
class LogMoneys extends Base{
|
||||
/**
|
||||
* 用户资金列表
|
||||
*/
|
||||
public function pageQueryByUser(){
|
||||
$key = input('key');
|
||||
$where = [];
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = [];
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order[$sortArr[0]] = $sortArr[1];
|
||||
}
|
||||
$where['dataFlag'] = 1;
|
||||
$where['loginName'] = ['like','%'.$key.'%'];
|
||||
return model('users')->where($where)->field('loginName,userId,userName,userMoney,lockMoney')->order($order)->paginate(input('limit/d'));
|
||||
}
|
||||
/**
|
||||
* 商家资金列表
|
||||
*/
|
||||
public function pageQueryByShop(){
|
||||
$key = input('key');
|
||||
$where = [];
|
||||
$where['u.dataFlag'] = 1;
|
||||
$where['s.dataFlag'] = 1;
|
||||
$where['loginName'] = ['like','%'.$key.'%'];
|
||||
return Db::name('shops')->alias('s')->join('__USERS__ u','s.userId=u.userId','inner')->where($where)->field('loginName,shopId,shopName,shopMoney,s.lockMoney')->paginate(input('limit/d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
public function getUserInfoByType(){
|
||||
$type = (int)input('type',0);
|
||||
$id = (int)input('id');
|
||||
$data = [];
|
||||
if($type==1){
|
||||
$data = Db::name('shops')->alias('s')->join('__USERS__ u','s.userId=u.userId','inner')->where('shopId',$id)->field('shopId as userId,shopName as userName,loginName,1 as userType')->find();
|
||||
}else{
|
||||
$data = model('users')->where('userId',$id)->field('loginName,userId,userName,0 as userType')->find();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$userType = input('type');
|
||||
$userId = input('id');
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$where = [];
|
||||
if($startDate!='')$where['createTime'] = ['>=',$startDate." 00:00:00"];
|
||||
if($endDate!='')$where[' createTime'] = ['<=',$endDate." 23:59:59"];
|
||||
$where['targetType'] = $userType;
|
||||
$where['targetId'] = $userId;
|
||||
$page = $this->where($where)->order('id', 'desc')->paginate(input('limit/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
$page['Rows'][$key]['dataSrc'] = WSTLangMoneySrc($v['dataSrc']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
*/
|
||||
public function add($log){
|
||||
$log['createTime'] = date('Y-m-d H:i:s');
|
||||
$this->create($log);
|
||||
//dump($log);
|
||||
if($log['moneyType']==1){
|
||||
if($log['targetType']==1){
|
||||
if($log['payType']==='ect'){
|
||||
ectLog($log['targetId'],$log['money'],12,'结算',['userECT'=>['exp','userECT+'.$log['money']]],1);
|
||||
}else {
|
||||
Db::name('shops')->where(["shopId" => $log['targetId']])->setInc('shopMoney', $log['money']);
|
||||
}
|
||||
}else{
|
||||
if($log['payType']==='ect'){
|
||||
ectLog($log['targetId'],$log['money'],13,'退款',['userECT'=>['exp','userECT+'.$log['money']]],1);
|
||||
}else{
|
||||
Db::name('users')->where(["userId"=>$log['targetId']])->setInc('userMoney',$log['money']);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if($log['targetType']==1){
|
||||
Db::name('shops')->where(["shopId"=>$log['targetId']])->setDec('shopMoney',$log['money']);
|
||||
}else{
|
||||
if($log['payType']==='ect'){
|
||||
ectLog($log['targetId'],$log['money'],11,'购物',['userECT'=>['exp','userECT-'.$log['money']]],2);
|
||||
}else{
|
||||
Db::name('users')->where(["userId"=>$log['targetId']])->setDec('userMoney',$log['money']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
hyhproject/admin/model/LogOperates.php
Executable file
51
hyhproject/admin/model/LogOperates.php
Executable file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 操作日志业务处理
|
||||
*/
|
||||
class LogOperates extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$where = [];
|
||||
if($startDate!='')$where['l.operateTime'] = ['>=',$startDate." 00:00:00"];
|
||||
if($endDate!='')$where[' l.operateTime'] = ['<=',$endDate." 23:59:59"];
|
||||
return $mrs = Db::name('log_operates')->alias('l')->join('__STAFFS__ s',' l.staffId=s.staffId','left')
|
||||
->join('__MENUS__ m',' l.menuId=m.menuId','left')
|
||||
->where($where)
|
||||
->field('l.*,s.staffName,m.menuName')
|
||||
->order('l.operateId', 'desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增操作权限
|
||||
*/
|
||||
public function add($param){
|
||||
$data = [];
|
||||
$data['staffId'] = (int)session('WST_STAFF.staffId');
|
||||
$data['operateTime'] = date('Y-m-d H:i:s');
|
||||
$data['menuId'] = $param['menuId'];
|
||||
$data['operateDesc'] = $param['operateDesc'];
|
||||
$data['content'] = $param['content'];
|
||||
$data['operateUrl'] = $param['operateUrl'];
|
||||
$data['operateIP'] = $param['operateIP'];
|
||||
$this->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定的操作记录
|
||||
*/
|
||||
public function getById($id){
|
||||
$rs = $this->get($id);
|
||||
if(!empty($rs)){
|
||||
return WSTReturn('', 1,$rs);
|
||||
}
|
||||
return WSTReturn('对不起,没有找到该记录', -1);
|
||||
}
|
||||
}
|
41
hyhproject/admin/model/LogSms.php
Executable file
41
hyhproject/admin/model/LogSms.php
Executable file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 短信日志类
|
||||
*/
|
||||
class LogSms extends Base{
|
||||
|
||||
/**
|
||||
* 写入并发送短讯记录
|
||||
*/
|
||||
public function sendSMS($smsSrc,$userId,$phoneNumber,$params,$smsFunc){
|
||||
if((int)WSTConf('CONF.smsOpen')==0)return WSTReturn('未开启短信接口');
|
||||
$data = [];
|
||||
$data['smsSrc'] = $smsSrc;
|
||||
$data['smsUserId'] = $userId;
|
||||
$data['smsPhoneNumber'] = $phoneNumber;
|
||||
$data['smsContent'] = 'N/A';
|
||||
$data['smsReturnCode'] = '';
|
||||
$data['smsFunc'] = $smsFunc;
|
||||
$data['smsIP'] = request()->ip();
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$this->data($data)->save();
|
||||
$rdata = ['msg'=>'短信发送失败!','status'=>-1];
|
||||
hook('sendSMS',['phoneNumber'=>$phoneNumber,"params"=>$params,'smsId'=>$this->smsId,'status'=>&$rdata]);
|
||||
return $rdata;
|
||||
}
|
||||
|
||||
public function pageQuery(){
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$where = [];
|
||||
if($startDate!='')$where['l.createTime'] = ['>=',$startDate." 00:00:00"];
|
||||
if($endDate!='')$where[' l.createTime'] = ['<=',$endDate." 23:59:59"];
|
||||
return $mrs = Db::name('log_sms')->alias('l')->join('__STAFFS__ s',' l.smsUserId=s.staffId','left')
|
||||
->where($where)
|
||||
->field('l.*,s.staffName')
|
||||
->order('l.smsId', 'desc')->paginate(input('limit/d'));
|
||||
}
|
||||
}
|
24
hyhproject/admin/model/LogStaffLogins.php
Executable file
24
hyhproject/admin/model/LogStaffLogins.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 登录日志业务处理
|
||||
*/
|
||||
class LogStaffLogins extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$where = [];
|
||||
if($startDate!='')$where['l.loginTime'] = ['>=',$startDate." 00:00:00"];
|
||||
if($endDate!='')$where[' l.loginTime'] = ['<=',$endDate." 23:59:59"];
|
||||
return $mrs = Db::name('log_staff_logins')->alias('l')->join('__STAFFS__ s',' l.staffId=s.staffId','left')
|
||||
->where($where)
|
||||
->field('l.*,s.staffName')
|
||||
->order('l.loginId', 'desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
}
|
150
hyhproject/admin/model/Member.php
Executable file
150
hyhproject/admin/model/Member.php
Executable file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
use think\Validate;
|
||||
class Member extends Base{
|
||||
public function memberByPage(){
|
||||
$where='u.userStatus=1 AND u.dataFlag=1 AND u.userType=0';
|
||||
$start=input('startDate');
|
||||
$end=input('endDate');
|
||||
$loginName=input('loginName');
|
||||
$userPhone=input('userPhone');
|
||||
//dump($nonlogTime);
|
||||
if($loginName!='')$where.= ' AND u.loginName LIKE "%'.$loginName.'%"';
|
||||
if($userPhone!='')$where.= ' AND u.userPhone LIKE "%'.$userPhone.'%"';
|
||||
if($start!='' && $end!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$where.=' AND con.loginTime BETWEEN "'.$start.'" AND "'.$end.'"';
|
||||
}else if($start!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$where.= ' AND con.loginTime>="'.$start.'"';
|
||||
}else if($end!=''){
|
||||
$end = date('Y-m-d 00:00:00',strtotime(input('endDate')));
|
||||
$where.= ' AND con.loginTime<="'.$end.'"';
|
||||
}
|
||||
$result=Db::table('__USERS__')->alias('u')
|
||||
->join('(select l.*,count(l.userId) logNum from __LOG_USER_LOGINS__ l group by l.userId ) con','con.userId=u.userId','left')
|
||||
->join('__ORDERS__ o','u.userId=o.userId','left')
|
||||
->where($where)
|
||||
->field('u.loginName,trueName,u.userPhone,lastTime,u.createTime,con.logNum,count(o.userId) orderNum')
|
||||
->order('loginTime desc')
|
||||
->group('u.userId,trueName')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
//dump(db::getlastsql());
|
||||
//dump($result);
|
||||
return $result;
|
||||
}
|
||||
public function toExport(){
|
||||
$name="活跃用户数据列表";
|
||||
$where='u.userStatus=1 AND u.dataFlag=1 AND u.userType=0';
|
||||
$start=input('startDate');
|
||||
$end=input('endDate');
|
||||
$loginName=input('loginName');
|
||||
$userPhone=input('userPhone');
|
||||
//dump($nonlogTime);
|
||||
if($loginName!='')$where.= ' AND u.loginName LIKE "%'.$loginName.'%"';
|
||||
if($userPhone!='')$where.= ' AND u.userPhone LIKE "%'.$userPhone.'%"';
|
||||
if($start!='' && $end!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
}else if($start!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
}else if($end!=''){
|
||||
$end = date('Y-m-d 00:00:00',strtotime(input('endDate')));
|
||||
}else{
|
||||
$end = date('Y-m-d 23:59:59',strtotime("now"));
|
||||
}
|
||||
$where.=' AND con.loginTime BETWEEN "'.$start.'" AND "'.$end.'"';
|
||||
|
||||
$page=Db::table('__USERS__')->alias('u')
|
||||
->join('(select l.*,count(l.userId) logNum from __LOG_USER_LOGINS__ l group by l.userId ) con','con.userId=u.userId','left')
|
||||
->join('__ORDERS__ o','u.userId=o.userId','left')
|
||||
->where($where)
|
||||
->field('u.loginName,trueName,u.userPhone,lastTime,u.createTime,con.logNum,count(o.userId) orderNum')
|
||||
->order('loginTime desc')
|
||||
->group('u.userId')
|
||||
->select();
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A1', '登录账号')
|
||||
->setCellValue('B1', '真实姓名')
|
||||
->setCellValue('C1', '联系方式')
|
||||
->setCellValue('D1', '最后登录时间')
|
||||
->setCellValue('E1', '登陆次数')
|
||||
->setCellValue('F1', '订单数量')
|
||||
->setCellValue('G1', '创建时间');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:G1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['loginName'])
|
||||
->setCellValue('B'.$i, $page[$row]['trueName'])
|
||||
->setCellValue('C'.$i, $page[$row]['userPhone'])
|
||||
->setCellValue('D'.$i, $page[$row]['lastTime'])
|
||||
->setCellValue('E'.$i, $page[$row]['logNum'])
|
||||
->setCellValue('F'.$i, $page[$row]['orderNum'])
|
||||
->setCellValue('G'.$i, $page[$row]['createTime']);
|
||||
|
||||
}
|
||||
//输出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');
|
||||
}
|
||||
}
|
107
hyhproject/admin/model/Menus.php
Executable file
107
hyhproject/admin/model/Menus.php
Executable file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 菜单业务处理
|
||||
*/
|
||||
class Menus extends Base{
|
||||
protected $insert = ['dataFlag'=>1];
|
||||
/**
|
||||
* 获取菜单列表
|
||||
*/
|
||||
public function listQuery($parentId = -1){
|
||||
if($parentId==-1)return ['id'=>0,'name'=>WSTConf('CONF.mallName'),'isParent'=>true,'open'=>true];
|
||||
$rs = $this->where(['parentId'=>$parentId,'dataFlag'=>1])->field('menuId id,menuName name')->order('menuSort', 'asc')->select();
|
||||
if(count($rs)>0){
|
||||
foreach ($rs as $key =>$v){
|
||||
$rs[$key]['isParent'] = true;
|
||||
}
|
||||
};
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 获取菜单
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['dataFlag'=>1,'menuId'=>$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'menuId');
|
||||
$result = $this->validate('Menus.add')->save($data);
|
||||
if(false !== $result){
|
||||
WSTClearAllCache();
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑菜单
|
||||
*/
|
||||
public function edit(){
|
||||
$menuId = input('post.menuId/d');
|
||||
$result = $this->validate('Menus.edit')->allowField(['menuName','menuIcon','menuSort'])->save(input('post.'),['menuId'=>$menuId]);
|
||||
if(false !== $result){
|
||||
WSTClearAllCache();
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
public function del(){
|
||||
$menuId = input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['menuId'=>$menuId]);
|
||||
if(false !== $result){
|
||||
WSTClearAllCache();
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
public function getChildMenus($parentId,$data){
|
||||
$rdata = [];
|
||||
foreach($data as $v){
|
||||
if($v['parentId']==$parentId){
|
||||
$v['child'] = $this->getChildMenus($v['menuId'],$data);
|
||||
$rdata[] = $v;
|
||||
}
|
||||
}
|
||||
return $rdata;
|
||||
}
|
||||
/**
|
||||
* 获取用户菜单
|
||||
*/
|
||||
public function getMenus(){
|
||||
//用户权限判断
|
||||
$STAFF = session('WST_STAFF');
|
||||
$datas = [];
|
||||
$dbo = $this->alias('m')->join('__PRIVILEGES__ p','m.menuId= p.menuId and isMenuPrivilege=1 and p.dataFlag=1','left')
|
||||
->where(['m.dataFlag'=>1]);
|
||||
if((int)$STAFF['staffId']!=1){
|
||||
$dbo->where(['m.menuId'=>['in',$STAFF['menuIds']]]);
|
||||
}
|
||||
$menus = $dbo->field('m.menuId,m.menuName,privilegeUrl,m.parentId,m.menuIcon')
|
||||
->order('menuSort', 'asc')
|
||||
->select();
|
||||
if(!empty($menus)){
|
||||
foreach($menus as $key =>$v0){
|
||||
if($v0['parentId']==0){
|
||||
$v0['child'] = $this->getChildMenus($v0['menuId'],$menus);
|
||||
$datas[] = $v0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $datas;
|
||||
}
|
||||
}
|
206
hyhproject/admin/model/Messages.php
Executable file
206
hyhproject/admin/model/Messages.php
Executable file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商城消息业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Messages extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['m.dataFlag'] = 1;
|
||||
|
||||
$msgType = (int)input('msgType');
|
||||
|
||||
if($msgType >= 0)$where['msgType'] = $msgType;
|
||||
|
||||
$msgContent = input('msgContent');
|
||||
|
||||
if(!empty($msgContent))$where['msgContent']=['like',"%$msgContent%"];
|
||||
|
||||
$rs = $this->alias('m')
|
||||
|
||||
->field('m.*,u.loginName,s.shopName,st.loginName stName')
|
||||
|
||||
->join('__USERS__ u','m.receiveUserId=u.userId','left')
|
||||
|
||||
->join('__SHOPS__ s','m.receiveUserId=s.shopId','left')
|
||||
|
||||
->join('__STAFFS__ st','m.sendUserId=st.staffId','left')
|
||||
|
||||
->order('id desc')
|
||||
|
||||
->where($where)
|
||||
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
|
||||
foreach ($rs['Rows'] as $key => $v){
|
||||
|
||||
$rs['Rows'][$key]['msgContent'] = WSTMSubstr(strip_tags($v['msgContent']),0,140);
|
||||
|
||||
}
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['id'=>$id,'dataFlag'=>1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
// 图片记录
|
||||
|
||||
// $rule = '/src="\/(upload.*?)"/';
|
||||
|
||||
// preg_match_all($rule,$data['msgContent'],$result);
|
||||
|
||||
// mark 20180608 by zl
|
||||
|
||||
$rule = '/src=".*?\/(upload.*?)"/';
|
||||
|
||||
preg_match_all($rule,htmlspecialchars_decode($data['msgContent']),$result);
|
||||
|
||||
// 获取src数组
|
||||
|
||||
$imgs = $result[1];
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$data['sendUserId'] = session('WST_STAFF.staffId');
|
||||
|
||||
//判断发送对象
|
||||
|
||||
if($data['sendType']=='theUser'){
|
||||
|
||||
$ids = explode(',',$data['htarget']);
|
||||
|
||||
}
|
||||
|
||||
elseif($data['sendType']=='shop'){
|
||||
|
||||
//获取所有店铺的id
|
||||
|
||||
$ids = model('Shops')->getAllShopId();
|
||||
|
||||
}elseif($data['sendType']=='users'){
|
||||
|
||||
//获取所有用户id
|
||||
|
||||
$ids = model('users')->getAllUserId();
|
||||
|
||||
}
|
||||
|
||||
WSTUnset($data,'id,sendType,htarget');//删除多余字段
|
||||
|
||||
$list = [];
|
||||
|
||||
//去重
|
||||
|
||||
array_unique($ids);
|
||||
|
||||
foreach($ids as $v)
|
||||
|
||||
{
|
||||
|
||||
$data['receiveUserId'] = $v;
|
||||
|
||||
$data['msgType'] = 0;//后台手工发送消息
|
||||
|
||||
$list[] = $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->allowField(true)->saveAll($list);
|
||||
|
||||
$id = $result[0]['id'];//新增的第一条消息id
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $imgs);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = input('post.id/d');
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
$result = $this->update($data,['id'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
194
hyhproject/admin/model/MobileBtns.php
Executable file
194
hyhproject/admin/model/MobileBtns.php
Executable file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商家认证业务处理
|
||||
|
||||
*/
|
||||
|
||||
class MobileBtns extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$btnSrc = (int)input('btnSrc1',-1);
|
||||
|
||||
$btnName = input('btnName1');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($btnSrc>-1){
|
||||
|
||||
$where['btnSrc'] = $btnSrc;
|
||||
|
||||
}
|
||||
|
||||
if($btnName!=''){
|
||||
|
||||
$where['btnName'] = ['like',"%$btnName%"];
|
||||
|
||||
}
|
||||
|
||||
return $this->field(true)
|
||||
|
||||
->where($where)
|
||||
|
||||
->order('btnSrc asc,btnSort asc')
|
||||
|
||||
->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['id'=>$id]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['btnSort'] = (int)$data['btnSort'];
|
||||
|
||||
WSTUnset($data,'id');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('MobileBtns.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !==$result){
|
||||
|
||||
cache('WST_MOBILE_BTN',null);
|
||||
|
||||
$id = $this->id;
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $data['btnImg']);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['btnSort'] = (int)$data['btnSort'];
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, (int)$data['id'], $data['btnImg'], 'mobile_btns', 'btnImg');
|
||||
|
||||
$result = $this->validate('MobileBtns.edit')->allowField(true)->save($data,['id'=>(int)$data['id']]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('WST_MOBILE_BTN',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('post.id/d');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUnuseImage('mobile_btns','btnImg',$id);
|
||||
|
||||
$result = $this->where(['id'=>$id])->delete();
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('WST_MOBILE_BTN',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
echo $e->getMessage();
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
79
hyhproject/admin/model/Navs.php
Executable file
79
hyhproject/admin/model/Navs.php
Executable file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 导航管理业务处理
|
||||
*/
|
||||
class Navs extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
return $this->field(true)->order('id desc')->paginate(input('limit/d'));
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->get($id);
|
||||
}
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
WSTUnset($data,'id');
|
||||
$result = $this->validate('navs.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
cache('WST_NAVS',null);
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = input('post.id/d',0);
|
||||
//获取数据
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'createTime');
|
||||
$result = $this->validate('navs.edit')->allowField(true)->save($data,['id'=>$Id]);
|
||||
if(false !== $result){
|
||||
cache('WST_NAVS',null);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d');
|
||||
$result = $this->destroy($id);
|
||||
if(false !== $result){
|
||||
cache('WST_NAVS',null);
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置显示隐藏
|
||||
*/
|
||||
public function editiIsShow(){
|
||||
$id = input('post.id/d',0);
|
||||
$field = input('post.field');
|
||||
$val = input('post.val/d',0);
|
||||
if(!in_array($field,['isShow','isOpen']))return WSTReturn("非法的操作内容",-1);
|
||||
$result = Db::name('navs')->where(['id'=>['eq',$id]])->setField($field, $val);
|
||||
if(false !== $result){
|
||||
cache('WST_NAVS',null);
|
||||
return WSTReturn("设置成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
416
hyhproject/admin/model/OrderComplains.php
Executable file
416
hyhproject/admin/model/OrderComplains.php
Executable file
@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 订单投诉业务处理
|
||||
|
||||
*/
|
||||
|
||||
class OrderComplains extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取订单投诉列表
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$startDate = input('startDate');
|
||||
|
||||
$endDate = input('endDate');
|
||||
|
||||
$shopName = Input('shopName');
|
||||
|
||||
$orderNo = Input('orderNo');
|
||||
|
||||
$complainStatus = (int)Input('complainStatus',-1);
|
||||
|
||||
// 搜素条件
|
||||
|
||||
$areaId1 = (int)input('areaId1');
|
||||
|
||||
if($areaId1>0){
|
||||
|
||||
$where['s.areaIdPath'] = ['like',"$areaId1%"];
|
||||
|
||||
$areaId2 = (int)input("areaId1_".$areaId1);
|
||||
|
||||
if($areaId2>0)$where['s.areaIdPath'] = ['like',$areaId1."_"."$areaId2%"];
|
||||
|
||||
$areaId3 = (int)input("areaId1_".$areaId1."_".$areaId2);
|
||||
|
||||
if($areaId3>0)$where['s.areaId'] = $areaId3;
|
||||
|
||||
}
|
||||
|
||||
if($startDate!='' && $endDate!=''){
|
||||
|
||||
$where['oc.complainTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
|
||||
}else if($startDate!=''){
|
||||
|
||||
$where['oc.complainTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
|
||||
}else if($endDate!=''){
|
||||
|
||||
$where['oc.complainTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if($complainStatus>-1)$where['oc.complainStatus']=$complainStatus;
|
||||
|
||||
if($orderNo!='')$where['o.orderNo']=['like',"%$orderNo%"];
|
||||
|
||||
$where['o.dataFlag']=1;
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$order = [];
|
||||
|
||||
if($sort!=''){
|
||||
|
||||
$sortArr = explode('.',$sort);
|
||||
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
|
||||
}
|
||||
|
||||
$rs = Db::name('orders')->alias('o')
|
||||
|
||||
->field('oc.complainId,o.orderId,o.orderNo,o.orderSrc,s.shopName,u.userName,u.loginName,oc.complainTime,oc.complainStatus,oc.complainType,o.orderCode')
|
||||
|
||||
->join('__SHOPS__ s','o.shopId=s.shopId','inner','left')
|
||||
|
||||
->join('__USERS__ u','o.userId=u.userId','inner')
|
||||
|
||||
->join('__ORDER_COMPLAINS__ oc','oc.orderId=o.orderId','inner')
|
||||
|
||||
->where($where)
|
||||
|
||||
->order($order)
|
||||
|
||||
->order('complainId desc')
|
||||
|
||||
->paginate()
|
||||
|
||||
->toArray();
|
||||
|
||||
if(count($rs['Rows'])>0){
|
||||
|
||||
foreach ($rs['Rows'] as $key => $v){
|
||||
|
||||
$rs['Rows'][$key]['orderCodeTitle'] = WSTOrderCodeTitle($v['orderCode']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取订单详细信息
|
||||
|
||||
*/
|
||||
|
||||
public function getDetail(){
|
||||
|
||||
$complainId = (int)Input('cid');
|
||||
|
||||
$data = $this->alias('oc')
|
||||
|
||||
->field('oc.*,u.userName,u.loginName')
|
||||
|
||||
->join('__USERS__ u','oc.complainTargetId=u.userId','inner')
|
||||
|
||||
->where("oc.complainId=$complainId")
|
||||
|
||||
->find();
|
||||
|
||||
if($data){
|
||||
|
||||
if($data['complainAnnex']!='')$data['complainAnnex'] = explode(',',$data['complainAnnex']);
|
||||
|
||||
if($data['respondAnnex']!='')$data['respondAnnex'] = explode(',',$data['respondAnnex']);
|
||||
|
||||
$data['userName'] = ($data['userName']=='')?$data['loginName']:$data['userName'];
|
||||
|
||||
$rs = Db::name('orders')->alias('o')
|
||||
|
||||
->field('o.orderStatus,o.areaId,o.userAddress,o.orderNo,o.userName,s.shopName,o.userAddress')
|
||||
|
||||
->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
|
||||
->where(['o.dataFlag'=>1,
|
||||
|
||||
'o.orderId'=>$data['orderId']])
|
||||
|
||||
->find();
|
||||
|
||||
//获取日志信息
|
||||
|
||||
$rs['log'] = Db::name('log_orders')->alias('lo')
|
||||
|
||||
->field('lo.*,u.loginName,u.userType,s.shopName')
|
||||
|
||||
->join('__USERS__ u','lo.logUserId=u.userId','left')
|
||||
|
||||
->join('__SHOPS__ s','u.userType=1 and s.userId=u.userId','left')
|
||||
|
||||
->where(['orderId'=>$data['orderId']])
|
||||
|
||||
->select();
|
||||
|
||||
//获取相关商品
|
||||
|
||||
$rs['goodslist'] = Db::name('order_goods')->where(['orderId'=>$data['orderId']])->select();
|
||||
|
||||
$data['order'] = $rs;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 转交给应诉人应诉
|
||||
|
||||
*/
|
||||
|
||||
public function deliverRespond(){
|
||||
|
||||
$id = (int)Input('id');
|
||||
|
||||
if($id==0){
|
||||
|
||||
return WSTReturn('无效的投诉信息',-1);
|
||||
|
||||
}
|
||||
|
||||
//判断是否已经处理过了
|
||||
|
||||
$rs = $this->alias('oc')
|
||||
|
||||
->field('oc.complainStatus,oc.respondTargetId,o.orderNo,s.userId,o.shopId')
|
||||
|
||||
->join('__ORDERS__ o','oc.orderId=o.orderId','inner')
|
||||
|
||||
->join('__SHOPS__ s','o.shopId = s.shopId','left')
|
||||
|
||||
->where("complainId=$id")
|
||||
|
||||
->find();
|
||||
|
||||
if($rs['complainStatus']==0){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['needRespond'] = 1;
|
||||
|
||||
$data['complainStatus'] = 1;
|
||||
|
||||
$data['deliverRespondTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$ers = $this->where('complainId='.$id)->update($data);
|
||||
|
||||
if($ers!==false){
|
||||
|
||||
//发站内信息提醒
|
||||
|
||||
$tpl = WSTMsgTemplates('ORDER_NEW_COMPLAIN');
|
||||
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
|
||||
$find = ['${ORDER_NO}'];
|
||||
|
||||
$replace = [$rs['orderNo']];
|
||||
|
||||
$msg = array();
|
||||
|
||||
$msg["shopId"] = $rs["shopId"];
|
||||
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
|
||||
$msg["msgType"] = 1;
|
||||
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
|
||||
$msg["msgJson"] = ['from'=>3,'dataId'=>$id];
|
||||
|
||||
model("common/MessageQueues")->add($msg);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功',1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('操作失败,该投诉状态已发生改变,请刷新后重试!',-1);
|
||||
|
||||
}
|
||||
|
||||
return $rd;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 仲裁
|
||||
|
||||
*/
|
||||
|
||||
public function finalHandle(){
|
||||
|
||||
$rd = array('status'=>-1,'msg'=>'无效的投诉信息');
|
||||
|
||||
$complainId = (int)Input('cid');
|
||||
|
||||
if($complainId==0){
|
||||
|
||||
return WSTReturn('无效的投诉信息',-1);
|
||||
|
||||
}
|
||||
|
||||
//判断是否已经处理过了
|
||||
|
||||
$rs = $this->alias('oc')
|
||||
|
||||
->field('oc.complainStatus,s.userId shopUserId,o.shopId,o.userId,o.orderNo,o.orderId,oc.needRespond')
|
||||
|
||||
->join('__ORDERS__ o','oc.orderId=o.orderId','inner')
|
||||
|
||||
->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
|
||||
->where("complainId=$complainId")
|
||||
|
||||
->find();
|
||||
|
||||
if($rs['complainStatus']!=4){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['finalHandleStaffId'] = session('WST_STAFF.staffId');
|
||||
|
||||
$data['complainStatus'] = 4;
|
||||
|
||||
$data['finalResult'] = Input('finalResult');
|
||||
|
||||
$data['finalResultTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$ers = $this->where('complainId='.$complainId)->update($data);
|
||||
|
||||
if($ers!==false){
|
||||
|
||||
//需要卖家回应的话则给卖家也一条消息
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$tpl = WSTMsgTemplates('ORDER_HANDLED_COMPLAIN');
|
||||
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
|
||||
//发站内商家信息提醒
|
||||
|
||||
$find = ['${ORDER_NO}'];
|
||||
|
||||
$replace = [$rs['orderNo']];
|
||||
|
||||
$content = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
|
||||
if($rs['needRespond']==1){
|
||||
|
||||
$msg = array();
|
||||
|
||||
$msg["shopId"] = $rs["shopId"];
|
||||
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
|
||||
$msg["msgType"] = 1;
|
||||
|
||||
$msg["content"] = $content ;
|
||||
|
||||
$msg["msgJson"] = ['from'=>3,'dataId'=>$complainId];
|
||||
|
||||
model("common/MessageQueues")->add($msg);
|
||||
|
||||
}
|
||||
|
||||
//发站内用户信息提醒
|
||||
|
||||
WSTSendMsg($rs['userId'],$content,['from'=>3,'dataId'=>$complainId]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功',1);
|
||||
|
||||
}
|
||||
|
||||
}catch(\Exception $e){
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('操作失败,该投诉状态已发生改变,请刷新后重试!',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
723
hyhproject/admin/model/OrderRefunds.php
Executable file
723
hyhproject/admin/model/OrderRefunds.php
Executable file
@ -0,0 +1,723 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Loader;
|
||||
use think\Db;
|
||||
use Env;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 退款订单业务处理类
|
||||
*/
|
||||
class OrderRefunds extends Base{
|
||||
|
||||
/**
|
||||
* 获取用户退款订单列表
|
||||
*/
|
||||
public function refundPageQuery(){
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$where = ['o.dataFlag'=>1];
|
||||
$where['orderStatus'] = ['in',[-1,-3]];
|
||||
$orderNo = input('orderNo');
|
||||
$shopName = input('shopName');
|
||||
$deliverType = (int)input('deliverType',-1);
|
||||
$areaId1 = (int)input('areaId1');
|
||||
if($areaId1>0){
|
||||
$where['s.areaIdPath'] = ['like',"$areaId1%"];
|
||||
$areaId2 = (int)input("areaId1_".$areaId1);
|
||||
if($areaId2>0)$where['s.areaIdPath'] = ['like',$areaId1."_"."$areaId2%"];
|
||||
$areaId3 = (int)input("areaId1_".$areaId1."_".$areaId2);
|
||||
if($areaId3>0)$where['s.areaId'] = $areaId3;
|
||||
}
|
||||
$isRefund = (int)input('isRefund',-1);
|
||||
if($orderNo!='')$where['orderNo'] = ['like','%'.$orderNo.'%'];
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
|
||||
if($deliverType!=-1)$where['o.deliverType'] = $deliverType;
|
||||
if($isRefund!=-1)$where['o.isRefund'] = $isRefund;
|
||||
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['orf.createTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['orf.createTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['orf.createTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = [];
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order[$sortArr[0]] = $sortArr[1];
|
||||
}
|
||||
$page = Db::name('orders')->alias('o')->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
->join('__USERS__ u','o.userId=u.userId','left')
|
||||
->join('__ORDER_REFUNDS__ orf ','o.orderId=orf.orderId and refundStatus in (0,1,2)')
|
||||
->where($where)
|
||||
->field('orf.id refundId,o.orderId,o.orderNo,s.shopName,s.shopId,s.shopQQ,s.shopWangWang,o.goodsMoney,o.totalMoney,o.realTotalMoney,refundStatus,
|
||||
o.orderStatus,u.loginName,o.deliverType,payType,payFrom,o.orderStatus,orderSrc,orf.backMoney,orf.backProductNum,orf.backCouponsNum,orf.backWangNum,orf.refundRemark,isRefund,orf.createTime,o.orderCode,o.useScore')
|
||||
->order($order)
|
||||
->order('orf.createTime', 'desc')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
|
||||
if(count($page['Rows'])>0){
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
$page['Rows'][$key]['payType'] = WSTLangPayType($v['payType']);
|
||||
$page['Rows'][$key]['deliverType'] = WSTLangDeliverType($v['deliverType']==1);
|
||||
$page['Rows'][$key]['status'] = WSTLangOrderStatus($v['orderStatus']);
|
||||
$page['Rows'][$key]['orderCodeTitle'] = WSTOrderCodeTitle($v['orderCode']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 获取退款资料
|
||||
*/
|
||||
public function getInfoByRefund(){
|
||||
return $this->alias('orf')->join('__ORDERS__ o','orf.orderId=o.orderId')->where(['orf.id'=>(int)input('get.id'),'isRefund'=>0,'orderStatus'=>['in',[-1,-3]],'refundStatus'=>['in',[0,1]]])
|
||||
->field('orf.id refundId,orderNo,o.orderId,goodsMoney,refundReson,refundOtherReson,totalMoney,realTotalMoney,deliverMoney,payType,payFrom,backMoney,o.useScore,o.scoreMoney,tradeNo,orf.backProductNum,orf.backCouponsNum,orf.backWangNum,o.productNum,o.couponsNum,o.wangNum,o.moneyNum')
|
||||
->find();
|
||||
}
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
public function orderRefund(){
|
||||
$id = (int)input('post.id');
|
||||
if($id==0)return WSTReturn("操作失败!");
|
||||
$refund = $this->get($id);
|
||||
//if(empty($refund) || $refund->refundStatus!=1)return WSTReturn("该退款订单不存在或已退款!");
|
||||
if(empty($refund))return WSTReturn("该退款订单不存在或已退款!");
|
||||
$order = model('orders')->get($refund->orderId);
|
||||
// dump($order->payFrom);
|
||||
if($order->payType==1 && $order->payFrom=='wallets'){
|
||||
return $this->saveOrderRefund($refund,$order);
|
||||
}
|
||||
if($order->payType==1 && $order->payFrom=='ect'){
|
||||
return $this->ectOrderRefund($refund,$order);
|
||||
}
|
||||
if($order->payType==1 && $order->payFrom=='qlgpay'){
|
||||
return $this->qlgOrderRefund($refund,$order);
|
||||
}
|
||||
$content = input('post.content');
|
||||
$refundId = (int)input('post.id');
|
||||
$request_no = $order['orderNo'].$order['userId'];
|
||||
$backMoney = $refund["backMoney"];
|
||||
$tradeNo = $order['tradeNo'];
|
||||
$refund_reason = "订单【".$order['orderNo']."】退款";
|
||||
Loader::import('alipay.aop.AopClient', EXTEND_PATH,'.php');
|
||||
Loader::import('alipay.aop.request.AlipayTradeRefundRequest', EXTEND_PATH,'.php');
|
||||
// require Env::get('root_path') . 'extend/alipay/aop/AopClient.php';
|
||||
// require Env::get('root_path') . 'extend/alipay/aop/request/AlipayTradeRefundRequest.php';
|
||||
$payment = model('common/payments')->getPayment("app_alipays");
|
||||
//dump($payment);
|
||||
$aop = new \AopClient ();
|
||||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||||
$aop->appId = $payment["appId"];
|
||||
$aop->rsaPrivateKey = $payment["rsaPrivateKey"];
|
||||
$aop->alipayrsaPublicKey=$payment["alipayrsaPublicKey"];
|
||||
$aop->apiVersion = '1.0';
|
||||
$aop->signType = 'RSA2';
|
||||
$aop->postCharset='UTF-8';
|
||||
$aop->format='json';
|
||||
$request = new \AlipayTradeRefundRequest ();
|
||||
|
||||
$request->setBizContent("{" .
|
||||
"\"trade_no\":\"$tradeNo\"," .
|
||||
"\"refund_amount\":\"$backMoney\"," .
|
||||
"\"refund_reason\":\"$refund_reason\"," .
|
||||
"\"out_request_no\":\"$request_no\"" .
|
||||
" }");
|
||||
|
||||
$result = $aop->execute ( $request);
|
||||
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
||||
$resultCode = $result->$responseNode->code;
|
||||
if(!empty($resultCode) && $resultCode == 10000){
|
||||
if($result->$responseNode->fund_change=="Y"){
|
||||
$obj = array();
|
||||
$obj['refundTradeNo'] = $request_no;//退款单号
|
||||
$obj['content'] = $content;
|
||||
$obj['refundId'] = $refundId;
|
||||
$rs = $this->complateOrderRefund($obj);
|
||||
if($rs['status']==1){
|
||||
return WSTReturn("退款成功",1);
|
||||
}else{
|
||||
return WSTReturn("退款失败",1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$msg = $result->$responseNode->sub_msg;
|
||||
//dump($msg);
|
||||
return WSTReturn($msg,-1);
|
||||
}
|
||||
|
||||
}
|
||||
public function complateOrderRefund($obj){
|
||||
Db::startTrans();
|
||||
try{
|
||||
$content = $obj['content'];
|
||||
$refundTradeNo = $obj['refundTradeNo'];
|
||||
$refundId = $obj['refundId'];
|
||||
$refund = $this->get($refundId);
|
||||
$order = model('orders')->get($refund->orderId);
|
||||
if(!(in_array($order->orderStatus,[-1,-3]) && $order->isRefund==0 && ($order->isPay==1 || ($order->payType==0 && $order->useScore>0))))return WSTReturn("无效的退款订单!");
|
||||
//修改退款单信息
|
||||
$refund->refundRemark = $content;
|
||||
$refund->refundTime = date('Y-m-d H:i:s');
|
||||
$refund->refundStatus = 2;
|
||||
$refund->refundTradeNo = $refundTradeNo;
|
||||
$refund->save();
|
||||
//修改订单状态
|
||||
$order->isRefund = 1;
|
||||
$order->save();
|
||||
|
||||
if($order->useScore>0){
|
||||
$score = [];
|
||||
$score['userId'] = $order->userId;
|
||||
$score['score'] = $order->useScore;
|
||||
$score['dataSrc'] = 4;
|
||||
$score['dataId'] = $refund['id'];
|
||||
$score['dataRemarks'] = "返还订单【".$order->orderNo."】积分".$order->useScore."个";
|
||||
$score['scoreType'] = 1;
|
||||
model('common/UserScores')->add($score);
|
||||
}
|
||||
|
||||
//发送一条用户信息
|
||||
$tpl = WSTMsgTemplates('ORDER_REFUND_SUCCESS');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${REMARK}'];
|
||||
$replace = [$order->orderNo,$content];
|
||||
WSTSendMsg($order->userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>1,'dataId'=>$order->orderId]);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
WSTWxMessage(['CODE'=>'WX_ORDER_REFUND_SUCCESS','userId'=>$order->userId,'params'=>$params]);
|
||||
}
|
||||
//如果有钱剩下,那么就退回到商家钱包
|
||||
$shopMoneys = $order->realTotalMoney-$refund->backMoney;
|
||||
if($shopMoneys>0){
|
||||
//创建商家资金流水
|
||||
$lm = [];
|
||||
$lm['targetType'] = 1;
|
||||
$lm['targetId'] = $order->shopId;
|
||||
$lm['dataId'] = $order->orderId;
|
||||
$lm['dataSrc'] = 1;
|
||||
$lm['remark'] = '订单【'.$order->orderNo.'】退款,返回商家金额¥'.$shopMoneys."。";
|
||||
$lm['moneyType'] = 1;
|
||||
$lm['money'] = $shopMoneys;
|
||||
$lm['payType'] = 0;
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
model('LogMoneys')->add($lm);
|
||||
//发送商家信息
|
||||
$tpl = WSTMsgTemplates('ORDER_SHOP_REFUND');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${MONEY}'];
|
||||
$replace = [$order->orderNo,$shopMoneys];
|
||||
|
||||
$msg = array();
|
||||
$msg["shopId"] = $order->shopId;
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
$msg["msgType"] = 1;
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
$msg["msgJson"] = ['from'=>1,'dataId'=>$order->orderId];
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['SHOP_MONEY'] = $shopMoneys;
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
|
||||
$msg = array();
|
||||
$tplCode = "WX_ORDER_SHOP_REFUND";
|
||||
$msg["shopId"] = $order->shopId;
|
||||
$msg["tplCode"] = $tplCode;
|
||||
$msg["msgType"] = 4;
|
||||
$msg["paramJson"] = ['CODE'=>'WX_ORDER_SHOP_REFUND','params'=>$params];
|
||||
$msg["msgJson"] = "";
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("退款成功",1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("退款失败,请刷新后再重试");
|
||||
}
|
||||
|
||||
public function saveOrderRefund($refund,$order){
|
||||
$content = input('post.content');
|
||||
$lockCashMoney = $order["lockCashMoney"];
|
||||
if(!(in_array($order->orderStatus,[-1,-3]) && $order->isRefund==0 && ($order->isPay==1 || ($order->payType==0 && $order->useScore>0))))return WSTReturn("无效的退款订单!");
|
||||
Db::startTrans();
|
||||
try{
|
||||
//修改退款单信息
|
||||
$refund->refundRemark = $content;
|
||||
$refund->refundTime = date('Y-m-d H:i:s');
|
||||
$refund->refundStatus = 2;
|
||||
$refund->save();
|
||||
//修改订单状态
|
||||
$order->isRefund = 1;
|
||||
$order->save();
|
||||
//创建用户资金流水记录
|
||||
if($refund->backMoney>0){
|
||||
$lm = [];
|
||||
$lm['targetType'] = 0;
|
||||
$lm['targetId'] = $order->userId;
|
||||
$lm['dataId'] = $order->orderId;
|
||||
$lm['dataSrc'] = 1;
|
||||
$lm['remark'] = '订单【'.$order->orderNo.'】退款¥'.$refund->backMoney."。".(($content!='')?"【退款备注】:".$content:'');
|
||||
$lm['moneyType'] = 1;
|
||||
$lm['money'] = $refund->backMoney;
|
||||
$lm['payType'] = 0;
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
model('common/LogMoneys')->add($lm);
|
||||
//修改用户充值金额
|
||||
model('users')->where(["userId"=>$order->userId])->setInc("rechargeMoney",($lockCashMoney>$refund->backMoney)?$refund->backMoney:$lockCashMoney);
|
||||
}
|
||||
|
||||
if($order->useScore>0) {
|
||||
$score = [];
|
||||
$score['userId'] = $order->userId;
|
||||
$score['score'] = $order->useScore;
|
||||
$score['dataSrc'] = 4;
|
||||
$score['dataId'] = $refund['id'];
|
||||
$score['dataRemarks'] = "返还订单【" . $order->orderNo . "】积分" . $order->useScore . "个";
|
||||
$score['scoreType'] = 1;
|
||||
model('common/UserScores')->add($score);
|
||||
}
|
||||
//发送一条用户信息
|
||||
$tpl = WSTMsgTemplates('ORDER_REFUND_SUCCESS');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${REMARK}'];
|
||||
$replace = [$order->orderNo,$content];
|
||||
WSTSendMsg($order->userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>1,'dataId'=>$order->orderId]);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
WSTWxMessage(['CODE'=>'WX_ORDER_REFUND_SUCCESS','userId'=>$order->userId,'params'=>$params]);
|
||||
}
|
||||
//如果有钱剩下,那么就退回到商家钱包
|
||||
$shopMoneys = $order->realTotalMoney-$refund->backMoney;
|
||||
if($shopMoneys>0){
|
||||
//创建商家资金流水
|
||||
$lm = [];
|
||||
$lm['targetType'] = 1;
|
||||
$lm['targetId'] = $order->shopId;
|
||||
$lm['dataId'] = $order->orderId;
|
||||
$lm['dataSrc'] = 1;
|
||||
$lm['remark'] = '订单【'.$order->orderNo.'】退款,返回商家金额¥'.$shopMoneys."。";
|
||||
$lm['moneyType'] = 1;
|
||||
$lm['money'] = $shopMoneys;
|
||||
$lm['payType'] = 0;
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
model('LogMoneys')->add($lm);
|
||||
//dump($lm);
|
||||
//发送商家信息
|
||||
$tpl = WSTMsgTemplates('ORDER_SHOP_REFUND');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${MONEY}'];
|
||||
$replace = [$order->orderNo,$shopMoneys];
|
||||
|
||||
$msg = array();
|
||||
$msg["shopId"] = $order->shopId;
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
$msg["msgType"] = 1;
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
$msg["msgJson"] = ['from'=>1,'dataId'=>$order->orderId];
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['SHOP_MONEY'] = $shopMoneys;
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
|
||||
$msg = array();
|
||||
$tplCode = "WX_ORDER_SHOP_REFUND";
|
||||
$msg["shopId"] = $order->shopId;
|
||||
$msg["tplCode"] = $tplCode;
|
||||
$msg["msgType"] = 4;
|
||||
$msg["paramJson"] = ['CODE'=>'WX_ORDER_SHOP_REFUND','params'=>$params];
|
||||
$msg["msgJson"] = "";
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
}
|
||||
// die;
|
||||
Db::commit();
|
||||
return WSTReturn("退款成功",1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("退款失败,请刷新后再重试");
|
||||
}
|
||||
public function qlgOrderRefund($refund,$order){
|
||||
$content = input('post.content');
|
||||
//dump($refund);
|
||||
if(!(in_array($order->orderStatus,[-1,-3]) && $order->isRefund==0 && ($order->isPay==1 || ($order->payType==0 && $order->useScore>0))))return WSTReturn("无效的退款订单!");
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
//修改退款单信息
|
||||
$refund->refundRemark = $content;
|
||||
$refund->refundTime = date('Y-m-d H:i:s');
|
||||
$refund->refundStatus = 2;
|
||||
//修改订单状态
|
||||
$order->isRefund = 1;
|
||||
$order->save();
|
||||
$userId = $order->userId;
|
||||
//创建用户资金流水记录
|
||||
$um = Db::name('users');
|
||||
$lmm = Db::name('log_moneys');
|
||||
$nowTime = time();
|
||||
//记录各个券支出
|
||||
//产品券
|
||||
if($refund->backProductNum > 0){
|
||||
Model('common/LogMoneys')->addMoneyLog(0,$userId,$order->orderId,1,'交易订单【'.$order->orderNo.'】退款¥'.$refund->backProductNum,1,$refund->backProductNum,'qlgpay',1);
|
||||
}
|
||||
//优惠券
|
||||
if($refund->backCouponsNum > 0){
|
||||
Model('common/LogMoneys')->addMoneyLog(0,$userId,$order->orderId,1,'交易订单【'.$order->orderNo.'】退款¥'.$refund->backCouponsNum,1,$refund->backCouponsNum,'qlgpay',2);
|
||||
}
|
||||
//旺旺券
|
||||
if($refund->backWangNum > 0){
|
||||
Model('common/LogMoneys')->addMoneyLog(0,$userId,$order->orderId,1,'交易订单【'.$order->orderNo.'】退款¥'.$refund->backWangNum,1,$refund->backWangNum,'qlgpay',3);
|
||||
}
|
||||
//发送一条用户信息
|
||||
$tpl = WSTMsgTemplates('ORDER_REFUND_SUCCESS');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${REMARK}'];
|
||||
$replace = [$order->orderNo,$content];
|
||||
WSTSendMsg($order->userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>1,'dataId'=>$order->orderId]);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
WSTWxMessage(['CODE'=>'WX_ORDER_REFUND_SUCCESS','userId'=>$order->userId,'params'=>$params]);
|
||||
}
|
||||
//如果有钱剩下,那么就退回到商家钱包
|
||||
$userId=Db::name('shops')->where('shopId',$order->shopId)->value('userId');
|
||||
$backShopNum = round($order->productNum - $refund->backProductNum,2);
|
||||
if($backShopNum > 0){
|
||||
Model('common/LogMoneys')->addMoneyLog(1,$order->shopId,$order->orderId,1,'交易订单【'.$order->orderNo.'】退款剩余收入¥'.$backShopNum,1,$backShopNum,'qlgpay',1);
|
||||
}
|
||||
$backShopNum = round($order->couponsNum - $refund->backCouponsNum,2);
|
||||
if($backShopNum > 0){
|
||||
Model('common/LogMoneys')->addMoneyLog(1,$order->shopId,$order->orderId,1,'交易订单【'.$order->orderNo.'】退款剩余收入¥'.$backShopNum,1,$backShopNum,'qlgpay',2);
|
||||
}
|
||||
$backShopNum = round($order->wangNum - $refund->backWangNum,2);
|
||||
if($backShopNum > 0){
|
||||
Model('common/LogMoneys')->addMoneyLog(1,$order->shopId,$order->orderId,1,'交易订单【'.$order->orderNo.'】退款剩余收入¥'.$backShopNum,1,$backShopNum,'qlgpay',3);
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("退款成功",1);
|
||||
}catch (\Exception $e) {
|
||||
dump($e);
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("退款失败,请刷新后再重试");
|
||||
}
|
||||
public function ectOrderRefund($refund,$order){
|
||||
$content = input('post.content');
|
||||
$lockCashMoney = $order["lockCashMoney"];
|
||||
//dump($refund);
|
||||
if(!(in_array($order->orderStatus,[-1,-3]) && $order->isRefund==0 && ($order->isPay==1 || ($order->payType==0 && $order->useScore>0))))return WSTReturn("无效的退款订单!");
|
||||
|
||||
Db::startTrans();
|
||||
try{
|
||||
//修改退款单信息
|
||||
$refund->refundRemark = $content;
|
||||
$refund->refundTime = date('Y-m-d H:i:s');
|
||||
$refund->refundStatus = 2;
|
||||
//修改订单状态
|
||||
$order->isRefund = 1;
|
||||
$order->save();
|
||||
//创建用户资金流水记录
|
||||
$ectInfo=db('orders_ect')->where('orderId',$order['orderId'])->field('ectPrice,orderEctNum')->find();
|
||||
//获取退还给用户的ECT数量
|
||||
$ectNum=round(($refund->backMoney/$ectInfo['ectPrice']),2);
|
||||
if($ectNum>0){
|
||||
$lm = [];
|
||||
$lm['targetType'] = 0;
|
||||
$lm['targetId'] = $order->userId;
|
||||
$lm['dataId'] = $order->orderId;
|
||||
$lm['dataSrc'] = 1;
|
||||
$lm['remark'] = '订单【'.$order->orderNo.'】退ECT数量'.$ectNum."。".(($content!='')?"【退款备注】:".$content:'');
|
||||
$lm['moneyType'] = 1;
|
||||
$lm['money'] = $ectNum;
|
||||
$lm['payType'] = "ect";
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
model('common/LogMoneys')->add($lm);
|
||||
}
|
||||
if($order->useScore>0){
|
||||
$score = [];
|
||||
$score['userId'] = $order->userId;
|
||||
$score['score'] = $order->useScore;
|
||||
$score['dataSrc'] = 4;
|
||||
$score['dataId'] = $refund['id'];
|
||||
$score['dataRemarks'] = "返还订单【".$order->orderNo."】积分".$order->useScore."个";
|
||||
$score['scoreType'] = 1;
|
||||
model('common/UserScores')->add($score);
|
||||
}
|
||||
//发送一条用户信息
|
||||
$tpl = WSTMsgTemplates('ORDER_REFUND_SUCCESS');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${REMARK}'];
|
||||
$replace = [$order->orderNo,$content];
|
||||
WSTSendMsg($order->userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>1,'dataId'=>$order->orderId]);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
WSTWxMessage(['CODE'=>'WX_ORDER_REFUND_SUCCESS','userId'=>$order->userId,'params'=>$params]);
|
||||
}
|
||||
//如果有钱剩下,那么就退回到商家钱包,先获取总的ECT数量
|
||||
|
||||
$backShopEctNum=round(($ectInfo['orderEctNum']-$ectNum),2);
|
||||
if($backShopEctNum>0){
|
||||
//创建商家资金流水
|
||||
$userId=db('shops')->where('shopId',$order['shopId'])->value('userId');
|
||||
$l = [];
|
||||
$l['targetType'] = 1;
|
||||
$l['targetId'] = $userId;
|
||||
$l['dataId'] = $order->orderId;
|
||||
$l['dataSrc'] = 1;
|
||||
$l['remark'] = '订单【'.$order->orderNo.'】退款,返回商家ect数量:'.$backShopEctNum."。";
|
||||
$l['moneyType'] = 1;
|
||||
$l['money'] = $backShopEctNum;
|
||||
$l['payType'] = "ect";
|
||||
$l['createTime'] = date('Y-m-d H:i:s');
|
||||
model('LogMoneys')->add($l);
|
||||
//dump(Db::getlastsql());die;
|
||||
//发送商家信息
|
||||
$tpl = WSTMsgTemplates('ORDER_SHOP_REFUND');
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
$find = ['${ORDER_NO}','${MONEY}'];
|
||||
$replace = [$order->orderNo,$backShopEctNum];
|
||||
|
||||
$msg = array();
|
||||
$msg["shopId"] = $order->shopId;
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
$msg["msgType"] = 1;
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
$msg["msgJson"] = ['from'=>1,'dataId'=>$order->orderId];
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
//微信消息
|
||||
if((int)WSTConf('CONF.wxenabled')==1){
|
||||
$reasonData = WSTDatas('REFUND_TYPE',$refund->refundReson);
|
||||
$params = [];
|
||||
$params['ORDER_NO'] = $order->orderNo;
|
||||
$params['REASON'] = $reasonData['dataName'].(($refund->refundReson==10000)?" - ".$refund->refundOtherReson:"");
|
||||
$params['SHOP_MONEY'] = $backShopEctNum;
|
||||
$params['MONEY'] = $refund->backMoney.(($order['useScore']>0)?("【退回积分:".$order['useScore']."】"):"");
|
||||
|
||||
$msg = array();
|
||||
$tplCode = "WX_ORDER_SHOP_REFUND";
|
||||
$msg["shopId"] = $order->shopId;
|
||||
$msg["tplCode"] = $tplCode;
|
||||
$msg["msgType"] = 4;
|
||||
$msg["paramJson"] = ['CODE'=>'WX_ORDER_SHOP_REFUND','params'=>$params];
|
||||
$msg["msgJson"] = "";
|
||||
model("common/MessageQueues")->add($msg);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("退款成功",1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("退款失败,请刷新后再重试");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出订单
|
||||
*/
|
||||
public function toExport(){
|
||||
$name='退款订单表';
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$where = ['o.dataFlag'=>1];
|
||||
$where['orderStatus'] = ['in',[-1,-3]];
|
||||
$orderNo = input('orderNo');
|
||||
$shopName = input('shopName');
|
||||
$deliverType = (int)input('deliverType',-1);
|
||||
$areaId1 = (int)input('areaId1');
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['orf.createTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['orf.createTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['orf.createTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
$isRefund = (int)input('isRefund',-1);
|
||||
if($orderNo!='')$where['orderNo'] = ['like','%'.$orderNo.'%'];
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
if($deliverType!=-1)$where['o.deliverType'] = $deliverType;
|
||||
if($isRefund!=-1)$where['o.isRefund'] = $isRefund;
|
||||
|
||||
if($areaId1>0){
|
||||
$where['s.areaIdPath'] = ['like',"$areaId1%"];
|
||||
$areaId2 = (int)input("areaId1_".$areaId1);
|
||||
if($areaId2>0)$where['s.areaIdPath'] = ['like',$areaId1."_"."$areaId2%"];
|
||||
$areaId3 = (int)input("areaId1_".$areaId1."_".$areaId2);
|
||||
if($areaId3>0)$where['s.areaId'] = $areaId3;
|
||||
}
|
||||
$isRefund = (int)input('isRefund',-1);
|
||||
|
||||
// 排序
|
||||
$sort = input('sort');
|
||||
$order = [];
|
||||
if($sort!=''){
|
||||
$sortArr = explode('.',$sort);
|
||||
$order[$sortArr[0]] = $sortArr[1];
|
||||
}
|
||||
$page = Db::name('orders')->alias('o')->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
->join('__USERS__ u','o.userId=u.userId','left')
|
||||
->join('__ORDER_REFUNDS__ orf ','o.orderId=orf.orderId and refundStatus in (1,2)')
|
||||
->where($where)
|
||||
->field('orf.id refundId,o.orderId,o.orderNo,s.shopName,s.shopId,s.shopQQ,s.shopWangWang,o.goodsMoney,o.totalMoney,o.realTotalMoney,
|
||||
o.orderStatus,u.loginName,o.deliverType,payType,o.payFrom,o.orderStatus,orderSrc,orf.backMoney,orf.refundRemark,isRefund,orf.createTime,o.orderCode,o.useScore')
|
||||
->order($order)
|
||||
->order('orf.createTime', 'desc')
|
||||
->select();
|
||||
if(count($page)>0){
|
||||
foreach ($page as &$v){
|
||||
$v['payType'] = WSTLangPayType($v['payType']);
|
||||
$v['deliverType'] = WSTLangDeliverType($v['deliverType']==1);
|
||||
$v['status'] = WSTLangOrderStatus($v['orderStatus']);
|
||||
$v['orderCodeTitle'] = WSTOrderCodeTitle($v['orderCode']);
|
||||
}
|
||||
}
|
||||
|
||||
unset($v);
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->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', '退款状态')
|
||||
->setCellValue('K1', '退款备注');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:R1')->applyFromArray($styleArray);
|
||||
$reRefundInfo=['0'=>'未退款','1'=>'已退款'];
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
if($page[$row]['payFrom'] =='ect'){
|
||||
$page[$row]['payFrom'] = 'ECT';
|
||||
}else if($page[$row]['payFrom'] =='wallets'){
|
||||
$page[$row]['payFrom'] = '余额';
|
||||
}else if($page[$row]['payFrom'] =='app_alipays' || $page[$row]['payFrom'] =='alipays'){
|
||||
$page[$row]['payFrom'] = '支付宝';
|
||||
}else if($page[$row]['payFrom'] =='weixinpays'){
|
||||
$page[$row]['payFrom'] = '微信';
|
||||
}else if($page[$row]['payFrom'] =='cod'){
|
||||
$page[$row]['payFrom'] = '货到付款';
|
||||
}
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['orderNo'])
|
||||
->setCellValue('B'.$i, $page[$row]['loginName'])
|
||||
->setCellValue('C'.$i, $page[$row]['shopName'])
|
||||
->setCellValue('D'.$i, $page[$row]['orderCodeTitle'])
|
||||
->setCellValue('E'.$i, $page[$row]['deliverType'])
|
||||
->setCellValue('F'.$i, $page[$row]['payFrom'])
|
||||
->setCellValue('G'.$i, $page[$row]['realTotalMoney'])
|
||||
->setCellValue('H'.$i, $page[$row]['backMoney'])
|
||||
->setCellValue('I'.$i, $page[$row]['createTime'])
|
||||
->setCellValue('J'.$i, $reRefundInfo[$page[$row]['isRefund']])
|
||||
->setCellValue('K'.$i, $page[$row]['refundRemark']);
|
||||
}
|
||||
|
||||
//输出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');
|
||||
}
|
||||
}
|
478
hyhproject/admin/model/Orders.php
Executable file
478
hyhproject/admin/model/Orders.php
Executable file
@ -0,0 +1,478 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 订单业务处理类
|
||||
*/
|
||||
class Orders extends Base{
|
||||
/**
|
||||
* 获取用户订单列表
|
||||
*/
|
||||
public function pageQuery($orderStatus = 10000,$isAppraise = -1){
|
||||
$where = ['o.dataFlag'=>1];
|
||||
if($orderStatus!=10000){
|
||||
$where['orderStatus'] = $orderStatus;
|
||||
}
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$orderNo = input('orderNo');
|
||||
$shopName = input('shopName');
|
||||
$userPhone = input('userPhone');
|
||||
$userId = (int)input('userId');
|
||||
$payType = (int)input('payType',-1);
|
||||
$deliverType = (int)input('deliverType',-1);
|
||||
$sort = input('sort');
|
||||
$investmentStaff =htmlspecialchars(input('investmentStaff')); // mark
|
||||
if($isAppraise!=-1)$where['isAppraise'] = $isAppraise;
|
||||
if($orderNo!='')$where['orderNo'] = ['like','%'.$orderNo.'%'];
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
if($userPhone!='')$where['o.userPhone'] = ['like','%'.$userPhone.'%'];
|
||||
if($userId>0)$where['o.userId'] = $userId;
|
||||
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['o.createTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['o.createTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['o.createTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
$areaId1 = (int)input('areaId1');
|
||||
|
||||
if($areaId1>0){
|
||||
$where['s.areaIdPath'] = ['like',"$areaId1%"];
|
||||
$areaId2 = (int)input("areaId1_".$areaId1);
|
||||
if($areaId2>0)$where['s.areaIdPath'] = ['like',$areaId1."_"."$areaId2%"];
|
||||
$areaId3 = (int)input("areaId1_".$areaId1."_".$areaId2);
|
||||
if($areaId3>0)$where['s.areaId'] = $areaId3;
|
||||
}
|
||||
|
||||
if($deliverType!=-1)$where['o.deliverType'] = $deliverType;
|
||||
if($payType!=-1)$where['o.payType'] = $payType;
|
||||
$order = 'o.createTime desc';
|
||||
if($sort){
|
||||
$sort = str_replace('.',' ',$sort);
|
||||
$order = $sort;
|
||||
}
|
||||
//mark
|
||||
if($investmentStaff !=""){
|
||||
$where['se.investmentStaff'] = ['like',"%".$investmentStaff."%"];
|
||||
$where['orderStatus'] = 2;
|
||||
}
|
||||
// $page = $this->alias('o')->join('__USERS__ u','o.userId=u.userId','left')->join('__SHOPS__ s','o.shopId=s.shopId','left')->where($where)
|
||||
// ->field('o.orderId,o.orderNo,u.loginName,s.shopName,s.shopId,s.shopQQ,s.shopWangWang,o.goodsMoney,o.totalMoney,o.realTotalMoney,
|
||||
// o.orderStatus,o.userName,o.deliverType,payType,payFrom,o.orderStatus,orderSrc,o.createTime,o.orderCode')
|
||||
// ->order($order)
|
||||
// ->paginate(input('limit/d'))->toArray();
|
||||
//添加对接人员查询 mark 20180514
|
||||
$page = $this->alias('o')->join('__USERS__ u','o.userId=u.userId','left')->join('__SHOPS__ s','o.shopId=s.shopId','left')->join('__SHOP_EXTRAS__ se','o.shopId=se.shopId','left')->where($where)
|
||||
->field('o.orderId,o.orderNo,u.loginName,s.shopName,s.shopId,s.userId shopUserId,s.shopQQ,s.shopWangWang,o.goodsMoney,o.totalMoney,o.realTotalMoney,
|
||||
o.orderStatus,o.userName,o.payable,o.deliverType,o.productNum,o.couponsNum,o.wangNum,o.moneyNum,o.productHandlingFee,o.productTaxFee,o.couponsHandlingFee,o.couponsTaxFee,payType,payFrom,o.orderStatus,orderSrc,o.createTime,o.orderCode,se.investmentStaff')
|
||||
->order($order)
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
$page['Rows'][$key]['loginName'] = "【".$v['loginName']."】";
|
||||
$page['Rows'][$key]['userName'] = $v['userName'];
|
||||
$shopUserInfo = getUserInfo(['userId'=>$v['shopUserId']],'loginName');
|
||||
$page['Rows'][$key]['shopLoginName'] = "【".$shopUserInfo['loginName']."】";
|
||||
$page['Rows'][$key]['payType'] = WSTLangPayType($v['payType']);
|
||||
$page['Rows'][$key]['deliverType'] = WSTLangDeliverType($v['deliverType']==1);
|
||||
$page['Rows'][$key]['status'] = WSTLangOrderStatus($v['orderStatus']);
|
||||
$page['Rows'][$key]['orderCodeTitle'] = WSTOrderCodeTitle($v['orderCode']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 获取凭证
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getCertificate(){
|
||||
$certificateStatus = (int)input('post.certificateStatus');
|
||||
$shopName = input('post.shopName');
|
||||
$data = [];
|
||||
$m = Db::name('orders');
|
||||
$tm = Model('common/Table');
|
||||
$tm->setTable('shops');
|
||||
// $certificateStatus = 2;
|
||||
if($certificateStatus <=1){//未上传和不需上传的订单
|
||||
$where = ['certificateStatus'=>$certificateStatus,'orderStatus'=>2,'dataFlag'=>1];
|
||||
if($shopName){
|
||||
$shopIds = $tm->getColumn(['shopName'=>['LIKE','%'.$shopName.'%']],'shopId');
|
||||
$where = array_merge($where,['shopId'=>['IN',$shopIds]]);
|
||||
}
|
||||
$data = $m->where($where)->group('shopId')->field('shopId,sum(payable) payNum')->paginate(input('limit/d'))->toArray();
|
||||
foreach ($data['Rows'] as &$v) {
|
||||
$v['status'] = $certificateStatus;
|
||||
$v['list'] = $m->where($where)->where(['shopId'=>$v['shopId']])->field('orderId,orderNo,payable')->select();
|
||||
}
|
||||
}else{
|
||||
$where = ['status'=>$certificateStatus];
|
||||
if($shopName){
|
||||
$shopIds = $tm->getColumn(['shopName'=>['LIKE','%'.$shopName.'%']],'shopId');
|
||||
$where = array_merge($where,['shopId'=>['IN',$shopIds]]);
|
||||
}
|
||||
$data = Db::name('order_shop_certificate')->where($where)->field('*')->paginate(input('limit/d'))->toArray();
|
||||
foreach ($data['Rows'] as &$v) {
|
||||
$v['payNum'] = $m->where(['orderId'=>['IN',$v['orderIds']]])->sum('payable');
|
||||
$v['list'] = $m->where(['orderId'=>['IN',$v['orderIds']]])->field('orderId,orderNo,payable')->select();
|
||||
}
|
||||
}
|
||||
foreach ($data['Rows'] as &$val) {
|
||||
$val['shop'] = $tm->getInfo(['shopId'=>$val['shopId']],'shopName,phone');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
//凭证设置
|
||||
public function certificateSet(){
|
||||
$id = input('post.id');
|
||||
$status = input('post.status') + 2;
|
||||
$data['status'] = $status;
|
||||
$data['reasonsForRefusal'] = (string)input('post.reasonsForRefusal');
|
||||
$m = Model('common/Table');
|
||||
$m->setTable('order_shop_certificate');
|
||||
$orderIds = $m->getField(['id'=>$id],'orderIds');
|
||||
Db::startTrans();
|
||||
try{
|
||||
$m->setTable('order_shop_certificate');
|
||||
if(false !== $m->updateInfo(['id'=>$id],$data)){
|
||||
$m->setTable('orders');
|
||||
$m->updateInfo(['orderId'=>['IN',$orderIds]],['certificateStatus'=>$status]);
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("操作成功",1);
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("操作失败");
|
||||
}
|
||||
/**
|
||||
* 获取用户退款订单列表
|
||||
*/
|
||||
public function refundPageQuery(){
|
||||
$where = ['o.dataFlag'=>1];
|
||||
$where['orderStatus'] = ['in',[-1,-4]];
|
||||
$where['o.payType'] = 1;
|
||||
$orderNo = input('orderNo');
|
||||
$shopName = input('shopName');
|
||||
$deliverType = (int)input('deliverType',-1);
|
||||
$areaId1 = (int)input('areaId1');
|
||||
$areaId2 = (int)input('areaId2');
|
||||
$areaId3 = (int)input('areaId3');
|
||||
$isRefund = (int)input('isRefund',-1);
|
||||
if($orderNo!='')$where['orderNo'] = ['like','%'.$orderNo.'%'];
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
if($areaId1>0)$where['s.areaId1'] = $areaId1;
|
||||
if($areaId2>0)$where['s.areaId2'] = $areaId2;
|
||||
if($areaId3>0)$where['s.areaId3'] = $areaId3;
|
||||
if($deliverType!=-1)$where['o.deliverType'] = $deliverType;
|
||||
if($isRefund!=-1)$where['o.isRefund'] = $isRefund;
|
||||
$page = $this->alias('o')->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
->join('__ORDER_REFUNDS__ orf ','o.orderId=orf.orderId','left')
|
||||
->where($where)
|
||||
->field('o.orderId,o.orderNo,s.shopName,s.shopId,s.shopQQ,s.shopWangWang,o.goodsMoney,o.totalMoney,o.realTotalMoney,
|
||||
o.orderStatus,o.userName,o.deliverType,payType,payFrom,o.orderStatus,orderSrc,orf.refundRemark,isRefund,o.createTime')
|
||||
->order('o.createTime', 'desc')
|
||||
->paginate(input('pagesize/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
$page['Rows'][$key]['payType'] = WSTLangPayType($v['payType']);
|
||||
$page['Rows'][$key]['deliverType'] = WSTLangDeliverType($v['deliverType']==1);
|
||||
$page['Rows'][$key]['status'] = WSTLangOrderStatus($v['orderStatus']);
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 获取退款资料
|
||||
*/
|
||||
public function getInfoByRefund(){
|
||||
return $this->where(['orderId'=>(int)input('get.id'),'isRefund'=>0,'orderStatus'=>['in',[-1,-4]]])
|
||||
->field('orderNo,orderId,goodsMoney,totalMoney,realTotalMoney,deliverMoney,payType,payFrom,tradeNo')
|
||||
->find();
|
||||
}
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
public function orderRefund(){
|
||||
$id = (int)input('post.id');
|
||||
$content = input('post.content');
|
||||
if($id==0)return WSTReturn("操作失败!");
|
||||
$order = $this->where(['orderId'=>(int)input('post.id'),'payType'=>1,'isRefund'=>0,'orderStatus'=>['in',[-1,-4]]])
|
||||
->field('userId,orderNo,orderId,goodsMoney,totalMoney,realTotalMoney,deliverMoney,payType,payFrom,tradeNo')
|
||||
->find();
|
||||
if(empty($order))return WSTReturn("该订单不存在或已退款!");
|
||||
Db::startTrans();
|
||||
try{
|
||||
$order->isRefund = 1;
|
||||
$order->save();
|
||||
//修改用户账户金额
|
||||
Db::name('users')->where('userId',$order->userId)->setInc('userMoney',$order->realTotalMoney);
|
||||
//创建资金流水记录
|
||||
$lm = [];
|
||||
$lm['targetType'] = 0;
|
||||
$lm['targetId'] = $order->userId;
|
||||
$lm['dataId'] = $order->orderId;
|
||||
$lm['dataSrc'] = 1;
|
||||
$lm['remark'] = '订单【'.$order->orderNo.'】退款¥'.$order->realTotalMoney."。".(($content!='')?"【退款备注】:".$content:'');
|
||||
$lm['moneyType'] = 1;
|
||||
$lm['money'] = $order->realTotalMoney;
|
||||
$lm['payType'] = 0;
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
model('LogMoneys')->save($lm);
|
||||
//创建退款记录
|
||||
$data = [];
|
||||
$data['orderId'] = $id;
|
||||
$data['refundRemark'] = $content;
|
||||
$data['refundTime'] = date('Y-m-d H:i:s');
|
||||
$rs = Db::name('order_refunds')->insert($data);
|
||||
if(false !== $rs){
|
||||
//发送一条用户信息
|
||||
WSTSendMsg($order['userId'],"您的退款订单【".$order['orderNo']."】已处理,请留意账户到账情况。".(($content!='')?"【退款备注:".$content."】":""),['from'=>1,'dataId'=>$id]);
|
||||
Db::commit();
|
||||
return WSTReturn("操作成功",1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("操作失败,请刷新后再重试");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
*/
|
||||
public function getByView($orderId){
|
||||
$orders = $this->alias('o')->join('__EXPRESS__ e','o.expressId=e.expressId','left')
|
||||
->join('__ORDER_REFUNDS__ orf ','o.orderId=orf.orderId','left')
|
||||
->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
->join('__USERS__ u','o.userId=u.userId','left')
|
||||
->where('o.dataFlag=1 and o.orderId='.$orderId)
|
||||
->field('o.*,e.expressName,u.loginName,s.shopName,s.shopQQ,s.shopWangWang,orf.refundRemark,orf.refundTime,orf.backProductNum,orf.backCouponsNum,orf.backWangNum')->find();
|
||||
if(empty($orders))return WSTReturn("无效的订单信息");
|
||||
//获取订单信息
|
||||
$orders['log'] = Db::name('log_orders')->where('orderId',$orderId)->order('logId asc')->select();
|
||||
//获取订单商品
|
||||
$orders['goods'] = Db::name('order_goods')->where('orderId',$orderId)->order('id asc')->select();
|
||||
$orders['userCertificate'] = Db::name('order_certificate')->where(['orderId'=>$orderId,'isShop'=>0])->order('id desc')->select();
|
||||
//$orders['shopCertificate'] = Db::name('order_certificate')->where(['orderId'=>$orderId,'isShop'=>1])->order('id desc')->select();
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出订单
|
||||
*/
|
||||
public function toExport(){
|
||||
$name='订单表';
|
||||
$where = ['o.dataFlag'=>1];
|
||||
$orderStatus = (int)input('orderStatus',0);
|
||||
if($orderStatus==0){
|
||||
$name='待发货订单表';
|
||||
}else if($orderStatus==-2){
|
||||
$name='待付款订单表';
|
||||
}else if($orderStatus==1){
|
||||
$name='配送中订单表';
|
||||
}else if($orderStatus==10000){
|
||||
$name='订单列表';
|
||||
}else if($orderStatus==-1){
|
||||
$name='取消订单表';
|
||||
}else if($orderStatus==-3){
|
||||
$name='拒收订单表';
|
||||
}else if($orderStatus==2){
|
||||
$name='已收货订单表';
|
||||
}
|
||||
if($orderStatus!=10000){
|
||||
$where['o.orderStatus'] = $orderStatus;
|
||||
}
|
||||
$startDate = input('startDate');
|
||||
$endDate = input('endDate');
|
||||
$orderNo = input('orderNo');
|
||||
$shopName = input('shopName');
|
||||
$userPhone = input('userPhone');
|
||||
$userId = (int)input('userId');
|
||||
$payType = (int)input('payType',-1);
|
||||
$deliverType = (int)input('deliverType',-1);
|
||||
if($startDate!='' && $endDate!=''){
|
||||
$where['o.createTime'] = ['between',[$startDate.' 00:00:00',$endDate.' 23:59:59']];
|
||||
}else if($startDate!=''){
|
||||
$where['o.createTime'] = ['>=',$startDate.' 00:00:00'];
|
||||
}else if($endDate!=''){
|
||||
$where['o.createTime'] = ['<=',$endDate.' 23:59:59'];
|
||||
}
|
||||
if($orderNo!='')$where['orderNo'] = ['like','%'.$orderNo.'%'];
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
if($userPhone!='')$where['o.userPhone'] = ['like','%'.$userPhone.'%'];
|
||||
if($userId>0){
|
||||
$where['o.userId'] = $userId;
|
||||
$user = Db::name('users')->where('userId',$userId)->field('userName')->find();
|
||||
$name = $user['userName'].'的订单表';
|
||||
}
|
||||
$areaId1 = (int)input('areaId1');
|
||||
if($areaId1>0){
|
||||
$where['s.areaIdPath'] = ['like',"$areaId1%"];
|
||||
$areaId2 = (int)input("areaId1_".$areaId1);
|
||||
if($areaId2>0)$where['s.areaIdPath'] = ['like',$areaId1."_"."$areaId2%"];
|
||||
$areaId3 = (int)input("areaId1_".$areaId1."_".$areaId2);
|
||||
if($areaId3>0)$where['s.areaId'] = $areaId3;
|
||||
}
|
||||
|
||||
if($deliverType!=-1)$where['o.deliverType'] = $deliverType;
|
||||
if($payType!=-1)$where['o.payType'] = $payType;
|
||||
$page = $this->alias('o')->where($where)
|
||||
->join('__USERS__ u','o.userId=u.userId','left')
|
||||
->join('__SHOPS__ s','o.shopId=s.shopId','left')
|
||||
->join('__LOG_ORDERS__ lo','lo.orderId=o.orderId and lo.orderStatus in (-1,-3) ','left')
|
||||
->field('o.orderId,o.orderNo,u.loginName,s.shopName,s.shopId,s.shopQQ,s.shopWangWang,o.goodsMoney,o.totalMoney,o.realTotalMoney,o.deliverMoney,lo.logContent,o.orderStatus,o.userName,o.userAddress,o.userPhone,o.orderRemarks,o.invoiceClient,o.receiveTime,
|
||||
o.deliveryTime,o.deliverType,o.productNum,o.couponsNum,o.wangNum,o.moneyNum,o.productHandlingFee,o.productTaxFee,o.couponsHandlingFee,o.couponsTaxFee,payType,payFrom,o.orderStatus,orderSrc,o.commissionFee,o.createTime')
|
||||
->order('o.createTime desc')
|
||||
->select();
|
||||
if(count($page)>0){
|
||||
foreach ($page as $key => $v){
|
||||
$page[$key]['userName'] = "【".$v['loginName']."】".$v['userName'];
|
||||
$page[$key]['payTypeName'] = WSTLangPayType($v['payType']);
|
||||
$page[$key]['deliverType'] = WSTLangDeliverType($v['deliverType']==1);
|
||||
$page[$key]['status'] = WSTLangOrderStatus($v['orderStatus']);
|
||||
}
|
||||
}
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(16);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(16);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(26);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('Z')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:W1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:W1')->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', '发票信息')
|
||||
->setCellValue('K1', '订单总金额')
|
||||
->setCellValue('L1', '现金额')
|
||||
->setCellValue('M1', '旺旺券')
|
||||
->setCellValue('N1', '产品券')
|
||||
->setCellValue('O1', '产品券税')
|
||||
->setCellValue('P1', '产品券手续费')
|
||||
->setCellValue('Q1', '优惠券')
|
||||
->setCellValue('R1', '优惠券税')
|
||||
->setCellValue('S1', '优惠券手续费')
|
||||
->setCellValue('T1', '运费')
|
||||
->setCellValue('U1', '实付金额')
|
||||
->setCellValue('V1', '支付方式')
|
||||
->setCellValue('W1', '下单时间')
|
||||
->setCellValue('X1', '发货时间')
|
||||
->setCellValue('Y1', '收货时间')
|
||||
->setCellValue('Z1', '取消/拒收原因');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:U1')->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]['status'])
|
||||
->setCellValue('C'.$i, $page[$row]['shopName'])
|
||||
->setCellValue('D'.$i, $page[$row]['userName'])
|
||||
->setCellValue('E'.$i, $page[$row]['userAddress'])
|
||||
->setCellValue('F'.$i, $page[$row]['userPhone'])
|
||||
->setCellValue('G'.$i, $page[$row]['payTypeName'])
|
||||
->setCellValue('H'.$i, $page[$row]['deliverType'])
|
||||
->setCellValue('I'.$i, $page[$row]['orderRemarks'])
|
||||
->setCellValue('J'.$i, $page[$row]['invoiceClient'])
|
||||
->setCellValue('K'.$i, $page[$row]['totalMoney'])
|
||||
->setCellValue('L'.$i, $page[$row]['moneyNum'])
|
||||
->setCellValue('M'.$i, $page[$row]['wangNum'])
|
||||
->setCellValue('N'.$i, $page[$row]['productNum'])
|
||||
->setCellValue('O'.$i, $page[$row]['productTaxFee'])
|
||||
->setCellValue('P'.$i, $page[$row]['productHandlingFee'])
|
||||
->setCellValue('Q'.$i, $page[$row]['couponsNum'])
|
||||
->setCellValue('R'.$i, $page[$row]['couponsTaxFee'])
|
||||
->setCellValue('S'.$i, $page[$row]['couponsHandlingFee'])
|
||||
->setCellValue('T'.$i, $page[$row]['deliverMoney'])
|
||||
->setCellValue('U'.$i, $page[$row]['realTotalMoney'])
|
||||
->setCellValue('V'.$i, $page[$row]['payFrom'])
|
||||
->setCellValue('W'.$i, $page[$row]['createTime'])
|
||||
->setCellValue('X'.$i, $page[$row]['deliveryTime'])
|
||||
->setCellValue('Y'.$i, $page[$row]['receiveTime'])
|
||||
->setCellValue('Z'.$i, $page[$row]['logContent']);
|
||||
}
|
||||
|
||||
//输出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');
|
||||
}
|
||||
}
|
74
hyhproject/admin/model/Payments.php
Executable file
74
hyhproject/admin/model/Payments.php
Executable file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 支付管理业务处理
|
||||
*/
|
||||
class Payments extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
return $this->field(true)->order('id desc')->paginate(input('limit/d'));
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->get(['id'=>$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = input('post.id/d',0);
|
||||
//获取数据
|
||||
$data = input('post.');
|
||||
$data["payConfig"] = isset($data['payConfig'])?json_encode($data['payConfig']):"";
|
||||
$data['enabled']=1;
|
||||
$result = $this->validate('payments.edit')->allowField(true)->save($data,['id'=>$Id]);
|
||||
if(false !== $result){
|
||||
cache('WST_PAY_SRC',null);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d',0);
|
||||
$data = [];
|
||||
$data['enabled'] = 0;
|
||||
$result = $this->update($data,['id'=>$id]);
|
||||
if(false !== $result){
|
||||
cache('WST_PAY_SRC',null);
|
||||
return WSTReturn("卸载成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
//商家应用ect支付
|
||||
public function pay(){
|
||||
$data=[];
|
||||
$data['shopId']=input('id');
|
||||
$data['paymentsId']=6;
|
||||
$data['status']=input('status');
|
||||
//dump($data['shopId']);
|
||||
$row=db('shop_pay')->where('shopId',$data['shopId'])->find();
|
||||
if(!$row){
|
||||
$data['status']=1;
|
||||
db('shop_pay')->insert($data);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}
|
||||
if($data['status']==1){
|
||||
db('shop_pay')->where(['shopId'=>$data['shopId'],'paymentsId'=>$data['paymentsId']])
|
||||
->update(['status'=>0]);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}
|
||||
if($data['status']==0){
|
||||
db('shop_pay')->where(['shopId'=>$data['shopId'],'paymentsId'=>$data['paymentsId']])
|
||||
->update(['status'=>1]);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}
|
||||
}
|
||||
}
|
116
hyhproject/admin/model/Privileges.php
Executable file
116
hyhproject/admin/model/Privileges.php
Executable file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 权限业务处理
|
||||
*/
|
||||
class Privileges extends Base{
|
||||
/**
|
||||
* 加载指定菜单的权限
|
||||
*/
|
||||
public function listQuery($parentId){
|
||||
$rs = $this->where(['menuId'=>$parentId,'dataFlag'=>1])->order('privilegeId', 'asc')->select();
|
||||
return ['Rows'=>$rs,'Total'=>count($rs)];
|
||||
}
|
||||
/**
|
||||
* 获取指定权限
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['privilegeId'=>$id,'dataFlag'=>1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$result = $this->validate('Privileges.add')->allowField(true)->save(input('post.'));
|
||||
if(false !== $result){
|
||||
WSTClearAllCache();
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$id = input('post.id/d');
|
||||
$result = $this->validate('Privileges.edit')->allowField(true)->save(input('post.'),['privilegeId'=>$id]);
|
||||
if(false !== $result){
|
||||
WSTClearAllCache();
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d');
|
||||
$result = $this->where(['privilegeId'=>$id])->delete();
|
||||
if(false !== $result){
|
||||
WSTClearAllCache();
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测权限代码是否存在
|
||||
*/
|
||||
public function checkPrivilegeCode(){
|
||||
$privilegeId = input('privilegeId/d',0);
|
||||
$code = input('code');
|
||||
if($code=='')return WSTReturn("", 1);
|
||||
$where = [];
|
||||
$where["privilegeCode"] = $code;
|
||||
$where["dataFlag"] = 1;
|
||||
if($privilegeId>0){
|
||||
$where["privilegeId"] = ["<>",$privilegeId];
|
||||
}
|
||||
$rs = $this->where($where)->Count();
|
||||
if($rs==0)return WSTReturn("", 1);
|
||||
return WSTReturn("该权限代码已存在!", -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载权限并且标用户的权限
|
||||
*/
|
||||
public function listQueryByRole($id){
|
||||
$mrs = Db::name('menus')->alias('m')->join('__PRIVILEGES__ p','m.menuId= p.menuId and isMenuPrivilege=1 and p.dataFlag=1','left')
|
||||
->where(['parentId'=>$id,'m.dataFlag'=>1])
|
||||
->field('m.menuId id,m.menuName name,p.privilegeCode,1 as isParent')
|
||||
->order('menuSort', 'asc')
|
||||
->select();
|
||||
$prs = $this->where(['dataFlag'=>1,'menuId'=>$id])->field('privilegeId id,privilegeName name,privilegeCode,0 as isParent')->select();
|
||||
if($mrs){
|
||||
if($prs){
|
||||
foreach ($prs as $v){
|
||||
array_unshift($mrs,$v);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if($prs)$mrs = $prs;
|
||||
}
|
||||
if(!$mrs)return [];
|
||||
foreach ($mrs as $key =>$v){
|
||||
if($v['isParent']==1){
|
||||
$mrs[$key]['isParent'] = true;
|
||||
$mrs[$key]['open'] = true;
|
||||
}else{
|
||||
$mrs[$key]['id'] = 'p'.$v['id'];
|
||||
}
|
||||
}
|
||||
return $mrs;
|
||||
}
|
||||
/**
|
||||
* 加载全部权限
|
||||
*/
|
||||
public function getAllPrivileges(){
|
||||
return $this->where(['dataFlag'=>1])->field('menuId,privilegeName,privilegeCode,privilegeUrl,otherPrivilegeUrl')->select();
|
||||
}
|
||||
}
|
340
hyhproject/admin/model/Recommends.php
Executable file
340
hyhproject/admin/model/Recommends.php
Executable file
@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 推荐业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Recommends extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取已推荐商品
|
||||
|
||||
*/
|
||||
|
||||
public function listQueryByGoods(){
|
||||
|
||||
$dataType = (int)input('post.dataType');
|
||||
|
||||
$goodsCatId = (int)input('post.goodsCatId');
|
||||
|
||||
$rs = $this->alias('r')->join('__GOODS__ g','r.dataId=g.goodsId','inner')
|
||||
|
||||
->join('__SHOPS__ s','s.shopId=g.shopId','inner')
|
||||
|
||||
->where(['dataSrc'=>0,'dataType'=>$dataType,'r.goodsCatId'=>$goodsCatId])
|
||||
|
||||
->field('dataId,goodsName,shopName,dataSort,isSale,g.dataFlag,goodsStatus')->order('dataSort asc')->select();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
if($v['isSale']!=1 || $v['dataFlag']!=1 || $v['goodsStatus']!=1)$v['invalid'] = true;
|
||||
|
||||
$data[] = $v;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 推荐商品
|
||||
|
||||
*/
|
||||
|
||||
public function editGoods(){
|
||||
|
||||
$ids = input('post.ids');
|
||||
|
||||
$dataType = (int)input('post.dataType');
|
||||
|
||||
$goodsCatId = (int)input('post.goodsCatId');
|
||||
|
||||
$ids = explode(',',$ids);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$this->where(['dataSrc'=>0,'dataType'=>$dataType,'goodsCatId'=>$goodsCatId])->delete();
|
||||
|
||||
if(!empty($ids)){
|
||||
|
||||
//查看商品是否有效
|
||||
|
||||
$rs = Db::name('goods')->where(['goodsStatus'=>1,'dataFlag'=>1,'goodsId'=>['in',$ids]])->field('goodsId')->select();
|
||||
|
||||
if(!empty($rs)){
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
$tmp = [];
|
||||
|
||||
$tmp['goodsCatId'] = $goodsCatId;
|
||||
|
||||
$tmp['dataSrc'] = 0;
|
||||
|
||||
$tmp['dataType'] = $dataType;
|
||||
|
||||
$tmp['dataId'] = $v['goodsId'];
|
||||
|
||||
$tmp['dataSort'] = (int)input('post.ipt'.$v['goodsId']);
|
||||
|
||||
$data[] = $tmp;
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($data);
|
||||
|
||||
}
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("提交成功", 1);
|
||||
|
||||
}catch(\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('提交失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取已推荐店铺
|
||||
|
||||
*/
|
||||
|
||||
public function listQueryByShops(){
|
||||
|
||||
$dataType = (int)input('post.dataType');
|
||||
|
||||
$goodsCatId = (int)input('post.goodsCatId');
|
||||
|
||||
$rs = $this->alias('r')->join('__SHOPS__ s','r.dataId=s.shopId','inner')
|
||||
|
||||
->where(['dataSrc'=>1,'dataType'=>$dataType,'r.goodsCatId'=>$goodsCatId])
|
||||
|
||||
->field('dataId,shopSn,shopName,dataSort,shopStatus,dataFlag')->order('dataSort asc')->select();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
if($v['dataFlag']!=1 || $v['shopStatus']!=1)$v['invalid'] = true;
|
||||
|
||||
$data[] = $v;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 推荐店铺
|
||||
|
||||
*/
|
||||
|
||||
public function editShops(){
|
||||
|
||||
$ids = input('post.ids');
|
||||
|
||||
$dataType = (int)input('post.dataType');
|
||||
|
||||
$goodsCatId = (int)input('post.goodsCatId');
|
||||
|
||||
$ids = explode(',',$ids);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$this->where(['dataSrc'=>1,'dataType'=>$dataType,'goodsCatId'=>$goodsCatId])->delete();
|
||||
|
||||
if(!empty($ids)){
|
||||
|
||||
//查看商品是否有效
|
||||
|
||||
$rs = Db::name('shops')->where(['shopStatus'=>1,'dataFlag'=>1,'shopId'=>['in',$ids]])->field('shopId')->select();
|
||||
|
||||
if(!empty($rs)){
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
$tmp = [];
|
||||
|
||||
$tmp['goodsCatId'] = $goodsCatId;
|
||||
|
||||
$tmp['dataSrc'] = 1;
|
||||
|
||||
$tmp['dataType'] = $dataType;
|
||||
|
||||
$tmp['dataId'] = $v['shopId'];
|
||||
|
||||
$tmp['dataSort'] = (int)input('post.ipt'.$v['shopId']);
|
||||
|
||||
$data[] = $tmp;
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($data);
|
||||
|
||||
}
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("提交成功", 1);
|
||||
|
||||
}catch(\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('提交失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取已推荐品牌
|
||||
|
||||
*/
|
||||
|
||||
public function listQueryByBrands(){
|
||||
|
||||
$dataType = (int)input('post.dataType');
|
||||
|
||||
$goodsCatId = (int)input('post.goodsCatId');
|
||||
|
||||
$rs = $this->alias('r')->join('__BRANDS__ s','r.dataId=s.brandId','inner')
|
||||
|
||||
->where(['dataSrc'=>2,'dataType'=>$dataType,'r.goodsCatId'=>$goodsCatId])
|
||||
|
||||
->field('dataId,brandName,dataSort,dataFlag')->order('dataSort asc')->select();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
if($v['dataFlag']!=1)$v['invalid'] = true;
|
||||
|
||||
$data[] = $v;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 推荐品牌
|
||||
|
||||
*/
|
||||
|
||||
public function editBrands(){
|
||||
|
||||
$ids = input('post.ids');
|
||||
|
||||
$dataType = (int)input('post.dataType');
|
||||
|
||||
$goodsCatId = (int)input('post.goodsCatId');
|
||||
|
||||
$ids = explode(',',$ids);
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$this->where(['dataSrc'=>2,'dataType'=>$dataType,'goodsCatId'=>$goodsCatId])->delete();
|
||||
|
||||
if(!empty($ids)){
|
||||
|
||||
//查看商品是否有效
|
||||
|
||||
$rs = Db::name('brands')->where(['dataFlag'=>1,'brandId'=>['in',$ids]])->field('brandId')->select();
|
||||
|
||||
if(!empty($rs)){
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($rs as $key => $v){
|
||||
|
||||
$tmp = [];
|
||||
|
||||
$tmp['goodsCatId'] = $goodsCatId;
|
||||
|
||||
$tmp['dataSrc'] = 2;
|
||||
|
||||
$tmp['dataType'] = $dataType;
|
||||
|
||||
$tmp['dataId'] = $v['brandId'];
|
||||
|
||||
$tmp['dataSort'] = (int)input('post.ipt'.$v['brandId']);
|
||||
|
||||
$data[] = $tmp;
|
||||
|
||||
}
|
||||
|
||||
$this->saveAll($data);
|
||||
|
||||
}
|
||||
|
||||
WSTClearAllCache();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("提交成功", 1);
|
||||
|
||||
}catch(\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('提交失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
497
hyhproject/admin/model/Reports.php
Executable file
497
hyhproject/admin/model/Reports.php
Executable file
@ -0,0 +1,497 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 报表业务处理
|
||||
*/
|
||||
class Reports extends Base{
|
||||
/**
|
||||
* 获取商品销售统计
|
||||
*/
|
||||
public function topSaleGoodsByPage(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$startTime = strtotime(input('startDate'));
|
||||
$endTime =strtotime(input('endDate'));
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
$shopName = input('post.shopName');
|
||||
$goodsName = input('post.goodsName');
|
||||
$where='(payType=0 or (payType=1 and isPay=1)) and o.dataFlag=1';
|
||||
if($shopName)$where.=' AND shopName like "%'.$shopName.'%"';
|
||||
if($goodsName)$where.=' AND g.goodsName like "%'.$goodsName.'%"';
|
||||
if($goodsCatIdPath !='')$where.=' AND g.goodsCatIdPath like "%'.$goodsCatIdPath.'%"';
|
||||
$rs= Db::field('og.goodsId,g.goodsName,goodsSn,s.shopId,shopName,sum(og.goodsNum) goodsNum,og.goodsImg,count(og.goodsId)orderNum,pageNum,goodsCatIdPath')
|
||||
->name('order_goods')->alias('og')
|
||||
->join('(select p.*,count(p.goodsId) pageNum from __PAGE_VIEW__ p group by p.goodsId ) con','con.goodsId=og.goodsId','left')
|
||||
->join('__ORDERS__ o','og.orderId=o.orderId','left')
|
||||
->join('__GOODS__ g','og.goodsId=g.goodsId','left')
|
||||
->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->order('goodsNum desc')
|
||||
->whereTime('o.createTime','between',[$start,$end])
|
||||
->where($where)
|
||||
->group('og.goodsId,g.goodsName,goodsSn,s.shopId,shopName,og.goodsImg')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 获取店铺销售统计
|
||||
*/
|
||||
public function topShopSalesByPage(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$shopName = input('shopName');
|
||||
$where='(payType=0 or (payType=1 and isPay=1)) and o.dataFlag=1';
|
||||
if($shopName)$where.=' AND shopName like "%'.$shopName.'%"';
|
||||
$rs = Db::field('s.shopId,s.shopImg,s.shopName,sum(o.totalMoney) totalMoney,count(o.shopId) orderNum,s.userId')
|
||||
->name('shops')->alias('s')
|
||||
->join('__ORDERS__ o','s.shopId=o.shopId')
|
||||
->order('totalMoney desc,orderNum desc')
|
||||
->whereTime('o.createTime','between',[$start,$end])
|
||||
->where($where)
|
||||
->group('o.shopId')
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
foreach($rs['Rows'] as $k=>$v){
|
||||
$onLineArr = Db::name('orders')
|
||||
->whereTime('createTime','between',[$start,$end])
|
||||
->field('sum(totalMoney) totalMoney,sum(realTotalMoney) realTotalMoney')
|
||||
->where('payType=1 and isPay=1 and dataFlag=1 and orderStatus=2')
|
||||
->where(['shopId'=>$v['shopId']])
|
||||
->find();
|
||||
$rs['Rows'][$k]['onLinePayMoney'] = (float)$onLineArr['totalMoney'];// 在线支付总金额
|
||||
$rs['Rows'][$k]['onLinePayTrueMoney'] = (float)$onLineArr['realTotalMoney'];// 在线支付实际金额
|
||||
$rs['Rows'][$k]['offLinePayMoney'] = (float)Db::name('orders')
|
||||
->whereTime('createTime','between',[$start,$end])
|
||||
->where('payType=0 and dataFlag=1 and orderStatus=2')
|
||||
->where(['shopId'=>$v['shopId']])
|
||||
->value('sum(totalMoney)');;// 货到付款金额
|
||||
$rs['Rows'][$k]['ectNum']=db('user_ect_log')->where(['userId'=>$v['userId'],'ectType'=>12])->value('sum(ectNum)ectNum');
|
||||
}
|
||||
return $rs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取销售额
|
||||
*/
|
||||
public function statSales(){
|
||||
$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);
|
||||
$rs = Db::field('left(createTime,10) createTime,orderSrc,sum(totalMoney) totalMoney')->name('orders')->whereTime('createTime','between',[$start,$end])
|
||||
->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),orderSrc')->select();
|
||||
$rdata = [];
|
||||
if(count($rs)>0){
|
||||
$days = [];
|
||||
$payTypes = [0,1,2,3,4];
|
||||
$tmp = [];
|
||||
foreach($rs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp[$v['orderSrc']."_".$v['createTime']] = $v['totalMoney'];
|
||||
}
|
||||
$rdata['map'] = ['p0'=>0,'p1'=>0,'p2'=>0,'p3'=>0,'p4'=>0];
|
||||
foreach($days as $v){
|
||||
$total = 0;
|
||||
foreach($payTypes as $p){
|
||||
$pv = isset($tmp[$p."_".$v])?$tmp[$p."_".$v]:0;
|
||||
$rdata['p'.$p][] = (float)$pv;
|
||||
$total = $total + (float)$pv;
|
||||
$rdata['map']['p'.$p] = $rdata['map']['p'.$p] + (float)$pv;
|
||||
}
|
||||
$rdata['total'][] = $total;
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
}
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单统计
|
||||
*/
|
||||
public function statOrders(){
|
||||
$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);
|
||||
$rs = Db::field('left(createTime,10) createTime,orderSrc,count(orderId) orderNum')->name('orders')->whereTime('createTime','between',[$start,$end])
|
||||
->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),orderSrc')->select();
|
||||
$rdata = [];
|
||||
if(count($rs)>0){
|
||||
$days = [];
|
||||
$payTypes = [0,1,2,3,4];
|
||||
$tmp = [];
|
||||
foreach($rs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp[$v['orderSrc']."_".$v['createTime']] = $v['orderNum'];
|
||||
}
|
||||
$rdata['map'] = ['p0'=>0,'p1'=>0,'p2'=>0,'p3'=>0,'p4'=>0];
|
||||
foreach($days as $v){
|
||||
$total = 0;
|
||||
foreach($payTypes as $p){
|
||||
$pv = isset($tmp[$p."_".$v])?$tmp[$p."_".$v]:0;
|
||||
$rdata['p'.$p][] = (float)$pv;
|
||||
$total = $total + (float)$pv;
|
||||
$rdata['map']['p'.$p] = $rdata['map']['p'.$p] + (float)$pv;
|
||||
}
|
||||
$rdata['total'][] = $total;
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
}
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
/*首页获取订单数量*/
|
||||
public function getOrders(){
|
||||
$data = cache('orderData');
|
||||
if(empty($data)){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$payType = -1;
|
||||
$rs = Db::field('left(createTime,10) createTime,orderSrc,count(orderId) orderNum')->name('orders')->whereTime('createTime','between',[$start,$end])
|
||||
->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),orderSrc')->select();
|
||||
$rdata = [];
|
||||
if(count($rs)>0){
|
||||
$days = [];
|
||||
$tmp = [];
|
||||
$payTypes = [0,1,2,3,4];
|
||||
foreach($rs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp[$v['orderSrc']."_".$v['createTime']] = $v['orderNum'];
|
||||
}
|
||||
foreach($days as $v){
|
||||
$total = 0;
|
||||
foreach($payTypes as $p){
|
||||
$pv = isset($tmp[$p."_".$v])?$tmp[$p."_".$v]:0;
|
||||
$total = $total + (float)$pv;
|
||||
}
|
||||
$rdata['total'][] = $total;
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
cache('orderData',$rdata,7200);
|
||||
}
|
||||
}else{
|
||||
$rdata = cache('orderData');
|
||||
}
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
/**
|
||||
* 获取新增用户
|
||||
*/
|
||||
public function statNewUser(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$urs = Db::field('left(createTime,10) createTime,count(userId) userNum')
|
||||
->name('users')
|
||||
->whereTime('createTime','between',[$start,$end])
|
||||
->where(['dataFlag'=>1,'userType'=>0])
|
||||
->order('createTime asc')
|
||||
->group('left(createTime,10)')
|
||||
->select();
|
||||
$srs = Db::field('left(createTime,10) createTime,count(shopId) userNum')
|
||||
->name('shops')
|
||||
->whereTime('createTime','between',[$start,$end])
|
||||
->where(['dataFlag'=>1])
|
||||
->order('createTime asc')
|
||||
->group('left(createTime,10)')
|
||||
->select();
|
||||
$rdata = [];
|
||||
$days = [];
|
||||
$tmp = [];
|
||||
if(count($urs)>0){
|
||||
foreach($urs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp["0_".$v['createTime']] = $v['userNum'];
|
||||
}
|
||||
}
|
||||
if(count($srs)>0){
|
||||
foreach($srs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp["1_".$v['createTime']] = $v['userNum'];
|
||||
}
|
||||
}
|
||||
sort($days);
|
||||
foreach($days as $v){
|
||||
$rdata['u0'][] = isset($tmp['0_'.$v])?$tmp['0_'.$v]:0;
|
||||
$rdata['u1'][] = isset($tmp['1_'.$v])?$tmp['1_'.$v]:0;
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
/**
|
||||
* 会员登录统计
|
||||
*/
|
||||
public function statUserLogin(){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$prefix = config('database.prefix');
|
||||
$sql ='select createTime,userType,count(userId) userNum from (
|
||||
SELECT left(loginTime,10) createTime,`userType`,u.userId
|
||||
FROM `'.$prefix.'users` `u` INNER JOIN `'.$prefix.'log_user_logins` `lg` ON `u`.`userId`=`lg`.`userId`
|
||||
WHERE `loginTime` BETWEEN "'.$start.'" AND "'.$end.'" AND ( dataFlag=1 )
|
||||
GROUP BY left(loginTime,10),userType,lg.userId
|
||||
) a GROUP BY createTime, userType ORDER BY createTime asc ';
|
||||
$rs = Db::query($sql);
|
||||
$rdata = [];
|
||||
if(count($rs)>0){
|
||||
$days = [];
|
||||
$tmp = [];
|
||||
foreach($rs as $key => $v){
|
||||
if(!in_array($v['createTime'],$days))$days[] = $v['createTime'];
|
||||
$tmp[$v['userType']."_".$v['createTime']] = $v['userNum'];
|
||||
}
|
||||
foreach($days as $v){
|
||||
$rdata['u0'][] = isset($tmp['0_'.$v])?$tmp['0_'.$v]:0;
|
||||
$rdata['u1'][] = isset($tmp['1_'.$v])?$tmp['1_'.$v]:0;
|
||||
}
|
||||
$rdata['days'] = $days;
|
||||
}
|
||||
return WSTReturn('',1,$rdata);
|
||||
}
|
||||
/**
|
||||
* 导出商品销售订单
|
||||
*/
|
||||
public function toExportGoods(){
|
||||
$name='商品销售统计表';
|
||||
$start = input('startDate');
|
||||
$end = input('endDate');
|
||||
$where=[];
|
||||
$shopName = input('shopName');
|
||||
$goodsName = input('goodsName');
|
||||
$goodsCatIdPath = input('goodsCatIdPath');
|
||||
if($goodsCatIdPath !='')$where['g.goodsCatIdPath'] = ['like','%'.$goodsCatIdPath.'%'];
|
||||
if($shopName!='')$where['shopName'] = ['like','%'.$shopName.'%'];
|
||||
if($goodsName!='')$where['g.goodsName'] = ['like','%'.$goodsName.'%'];
|
||||
if($start!='' && $end!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$where['o.createTime'] = ['between',[$start.' 00:00:00',$end.' 23:59:59']];
|
||||
}else if($start!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$where['o.createTime'] = ['>=',$start.' 00:00:00'];
|
||||
}else if($end!=''){
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$where['o.createTime'] = ['<=',$end.' 23:59:59'];
|
||||
}
|
||||
$page=Db::field('og.goodsId,g.goodsName,goodsSn,s.shopId,shopName,sum(og.goodsNum) goodsNum,og.goodsImg,count(og.goodsId)orderNum,pageNum')
|
||||
->name('order_goods')->alias('og')
|
||||
->join('(select p.*,count(p.goodsId) pageNum from __PAGE_VIEW__ p group by p.goodsId ) con','con.goodsId=og.goodsId','left')
|
||||
->join('__ORDERS__ o','og.orderId=o.orderId','left')
|
||||
->join('__GOODS__ g','og.goodsId=g.goodsId','left')
|
||||
->join('__SHOPS__ s','g.shopId=s.shopId','left')
|
||||
->order('goodsNum desc')
|
||||
->where($where)
|
||||
->where('(payType=0 or (payType=1 and isPay=1)) and o.dataFlag=1')
|
||||
->group('og.goodsId,g.goodsName,goodsSn,s.shopId,shopName,og.goodsImg')
|
||||
->select();
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A1', '商品ID')
|
||||
->setCellValue('B1', '商品编号')
|
||||
->setCellValue('C1', '商品名称')
|
||||
->setCellValue('D1', '商品销量')
|
||||
->setCellValue('E1', '所属店铺')
|
||||
->setCellValue('F1', '订单总数')
|
||||
->setCellValue('G1', '浏览总数');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:G1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['goodsId'])
|
||||
->setCellValue('B'.$i, chunk_split($page[$row]['goodsSn']))
|
||||
->setCellValue('C'.$i, $page[$row]['goodsName'])
|
||||
->setCellValue('D'.$i, $page[$row]['goodsNum'])
|
||||
->setCellValue('E'.$i, $page[$row]['shopName'])
|
||||
->setCellValue('F'.$i, $page[$row]['orderNum'])
|
||||
->setCellValue('G'.$i, $page[$row]['pageNum']);
|
||||
|
||||
}
|
||||
//输出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');
|
||||
}
|
||||
/**
|
||||
* 导出商品销售订单
|
||||
*/
|
||||
public function toExportShop(){
|
||||
$name='店铺销售统计表';
|
||||
$start = input('startDate');
|
||||
$end = input('endDate');
|
||||
$shopName = input('shopName');
|
||||
$wh='(payType=0 or (payType=1 and isPay=1)) and o.dataFlag=1';
|
||||
if($shopName)$wh.=' AND shopName like "%'.$shopName.'%"';
|
||||
$where=[];
|
||||
if($start!='' && $end!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$where['o.createTime'] = ['between',[$start.' 00:00:00',$end.' 23:59:59']];
|
||||
}else if($start!=''){
|
||||
$start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||||
$where['o.createTime'] = ['>=',$start.' 00:00:00'];
|
||||
}else if($end!=''){
|
||||
$end = date('Y-m-d 23:59:59',strtotime(input('endDate')));
|
||||
$where['o.createTime'] = ['<=',$end.' 23:59:59'];
|
||||
}
|
||||
$page=Db::field('s.shopId,s.shopImg,s.shopName,sum(o.totalMoney) totalMoney,count(o.orderId) orderNum')
|
||||
->name('shops')->alias('s')
|
||||
->join('__ORDERS__ o','s.shopId=o.shopId')
|
||||
->order('totalMoney desc,orderNum desc')
|
||||
->where($where)
|
||||
->where($wh)
|
||||
->group('o.shopId')
|
||||
->select();
|
||||
|
||||
foreach($page as $k=>$v){
|
||||
$onLineArr = Db::name('orders')->alias('o')
|
||||
->where($where)
|
||||
->field('sum(totalMoney) totalMoney,sum(realTotalMoney) realTotalMoney')
|
||||
->where('payType=1 and isPay=1 and dataFlag=1 and orderStatus=2')
|
||||
->where(['shopId'=>$v['shopId']])
|
||||
->find();
|
||||
$page[$k]['onLinePayMoney'] = (float)$onLineArr['totalMoney'];// 在线支付总金额
|
||||
$page[$k]['onLinePayTrueMoney'] = (float)$onLineArr['realTotalMoney'];// 在线支付实际金额
|
||||
$page[$k]['offLinePayMoney'] = (float)Db::name('orders')->alias('o')
|
||||
->where($where)
|
||||
->where('payType=0 and dataFlag=1 and orderStatus=2')
|
||||
->where(['shopId'=>$v['shopId']])
|
||||
->value('sum(totalMoney)');;// 货到付款金额
|
||||
}
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A1', '店铺名称')
|
||||
->setCellValue('B1', '订单总金额')
|
||||
->setCellValue('C1', '订单总数')
|
||||
->setCellValue('D1', '在线支付总金额')
|
||||
->setCellValue('E1', '在线支付实际金额')
|
||||
->setCellValue('F1', '货到付款金额');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:E1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['shopName'])
|
||||
->setCellValue('B'.$i, $page[$row]['totalMoney'])
|
||||
->setCellValue('C'.$i, $page[$row]['orderNum'])
|
||||
->setCellValue('D'.$i, $page[$row]['onLinePayMoney'])
|
||||
->setCellValue('E'.$i, $page[$row]['onLinePayTrueMoney'])
|
||||
->setCellValue('F'.$i, $page[$row]['offLinePayMoney']);
|
||||
|
||||
}
|
||||
//输出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');
|
||||
}
|
||||
}
|
75
hyhproject/admin/model/Roles.php
Executable file
75
hyhproject/admin/model/Roles.php
Executable file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 角色志业务处理
|
||||
*/
|
||||
class Roles extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
return $this->where('dataFlag',1)->field('roleId,roleName,roleDesc')->paginate(input('limit/d'));
|
||||
}
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function listQuery(){
|
||||
return $this->where('dataFlag',1)->field('roleId,roleName')->select();
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['roleId'=>$id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色权限
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['dataFlag'=>1,'roleId'=>$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$result = $this->validate('Roles.add')->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$id = input('post.roleId/d');
|
||||
$result = $this->validate('Roles.edit')->allowField(true)->save(input('post.'),['roleId'=>$id]);
|
||||
if(false !== $result){
|
||||
$staffRoleId = (int)session('WST_STAFF.staffRoleId');
|
||||
if($id==$staffRoleId){
|
||||
$STAFF = session('WST_STAFF');
|
||||
$STAFF['privileges'] = explode(',',input('post.privileges'));
|
||||
$STAFF['roleName'] = Input('post.roleName');
|
||||
session('WST_STAFF',$STAFF);
|
||||
}
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
795
hyhproject/admin/model/Settlements.php
Executable file
795
hyhproject/admin/model/Settlements.php
Executable file
@ -0,0 +1,795 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
use think\Loader;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 结算业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Settlements extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取结算列表
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$settlementNo = input('settlementNo');
|
||||
|
||||
$shopName = input('shopName');
|
||||
|
||||
$settlementStatus = (int)input('settlementStatus',-1);
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($settlementNo!='')$where['settlementNo'] = ['like','%'.$settlementNo.'%'];
|
||||
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
|
||||
if($settlementStatus>=0)$where['settlementStatus'] = $settlementStatus;
|
||||
|
||||
$order = 'st.settlementId desc';
|
||||
|
||||
if($sort){
|
||||
|
||||
$sortArr = explode('.',$sort);
|
||||
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
|
||||
if($sortArr[0]=='settlementNo'){
|
||||
|
||||
$order = $sortArr[0].'+0 '.$sortArr[1];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$result=Db::name('settlements')->alias('st')
|
||||
|
||||
->join('__SHOPS__ s','s.shopId=st.shopId','left')
|
||||
|
||||
->join('__ORDERS__ o','o.settlementId=st.settlementId','left')
|
||||
|
||||
->join('__SHOPS_DEPOSIT_DETAIL__ sd','sd.orderId=o.orderId','left')
|
||||
|
||||
->join('__PAYMENTS__ p','p.payCode=o.payFrom','left')
|
||||
|
||||
->where($where)->field('s.shopName,settlementNo,sd.cashDeposit,st.settlementId,st.settlementMoney,st.commissionFee,st.backMoney,st.settlementStatus,st.settlementTime,st.createTime,payFrom,payName')->order($order)
|
||||
|
||||
->paginate(input('limit/d'))->toArray();
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取结算订单详情
|
||||
|
||||
*/
|
||||
|
||||
public function getById(){
|
||||
|
||||
$settlementId = (int)input('id');
|
||||
|
||||
$object = Db::name('settlements')->alias('st')->where('settlementId',$settlementId)->join('__SHOPS__ s','s.shopId=st.shopId','left')->field('s.shopName,st.*')->find();
|
||||
|
||||
// dump($object);die;
|
||||
|
||||
|
||||
|
||||
if(!empty($object)){
|
||||
|
||||
$object['list'] = Db::name('orders')->alias('o')->join('__SHOPS_DEPOSIT_DETAIL__ sd','o.orderId=sd.orderId','left')->where(['o.settlementId'=>$settlementId])
|
||||
|
||||
->field('sd.cashDeposit,o.orderId,orderNo,o.payType,goodsMoney,deliverMoney,realTotalMoney,totalMoney,commissionFee,scoreMoney,createTime')
|
||||
|
||||
->order('payType desc,orderId desc')->select();
|
||||
|
||||
}
|
||||
|
||||
// dump($object);die;
|
||||
|
||||
return $object;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 处理订单
|
||||
|
||||
*/
|
||||
|
||||
public function handle(){
|
||||
|
||||
$id = (int)input('settlementId');
|
||||
|
||||
$remarks = input('remarks');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$object = $this->get($id);
|
||||
|
||||
$object->settlementStatus = 1;
|
||||
|
||||
$object->settlementTime = date('Y-m-d H:i:s');
|
||||
|
||||
if($remarks!='')$object->remarks = $remarks;
|
||||
|
||||
$rs = $object->save();
|
||||
|
||||
if(false !== $rs){
|
||||
|
||||
$shop = model('Shops')->get($object->shopId);
|
||||
|
||||
WSTSendMsg($shop['userId'],"您的结算申请【".$object->settlementNo."】已处理,请留意到账户息哦~",['from'=>4,'dataId'=>$id]);
|
||||
|
||||
$shop->shopMoney = $shop->shopMoney+$object->backMoney;
|
||||
|
||||
$shop->paymentMoney = $shop->paymentMoney + $object->commissionFee;
|
||||
|
||||
$shop->save();
|
||||
|
||||
$lmarr = [];
|
||||
|
||||
//增加资金变动信息
|
||||
|
||||
if($object->settlementMoney>0){
|
||||
|
||||
$lm = [];
|
||||
|
||||
$lm['targetType'] = 1;
|
||||
|
||||
$lm['targetId'] = $object->shopId;
|
||||
|
||||
$lm['dataId'] = $id;
|
||||
|
||||
$lm['dataSrc'] = 2;
|
||||
|
||||
$lm['remark'] = '结算订单申请【'.$object->settlementNo.'】收入订单金额¥'.$object->settlementMoney;
|
||||
|
||||
$lm['moneyType'] = 1;
|
||||
|
||||
$lm['money'] = $object->settlementMoney;
|
||||
|
||||
$lm['payType'] = 0;
|
||||
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$lmarr[] = $lm;
|
||||
|
||||
}
|
||||
|
||||
if($object->commissionFee>0){
|
||||
|
||||
//要对有积分支付的佣金记录进行处理
|
||||
|
||||
$commissionFee = $object->commissionFee;
|
||||
|
||||
//如果backMoney小于0则说明平台收到的钱不足以支付佣金,这个backMoney已经减去了积分支付,所以直接显示backMoney为应付的佣金就好
|
||||
|
||||
if($object->backMoney<0){
|
||||
|
||||
$commissionFee = $object->backMoney;
|
||||
|
||||
}
|
||||
|
||||
$lm = [];
|
||||
|
||||
$lm['targetType'] = 1;
|
||||
|
||||
$lm['targetId'] = $object->shopId;
|
||||
|
||||
$lm['dataId'] = $id;
|
||||
|
||||
$lm['dataSrc'] = 2;
|
||||
|
||||
$lm['remark'] = '结算订单申请【'.$object->settlementNo.'】支出订单佣金¥'.$commissionFee."。".(($object->remarks!='')?"【操作备注】:".$object->remarks:'');
|
||||
|
||||
$lm['moneyType'] = 0;
|
||||
|
||||
$lm['money'] = $commissionFee;
|
||||
|
||||
$lm['payType'] = 0;
|
||||
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$lmarr[] = $lm;
|
||||
|
||||
}
|
||||
|
||||
if(count($lmarr)>0)model('LogMoneys')->saveAll($lmarr);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功!',1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('操作失败!',-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取订单商品
|
||||
|
||||
*/
|
||||
|
||||
public function pageGoodsQuery(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
return Db::name('orders')->alias('o')->join('__ORDER_GOODS__ og','o.orderId=og.orderId')->where('o.settlementId',$id)
|
||||
|
||||
->field('orderNo,og.goodsPrice,og.goodsName,og.goodsSpecNames,og.goodsNum,og.commissionRate')->order('o.payType desc,o.orderId desc')->paginate(input('limit/d'))->toArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取待结算商家
|
||||
|
||||
*/
|
||||
|
||||
public function pageShopQuery(){
|
||||
|
||||
$areaIdPath = input('areaIdPath');
|
||||
|
||||
$shopName = input('shopName');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($shopName!='')$where['s.shopName|s.shopSn'] = ['like','%'.$shopName.'%'];
|
||||
|
||||
if($areaIdPath !='')$where['s.areaIdPath'] = ['like',$areaIdPath."%"];
|
||||
|
||||
$where['s.dataFlag'] = 1;
|
||||
|
||||
$where['s.noSettledOrderNum'] = ['>',0];
|
||||
|
||||
return Db::table('__SHOPS__')->alias('s')->join('__AREAS__ a2','s.areaId=a2.areaId')
|
||||
|
||||
->where($where)
|
||||
|
||||
->field('shopId,shopSn,shopName,a2.areaName,shopkeeper,telephone,abs(noSettledOrderFee) noSettledOrderFee,noSettledOrderNum')
|
||||
|
||||
->order('noSettledOrderFee desc')->paginate(input('limit/d'));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取商家未结算的订单
|
||||
|
||||
*/
|
||||
|
||||
public function pageShopOrderQuery(){
|
||||
|
||||
$orderNo = input('orderNo');
|
||||
|
||||
$payType = (int)input('payType',-1);
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['settlementId'] = 0;
|
||||
|
||||
$where['orderStatus'] = 2;
|
||||
|
||||
$where['shopId'] = (int)input('id');
|
||||
|
||||
$where['dataFlag'] = 1;
|
||||
|
||||
if($orderNo!='')$where['orderNo'] = ['like','%'.$orderNo.'%'];
|
||||
|
||||
if(in_array($payType,[0,1]))$where['payType'] = $payType;
|
||||
|
||||
$page = Db::name('orders')->where($where)
|
||||
|
||||
->field('orderId,orderNo,payType,goodsMoney,deliverMoney,realTotalMoney,totalMoney,commissionFee,createTime')
|
||||
|
||||
->order('payType desc,orderId desc')->paginate(input('limit/d'))->toArray();
|
||||
|
||||
if(count($page['Rows'])>0){
|
||||
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
|
||||
$page['Rows'][$key]['payTypeName'] = WSTLangPayType($v['payType']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 生成结算单
|
||||
|
||||
*/
|
||||
|
||||
public function generateSettleByShop(){
|
||||
|
||||
$shopId = (int)input('id');
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['shopId'] = $shopId;
|
||||
|
||||
$where['dataFlag'] = 1;
|
||||
|
||||
$where['orderStatus'] = 2;
|
||||
|
||||
$where['settlementId'] = 0;
|
||||
|
||||
$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']);
|
||||
|
||||
}
|
||||
|
||||
$backMoney = $settlementMoney-$commissionFee;
|
||||
|
||||
$shops = model('shops')->get($shopId);
|
||||
|
||||
if(empty($shops))WSTReturn('无效的店铺结算账号!');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['settlementType'] = 0;
|
||||
|
||||
$data['shopId'] = $shopId;
|
||||
|
||||
$data['settlementMoney'] = $settlementMoney;
|
||||
|
||||
$data['commissionFee'] = $commissionFee;
|
||||
|
||||
$data['backMoney'] = $settlementMoney-$commissionFee;
|
||||
|
||||
$data['settlementStatus'] = 1;
|
||||
|
||||
$data['settlementTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$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]);
|
||||
|
||||
$shops->shopMoney = $shops->shopMoney + $backMoney;
|
||||
|
||||
$shops->noSettledOrderNum = 0;
|
||||
|
||||
$shops->noSettledOrderFee = 0;
|
||||
|
||||
$shops->paymentMoney = 0;
|
||||
|
||||
//修改商家充值金额
|
||||
|
||||
$lockCashMoney = (($shops->rechargeMoney - $commissionFee)>=0)?($shops->rechargeMoney - $commissionFee):0;
|
||||
|
||||
$shops->rechargeMoney = $lockCashMoney;
|
||||
|
||||
$shops->save();
|
||||
|
||||
|
||||
|
||||
//发消息
|
||||
|
||||
$tpl = WSTMsgTemplates('SHOP_SETTLEMENT');
|
||||
|
||||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||||
|
||||
$find = ['${SETTLEMENT_NO}'];
|
||||
|
||||
$replace = [$this->settlementNo];
|
||||
|
||||
|
||||
|
||||
$msg = array();
|
||||
|
||||
$msg["shopId"] = $shopId;
|
||||
|
||||
$msg["tplCode"] = $tpl["tplCode"];
|
||||
|
||||
$msg["msgType"] = 1;
|
||||
|
||||
$msg["content"] = str_replace($find,$replace,$tpl['tplContent']) ;
|
||||
|
||||
$msg["msgJson"] = ['from'=>4,'dataId'=>$this->settlementId];
|
||||
|
||||
model("common/MessageQueues")->add($msg);
|
||||
|
||||
}
|
||||
|
||||
//增加资金变动信息
|
||||
|
||||
$lmarr = [];
|
||||
|
||||
if($settlementMoney>0){
|
||||
|
||||
$lm = [];
|
||||
|
||||
$lm['targetType'] = 1;
|
||||
|
||||
$lm['targetId'] = $shopId;
|
||||
|
||||
$lm['dataId'] = $this->settlementId;
|
||||
|
||||
$lm['dataSrc'] = 2;
|
||||
|
||||
$lm['remark'] = '结算订单申请【'.$this->settlementNo.'】收入订单金额¥'.$settlementMoney."。";
|
||||
|
||||
$lm['moneyType'] = 1;
|
||||
|
||||
$lm['money'] = $settlementMoney;
|
||||
|
||||
$lm['payType'] = 0;
|
||||
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$lmarr[] = $lm;
|
||||
|
||||
}
|
||||
|
||||
if($commissionFee>0){
|
||||
|
||||
$lm = [];
|
||||
|
||||
$lm['targetType'] = 1;
|
||||
|
||||
$lm['targetId'] = $shopId;
|
||||
|
||||
$lm['dataId'] = $this->settlementId;
|
||||
|
||||
$lm['dataSrc'] = 2;
|
||||
|
||||
$lm['remark'] = '结算订单申请【'.$this->settlementNo.'】收取订单佣金¥'.$commissionFee."。";
|
||||
|
||||
$lm['moneyType'] = 0;
|
||||
|
||||
$lm['money'] = $commissionFee;
|
||||
|
||||
$lm['payType'] = 0;
|
||||
|
||||
$lm['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$lmarr[] = $lm;
|
||||
|
||||
}
|
||||
|
||||
if(count($lmarr)>0)model('LogMoneys')->saveAll($lmarr);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('生成结算单成功',1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('生成结算单失败',-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 导出
|
||||
|
||||
*/
|
||||
|
||||
public function toExport(){
|
||||
|
||||
$name='结算申请表';
|
||||
|
||||
$settlementNo = input('settlementNo');
|
||||
|
||||
$shopName = input('shopName');
|
||||
|
||||
$settlementStatus = (int)input('settlementStatus',-1);
|
||||
|
||||
$sort = input('sort');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($settlementNo!='')$where['settlementNo'] = ['like','%'.$settlementNo.'%'];
|
||||
|
||||
if($shopName!='')$where['shopName|shopSn'] = ['like','%'.$shopName.'%'];
|
||||
|
||||
if($settlementStatus>=0)$where['settlementStatus'] = $settlementStatus;
|
||||
|
||||
$order = 'st.settlementId desc';
|
||||
|
||||
if($sort){
|
||||
|
||||
$sortArr = explode('.',$sort);
|
||||
|
||||
$order = $sortArr[0].' '.$sortArr[1];
|
||||
|
||||
if($sortArr[0]=='settlementNo'){
|
||||
|
||||
$order = $sortArr[0].'+0 '.$sortArr[1];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$page=Db::name('settlements')->alias('st')
|
||||
|
||||
->join('__SHOPS__ s','s.shopId=st.shopId','left')
|
||||
|
||||
->join('__ORDERS__ o','o.settlementId=st.settlementId','left')
|
||||
|
||||
->join('__SHOPS_DEPOSIT_DETAIL__ sd','sd.orderId=o.orderId','left')
|
||||
|
||||
->join('__PAYMENTS__ p','p.payCode=o.payFrom','left')
|
||||
|
||||
->where($where)->field('s.shopName,settlementNo,sd.cashDeposit,st.settlementId,st.settlementMoney,st.commissionFee,st.backMoney,st.settlementStatus,st.settlementTime,st.createTime,payFrom,payName')->order($order)
|
||||
|
||||
->select();
|
||||
|
||||
foreach($page as &$v){
|
||||
|
||||
$order_list=db('orders')->where('settlementId',$v['settlementId'])->field('orderNo,realTotalMoney,scoreMoney')->select();
|
||||
|
||||
$v['order_number']='';
|
||||
|
||||
if(count($order_list)>0){
|
||||
|
||||
foreach($order_list as $val){
|
||||
|
||||
$v['order_number']=$v['order_number'].$val['orderNo'].',';//
|
||||
|
||||
}
|
||||
|
||||
//.$order_list['realTotalMoney'].$order_list['scoreMoney'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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(12);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:K1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:K1')->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:I1')->applyFromArray($styleArray);
|
||||
|
||||
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
|
||||
$i = $row+2;
|
||||
|
||||
$objPHPExcel->getActiveSheet()
|
||||
|
||||
->setCellValue('A'.$i, $page[$row]['settlementNo'])
|
||||
|
||||
->setCellValue('B'.$i, $page[$row]['shopName'])
|
||||
|
||||
->setCellValue('C'.$i, '¥'.$page[$row]['settlementMoney'])
|
||||
|
||||
->setCellValue('D'.$i, '¥'.$page[$row]['commissionFee'])
|
||||
|
||||
->setCellValue('E'.$i, '¥'.(float)$page[$row]['cashDeposit'])
|
||||
|
||||
->setCellValue('F'.$i, '¥'.$page[$row]['backMoney'])
|
||||
|
||||
->setCellValue('G'.$i, $page[$row]['createTime'])
|
||||
|
||||
->setCellValue('H'.$i, $page[$row]['settlementStatus']==1?'已结算':'未结算')
|
||||
|
||||
->setCellValue('I'.$i, $page[$row]['order_number'])
|
||||
|
||||
->setCellValue('J'.$i, $page[$row]['payName']);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//输出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');
|
||||
|
||||
}
|
||||
|
||||
}
|
1367
hyhproject/admin/model/Shops.php
Executable file
1367
hyhproject/admin/model/Shops.php
Executable file
File diff suppressed because it is too large
Load Diff
139
hyhproject/admin/model/SpecCats.php
Executable file
139
hyhproject/admin/model/SpecCats.php
Executable file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 规格分类业务处理
|
||||
*/
|
||||
class SpecCats extends Base{
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$isExistAllowImg = false;
|
||||
$msg = '';
|
||||
$data = input('post.');
|
||||
if($data['isAllowImg']==1){
|
||||
if($this->checkExistAllowImg((int)$data['goodsCatId'],0)){
|
||||
return WSTReturn("同一分类下已存在允许上传图片规格类型,请先修改之后再新增");
|
||||
}
|
||||
}
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data["dataFlag"] = 1;
|
||||
$goodsCats = model('GoodsCats')->getParentIs($data['goodsCatId']);
|
||||
if(!empty($goodsCats))$data['goodsCatPath'] = implode('_',$goodsCats)."_";
|
||||
$result = $this->validate('SpecCats.add')->allowField(['catName','isShow','isAllowImg','goodsCatPath','goodsCatId','dataFlag','createTime'])->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 检测是否存在统一分类下的上传图片分类
|
||||
*/
|
||||
public function checkExistAllowImg($goodsCatId,$catId){
|
||||
$dbo = $this->where(['goodsCatId'=>$goodsCatId,'dataFlag'=>1,'isAllowImg'=>1]);
|
||||
if($catId>0)$dbo->where('catId','<>',$catId);
|
||||
$rs = $dbo->count();
|
||||
if($rs>0)return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$catId = input('post.catId/d');
|
||||
$data = input('post.');
|
||||
if($data['isAllowImg']==1){
|
||||
if($this->checkExistAllowImg((int)$data['goodsCatId'],$catId)){
|
||||
return WSTReturn("同一分类下已存在允许上传图片规格类型,请先修改之后再保存");
|
||||
}
|
||||
}
|
||||
$goodsCats = model('GoodsCats')->getParentIs($data['goodsCatId']);
|
||||
if(!empty($goodsCats))$data['goodsCatPath'] = implode('_',$goodsCats)."_";
|
||||
$result = $this->validate('SpecCats.edit')->allowField(['catName','goodsCatPath','goodsCatId','isShow','isAllowImg'])->save($data,['catId'=>$catId,"dataFlag"=>1]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$catId = input('post.catId/d');
|
||||
$data["dataFlag"] = -1;
|
||||
$result = $this->save($data,['catId'=>$catId]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示隐藏
|
||||
*/
|
||||
public function setToggle(){
|
||||
$catId = input('post.catId/d');
|
||||
$isShow = input('post.isShow/d');
|
||||
$result = $this->where(['catId'=>$catId,"dataFlag"=>1])->setField("isShow", $isShow);
|
||||
if(false !== $result){
|
||||
return WSTReturn("设置成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 根据ID获取
|
||||
*/
|
||||
public function getById($catId){
|
||||
$obj = null;
|
||||
if($catId>0){
|
||||
$obj = $this->get(['catId'=>$catId,"dataFlag"=>1]);
|
||||
}else{
|
||||
$obj = self::getEModel("spec_cats");
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$keyName = input('keyName');
|
||||
$goodsCatPath = input('goodsCatPath');
|
||||
$dbo = $this->field(true);
|
||||
$map = array();
|
||||
$map['dataFlag'] = 1;
|
||||
if($keyName!="")$map['catName'] = ["like","%".$keyName."%"];
|
||||
if($goodsCatPath!='')$map['goodsCatPath'] = ["like",$goodsCatPath."_%"];
|
||||
$dbo = $dbo->field("catName name, catId id, isShow ,isAllowImg")->where($map);
|
||||
$page = $dbo->order('catSort asc,catId asc')->paginate(input('limit/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
$keyCats = model('GoodsCats')->listKeyAll();
|
||||
foreach ($page['Rows'] as $key => $v){
|
||||
$goodsCatPath = $page['Rows'][$key]['goodsCatPath'];
|
||||
$page['Rows'][$key]['goodsCatNames'] = self::getGoodsCatNames($goodsCatPath,$keyCats);
|
||||
$page['Rows'][$key]['children'] = [];
|
||||
$page['Rows'][$key]['isextend'] = false;
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function getGoodsCatNames($goodsCatPath, $keyCats){
|
||||
$catIds = explode("_",$goodsCatPath);
|
||||
$catNames = array();
|
||||
for($i=0,$k=count($catIds);$i<$k;$i++){
|
||||
if($catIds[$i]=='')continue;
|
||||
if(isset($keyCats[$catIds[$i]]))$catNames[] = $keyCats[$catIds[$i]];
|
||||
}
|
||||
return implode("→",$catNames);
|
||||
}
|
||||
}
|
416
hyhproject/admin/model/Staffs.php
Executable file
416
hyhproject/admin/model/Staffs.php
Executable file
@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use wstmart\admin\model\Roles;
|
||||
|
||||
use wstmart\admin\model\LogStaffLogins;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 职员业务处理
|
||||
|
||||
*/
|
||||
|
||||
class Staffs extends Base{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 判断用户登录帐号密码
|
||||
|
||||
*/
|
||||
|
||||
public function checkLogin(){
|
||||
|
||||
$loginName = input("post.loginName");
|
||||
|
||||
$loginPwd = input("post.loginPwd");
|
||||
|
||||
$code = input("post.verifyCode");
|
||||
|
||||
if(!WSTVerifyCheck($code)){
|
||||
|
||||
return WSTReturn('验证码错误!');
|
||||
|
||||
}
|
||||
|
||||
$decrypt_data = WSTRSA($loginPwd);
|
||||
|
||||
if($decrypt_data['status']==1){
|
||||
|
||||
$loginPwd = $decrypt_data['data'];
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn('登录失败');
|
||||
|
||||
}
|
||||
|
||||
$staff = $this->where(['loginName'=>$loginName,'staffStatus'=>1,'dataFlag'=>1])->find();
|
||||
|
||||
if(empty($staff))return WSTReturn('账号或密码错误!');
|
||||
|
||||
if($staff['loginPwd']==md5($loginPwd.$staff['secretKey'])){
|
||||
|
||||
$staff->lastTime = date('Y-m-d H:i:s');
|
||||
|
||||
$staff->lastIP = request()->ip();
|
||||
|
||||
$staff->save();
|
||||
|
||||
//记录登录日志
|
||||
|
||||
LogStaffLogins::create([
|
||||
|
||||
'staffId'=>$staff['staffId'],
|
||||
|
||||
'loginTime'=> date('Y-m-d H:i:s'),
|
||||
|
||||
'loginIp'=>request()->ip()
|
||||
|
||||
]);
|
||||
|
||||
//获取角色权限
|
||||
|
||||
$role = Roles::get(['dataFlag'=>1,'roleId'=>$staff['staffRoleId']]);
|
||||
|
||||
$staff['roleName'] = $role['roleName'];
|
||||
|
||||
if($staff['staffId']==1){
|
||||
|
||||
$staff['privileges'] = Db::name('privileges')->where(['dataFlag'=>1])->column('privilegeCode');
|
||||
|
||||
$staff['menuIds'] = Db::name('menus')->where('dataFlag',1)->column('menuId');
|
||||
|
||||
}else{
|
||||
|
||||
$staff['privileges'] = explode(',',$role['privileges']);
|
||||
|
||||
$staff['menuIds'] = [];
|
||||
|
||||
//获取管理员拥有的菜单
|
||||
|
||||
if(!empty($staff['privileges'])){
|
||||
|
||||
$menus = Db::name('menus')->alias('m')->join('__PRIVILEGES__ p','m.menuId=p.menuId and p.dataFlag=1','inner')
|
||||
|
||||
->where(['p.privilegeCode'=>['in',$staff['privileges']]])->field('m.menuId')->select();
|
||||
|
||||
$menuIds = [];
|
||||
|
||||
if(!empty($menus)){
|
||||
|
||||
foreach ($menus as $key => $v){
|
||||
|
||||
$menuIds[] = $v['menuId'];
|
||||
|
||||
}
|
||||
|
||||
$staff['menuIds'] = $menuIds;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
session("WST_STAFF",$staff);
|
||||
|
||||
return WSTReturn("",1,$staff);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn('账号或密码错误!');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$key = input('key');
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['s.dataFlag'] = 1;
|
||||
|
||||
if($key!='')$where['loginName|staffName|staffNo'] = ['like','%'.$key.'%'];
|
||||
|
||||
return Db::name('staffs')->alias('s')->join('__ROLES__ r','s.staffRoleId=r.roleId and r.dataFlag=1','left')
|
||||
|
||||
->where($where)->field('staffId,staffName,loginName,workStatus,staffNo,lastTime,lastIP,roleName')
|
||||
|
||||
->order('staffId', 'desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$staffId = (int)session('WST_STAFF.staffId');
|
||||
|
||||
$id = (int)input('post.id/d');
|
||||
|
||||
if($staffId==$id)return WSTReturn('不允许删除自己',-1);
|
||||
|
||||
if($id==1)return WSTReturn('不允许删除最高管理员',-1);
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->update($data,['staffId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTUnuseImage('staffs','staffPhoto',$id);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('删除失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取角色权限
|
||||
|
||||
*/
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['dataFlag'=>1,'staffId'=>$id]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['secretKey'] = rand(1000,9999);
|
||||
|
||||
$data["loginPwd"] = md5(input("post.loginPwd").$data["secretKey"]);
|
||||
|
||||
$data["staffFlag"] = 1;
|
||||
|
||||
$data["createTime"] = date('Y-m-d H:i:s');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('Staffs.add')->allowField(true)->save($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTUseImages(1, $this->staffId,$data['staffPhoto']);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$id = input('post.staffId/d');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
WSTUnset($data, 'staffId,loginPwd,secretKey,dataFlag,createTime,lastTime,lastIP');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, $id,$data['staffPhoto'],'staffs','staffPhoto');
|
||||
|
||||
$result = $this->validate('Staffs.edit')->allowField(true)->save($data,['staffId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
Db::commit();
|
||||
|
||||
if(session('WST_STAFF.staffId')==$id){
|
||||
|
||||
session('WST_STAFF.staffPhoto',$data['staffPhoto']);
|
||||
|
||||
session('WST_STAFF.staffName',$data['staffName']);
|
||||
|
||||
}
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 检测账号是否重复
|
||||
|
||||
*/
|
||||
|
||||
public function checkLoginKey($key){
|
||||
|
||||
$rs = $this->where(['loginName'=>$key,'dataFlag'=>1])->count();
|
||||
|
||||
return ($rs==0)?WSTReturn('该账号可用', 1):WSTReturn("对不起,该账号已存在");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改自己密码
|
||||
|
||||
*/
|
||||
|
||||
public function editMyPass($staffId){
|
||||
|
||||
if(input("post.newPass")=='')WSTReturn("密码不能为空");
|
||||
|
||||
$staff = $this->where('staffId',$staffId)->field('secretKey,loginPwd')->find();
|
||||
|
||||
if(empty($staff))return WSTReturn("修改失败");
|
||||
|
||||
$srcPass = md5(input("post.srcPass").$staff["secretKey"]);
|
||||
|
||||
if($srcPass!=$staff['loginPwd'])return WSTReturn("原密码错误");
|
||||
|
||||
$staff->loginPwd = md5(input("post.newPass").$staff["secretKey"]);
|
||||
|
||||
$result = $staff->save();
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改职员密码
|
||||
|
||||
*/
|
||||
|
||||
public function editPass($staffId){
|
||||
|
||||
if(input("post.newPass")=='')WSTReturn("密码不能为空");
|
||||
|
||||
$staff = $this->where('staffId',$staffId)->field('secretKey')->find();
|
||||
|
||||
if(empty($staff))return WSTReturn("修改失败");
|
||||
|
||||
$staff->loginPwd = md5(input("post.newPass").$staff["secretKey"]);
|
||||
|
||||
$result = $staff->save();
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
return WSTReturn("修改成功", 1);
|
||||
|
||||
}else{
|
||||
|
||||
return WSTReturn($this->getError(),-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取所有的职员列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery(){
|
||||
|
||||
$where = [];
|
||||
|
||||
$where['dataFlag'] = 1;
|
||||
|
||||
$where['staffStatus'] = 1;
|
||||
|
||||
return Db::name('staffs')->where($where)->field('staffId,staffName')
|
||||
|
||||
->order('staffName', 'asc')->select();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
250
hyhproject/admin/model/Styles.php
Executable file
250
hyhproject/admin/model/Styles.php
Executable file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商城配置业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Styles extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取分类
|
||||
|
||||
*/
|
||||
|
||||
public function getCats(){
|
||||
|
||||
return $this->distinct(true)->field('styleSys')->select();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 获取风格列表
|
||||
|
||||
*/
|
||||
|
||||
public function listQuery(){
|
||||
|
||||
$styleSys = input('styleSys');
|
||||
|
||||
$rs = $this->where('styleSys',$styleSys)->select();
|
||||
|
||||
return ['sys'=>$styleSys,'list'=>$rs];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 初始化风格列表
|
||||
|
||||
*/
|
||||
|
||||
public function initStyles(){
|
||||
|
||||
$styles = $this->field('styleSys,stylePath,id')->select();
|
||||
|
||||
$sys = [];
|
||||
|
||||
foreach ($styles as $key => $v) {
|
||||
|
||||
$sys[$v['styleSys']][$v['stylePath']] = 1;
|
||||
|
||||
//删除不存在的风格记录
|
||||
|
||||
if(!is_dir(WSTRootPath(). DS .'hyhproject'. DS .$v['styleSys']. DS .'view'. DS.$v['stylePath'])){
|
||||
|
||||
$this->where('id',$v['id'])->delete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
//添加不存在的风格目录
|
||||
|
||||
$prefix = config('database.prefix');
|
||||
|
||||
foreach ($sys as $key => $v) {
|
||||
|
||||
$dirs = array_map('basename',glob(WSTRootPath(). DS .'hyhproject'.DS.$key.DS.'view'.DS.'*', GLOB_ONLYDIR));
|
||||
|
||||
foreach ($dirs as $dkey => $dv) {
|
||||
|
||||
if(!isset($v[$dv])){
|
||||
|
||||
$sqlPath = WSTRootPath(). DS .'hyhproject'. DS .$key. DS .'view'. DS .$dv. DS.'sql'.DS.'install.sql';// sql路径
|
||||
|
||||
$hasFile = file_exists($sqlPath);
|
||||
|
||||
if(!$hasFile)continue;
|
||||
|
||||
$sql = file_get_contents($sqlPath);
|
||||
|
||||
$this->excute($sql,$prefix);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function changeStyle(){
|
||||
|
||||
$id = (int)input('post.id');
|
||||
|
||||
$object = $this->get($id);
|
||||
|
||||
// styleSys stylePath
|
||||
|
||||
|
||||
|
||||
$sqlPath = WSTRootPath(). DS .'hyhproject'. DS .$object['styleSys']. DS .'view'. DS .$object['stylePath']. DS.'sql'.DS.'style.sql';// sql路径
|
||||
|
||||
$hasFile = file_exists($sqlPath);
|
||||
|
||||
if(!$hasFile)return WSTReturn('风格sql文件不存在,请联系管理员');
|
||||
|
||||
$sql = file_get_contents($sqlPath);
|
||||
|
||||
|
||||
|
||||
$positionArr = ['home'=>1,'wechat'=>2,'mobile'=>3];
|
||||
|
||||
if(!isset($positionArr[$object['styleSys']]))return WSTReturn('风格目录出错,请联系管理员');
|
||||
|
||||
$positionType = $positionArr[$object['styleSys']];// 1:PC版 2:微信 3:手机版
|
||||
|
||||
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$prefix = config('database.prefix');
|
||||
|
||||
/* 删除与风格无关广告 */
|
||||
|
||||
$delAds = "delete from `".$prefix."ads` where positionType='".$positionType."';";
|
||||
|
||||
// 若为pc版,则保留商家入驻广告位置
|
||||
|
||||
if($positionType==1){
|
||||
|
||||
// 获取当前商家入驻广告位置的主键id
|
||||
|
||||
$positionId = Db::name('ad_positions')->where(['positionCode'=>'ads-shop-apply'])->value('positionId');
|
||||
|
||||
$delAds = "delete from `".$prefix."ads` where positionType='".$positionType."' and adPositionId!=$positionId;";
|
||||
|
||||
}
|
||||
|
||||
Db::execute($delAds);
|
||||
|
||||
|
||||
|
||||
/* 删除无关广告位 */
|
||||
|
||||
$delAdPosition = "delete from `".$prefix."ad_positions` where positionType='".$positionType."';";
|
||||
|
||||
// 若为pc版,则保留商家入驻广告
|
||||
|
||||
if($positionType==1){
|
||||
|
||||
$delAdPosition = "delete from `".$prefix."ad_positions` where positionType='".$positionType."' and positionCode not in ('ads-shop-apply');";
|
||||
|
||||
}
|
||||
|
||||
Db::execute($delAdPosition);
|
||||
|
||||
$flag = $this->excute($sql,$prefix);
|
||||
|
||||
if($flag===false)throw new \Exception("风格sql执行出错", 1);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$rs = $this->where('styleSys',$object['styleSys'])->update(['isUse'=>0]);
|
||||
|
||||
if(false !== $rs){
|
||||
|
||||
$object->isUse = 1;
|
||||
|
||||
$object->save();
|
||||
|
||||
cache('WST_CONF',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功',1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn("操作失败");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 执行sql
|
||||
|
||||
*/
|
||||
|
||||
private function excute($sql,$db_prefix=''){
|
||||
|
||||
if(!isset($sql) || empty($sql)) return;
|
||||
|
||||
$sql = str_replace("\r", " ", str_replace('`wst_', '`'.$db_prefix, $sql));// 替换表前缀
|
||||
|
||||
$ret = array();
|
||||
|
||||
foreach(explode(";\n", trim($sql)) as $query) {
|
||||
|
||||
Db::execute(trim($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
134
hyhproject/admin/model/SysConfigs.php
Executable file
134
hyhproject/admin/model/SysConfigs.php
Executable file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 商城配置业务处理
|
||||
|
||||
*/
|
||||
|
||||
use think\Db;
|
||||
|
||||
class SysConfigs extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 获取商城配置
|
||||
|
||||
*/
|
||||
|
||||
public function getSysConfigs(){
|
||||
|
||||
$rs = $this->field('fieldCode,fieldValue')->select();
|
||||
|
||||
$rv = [];
|
||||
|
||||
$split = [
|
||||
|
||||
'submitOrderTipUsers','payOrderTipUsers','cancelOrderTipUsers','rejectOrderTipUsers','refundOrderTipUsers','complaintOrderTipUsers','cashDrawsTipUsers'
|
||||
|
||||
];
|
||||
|
||||
foreach ($rs as $v){
|
||||
|
||||
if(in_array($v['fieldCode'],$split)){
|
||||
|
||||
$rv[$v['fieldCode']] = ($v['fieldValue']=='')?[]:explode(',',$v['fieldValue']);
|
||||
|
||||
}else{
|
||||
|
||||
$rv[$v['fieldCode']] = $v['fieldValue'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$signScore = explode(",",$rv['signScore']);
|
||||
|
||||
for($i=0;$i<31;++$i){
|
||||
|
||||
$rv['signScore'.$i] = ($signScore[0]==0)?0:$signScore[$i];
|
||||
|
||||
}
|
||||
|
||||
return $rv;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit($fieldType = 0){
|
||||
if(1 == input('isDataConfigs')){
|
||||
$data = input('post.');
|
||||
unset($data['isDataConfigs']);
|
||||
$m = Model('Table');
|
||||
$m->setTable('data_configs');
|
||||
Db::startTrans();
|
||||
try{
|
||||
foreach ($data as $k=>$v) {
|
||||
$m->updateInfo(['configId'=>$k],['fieldValue'=>$v]);
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("操作成功", 1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
}else{
|
||||
$list = $this->where('fieldType',$fieldType)->field('configId,fieldCode,fieldValue')->select();
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
foreach ($list as $key =>$v){
|
||||
|
||||
$code = trim($v['fieldCode']);
|
||||
|
||||
if(in_array($code,['wstVersion','wstMd5','wstMobileImgSuffix','mallLicense']))continue;
|
||||
|
||||
$val = Input('post.'.trim($v['fieldCode']));
|
||||
|
||||
//启用图片
|
||||
|
||||
if(substr($val,0,7)=='upload/' && strpos($val,'.')!==false){
|
||||
|
||||
WSTUseImages(1, $v['configId'],$val, 'sys_configs','fieldValue');
|
||||
|
||||
}
|
||||
|
||||
$this->update(['fieldValue'=>$val],['fieldCode'=>$code]);
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
cache('WST_CONF',null);
|
||||
|
||||
return WSTReturn("操作成功", 1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return WSTReturn("操作失败", 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
73
hyhproject/admin/model/TemplateMsgs.php
Executable file
73
hyhproject/admin/model/TemplateMsgs.php
Executable file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 消息模板业务处理
|
||||
*/
|
||||
class TemplateMsgs extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery($tplType,$dataType){
|
||||
//dump($tplType);
|
||||
$page = $this->where(['dataFlag'=>1,'tplType'=>$tplType])->paginate(input('limit/d'))->toArray();
|
||||
//dump($page);
|
||||
if(count($page['Rows'])>0){
|
||||
foreach($page['Rows'] as $key =>$data){
|
||||
$d = WSTDatas($dataType,$data['tplCode']);
|
||||
$page['Rows'][$key]['tplCode'] = $d[$data['tplCode']]['dataName'];
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 显示是否显示/隐藏
|
||||
*/
|
||||
public function editiIsShow(){
|
||||
//获取子集
|
||||
$id = input('post.id/d');
|
||||
$status = input('post.status/d',0)?0:1;
|
||||
$result = $this->where('id',$id)->update(['status' => $status]);
|
||||
if(false !== $result){
|
||||
cache('WST_MSG_TEMPLATES',null);
|
||||
return WSTReturn("操作成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
public function pageEmailQuery(){
|
||||
$page = $this->where(['dataFlag'=>1,'tplType'=>1])->paginate(input('limit/d'))->toArray();
|
||||
if(count($page['Rows'])>0){
|
||||
foreach($page['Rows'] as $key =>$data){
|
||||
$d = WSTDatas('TEMPLATE_EMAIL',$data['tplCode']);
|
||||
$page['Rows'][$key]['tplCode'] = $d[$data['tplCode']]['dataName'];
|
||||
$page['Rows'][$key]['tplContent'] = strip_tags(htmlspecialchars_decode($data['tplContent']));
|
||||
}
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
/**
|
||||
* 获取角色权限
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->get(['dataFlag'=>1,'id'=>$id]);
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$id = (int)input('post.id/d');
|
||||
$tplCode = input('post.tplCode');
|
||||
$data = [];
|
||||
$data['tplContent'] = input('post.tplContent');
|
||||
$data['status'] = input('post.seoMallSwitch');
|
||||
$result = $this->save($data,['id'=>$id,'tplCode'=>$tplCode]);
|
||||
if(false !== $result){
|
||||
cache('WST_MSG_TEMPLATES',null);
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
176
hyhproject/admin/model/UserRanks.php
Executable file
176
hyhproject/admin/model/UserRanks.php
Executable file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 会员等级业务处理
|
||||
|
||||
*/
|
||||
|
||||
class UserRanks extends Base{
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
return $this->where('dataFlag',1)->field(true)->order('rankId desc')->paginate(input('limit/d'));
|
||||
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
|
||||
return $this->get(['rankId'=>$id,'dataFlag'=>1]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 新增
|
||||
|
||||
*/
|
||||
|
||||
public function add(){
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
$data['startScore'] = (int) $data['startScore'];
|
||||
|
||||
$data['endScore'] = (int) $data['endScore'];
|
||||
|
||||
WSTUnset($data,'rankId');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->validate('UserRanks.add')->allowField(true)->save($data);
|
||||
|
||||
$id = $this->rankId;
|
||||
|
||||
//启用上传图片
|
||||
|
||||
WSTUseImages(1, $id, $data['userrankImg']);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('WST_USER_RANK',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("新增成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('新增失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 编辑
|
||||
|
||||
*/
|
||||
|
||||
public function edit(){
|
||||
|
||||
$Id = (int)input('post.rankId');
|
||||
|
||||
$data = input('post.');
|
||||
|
||||
$data['startScore'] = (int) $data['startScore'];
|
||||
|
||||
$data['endScore'] = (int) $data['endScore'];
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
WSTUseImages(1, $Id, $data['userrankImg'], 'user_ranks', 'userrankImg');
|
||||
|
||||
WSTUnset($data,'createTime');
|
||||
|
||||
$result = $this->validate('UserRanks.edit')->allowField(true)->save($data,['rankId'=>$Id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
cache('WST_USER_RANK',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("编辑成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 删除
|
||||
|
||||
*/
|
||||
|
||||
public function del(){
|
||||
|
||||
$id = (int)input('post.id/d');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['dataFlag'] = -1;
|
||||
|
||||
$result = $this->update($data,['rankId'=>$id]);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
WSTUnuseImage('user_ranks','userrankImg',$id);
|
||||
|
||||
cache('WST_USER_RANK',null);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn("删除成功", 1);
|
||||
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('编辑失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
148
hyhproject/admin/model/UserScores.php
Executable file
148
hyhproject/admin/model/UserScores.php
Executable file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace wstmart\admin\model;
|
||||
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
|
||||
* ============================================================================
|
||||
|
||||
* 积分流水日志业务处理
|
||||
|
||||
*/
|
||||
|
||||
class UserScores extends Base{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 获取用户信息
|
||||
|
||||
*/
|
||||
|
||||
public function getUserInfo(){
|
||||
|
||||
$id = (int)input('id');
|
||||
|
||||
return model('users')->where('userId',$id)->field('loginName,userId,userName')->find();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 分页
|
||||
|
||||
*/
|
||||
|
||||
public function pageQuery(){
|
||||
|
||||
$userId = input('id');
|
||||
|
||||
$startDate = input('startDate');
|
||||
|
||||
$endDate = input('endDate');
|
||||
|
||||
$where = [];
|
||||
|
||||
if($startDate!='')$where['createTime'] = ['>=',$startDate." 00:00:00"];
|
||||
|
||||
if($endDate!='')$where[' createTime'] = ['<=',$endDate." 23:59:59"];
|
||||
|
||||
$where['userId'] = $userId;
|
||||
|
||||
$page = $this->where($where)->order('scoreId', 'desc')->paginate(input('limit/d'))->toArray();
|
||||
|
||||
if(count($page['Rows'])>0){
|
||||
|
||||
foreach ($page['Rows'] as $key => $v) {
|
||||
|
||||
$page['Rows'][$key]['dataSrc'] = WSTLangScore($v['dataSrc']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* 新增记录
|
||||
|
||||
*/
|
||||
|
||||
public function addByAdmin(){
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['userId'] = (int)input('userId');
|
||||
|
||||
$data['score'] = (int)input('score');
|
||||
|
||||
$data['dataSrc'] = 10001;
|
||||
|
||||
$data['dataId'] = 0;
|
||||
|
||||
$data['scoreType'] = (int)input('scoreType');
|
||||
|
||||
$data['dataRemarks'] = input('dataRemarks');
|
||||
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
|
||||
//判断用户身份
|
||||
|
||||
$user = model('users')->where(['userId'=>$data['userId'],'dataFlag'=>1])->find();
|
||||
|
||||
if(empty($user))return WSTReturn('无效的会员');
|
||||
|
||||
if(!in_array($data['scoreType'],[0,1]))return WSTReturn('无效的调节类型');
|
||||
|
||||
if($data['score']<=0)return WSTReturn('调节积分必须大于0');
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$result = $this->insert($data);
|
||||
|
||||
if(false !== $result){
|
||||
|
||||
if($data['scoreType']==1){
|
||||
|
||||
$user->userScore = $user->userScore+$data['score'];
|
||||
|
||||
$user->userTotalScore = $user->userTotalScore+$data['score'];
|
||||
|
||||
}else{
|
||||
|
||||
$user->userScore = $user->userScore-$data['score'];
|
||||
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return WSTReturn('操作成功',1);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
|
||||
Db::rollback();errLog($e);
|
||||
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
587
hyhproject/admin/model/Users.php
Executable file
587
hyhproject/admin/model/Users.php
Executable file
@ -0,0 +1,587 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 会员业务处理
|
||||
*/
|
||||
class Users extends Base{
|
||||
/**
|
||||
* 个体认证审核列表
|
||||
* @param int $isPersonal 是否是个体认证
|
||||
* @return array
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getReview($isPersonal=1){
|
||||
|
||||
if(1 == $isPersonal){
|
||||
$m = Db::name('auth_personal a');
|
||||
}else{
|
||||
$m = Db::name('auth_company a');
|
||||
}
|
||||
$where=[];
|
||||
$loginName = input('post.loginName');
|
||||
if($loginName) $where['u.loginName|u.userPhone'] = $loginName;
|
||||
$rs = $m->join('__USERS__ u','a.userId=u.userId')
|
||||
->where($where)
|
||||
->field('u.loginName,u.userPhone,a.*')
|
||||
->order('status ASC,createTime ASC')
|
||||
->paginate(input('limit/d'))
|
||||
->toArray();
|
||||
return $rs;
|
||||
}
|
||||
/**个体认证操作
|
||||
* @param int $isPersonal 是否是个体认证
|
||||
* @return array
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
public function authAction($isPersonal=1){
|
||||
$data = input('post.');
|
||||
$id = $data['id'];
|
||||
if(1 == $data['status']){
|
||||
unset($data['reasonsForRefusal']);
|
||||
}
|
||||
$field = '*';
|
||||
$user_data = [];
|
||||
if(1 == $isPersonal){
|
||||
$field = 'userId,householdName trueName,userPhone';
|
||||
$user_data['authType'] = 1;
|
||||
$m = Db::name('auth_personal a');
|
||||
}else{
|
||||
$user_data['authType'] = 2;
|
||||
$field = 'userId,trueName,userPhone';
|
||||
$m = Db::name('auth_company a');
|
||||
}
|
||||
$where['id'] = $id;
|
||||
$authInfo = $m->where($where)->field($field)->find();
|
||||
if(!$authInfo){
|
||||
return WSTReturn('认证不存在');
|
||||
}else{
|
||||
if(1 == $data['status']) {
|
||||
$user_data['userPhone'] = $authInfo['userPhone'];
|
||||
$user_data['trueName'] = $authInfo['trueName'];
|
||||
$user_data['userName'] = $authInfo['trueName'];
|
||||
}else{
|
||||
$user_data['authType'] = 0;
|
||||
}
|
||||
Db::name('users')->where(['userId' => $authInfo['userId']])->update($user_data);
|
||||
}
|
||||
$data['updateTime'] = time();
|
||||
$rs = $m->where($where)->update($data);
|
||||
if(false !== $rs){
|
||||
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
return WSTReturn('操作失败,请重试',-1);
|
||||
}
|
||||
/**
|
||||
* 获取申请列表
|
||||
*/
|
||||
public function getUserUpdateList(){
|
||||
$where=[];
|
||||
$loginName = input('post.loginName');
|
||||
if($loginName) $where['u.loginName|u.userPhone'] = $loginName;
|
||||
$rs = Db::name('user_update d')
|
||||
->join('__USERS__ u','d.userId=u.userId')
|
||||
->join('__SHOPS__ s','d.shopId=s.shopId')
|
||||
->where($where)
|
||||
->field('u.loginName,u.userPhone,u.trueName,s.userName,s.phone,s.shopName,s.provinceId,s.cityId,s.countyId,s.townId,s.villageId,d.userId,d.shopId,d.id,d.applyLevel,d.confirmImg,d.shopImg,d.status,d.reasonsForRefusal,d.createTime,d.updateTime')
|
||||
->order('status ASC,createTime ASC')
|
||||
->paginate(input('limit/d'))
|
||||
->toArray();
|
||||
$m = Model('common/Position');
|
||||
foreach ($rs['Rows'] as &$v) {
|
||||
$m->initData(1);
|
||||
$v['province'] = $m->getAreaName($v['provinceId']);
|
||||
|
||||
$m->initData(2);
|
||||
$v['city'] = $m->getAreaName($v['cityId']);
|
||||
|
||||
$m->initData(3);
|
||||
$v['county'] = $m->getAreaName($v['countyId']);
|
||||
|
||||
$m->initData(4);
|
||||
$v['town'] = $m->getAreaName($v['townId']);
|
||||
|
||||
$m->initData(5);
|
||||
$v['village'] = $m->getAreaName($v['villageId']);
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
/**
|
||||
* 申请操作
|
||||
*/
|
||||
public function setUserUpdate(){
|
||||
|
||||
$data = input('post.');
|
||||
$id = $data['id'];
|
||||
$applyInfo = Db::name('user_update')->where(['id'=>$id])->field('userId,shopId,applyLevel')->find();
|
||||
if(!$applyInfo){
|
||||
return WSTReturn('此数据不存在');
|
||||
}
|
||||
$applyLevel = $applyInfo['applyLevel'];
|
||||
if(!in_array($applyLevel,[2,3,4])) return WSTReturn('请正确输入等级!');
|
||||
if(1 == $data['status']){
|
||||
unset($data['reasonsForRefusal']);
|
||||
//店铺位置信息
|
||||
$shopInfo = Model('common/shops')->getFieldsById($applyInfo['shopId'],'provinceId,cityId,countyId,townId,villageId');
|
||||
$shopInfo = $shopInfo->toArray();
|
||||
//检查是否已有代理
|
||||
$applyArea='';
|
||||
switch ($applyLevel) {
|
||||
case 2:
|
||||
$applyArea = 'countyId';
|
||||
break;
|
||||
case 3:
|
||||
$applyArea = 'townId';
|
||||
break;
|
||||
case 4:
|
||||
$applyArea = 'villageId';
|
||||
break;
|
||||
}
|
||||
if(Db::name('user_update')->where(['status'=>1,'applyLevel'=>$applyLevel,$applyArea=>$shopInfo[$applyArea]])->value('id')){
|
||||
return WSTReturn('当前区域代理已存在');
|
||||
}
|
||||
$data = array_merge($data,$shopInfo);
|
||||
}
|
||||
Db::startTrans();
|
||||
try{
|
||||
$data['updateTime'] = time();
|
||||
if(1 == $data['status']){
|
||||
//升级会员等级,没啥用了,留着吧
|
||||
$userInfo = getUserInfo(['userId'=>$applyInfo['userId']],'userLevel');
|
||||
if($applyLevel > $userInfo['userLevel']){
|
||||
Db::name('users')->where(['userId'=>$applyInfo['userId']])->update(['userLevel'=>$applyLevel]);
|
||||
}
|
||||
}
|
||||
if(false !== Db::name('user_update')->where(['id'=>$id])->update($data)){
|
||||
Db::commit();
|
||||
return WSTReturn('操作成功',1);
|
||||
}
|
||||
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn('操作失败',-1);
|
||||
|
||||
}
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
/******************** 查询 ************************/
|
||||
$where = [];
|
||||
$where['u.dataFlag'] = 1;
|
||||
$lName = input('loginName1');
|
||||
$phone = input('loginPhone');
|
||||
$email = input('loginEmail');
|
||||
$uType = input('userType');
|
||||
$uStatus = input('userStatus1');
|
||||
$sort = input('sort');
|
||||
if(!empty($lName))
|
||||
$where['loginName|s.shopName'] = ['like',"%$lName%"];
|
||||
if(!empty($phone))
|
||||
$where['userPhone'] = ['like',"%$phone%"];
|
||||
if(!empty($email))
|
||||
$where['userEmail'] = ['like',"%$email%"];
|
||||
if(is_numeric($uType))
|
||||
$where['userType'] = ['=',"$uType"];
|
||||
if(is_numeric($uStatus))
|
||||
$where['userStatus'] = ['=',"$uStatus"];
|
||||
$order = 'u.userId desc';
|
||||
if($sort){
|
||||
//$sort = str_replace('.',' ',$sort);
|
||||
//$order = $sort;
|
||||
}
|
||||
/********************* 取数据 *************************/
|
||||
$rs = $this->alias('u')->join('__SHOPS__ s','u.userId=s.userId and s.dataFlag=1','left')->join('__USER_TREES__ t','u.userId=t.uid','left')->where($where)
|
||||
->field(['u.userId','u.regConfirmImg','loginName','u.userName','userType','userPhone','userEmail','userECT','userScore','u.createTime','u.productNum','u.couponsNum','u.wangNum','userStatus','lastTime','s.shopId','userMoney','u.lockMoney','t.pid'])
|
||||
->order($order)
|
||||
->group('u.userId')
|
||||
->paginate(input('limit/d'))
|
||||
->toArray();
|
||||
$m = Model('Table');
|
||||
foreach ($rs['Rows'] as &$v) {
|
||||
if($v['pid']){
|
||||
$m->setTable('users');
|
||||
$v['pName'] = $m->getField(['userId'=>$v['pid']],'loginName');
|
||||
}else{
|
||||
$v['pName'] = '';
|
||||
}
|
||||
$m->setTable('user_vouchers_summary');
|
||||
$sInfo = $m->getInfo(['userId'=>$v['userId']],'expectedProductNum,expectedCouponsNum');
|
||||
$v['expectedProductNum'] = (float)$sInfo['expectedProductNum'];
|
||||
$v['expectedCouponsNum'] = (float)$sInfo['expectedCouponsNum'];
|
||||
$r = WSTUserRank($v['userScore']);
|
||||
$v['rank'] = $r['rankName'];
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
public function getById($id){
|
||||
return $this->get(['userId'=>$id]);
|
||||
}
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data["loginSecret"] = rand(1000,9999);
|
||||
$data['loginPwd'] = md5($data['loginPwd'].$data['loginSecret']);
|
||||
WSTUnset($data,'userId,userType,userScore,userTotalScore,lastIP,lastTime,userMoney,lockMoney,dataFlag,rechargeMoney');
|
||||
Db::startTrans();
|
||||
try{
|
||||
$result = $this->validate('Users.add')->allowField(true)->save($data);
|
||||
$id = $this->userId;
|
||||
if(false !== $result){
|
||||
hook("adminAfterAddUser",["userId"=>$id]);
|
||||
WSTUseImages(1, $id, $data['userPhoto']);
|
||||
Db::commit();
|
||||
return WSTReturn("新增成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('新增失败',-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = (int)input('post.userId');
|
||||
$data = input('post.');
|
||||
$u = $this->where('userId',$Id)->field('loginSecret')->find();
|
||||
if(empty($u))return WSTReturn('无效的用户');
|
||||
//判断是否需要修改密码
|
||||
if(empty($data['loginPwd'])){
|
||||
unset($data['loginPwd']);
|
||||
}else{
|
||||
//修改联盟登录密码
|
||||
$password = $data['loginPwd'];
|
||||
$data['loginPwd'] = md5($data['loginPwd'].$u['loginSecret']);
|
||||
}
|
||||
Db::startTrans();
|
||||
try{
|
||||
if(isset($data['userPhoto'])){
|
||||
WSTUseImages(1, $Id, $data['userPhoto'], 'users', 'userPhoto');
|
||||
}
|
||||
|
||||
WSTUnset($data,'loginName,createTime,userId,userType,userScore,userTotalScore,lastIP,lastTime,userMoney,lockMoney,dataFlag,rechargeMoney');
|
||||
$result = $this->allowField(true)->save($data,['userId'=>$Id]);
|
||||
if(false !== $result){
|
||||
// 同步修改联盟密码
|
||||
// if(!empty($password)){
|
||||
// Db::table('rd_users')->where(['shop_id'=>$Id])->setField('password',md5($password));
|
||||
// }
|
||||
hook("adminAfterEditUser",["userId"=>$Id]);
|
||||
Db::commit();
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('编辑失败',-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 查看会员定返数据
|
||||
*/
|
||||
public function viewUserDayData(){
|
||||
|
||||
}
|
||||
/**
|
||||
* 充值
|
||||
*/
|
||||
public function recharge(){
|
||||
$userId = (int)input('post.userId');
|
||||
$loginName = input('post.loginName');
|
||||
$rechargeCurrency = input('post.rechargeCurrency');//充值币种,1为ECT
|
||||
$rechargeType = (int)input('post.rechargeType');//1充值0扣除
|
||||
$rechargeNum = (float)input('post.rechargeNum');
|
||||
if($rechargeNum <=0){
|
||||
return WSTReturn('请正确输入充值数量!');
|
||||
}
|
||||
$rechargeNames = ['0'=>'扣除','1'=>'充值'];
|
||||
if(!$rechargeCurrency) return WSTReturn('请正确输入币种!');
|
||||
if(!$userId) $userId = $this->where('loginName',$loginName)->value('userId');
|
||||
if(!$userId) return WSTReturn('未找到此会员');
|
||||
Db::startTrans();
|
||||
try{
|
||||
switch ($rechargeCurrency) {
|
||||
case 1://预获产品券
|
||||
Model('common/UserVouchers')->insertVouchersNotice($userId,0,$rechargeNum,0,'系统'.$rechargeNames[$rechargeType],$rechargeType);
|
||||
break;
|
||||
case 2://预获优惠券
|
||||
Model('common/UserVouchers')->insertVouchersNotice($userId,0,0,$rechargeNum,'系统'.$rechargeNames[$rechargeType],$rechargeType);
|
||||
break;
|
||||
case 3://产品券
|
||||
case 4://优惠券
|
||||
case 5://旺旺券
|
||||
$rechargeCurrency-=2;
|
||||
Model('common/LogMoneys')->addMoneyLog(0,$userId,0,2,'系统'.$rechargeNames[$rechargeType],$rechargeType,$rechargeNum,'system',$rechargeCurrency);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Db::commit();
|
||||
return WSTReturn("操作成功", 1);
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('操作失败',-1);
|
||||
}
|
||||
// if($userId){
|
||||
// $u = $this->where('userId',$userId)->field('userId,loginSecret,userECT')->find();
|
||||
// }else{
|
||||
// $u = $this->where('loginName',$loginName)->field('userId,loginSecret,userECT')->find();
|
||||
// }
|
||||
|
||||
// if(empty($u))return WSTReturn('无效的用户');
|
||||
// $userId = $u['userId'];
|
||||
// if($rechargeType == 2){//扣除
|
||||
// if($rechargeCurrency == 1){
|
||||
// if($u['userECT'] < $rechargeNum ){
|
||||
// return WSTReturn('余额不足以扣除!当前余额:'.$u['userECT']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Db::startTrans();
|
||||
// try{
|
||||
// if($rechargeCurrency == 1){//ECT
|
||||
// if($rechargeType == 1){//充值
|
||||
// ectLog($userId,$rechargeNum,10,'',['userECT'=>['exp','userECT+'.$rechargeNum]],1);
|
||||
// }else{
|
||||
// ectLog($userId,$rechargeNum,10,'',['userECT'=>['exp','userECT-'.$rechargeNum]],2);
|
||||
// }
|
||||
// }
|
||||
// Db::commit();
|
||||
// return WSTReturn("操作成功", 1);
|
||||
// }catch (\Exception $e) {
|
||||
// Db::rollback();errLog($e);
|
||||
// return WSTReturn('操作失败',-1);
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = (int)input('post.id');
|
||||
if($id==1){
|
||||
return WSTReturn('无法删除自营店铺账号',-1);
|
||||
}
|
||||
Db::startTrans();
|
||||
try{
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['userId'=>$id]);
|
||||
if(false !== $result){
|
||||
//删除店铺信息
|
||||
model('shops')->delByUserId($id);
|
||||
hook("adminAfterDelUser",["userId"=>$id]);
|
||||
WSTUnuseImage('users','userPhoto',$id);
|
||||
Db::commit();
|
||||
return WSTReturn("删除成功", 1);
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();errLog($e);
|
||||
return WSTReturn('删除失败',-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
public function changeUserStatus($id, $status){
|
||||
Db::startTrans();
|
||||
try{
|
||||
|
||||
$this->update(['userStatus'=>(int)$status],['userId'=>(int)$id]);
|
||||
if(0 == $status){
|
||||
$lockTime =(int)input('post.lockTime');
|
||||
$lockReason =input('post.lockReason');
|
||||
Db::name('user_lock')->insert(['userId'=>$id,'lockTime'=>$lockTime,'lockReason'=>$lockReason,'createTime'=>time()]);
|
||||
$this->update(['userStatus'=>(int)$status],['userId'=>(int)$id]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return WSTReturn("操作成功",1);
|
||||
}catch (\Exception $e) {
|
||||
//dump($e);
|
||||
Db::rollback();errLog($e);
|
||||
}
|
||||
return WSTReturn("操作失败,请刷新后再重试");
|
||||
}
|
||||
/**
|
||||
* 根据用户名查找用户
|
||||
*/
|
||||
public function getByName($name){
|
||||
return $this->field(['userId','loginName'])->where(['loginName'=>['like',"%$name%"]])->select();
|
||||
}
|
||||
/**
|
||||
* 获取所有用户id
|
||||
*/
|
||||
public function getAllUserId()
|
||||
{
|
||||
return $this->where('dataFlag',1)->column('userId');
|
||||
}
|
||||
/**
|
||||
* 重置支付密码
|
||||
*/
|
||||
public function resetPayPwd(){
|
||||
$Id = (int)input('post.userId');
|
||||
$loginSecret = $this->where('userId',$Id)->value('loginSecret');
|
||||
// 重置支付密码为6个6
|
||||
$payPwd = md5('666666'.$loginSecret);
|
||||
$result = $this->where('userId',$Id)->setField('payPwd',$payPwd);
|
||||
if(false !== $result){
|
||||
return WSTReturn("重置成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户账号查找用户信息
|
||||
*/
|
||||
public function getUserByKey(){
|
||||
$key = input('key');
|
||||
$user = $this->where(['loginName|userPhone|userEmail'=>['=',$key],'dataFlag'=>1])->find();
|
||||
if(empty($user))return WSTReturn('找不到用户',-1);
|
||||
$shop = model('shops')->where(['userId'=>$user->userId,'dataFlag'=>1])->find();
|
||||
if(!empty($shop))return WSTReturn('该用户已存在关联的店铺信息',-1);
|
||||
return WSTReturn('',1,['loginName'=>$user->loginName,'userId'=>$user->userId]);
|
||||
}
|
||||
/**
|
||||
* 导出订单 --林莉
|
||||
*/
|
||||
public function toExport(){
|
||||
$name="会员管理表";
|
||||
$where = [];
|
||||
$where['u.dataFlag'] = 1;
|
||||
$lName = input('loginName1');
|
||||
$phone = input('loginPhone');
|
||||
$email = input('loginEmail');
|
||||
$uType = input('userType');
|
||||
$uStatus = input('userStatus1');
|
||||
$sort = input('sort');
|
||||
if(!empty($lName))
|
||||
$where['loginName|s.shopName'] = ['like',"%$lName%"];
|
||||
if(!empty($phone))
|
||||
$where['userPhone'] = ['like',"%$phone%"];
|
||||
if(!empty($email))
|
||||
$where['userEmail'] = ['like',"%$email%"];
|
||||
if(is_numeric($uType))
|
||||
$where['userType'] = ['=',"$uType"];
|
||||
if(is_numeric($uStatus))
|
||||
$where['userStatus'] = ['=',"$uStatus"];
|
||||
$order = 'u.userId desc';
|
||||
/********************* 取数据 *************************/
|
||||
$page = db('users')->alias('u')->join('__SHOPS__ s','u.userId=s.userId and s.dataFlag=1','left')->where($where)
|
||||
->field(['u.userId','loginName','userName','userType','userPhone','userEmail','userECT','userScore','u.createTime','userStatus','lastTime','s.shopId','userMoney','u.lockMoney'])
|
||||
->order($order)
|
||||
->select();
|
||||
foreach ($page as $key => $v) {
|
||||
$r = WSTUserRank($v['userScore']);
|
||||
$page[$key]['rank'] = $r['rankName'];
|
||||
}
|
||||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
// 设置excel文档的属性
|
||||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||||
->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(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(8);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(35);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(25);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->getFill()->getStartColor()->setARGB('333399');
|
||||
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A1', '账号')
|
||||
->setCellValue('B1', '用户名')
|
||||
->setCellValue('C1', '手机号码')
|
||||
->setCellValue('D1', '电子邮箱')
|
||||
->setCellValue('E1', '可用金额')
|
||||
->setCellValue('F1', '冻结金额')
|
||||
->setCellValue('G1', '积分')
|
||||
->setCellValue('H1', 'ECT')
|
||||
->setCellValue('I1', '等级')
|
||||
->setCellValue('J1', '注册时间')
|
||||
->setCellValue('K1', '状态');
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A1:R1')->applyFromArray($styleArray);
|
||||
|
||||
for ($row = 0; $row < count($page); $row++){
|
||||
$i = $row+2;
|
||||
$objPHPExcel->getActiveSheet()
|
||||
->setCellValue('A'.$i, $page[$row]['loginName'])
|
||||
->setCellValue('B'.$i, $page[$row]['userName'])
|
||||
->setCellValue('C'.$i, $page[$row]['userPhone'])
|
||||
->setCellValue('D'.$i, $page[$row]['userEmail'])
|
||||
->setCellValue('E'.$i, $page[$row]['userMoney'])
|
||||
->setCellValue('F'.$i, $page[$row]['lockMoney'])
|
||||
->setCellValue('G'.$i, $page[$row]['userScore'])
|
||||
->setCellValue('H'.$i, $page[$row]['userECT'])
|
||||
->setCellValue('I'.$i, $page[$row]['rank'])
|
||||
->setCellValue('J'.$i, $page[$row]['createTime'])
|
||||
->setCellValue('K'.$i, $page[$row]['userStatus']);
|
||||
}
|
||||
|
||||
//输出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');
|
||||
}
|
||||
}
|
113
hyhproject/admin/model/Weixinpays.php
Executable file
113
hyhproject/admin/model/Weixinpays.php
Executable file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Loader;
|
||||
use think\Db;
|
||||
use Env;
|
||||
use wstmart\common\model\Payments as M;
|
||||
use wstmart\common\model\LogPayParams as PM;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 微信支付业务处理
|
||||
*/
|
||||
class Weixinpays extends Base{
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private $wxpayConfig;
|
||||
private $wxpay;
|
||||
public function initialize() {
|
||||
header ("Content-type: text/html; charset=utf-8");
|
||||
require Env::get('root_path') . 'extend/wxpay/WxPayConf.php';
|
||||
require Env::get('root_path') . 'extend/wxpay/WxJsApiPay.php';
|
||||
$this->wxpayConfig = array();
|
||||
$m = new M();
|
||||
$this->wxpay = $m->getPayment("weixinpays");
|
||||
$this->wxpayConfig['appid'] = $this->wxpay['appId']; // 微信公众号身份的唯一标识
|
||||
$this->wxpayConfig['appsecret'] = $this->wxpay['appsecret']; // JSAPI接口中获取openid
|
||||
$this->wxpayConfig['mchid'] = $this->wxpay['mchId']; // 受理商ID
|
||||
$this->wxpayConfig['key'] = $this->wxpay['apiKey']; // 商户支付密钥Key
|
||||
|
||||
$this->wxpayConfig['apiclient_cert'] = WSTRootPath().'/extend/wxpay/cert/apiclient_cert.pem'; // 商户支付证书
|
||||
$this->wxpayConfig['apiclient_key'] = WSTRootPath().'/extend/wxpay/cert/apiclient_key.pem'; // 商户支付证书
|
||||
|
||||
$this->wxpayConfig['curl_timeout'] = 30;
|
||||
$this->wxpayConfig['notifyurl'] = url("admin/orderrefunds/wxrefundnodify","",true,true);
|
||||
$this->wxpayConfig['returnurl'] = "";
|
||||
// 初始化WxPayConf
|
||||
new \WxPayConf($this->wxpayConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
public function orderRefund($refund,$order){
|
||||
|
||||
$content = input('post.content');
|
||||
$refundId = (int)input('post.id');
|
||||
|
||||
$wxrefund = new \Refund();
|
||||
$refund_no = $order['orderNo'].$order['userId'];
|
||||
$wxrefund->setParameter("transaction_id",$order['tradeNo']);//微信订单号
|
||||
$wxrefund->setParameter("out_refund_no",$refund_no);//商户退款单号
|
||||
$wxrefund->setParameter("total_fee",$order['totalPayFee']);//订单金额
|
||||
$wxrefund->setParameter("refund_fee",$refund["backMoney"]*100);//退款金额
|
||||
$wxrefund->setParameter("refund_fee_type","CNY");//货币种类
|
||||
$wxrefund->setParameter("refund_desc","订单【".$order['orderNo']."】退款");//退款原因
|
||||
$wxrefund->setParameter("notify_url",$this->wxpayConfig['notifyurl']);//退款原因
|
||||
|
||||
$payParams = [];
|
||||
$payParams["userId"] = (int)$order['userId'];
|
||||
$payParams["refundId"] = $refundId;
|
||||
$payParams["isBatch"] = (int)$order['isBatch'];
|
||||
$payParams["content"] = $content;
|
||||
$pdata = array();
|
||||
$pdata["userId"] = $order['userId'];
|
||||
$pdata["transId"] = $refund_no;
|
||||
$pdata["paramsVa"] = json_encode($payParams);
|
||||
$pdata["payFrom"] = 'weixinpays';
|
||||
$m = new PM();
|
||||
$m->addPayLog($pdata);
|
||||
$rs = $wxrefund->getResult();
|
||||
if($rs["result_code"]=="SUCCESS"){
|
||||
return WSTReturn("退款成功",1);
|
||||
}else{
|
||||
return WSTReturn($rs['err_code_des'],-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步通知
|
||||
*/
|
||||
public function notify(){
|
||||
// 使用通用通知接口
|
||||
$notify = new \Notify();
|
||||
// 存储微信的回调
|
||||
$xml = file_get_contents("php://input");
|
||||
$notify->saveData ( $xml );
|
||||
if ($notify->data ["return_code"] == "SUCCESS"){
|
||||
$order = $notify->getData ();
|
||||
$req_info = $order["req_info"];
|
||||
|
||||
$reqinfo = $notify->decryptReqinfo($req_info);//解密退款加密信息
|
||||
$transId = $reqinfo["out_refund_no"];
|
||||
$m = new PM();
|
||||
$payParams = $m->getPayLog(["transId"=>$transId]);
|
||||
$content = $payParams['content'];
|
||||
$refundId = $payParams['refundId'];
|
||||
|
||||
$obj = array();
|
||||
$obj['refundTradeNo'] = $reqinfo["refund_id"];//微信退款单号
|
||||
$obj['content'] = $content;
|
||||
$obj['refundId'] = $refundId;
|
||||
$rs = model('admin/OrderRefunds')->complateOrderRefund($obj);
|
||||
if($rs['status']==1){
|
||||
echo "SUCCESS";
|
||||
}else{
|
||||
echo "FAIL";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
113
hyhproject/admin/model/WeixinpaysApp.php
Executable file
113
hyhproject/admin/model/WeixinpaysApp.php
Executable file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Loader;
|
||||
use think\Db;
|
||||
use Env;
|
||||
use wstmart\common\model\Payments as M;
|
||||
use wstmart\common\model\LogPayParams as PM;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 微信支付业务处理
|
||||
*/
|
||||
class WeixinpaysApp extends Base{
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private $wxpayConfig;
|
||||
private $wxpay;
|
||||
public function initialize() {
|
||||
header ("Content-type: text/html; charset=utf-8");
|
||||
require Env::get('root_path') . 'extend/wxpay/WxPayConf.php';
|
||||
require Env::get('root_path') . 'extend/wxpay/WxJsApiPay.php';
|
||||
$this->wxpayConfig = array();
|
||||
$m = new M();
|
||||
$this->wxpay = $m->getPayment("app_weixinpays");
|
||||
$this->wxpayConfig['appid'] = $this->wxpay['appId']; // 微信公众号身份的唯一标识
|
||||
$this->wxpayConfig['appsecret'] = $this->wxpay['appsecret']; // JSAPI接口中获取openid
|
||||
$this->wxpayConfig['mchid'] = $this->wxpay['mchId']; // 受理商ID
|
||||
$this->wxpayConfig['key'] = $this->wxpay['apiKey']; // 商户支付密钥Key
|
||||
|
||||
$this->wxpayConfig['apiclient_cert'] = WSTRootPath().'/extend/wxpay/cert2/apiclient_cert.pem'; // 商户支付证书
|
||||
$this->wxpayConfig['apiclient_key'] = WSTRootPath().'/extend/wxpay/cert2/apiclient_key.pem'; // 商户支付证书
|
||||
|
||||
$this->wxpayConfig['curl_timeout'] = 30;
|
||||
$this->wxpayConfig['notifyurl'] = url("admin/orderrefunds/wxapprefundnodify","",true,true);
|
||||
$this->wxpayConfig['returnurl'] = "";
|
||||
// 初始化WxPayConf
|
||||
new \WxPayConf($this->wxpayConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
public function orderRefund($refund,$order){
|
||||
|
||||
$content = input('post.content');
|
||||
$refundId = (int)input('post.id');
|
||||
|
||||
$wxrefund = new \Refund();
|
||||
$refund_no = $order['orderNo'].$order['userId'];
|
||||
$wxrefund->setParameter("transaction_id",$order['tradeNo']);//微信订单号
|
||||
$wxrefund->setParameter("out_refund_no",$refund_no);//商户退款单号
|
||||
$wxrefund->setParameter("total_fee",$order['totalPayFee']);//订单金额
|
||||
$wxrefund->setParameter("refund_fee",$refund["backMoney"]*100);//退款金额
|
||||
$wxrefund->setParameter("refund_fee_type","CNY");//货币种类
|
||||
$wxrefund->setParameter("refund_desc","订单【".$order['orderNo']."】退款");//退款原因
|
||||
$wxrefund->setParameter("notify_url",$this->wxpayConfig['notifyurl']);//退款原因
|
||||
|
||||
$payParams = [];
|
||||
$payParams["userId"] = (int)$order['userId'];
|
||||
$payParams["refundId"] = $refundId;
|
||||
$payParams["isBatch"] = (int)$order['isBatch'];
|
||||
$payParams["content"] = $content;
|
||||
$pdata = array();
|
||||
$pdata["userId"] = $order['userId'];
|
||||
$pdata["transId"] = $refund_no;
|
||||
$pdata["paramsVa"] = json_encode($payParams);
|
||||
$pdata["payFrom"] = 'app_weixinpays';
|
||||
$m = new PM();
|
||||
$m->addPayLog($pdata);
|
||||
$rs = $wxrefund->getResult();
|
||||
if($rs["result_code"]=="SUCCESS"){
|
||||
return WSTReturn("退款成功",1);
|
||||
}else{
|
||||
return WSTReturn($rs['err_code_des'],-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步通知
|
||||
*/
|
||||
public function notify(){
|
||||
// 使用通用通知接口
|
||||
$notify = new \Notify();
|
||||
// 存储微信的回调
|
||||
$xml = file_get_contents("php://input");
|
||||
$notify->saveData ( $xml );
|
||||
if ($notify->data ["return_code"] == "SUCCESS"){
|
||||
$order = $notify->getData ();
|
||||
$req_info = $order["req_info"];
|
||||
|
||||
$reqinfo = $notify->decryptReqinfo($req_info);//解密退款加密信息
|
||||
$transId = $reqinfo["out_refund_no"];
|
||||
$m = new PM();
|
||||
$payParams = $m->getPayLog(["transId"=>$transId]);
|
||||
$content = $payParams['content'];
|
||||
$refundId = $payParams['refundId'];
|
||||
|
||||
$obj = array();
|
||||
$obj['refundTradeNo'] = $reqinfo["refund_id"];//微信退款单号
|
||||
$obj['content'] = $content;
|
||||
$obj['refundId'] = $refundId;
|
||||
$rs = model('admin/OrderRefunds')->complateOrderRefund($obj);
|
||||
if($rs['status']==1){
|
||||
echo "SUCCESS";
|
||||
}else{
|
||||
echo "FAIL";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
70
hyhproject/admin/model/WxPassiveReplys.php
Executable file
70
hyhproject/admin/model/WxPassiveReplys.php
Executable file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 微信被动回复业务处理
|
||||
*/
|
||||
class WxPassiveReplys extends Base{
|
||||
/**
|
||||
* 文本消息分页
|
||||
*/
|
||||
public function textPageQuery(){
|
||||
return $this->where(['dataFlag'=>1,'msgType'=>'text'])->field(true)->order('id desc')->paginate(input('limit/d'));
|
||||
}
|
||||
/**
|
||||
* 图文消息分页
|
||||
*/
|
||||
public function newsPageQuery(){
|
||||
$rs = $this->where(['dataFlag'=>1,'msgType'=>'news'])->field(true)->order('id desc')->paginate(input('limit/d'));
|
||||
return WSTReturn('',1,$rs);
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
return $this->get(['id'=>$id,'dataFlag'=>1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
WSTUnset($data,'id');
|
||||
|
||||
$result = $this->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}
|
||||
return WSTReturn($this->getError(), -1);
|
||||
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$Id = (int)input('post.id');
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'createTime');
|
||||
$result = $this->allowField(true)->save($data,['id'=>$Id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}
|
||||
return WSTReturn('编辑失败',-1);
|
||||
}
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$id = (int)input('post.id/d');
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->update($data,['id'=>$id]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}
|
||||
return WSTReturn('编辑失败',-1);
|
||||
}
|
||||
}
|
49
hyhproject/admin/model/WxTemplateParams.php
Executable file
49
hyhproject/admin/model/WxTemplateParams.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 微信消息参数模板业务处理
|
||||
*/
|
||||
class WxTemplateParams extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function listQuery($parentId){
|
||||
$rs = $this->where('parentId',$parentId)->select();
|
||||
return WSTReturn('',1,$rs);
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$id = (int)input('post.id/d');
|
||||
$tplCode = input('post.tplCode');
|
||||
$data = [];
|
||||
$data['tplContent'] = input('post.tplContent');
|
||||
$data['tplExternaId'] = input('post.tplExternaId');
|
||||
$data['status'] = input('post.seoMallSwitch');
|
||||
$result = model('admin/TemplateMsgs')->save($data,['id'=>$id,'tplCode'=>$tplCode]);
|
||||
if(false !== $result){
|
||||
cache('WST_MSG_TEMPLATES',null);
|
||||
$this->where('parentId',$id)->delete();
|
||||
$num = (int)input('num');
|
||||
if($num>0){
|
||||
$tdata = [];
|
||||
for($i=0;$i<=$num;$i++){
|
||||
$code = input('code_'.$i);
|
||||
if($code=='')continue;
|
||||
$data = [];
|
||||
$data['parentId'] = $id;
|
||||
$data['fieldCode'] = $code;
|
||||
$data['fieldVal'] = input('val_'.$i);
|
||||
$tdata[] = $data;
|
||||
}
|
||||
if(count($tdata)>0)$this->saveAll($tdata);
|
||||
}
|
||||
return WSTReturn("编辑成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
216
hyhproject/admin/model/Wxmenus.php
Executable file
216
hyhproject/admin/model/Wxmenus.php
Executable file
@ -0,0 +1,216 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 微信菜单业务处理
|
||||
*/
|
||||
class WxMenus extends Base{
|
||||
/**
|
||||
* 获取树形分类
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$list = $this->where(['dataFlag'=>1,'parentId'=>input('menuId/d',0)])->order('menuSort asc,menuId desc')->paginate(input('post.limit/d'))->toArray();
|
||||
foreach($list['Rows'] as $key=>$v){
|
||||
$list['Rows'][$key]['menuUrl'] = htmlspecialchars_decode($v['menuUrl']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*/
|
||||
public function listQuery(){
|
||||
$listMenu = $this->where(['dataFlag'=>1,'parentId'=>0])->field('menuId,menuName')->order('menuSort asc')->select();
|
||||
for ($i = 0; $i < count($listMenu); $i++) {
|
||||
$parentId = $listMenu[$i]["menuId"];
|
||||
$listSon = $this->where(['dataFlag'=>1,'parentId'=>$parentId])->field('menuId,menuName')->order('menuSort asc')->select();
|
||||
$listMenu[$i]['listSon'] = $listSon;
|
||||
}
|
||||
return $listMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定对象
|
||||
*/
|
||||
public function getById($id){
|
||||
$data = $this->where(['menuId'=>$id])->find();
|
||||
$data['menuUrl'] = htmlspecialchars_decode($data['menuUrl']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 与微信菜单同步
|
||||
*/
|
||||
public function synchroWx(){
|
||||
$this->where('menuId>0')->delete();
|
||||
$wx = WXAdmin();
|
||||
$data = $wx->wxMenuGet();
|
||||
if(isset($data['errcode'])){
|
||||
if($data['errcode']!=0)return WSTReturn('与微信同步失败,请清除缓存重试');
|
||||
}
|
||||
if($data){
|
||||
$data = $data['menu']['button'];
|
||||
$type = array('click'=>1,'view'=>2,'scancode_push'=>3,'scancode_waitmsg'=>4,'pic_sysphoto'=>5,'pic_photo_or_album'=>6,'pic_weixin'=>7,'location_select'=>8,'media_id'=>9,'view_limited'=>10);
|
||||
$dataList = [];
|
||||
foreach( $data as $key=>$v){
|
||||
$data = [];
|
||||
$data['menuName'] = $v['name'];
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$data['menuType'] = (isset($v['type']))?$type[$v['type']]:'';
|
||||
$data['menuKey'] = (isset($v['key']))?$v['key']:'';
|
||||
$data['menuSort'] = $key;
|
||||
$data['menuUrl'] = '';
|
||||
$rs = $this->insert($data,false,true);
|
||||
if($v['sub_button']){
|
||||
foreach($v['sub_button'] as $keys=>$vs){
|
||||
$datas = [];
|
||||
$datas['menuName'] = $vs['name'];
|
||||
$datas['parentId'] = $rs;
|
||||
$datas['menuSort'] = $keys;
|
||||
$datas['createTime'] = date('Y-m-d H:i:s');
|
||||
$datas['menuType'] = (isset($vs['type']))?$type[$vs['type']]:'';
|
||||
$datas['menuKey'] = (isset($vs['key']))?$vs['key']:'';
|
||||
$datas['menuUrl'] = (isset($vs['url']))?$vs['url']:'';
|
||||
$dataList[] = $datas;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->insertAll($dataList);
|
||||
return WSTReturn("与微信同步成功", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步到微信菜单
|
||||
*/
|
||||
public function synchroAd(){
|
||||
$rs = Db::name('wx_menus')->where('dataFlag=1')->order('menuSort asc')->select();
|
||||
$arr = $this->makeNewArr($rs,0);
|
||||
header('content-type:text/html;charset=utf-8');
|
||||
$arr = json_encode($arr,JSON_UNESCAPED_UNICODE);
|
||||
$wx = WXAdmin();
|
||||
$data = $wx->wxMenuCreate($arr);
|
||||
if($data['errcode']==0){
|
||||
return WSTReturn('菜单同步成功',1);
|
||||
}
|
||||
return WSTReturn('菜单同步失败,请清除缓存重试');
|
||||
}
|
||||
function makeNewArr($data,$pId){
|
||||
$type = array(1=>'click',2=>'view',3=>'scancode_push',4=>'scancode_waitmsg',5=>'pic_sysphoto',6=>'pic_photo_or_album',7=>'pic_weixin',8=>'location_select',9=>'media_id',10=>'view_limited');
|
||||
$c=0;
|
||||
$newArr = [];
|
||||
foreach($data as $k=>$v){
|
||||
if($v['parentId']==$pId){
|
||||
$sub_button = $this->makeNewArr($data,$v['menuId']);
|
||||
if($pId==0){
|
||||
$arr = ['name'=>$v['menuName']];
|
||||
if(!empty($sub_button)){
|
||||
$arr['sub_button'] = $sub_button;
|
||||
}else{
|
||||
$arr['key']=$v['menuKey'];
|
||||
$arr['type']=$type[$v['menuType']];
|
||||
if($v['menuUrl']!='')
|
||||
$arr['url']= htmlspecialchars_decode($v['menuUrl']);
|
||||
}
|
||||
$newArr['button'][] = $arr;
|
||||
}else{
|
||||
$newArr[$c]['name'] = $v['menuName'];
|
||||
$newArr[$c]['key'] = $v['menuKey'];
|
||||
$newArr[$c]['type'] =$type[$v['menuType']];
|
||||
if($v['menuUrl']!='')
|
||||
$newArr[$c]['url'] = htmlspecialchars_decode($v['menuUrl']);
|
||||
++$c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $newArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜单个数
|
||||
*/
|
||||
function menuNum($parentId){
|
||||
$rs = $this->where(['parentId'=>$parentId,'dataFlag'=>1])->field('menuId')->select();
|
||||
return count($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(){
|
||||
$data = input('post.');
|
||||
if($data['content']==0){
|
||||
$data['menuType'] = 2;
|
||||
}
|
||||
WSTUnset($data,'menuId,dataFlag,content');
|
||||
if(!$data['menuName'])return WSTReturn("请输入菜单名称");
|
||||
$num = $this->menuNum($data['parentId']);
|
||||
if($data['parentId']==0){
|
||||
if($num>=3)return WSTReturn("一级菜单数,个数应为1~3个 ");
|
||||
}else{
|
||||
if($num>=5)return WSTReturn("二级菜单数,个数应为1~5个 ");
|
||||
}
|
||||
$data['parentId'] = $data['parentId'];
|
||||
$data['createTime'] = date('Y-m-d H:i:s');
|
||||
$result = $this->allowField(true)->save($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("新增成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$menuId = input('post.menuId/d');
|
||||
$data = input('post.');
|
||||
if($data['content']==0){
|
||||
$data['menuType'] = 2;
|
||||
}
|
||||
WSTUnset($data,'menuId,dataFlag,createTime,content');
|
||||
if(!$data['menuName'])return WSTReturn("请输入菜单名称");
|
||||
$result = $this->allowField(true)->save($data,['menuId'=>$menuId]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("修改成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del(){
|
||||
$ids = array();
|
||||
$ids[] = input('post.id/d');
|
||||
$ids = $this->getChild($ids,$ids);
|
||||
$data = [];
|
||||
$data['dataFlag'] = -1;
|
||||
$result = $this->where("menuId in(".implode(',',$ids).")")->update($data);
|
||||
if(false !== $result){
|
||||
return WSTReturn("删除成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 迭代获取下级
|
||||
*/
|
||||
public function getChild($ids = array(),$pids = array()){
|
||||
$result = $this->where("dataFlag=1 and parentId in(".implode(',',$pids).")")->field('menuId')->select();
|
||||
if(count($result)>0){
|
||||
$cids = array();
|
||||
foreach ($result as $key =>$v){
|
||||
$cids[] = $v['menuId'];
|
||||
}
|
||||
$ids = array_merge($ids,$cids);
|
||||
return $this->getChild($ids,$cids);
|
||||
}else{
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
}
|
115
hyhproject/admin/model/Wxusers.php
Executable file
115
hyhproject/admin/model/Wxusers.php
Executable file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
namespace wstmart\admin\model;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 微信用户业务处理
|
||||
*/
|
||||
class WxUsers extends Base{
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
public function pageQuery(){
|
||||
$key = input('get.key');
|
||||
$where = [];
|
||||
if($key!='')$where['userName'] = ['like','%'.$key.'%'];
|
||||
return $this->where($where)->order('subscribeTime desc,userId desc')->paginate(input('post.limit/d'))->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定对象
|
||||
*/
|
||||
public function getById($id){
|
||||
return $this->where(['userId'=>$id])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 与微信用户管理同步
|
||||
*/
|
||||
public function synchroWx(){
|
||||
$this->where('userId>0')->delete();
|
||||
$wx = WXAdmin();
|
||||
$data = $wx->wxUserGet();
|
||||
if(isset($data['errcode'])){
|
||||
if($data['errcode']!=0)return WSTReturn('与微信同步失败,请清除缓存重试');
|
||||
}
|
||||
if(isset($data['data']) && count($data['data']['openid'])>0){
|
||||
$dataList = [];
|
||||
foreach($data['data']['openid'] as $key=>$v){
|
||||
$datas = [];
|
||||
$datas['openId'] = $v;
|
||||
$datas['userFill'] = -1;
|
||||
$dataList[] = $datas;
|
||||
}
|
||||
$this->insertAll($dataList);
|
||||
return WSTReturn("共".$data['total']."个用户需同步", 1,$dataList);
|
||||
}
|
||||
}
|
||||
|
||||
public function wxLoad(){
|
||||
$openId = input('post.id');
|
||||
$wx = WXAdmin();
|
||||
$userInfo = $wx->wxUserInfo($openId);
|
||||
if(isset($userInfo['errcode'])){
|
||||
if($userInfo['errcode']!=0)return WSTReturn('与微信同步失败,请清除缓存重试');
|
||||
}
|
||||
$data = [];
|
||||
$data['userName'] = $userInfo['nickname'];
|
||||
$data['userSex'] = $userInfo['sex'];
|
||||
$data['userAreas'] = $userInfo['country'].$userInfo['province'].$userInfo['city'];
|
||||
$data['userPhoto'] = $userInfo['headimgurl'];
|
||||
$data['userRemark'] = $userInfo['remark'];
|
||||
$data['subscribeTime'] = date('Y-m-d H:i:s',$userInfo['subscribe_time']);
|
||||
$data['groupId'] = $userInfo['groupid'];
|
||||
$data['openId'] = $userInfo['openid'];
|
||||
$data['userFill'] = 1;
|
||||
$result = $this->update($data,['openId'=>$openId,'userFill'=>-1]);
|
||||
if(false !== $result){
|
||||
return WSTReturn("", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(){
|
||||
$userId = input('post.id/d');
|
||||
$data = input('post.');
|
||||
WSTUnset($data,'userId,userName,userSex,userAreas,userPhoto,subscribeTime,groupId,openId');
|
||||
$result = $this->allowField(true)->save($data,['userId'=>$userId]);
|
||||
if(false !== $result){
|
||||
$info = $this->getById($userId);
|
||||
$wdata = [];
|
||||
$wdata["openid"] = $info["openId"];
|
||||
$wdata["remark"] = $info["userRemark"];
|
||||
$wdata = json_encode($wdata,JSON_UNESCAPED_UNICODE);
|
||||
$wx = WXAdmin();
|
||||
$data = $wx->wxUpdateremark($wdata);
|
||||
return WSTReturn("修改成功", 1);
|
||||
}else{
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 写入unionId
|
||||
*/
|
||||
public function recodeUnionId(){
|
||||
$m = new \wstmart\common\model\Users;
|
||||
// 取出已关联微信的账号
|
||||
$rs = $m->field('userId,wxOpenId')->where(['wxOpenId'=>['<>','']])->where("isNull(wxUnionId)")->select();
|
||||
if(empty($rs))return WSTReturn('无需写入unionId');
|
||||
// 写入UnionId
|
||||
$wx = WXAdmin();
|
||||
$update = [];
|
||||
foreach($rs as $k=>$v){
|
||||
$data = $wx->wxUserInfo($v['wxOpenId']);
|
||||
$item = ['userId'=>$v['userId'],'wxUnionId'=>$data['unionid']];
|
||||
array_push($update, $item);
|
||||
}
|
||||
$flag = $m->saveAll($update);
|
||||
if($flag!==false)return WSTReturn('unionId写入完成',1);
|
||||
return WSTReturn($this->getError(),-1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user