339 行
14 KiB
PHP
可执行文件
339 行
14 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Vip\Controller;
|
||
|
||
use Think\Controller;
|
||
use Think\Jssdk;
|
||
use Think\Jssdks;
|
||
//[1.2.99]
|
||
class IntegralController extends BaseController {
|
||
Public function index() {
|
||
$vid = session('vid');
|
||
|
||
$vip = D('Vip')->getFind(array('id'=>$vid));
|
||
$Order = D('IntegralOrder')->getSelect(array('vid'=>$vid,'integral'=>array('gt',0)),'*','addtime desc');
|
||
$sum = D('IntegralOrder')->getSum(array('vid'=>$vid,'type'=>array('in','3,5')),'integral');
|
||
$list = array();
|
||
foreach ($Order as $key=>$val){
|
||
$Order[$key]['timeymd'] = date('Y-m-d',$val['addtime']);
|
||
$Order[$key]['timedetail'] = date('H:i:s',$val['addtime']);
|
||
|
||
$day = $Order[$key]['timeymd'];
|
||
if(array_key_exists($day,$list)){
|
||
array_push($list[$day]['list'],$Order[$key]);
|
||
}else{
|
||
$list[$day]['date'] = $day;
|
||
$list[$day]['list'] = array();
|
||
array_push($list[$day]['list'],$Order[$key]);
|
||
}
|
||
}
|
||
|
||
$this->assign('sum',$sum);
|
||
$this->assign('list',$list);
|
||
$this->assign('vip',$vip);
|
||
$userInfo = session('userinfo');
|
||
if($userInfo['style_model']==2){
|
||
$this->display('index2');
|
||
}else if($userInfo['style_model']==3){
|
||
$this->display('index3');
|
||
}else{
|
||
$this->display();
|
||
}
|
||
}
|
||
public function toCash(){
|
||
$vid = session('vid');
|
||
$vip = M('vip')->where(array('id'=>$vid))->find();
|
||
$allCashIntegral = M('integral_cash')->where(array('vid'=>$vid))->sum('cash_integral');
|
||
$this->assign('allCashIntegral',$allCashIntegral?$allCashIntegral:0);
|
||
$percentage = M('integral_percentage')->where(array('merchantid'=>$vip['merchant_id']))->find();
|
||
$this->assign('percentage',$percentage);
|
||
$this->assign('vip',$vip);
|
||
|
||
$this->display();
|
||
}
|
||
public function exItems(){
|
||
$vid = session('vid');
|
||
$vip = M('vip')->where(array('id'=>$vid))->find();
|
||
|
||
$percentage = M('integral_percentage')->where(array('merchantid'=>$vip['merchant_id']))->find();
|
||
|
||
$list = M('retail_goods as r')
|
||
->join('ls_store as s on s.id=r.storeid')
|
||
->where(array('s.merchantid'=>$vip['merchant_id'],'r.can_exchange'=>1,'r.max_swap_num'=>array('gt',0)))
|
||
->field('r.*')
|
||
->select();
|
||
$order = array();
|
||
foreach ($list as $val){
|
||
$map['vid'] = $vid;
|
||
$map['exchangeid'] = $val['id'];
|
||
$map['state'] = 0;
|
||
$count = M('integral_exchange')->where($map)->count();
|
||
if($count<$val['max_swap']){
|
||
$order[] = $val;
|
||
}
|
||
}
|
||
$this->assign('list',$order);
|
||
|
||
//jssdk
|
||
$wechat = M('wxconfig')->where(array('storeid'=>$vip['primaryid']))->find();
|
||
if ($wechat['type'] == 1) {
|
||
$jssdk = new Jssdk($wechat['appid'], $wechat['appsecret']);
|
||
} else if ($wechat['type'] == 2) {
|
||
$access_token = get_authorizer_access_token($vip['primaryid']);
|
||
$jssdk = new Jssdks($wechat['authorizer_appid'], $access_token);
|
||
} else {
|
||
$this->error('微信配置参数有误');
|
||
}
|
||
$signPackage = $jssdk->GetSignPackage();
|
||
$this->assign('signPackage', $signPackage);
|
||
|
||
$useIntegral = M('integral_order')->where(array('vid'=>$vid,'type'=>9))->sum('integral');
|
||
$this->assign('useIntegral',$useIntegral?$useIntegral:0);
|
||
$this->assign('vip',$vip);
|
||
$this->display();
|
||
}
|
||
|
||
/*
|
||
* 查看余额是否足够
|
||
* */
|
||
public function getDetail(){
|
||
$vid = session('vid');
|
||
$integral = I('post.integral');
|
||
$id = I('post.id');
|
||
if(empty($vid) || empty($id) || empty($integral)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
}else{
|
||
$vip = M('vip')->where(array('id'=>$vid))->find();
|
||
if(empty($vip)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '会员不存在';
|
||
}else{
|
||
if($vip['integral']<$integral){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '积分不足'.$integral;
|
||
}else{
|
||
$map['id'] = $id;
|
||
$map['can_exchange'] = 1;
|
||
$map['goods_num'] = array('gt',0);//库存>0
|
||
$retail = M('retail_goods')->where($map)->find();
|
||
if(empty($retail)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '商品库存不足';
|
||
}else{
|
||
$percentage = M('integral_percentage')->where(array('merchantid'=>$vip['merchant_id']))->find();
|
||
$map1['type'] = 5;
|
||
$map1['vid'] = $vid;
|
||
$map1['state'] = 0;
|
||
$map1['bigintime'] = array('gt',strtotime(date('Y-m-d',time())));
|
||
$dayCount = M('integral_exchange')->where($map1)->count();
|
||
if($dayCount>=$percentage['max_day_swap']){
|
||
$result['status'] = 0;
|
||
$result['M'] = M()->_sql();
|
||
$result['msg'] = '每日最多换购商品'.$percentage['max_day_swap'].'次';
|
||
}else{
|
||
unset($map1['bigintime']);
|
||
$map1['exchangeid'] = $id;
|
||
$exchangeCount = M('integral_exchange')->where($map1)->count();
|
||
if($exchangeCount>=$retail['max_swap']){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该商品最多换购'.$retail['max_swap'].'次';
|
||
}else{
|
||
unset($map1['vid']);
|
||
$exchangeAllCount = M('integral_exchange')->where($map1)->count();
|
||
if($exchangeAllCount>=$retail['max_swap_num']){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该商品已经被换购完';
|
||
}else{
|
||
$result['status'] = 1;
|
||
$result['msg'] = '您可以进行换购';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
/*
|
||
* 兑换商品
|
||
* */
|
||
public function toExItem(){
|
||
$vid = session('vid');
|
||
$id = I('post.id');
|
||
$out_trade_no = I('post.out_trade_no');
|
||
if(!empty($id) && !empty($vid) && !empty($out_trade_no)){
|
||
$PingAnOrderModel = D('PingAnOrder');
|
||
$order = $PingAnOrderModel->getOrder(array('out_trade_no' => $out_trade_no));
|
||
if (empty($order)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单不存在';
|
||
}else{
|
||
$map['id'] = $id;
|
||
$map['can_exchange'] = 1;
|
||
$map['goods_num'] = array('gt',0);//库存>0
|
||
$retail = M('retail_goods')->where($map)->find();
|
||
if(!empty($retail)){
|
||
$exchange['vid'] = $vid;
|
||
$exchange['storeid'] = $order['storeid'];
|
||
$exchange['exchangeid'] = $id;
|
||
$exchange['bigintime'] = time();
|
||
$exchange['type'] = 5;
|
||
$exchange['status'] = 1;
|
||
$exchange['state'] = 1;
|
||
$addE = M('integral_exchange')->add($exchange);
|
||
|
||
$item['money'] = $retail['exchange_money'];
|
||
$item['allmoney'] = $retail['exchange_money'];
|
||
$item['orderid'] = $order['id'];
|
||
$item['exchangeid'] = $addE;
|
||
$item['type'] = 3; //1是充值 2是余额消费 3微信在线支付 4大转盘抽奖 5拆红包 6余额与微信同时支付
|
||
$item['status'] = 0;
|
||
$item['addtime'] = time();
|
||
$item['storeid'] = $order['storeid'];
|
||
$item['vipid'] = $vid;
|
||
$item['remark'] = '积分换购支付' . $item['money'] . '元';
|
||
$addR = M('rechargeorder')->add($item);
|
||
if($addE && $addR){
|
||
$result['orderid'] = $addR;
|
||
$result['status'] = 1;
|
||
$result['msg'] = '添加记录成功';
|
||
}else{
|
||
$result['status'] = 0;
|
||
$result['msg'] = '添加记录失败';
|
||
}
|
||
}else{
|
||
$result['msg'] = '商品不存在';
|
||
$result['status'] = 0;
|
||
}
|
||
}
|
||
}else{
|
||
$result['msg'] = '缺少参数';
|
||
$result['status'] = 0;
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//查询换购状态
|
||
public function searchExchange(){
|
||
$orderid = I('post.orderid');
|
||
$vid = session('vid');
|
||
if(empty($orderid) || empty($vid)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
}else{
|
||
$rechargeorder = M('rechargeorder')->where(array('id'=>$orderid))->find();
|
||
if(empty($rechargeorder)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '换购订单不存在';
|
||
}else{
|
||
if($rechargeorder['status']==1){
|
||
$result['status'] = 1;
|
||
$result['msg'] = '兑换成功';
|
||
}else{
|
||
$time = get_runtime();
|
||
if($time<5){
|
||
$this->searchExchange();
|
||
}else{
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付失败';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//兑换记录
|
||
public function exOrder(){
|
||
$vid = session('vid');
|
||
$list = M('integral_order')->where(array('vid'=>$vid,'type'=>9))->order('time desc')->select();
|
||
foreach ($list as &$val){
|
||
$val['time'] = date('Y-m-d H:i',$val['time']);
|
||
}
|
||
$this->assign('order',$list);
|
||
$this->display();
|
||
}
|
||
//提交提现申请
|
||
public function toSubmitOrder(){
|
||
$integral = I('post.integral');
|
||
$vid = session('vid');
|
||
if(empty($integral) || empty($vid)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
}else{
|
||
$vip = M('vip')->where(array('id'=>$vid))->find();
|
||
if(empty($vip)){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '会员不存在';
|
||
}else{
|
||
if(empty($vip['bank_username']) || empty($vip['bank_id']) || empty($vip['bank_card'])){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请先到储值卡中心绑定银行卡';
|
||
}else{
|
||
$percentage = M('integral_percentage')->where(array('merchantid'=>$vip['merchant_id']))->find();
|
||
if(empty($percentage) || $percentage['isopen_cash']==0 || $percentage['cash_ratio']==0 || $percentage['max_cash_integral']==0){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '商家未开启积分提现';
|
||
}else if($vip['cash_integral']<$integral){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '可提现积分不足'.$integral;
|
||
}else{
|
||
$map['vid'] = $vid;
|
||
$map['addtime'] = array('gt',strtotime(date('Y-m-d')));
|
||
$count = M('integral_cash')->where($map)->count();
|
||
if($count>=$percentage['max_day_time']){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '已达到每日最大提现次数';
|
||
}else{
|
||
if($integral>$percentage['max_cash_integral']){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '单次最大提现积分为: '.$percentage['max_cash_integral'];
|
||
}else{
|
||
$money = round($percentage['cash_ratio']*$integral,2);
|
||
if($money<0){
|
||
$result['status'] = 0;
|
||
$result['msg'] = '提现金额不足0.01元';
|
||
}else{
|
||
$addOrder['vid'] = $vid;
|
||
$addOrder['merchantid'] = $vip['merchant_id'];
|
||
$addOrder['cash_ratio'] = $percentage['cash_ratio'];
|
||
$addOrder['cash_integral'] = $integral;
|
||
$addOrder['money'] = $money;
|
||
$addOrder['addtime'] = time();
|
||
$addOrder['status'] = 0;
|
||
$addOrder['state'] = 0;
|
||
$addOrder['remark'] = '';
|
||
$add = M('integral_cash')->add($addOrder);
|
||
if($add){
|
||
$vip = M('vip')->where(array('id'=>$vid))->setDec('cash_integral',$integral);
|
||
$result['status'] = 1;
|
||
$result['msg'] = '提现申请成功';
|
||
}else{
|
||
$result['status'] = 0;
|
||
$result['msg'] = '提现申请失败';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//提现记录
|
||
public function cash_order(){
|
||
$vid = session('vid');
|
||
$order = M('integral_cash')->where(array('vid'=>$vid))->order('addtime desc')->select();
|
||
|
||
foreach ($order as &$val){
|
||
$val['addtime'] = date('Y-m-d H:i',$val['addtime']);
|
||
// $val['status'] = $val['status']?'提现成功':'待商家审核';
|
||
}
|
||
$this->assign('order',$order);
|
||
$this->display();
|
||
}
|
||
} |