628 lines
24 KiB
PHP
Executable File
628 lines
24 KiB
PHP
Executable File
<?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');
|
|
}
|
|
}
|