1367 lines
60 KiB
PHP
Executable File
1367 lines
60 KiB
PHP
Executable File
<?php
|
||
namespace wstmart\admin\model;
|
||
use think\Db;
|
||
use think\Loader;
|
||
use think\Validate;
|
||
/**
|
||
* ============================================================================
|
||
* 店铺业务处理
|
||
*/
|
||
class Shops extends Base{
|
||
/**
|
||
* 分页
|
||
*/
|
||
public function pageQuery($shopStatus=1){
|
||
$areaIdPath = input('areaIdPath');
|
||
$shopName = input('shopName');
|
||
$telephone = input('userPhone');
|
||
$catId =(int)input('cat');
|
||
$isInvestment = (int)input('isInvestment/d',-1);
|
||
$where = [];
|
||
$where['s.dataFlag'] = 1;
|
||
$where['s.applyStatus'] = 2;
|
||
$where['s.shopStatus'] = $shopStatus;
|
||
if($catId!="0"){
|
||
$where['c.catId'] = $catId;
|
||
}
|
||
if(in_array($isInvestment,[0,1]))$where['ss.isInvestment'] = $isInvestment;
|
||
if($shopName!='')$where['shopName'] = ['like','%'.$shopName.'%'];
|
||
if($telephone!='')$where['telephone'] = ['like','%'.$telephone.'%'];
|
||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||
if($catId !='')$where['catId'] = ['like',$catId."%"];
|
||
$sort = input('sort');
|
||
$order = [];
|
||
if($sort!=''){
|
||
$sortArr = explode('.',$sort);
|
||
$order = $sortArr[0].' '.$sortArr[1];
|
||
}
|
||
$result=Db::table('__SHOPS__')->alias('s')
|
||
->join('__AREAS__ a2','s.areaId=a2.areaId','left')
|
||
->join('__USERS__ u','u.userId=s.userId','left')
|
||
->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','left')
|
||
->join('__CAT_SHOPS__ c','c.shopId=s.shopId','left')
|
||
->join('__SHOP_PAY__ sp','sp.shopId=s.shopId','left')
|
||
->join('__SHOP_COMMISSION__ sc','sc.shopId=s.shopId','left')
|
||
->where($where)
|
||
->field('u.loginName,s.shopId,shopSn,shopName,a2.areaName,shopkeeper,telephone,shopAddress,shopCompany,shopAtive,shopStatus,s.applyTime,s.createTime,sp.status,sc.commission')
|
||
->order('createTime desc')->group('s.shopId')
|
||
->paginate(input('limit/d'))->toArray();
|
||
foreach ($result['Rows'] as &$value) {
|
||
$catName=db('cat_shops')->alias('a')->join('goods_cats g','g.catId=a.catId')
|
||
->where('shopId',$value['shopId'])->field('catName')->select();
|
||
$value['catName']="";
|
||
if(count($catName)>1){
|
||
foreach ($catName as &$v) {
|
||
$value['catName']=$value['catName'].$v['catName'].',';
|
||
}
|
||
}
|
||
$goodsNum=db('goods')->alias('g')->where(['shopId'=>$value['shopId'],'isSale'=>1,'dataFlag'=>1])->field('count(goodsId)goodsNum')->select();
|
||
$value['goodsNum']="";
|
||
foreach ($goodsNum as &$v) {
|
||
$value['goodsNum']=$value['goodsNum'].$v['goodsNum'];
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
/**
|
||
* 分页>where('a.orgin_id=b.id AND a.orgin_id=c.orgin_id AND b.status='.$status.' AND a.task_name like %'.$serch_val.'%')
|
||
*/
|
||
public function pageQueryByApply(){
|
||
$areaIdPath = input('areaIdPath');
|
||
//$catId = input('cat/d');
|
||
$shopName = input('shopName');
|
||
$investmentStaff = input('investmentStaff');// mark hsf 20180112
|
||
$isInvestment = (int)input('isInvestment/d',-1);
|
||
$where = [];
|
||
$where['s.dataFlag'] = 1;
|
||
$where['s.applyStatus'] = ['in',[-1,1,2]];// mark hsf 20180112
|
||
if(in_array($isInvestment,[0,1]))$where['ss.isInvestment'] = $isInvestment;
|
||
if($shopName!='')$where['shopName'] = ['like','%'.$shopName.'%'];
|
||
if($investmentStaff!='')$where['ss.investmentStaff'] = ['like','%'.$investmentStaff.'%'];// mark hsf 20180112
|
||
//if($catId !='')$where['catId'] = ['like',$catId."%"];
|
||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||
return Db::table('__SHOPS__')->alias('s')->join('__AREAS__ a2','s.areaId=a2.areaId','left')
|
||
->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','left')
|
||
->join('__USERS__ u','u.userId=s.userId','left')
|
||
//->join('__CAT_SHOPS__ c','c.shopId=s.shopId','left')
|
||
->where($where)
|
||
->field('u.loginName,s.shopId,applyLinkMan,applyLinkTel,investmentStaff,isInvestment,shopName,a2.areaName,shopAddress,shopCompany,applyTime,applyStatus')
|
||
->order('s.applyStatus=1 DESC,s.applyStatus ASC,s.shopId desc')->paginate(input('limit/d'));// mark hsf 20180112
|
||
}
|
||
/**
|
||
* 开店申请列表
|
||
*/
|
||
public function shopApplyList(){
|
||
//$areaIdPath = input('areaIdPath');
|
||
$shopName = input('shopName');
|
||
$where = [];
|
||
$where['s.dataFlag'] = 1;
|
||
if($shopName!='')$where['shopName'] = ['like','%'.$shopName.'%'];
|
||
//if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||
return Db::name('shops')->alias('s')
|
||
->join('__USERS__ u','u.userId=s.userId','left')
|
||
->where($where)
|
||
->field('u.loginName,u.trueName,s.*,from_unixtime(s.createTime) applyTime')
|
||
->order('s.status ASC,s.createTime ASC')->paginate(input('limit/d'));// mark hsf 20180112
|
||
// return Db::table('__SHOPS__')->alias('s')->join('__AREAS__ a2','s.areaId=a2.areaId','left')
|
||
// ->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','left')
|
||
// ->join('__USERS__ u','u.userId=s.userId','left')
|
||
// //->join('__CAT_SHOPS__ c','c.shopId=s.shopId','left')
|
||
// ->where($where)
|
||
// ->field('u.loginName,s.shopId,applyLinkMan,applyLinkTel,investmentStaff,isInvestment,shopName,a2.areaName,shopAddress,shopCompany,applyTime,applyStatus')
|
||
// ->order('s.applyStatus=1 DESC,s.applyStatus ASC,s.shopId desc')->paginate(input('limit/d'));// mark hsf 20180112
|
||
}
|
||
|
||
/**
|
||
* 为店铺添加质保金
|
||
*/
|
||
public function topDeposit(){
|
||
Db::startTrans();
|
||
try{
|
||
$shopId = input('shopId');
|
||
$applyStatus = (int)input('applyStatus');
|
||
$cashDeposit = input('addDeposit');//充值质保金金额
|
||
$offDeposit = input('offDeposit');//扣除质保金金额
|
||
$offCause = input('offCause');//扣除质保金原因
|
||
// echo $offCause;die;
|
||
// echo $applyStatus;die;
|
||
if($applyStatus == 1){
|
||
$deposit_info = Db::name('shops_deposit')->where('shopId',$shopId)->field('shopId,payDeposit,cashDeposit')->find();
|
||
// dump($deposit_info);die;
|
||
$data_deposit['cashDeposit'] = $deposit_info['cashDeposit'] + $cashDeposit;
|
||
// echo $data_deposit['cashDeposit'];die;
|
||
|
||
if($deposit_info['payDeposit'] < $data_deposit['cashDeposit']){
|
||
return WSTReturn("质保金大于店铺应交剩余金额",2);
|
||
}elseif($deposit_info['payDeposit'] == $data_deposit['cashDeposit']){
|
||
$data_deposit['isFinish'] = 1;
|
||
$data_deposit['completeTime'] = time();
|
||
}
|
||
|
||
$res = Db::name('shops_deposit')->where('shopId',$shopId)->update($data_deposit);//商户充值质保金
|
||
//添加到质保金变动记录表
|
||
$detail = [];
|
||
$detail['shopId'] = $shopId;
|
||
$detail['cashDeposit'] = $cashDeposit;
|
||
$detail['payType'] = 3;
|
||
$detail['payTime'] = time();
|
||
Db::name('shops_deposit_detail')->insert($detail);
|
||
}else{
|
||
|
||
$deposit_info = Db::name('shops_deposit')->where('shopId',$shopId)->field('shopId,payDeposit,cashDeposit')->find();
|
||
$data_deposit['cashDeposit'] = $deposit_info['cashDeposit'] - $offDeposit;
|
||
$data_deposit['isFinish'] = 2;
|
||
Db::name('shops_deposit')->where('shopId',$shopId)->update($data_deposit);//扣除商户质保金
|
||
//添加到质保金变动记录表
|
||
$detail = [];
|
||
$detail['shopId'] = $shopId;
|
||
$detail['cashDeposit'] = $offDeposit;
|
||
$detail['payType'] = 4;
|
||
$detail['payTime'] = time();
|
||
Db::name('shops_deposit_detail')->insert($detail);
|
||
//为商户发送扣除质保金提醒
|
||
$userId = Db::name('shops')->where('shopId',$shopId)->field('userId')->find();
|
||
// dump($userId);die;
|
||
$messages = [];
|
||
$messages['msgType'] = 1;
|
||
$messages['sendUserId'] = 1;
|
||
$messages['receiveUserId'] = $userId['userId'];
|
||
$messages['msgContent'] = $offCause;
|
||
$messages['msgStatus'] = 0;
|
||
$messages['msgJson'] = '{"from":0,"dataId":"0"}';
|
||
$messages['dataFlag'] = 1;
|
||
$messages['from'] = 0;
|
||
$messages['createTime'] = date('Y-m-d',time());
|
||
Db::name('messages')->insert($messages);
|
||
}
|
||
Db::commit();
|
||
return WSTReturn('操作成功',1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('操作失败',2);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
*/
|
||
public function del(){
|
||
$id = input('post.id/d');
|
||
if($id==1)return WSTReturn('无法删除自营店铺');
|
||
Db::startTrans();
|
||
try{
|
||
$shop = $this->get($id);
|
||
$shop->dataFlag = -1;
|
||
$result = $shop->save();
|
||
WSTUnuseImage('shops','shopImg',$id);
|
||
// 店铺申请表的图片标记为删除
|
||
$imgArr = model('shopExtras')->field('legalCertificateImg,businessLicenceImg,bankAccountPermitImg,organizationCodeImg,taxRegistrationCertificateImg,taxpayerQualificationImg')->where(['shopId'=>$id])->find();
|
||
WSTUnuseImage($imgArr->getData());
|
||
if(false !== $result){
|
||
//删除推荐店铺
|
||
Db::name('recommends')->where(['dataSrc'=>1,'dataId'=>$id])->delete();
|
||
//删除店铺与商品分类的关系
|
||
Db::name('cat_shops')->where(['shopId'=>$id])->delete();
|
||
//删除用户店铺身份
|
||
Db::name('users')->where(['userId'=>$shop->userId])->update(['dataFlag'=>-1]);
|
||
//下架及下架商品
|
||
model('goods')->delByshopId($id);
|
||
//删除店铺钩子事件
|
||
hook('afterChangeShopStatus',['shopId'=>$id]);
|
||
Db::commit();
|
||
return WSTReturn("删除成功", 1);
|
||
}
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
}
|
||
return WSTReturn('删除失败',-1);
|
||
}
|
||
/**
|
||
* 根据根据userId删除店铺
|
||
*/
|
||
public function delByUserId($userId){
|
||
if($userId==1)return WSTReturn('无法删除自营店铺');
|
||
$shop = $this->where('userId',$userId)->find();
|
||
if(!$shop)return;
|
||
$shop->dataFlag = -1;
|
||
$result = $shop->save();
|
||
WSTUnuseImage('shops','shopImg',$shop->shopId);
|
||
if(false !== $result){
|
||
//删除推荐店铺
|
||
Db::name('recommends')->where(['dataSrc'=>1,'dataId'=>$shop->shopId])->delete();
|
||
//删除店铺与商品分类的关系
|
||
Db::name('cat_shops')->where(['shopId'=>$shop->shopId])->delete();
|
||
//下架及删除商品
|
||
model('goods')->delByshopId($shop->shopId);
|
||
//删除店铺钩子事件
|
||
hook('afterChangeShopStatus',['shopId'=>$shop->shopId]);
|
||
return WSTReturn("删除成功", 1);
|
||
}
|
||
return WSTReturn('删除失败',-1);
|
||
}
|
||
/**
|
||
* 获取商家入驻资料
|
||
*/
|
||
public function getShopApply($id){
|
||
$shop = $this->alias('s')->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','inner')
|
||
->join('__USERS__ u','u.userId=s.userId','inner')
|
||
->where('s.shopId',$id)
|
||
->find()
|
||
->toArray();
|
||
//获取经营范围
|
||
$goodscats = Db::name('cat_shops')->where('shopId',$id)->select();
|
||
$shop['catshops'] = [];
|
||
foreach ($goodscats as $v){
|
||
$shop['catshops'][$v['catId']] = true;
|
||
}
|
||
$shop['auxiliary']=db('shop_auxiliary')->where('shopId',$shop['shopId'])->select();
|
||
$shop['taxRegistrationCertificateImgVO'] = ($shop['taxRegistrationCertificateImg']!='')?explode(',',$shop['taxRegistrationCertificateImg']):[];
|
||
return $shop;
|
||
}
|
||
/**
|
||
* 获取店铺信息
|
||
*/
|
||
public function getById($id){
|
||
$shop = $this->alias('s')->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','inner')
|
||
->where('s.shopId',$id)
|
||
->find()
|
||
->toArray();
|
||
//获取经营范围
|
||
$goodscats = Db::name('cat_shops')->where('shopId',$id)->select();
|
||
$shop['catshops'] = [];
|
||
foreach ($goodscats as $v){
|
||
$shop['catshops'][$v['catId']] = true;
|
||
}
|
||
//获取认证类型
|
||
$shopAccreds = Db::name('shop_accreds')->where('shopId',$id)->select();
|
||
$shop['accreds'] = [];
|
||
foreach ($shopAccreds as $v){
|
||
$shop['accreds'][$v['accredId']] = true;
|
||
}
|
||
$shop['taxRegistrationCertificateImgVO'] = ($shop['taxRegistrationCertificateImg']!='')?explode(',',$shop['taxRegistrationCertificateImg']):[];
|
||
return $shop;
|
||
}
|
||
/**
|
||
* 生成店铺编号
|
||
* @param $key 编号前缀,要控制不要超过int总长度,最好是一两个字母
|
||
*/
|
||
public function getShopSn($key = ''){
|
||
$rs = $this->Max("REPLACE(shopSn,'S','')+''");
|
||
if($rs==''){
|
||
return $key.'000000001';
|
||
}else{
|
||
for($i=0;$i<1000;$i++){
|
||
$num = (int)str_replace($key,'',$rs);
|
||
$shopSn = $key.sprintf("%09d",($num+1));
|
||
$ischeck = $this->checkShopSn($shopSn);
|
||
if(!$ischeck)return $shopSn;
|
||
}
|
||
return '';//一直都检测到那就不要强行添加了
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 检测店铺编号是否存在
|
||
*/
|
||
public function checkShopSn($shopSn,$shopId=0){
|
||
$dbo = $this->where(['shopSn'=>$shopSn,'dataFlag'=>1]);
|
||
if($shopId>0)$dbo->where('shopId','<>',$shopId);
|
||
$num = $dbo->Count();
|
||
if($num==0)return false;
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 处理申请
|
||
*/
|
||
public function handleApply(){
|
||
$data = input('post.');
|
||
$shopId=$data['shopId'];
|
||
Db::startTrans();
|
||
try{
|
||
$shops = $this->get($shopId);
|
||
if($data['status']==1){
|
||
//建立店铺配置信息
|
||
$sc = [];
|
||
$sc['shopId'] = $shopId;
|
||
if(!Db::name('ShopConfigs')->where($sc)->value('shopId')){
|
||
Db::name('ShopConfigs')->insert($sc);
|
||
}
|
||
if(!Db::name('shop_users')->where($sc)->value('shopId')){
|
||
$su = [];
|
||
$su["shopId"] = $shopId;
|
||
$su["userId"] = $shops->userId;
|
||
$su["roleId"] = 0;
|
||
Db::name('shop_users')->insert($su);
|
||
}
|
||
if(!Db::name('shop_scores')->where($sc)->value('shopId')){
|
||
//建立店铺评分记录
|
||
$ss = [];
|
||
$ss['shopId'] = $shopId;
|
||
Db::name('shop_scores')->insert($ss);
|
||
}
|
||
|
||
Db::name('shops')->where(['shopId'=>$shopId])->update(['status'=>1]);
|
||
if($shops->status!=$data['status']){
|
||
$userInfo = getUserInfo(['userId'=>$shops->userId],'userLevel,userType');
|
||
if($userInfo['userLevel'] == 0 || $userInfo['userType'] == 0){
|
||
$user_data['userLevel'] = empty($userInfo['userLevel']) ? 1 : $userInfo['userLevel'];
|
||
$user_data['userType'] = empty($userInfo['userType']) ? 1 : $userInfo['userType'];
|
||
Db::name('users')->where(['userId'=>$shops->userId])->update($user_data);
|
||
}
|
||
//发送开店成功短信
|
||
$tpl = WSTMsgTemplates('PHONE_USER_SHOP_OPEN_SUCCESS');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1' && $data['phone']!=''){
|
||
$params = ['tpl'=>$tpl,'params'=>['MALL_NAME'=>WSTConf("CONF.mallName"),'LOGIN_NAME'=>$data['userName']]];
|
||
$rv = model('admin/LogSms')->sendSMS(0,$shops->userId,$data['phone'],$params,'handleApply');
|
||
}
|
||
}
|
||
//店铺申请成功之后钩子 mark 20180530 by zll
|
||
//hook('afterShopHandleApply',['userId'=>$shops->userId]);
|
||
}else{
|
||
if($shops->status!=$data['status']){
|
||
//发送开店失败短信
|
||
$tpl = WSTMsgTemplates('PHONE_SHOP_OPEN_FAIL');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1' && $data['phone']!=''){
|
||
$params = ['tpl'=>$tpl,'params'=>['MALL_NAME'=>WSTConf("CONF.mallName"),'REASON'=>$data['applyDesc']]];
|
||
$rv = model('admin/LogSms')->sendSMS(0,$shops->userId,$data['phone'],$params,'handleApply');
|
||
}
|
||
}
|
||
}
|
||
$this->allowField(true)->save($data,['shopId'=>$shopId]);
|
||
Db::commit();
|
||
// //店铺申请成功之后钩子 mark 20180530 by zll
|
||
// hook('afterShopHandleApply',['userId'=>$shops->userId,'applyStatus'=>$data['applyStatus']]);
|
||
return WSTReturn("操作成功", 1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
//return WSTReturn($e->getMessage());
|
||
return WSTReturn('操作失败',-1);
|
||
//echo $e->getMessage();
|
||
}
|
||
}
|
||
public function handleApplyTest(){
|
||
$shopId = input('post.shopId/d',0);
|
||
$shops = $this->get($shopId);
|
||
$shopAds=input('shopAds');
|
||
$auxiliary=explode(',',$shopAds);
|
||
if(empty($shops))return WSTReturn('删除失败,该入驻申请不存在');
|
||
if($shops->applyStatus==2)return WSTReturn('该入驻申请已通过',1);
|
||
$validate = Loader::validate('Shops');
|
||
if(!$validate->check(Input('post.')))return WSTReturn($validate->getError());
|
||
|
||
//判断经营范围
|
||
$goodsCatIds = input('post.goodsCatIds');
|
||
$accredIds = input('post.accredIds');
|
||
if($goodsCatIds=='')return WSTReturn('请选择经营范围');
|
||
$data = input('post.');
|
||
$data['createTime']=date('Y-m-d');
|
||
$data['applyStatus'] = ($data['applyStatus']==2)?2:-1;
|
||
if($data['applyStatus']!=2 && $data['applyDesc']==''){
|
||
return WSTReturn('请输入审核不通过原因');
|
||
}
|
||
if($data['applyStatus']==2 && $data['cashDeposit'] ==''){
|
||
return WSTReturn('请输入实缴保证金');
|
||
}
|
||
if($data['applyStatus']==2 && !is_numeric($data['cashDeposit'])){
|
||
return WSTReturn('实缴保证金请输入数字');
|
||
}
|
||
$shopLicense=input('shopLicense');
|
||
if((strpos($data['goodsCatIds'],'393')!==false)||$data['goodsCatIds']=='393'){
|
||
if($shopLicense==""){
|
||
return WSTReturn('食品许可证不能为空');
|
||
}
|
||
}else{
|
||
$data['shopLicense']='';
|
||
}
|
||
|
||
// $goodsCatIds = $data['goodsCatIds'];
|
||
if($data['payDeposit'] !=''){
|
||
if(!is_numeric($data['payDeposit'])){
|
||
return WSTReturn('应缴保证金请输入数字');
|
||
}
|
||
$payDeposit['payDeposit'] = $data['payDeposit'];
|
||
}else{
|
||
$payDeposit = Db::name('goods_cats')->where('catId',$goodsCatIds)->field('payDeposit')->find();
|
||
}
|
||
// dump($payDeposit);die;
|
||
$cashDeposit = $data['cashDeposit'];
|
||
$isFinish = '';
|
||
$completeTime = '';
|
||
if($payDeposit['payDeposit'] > $cashDeposit){
|
||
$isFinish = 2;
|
||
$completeTime = '';
|
||
}elseif($payDeposit['payDeposit'] <= $cashDeposit){
|
||
$isFinish = 1;
|
||
$completeTime = time();
|
||
}//elseif($payDeposit['payDeposit'] < $cashDeposit){
|
||
//return WSTReturn('通过保证金大于经营类目质保金,请重新输入');
|
||
//}
|
||
// echo $isFinish;die;
|
||
Db::startTrans();
|
||
try{
|
||
//保存店铺基础信息
|
||
$auxiliary_data=[];
|
||
$shopAuxiliary = Db::name('shop_auxiliary')->where('shopId='.$shopId)->find();
|
||
WSTUseImages(0, $shopAuxiliary['id'], $auxiliary,'shopauxiliary');
|
||
Db::name('shop_auxiliary')->where('shopId='.$shopId)->delete();
|
||
foreach($auxiliary as $k=>$v){
|
||
$auxiliary_data[$k]['shopId']=$shopId;
|
||
$auxiliary_data[$k]['auxiliaryImg']=$v;
|
||
}
|
||
//dump($shopAuxiliary);die;
|
||
Db::name('shop_auxiliary')->insertAll($auxiliary_data);
|
||
$areaIds = model('Areas')->getParentIs($data['areaId']);
|
||
if(!empty($areaIds))$data['areaIdPath'] = implode('_',$areaIds)."_";
|
||
$areaIds = model('Areas')->getParentIs($data['bankAreaId']);
|
||
if(!empty($areaIds))$data['bankAreaIdPath'] = implode('_',$areaIds)."_";
|
||
WSTUnset($data,'id,shopId,userId,dataFlag,goodsCatIds,accredIds,isSelf');
|
||
if($data['applyStatus']==2 && $data['shopSn']=='')$data['shopSn'] = $this->getShopSn('S');
|
||
$row=db('shop_license')->where('shopId',$shopId)->update(['shopLicense'=>$shopLicense]);
|
||
//启用上传图片
|
||
WSTUseImages(1, $shopId, $data['shopImg'],'shops','shopImg');
|
||
//WSTUseImages(1, $shopId, $shopLicense,'shops','shopLicense');
|
||
$this->allowField(true)->save($data,['shopId'=>$shopId,'dataFlag'=>1,'shopStatus'=>1]);
|
||
//更改用户身份
|
||
if($data['applyStatus']==2){
|
||
Db::name('users')->where('userId',$shops->userId)->update(['userType'=>1]);
|
||
}
|
||
//保存店铺其他信息
|
||
$areaIds = model('Areas')->getParentIs($data['businessAreaPath0']);
|
||
if(!empty($areaIds))$data['businessAreaPath0'] = implode('_',$areaIds)."_";
|
||
//if($data['establishmentDate']=='')unset($data['establishmentDate']);
|
||
//if($data['businessEndDate']=='')unset($data['businessEndDate']);
|
||
//if($data['businessStartDate']=='')unset($data['businessStartDate']);
|
||
//if($data['legalCertificateStartDate']=='')unset($data['legalCertificateStartDate']);
|
||
//if($data['legalCertificateEndDate']=='')unset($data['legalCertificateEndDate']);
|
||
//if($data['organizationCodeStartDate']=='')unset($data['organizationCodeStartDate']);
|
||
//if($data['organizationCodeEndDate']=='')unset($data['organizationCodeEndDate']);
|
||
//$data['registeredCapital'] = (float)$data['registeredCapital'];
|
||
|
||
$seModel = model('ShopExtras');
|
||
$Id = $seModel->where(['shopId'=>$shopId])->value('id');
|
||
/*
|
||
legalCertificateImg
|
||
businessLicenceImg
|
||
bankAccountPermitImg
|
||
organizationCodeImg
|
||
taxRegistrationCertificateImg
|
||
taxpayerQualificationImg
|
||
*/
|
||
// 启用上传图片[extras表]
|
||
WSTUseImages(1, $Id, $data['legalCertificateImg'], 'shop_extras', 'legalCertificateImg');
|
||
WSTUseImages(1, $Id, $data['businessLicenceImg'], 'shop_extras', 'businessLicenceImg');
|
||
WSTUseImages(1, $Id, $data['bankAccountPermitImg'], 'shop_extras', 'bankAccountPermitImg');
|
||
//WSTUseImages(1, $Id, $data['organizationCodeImg'], 'shop_extras', 'organizationCodeImg');
|
||
//WSTUseImages(1, $Id, $data['taxRegistrationCertificateImg'], 'shop_extras', 'taxRegistrationCertificateImg');
|
||
//WSTUseImages(1, $Id, $data['taxpayerQualificationImg'], 'shop_extras', 'taxpayerQualificationImg');
|
||
$seModel->allowField(true)->save($data,['shopId'=>$shopId]);
|
||
|
||
|
||
//经营范围
|
||
Db::name('cat_shops')->where('shopId','=',$shopId)->delete();
|
||
$goodsCats = explode(',',$goodsCatIds);
|
||
foreach ($goodsCats as $key =>$v){
|
||
if((int)$v>0){
|
||
Db::name('cat_shops')->insert(['shopId'=>$shopId,'catId'=>$v]);
|
||
}
|
||
}
|
||
//认证类型
|
||
Db::name('shop_accreds')->where('shopId','=',$shopId)->delete();
|
||
if($accredIds!=''){
|
||
$accreds = explode(',',$accredIds);
|
||
foreach ($accreds as $key =>$v){
|
||
if((int)$v>0){
|
||
Db::name('shop_accreds')->insert(['shopId'=>$shopId,'accredId'=>$v]);
|
||
}
|
||
}
|
||
}
|
||
if($data['applyStatus']==2){
|
||
//建立店铺配置信息
|
||
$sc = [];
|
||
$sc['shopId'] = $shopId;
|
||
Db::name('ShopConfigs')->insert($sc);
|
||
$su = [];
|
||
$su["shopId"] = $shopId;
|
||
$su["userId"] = $shops->userId;
|
||
$su["roleId"] = 0;
|
||
Db::name('shop_users')->insert($su);
|
||
//建立店铺评分记录
|
||
$ss = [];
|
||
$ss['shopId'] = $shopId;
|
||
Db::name('shop_scores')->insert($ss);
|
||
//店铺申请通过添加质保金
|
||
$deposit = [];
|
||
$deposit['shopId'] = $shopId;
|
||
$deposit['cashDeposit'] = $cashDeposit;
|
||
$deposit['passTime'] = time();
|
||
$deposit['payDeposit'] = $payDeposit['payDeposit'];
|
||
$deposit['isFinish'] = $isFinish;
|
||
$deposit['completeTime'] = $completeTime;
|
||
// dump($deposit);die;
|
||
Db::name('shops_deposit')->insert($deposit);
|
||
//加入商家质保金缴纳记录表
|
||
$detail = [];
|
||
$detail['shopId'] = $shopId;
|
||
$detail['cashDeposit'] = $cashDeposit;
|
||
$detail['payType'] = 1;
|
||
$detail['payTime'] = time();
|
||
Db::name('shops_deposit_detail')->insert($detail);
|
||
//店铺申请成功之后钩子 mark 20180530 by zll
|
||
hook('afterShopHandleApply',['userId'=>$shops->userId]);
|
||
}
|
||
if($shops->applyStatus!=$data['applyStatus'])$this->sendMessages($shopId,$shops->userId,$data,'handleApply');
|
||
Db::commit();
|
||
// //店铺申请成功之后钩子 mark 20180530 by zll
|
||
// hook('afterShopHandleApply',['userId'=>$shops->userId,'applyStatus'=>$data['applyStatus']]);
|
||
return WSTReturn("操作成功", 1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
//return WSTReturn($e->getMessage());
|
||
return WSTReturn('操作失败',-1);
|
||
//echo $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发送信息
|
||
*/
|
||
public function sendMessages($shopId,$userId,$data,$method){
|
||
$user = model('users')->get($userId);
|
||
$shops = model('shops')->get($shopId);
|
||
if((int)$data['applyStatus']==2){
|
||
//如果存在手机则发送手机号码提示
|
||
$tpl = WSTMsgTemplates('PHONE_USER_SHOP_OPEN_SUCCESS');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1' && $data['applyLinkTel']!=''){
|
||
$params = ['tpl'=>$tpl,'params'=>['MALL_NAME'=>WSTConf("CONF.mallName"),'LOGIN_NAME'=>$user->loginName]];
|
||
$rv = model('admin/LogSms')->sendSMS(0,$userId,$data['applyLinkTel'],$params,$method);
|
||
}
|
||
//发送邮件
|
||
/*
|
||
$tpl = WSTMsgTemplates('EMAIL_USER_SHOP_OPEN_SUCCESS');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1' && $data['applyLinkEmail']){
|
||
$find = ['${LOGIN_NAME}','${MALL_NAME}'];
|
||
$replace = [$user->loginName,WSTConf("CONF.mallName")];
|
||
$sendRs = WSTSendMail($data['applyLinkEmail'],'申请入驻审核通过',str_replace($find,$replace,$tpl['content']));
|
||
}
|
||
关闭发送邮件 20180203 make cheng */
|
||
// 会员发送一条商城消息
|
||
$tpl = WSTMsgTemplates('SHOP_OPEN_SUCCESS');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||
$find = ['${LOGIN_NAME}','${MALL_NAME}'];
|
||
$replace = [$user->loginName,WSTConf("CONF.mallName")];
|
||
WSTSendMsg($userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>0,'dataId'=>$shopId]);
|
||
}
|
||
//微信消息
|
||
if((int)WSTConf('CONF.wxenabled')==1){
|
||
$params = [];
|
||
$params['SHOP_NAME'] = $shops['shopName'];
|
||
$params['APPLY_TIME'] = $shops['applyTime'];
|
||
$params['NOW_TIME'] = date('Y-m-d H:i:s');
|
||
$params['REASON'] = "申请入驻成功";
|
||
WSTWxMessage(['CODE'=>'WX_SHOP_OPEN_SUCCESS','userId'=>$userId,'params'=>$params]);
|
||
}
|
||
}else{
|
||
//如果存在手机则发送手机号码提示
|
||
$tpl = WSTMsgTemplates('PHONE_SHOP_OPEN_FAIL');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1' && $data['applyLinkTel']!=''){
|
||
$params = ['tpl'=>$tpl,'params'=>['MALL_NAME'=>WSTConf("CONF.mallName"),'REASON'=>$data['applyDesc']]];
|
||
$rv = model('admin/LogSms')->sendSMS(0,$userId,$data['applyLinkTel'],$params,$method);
|
||
}
|
||
//发送邮件
|
||
// $tpl = WSTMsgTemplates('EMAIL_SHOP_OPEN_FAIL');
|
||
// if( $tpl['tplContent']!='' && $tpl['status']=='1' && $data['applyLinkEmail']){
|
||
// $find = ['${LOGIN_NAME}','${MALL_NAME}','${REASON}'];
|
||
// $replace = [$user->loginName,WSTConf("CONF.mallName"),$data['applyDesc']];
|
||
// $sendRs = WSTSendMail($data['applyLinkEmail'],'申请入驻失败',str_replace($find,$replace,$tpl['content']));
|
||
// }
|
||
// 会员发送一条商城消息
|
||
$tpl = WSTMsgTemplates('SHOP_OPEN_FAIL');
|
||
if( $tpl['tplContent']!='' && $tpl['status']=='1'){
|
||
$find = ['${LOGIN_NAME}','${MALL_NAME}','${REASON}'];
|
||
$replace = [$user->loginName,WSTConf("CONF.mallName"),$data['applyDesc']];
|
||
WSTSendMsg($userId,str_replace($find,$replace,$tpl['tplContent']),['from'=>0,'dataId'=>$shopId]);
|
||
}
|
||
//微信消息
|
||
if((int)WSTConf('CONF.wxenabled')==1){
|
||
$params = [];
|
||
$params['SHOP_NAME'] = $shops['shopName'];
|
||
$params['APPLY_TIME'] = $shops['applyTime'];
|
||
$params['NOW_TIME'] = date('Y-m-d H:i:s');
|
||
$params['REASON'] = $data['applyDesc'];
|
||
WSTWxMessage(['CODE'=>'WX_SHOP_OPEN_FAIL','userId'=>$userId,'params'=>$params]);
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 删除申请
|
||
*/
|
||
public function delApply(){
|
||
$id = input('post.id/d');
|
||
$shop = $this->get($id);
|
||
if($shop->applyStatus==2)return WSTReturn('通过申请的店铺不允许删除');
|
||
Db::startTrans();
|
||
try{
|
||
//删除店铺信息
|
||
Db::name('cat_shops')->where(['shopId'=>$id])->delete();
|
||
Db::name('shop_extras')->where(['shopId'=>$id])->delete();
|
||
Db::name('shops')->where(['shopId'=>$id])->delete();
|
||
WSTUnuseImage('shops','shopImg',$id);
|
||
Db::commit();
|
||
return WSTReturn("删除成功", 1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
}
|
||
return WSTReturn('删除失败',-1);
|
||
}
|
||
/**
|
||
* 新增
|
||
*/
|
||
public function add(){
|
||
$validate = Loader::validate('Shops');
|
||
if(!$validate->check(Input('post.')))return WSTReturn($validate->getError());
|
||
//判断经营范围
|
||
$goodsCatIds = Input('post.goodsCatIds');
|
||
$accredIds = Input('post.accredIds');
|
||
if($goodsCatIds=='')return WSTReturn('请选择经营范围');
|
||
Db::startTrans();
|
||
try{
|
||
$userId = 0;
|
||
$isNewUser = (int)input('post.isNew/d');
|
||
if($isNewUser==1){
|
||
//创建用户账号
|
||
$user = [];
|
||
$user['loginName'] = input('post.loginName');
|
||
$user['loginPwd'] = input('post.loginPwd');
|
||
$ck = WSTCheckLoginKey($user['loginName']);
|
||
if($ck['status']!=1)return $ck;
|
||
if($user['loginPwd']=='')$user['loginPwd'] = '88888888';
|
||
$loginPwd = $user['loginPwd'];
|
||
$user["loginSecret"] = rand(1000,9999);
|
||
$user['loginPwd'] = md5($user['loginPwd'].$user['loginSecret']);
|
||
$user["userType"] = 1;
|
||
$user['createTime'] = date('Y-m-d H:i:s');
|
||
model('users')->save($user);
|
||
$userId = model('users')->userId;
|
||
}else{
|
||
$userId = (int)input('post.shopUserId/d');
|
||
//检查用户是否可用
|
||
$shopUser = model('users')->where(['userId'=>$userId,'dataFlag'=>1])->find();
|
||
if(empty($shopUser))return WSTReturn('无效的账号信息');
|
||
$tmpShop = $this->where(['dataFlag'=>1,'userId'=>$userId])->find();
|
||
if(!empty($tmpShop))return WSTReturn('所关联账号已有店铺信息');
|
||
$shopUser->userType = 1;
|
||
$shopUser->save();
|
||
}
|
||
if($userId>0){
|
||
//创建商家基础信息
|
||
$data = input('post.');
|
||
$data['createTime'] = date('Y-m-d H:i:s');
|
||
$areaIds = model('Areas')->getParentIs($data['areaId']);
|
||
if(!empty($areaIds))$data['areaIdPath'] = implode('_',$areaIds)."_";
|
||
$areaIds = model('Areas')->getParentIs($data['bankAreaId']);
|
||
if(!empty($areaIds))$data['bankAreaIdPath'] = implode('_',$areaIds)."_";
|
||
WSTUnset($data,'id,shopId,dataFlag,isSelf');
|
||
if($data['shopSn']=='')$data['shopSn'] = $this->getShopSn('S');
|
||
$data['userId'] = $userId;
|
||
$data['applyStatus'] = 2;
|
||
$this->allowField(true)->save($data);
|
||
$shopId = $this->shopId;
|
||
//启用上传图片
|
||
WSTUseImages(1, $shopId, $data['shopImg']);
|
||
//保存店铺其他信息
|
||
$areaIds = model('Areas')->getParentIs($data['businessAreaPath0']);
|
||
if(!empty($areaIds))$data['businessAreaPath'] = implode('_',$areaIds)."_";
|
||
//if($data['establishmentDate']=='')unset($data['establishmentDate']);
|
||
//if($data['businessEndDate']=='')unset($data['businessEndDate']);
|
||
//if($data['businessStartDate']=='')unset($data['businessStartDate']);
|
||
//if($data['legalCertificateStartDate']=='')unset($data['legalCertificateStartDate']);
|
||
//if($data['legalCertificateEndDate']=='')unset($data['legalCertificateEndDate']);
|
||
//if($data['organizationCodeStartDate']=='')unset($data['organizationCodeStartDate']);
|
||
// if($data['organizationCodeEndDate']=='')unset($data['organizationCodeEndDate']);
|
||
//$data['registeredCapital'] = (float)$data['registeredCapital'];
|
||
$data['shopId'] = $shopId;
|
||
|
||
$seModel = model('ShopExtras');
|
||
$seModel->allowField(true)->save($data);
|
||
$Id = $seModel->where(['shopId'=>$shopId])->value('id');
|
||
// 判断是否有上传图片资料,启用上传图片[extras表]
|
||
WSTUseImages(1, $Id, $data['legalCertificateImg'], 'shop_extras');
|
||
WSTUseImages(1, $Id, $data['businessLicenceImg'], 'shop_extras');
|
||
WSTUseImages(1, $Id, $data['bankAccountPermitImg'], 'shop_extras');
|
||
//WSTUseImages(1, $Id, $data['organizationCodeImg'], 'shop_extras');
|
||
// WSTUseImages(1, $Id, $data['taxRegistrationCertificateImg'], 'shop_extras');
|
||
// WSTUseImages(1, $Id, $data['taxpayerQualificationImg'], 'shop_extras');
|
||
//建立店铺配置信息
|
||
$sc = [];
|
||
$sc['shopId'] = $shopId;
|
||
Db::name('ShopConfigs')->insert($sc);
|
||
$su = [];
|
||
$su["shopId"] = $shopId;
|
||
$su["userId"] = $userId;
|
||
$su["roleId"] = 0;
|
||
Db::name('shop_users')->insert($su);
|
||
//建立店铺评分记录
|
||
$ss = [];
|
||
$ss['shopId'] = $shopId;
|
||
Db::name('shop_scores')->insert($ss);
|
||
//经营范围
|
||
$goodsCats = explode(',',$goodsCatIds);
|
||
foreach ($goodsCats as $v){
|
||
if((int)$v>0)Db::name('cat_shops')->insert(['shopId'=>$shopId,'catId'=>$v]);
|
||
}
|
||
//认证类型
|
||
if($accredIds!=''){
|
||
$accreds = explode(',',$accredIds);
|
||
foreach ($accreds as $v){
|
||
if((int)$v>0)Db::name('shop_accreds')->insert(['shopId'=>$shopId,'accredId'=>$v]);
|
||
}
|
||
}
|
||
$data['applyStatus'] = 2;
|
||
$data['applyDesc'] = '';
|
||
$this->sendMessages($shopId,$userId,$data,'add');
|
||
}
|
||
Db::commit();
|
||
return WSTReturn("新增成功", 1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('新增失败',-1);
|
||
}
|
||
}
|
||
/**
|
||
* 编辑
|
||
*/
|
||
public function edit(){
|
||
$shopId = input('post.shopId/d',0);
|
||
$shops = $this->get($shopId);
|
||
$shopAds=input('shopAds');
|
||
$auxiliary=explode(',',$shopAds);
|
||
if(empty($shops) || $shops->dataFlag!=1)return WSTReturn('店铺不存在');
|
||
$validate = Loader::validate('Shops');
|
||
if(!$validate->check(Input('post.')))return WSTReturn($validate->getError());
|
||
//判断经营范围
|
||
$goodsCatIds = input('post.goodsCatIds');
|
||
$accredIds = input('post.accredIds');
|
||
if($goodsCatIds=='')return WSTReturn('请选择经营范围');
|
||
Db::startTrans();
|
||
try{
|
||
$data = input('post.');
|
||
$auxiliary_data=[];
|
||
$shopAuxiliary = Db::name('shop_auxiliary')->where('shopId='.$shopId)->find();
|
||
WSTUseImages(0, $shopAuxiliary['id'], $auxiliary,'shopauxiliary');
|
||
Db::name('shop_auxiliary')->where('shopId='.$shopId)->delete();
|
||
foreach($auxiliary as $k=>$v){
|
||
$auxiliary_data[$k]['shopId']=$shopId;
|
||
$auxiliary_data[$k]['auxiliaryImg']=$v;
|
||
}
|
||
Db::name('shop_auxiliary')->insertAll($auxiliary_data);
|
||
//保存店铺基础信息
|
||
$areaIds = model('Areas')->getParentIs($data['areaId']);
|
||
if(!empty($areaIds))$data['areaIdPath'] = implode('_',$areaIds)."_";
|
||
$areaIds = model('Areas')->getParentIs($data['bankAreaId']);
|
||
if(!empty($areaIds))$data['bankAreaIdPath'] = implode('_',$areaIds)."_";
|
||
WSTUnset($data,'id,shopId,userId,dataFlag,goodsCatIds,accredIds,isSelf,applyStatus,applyDesc');
|
||
//启用上传图片
|
||
WSTUseImages(1, $shopId, $data['shopImg'],'shops','shopImg');
|
||
$this->allowField(true)->save($data,['shopId'=>$shopId,'dataFlag'=>1]);
|
||
//保存店铺其他信息
|
||
$areaIds = model('Areas')->getParentIs($data['businessAreaPath0']);
|
||
if(!empty($areaIds))$data['businessAreaPath'] = implode('_',$areaIds)."_";
|
||
//if($data['establishmentDate']=='')unset($data['establishmentDate']);
|
||
//if($data['businessEndDate']=='')unset($data['businessEndDate']);
|
||
//if($data['businessStartDate']=='')unset($data['businessStartDate']);
|
||
//if($data['legalCertificateStartDate']=='')unset($data['legalCertificateStartDate']);
|
||
//if($data['legalCertificateEndDate']=='')unset($data['legalCertificateEndDate']);
|
||
//if($data['organizationCodeStartDate']=='')unset($data['organizationCodeStartDate']);
|
||
//if($data['organizationCodeEndDate']=='')unset($data['organizationCodeEndDate']);
|
||
//$data['registeredCapital'] = (float)$data['registeredCapital'];
|
||
$seModel = model('ShopExtras');
|
||
$Id = $seModel->where(['shopId'=>$shopId])->value('id');
|
||
// 启用上传图片[extras表]
|
||
WSTUseImages(1, $Id, $data['legalCertificateImg'], 'shop_extras','legalCertificateImg');
|
||
WSTUseImages(1, $Id, $data['businessLicenceImg'], 'shop_extras','businessLicenceImg');
|
||
WSTUseImages(1, $Id, $data['bankAccountPermitImg'], 'shop_extras','bankAccountPermitImg');
|
||
//WSTUseImages(1, $Id, $data['organizationCodeImg'], 'shop_extras','organizationCodeImg');
|
||
//WSTUseImages(1, $Id, $data['taxRegistrationCertificateImg'], 'shop_extras','taxRegistrationCertificateImg');
|
||
// WSTUseImages(1, $Id, $data['taxpayerQualificationImg'], 'shop_extras','taxpayerQualificationImg');
|
||
|
||
|
||
|
||
$seModel->allowField(true)->save($data,['shopId'=>$shopId]);
|
||
|
||
|
||
|
||
|
||
//经营范围
|
||
Db::name('cat_shops')->where('shopId','=',$shopId)->delete();
|
||
$goodsCats = explode(',',$goodsCatIds);
|
||
foreach ($goodsCats as $key =>$v){
|
||
if((int)$v>0){
|
||
Db::name('cat_shops')->insert(['shopId'=>$shopId,'catId'=>$v]);
|
||
}
|
||
}
|
||
//认证类型
|
||
Db::name('shop_accreds')->where('shopId','=',$shopId)->delete();
|
||
if($accredIds!=''){
|
||
$accreds = explode(',',$accredIds);
|
||
foreach ($accreds as $key =>$v){
|
||
if((int)$v>0){
|
||
Db::name('shop_accreds')->insert(['shopId'=>$shopId,'accredId'=>$v]);
|
||
}
|
||
}
|
||
}
|
||
if((int)input('shopStatus')!=1){
|
||
//店铺状态不正常就停用所有的商品
|
||
model('goods')->unsaleByshopId($shopId);
|
||
}
|
||
//删除店铺钩子事件
|
||
hook('afterChangeShopStatus',['shopId'=>$shopId]);
|
||
Db::commit();
|
||
return WSTReturn("编辑成功", 1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('编辑失败',-1);
|
||
}
|
||
}
|
||
/**
|
||
* 获取所有店铺id
|
||
*/
|
||
public function getAllShopId(){
|
||
return $this->where(['dataFlag'=>1,'shopStatus'=>1])->column('shopId');
|
||
}
|
||
|
||
/**
|
||
* 根据店铺ID获取店铺名称
|
||
*/
|
||
public function upShopName(){
|
||
$shopId = input('shopId/d');
|
||
// $shopId = 1;
|
||
$res = Db::name('shops')->where('shopId',$shopId)->field('shopId,shopName')->find();
|
||
// dump($res);die;
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 搜索经验范围的店铺
|
||
*/
|
||
public function searchQuery(){
|
||
$goodsCatatId = (int)input('post.goodsCatId');
|
||
if($goodsCatatId<=0)return [];
|
||
$key = input('post.key');
|
||
$where = [];
|
||
$where['dataFlag'] = 1;
|
||
$where['shopStatus'] = 1;
|
||
$where['catId'] = $goodsCatatId;
|
||
if($key!='')$where['shopName|shopSn'] = ['like','%'.$key.'%'];
|
||
return $this->alias('s')->join('__CAT_SHOPS__ cs','s.shopId=cs.shopId','inner')
|
||
->where($where)->field('shopName,s.shopId,shopSn')->select();
|
||
}
|
||
|
||
/**
|
||
* 自营自动登录
|
||
*/
|
||
public function selfLogin($id){
|
||
$shopId = $id;
|
||
$userid = $this->where(["dataFlag"=>1, "status"=>1,"shopId"=>$shopId])->field('userId')->find();
|
||
if(!empty($userid['userId'])){
|
||
$userId = $userid['userId'];
|
||
//获取用户信息
|
||
$u = new Users();
|
||
$rs = $u->getById($userId);
|
||
//获取用户等级
|
||
$rrs = WSTUserRank($rs['userTotalScore']);
|
||
$rs['rankId'] = $rrs['rankId'];
|
||
$rs['rankName'] = $rrs['rankName'];
|
||
$rs['userrankImg'] = $rrs['userrankImg'];
|
||
$ip = request()->ip();
|
||
$u->where(["userId"=>$userId])->update(["lastTime"=>date('Y-m-d H:i:s'),"lastIP"=>$ip]);
|
||
//加载店铺信息
|
||
$shops= new Shops();
|
||
$shop = $shops->where(["userId"=>$userId,"dataFlag" =>1])->find();
|
||
if(!empty($shop))$rs = array_merge($shop->toArray(),$rs->toArray());
|
||
//记录登录日志
|
||
$data = array();
|
||
$data["userId"] = $userId;
|
||
$data["loginTime"] = date('Y-m-d H:i:s');
|
||
$data["loginIp"] = $ip;
|
||
Db::name('log_user_logins')->insert($data);
|
||
if($rs['userPhoto']=='')$rs['userPhoto'] = WSTConf('CONF.userLogo');
|
||
session('WST_USER',$rs);
|
||
return WSTReturn("","1");
|
||
}
|
||
return WSTReturn("",-1);
|
||
}
|
||
|
||
/**
|
||
* 查询店铺佣金扣点
|
||
*/
|
||
public function commission($shopId){
|
||
$obj = Db::name('shops')->alias('s')
|
||
->join('__SHOP_COMMISSION__ sc','sc.shopId=s.shopId','left')->where('s.shopId',$shopId)->field('s.shopId,sc.commission,sc.userId,sc.userName,sc.usersPhone,sc.deductMoney')->find();
|
||
// dump($obj);die;
|
||
return $obj;
|
||
}
|
||
/**
|
||
* 设置店铺佣金扣点
|
||
*/
|
||
public function upCommission(){
|
||
$data['shopId'] = input('shopId/d');
|
||
$data['commission'] = input('commission');
|
||
$data['userName'] = input('userName');
|
||
//$data['userId'] = input('userId/d');
|
||
$data['usersPhone'] = input('usersPhone');
|
||
$user = Db::name('users')->where(['loginName|userPhone'=>$data['usersPhone']])->field('userId')->find();
|
||
if(!$user){
|
||
return WSTReturn('该职员不存在',-1);die;
|
||
}
|
||
$data['userId'] = $user['userId'];
|
||
$com = Db::name('shop_commission')->where('shopId',$data['shopId'])->find();
|
||
if($com){
|
||
$result = Db::name('shop_commission')->where('shopId',$data['shopId'])->update(['commission'=>$data['commission'],'usersPhone'=>$data['usersPhone'],'userName'=>$data['userName'],'userId'=>$data['userId']]);
|
||
}else{
|
||
$result = Db::name('shop_commission')->insert($data);
|
||
}
|
||
if($result){
|
||
return WSTReturn("操作成功",1);
|
||
}else{
|
||
return WSTReturn("操作失败",-1);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询业务员信息
|
||
*/
|
||
public function staffs(){
|
||
$userName = input('userName');
|
||
$data = Db::name('users')->where(['loginName'=>$userName,'userStatus'=>1,'dataFlag'=>1])->field('userPhone,userId')->find();
|
||
if($data){
|
||
return $data;
|
||
}else{
|
||
return WSTReturn('该职员不存在',-1);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 导出订单
|
||
*/
|
||
public function toExport($shopStatus=1){
|
||
$name="店铺列表";
|
||
$areaIdPath = input('areaIdPath');
|
||
$shopName = input('shopName');
|
||
$telephone = input('userPhone');
|
||
$catId =(int)input('cat');
|
||
$isInvestment = (int)input('isInvestment/d',-1);
|
||
$where = [];
|
||
$where['s.dataFlag'] = 1;
|
||
$where['s.applyStatus'] = 2;
|
||
$where['s.shopStatus'] = $shopStatus;
|
||
if($catId!="0"){
|
||
$where['c.catId'] = $catId;
|
||
}
|
||
if(in_array($isInvestment,[0,1]))$where['ss.isInvestment'] = $isInvestment;
|
||
if($shopName!='')$where['shopName'] = ['like','%'.$shopName.'%'];
|
||
if($telephone!='')$where['telephone'] = ['like','%'.$telephone.'%'];
|
||
if($areaIdPath !='')$where['areaIdPath'] = ['like',$areaIdPath."%"];
|
||
if($catId !='')$where['catId'] = ['like',$catId."%"];
|
||
$sort = input('sort');
|
||
$order = [];
|
||
if($sort!=''){
|
||
$sortArr = explode('.',$sort);
|
||
$order = $sortArr[0].' '.$sortArr[1];
|
||
}
|
||
$list=Db::table('__SHOPS__')->alias('s')
|
||
->join('__AREAS__ a2','s.areaId=a2.areaId','left')
|
||
->join('__USERS__ u','u.userId=s.userId','left')
|
||
->join('__SHOP_EXTRAS__ ss','s.shopId=ss.shopId','left')
|
||
->join('__CAT_SHOPS__ c','c.shopId=s.shopId','left')
|
||
->join('__SHOP_PAY__ sp','sp.shopId=s.shopId','left')
|
||
->where($where)
|
||
->field('u.loginName,s.shopId,shopSn,shopName,a2.areaName,shopkeeper,telephone,shopAddress,shopCompany,shopAtive,shopStatus,s.applyTime,s.createTime,sp.status')
|
||
->order('createTime desc')->group('s.shopId')
|
||
->select();
|
||
foreach ($list as &$value) {
|
||
$catName=db('cat_shops')->alias('a')->join('goods_cats g','g.catId=a.catId')
|
||
->where('shopId',$value['shopId'])->field('catName')->select();
|
||
$value['catName']="";
|
||
if(count($catName)>1){
|
||
foreach ($catName as &$v) {
|
||
$value['catName']=$value['catName'].$v['catName'].',';
|
||
}
|
||
}
|
||
$goodsNum=db('goods')->alias('g')->where(['shopId'=>$value['shopId'],'isSale'=>1,'dataFlag'=>1])->field('count(goodsId)goodsNum')->select();
|
||
$value['goodsNum']="";
|
||
foreach ($goodsNum as &$v) {
|
||
$value['goodsNum']=$value['goodsNum'].$v['goodsNum'];
|
||
}
|
||
}
|
||
//dump($list);die;
|
||
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(12);
|
||
$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(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->getFill()->getStartColor()->setARGB('333399');
|
||
|
||
$objPHPExcel->getActiveSheet()
|
||
->setCellValue('A1', '用户名称')
|
||
->setCellValue('B1', '店铺ID')
|
||
->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', '经营类目');
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->applyFromArray($styleArray);
|
||
for ($row = 0; $row < count($list); $row++){
|
||
$i = $row+2;
|
||
$objPHPExcel->getActiveSheet()
|
||
->setCellValue('A'.$i, $list[$row]['loginName'])
|
||
->setCellValue('B'.$i, $list[$row]['shopId'])
|
||
->setCellValue('C'.$i, $list[$row]['shopSn'])
|
||
->setCellValue('D'.$i, $list[$row]['shopName'])
|
||
->setCellValue('E'.$i, $list[$row]['areaName'])
|
||
->setCellValue('F'.$i, $list[$row]['shopkeeper'])
|
||
->setCellValue('G'.$i, $list[$row]['telephone'])
|
||
->setCellValue('H'.$i, $list[$row]['shopAddress'])
|
||
->setCellValue('I'.$i, $list[$row]['shopCompany'])
|
||
->setCellValue('J'.$i, $list[$row]['shopAtive'])
|
||
->setCellValue('K'.$i, $list[$row]['shopStatus'])
|
||
->setCellValue('L'.$i, $list[$row]['goodsNum'])
|
||
->setCellValue('M'.$i, $list[$row]['applyTime'])
|
||
->setCellValue('N'.$i, $list[$row]['createTime'])
|
||
->setCellValue('O'.$i, $list[$row]['catName']);
|
||
}
|
||
//输出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 detailByPage(){
|
||
$where='s.shopStatus=1 AND s.dataFlag=1';
|
||
$start=input('startDate');
|
||
$end=input('endDate');
|
||
$nonTime=input('nonTime');
|
||
if($nonTime){
|
||
$nonlogTime=date('Y-m-d H:i:s',strtotime('-'.$nonTime.'day'));
|
||
$where.=' AND l.nonlogTime<"'.$nonlogTime.'"';
|
||
}
|
||
//dump($nonlogTime);
|
||
// 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 lo.loginTime BETWEEN "'.$start.'" AND "'.$end.'"';
|
||
// }else if($start!=''){
|
||
// $start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||
// $where.= ' AND lo.loginTime>="'.$start.'"';
|
||
// }else if($end!=''){
|
||
// $end = date('Y-m-d 00:00:00',strtotime(input('endDate')));
|
||
// $where.= ' AND lo.loginTime<="'.$end.'"';
|
||
// }
|
||
// $result=Db::query('SELECT
|
||
// s.userId,s.shopName,l.loginNum,b.goodsNum
|
||
// FROM
|
||
// '.config('database.prefix').'shops s
|
||
// LEFT JOIN
|
||
// (SELECT COUNT(*) loginNum,userId FROM '.config('database.prefix').'log_user_logins a GROUP BY a.userId) l on l.userId=s.userId
|
||
// LEFT JOIN
|
||
// (SELECT COUNT(*) goodsNum,shopId FROM '.config('database.prefix').'goods g GROUP BY g.shopId) b on b.shopId=s.shopId
|
||
|
||
// ');
|
||
$result=Db::table('__SHOPS__')->alias('s')
|
||
//->join('__LOG_USER_LOGINS__ a','s.userId=a.userId','left')
|
||
->join('(SELECT COUNT(*) loginNum,userId,loginTime,MAX(loginTime) nonlogTime FROM __LOG_USER_LOGINS__ a GROUP BY a.userId) l','s.userId=l.userId','left')
|
||
->join('(SELECT COUNT(*) goodsNum,shopId,isSale FROM __GOODS__ g WHERE g.isSale=1 GROUP BY g.shopId) go','s.shopId=go.shopId','left')
|
||
->join('__LOG_USER_LOGINS__ lo','s.userId=lo.userId','left')
|
||
// ->join('(SELECT COUNT(*) orderNum,shopId,orderStatus FROM __ORDERS__ o GROUP BY o.shopId) oo','s.shopId=oo.shopId','left')
|
||
// ->join('(SELECT COUNT(*) orderNums,shopId,orderStatus FROM __ORDERS__ o2 GROUP BY o2.orderStatus) od','s.shopId=od.shopId','left')
|
||
//->whereTime('l.loginTime','between',[$start,$end])
|
||
->where($where)
|
||
->field('s.shopName,l.loginNum,go.goodsNum,s.shopId,s.shopCompany,shopkeeper,telephone,applyTime,nonlogTime')
|
||
->order('l.loginNum desc')
|
||
->group('s.shopId')
|
||
->paginate(input('limit/d'))->toArray();
|
||
//dump(db::getlastsql());
|
||
//dump($result);
|
||
foreach ($result['Rows'] as &$value) {
|
||
if($end=='')$end = date('Y-m-d 23:59:59',strtotime("now"));
|
||
if($start=='')$start = date('Y-m-d 23:59:59',strtotime("0"));
|
||
$value['nonTime']=sprintf("%.0f",(strtotime(date('Y-m-d H:i:s'))-strtotime($value['nonlogTime']))/86400);
|
||
$value['successOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>2,'dataFlag'=>1])->count('shopId');
|
||
$value['cancelOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>-1,'dataFlag'=>1])->count('shopId');
|
||
$value['nonpayOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>-2,'dataFlag'=>1])->count('shopId');
|
||
$value['deliveredOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>1,'dataFlag'=>1])->count('shopId');
|
||
}
|
||
// $result=Db::table('__SHOPS__')->alias('s')
|
||
// ->join('__LOG_USER_LOGINS__ a','s.userId=a.userId','left')
|
||
// ->join('__GOODS__ go','s.shopId=go.shopId','left')
|
||
// ->where($where)
|
||
// ->field('a.userId,shopName,count(a.userId)logNum,count(go.shopId)goodsNum')
|
||
// ->order('logNum desc')->group('a.userId,go.shopId,s.shopId,s.userId,a.userId')
|
||
// ->paginate(input('limit/d'))->toArray();
|
||
|
||
return $result;
|
||
}
|
||
/**
|
||
* 导出商家登录活跃数据订单
|
||
*/
|
||
public function toExports(){
|
||
$name="商家活跃信息列表";
|
||
$start=input('startDate');
|
||
$end=input('endDate');
|
||
$nonTime=input('nonTime');
|
||
$where='s.shopStatus=1 AND s.dataFlag=1';
|
||
if($nonTime){
|
||
$nonlogTime=date('Y-m-d H:i:s',strtotime('-'.$nonTime.'day'));
|
||
$where.=' AND l.nonlogTime<"'.$nonlogTime.'"';
|
||
}
|
||
// 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 lo.loginTime BETWEEN "'.$start.'" AND "'.$end.'"';
|
||
// }else if($start!=''){
|
||
// $start = date('Y-m-d 00:00:00',strtotime(input('startDate')));
|
||
// $where.= ' AND lo.loginTime>="'.$start.'"';
|
||
// }else if($end!=''){
|
||
// $end = date('Y-m-d 00:00:00',strtotime(input('endDate')));
|
||
// $where.= ' AND lo.loginTime<="'.$end.'"';
|
||
// }
|
||
$list=Db::query('SELECT
|
||
s.shopId,s.shopName,l.loginNum,b.goodsNum,l.nonlogTime,s.shopCompany,s.applyTime,s.shopkeeper,s.telephone
|
||
FROM
|
||
'.config('database.prefix').'shops s
|
||
LEFT JOIN
|
||
(SELECT COUNT(*) loginNum,userId,MAX(loginTime) nonlogTime FROM '.config('database.prefix').'log_user_logins a GROUP BY a.userId) l on l.userId=s.userId
|
||
LEFT JOIN
|
||
(SELECT COUNT(*) goodsNum,shopId FROM '.config('database.prefix').'goods g WHERE g.isSale=1 GROUP BY g.shopId) b on b.shopId=s.shopId
|
||
LEFT JOIN
|
||
(SELECT userId,loginTime FROM '.config('database.prefix').'log_user_logins)lo on lo.userId=s.userId
|
||
WHERE '.$where.'
|
||
GROUP BY s.shopId
|
||
ORDER BY l.loginNum DESC');
|
||
foreach ($list as &$value) {
|
||
if($end=='')$end = date('Y-m-d 23:59:59',strtotime("now"));
|
||
if($start=='')$start = date('Y-m-d 23:59:59',strtotime("0"));
|
||
$value['nonTime']=sprintf("%.0f",(strtotime(date('Y-m-d H:i:s'))-strtotime($value['nonlogTime']))/86400);
|
||
$value['successOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>2,'dataFlag'=>1])->count('shopId');
|
||
$value['cancelOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>-1,'dataFlag'=>1])->count('shopId');
|
||
$value['nonpayOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>-2,'dataFlag'=>1])->count('shopId');
|
||
$value['deliveredOrder']=db('orders')->whereTime('createTime','between',[$start,$end])
|
||
->where(['shopId'=>$value['shopId'],'orderStatus'=>1,'dataFlag'=>1])->count('shopId');
|
||
}
|
||
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(20);
|
||
$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()->getColumnDimension('L')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->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', '已发货订单');
|
||
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:S1')->applyFromArray($styleArray);
|
||
for ($row = 0; $row < count($list); $row++){
|
||
$i = $row+2;
|
||
$objPHPExcel->getActiveSheet()
|
||
->setCellValue('A'.$i, $list[$row]['shopName'])
|
||
->setCellValue('B'.$i, $list[$row]['shopCompany'])
|
||
->setCellValue('C'.$i, $list[$row]['applyTime'])
|
||
->setCellValue('D'.$i, $list[$row]['shopkeeper'])
|
||
->setCellValue('E'.$i, $list[$row]['telephone'])
|
||
->setCellValue('F'.$i, $list[$row]['nonTime'])
|
||
->setCellValue('G'.$i, $list[$row]['loginNum'])
|
||
->setCellValue('H'.$i, $list[$row]['goodsNum'])
|
||
->setCellValue('I'.$i, $list[$row]['successOrder'])
|
||
->setCellValue('J'.$i, $list[$row]['cancelOrder'])
|
||
->setCellValue('K'.$i, $list[$row]['nonpayOrder'])
|
||
->setCellValue('L'.$i, $list[$row]['deliveredOrder']);
|
||
}
|
||
//输出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');
|
||
}
|
||
|
||
} |