355 行
12 KiB
PHP
可执行文件
355 行
12 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace CashierApi\Controller;
|
|
|
|
use CashierApi\Business\BuySubCard;
|
|
use CashierApi\Business\QueryPayOrder;
|
|
use Think\Controller;
|
|
|
|
//[1.7.14]
|
|
|
|
/**
|
|
* 次卡
|
|
*/
|
|
class SubCardController extends BaseController
|
|
{
|
|
/**
|
|
* 展示门店购买次卡
|
|
* @param string $keyword
|
|
* @param string $page
|
|
* @param string $limit
|
|
* @return array
|
|
*/
|
|
public function subCardList()
|
|
{
|
|
// 接受数据
|
|
$keyword = I('post.keyword');
|
|
$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, 1, self::$store_id, $page, $limit, $keyword);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 展示门店购买卡包
|
|
* @param string $keyword
|
|
* @param string $page
|
|
* @param string $limit
|
|
* @return array
|
|
*/
|
|
public function cardBagList()
|
|
{
|
|
// 接受数据
|
|
$keyword = I('post.keyword');
|
|
$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, 1, self::$store_id, $page, $limit, $keyword);
|
|
$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);
|
|
}
|
|
$SubCardApi = new \Api\Controller\SubCardController();
|
|
// 判断类型
|
|
if ($type == 1) {
|
|
// 次卡
|
|
$res = $SubCardApi->subCardInfo(self::$merchant_id, 1, $card_id, self::$store_id);
|
|
} else {
|
|
// 卡包
|
|
$res = $SubCardApi->cardBagInfo(self::$merchant_id, 1, $card_id, self::$store_id);
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 展示卡包次卡详情
|
|
* @param int $bag_id 卡包id
|
|
* @return array
|
|
*/
|
|
public function cardBagDetails()
|
|
{
|
|
// 接受参数
|
|
$bag_id = I('post.bag_id');
|
|
if (!$bag_id) {
|
|
$res = array('status' => 0, 'msg' => '必要参数bag_id缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$res = A('Api/SubCard')->cardBagDetails(self::$merchant_id, $bag_id);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 下单,购买次卡
|
|
* @param int $vip_id 会员id
|
|
* @param int $type 类型 1.次卡 2.卡包
|
|
* @param int $card_id 次卡或卡包id
|
|
* @param int $pay_type 支付类型 1.现金 2.在线 5.其他支付
|
|
* @param int $pay_code 付款码
|
|
* @param int $other_pay_id 付款码
|
|
* @return array
|
|
*/
|
|
public function placeOrder()
|
|
{
|
|
// 接受数据
|
|
$vip_id = I('post.vip_id');
|
|
$type = I('post.type');
|
|
$card_id = I('post.card_id');
|
|
$pay_type = I('post.pay_type');
|
|
$pay_code = I('post.pay_code');
|
|
$other_pay_id = I('post.other_pay_id');
|
|
// 判断会员登录
|
|
if (!$vip_id) {
|
|
$res = array('status' => 0, 'msg' => '请先登录会员');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 判断
|
|
if (!in_array($type, array(1, 2)) || !$card_id || !in_array($pay_type, array(1, 2, 5))) {
|
|
$res = array('status' => 0, 'msg' => '必要参数异常,请刷新重试');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 核实会员信息
|
|
$Vip = D('RetailVip'); // 会员
|
|
$v_map = array(
|
|
$Vip::ID => $vip_id,
|
|
$Vip::MERCHANT_ID => self::$merchant_id,
|
|
$Vip::STATUS => 1,
|
|
);
|
|
// 查询会员信息
|
|
$vip_info = $Vip->getFind($v_map);
|
|
// 判断会员信息
|
|
if (empty($vip_info)) {
|
|
$res = array('status' => 0, 'msg' => '请核对会员信息是否正确');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
//判断其他支付
|
|
if ($pay_type == 5) {
|
|
$MerchantConfigModel = D('RetailMerchantConfig');
|
|
$merchantSet = $MerchantConfigModel->getFind(array($MerchantConfigModel::MERCHANT_ID => self::$merchant_id));
|
|
if (!empty($merchantSet) && $merchantSet[$MerchantConfigModel::OTHER_PAY_STATE] != 1) {
|
|
$res = array('status' => 0, 'msg' => '商家已关闭其他支付,请重新登录');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$OtherPayModel = D('RetailOtherPay');
|
|
if (!empty($other_pay_id)) {
|
|
$oMap1 = array(
|
|
$OtherPayModel::STATE => 1,
|
|
$OtherPayModel::STATUS => 1,
|
|
$OtherPayModel::ID => $other_pay_id,
|
|
$OtherPayModel::MERCHANT_ID => self::$merchant_id
|
|
);
|
|
$otherPay = $OtherPayModel->getFind($oMap1);
|
|
if (empty($otherPay)) {
|
|
$res = array('status' => 0, 'msg' => '该支付方式不存在');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
} else {
|
|
$oMap2 = array(
|
|
$OtherPayModel::STATE => 1,
|
|
$OtherPayModel::STATUS => 1,
|
|
$OtherPayModel::MERCHANT_ID => self::$merchant_id
|
|
);
|
|
$otherPay = $OtherPayModel->getCount($oMap2);
|
|
if (!empty($otherPay)) {
|
|
$res = array('status' => 0, 'msg' => '请选择其他支付');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
}
|
|
// 验证是否可以购买
|
|
$check_res = A('Api/SubCard')->checkCard(self::$merchant_id, self::$store_id, $vip_id, $card_id, $type, 4, 1);
|
|
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:
|
|
$p_cr[$PayOrder::PAY_TYPE] = 3;
|
|
break;
|
|
case 2:
|
|
// 接收支付码
|
|
if (!$pay_code || strlen($pay_code) != 18) {
|
|
$res = array('status' => 0, 'msg' => '请输入正确的付款码');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
// 处理支付码
|
|
$num = substr($pay_code, 0, 2);
|
|
if ($num >= 25 && $num <= 30) {
|
|
// 支付宝
|
|
$p_cr[$PayOrder::PAY_TYPE] = 2;
|
|
} else if ($num >= 10 && $num <= 15) {
|
|
// 微信
|
|
$p_cr[$PayOrder::PAY_TYPE] = 1;
|
|
} else {
|
|
$res = array('status' => 0, 'msg' => '请输入正确的付款码');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$p_cr[$PayOrder::CODE] = $pay_code;
|
|
break;
|
|
case 5:
|
|
$p_cr[$PayOrder::PAY_TYPE] = 7;
|
|
if (!empty($other_pay_id)) {
|
|
$p_cr[$PayOrder::OTHER_PAY_ID] = $other_pay_id;
|
|
}
|
|
break;
|
|
}
|
|
// 微信、支付宝获取支付模式
|
|
$Merchant = D('RetailMerchant'); // 商户
|
|
$Store = D('RetailStore'); // 门店
|
|
$config = array();
|
|
if ($p_cr[$PayOrder::PAY_TYPE] == 1 || $p_cr[$PayOrder::PAY_TYPE] == 2) {
|
|
$pay_mode = $PaySet->getFindMerchantConfig(self::$merchant_id, $p_cr[$PayOrder::PAY_TYPE]);
|
|
if ($pay_mode['status'] != 1) {
|
|
$res = array('status' => 0, 'msg' => $pay_mode['msg'] ? $pay_mode['msg'] : '暂无可用的支付模式');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$config = $pay_mode['config'];
|
|
$config['body'] = self::$merchant[$Merchant::NAME] . '-' . self::$store[$Store::STORE_NAME];
|
|
$p_cr[$PayOrder::M_PAY_TYPE] = $pay_mode['m_pay_type'];
|
|
}
|
|
// 数据 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_id;
|
|
$p_cr[$PayOrder::CASHIER_ID] = self::$cashier_id;
|
|
$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_id,
|
|
$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 || $pay_type == 5) {
|
|
// 现金
|
|
$p_up = array(
|
|
$PayOrder::ORDER_STATE => 'SUCCESS',
|
|
$PayOrder::TRADE_DATE => $time,
|
|
);
|
|
$p_save = $PayOrder->updateOrder(array($PayOrder::ID => $p_add[$PayOrder::ID]), $p_up);
|
|
if (!$p_save) {
|
|
$pay_res = array('status' => 0, 'msg' => '数据库发成故障,支付流水表更新失败,请重新支付');
|
|
}
|
|
} else {
|
|
// 在线支付
|
|
if ($p_add[$PayOrder::M_PAY_TYPE] == 3) {
|
|
//新大陆支付
|
|
$pay_res = A('Pay/PayContinent')->toContinentPay_v3($p_add, $config['body']);
|
|
} else {
|
|
if ($p_add[$PayOrder::PAY_TYPE] == 1) {
|
|
//微信
|
|
$pay_res = A('Pay/NewWxPay')->toWxPay_v2($p_add, $config);
|
|
} else if ($p_add[$PayOrder::PAY_TYPE] == 2) {
|
|
//支付宝
|
|
$pay_res = A('Pay/NewAliPay')->toAliPay_v2($p_add, $config);
|
|
} else {
|
|
$pay_res = array('status' => 0, 'msg' => '未知的支付类型');
|
|
}
|
|
}
|
|
}
|
|
// 判断支付
|
|
if (!empty($pay_res) && $pay_res['status'] == 0) {
|
|
$this->ajaxReturn($pay_res);
|
|
}
|
|
// 更新订单
|
|
$res = A('Api/SubCard')->updataCardOrder($p_add);
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 商品
|
|
*/
|
|
public function cardGoods()
|
|
{
|
|
// 接受数据
|
|
$type = I('post.type');
|
|
$card_id = I('post.card_id');
|
|
// 判断
|
|
if (!array($type, array(1, 2)) || !$card_id) {
|
|
$res = array('status' => 0, 'msg' => '参数缺失');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$res = A('Api/SubCard')->cardGoods($type, $card_id, self::$merchant_id, self::$store_id, 1);
|
|
|
|
print_r($res);
|
|
die;
|
|
}
|
|
|
|
/**
|
|
* 购买次卡 2020-10-23
|
|
*/
|
|
public function placeOrder_v1()
|
|
{
|
|
$data = I('post.');
|
|
$data['merchant_id'] = self::$merchant_id;
|
|
$data['store_id'] = self::$store_id;
|
|
$data['cashier_id'] = self::$cashier_id;
|
|
$data['merchantInfo'] = self::$merchant;
|
|
$data['storeInfo'] = self::$store;
|
|
$SubCardClass = new BuySubCard();
|
|
$result = $SubCardClass->placeSubCardOrder($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/**
|
|
* 查询订单
|
|
*/
|
|
public function queryOrder()
|
|
{
|
|
$data = I('post.');
|
|
$data['merchant_id'] = self::$merchant_id;
|
|
$QueryPayClass = new QueryPayOrder();
|
|
$result = $QueryPayClass->cardQueryOrder($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
} |