392 行
12 KiB
PHP
可执行文件
392 行
12 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace SmallProgramApi\Controller;
|
|
|
|
//[1.8.20]
|
|
|
|
/**
|
|
* 次卡
|
|
*/
|
|
class SubCardController extends BaseController
|
|
{
|
|
/**
|
|
* [_initialize]
|
|
* @return array
|
|
*/
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
if (!self::$store_id) {
|
|
$res = array('status' => 0, 'msg' => '缺少必要的store_id参数');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 次卡列表
|
|
* @param string $keyword
|
|
* @param string $page
|
|
* @param string $limit
|
|
* @return array
|
|
*/
|
|
public function subCardList()
|
|
{
|
|
// 接受数据
|
|
$page = intval(I('post.page'));
|
|
$limit = intval(I('post.limit'));
|
|
// 判断
|
|
if (!$page || !$limit) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取次卡
|
|
$res = A('Api/SubCard')->subCardList(self::$merchant_id, 2, self::$store_id, $page, $limit);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 次卡列表 不限门店版
|
|
* @param string $keyword
|
|
* @param string $page
|
|
* @param string $limit
|
|
* @return array
|
|
*/
|
|
public function subCardList_v1()
|
|
{
|
|
// 接受数据
|
|
$page = intval(I('post.page'));
|
|
$limit = intval(I('post.limit'));
|
|
// 判断
|
|
if (!$page || !$limit) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取次卡
|
|
$SubCardApi = new \Api\Controller\SubCardController();
|
|
$res = $SubCardApi->subCardList(self::$merchant_id, 2, '', $page, $limit);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 展示门店购买卡包
|
|
* @param string $keyword
|
|
* @param string $page
|
|
* @param string $limit
|
|
* @return array
|
|
*/
|
|
public function cardBagList()
|
|
{
|
|
// 接受数据
|
|
$page = intval(I('post.page'));
|
|
$limit = intval(I('post.limit'));
|
|
// 判断
|
|
if (!$page || !$limit) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取卡包
|
|
$res = A('Api/SubCard')->cardBagList(self::$merchant_id, 2, self::$store_id, $page, $limit);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 展示门店购买卡包 不限门店版
|
|
* @param string $keyword
|
|
* @param string $page
|
|
* @param string $limit
|
|
* @return array
|
|
*/
|
|
public function cardBagList_v1()
|
|
{
|
|
// 接受数据
|
|
$page = intval(I('post.page'));
|
|
$limit = intval(I('post.limit'));
|
|
// 判断
|
|
if (!$page || !$limit) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取卡包
|
|
$SubCardApi = new \Api\Controller\SubCardController();
|
|
$res = $SubCardApi->cardBagList(self::$merchant_id, 2, '', $page, $limit);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
|
|
/**
|
|
* 次卡,卡包信息展示
|
|
* @param int $type 1.次卡 2.卡包
|
|
* @param int $card_id
|
|
* @return array
|
|
*/
|
|
public function cardInfo()
|
|
{
|
|
// 接受参数
|
|
$type = I('post.type');
|
|
$card_id = I('post.card_id');
|
|
// 判断
|
|
if (!in_array($type, array(1, 2)) || !$card_id) {
|
|
$res = array('status' => 0, 'msg' => '必要参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断类型
|
|
if ($type == 1) {
|
|
// 次卡
|
|
$res = A('Api/SubCard')->subCardInfo(self::$merchant_id, 2, $card_id, self::$store_id);
|
|
} else {
|
|
// 卡包
|
|
$res = A('Api/SubCard')->cardBagInfo(self::$merchant_id, 2, $card_id, self::$store_id);
|
|
}
|
|
$this->ajaxBack($res);
|
|
}
|
|
|
|
/**
|
|
* 下单,购买次卡
|
|
* @param int $type 类型 1.次卡 2.卡包
|
|
* @param int $card_id 次卡或卡包id
|
|
* @param int $pay_type 支付类型 1.微信
|
|
* @return array
|
|
*/
|
|
public function placeOrder()
|
|
{
|
|
// 接受数据
|
|
$type = I('post.type');
|
|
$card_id = I('post.card_id');
|
|
$pay_type = I('post.pay_type');
|
|
// 判断
|
|
if (!in_array($type, array(1, 2)) || !$card_id || !$pay_type) {
|
|
$res = array('status' => 0, 'msg' => '必要参数异常,请刷新重试');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断登录
|
|
if (!self::$uid || self::$user['login_state'] != 1) {
|
|
$res = array('status' => -1, 'msg' => '请先登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断会员
|
|
$vip_info = $this->getVipInfo();
|
|
if (!$vip_info['vid']) {
|
|
$res = array('status' => 0, 'msg' => '请先绑定会员卡');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 验证是否可以购买
|
|
$check_res = A('Api/SubCard')->checkCard(self::$merchant_id, self::$store_id, $vip_info['vid'], $card_id, $type, 4, 2);
|
|
if ($check_res['status'] == 0) {
|
|
$this->ajaxReturn($check_res);
|
|
}
|
|
$data = $check_res['data'];
|
|
$time = time();
|
|
// 支付方式
|
|
$PayOrder = D('RetailPayOrder'); // 流水
|
|
$PaySet = D('RetailPaySet'); // 支付设置
|
|
$p_cr = array();
|
|
switch ($pay_type) {
|
|
case 1:
|
|
$config_result = $PaySet->getFindMerchantConfig(self::$merchant_id, 3);
|
|
if ($config_result['status'] != 1) {
|
|
$res = array('status' => 0, 'msg' => $config_result['msg'] ? $config_result['msg'] : '暂无可用的支付模式');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$p_cr[$PayOrder::PAY_TYPE] = 4;
|
|
break;
|
|
}
|
|
// 数据 pay_order
|
|
$p_cr[$PayOrder::ORDER_TYPE] = 7;
|
|
$p_cr[$PayOrder::STORE_ID] = self::$store_id;
|
|
$p_cr[$PayOrder::TRADE_AMOUNT] = $data['money'];
|
|
$p_cr[$PayOrder::ADD_TIME] = $time;
|
|
$p_cr[$PayOrder::ORDER_STATE] = 'WAIT_BUYER_PAY';
|
|
$p_cr[$PayOrder::VID] = $vip_info['vid'];
|
|
$p_cr[$PayOrder::UID] = self::$uid;
|
|
$p_cr[$PayOrder::MERCHANT_ID] = self::$merchant_id;
|
|
// 下单 pay_order
|
|
$p_add = $PayOrder->addPayOrder($p_cr);
|
|
if (!$p_add) {
|
|
$res = array('status' => 0, 'msg' => '下单失败1');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 数据 card_order
|
|
$CardOrder = D('RetailCardOrder'); // 购买记录
|
|
$co_cr = array(
|
|
$CardOrder::MERCHANT_ID => self::$merchant_id,
|
|
$CardOrder::STORE_ID => self::$store_id,
|
|
$CardOrder::VIP_ID => $vip_info['vid'],
|
|
$CardOrder::TYPE => $type,
|
|
$CardOrder::CARD_ID => $card_id,
|
|
$CardOrder::STATE => 0,
|
|
$CardOrder::PAY_ORDER_ID => $p_add[$PayOrder::ID],
|
|
);
|
|
// 下单 card_order
|
|
$co_add = $CardOrder->addOrder($co_cr);
|
|
if (!$co_add) {
|
|
$res = array('status' => 0, 'msg' => '下单失败2');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 微信支付
|
|
if ($pay_type == 1) { // 微信支付
|
|
$notify_url = $this->REQUEST_URL . '/index.php/SmallProgramApi/WxPay/card_notify_url';
|
|
$notify_func = "Api/SubCard/updataCardOrder";
|
|
$wei_xin_result = A('SmallProgramApi/Pay')->getWxPayData_v1($p_add, $notify_url, $notify_func);
|
|
if ($wei_xin_result['status'] == 0) {
|
|
$this->ajaxReturn($wei_xin_result);
|
|
}
|
|
$res['pay_data'] = $wei_xin_result;
|
|
}
|
|
$res['status'] = 1;
|
|
$res['pay_order_id'] = $p_add[$PayOrder::ID];
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 判断是否支付成功
|
|
* @param int $pay_order_id
|
|
* @param int $vip_id
|
|
* @return array
|
|
*/
|
|
public function checkPay()
|
|
{
|
|
// 接收参数
|
|
$pay_order_id = I('post.pay_order_id');
|
|
if (!$pay_order_id) {
|
|
$res = array('status' => 0, 'msg' => '必要参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断会员
|
|
$vip_info = $this->getVipInfo();
|
|
if (!$vip_info['vid']) {
|
|
$res = array('status' => 0, 'msg' => '请先绑定会员卡');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 条件
|
|
$CardOrder = D('RetailCardOrder'); // 购买记录
|
|
$co_map = array(
|
|
$CardOrder::MERCHANT_ID => self::$merchant_id,
|
|
$CardOrder::STORE_ID => self::$store_id,
|
|
$CardOrder::VIP_ID => $vip_info['vid'],
|
|
$CardOrder::STATE => 1,
|
|
$CardOrder::PAY_ORDER_ID => $pay_order_id,
|
|
);
|
|
$card_order = $CardOrder->getFind($co_map);
|
|
if (empty($card_order)) {
|
|
$res = array('status' => 0, 'msg' => '正在支付');
|
|
} else {
|
|
$res = array('status' => 1, 'msg' => '支付成功');
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 用户次卡列表
|
|
* @return array
|
|
*/
|
|
public function userCardList()
|
|
{
|
|
// 接收参数
|
|
$page = intval(I('post.page'));
|
|
$limit = intval(I('post.limit'));
|
|
// 判断
|
|
if (!$page || !$limit) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断登录
|
|
if (!self::$uid) {
|
|
$res = array('status' => 0, 'msg' => '请先登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取会员
|
|
$vip_info = $this->getVipInfo();
|
|
if (!$vip_info['vid']) {
|
|
$res = array('status' => 0, 'msg' => '请先绑定会员卡');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 查询
|
|
$SubCardApi = new \Api\Controller\SubCardController();
|
|
$res = $SubCardApi->userCardList(self::$merchant_id, $vip_info['vid'], $page, $limit, '', false);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 删除次卡
|
|
* @param int $vip_card_id
|
|
*/
|
|
public function deleteCard()
|
|
{
|
|
// 接收数据
|
|
$vip_card_id = I('post.vip_card_id');
|
|
// 判断
|
|
if (!$vip_card_id) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断登录
|
|
if (!self::$uid) {
|
|
$res = array('status' => 0, 'msg' => '请先登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取会员
|
|
$vip_info = $this->getVipInfo();
|
|
if (!$vip_info['vid']) {
|
|
$res = array('status' => 0, 'msg' => '请先绑定会员卡');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$res = A('Api/SubCard')->deleteCard(self::$merchant_id, $vip_info['vid'], $vip_card_id);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 用户次卡
|
|
* @param int $card_id
|
|
*/
|
|
public function userCardInfo()
|
|
{
|
|
// 接收数据
|
|
$vip_card_id = I('post.vip_card_id');
|
|
// 判断
|
|
if (!$vip_card_id) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断登录
|
|
if (!self::$uid) {
|
|
$res = array('status' => 0, 'msg' => '请先登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取会员
|
|
$vip_info = $this->getVipInfo();
|
|
if (!$vip_info['vid']) {
|
|
$res = array('status' => 0, 'msg' => '请先绑定会员卡');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$res = A('Api/SubCard')->userCardInfo(self::$merchant_id, $vip_info['vid'], $vip_card_id);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 使用次卡,获取使用码
|
|
*/
|
|
public function useCard()
|
|
{
|
|
// 接收数据
|
|
$vip_card_id = I('post.vip_card_id');
|
|
// 判断
|
|
if (!$vip_card_id) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断登录
|
|
if (!self::$uid) {
|
|
$res = array('status' => 0, 'msg' => '请先登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 获取会员
|
|
$vip_info = $this->getVipInfo();
|
|
if (!$vip_info['vid']) {
|
|
$res = array('status' => 0, 'msg' => '请先绑定会员卡');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 使用码
|
|
$res = A('Api/SubCard')->useCard(self::$merchant_id, $vip_info['vid'], $vip_card_id);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
} |