208 行
6.6 KiB
PHP
可执行文件
208 行
6.6 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace SmallProgramApi\Controller;
|
|
|
|
use Think\Controller;
|
|
|
|
//[1.4.13]
|
|
|
|
/**
|
|
* 红包控制器
|
|
* Class RewardController
|
|
* @package SmallProgramApi\Controller
|
|
*/
|
|
class RewardController extends BaseController
|
|
{
|
|
/**
|
|
* 获取红包商城首页红包
|
|
*/
|
|
public function getHomeReward()
|
|
{
|
|
$merchant_id = self::$merchant_id;
|
|
$uid = self::$uid;
|
|
$result = getRewardActivity(3, $merchant_id, self::$store_id, self::$user['vid'], $uid);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/**
|
|
* 商城首页开红包
|
|
*/
|
|
public function openHomeReward()
|
|
{
|
|
$merchant_id = self::$merchant_id;
|
|
$uid = self::$uid;
|
|
if (empty($uid) || empty($merchant_id)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少参数';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$RSPUModel = D('RetailSmallProgramUser');
|
|
$user = $RSPUModel->getFind(array($RSPUModel::ID => $uid));
|
|
if (empty($user) || empty($user[$RSPUModel::VID])) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '用户不存在';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$VipModel = D('RetailVip');
|
|
$vip = $VipModel->getFind(array($VipModel::ID => $user[$RSPUModel::VID]));
|
|
if (empty($vip)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '您未绑定公众号会员卡';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$item = array(
|
|
'merchant_id' => self::$merchant_id,
|
|
'store_id' => self::$store_id,
|
|
'uid' => $uid,
|
|
'grade_integral' => $vip['grade_integral'],
|
|
'vid' => $vip['id'],
|
|
);
|
|
$result = A('Api/RewardDealApi')->rewardDeal($item, 3);
|
|
$this->ajaxReturn($result);
|
|
|
|
}
|
|
|
|
/**
|
|
* 我的红包列表
|
|
*/
|
|
public function rewardList()
|
|
{
|
|
$merchant_id = self::$merchant_id;
|
|
$uid = self::$uid;
|
|
$page = I('post.page');
|
|
$limit = I('post.limit');
|
|
if (!empty($limit) && !empty($page)) {
|
|
$pages = "$page,$limit";
|
|
} else {
|
|
$pages = " ";
|
|
}
|
|
if (empty($uid) || empty($merchant_id)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少参数';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$RewardRecordModel = D('RetailRewardRecord');
|
|
$filed = array(
|
|
$RewardRecordModel::MONEY,
|
|
$RewardRecordModel::ADD_TIME,
|
|
$RewardRecordModel::REWARD_ID,
|
|
$RewardRecordModel::STATUS
|
|
);
|
|
$RetailRewardRecord = $RewardRecordModel->getSelect(array($RewardRecordModel::VID => $uid, $RewardRecordModel::MERCHANT_ID => $merchant_id), $filed, 'id desc', $pages);
|
|
foreach ($RetailRewardRecord as &$val) {
|
|
$RewardModel = D('Reward');
|
|
$type = $RewardModel->getFindField(array('id' => $val[$RewardRecordModel::REWARD_ID]), 'type');
|
|
$val['addtimes'] = date('Y.m.d H:i:s');
|
|
if ($type == 1) {
|
|
$val['remark'] = '公众号红包';
|
|
} elseif ($type == 2) {
|
|
$val['remark'] = '线下消费红包';
|
|
} elseif ($type == 3) {
|
|
$val['remark'] = '商城登录红包';
|
|
} elseif ($type == 4) {
|
|
$val['remark'] = '线上消费红包';
|
|
}
|
|
}
|
|
$result['status'] = 1;
|
|
$result['msg'] = '查询成功';
|
|
$result['data'] = $RetailRewardRecord;
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/**
|
|
* 获取支付完成后的红包
|
|
*/
|
|
public function getPayReward()
|
|
{
|
|
$order_no = I('post.order_no');
|
|
if (empty($order_no)) {
|
|
$this->ajaxReturn(array(
|
|
'status' => 0,
|
|
'msg' => '缺少参数',
|
|
));
|
|
}
|
|
$merchant_id = self::$merchant_id;
|
|
$uid = self::$uid;
|
|
$BillModel = D('RetailBillOrder');
|
|
$map = array(
|
|
'order_no' => strval($order_no),
|
|
'uid' => $uid
|
|
);
|
|
$bill = $BillModel->getFind($map, 'id,all_money');
|
|
if (!empty($bill)) {
|
|
$VipModel = D('RetailVip');
|
|
$vip = $VipModel->getFind(array('id' => self::$user['vid']));
|
|
if (empty($vip)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '请先注册会员';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$result = getRewardActivity(4, $merchant_id, self::$store_id, self::$user['vid'], $uid, $bill['id']);
|
|
} else {
|
|
$result = array(
|
|
'status' => 0,
|
|
'msg' => '请求有误',
|
|
);
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/**
|
|
* 线上支付拆红包接口
|
|
*/
|
|
public function openPayReward()
|
|
{
|
|
$order_no = I('post.order_no');
|
|
if (empty($order_no)) {
|
|
$this->ajaxReturn(array(
|
|
'status' => 0,
|
|
'msg' => '缺少参数',
|
|
));
|
|
}
|
|
$uid = self::$uid;
|
|
if (empty($uid)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少参数';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$RSPUModel = D('RetailSmallProgramUser');
|
|
$user = $RSPUModel->getFind(array($RSPUModel::ID => $uid));
|
|
if (empty($user) || empty($user[$RSPUModel::VID])) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '用户不存在';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$VipModel = D('RetailVip');
|
|
$vip = $VipModel->getFind(array($VipModel::ID => $user[$RSPUModel::VID]));
|
|
if (empty($vip)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '请先注册会员';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
$BillModel = D('RetailBillOrder');
|
|
$map = array(
|
|
'order_no' => strval($order_no),
|
|
'uid' => $uid
|
|
);
|
|
$bill = $BillModel->getFind($map, 'id,all_money');
|
|
if (!empty($bill)) {
|
|
$item = array(
|
|
'merchant_id' => self::$merchant_id,
|
|
'store_id' => self::$store_id,
|
|
'uid' => $uid,
|
|
'grade_integral' => $vip['grade_integral'],
|
|
'order_id' => $bill['id'],
|
|
'need_money' => $bill['all_money'],
|
|
'vid' => $vip['id'],
|
|
);
|
|
$result = A('Api/RewardDealApi')->rewardDeal($item, $type = 4);
|
|
$this->ajaxReturn($result);
|
|
} else {
|
|
$this->ajaxReturn(array(
|
|
'status' => 0,
|
|
'msg' => '请求有误',
|
|
));
|
|
}
|
|
}
|
|
} |