Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

View File

@ -0,0 +1,17 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Areas as M;
/**
* ============================================================================
* 地区控制器
*/
class Areas extends Base{
/**
* 列表查询
*/
public function listQuery(){
$m = new M();
$rs = $m->listQuery();
return WSTReturn('', 1,$rs);
}
}

View File

@ -0,0 +1,93 @@
<?php
namespace wstmart\wechat\controller;
use think\Controller;
/**
* ============================================================================
* 基础控制器
*/
class Base extends Controller {
public function __construct(){
parent::__construct();
WSTConf('CONF',WSTConfig());
$this->assign("v",WSTConf('CONF.wstVersion')."_".WSTConf('CONF.wstPcStyleId'));
if(WSTConf('CONF.wxenabled')==1){
if(!(request()->module()=="wechat" && request()->controller()=="Weixinpays" && request()->action()=="notify")){
WSTIsWeixin();//检测是否在微信浏览器上使用
}
$state = input('param.state');
if($state==WSTConf('CONF.wxAppCode')){
$type = input('param.type');
if($type=='1'){
WSTBindWeixin(1);
}else{
WSTBindWeixin(0);
}
}
}
if(WSTConf('CONF.seoMallSwitch')==0){
$this->redirect('wechat/switchs/index');
exit;
}
}
// 权限验证方法
protected function checkAuth(){
$state = input('param.state');
if($state==WSTConf('CONF.wxAppCode')){
WSTBindWeixin(1);
}
$request = request();
$USER = session('WST_USER');
if(empty($USER)){
if(request()->isAjax()){
die('{"status":-999,"msg":"还没关联帐号,正在关联帐号"}');
}else{
session('WST_WX_WlADDRESS',$request->url(true));
$url=urlencode($request->url(true));
$url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.WSTConf('CONF.wxAppId').'&redirect_uri='.$url.'&response_type=code&scope=snsapi_userinfo&state='.WSTConf('CONF.wxAppCode').'#wechat_redirect';
header("location:".$url);
exit;
}
}
}
// 店铺权限验证方法
protected function checkShopAuth($opt){
$shopMenus = WSTShopOrderMenus();
if($opt=="list"){
if(count($shopMenus)==0){
session('wxshoporder','对不起,您无权进行该操作');
$this->redirect('wechat/error/message',['code'=>'wxshoporder']);
exit;
}
}else{
if(!array_key_exists($opt,$shopMenus)){
if(request()->isAjax()){
die('{"status":-1,"msg":"您无权进行该操作"}');
}else{
session('wxshoporder','对不起,您无权进行该操作');
$this->redirect('wechat/error/message',['code'=>'wxshoporder']);
exit;
}
}
}
}
protected function fetch($template = '', $vars = [], $replace = [], $config = []){
$style = WSTConf('CONF.wstwechatStyle')?WSTConf('CONF.wstwechatStyle'):'default';
$replace['__WECHAT__'] = str_replace('/index.php','',\think\Request::instance()->root()).'/wstmart/wechat/view/'.$style;
return $this->view->fetch($style."/".$template, $vars, $replace, $config);
}
/**
* 上传图片
*/
public function uploadPic(){
return WSTUploadPic(0);
}
/**
* 获取验证码
*/
public function getVerify(){
WSTVerify();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Brands as M;
/**
* ============================================================================
* 品牌控制器
*/
class Brands extends Base{
/**
* 主页
*/
public function index(){
return $this->fetch('brands');
}
/**
* 列表
*/
public function pageQuery(){
$m = new M();
$rs = $m->pageQuery(input('pagesize/d'));
foreach ($rs['Rows'] as $key =>$v){
$rs['Rows'][$key]['brandImg'] = WSTImg($v['brandImg'],2);
}
return $rs;
}
}

View File

@ -0,0 +1,141 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Carts as M;
use wstmart\common\model\UserAddress;
use wstmart\common\model\Payments;
/**
* ============================================================================
* 购物车控制器
*/
class Carts extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/**
* 查看购物车列表
*/
public function index(){
$m = new M();
$carts = $m->getCarts(false);
$this->assign('carts',$carts);
return $this->fetch('carts');
}
/**
* 加入购物车
*/
public function addCart(){
$m = new M();
$rs = $m->addCart();
$rs['cartNum'] = WSTCartNum();
return $rs;
}
/**
* 修改购物车商品状态
*/
public function changeCartGoods(){
$m = new M();
$rs = $m->changeCartGoods();
return $rs;
}
/**
* 删除购物车里的商品
*/
public function delCart(){
$m = new M();
$rs= $m->delCart();
return $rs;
}
/**
* 计算运费、积分和总商品价格
*/
public function getCartMoney(){
$m = new M();
$data = $m->getCartMoney();
return $data;
}
/**
* 计算运费、积分和总商品价格/虚拟商品
*/
public function getQuickCartMoney(){
$m = new M();
$data = $m->getQuickCartMoney();
return $data;
}
/**
* 跳去购物车结算页面
*/
public function settlement(){
$m = new M();
//获取一个用户地址
$addressId = (int)input('addressId');
$ua = new UserAddress();
if($addressId>0){
$userAddress = $ua->getById($addressId);
}else{
$userAddress = $ua->getDefaultAddress();
}
$this->assign('userAddress',$userAddress);
//获取支付方式
$pa = new Payments();
$payments = $pa->getByGroup('3');
//获取已选的购物车商品
$carts = $m->getCarts(true);
hook("wechatControllerCartsSettlement",["carts"=>$carts,"payments"=>&$payments]);
$this->assign('payments',$payments);
//获取用户积分
$user = model('users')->getFieldsById((int)session('WST_USER.userId'),'userScore');
//计算可用积分和金额
$goodsTotalMoney = $carts['goodsTotalMoney'];
$goodsTotalScore = WSTScoreToMoney($goodsTotalMoney,true);
$useOrderScore =0;
$useOrderMoney = 0;
if($user['userScore']>$goodsTotalScore){
$useOrderScore = $goodsTotalScore;
$useOrderMoney = $goodsTotalMoney;
}else{
$useOrderScore = $user['userScore'];
$useOrderMoney = WSTScoreToMoney($useOrderScore);
}
$this->assign('userOrderScore',$useOrderScore);
$this->assign('userOrderMoney',$useOrderMoney);
$this->assign('carts',$carts);
return $this->fetch('settlement');
}
/**
* 跳去虚拟商品购物车结算页面
*/
public function quickSettlement(){
$m = new M();
//获取支付方式
$pa = new Payments();
$payments = $pa->getByGroup('3');
$this->assign('payments',$payments);
//获取用户积分
$user = model('users')->getFieldsById((int)session('WST_USER.userId'),'userScore');
//获取已选的购物车商品
$carts = $m->getQuickCarts();
//计算可用积分和金额
$goodsTotalMoney = $carts['goodsTotalMoney'];
$goodsTotalScore = WSTScoreToMoney($goodsTotalMoney,true);
$useOrderScore =0;
$useOrderMoney = 0;
if($user['userScore']>$goodsTotalScore){
$useOrderScore = $goodsTotalScore;
$useOrderMoney = $goodsTotalMoney;
}else{
$useOrderScore = $user['userScore'];
$useOrderMoney = WSTScoreToMoney($useOrderScore);
}
$this->assign('userOrderScore',$useOrderScore);
$this->assign('userOrderMoney',$useOrderMoney);
$this->assign('carts',$carts);
return $this->fetch('settlement_quick');
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace wstmart\wechat\controller;
/**
* ============================================================================
* 提现账号控制器
*/
class Cashconfigs extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth',
];
/**
* 查看提现账号
*/
public function index(){
$this->assign('area',model('areas')->listQuery(0));
$this->assign('banks',model('banks')->listQuery(0));
return $this->fetch('users/cashconfigs/list');
}
/**
* 获取用户数据
*/
public function pageQuery(){
$userId = (int)session('WST_USER.userId');
$data = model('CashConfigs')->pageQuery(0,$userId);
return WSTReturn("", 1,$data);
}
/**
* 获取记录
*/
public function getById(){
$id = (int)input('id');
return model('CashConfigs')->getById($id);
}
/**
* 新增
*/
public function add(){
return model('CashConfigs')->add();
}
/**
* 编辑
*/
public function edit(){
return model('CashConfigs')->edit();
}
/**
* 删除
*/
public function del(){
return model('CashConfigs')->del();
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace wstmart\wechat\controller;
/**
* ============================================================================
* 提现记录控制器
*/
class Cashdraws extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth',
];
/**
* 查看用户提现记录
*/
public function index(){
return $this->fetch('users/cashdraws/list');
}
/**
* 获取用户数据
*/
public function pageQuery(){
$userId = (int)session('WST_USER.userId');
$data = model('CashDraws')->pageQuery(0,$userId);
return WSTReturn("", 1,$data);
}
/**
* 提现
*/
public function drawMoney(){
return model('CashDraws')->drawMoney();
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace wstmart\wechat\controller;
/**
* ============================================================================
* 错误处理控制器
*/
class Error extends Base{
public function index(){
header("HTTP/1.0 404 Not Found");
return $this->fetch('error_sys');
}
public function message(){
$code = input('code');
if($code !== null && session($code)!=''){
$this->assign('message',session($code));
}else{
$this->assign('message','操作错误,请联系商城管理员');
}
return $this->fetch('error_lost');
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Favorites as M;
/**
* ============================================================================
* 收藏控制器
*/
class Favorites extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth',
];
/**
* 关注的商品
*/
public function goods(){
return $this->fetch('users/favorites/list_goods');
}
/**
* 关注的店铺
*/
public function shops(){
return $this->fetch('users/favorites/list_shops');
}
/**
* 关注的商品列表
*/
public function listGoodsQuery(){
$m = new M();
$data = $m->listGoodsQuery();
foreach($data['Rows'] as $k=>$v){
$data['Rows'][$k]['goodsImg'] = WSTImg($v['goodsImg'],3);
}
return WSTReturn("", 1,$data);
}
/**
* 关注的店铺列表
*/
public function listShopQuery(){
$m = new M();
$data = $m->listShopQuery();
foreach($data['Rows'] as $k=>$v){
$data['Rows'][$k]['shopImg'] = WSTImg($v['shopImg'],3);
if(!empty($v['goods'])){
foreach($v['goods'] as $k1=>$v1){
$v[$k1]['goodsImg'] = WSTImg($v1['goodsImg'],3);
}
}
}
return WSTReturn("", 1,$data);
}
/**
* 取消关注
*/
public function cancel(){
$m = new M();
$rs = $m->del();
return $rs;
}
/**
* 增加关注
*/
public function add(){
$m = new M();
$rs = $m->add();
return $rs;
}
}

View File

@ -0,0 +1,96 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\GoodsCats;
use wstmart\common\model\GoodsConsult as CG;
/**
* ============================================================================
* 商品控制器
*/
class Goods extends Base{
/**
* 商品主页
*/
public function detail(){
$m = model('goods');
$goods = $m->getBySale(input('goodsId/d'));
hook('wechatControllerGoodsIndex',['getParams'=>input()]);
// 找不到商品记录
if(empty($goods))return $this->fetch('error_lost');
if(!empty($goods)){
$goods['goodsDesc']=htmlspecialchars_decode($goods['goodsDesc']);
$rule = '/<img src="\/(upload.*?)"/';
preg_match_all($rule, $goods['goodsDesc'], $images);
foreach($images[0] as $k=>$v){
$goods['goodsDesc'] = str_replace('/'.$images[1][$k], '__ROOT__/'.WSTConf("CONF.goodsLogo") . "\" data-echo=\"__ROOT__/".WSTImg($images[1][$k],3), $goods['goodsDesc']);
}
$history = cookie("wx_history_goods");
$history = is_array($history)?$history:[];
array_unshift($history, (string)$goods['goodsId']);
$history = array_values(array_unique($history));
if(!empty($history)){
cookie("wx_history_goods",$history,25920000);
}
}
if(WSTConf('CONF.wxenabled')==1){
$we = WSTWechat();
$datawx = $we->getJsSignature('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$this->assign("datawx", $datawx);
}
$goods['consult'] = model('GoodsConsult')->firstQuery($goods['goodsId']);
$goods['appraises'] = model('GoodsAppraises')->getGoodsEachApprNum($goods['goodsId']);
$this->assign("info", $goods);
return $this->fetch('goods_detail');
}
/**
* 商品列表
*/
public function lists(){
$this->assign("keyword", input('keyword'));
$this->assign("catId", input('catId/d'));
$this->assign("brandId", input('brandId/d'));
return $this->fetch('goods_list');
}
/**
* 获取列表
*/
public function pageQuery(){
$m = model('goods');
$gc = new GoodsCats();
$catId = (int)input('catId');
if($catId>0){
$goodsCatIds = $gc->getParentIs($catId);
}else{
$goodsCatIds = [];
}
$rs = $m->pageQuery($goodsCatIds);
foreach ($rs['Rows'] as $key =>$v){
$rs['Rows'][$key]['goodsImg'] = WSTImg($v['goodsImg'],2);
$rs['Rows'][$key]['praiseRate'] = ($v['totalScore']>0)?(sprintf("%.2f",$v['totalScore']/($v['totalUsers']*15))*100).'%':'100%';
}
// `券`标签
hook('afterQueryGoods',['page'=>&$rs]);
return $rs;
}
/**
* 浏览历史页面
*/
public function history(){
return $this->fetch('users/history/list');
}
/**
* 获取浏览历史
*/
public function historyQuery(){
$rs = model('goods')->historyQuery();
if(!empty($rs)){
foreach($rs['Rows'] as $k=>$v){
$rs['Rows'][$k]['goodsImg'] = WSTImg($v['goodsImg'],3);
}
}
return $rs;
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\GoodsAppraises as M;
/**
* ============================================================================
* 评价控制器
*/
class GoodsAppraises extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth' => ['except'=>'getbyid'],// 只要访问only下的方法才才需要执行前置操作
];
/**
* 根据商品id获取评论
*/
public function getById(){
$m = new M();
$rs = $m->getById();
return $rs;
}
/**
* 根据订单id,用户id,商品id获取评价
*/
public function getAppr(){
$m = model('GoodsAppraises');
$rs = $m->getAppr();
if(!empty($rs['data']['images'])){
$imgs = explode(',',$rs['data']['images']);
foreach($imgs as $k=>$v){
$imgs[$k] = WSTImg($v,1);
}
$rs['data']['images'] = $imgs;
}
return $rs;
}
/**
* 添加评价
*/
public function add(){
$m = new M();
$rs = $m->add();
return $rs;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\wechat\model\GoodsCats as M;
/**
* ============================================================================
* 商品分类控制器
*/
class GoodsCats extends Base{
/**
* 列表
*/
public function index(){
$m = new M();
$goodsCatList = $m->getGoodsCats();
$this->assign('list',$goodsCatList);
return $this->fetch('goods_category');
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\GoodsConsult as CG;
/**
* ============================================================================
* 商品咨询控制器
*/
class GoodsConsult extends Base{
/**
* 商品咨询页
*/
public function index(){
$this->assign('goodsId',(int)input('goodsId'));
return $this->fetch('goodsconsult/list');
}
/**
* 根据商品id获取商品咨询
*/
public function listQuery(){
$m = new CG();
return $m->listQuery();
}
/**
* 发布商品咨询页
*/
public function consult(){
$this->assign('goodsId',(int)input('goodsId'));
return $this->fetch('goodsconsult/consult');
}
public function add(){
$m = new CG();
return $m->add();
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\wechat\model\Index as M;
/**
* ============================================================================
* 默认控制器
*/
class Index extends Base{
/**
* 首页
*/
public function index(){
$m = new M();
hook('wechatControllerIndexIndex',['getParams'=>input()]);
$news = $m->getSysMsg('msg');
$this->assign('news',$news);
$ads['count'] = count(model("common/Tags")->listAds("wx-ads-index",99,86400));
$ads['width'] = 'width:'.$ads['count'].'00%';
$this->assign("ads", $ads);
//是否关注公众号
$signinfo = session('WST_WX_SIGNINFO');
if(!empty($signinfo['subscribe'])){
$signinfo['subscribe'] = ($signinfo['subscribe']==1)?0:1;
}else{
$signinfo['subscribe'] = 0;
}
$subscribe = cookie("WST_WX_SUBSCRIBE");
if($subscribe)$signinfo['subscribe'] = 0;
if(WSTConf('CONF.wxenabled')==1){
$we = WSTWechat();
$datawx = $we->getJsSignature('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$this->assign("datawx", $datawx);
}
$this->assign("subscribe", $signinfo['subscribe']);
return $this->fetch('index');
}
/**
* 楼层
*/
public function pageQuery(){
$m = new M();
$rs = $m->pageQuery();
if(isset($rs['goods'])){
foreach ($rs['goods'] as $key =>$v){
$rs['goods'][$key]['goodsImg'] = WSTImg($v['goodsImg'],2);
}
}
return $rs;
}
/**
* 跳去登录之前的地址
*/
public function sessionAddress(){
session('WST_WX_WlADDRESS',input('url'));
return WSTReturn("", 1);
}
/**
* 关闭关注
*/
public function closeFollow(){
cookie("WST_WX_SUBSCRIBE",1,25920000);
return WSTReturn("", 1);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Invoices as M;
/**
* ============================================================================
* 发票信息控制器
*/
class Invoices extends Base{
/**
* 列表
*/
public function pageQuery(){
$m = new M();
$rs = $m->pageQuery(5);// 移动版只显示5条发票信息
return $rs;
}
/**
* 新增
*/
public function add(){
$m = new M();
return $m->add();
}
/**
* 修改
*/
public function edit(){
$m = new M();
return $m->edit();
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace wstmart\wechat\controller;
/**
* ============================================================================
* 资金流水控制器
*/
class Logmoneys extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/**
* 查看用户资金流水
*/
public function usermoneys(){
$userId = (int)session('WST_USER.userId');
$rs = model('Users')->getFieldsById($userId,['lockMoney','userMoney','payPwd']);
$rs['isSetPayPwd'] = ($rs['payPwd']=='')?0:1;
unset($rs['payPwd']);
$rs['num'] = count(model('cashConfigs')->listQuery(0,$userId));
$this->assign('rs',$rs);
return $this->fetch('users/logmoneys/list');
}
/**
* 资金流水
*/
public function record(){
$userId = (int)session('WST_USER.userId');
$rs = model('Users')->getFieldsById($userId,['lockMoney','userMoney','payPwd']);
$this->assign('rs',$rs);
return $this->fetch('users/logmoneys/record');
}
/**
* 列表
*/
public function pageQuery(){
$userId = (int)session('WST_USER.userId');
$data = model('LogMoneys')->pageQuery("",$userId);
return WSTReturn("", 1,$data);
}
/**
* 验证支付密码
*/
public function checkPayPwd(){
return model('wechat/users')->checkPayPwd();
}
/**
* 充值[用户]
*/
public function toRecharge(){
$userId = (int)session('WST_USER.userId');
$rs = model('Users')->getFieldsById($userId,'userMoney');
$this->assign('rs',$rs);
$payments = model('common/payments')->recharePayments('3');
$this->assign('payments',$payments);
$chargeItems = model('common/ChargeItems')->queryList();
$this->assign('chargeItems',$chargeItems);
return $this->fetch('users/recharge/recharge');
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Messages as M;
/**
* ============================================================================
* 商城消息控制器
*/
class Messages extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/**
* 查看商城消息
*/
public function index(){
return $this->fetch('users/messages/list');
}
/**
* 获取列表
*/
public function pageQuery(){
$m = new M();
return $m->pageQuery();
}
/**
* 获取列表详情
*/
public function getById(){
$m = new M();
return $m->getById();
}
/**
* 删除地址
*/
public function del(){
$m = new M();
return $m->batchDel();
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\wechat\model\Articles as M;
/**
* ============================================================================
* 新闻控制器
*/
class News extends Base{
/**
* 列表查询
*/
public function view(){
$m = new M();
$data = $m->getChildInfos();
$catId = $data['0']['catId'];
$articleId = (int)input('articleId');
$this->assign('articleId',$articleId);
$this->assign('catInfo',$data);
$this->assign('catId',$catId);
return $this->fetch('articles/news_list');
}
/**
* 获取商城快讯列表
*/
public function getNewsList(){
$m = new M();
$data = $m->getArticles();
foreach($data as $k=>$v){
$data[$k]['articleContent'] = strip_tags(html_entity_decode($v['articleContent']));
$data[$k]['createTime'] = date('Y-m-d',strtotime($data[$k]['createTime']));
$data[$k]['coverImg'] = str_replace("_thumb.", ".", $data[$k]['coverImg']);
}
return $data;
}
/**
* 查看详情
*/
public function getNews(){
$m = new M();
$data = $m->getNewsById();
$data['articleContent']=htmlspecialchars_decode($data['articleContent']);
$data['createTime'] = date('Y-m-d',strtotime($data['createTime']));
return $data;
}
/**
* 点赞
*/
public function like(){
$m = new M();
$data = $m->like();
return $data;
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\OrderComplains as M;
/**
* ============================================================================
* 投诉控制器
*/
class orderComplains extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
public function complain(){
$oId = (int)input('oId');
$this->assign('oId',$oId);
return $this->fetch('users/orders/orders_complains');
}
/**
* 保存订单投诉信息
*/
public function saveComplain(){
return model('OrderComplains')->saveComplain();
}
/**
* 用户投诉列表
*/
public function index(){
return $this->fetch('users/orders/list_complains');
}
/**
* 获取用户投诉列表
*/
public function complainByPage(){
$m = model('OrderComplains');
return $m->queryUserComplainByPage();
}
/**
* 用户查投诉详情
*/
public function getComplainDetail(){
$rs = model('OrderComplains')->getComplainDetail(0);
$annex = $rs['complainAnnex'];
if($annex){
foreach($annex as $k=>$v){
$annex1[] = WSTImg($v,2);
}
$rs['complainAnnex'] = $annex1;
}
return $rs;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\OrderRefunds as M;
/**
* ============================================================================
* 订单退款控制器
*/
class Orderrefunds extends Base{
/**
* 用户申请退款
*/
public function refund(){
$m = new M();
$rs = $m->refund();
return $rs;
}
/**
* 商家处理是否同意
*/
public function shopRefund(){
$m = new M();
$rs = $m->shopRefund();
return $rs;
}
}

View File

@ -0,0 +1,269 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Orders as M;
use wstmart\common\model\Payments;
/**
* ============================================================================
* 订单控制器
*/
class Orders extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/*********************************************** 用户操作订单 ************************************************************/
/**
* 提醒发货
*/
public function noticeDeliver(){
$m = new M();
return $m->noticeDeliver();
}
/**
* 提交订单
*/
public function submit(){
$m = new M();
$rs = $m->submit(1);
return $rs;
}
/**
* 提交虚拟订单
*/
public function quickSubmit(){
$m = new M();
$rs = $m->quickSubmit();
return $rs;
}
/**
* 在线支付方式
*/
public function succeed(){
//获取支付方式
$pa = new Payments();
$payments = $pa->getByGroup('3');
$this->assign('payments',$payments);
$this->assign('orderNo',input("get.orderNo"));
$this->assign('isBatch',(int)input("get.isBatch/d",0));
return $this->fetch("users/orders/orders_pay_list");
}
/**
* 订单管理
*/
public function index(){
$type = input('param.type','');
$this->assign('type',$type);
return $this->fetch("users/orders/orders_list");
}
/**
* 订单列表
*/
public function getOrderList(){
/*
-3:拒收、退款列表
-2:待付款列表
-1:已取消订单
0,1: 待收货
2:待评价/已完成
*/
$flag = -1;
$type = input('param.type');
$status = [];
switch ($type) {
case 'waitPay':
$status=[-2];
break;
case 'waitDeliver':
$status=[0];
break;
case 'waitReceive':
$status=[1];
break;
case 'waitAppraise':
$status=[2];
$flag=0;
break;
case 'finish':
$status=[2];
break;
case 'abnormal': // 退款/拒收 与取消合并
$status=[-1,-3];
break;
default:
$status=[-3,-2,-1,0,1,2];
break;
}
$m = new M();
$rs = $m->userOrdersByPage($status,$flag);
foreach($rs['Rows'] as $k=>$v){
if(!empty($v['list'])){
foreach($v['list'] as $k1=>$v1){
$rs['Rows'][$k]['list'][$k1]['goodsImg'] = $v1['goodsImg'];
}
}
}
return $rs;
}
/**
* 订单详情
*/
public function getDetail(){
$m = new M();
$rs = $m->getByView((int)input('id'));
$rs['status'] = WSTLangOrderStatus($rs['orderStatus']);
$rs['payInfo'] = WSTLangPayType($rs['payType']);
$rs['deliverInfo'] = WSTLangDeliverType($rs['deliverType']);
foreach($rs['goods'] as $k=>$v){
$v['goodsImg'] = WSTImg($v['goodsImg'],3);
}
// 优惠券钩子
hook('wechatDocumentOrderSummaryView',['rs'=>&$rs]);
// 满就送钩子
hook('wechatDocumentOrderViewGoodsPromotion',['rs'=>&$rs]);
return $rs;
}
/**
* 用户确认收货
*/
public function receive(){
$m = new M();
$rs = $m->receive();
return $rs;
}
/**
* 用户-评价页
*/
public function orderAppraise(){
$m = model('Orders');
$oId = (int)input('oId');
//根据订单id获取 商品信息
$data = $m->getOrderInfoAndAppr();
$data['shopName']=model('shops')->getShopName($oId);
$this->assign('data',$data);
$this->assign('oId',$oId);
return $this->fetch('users/orders/orders_appraises');
}
/**
* 用户取消订单
*/
public function cancellation(){
$m = new M();
$rs = $m->cancel();
return $rs;
}
/**
* 用户拒收订单
*/
public function reject(){
$m = new M();
$rs = $m->reject();
return $rs;
}
/**
* 用户退款
*/
public function getRefund(){
$m = new M();
return $m->getMoneyByOrder((int)input('id'));
}
/*********************************************** 商家操作订单 ************************************************************/
/**
* 商家-查看订单列表
*/
public function sellerOrder(){
$this->checkShopAuth("list");
$type = input('param.type','');
$this->assign('type',$type);
$express = model('Express')->listQuery();
$this->assign('express',$express);
return $this->fetch('users/sellerorders/orders_list');
}
/**
* 商家-订单列表
*/
public function getSellerOrderList(){
/*
-3:拒收、退款列表
-2:待付款列表
-1:已取消订单
0: 待发货
1,2:待评价/已完成
*/
$type = input('param.type');
$this->checkShopAuth($type);
$status = [];
switch ($type) {
case 'waitPay':
$status=-2;
break;
case 'waitDeliver':
$status=0;
break;
case 'waitReceive':
$status=1;
break;
case 'waitDelivery':
$status=0;
break;
case 'finish':
$status=2;
break;
case 'abnormal': // 退款/拒收 与取消合并
$status=[-1,-3];
break;
default:
$status=[-3,-2,-1,0,1,2];
break;
}
$m = new M();
$rs = $m->shopOrdersByPage($status);
foreach($rs['Rows'] as $k=>$v){
if(!empty($v['list'])){
foreach($v['list'] as $k1=>$v1){
$rs['Rows'][$k]['list'][$k1]['goodsImg'] = $v1['goodsImg'];
}
}
}
return WSTReturn('操作成功',1,$rs);
}
/**
* 商家发货
*/
public function deliver(){
$this->checkShopAuth("waitDeliver");
$m = new M();
$rs = $m->deliver();
return $rs;
}
/**
* 商家修改订单价格
*/
public function editOrderMoney(){
$this->checkShopAuth("waitPay");
$m = new M();
$rs = $m->editOrderMoney();
return $rs;
}
/**
* 商家-操作退款
*/
public function toShopRefund(){
$this->checkShopAuth("abnormal");
return model('OrderRefunds')->getRefundMoneyByOrder((int)input('id'));
}
}

View File

@ -0,0 +1,151 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\GoodsCats;
use wstmart\wechat\model\Goods;
/**
* ============================================================================
* 门店控制器
*/
class Shops extends Base{
/**
* 店铺街
*/
public function shopStreet(){
$gc = new GoodsCats();
$goodsCats = $gc->listQuery(0);
$this->assign('goodscats',$goodsCats);
$this->assign("keyword", input('keyword'));
return $this->fetch('shop_street');
}
/**
* 店铺首页
*/
public function index(){
$s = model('shops');
$shopId = (int)input('shopId',1);
$data = $s->getShopSummary($shopId);
$this->assign('data',$data);
// 是否已关注
$isFavor = model('favorites')->checkFavorite($shopId,1);
$this->assign('isFavor',$isFavor);
$this->assign("goodsName", input('goodsName'));
return $this->fetch('shop_index');
}
/**
* 店铺详情
*/
public function home(){
$s = model('shops');
$shopId = (int)input("param.shopId/d",1);
$data['shop'] = $s->getShopInfo($shopId);
$ct1 = input("param.ct1/d",0);
$ct2 = input("param.ct2/d",0);
$goodsName = input("param.goodsName");
if(($data['shop']['shopId']==1 || $shopId==0) && $ct1==0 && !isset($goodsName))
$this->redirect('wechat/shops/selfShop');
$gcModel = model('ShopCats');
$data['shopcats'] = $gcModel->getShopCats($shopId);
$this->assign('shopId',$shopId);//店铺id
$this->assign('ct1',$ct1);//一级分类
$this->assign('ct2',$ct2);//二级分类
$this->assign('goodsName',urldecode($goodsName));//搜索
$this->assign('data',$data);
// 是否已关注
$isFavor = model('favorites')->checkFavorite($shopId,1);
$this->assign('isFavor',$isFavor);
$followNum = model('favorites')->followNum($shopId,1);
$this->assign('followNum',$followNum);
$cart = model('carts')->getCartInfo();
$this->assign('cart',$cart);
return $this->fetch('shop_home');
}
/**
* 店铺商品列表
*/
public function shopGoodsList(){
$s = model('shops');
$shopId = (int)input("param.shopId/d",1);
$ct1 = input("param.ct1/d",0);
$ct2 = input("param.ct2/d",0);
$goodsName = input("param.goodsName");
$gcModel = model('ShopCats');
$data['shopcats'] = $gcModel->getShopCats($shopId);
$this->assign('shopId',$shopId);//店铺id
$this->assign('ct1',$ct1);//一级分类
$this->assign('ct2',$ct2);//二级分类
$this->assign('goodsName',urldecode($goodsName));//搜索
$this->assign('data',$data);
return $this->fetch('shop_goods_list');
}
/**
* 获取店铺商品
*/
public function getShopGoods(){
$shopId = (int)input('shopId',1);
$g = model('goods');
$rs = $g->shopGoods($shopId);
foreach($rs['Rows'] as $k=>$v){
$rs['Rows'][$k]['goodsImg'] = WSTImg($v['goodsImg'],2);
}
return $rs;
}
/**
* 自营店铺
*/
public function selfShop(){
$s = model('shops');
$data['shop'] = $s->getShopInfo(1);
if(empty($data['shop']))return $this->fetch('error_lost');
$this->assign('selfShop',1);
$data['shopcats'] = model('ShopCats')->getShopCats(1);
$this->assign('goodsName',urldecode(input("param.goodsName")));//搜索
// 店长推荐
$data['rec'] = $s->getRecGoods('rec');
// 热销商品
$data['hot'] = $s->getRecGoods('hot');
$this->assign('data',$data);
// 是否已关注
$isFavor = model('favorites')->checkFavorite(1,1);
$this->assign('isFavor',$isFavor);
$followNum = model('favorites')->followNum(1,1);
$this->assign('followNum',$followNum);
$this->assign("keyword", input('keyword'));
return $this->fetch('self_shop');
}
public function getFloorData(){
$s = model('shops');
$rs = $s->getFloorData();
if(isset($rs['goods'])){
foreach($rs['goods'] as $k=>$v){
$rs['goods'][$k]['goodsImg'] = WSTImg($v['goodsImg'],2);
}
}
return $rs;
}
/**
* 店铺街列表
*/
public function pageQuery(){
$m = model('shops');
$rs = $m->pageQuery(input('pagesize/d'));
foreach ($rs['Rows'] as $key =>$v){
$rs['Rows'][$key]['shopImg'] = WSTImg($v['shopImg'],3);
}
return $rs;
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace wstmart\wechat\controller;
/**
* ============================================================================
* 关闭提示处理控制器
*/
use think\Controller;
class Switchs extends Controller{
public function __construct(){
parent::__construct();
WSTConf('CONF',WSTConfig());
$this->assign("v",WSTConf('CONF.wstVersion')."_".WSTConf('CONF.wstPcStyleId'));
if(WSTConf('CONF.wxenabled')==1){
if(!(request()->module()=="wechat" && request()->controller()=="Weixinpays" && request()->action()=="notify")){
WSTIsWeixin();//检测是否在微信浏览器上使用
}
}
}
protected function fetch($template = '', $vars = [], $replace = [], $config = []){
$style = WSTConf('CONF.wstwechatStyle')?WSTConf('CONF.wstwechatStyle'):'default';
$replace['__WECHAT__'] = str_replace('/index.php','',\think\Request::instance()->root()).'/wstmart/wechat/view/'.$style;
return $this->view->fetch($style."/".$template, $vars, $replace, $config);
}
public function index(){
return $this->fetch('error_switch');
}
}

View File

@ -0,0 +1,211 @@
<?php
namespace wstmart\wechat\controller;
use think\Loader;
use wstmart\common\model\Payments as M;
use wstmart\common\model\Orders as OM;
use wstmart\common\model\LogMoneys as LM;
/**
* ============================================================================
* 银联支付控制器
*/
class Unionpays extends Base{
/**
* 初始化
*/
private $unionConfig;
public function _initialize() {
header ("Content-type: text/html; charset=utf-8");
Loader::import('unionpay.sdk.acp_service');
$m = new M();
$this->unionConfig = $m->getPayment("unionpays");
$config = array();
$config["signCertPwd"] = $this->unionConfig["unionSignCertPwd"];//"000000"
$config["signMethod"] = "01";
$config["frontUrl"] = url("wechat/orders/index","",true,true);
$config["backUrl"] = url("wechat/unionpays/notify","",true,true);
new \SDKConfig($config);
}
public function getUnionpaysUrl(){
$m = new OM();
$payObj = input("payObj/s");
$data = array();
if($payObj=="recharge"){
$needPay = input("needPay/d");
$data["status"] = $needPay>0?1:-1;
}else{
$userId = (int)session('WST_USER.userId');
$data = $m->checkOrderPay();
}
return $data;
}
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $config_value 支付方式信息
*/
public function toUnionpay(){
$payObj = input("payObj/s");
$m = new OM();
$obj = array();
$data = array();
$orderAmount = 0;
$orderId = "";
$extra_param = "";
if($payObj=="recharge"){//充值
$orderAmount = input("needPay/d");
$targetType = (int)input("targetType/d");
$targetId = (int)session('WST_USER.userId');
if($targetType==1){//商家
$targetId = (int)session('WST_USER.shopId');
}
$data["status"] = $orderAmount>0?1:-1;
$orderId = WSTOrderNo();
$extra_param = $payObj."|".$targetId."|".$targetType;
}else{
$obj["orderNo"] = input("orderNo/s");
$obj["isBatch"] = (int)input("isBatch/d");
$data = $m->checkOrderPay($obj);
if($data["status"]==1){
$userId = (int)session('WST_USER.userId');
$obj["userId"] = $userId;
$order = $m->getPayOrders($obj);
$orderAmount = $order["needPay"];
$payRand = $order["payRand"];
$orderId = $obj["orderNo"]."a".$payRand;
$extra_param = $payObj."|".$userId."|".$obj["isBatch"];
}
}
if($data["status"]==1){
$params = array(
//以下信息非特殊情况不需要改动
'version' => \SDKConfig::$version, //版本号
'encoding' => 'utf-8', //编码方式
'txnType' => '01', //交易类型
'txnSubType' => '01', //交易子类
'bizType' => '000201', //业务类型
'frontUrl' => \SDKConfig::$frontUrl, //前台通知地址
'backUrl' => \SDKConfig::$backUrl, //后台通知地址
'signMethod' => \SDKConfig::$signMethod,//签名方法
'channelType' => '08', //渠道类型07-PC08-手机
'accessType' => '0', //接入类型
'currencyCode' => '156', //交易币种境内商户固定156
//TODO 以下信息需要填写
'merId' => $this->unionConfig["unionMerId"], //"777290058110048",//商户代码
'orderId' => $orderId, //商户订单号8-32位数字字母不能含“-”或“_”
'txnTime' => date('YmdHis'), //订单发送时间格式为YYYYMMDDhhmmss取北京时间
'txnAmt' => $orderAmount*100, //交易金额单位分此处默认取demo演示页面传递的参数
// 订单超时时间。
//'payTimeout' => date('YmdHis', strtotime('+15 minutes')),
'reqReserved' => $extra_param,
);
$acpService = new \AcpService();
$acpService::sign ( $params );
$uri = \SDKConfig::$frontTransUrl;
$html_form = $acpService::createAutoFormHtml( $params, $uri );
echo $html_form;
}else{
}
}
/**
* 异步回调接口
*/
public function notify(){
//计算得出通知验证结果
$acpService = new \AcpService(); // 使用银联原生自带的累 和方法 这里只是引用了一下 而已
$verify_result = $acpService->validate($_POST);
if($verify_result){//验证成功
$out_trade_no = $_POST['orderId']; //商户订单号
$queryId = $_POST['queryId']; //银联支付流水号
// 解释: 交易成功且结束,即不可再做任何操作。
if($_POST['respMsg'] == 'Success!'){
$m = new OM();
$extras = explode("|",$_POST['reqReserved']);
$rs = array();
if($extras[0]=="recharge"){//充值
$targetId = (int)$extras [1];
$targetType = (int)$extras [2];
$obj = array ();
$obj["trade_no"] = $_POST['trade_no'];
$obj["out_trade_no"] = $_POST["out_trade_no"];;
$obj["targetId"] = $targetId;
$obj["targetType"] = $targetType;
$obj["total_fee"] = $_POST['total_fee'];
$obj["payFrom"] = 'unionpays';
// 支付成功业务逻辑
$m = new LM();
$rs = $m->complateRecharge ( $obj );
}else{
//商户订单号
$obj = array();
$tradeNo = explode("a",$out_trade_no);
$obj["trade_no"] = $_POST['trade_no'];
$obj["out_trade_no"] = $tradeNo[0];
$obj["total_fee"] = $_POST['total_fee'];
$obj["userId"] = $extras[1];
$obj["isBatch"] = $extras[2];
$obj["payFrom"] = 'unionpays';
//支付成功业务逻辑
$rs = $m->complatePay($obj);
}
if($rs["status"]==1){
echo 'success';
}else{
echo 'fail';
}
}
}else{
echo "fail"; //验证失败
}
}
/**
* 同步回调接口
*/
public function response(){
//计算得出通知验证结果
$acpService = new \AcpService(); // 使用银联原生自带的累 和方法 这里只是引用了一下 而已
$verify_result = $acpService->validate($_POST);
if($verify_result){ //验证成功
$order_sn = $out_trade_no = $_POST['orderId']; //商户订单号
$queryId = $_POST['queryId']; //银联支付流水号
$respMsg = $_POST['respMsg']; //交易状态
if($_POST['respMsg'] == 'success'){
$m = new OM();
$extras = explode("|",$_POST['extra_param']);
if($extras[0]=="recharge"){//充值
$this->redirect(url("wechat/users/index"));
}else{
$obj = array();
$tradeNo = explode("a",$out_trade_no);
$obj["orderNo"] = $tradeNo[0];
$obj["userId"] = $extras[1];
$obj["isBatch"] = $extras[2];
$rs = $m->getOrderType($obj);
$this->redirect(url("wechat/orders/index"));
}
}else {
$this->error('支付失败');
}
}else {
$this->error('支付失败');
}
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\UserAddress as M;
/**
* ============================================================================
* 用户地址控制器
*/
class UserAddress extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/**
* 地址管理
*/
public function index(){
$m = new M();
$userId = session('WST_USER.userId');
$addressList = $m->listQuery($userId);
//获取省级地区信息
$area = model('WeChat/Areas')->listQuery(0);
$this->assign('area',$area);
$this->assign('list', $addressList);
$this->assign('type', (int)input('type'));
$this->assign('addressId', (int)input('addressId'));//结算选中的地址
return $this->fetch('users/useraddress/list');
}
/**
* 获取地址信息
*/
public function getById(){
$m = new M();
return $m->getById(input('post.addressId/d'));
}
/**
* 设置为默认地址
*/
public function setDefault(){
$m = new M();
return $m->setDefault();
}
/**
* 新增/编辑地址
*/
public function edits(){
$m = new M();
if((int)input('addressId')>0){
$rs = $m->edit();
}else{
$rs = $m->add();
}
return $rs;
}
/**
* 删除地址
*/
public function del(){
$m = new M();
return $m->del();
}
}

View File

@ -0,0 +1,372 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\wechat\model\Users as M;
use wstmart\wechat\model\Messages;
use wstmart\common\model\LogSms;
use wstmart\common\model\Users as MUsers;
/**
* ============================================================================
* 用户控制器
*/
class Users extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth' => ['except'=>'checklogin,login,register,getverify,getphoneverifycode,checkuserphone']// 访问这些except下的方法不需要执行前置操作
];
/**
* 会员登录页
*/
public function login(){
//如果已经登录了则直接跳去用户中心
$USER = session('WST_USER');
if(!empty($USER) && $USER['userId']!=''){
$this->redirect("users/index");
}
$userinfo = session('WST_WX_USERINFO');
$this->assign('info',$userinfo);
return $this->fetch('login');
}
/**
* 会员登录
*/
public function checkLogin(){
$m = new M();
$rs = $m->checkLogin(1);
$rs['url'] = session('WST_WX_WlADDRESS');
return $rs;
}
/**
* 会员注册
*/
public function register(){
$m = new M();
$rs = $m->regist(1);
$rs['url'] = session('WST_WX_WlADDRESS');
return $rs;
}
/**
* 手机号码是否存在
*/
public function checkUserPhone(){
$userPhone = input("post.userPhone");
$m = new M();
$rs = $m->checkUserPhone($userPhone,(int)session('WST_USER.userId'));
if($rs["status"]!=1){
return WSTReturn("手机号已注册",-1);
}else{
return WSTReturn("",1);
}
}
/**
* 获取验证码
*/
public function getPhoneVerifyCode(){
$userPhone = input("post.userPhone");
$rs = array();
if(!WSTIsPhone($userPhone)){
return WSTReturn("手机号格式不正确!");
exit();
}
$m = new M();
$rs = $m->checkUserPhone($userPhone,(int)session('WST_USER.userId'));
if($rs["status"]!=1){
return WSTReturn("手机号已存在!");
exit();
}
$phoneVerify = rand(100000,999999);
$tpl = WSTMsgTemplates('PHONE_USER_REGISTER_VERFIY');
if($tpl['tplContent']!='' && $tpl['status']=='1'){
$params = ['tpl'=>$tpl,'params'=>['MALL_NAME'=>WSTConf("CONF.mallName"),'VERFIY_CODE'=>$phoneVerify,'VERFIY_TIME'=>10]];
$m = new LogSms();
$rv = $m->sendSMS(0,$userPhone,$params,'getPhoneVerifyCode',$phoneVerify);
}
if($rv['status']==1){
session('VerifyCode_userPhone',$phoneVerify);
session('VerifyCode_userPhone_Time',time());
}
return $rv;
}
/**
* 会员中心
*/
public function index(){
$userId = session('WST_USER.userId');
$m = new M();
$user = $m->getById($userId);
if($user['userName']=='')$user['userName']=$user['loginName'];
$this->assign('user', $user);
//商城未读消息的数量 及 各订单状态数量
$data = model('index')->getSysMsg('msg','order','follow','history');
$this->assign('data',$data);
if(WSTConf('CONF.wxenabled')==1){
$we = WSTWechat();
$datawx = $we->getJsSignature('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$this->assign("datawx", $datawx);
}
return $this->fetch('users/index');
}
/**
* 个人信息
*/
public function edit(){
$userId = session('WST_USER.userId');
$m = new M();
$user = $m->getById($userId);
$this->assign('user', $user);
return $this->fetch('users/edit');
}
/**
* 编辑个人信息
*/
public function editUserInfo(){
$m = new M();
return $m->edit();
}
/**
* 账户安全
*/
public function security(){
$m = new M();
$userId = (int)session('WST_USER.userId');
$user = $m->getById($userId);
$payPwd = $user['payPwd'];
$userPhone = $user['userPhone'];
$loginPwd = $user['loginPwd'];
$user['loginPwd'] = empty($loginPwd)?0:1;
$user['payPwd'] = empty($payPwd)?0:1;
$user['userPhone'] = empty($userPhone)?0:1;
$this->assign('user', $user);
session('Edit_userPhone_Time', null);
return $this->fetch('users/security/index');
}
/**
* 修改登录密码
*/
public function editLoginPass(){
$m = new M();
$userId = (int)session('WST_USER.userId');
$user = $m->getById($userId);
$loginPwd = $user['loginPwd'];
$user['loginPwd'] = empty($loginPwd)?0:1;
$this->assign('user', $user);
return $this->fetch('users/security/user_login_pass');
}
public function editloginPwd(){
$m = new M();
$userId = (int)session('WST_USER.userId');
return $m->editPass($userId);
}
/**
* 修改支付密码
*/
public function editPayPass(){
$m = new M();
$userId = (int)session('WST_USER.userId');
$user = $m->getById($userId);
$payPwd = $user['payPwd'];
$user['payPwd'] = empty($payPwd)?0:1;
$this->assign('user', $user);
return $this->fetch('users/security/user_pay_pass');
}
public function editpayPwd(){
$m = new M();
$userId = (int)session('WST_USER.userId');
return $m->editPayPass($userId);
}
/**
* 忘记支付密码
*/
public function backPayPass(){
$m = new M();
$userId = (int)session('WST_USER.userId');
$user = $m->getById($userId);
$userPhone = $user['userPhone'];
$user['userPhone'] = WSTStrReplace($user['userPhone'],'*',3);
$user['phoneType'] = empty($userPhone)?0:1;
$backType = (int)session('Type_backPaypwd');
$timeVerify = session('Verify_backPaypwd_Time');
$user['backType'] = ($backType==1 && time()<floatval($timeVerify)+10*60)?1:0;
$this->assign('user', $user);
return $this->fetch('users/security/user_back_paypwd');
}
/**
* 忘记支付密码:发送短信
*/
public function backpayCode(){
$m = new MUsers();
$data = $m->getById(session('WST_USER.userId'));
$userPhone = $data['userPhone'];
$phoneVerify = rand(100000,999999);
$rv = ['status'=>-1,'msg'=>'短信发送失败'];
$tpl = WSTMsgTemplates('PHONE_FOTGET_PAY');
if($tpl['tplContent']!='' && $tpl['status']=='1'){
$params = ['tpl'=>$tpl,'params'=>['LOGIN_NAME'=>$data['loginName'],'VERFIY_CODE'=>$phoneVerify,'VERFIY_TIME'=>10]];
$m = new LogSms();
$rv = $m->sendSMS(0,$userPhone,$params,'getPhoneVerifyt',$phoneVerify);
}
if($rv['status']==1){
$USER = [];
$USER['userPhone'] = $userPhone;
$USER['phoneVerify'] = $phoneVerify;
session('Verify_backPaypwd_info',$USER);
session('Verify_backPaypwd_Time',time());
return WSTReturn('短信发送成功!',1);
}
return $rv;
}
/**
* 忘记支付密码:验证短信
*/
public function verifybackPay(){
$phoneVerify = input("post.phoneCode");
$timeVerify = session('Verify_backPaypwd_Time');
if(!session('Verify_backPaypwd_info.phoneVerify') || time()>floatval($timeVerify)+10*60){
return WSTReturn("校验码已失效,请重新发送!");
exit();
}
if($phoneVerify==session('Verify_backPaypwd_info.phoneVerify')){
session('Type_backPaypwd',1);
return WSTReturn("验证成功",1);
}
return WSTReturn("校验码不一致,请重新输入!");
}
/**
* 忘记支付密码:重置密码
*/
public function resetbackPay(){
$m = new M();
return $m->resetbackPay();
}
/**
* 修改手机
*/
public function editPhone(){
$m = new M();
$userId = (int)session('WST_USER.userId');
$user = $m->getById($userId);
$userPhone = $user['userPhone'];
$user['userPhone'] = WSTStrReplace($user['userPhone'],'*',3);
$user['phoneType'] = empty($userPhone)?0:1;
$this->assign('user', $user);
session('Edit_userPhone_Time', null);
return $this->fetch('users/security/user_phone');
}
/**
* 绑定手机:发送短信验证码
*/
public function sendCodeTie(){
$userPhone = input("post.userPhone");
if(!WSTIsPhone($userPhone)){
return WSTReturn("手机号格式不正确!");
exit();
}
$rs = array();
$m = new MUsers();
$rs = WSTCheckLoginKey($userPhone,(int)session('WST_USER.userId'));
if($rs["status"]!=1){
return WSTReturn("手机号已存在!");
exit();
}
$data = $m->getById(session('WST_USER.userId'));
$phoneVerify = rand(100000,999999);
$rv = ['status'=>-1,'msg'=>'短信发送失败'];
$tpl = WSTMsgTemplates('PHONE_BIND');
if($tpl['tplContent']!='' && $tpl['status']=='1'){
$params = ['tpl'=>$tpl,'params'=>['LOGIN_NAME'=>$data['loginName'],'VERFIY_CODE'=>$phoneVerify,'VERFIY_TIME'=>10]];
$m = new LogSms();
$rv = $m->sendSMS(0,$userPhone,$params,'sendCodeTie',$phoneVerify);
}
if($rv['status']==1){
$USER = [];
$USER['userPhone'] = $userPhone;
$USER['phoneVerify'] = $phoneVerify;
session('Verify_info',$USER);
session('Verify_userPhone_Time',time());
return WSTReturn('短信发送成功!',1);
}
return $rv;
}
/**
* 绑定手机
*/
public function phoneEdit(){
$phoneVerify = input("post.phoneCode");
$timeVerify = session('Verify_userPhone_Time');
if(!session('Verify_info.phoneVerify') || time()>floatval($timeVerify)+10*60){
return WSTReturn("校验码已失效,请重新发送!");
exit();
}
if($phoneVerify==session('Verify_info.phoneVerify')){
$m = new M();
$rs = $m->editPhone((int)session('WST_USER.userId'),session('Verify_info.userPhone'));
return $rs;
}
return WSTReturn("校验码不一致,请重新输入!");
}
/**
* 修改手机:发送短信验证码
*/
public function sendCodeEdit(){
$m = new MUsers();
$data = $m->getById(session('WST_USER.userId'));
$userPhone = $data['userPhone'];
$phoneVerify = rand(100000,999999);
$rv = ['status'=>-1,'msg'=>'短信发送失败'];
$tpl = WSTMsgTemplates('PHONE_EDIT');
if($tpl['tplContent']!='' && $tpl['status']=='1'){
$params = ['tpl'=>$tpl,'params'=>['LOGIN_NAME'=>$data['loginName'],'VERFIY_CODE'=>$phoneVerify,'VERFIY_TIME'=>10]];
$m = new LogSms();
$rv = $m->sendSMS(0,$userPhone,$params,'getPhoneVerifyt',$phoneVerify);
}
if($rv['status']==1){
$USER = [];
$USER['userPhone'] = $userPhone;
$USER['phoneVerify'] = $phoneVerify;
session('Verify_info2',$USER);
session('Verify_userPhone_Time2',time());
return WSTReturn('短信发送成功!',1);
}
return $rv;
}
/**
* 修改手机
*/
public function phoneEdito(){
$phoneVerify = input("post.phoneCode");
$timeVerify = session('Verify_userPhone_Time2');
if(!session('Verify_info2.phoneVerify') || time()>floatval($timeVerify)+10*60){
return WSTReturn("校验码已失效,请重新发送!");
exit();
}
if($phoneVerify==session('Verify_info2.phoneVerify')){
session('Edit_userPhone_Time',time());
return WSTReturn("验证成功",1);
//return $rs;
}
return WSTReturn("校验码不一致,请重新输入!");
}
public function editPhoneo(){
$m = new M();
$userId = (int)session('WST_USER.userId');
$user = $m->getById($userId);
$userPhone = $user['userPhone'];
$user['userPhone'] = WSTStrReplace($user['userPhone'],'*',3);
$timeVerify = session('Edit_userPhone_Time');
if(time()>floatval($timeVerify)+15*60){
$user['phoneType'] = 1;
}else{
$user['phoneType'] = 0;
}
$this->assign('user', $user);
return $this->fetch('users/security/user_phone');
}
public function userSet(){
return $this->fetch('users/userset/list');
}
public function aboutUs(){
return $this->fetch('users/userset/about');
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\UserScores as MUserscores;
/**
* ============================================================================
* 地区控制器
*/
class Userscores extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/**
* 查看
*/
public function index(){
$rs = model('Users')->getFieldsById((int)session('WST_USER.userId'),['userScore','userTotalScore']);
$this->assign('object',$rs);
return $this->fetch('users/userscores/list');
}
/**
* 获取数据
*/
public function pageQuery(){
$userId = (int)session('WST_USER.userId');
$data = model('UserScores')->pageQuery($userId);
return WSTReturn("", 1,$data);
}
/**
* 签到积分
*/
public function signScore(){
$m = new MUserscores();
$userId = (int)session('WST_USER.userId');
$rs = $m->signScore($userId);
return $rs;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace wstmart\wechat\controller;
use wstmart\common\model\Orders as OM;
/**
* ============================================================================
* 余额控制器
*/
class Wallets extends Base{
// 前置方法执行列表
protected $beforeActionList = [
'checkAuth'
];
/**
* 跳去支付页面
*/
public function payment(){
$data = [];
$data['orderNo'] = input('orderNo');
$data['isBatch'] = (int)input('isBatch');
$data['userId'] = (int)session('WST_USER.userId');
$this->assign('data',$data);
$m = new OM();
$rs = $m->getOrderPayInfo($data);
$list = $m->getByUnique();
$this->assign('rs',$list);
if(empty($rs)){
$this->assign('type','');
return $this->fetch("users/orders/orders_list");
}else{
$this->assign('needPay',$rs['needPay']);
//获取用户钱包
$user = model('users')->getFieldsById($data['userId'],'userMoney,payPwd');
$this->assign('userMoney',$user['userMoney']);
$payPwd = $user['payPwd'];
$payPwd = empty($payPwd)?0:1;
$this->assign('payPwd',$payPwd);
}
return $this->fetch('users/orders/orders_pay_wallets');
}
/**
* 钱包支付
*/
public function payByWallet(){
$m = new OM();
return $m->payByWallet();
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace wstmart\wechat\controller;
use think\Controller;
/**
* ============================================================================
* 微信接入接口控制器
*/
class Weixin extends Controller{
public function index(){
if(isset($_GET['echostr'])){
$this->first();
}else{
$wechat = new \wechat\WSTWechat(WSTConf('CONF.wxAppId'),WSTConf('CONF.wxAppKey'));
$wechat->responseMsg();
}
}
public function first()
{
$echoStr = input("echostr");
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
private function checkSignature()
{
$signature = input("signature");
$timestamp = input("timestamp");
$nonce = input("nonce");
$token = WSTConf('CONF.wxAppCode');
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
/******************** 调用模板消息接口 *************************/
public function getTemplates(){
$wechat = new \wechat\WSTWechat(WSTConf('CONF.wxAppId'),WSTConf('CONF.wxAppKey'));
$rs = $wechat->getTemplates();
dump(json_decode($rs,true));
}
public function sendTemplate(){
$wechat = new \wechat\WSTWechat(WSTConf('CONF.wxAppId'),WSTConf('CONF.wxAppKey'));
$wechat->sendTemplate();
}
}

View File

@ -0,0 +1,204 @@
<?php
namespace wstmart\wechat\controller;
use think\Loader;
use wstmart\common\model\Payments as M;
use wstmart\common\model\Orders as OM;
use wstmart\common\model\LogMoneys as LM;
use wstmart\common\model\ChargeItems as CM;
/**
* ============================================================================
* 微信支付控制器
*/
class Weixinpays extends Base{
/**
* 初始化
*/
private $wxpayConfig;
private $wxpay;
public function _initialize() {
header ("Content-type: text/html; charset=utf-8");
Loader::import('wxpay.WxPayConf');
Loader::import('wxpay.WxJsApiPay');
$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['notifyurl'] = url("wechat/weixinpays/notify","",true,true);
$this->wxpayConfig['returnurl'] = url("wechat/orders/index","",true,true);
$this->wxpayConfig['curl_timeout'] = 30;
// 初始化WxPayConf
new \WxPayConf($this->wxpayConfig);
}
public function toPay(){
$data = [];
$payObj = input("payObj/s");
if($payObj=="recharge"){
$cm = new CM();
$itemId = (int)input("itemId/d");
$targetType = (int)input("targetType/d");
$targetId = (int)session('WST_USER.userId');
if($targetType==1){//商家
$targetId = (int)session('WST_USER.shopId');
}
$needPay = 0;
if($itemId>0){
$item = $cm->getItemMoney($itemId);
$needPay = isSet($item["chargeMoney"])?$item["chargeMoney"]:0;
}else{
$needPay = (int)input("needPay/d");
}
$out_trade_no = WSTOrderNo();
$body = "钱包充值";
$data["status"] = $needPay>0?1:-1;
$attach = $payObj."@".$targetId."@".$targetType."@".$needPay."@".$itemId;
$returnurl = url("wechat/logmoneys/usermoneys","",true,true);
}else{
$data['orderNo'] = input('orderNo');
$data['isBatch'] = (int)input('isBatch');
$data['userId'] = (int)session('WST_USER.userId');
$m = new OM();
$rs = $m->getOrderPayInfo($data);
if(empty($rs)){
$this->assign('type','');
return $this->fetch("users/orders/orders_list");
}else{
$pkey = base64_decode(input("pkey"));
$extras = explode ( "@",$pkey);
$m = new OM();
$userId = (int)session('WST_USER.userId');
$obj["userId"] = $userId;
$obj["orderNo"] = input("orderNo");
$obj["isBatch"] = (int)input("isBatch");
$rs = $m->getByUnique();
$this->assign('rs',$rs);
$body = "支付订单";
$order = $m->getPayOrders($obj);
$needPay = $order["needPay"];
$payRand = $order["payRand"];
$out_trade_no = $obj["orderNo"]."a1".$payRand;
$attach = $userId."@".$obj["orderNo"]."@".$obj["isBatch"];
$returnurl = url("wechat/orders/index","",true,true);
}
}
//使用jsapi接口
$jsApi = new \JsApi();
//使用统一支付接口
$unifiedOrder = new \UnifiedOrder();
$openid = session('WST_USER.wxOpenId');
$unifiedOrder->setParameter("openid",$openid);//商品描述
//自定义订单号,此处仅作举例
$unifiedOrder->setParameter("out_trade_no",$out_trade_no);//商户订单号
$unifiedOrder->setParameter("notify_url",$this->wxpayConfig ['notifyurl']);//通知地址
$unifiedOrder->setParameter("trade_type","JSAPI");//交易类型
$unifiedOrder->setParameter("body",$body);//商品描述
$needPay = WSTBCMoney($needPay,0,2);
$unifiedOrder->setParameter("total_fee", $needPay * 100);//总金额
$userId = (int)session('WST_USER.userId');
$this->assign('needPay',$needPay);
$this->assign('returnUrl',$returnurl );
$this->assign('payObj',$payObj);
$unifiedOrder->setParameter("attach",$attach);//附加数据
$prepay_id = $unifiedOrder->getPrepayId();
//=========步骤3使用jsapi调起支付============
$jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters();
$this->assign('jsApiParameters',$jsApiParameters);
return $this->fetch('users/orders/orders_pay');
}
public function toAddonPay() {
$this->assign('payObj',session("addonPay.payObj"));
$this->assign('object',session("addonPay.object"));
$this->assign('needPay',session("addonPay.needPay"));
$this->assign('returnUrl',session("addonPay.returnUrl"));
$this->assign('jsApiParameters',session("addonPay.jsApiParameters"));
$ctr = new \think\addons\Controller();
return $ctr->fetch(session("addonPay.showUrl"));
}
public function notify() {
// 使用通用通知接口
$notify = new \Notify();
// 存储微信的回调
$xml = file_get_contents("php://input");
$notify->saveData ( $xml );
if ($notify->checkSign () == FALSE) {
$notify->setReturnParameter ( "return_code", "FAIL" ); // 返回状态码
$notify->setReturnParameter ( "return_msg", "签名失败" ); // 返回信息
} else {
$notify->setReturnParameter ( "return_code", "SUCCESS" ); // 设置返回码
}
$returnXml = $notify->returnXml ();
if ($notify->checkSign () == TRUE) {
if ($notify->data ["return_code"] == "FAIL") {
// 此处应该更新一下订单状态,商户自行增删操作
} elseif ($notify->data ["result_code"] == "FAIL") {
// 此处应该更新一下订单状态,商户自行增删操作
} else {
$order = $notify->getData ();
$rs = $this->process($order);
if($rs["status"]==1){
echo "SUCCESS";
}else{
echo "FAIL";
}
}
}
}
//订单处理
private function process($order) {
$obj = array();
$obj["trade_no"] = $order['transaction_id'];
$obj["total_fee"] = (float)$order["total_fee"]/100;
$extras = explode ( "@", $order ["attach"] );
if($extras[0]=="recharge"){//充值
$targetId = (int)$extras [1];
$targetType = (int)$extras [2];
$itemId = (int)$extras [4];
$obj["out_trade_no"] = $order['out_trade_no'];
$obj["targetId"] = $targetId;
$obj["targetType"] = $targetType;
$obj["itemId"] = $itemId;
$obj["payFrom"] = 'weixinpays';
// 支付成功业务逻辑
$m = new LM();
$rs = $m->complateRecharge ( $obj );
}else{
$obj["userId"] = $extras[0];
$obj["out_trade_no"] = $extras[1];
$obj["isBatch"] = $extras[2];
$obj["payFrom"] = "weixinpays";
// 支付成功业务逻辑
$m = new OM();
$rs = $m->complatePay ( $obj );
}
return $rs;
}
}