3827 行
174 KiB
PHP
可执行文件
3827 行
174 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Pay\Controller;
|
||
|
||
use Think\Controller;
|
||
|
||
use Pay\Library\Cloud\CloudAliPay as CloudAliPayCtrl;
|
||
use Pay\Library\Cloud\CloudWxPay as CloudWxPayCtrl;
|
||
//[1.5.43]
|
||
class PayController extends BaseController
|
||
{
|
||
public function placeVipOrder()
|
||
{
|
||
$storeid = I('post.storeid');
|
||
$code = I('post.code');
|
||
$money = I('post.money');
|
||
$adminid = I('post.adminid');
|
||
if (empty($storeid) || empty($code) || empty($money) || empty($adminid)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (!empty($store)) {
|
||
$PayOrderModel = D('PayOrder');
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$status = true;
|
||
$pay_type = 2;
|
||
$Order['pay_type'] = $pay_type;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$status = true;
|
||
$pay_type = 1;
|
||
$Order['pay_type'] = $pay_type;
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = "请扫描正确的二维码";
|
||
}
|
||
if ($status) { //创建订单
|
||
$Order ['order_type'] = 2;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['trade_amount'] = $money;
|
||
$Order ['cdate'] = time();
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['state'] = 0;
|
||
$Order ['code'] = $code;
|
||
$Order ['adminid'] = $adminid;
|
||
|
||
$orderid = $PayOrderModel->addOrder($Order);
|
||
if ($orderid) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderid);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderid), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
switch ($pay_type) {
|
||
case 1:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPay($orderid, $out_trade_no, $code, $storeid, $money);
|
||
break;
|
||
case 2:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPay($orderid, $out_trade_no, $code, $storeid, $money);
|
||
break;
|
||
}
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '订单创建失败请重试';
|
||
}
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '门店不存在或被禁用';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
//购买商品下单支付
|
||
public function placeOrder()
|
||
{
|
||
$storeid = I('post.storeid');
|
||
$adminid = I('post.adminid');
|
||
$code = I('post.code');
|
||
$trade_amount = I('post.money');
|
||
$merchantid = I('post.merchantid');
|
||
$orderInfo = $_POST['orderInfo'];
|
||
if (empty($storeid) || empty($code) || empty($adminid) || empty($trade_amount)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (!empty($store)) {
|
||
$PayOrderModel = D('PayOrder');
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$pay_type = 2;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$pay_type = 1;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order['pay_type'] = $pay_type;
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['trade_amount'] = $trade_amount;
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
|
||
$orderid = $PayOrderModel->addOrder($Order);
|
||
if ($orderid) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderid);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderid), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
switch ($pay_type) {
|
||
case 1:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPay($orderid, $out_trade_no, $code, $storeid, $Order ['trade_amount'], $adminid, $merchantid, $orderInfo);
|
||
break;
|
||
case 2:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPay($orderid, $out_trade_no, $code, $storeid, $Order ['trade_amount'], $adminid, $merchantid, $orderInfo);
|
||
break;
|
||
}
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
}
|
||
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
//生成订单流水号
|
||
public function createOrderTradeNo($orderid)
|
||
{
|
||
$left = date('Ymd', time());
|
||
$orderid = (string)$orderid;
|
||
if (strlen($orderid) < 6) {
|
||
$orderid = str_pad($orderid, 6, "0", STR_PAD_LEFT);
|
||
} else if (strlen($orderid) > 6) {
|
||
$orderid = substr($orderid, -5, 5);
|
||
}
|
||
$l = substr(time(), 0, 4);
|
||
$str = $left . $l . $orderid;
|
||
return $str;
|
||
}
|
||
|
||
|
||
//退款
|
||
public function refund()
|
||
{
|
||
$storeid = I('post.storeid');
|
||
$adminid = I('post.adminid');
|
||
$out_trade_no = I('post.out_trade_no');
|
||
$goods_info = $_POST['goods_info'];
|
||
if (empty($storeid) || empty($adminid) || empty($out_trade_no) || empty($goods_info)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$PayOrder = D('PayOrder');
|
||
$Order = $PayOrder->getFind(array('out_trade_no' => $out_trade_no, 'storeid' => $storeid));
|
||
if (empty($Order)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单不存在';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$refundCount = $PayOrder->getCount(array('pid' => $Order['id']));
|
||
if ($refundCount >= 10) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该订单退款次数已达上限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$allMoney = 0;
|
||
$allIntegral = 0;
|
||
$tempGoods = json_decode($goods_info, true);
|
||
$goods = json_decode($Order['goods_info'], true);
|
||
foreach ($tempGoods as $val) {
|
||
foreach ($goods as &$v) {
|
||
if ($val['goods_id'] == $v['id']) {
|
||
if (intval($val['agoods_count']) <= intval($v['agoods_count'] - $v['refund_num'])) {
|
||
$allMoney += ($v['unit_price'] * $val['agoods_count']);
|
||
if ($v['type'] == 2) {
|
||
$allIntegral += $v['unit_integral'] * $val['agoods_count'];
|
||
}
|
||
$v['refund_num'] += $val['agoods_count'];
|
||
continue;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该订单已全退款';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!$allMoney) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '商品退款信息错误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$item = array(
|
||
'refund_money' => $allMoney,
|
||
'integral' => $allIntegral,
|
||
'adminid' => $adminid,
|
||
'original_order' => $goods,
|
||
'refund_goods_info' => $tempGoods,
|
||
'out_refund_no' => 're' . $this->createOrderTradeNo($Order['id'])
|
||
);
|
||
|
||
switch (intval($Order['pay_type'])) {
|
||
case 1:
|
||
A('Pay/WxPay')->refund($storeid, $Order['trade_no'], $item);
|
||
break;
|
||
case 2:
|
||
A('Pay/AliPay')->refund($storeid, $Order['trade_no'], $item);
|
||
break;
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 暂未完成。 差新大陆。。
|
||
* 10-29 oem 退款 微信 支付宝 退款。。。。。
|
||
* goods_info id是商品sell表的id agoods_count是商品的数量数组类型 "[{"id":"36","goods_id":1,"price":10,"agoods_count":"1"},{"id":"37","agoods_count":"1"}]"
|
||
*
|
||
* */
|
||
public function oemrefund()
|
||
{
|
||
$storeid = I('post.storeid');
|
||
$adminid = I('post.adminid');
|
||
$out_trade_no = I('post.out_trade_no');
|
||
$goods_info = $_POST['goods_info'];
|
||
if (empty($storeid) || empty($adminid) || empty($out_trade_no) || empty($goods_info)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$PayOrder = D('PayOrder');
|
||
$Order = $PayOrder->getFind(array('out_trade_no' => $out_trade_no, 'storeid' => $storeid));
|
||
if (empty($Order)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单不存在';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$refundCount = $PayOrder->getCount(array('pid' => $Order['id']));
|
||
if ($refundCount >= 10) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该订单退款次数已达上限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$allMoney = 0;
|
||
$tempGoods = json_decode($goods_info, true);
|
||
// 历史订单号
|
||
$oldorderid = M('retail_bill')->where(array('pay_orderid' => $Order['id']))->getField('order_id');
|
||
$sellids = M('retail_bill')->where(array('pay_orderid' => $Order['id']))->getField('sellid');
|
||
$sellids = $sellids ? $sellids : array(0);
|
||
$goods = M('retail_sell')->where(array('id' => $sellids))->select();
|
||
foreach ($tempGoods as $val) {
|
||
foreach ($goods as &$v) {
|
||
if ($val['goods_id'] == $v['goods_id']) {
|
||
if (round($val['agoods_count'], 2) <= round($v['num'] - $v['refund_num'], 2)) {
|
||
$allMoney += ($v['price'] * $val['agoods_count']);
|
||
$v['refund_num'] += $val['agoods_count'];
|
||
continue;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该订单已全退款';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (!$allMoney) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '商品退款信息错误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$item = array(
|
||
'refund_money' => $allMoney,
|
||
'adminid' => $adminid,
|
||
'original_order' => $goods,
|
||
'refund_goods_info' => $tempGoods,
|
||
'out_refund_no' => 're' . $this->createOrderTradeNo($Order['id']),
|
||
'oldorderid' => $oldorderid,
|
||
'storeid' => $storeid
|
||
);
|
||
|
||
switch (intval($Order['pay_type'])) {
|
||
case 1:
|
||
A('Pay/WxPay')->oemrefund($storeid, $Order['trade_no'], $item);
|
||
break;
|
||
case 2:
|
||
A('Pay/AliPay')->oemrefund($storeid, $Order['trade_no'], $item);
|
||
break;
|
||
}
|
||
}
|
||
|
||
//小程序退款 2019-1-05 $fee_state 1退还配送费 2不退还配送费
|
||
public function XcxRefund()
|
||
{
|
||
$id = I('post.id');
|
||
$adminid = I('post.adminid');
|
||
$storeid = I('post.storeid');
|
||
$fee_state = I('post.fee_state');
|
||
$fee_state = $fee_state ? $fee_state : 1;
|
||
if (empty($storeid) || empty($id) || empty($adminid)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$cashier = D('Cashier')->getFind(array('id' => $adminid, 'storeid' => $storeid));
|
||
if (empty($cashier)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员不存在';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$map = array(
|
||
'id' => $id,
|
||
'paytype' => array('in', '5,6,8'),
|
||
'type' => 1,
|
||
'status' => array('in', '1,3'),
|
||
'refund_status' => 1,
|
||
'pay_state' => 1
|
||
);
|
||
$BillModel = D('Bill');
|
||
$billOrder = $BillModel->getFind($map);
|
||
if (empty($billOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单不存在或已退款';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($billOrder['order_genre'] == 2 || $billOrder['order_genre'] == 3) {
|
||
A('Sellapi/GroupOrder')->GroupAndSecKillRefund_v1($billOrder['id'], $adminid, $billOrder['merchantid'], $billOrder, $fee_state);
|
||
} else {
|
||
$res = A('Xcxapi/Pay')->XcxRefund($billOrder, $adminid, $fee_state);
|
||
if ($res['status'] == 1) {
|
||
//退款成功,修改订单
|
||
$SellModel = D('Sell');
|
||
$PayOrderModel = D('PayOrder');
|
||
$GoodsModel = D('Goods');
|
||
$SkuGoodsModel = D('SkuGoods');
|
||
|
||
$sell_ids = array();
|
||
$sellOrderList = $SellModel->getSelect(array('id' => array('in', $billOrder['sellid'])));
|
||
foreach ($sellOrderList as $val) {
|
||
if ($billOrder['order_type'] == 1) {
|
||
//老版小程序退款
|
||
$SellModel->updateOrder(array('id' => $val['id']), array('is_refund' => 2, 'refund_num' => $val['num']));
|
||
unset($val['id']);
|
||
$val['refund_num'] = $val['num'];
|
||
$val['status'] = 2;
|
||
$val['pay_state'] = 1;
|
||
$val['is_refund'] = 3;
|
||
$add_id = $SellModel->addOrder($val);
|
||
$sell_ids[] = $add_id;
|
||
} else {
|
||
$oldSell = $SellModel->getFind(array('id' => $val['sell_id']));
|
||
$save = array(
|
||
'is_refund' => 2,
|
||
'pay_state' => 1,
|
||
'refund_num' => round($oldSell['refund_num'] + $val['num'], 3),
|
||
'wait_refund_num' => 0
|
||
);
|
||
$SellModel->updateOrder(array('id' => $val['sell_id']), $save);
|
||
}
|
||
if (!empty($val['skuinfo'])) {
|
||
$num = $val['num'];
|
||
$sku = json_decode($val['skuinfo'], true);
|
||
M("retail_goodsku")->where(array("id" => $sku[0]['id'], "status" => 2))->setInc('num', $val['num']);//需要修改规格库存
|
||
} else if (!empty($val['sku_json_info'])) {
|
||
$sku = json_decode($val['sku_json_info'], true);
|
||
$num = $sku['sku_num'] * $val['num'];
|
||
$SkuGoodsModel->toSetInc(array("id" => $sku['id']), 'goods_num', $val['num']);//需要修改规格库存
|
||
} else {
|
||
$num = $val['num'];
|
||
}
|
||
$less_stock = $GoodsModel->toSetDec(array('id' => $val['goods_id']), 'sell_num', $num); //销售数量
|
||
//加入库存明细
|
||
//根据商品id查询出商品现有库存(发生操作前)
|
||
$now_quantity = $GoodsModel->getFindField(array('id' => $val['goods_id']), 'goods_num');
|
||
$log['original_stock'] = $now_quantity; //商品原库存
|
||
$log['do_num'] = $num; //需要操作的数量
|
||
$log['type'] = 1; //2为减库存 1添加
|
||
$log['goods_id'] = $val['goods_id']; //商品id
|
||
$log['sell_id'] = $add_id; //sell表id
|
||
$log['storeid'] = $storeid; //门店id
|
||
$log['present_stock'] = $now_quantity + $num; //现库存
|
||
$log['merchantid'] = $billOrder['merchantid']; //商户id
|
||
$log['addtime'] = time();
|
||
$log['supplier_id'] = -3; // 退货入库
|
||
$log['remark'] = '退款增加';
|
||
M('retail_quantity_logs')->add($log);
|
||
$GoodsModel->toSetInc(array('id' => $val['goods_id']), 'goods_num', $num);
|
||
}
|
||
|
||
if ($billOrder['order_type'] == 1) {
|
||
//老版小程序退款
|
||
if ($billOrder['isneedsend'] == 2) {
|
||
$billOrder['fee_state'] = $fee_state;
|
||
if ($fee_state == 2) {
|
||
$billOrder['allmoney'] = round($billOrder['allmoney'] - $billOrder['distribution_fee'], 2);
|
||
}
|
||
}
|
||
$billOrder['refund_num'] = $billOrder['order_id'];
|
||
$billOrder['order_id'] = $this->createOrderTradeNo($billOrder['id']);
|
||
unset($billOrder['id']);
|
||
unset($billOrder['addtime']);
|
||
$billOrder['sellid'] = implode(',', $sell_ids);
|
||
$billOrder['order_type'] = 2;
|
||
$billOrder['refund_money'] = $billOrder['allmoney'];
|
||
$billOrder['refund_status'] = 2;
|
||
$billOrder['addtime'] = time();
|
||
if (!empty($res['refund_no'])) {
|
||
$billOrder['refund_no'] = $res['refund_no'];
|
||
}
|
||
$billOrder['admin_id'] = $adminid;
|
||
$new_bill_id = $BillModel->addOrder($billOrder);
|
||
$order_id = $this->createOrderTradeNo($new_bill_id);
|
||
$BillModel->updateOrder(array('id' => $new_bill_id), array('order_id' => $order_id));
|
||
$SellModel->updateOrder(array('id' => array('in', $sell_ids)), array('bill_id' => $new_bill_id));
|
||
} else {
|
||
//新版退款
|
||
$new_bill_id = $billOrder['id'];
|
||
$oldBill = $BillModel->getFind(array('order_id' => strval($billOrder['refund_num'])));
|
||
$refund_money = round($oldBill['refund_money'] + $billOrder['allmoney'], 2);
|
||
$save = array(
|
||
'refund_status' => 2,
|
||
'refund_money' => $refund_money,
|
||
'fee_state' => $fee_state
|
||
);
|
||
$BillModel->updateOrder(array('id' => $oldBill['id']), $save);
|
||
}
|
||
$PayOrderModel->updateOrder(array('id' => array('in', $res['pay_order_id'])), array('bill_id' => $new_bill_id));//更新pay_order表
|
||
$save = array(
|
||
'refund_status' => 2,
|
||
'refund_money' => $billOrder['allmoney'],
|
||
'cancel_time' => 1,
|
||
'fee_state' => $fee_state
|
||
);
|
||
$update = $BillModel->updateOrder(array('id' => $id), $save);
|
||
if ($new_bill_id && $update) {
|
||
if ($billOrder['user_upgrade'] == 2 && $billOrder['type'] == 1 && !empty($billOrder['uid'])) {
|
||
$this->downgrade($billOrder['uid']);
|
||
}
|
||
$result['status'] = 1;
|
||
$result['msg'] = '退款成功';
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '退款失败';
|
||
}
|
||
} else {
|
||
$result = $res;
|
||
$result["status"] = 0;
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* plus会员版本 商城退款降级
|
||
*/
|
||
public function downgrade($uid)
|
||
{
|
||
$plus_info = M('retail_plus_vip')->where(array('xcx_vip_id' => $uid))->find();
|
||
if ($plus_info) {
|
||
$data['plus_vip_id'] = array('exp', null);
|
||
$data['type'] = 1;
|
||
M('retail_xcxvip')->where(array('id' => $plus_info['xcx_vip_id']))->save($data);
|
||
if (!empty($plus_info['vip_id'])) {
|
||
$vip['plus_id'] = 0;
|
||
$vip['plus_type'] = 3;
|
||
$vip['plus_state'] = 2;
|
||
M('retail_vip')->where(array('id' => $plus_info['vip_id']))->save($vip);
|
||
}
|
||
M('retail_plus_vip')->where(array('id' => $plus_info['id']))->delete();
|
||
}
|
||
}
|
||
//10-31
|
||
//购买商品下单支付
|
||
public function placeOrderbackups()
|
||
{
|
||
$guideid = I('post.guideid');//导购员
|
||
$storeid = I('post.storeid');
|
||
$adminid = I('post.adminid');
|
||
$code = I('post.code');
|
||
$merchantid = I('post.merchantid');
|
||
$orderInfo = $_POST['orderInfo'];
|
||
|
||
//2018-10-30
|
||
$vid = I("post.vid");
|
||
$cardNum = I("post.cardnum");
|
||
$discount = I("post.discount");
|
||
$couponid = I("post.mcouponid");//会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$couponMoney = I("post.reducemoney");//使用优惠券时减免的金额,没有则为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
|
||
if (empty($storeid) || empty($code) || empty($adminid)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (!empty($store)) {
|
||
$PayOrderModel = D('PayOrder');
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$pay_type = 2;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$pay_type = 1;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$config = D('Payset')->getFindConfig($storeid);//获取商户微信配置信息
|
||
if (empty($config)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付参数未配置';
|
||
$this->ajaxReturn($data);
|
||
} else if ($config['status'] == 1) {
|
||
//普通商户模式
|
||
$Order ['m_pay_type'] = 1;
|
||
} else if ($config['status'] == 3) {
|
||
//服务商模式
|
||
$Order ['m_pay_type'] = 2;
|
||
} else if ($config['status'] == 4) {
|
||
//新大陆模式
|
||
$Order ['m_pay_type'] = 3;
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付配置有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
//创建订单
|
||
$Order ['pay_type'] = $pay_type;
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
|
||
$orderid = $PayOrderModel->addOrder($Order);
|
||
if ($orderid) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderid);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderid), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $orderInfo,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' > 3,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'discount' => $discount,
|
||
'cardnum' => $cardNum,
|
||
'couponMoney' => $couponMoney,
|
||
'exchange_money' => $couponMoney,
|
||
'types' => '',
|
||
'small_changes_money' => $small_changes_money,
|
||
'couponid' => $couponid,
|
||
'guideid' => $guideid,
|
||
'order_id' => $out_trade_no,
|
||
'pay_orderid' => $orderid,
|
||
'm_pay_type' => $Order['m_pay_type']
|
||
);
|
||
$create = A("Sellapi/Pay")->createSellOrder($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderid), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderid;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($pay_type) {
|
||
case 1:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 2:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
* 2018-11-24 新下单支付接口 统一支付
|
||
* */
|
||
protected function newPlaceOrderPay_v1()
|
||
{
|
||
$guideid = I('post.guideid');//导购员
|
||
$storeid = I('post.storeid');
|
||
$adminid = I('post.adminid');
|
||
$code = I('post.code');
|
||
$merchantid = I('post.merchantid');
|
||
$orderInfo = $_POST['orderInfo'];
|
||
|
||
$payType = I('post.payType');
|
||
$vid = I("post.vid");
|
||
$cardNum = I("post.cardnum");
|
||
$discount = I("post.discount");
|
||
$couponid = I("post.mcouponid"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$couponMoney = I("post.reducemoney"); //使用优惠券时减免的金额,没有则为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($storeid) || empty($code) || empty($adminid)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
//微信支付
|
||
//支付宝
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$pay_type = 2;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$pay_type = 1;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$config = D('Payset')->getFindConfig($storeid);//获取商户微信配置信息
|
||
if (empty($config)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付参数未配置';
|
||
$this->ajaxReturn($data);
|
||
} else if ($config['status'] == 1) {
|
||
//普通商户模式
|
||
$Order ['m_pay_type'] = 1;
|
||
} else if ($config['status'] == 3) {
|
||
//服务商模式
|
||
$Order ['m_pay_type'] = 2;
|
||
} else if ($config['status'] == 4) {
|
||
//新大陆模式
|
||
$Order ['m_pay_type'] = 3;
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付配置有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
$Order['pay_type'] = 5;
|
||
//银行卡支付 其他支付
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
|
||
$orderid = $PayOrderModel->addOrder($Order);
|
||
if ($orderid) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderid);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderid), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $orderInfo,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'discount' => $discount,
|
||
'cardnum' => $cardNum,
|
||
'couponMoney' => $couponMoney,
|
||
'exchange_money' => $couponMoney,
|
||
'small_changes_money' => $small_changes_money,
|
||
'couponid' => $couponid,
|
||
'guideid' => $guideid,
|
||
'order_id' => $out_trade_no,
|
||
'pay_orderid' => $orderid,
|
||
'm_pay_type' => $Order['m_pay_type']
|
||
);
|
||
$create = A("Sellapi/Pay")->createBillOrder_v1($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderid), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderid;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($pay_type) {
|
||
case 1:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 2:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* 2018-11-28 会员充值
|
||
* */
|
||
public function placeVipRechargeOrder_v1()
|
||
{
|
||
$money = I('post.money'); //充值金额
|
||
$adminid = I('post.adminid'); //收银员id
|
||
$vid = I('post.vid'); //会员id
|
||
$storeid = I('post.storeid'); //门店id
|
||
$pay_type = I('post.pay_type'); //支付类型 1现金 2微信支付宝 3支付宝刷脸支付
|
||
$code = I('post.code'); //微信支付宝支付时必传
|
||
$user_type = I('post.user_type'); //现金支付时传 1收银员 2店长
|
||
$rechargecode = I('post.rechargecode'); //收银员充值密码
|
||
$username = I('post.username'); //店长登录名
|
||
$password = I('post.password'); //店长登录密码
|
||
$recharge_dis = I('post.recharge_dis'); //充值优惠id
|
||
$custom_givemoney = I('post.custom_givemoney');// 自定义赠送金额
|
||
$faceToken = I('post.faceToken'); //刷脸支付token
|
||
if (empty($storeid) || empty($money) || empty($adminid) || empty($vid)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
if (!empty($custom_givemoney) && $custom_givemoney != 0 && $custom_givemoney != "") { //自定义赠送
|
||
if ($custom_givemoney < 0 || $custom_givemoney > $money) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '赠送金额有误或不能大于充值金额';
|
||
$this->ajaxReturn($data);
|
||
exit;
|
||
}
|
||
$customviprecharge = M('retail_cashier')->where(array('id' => $adminid))->getField('customviprecharge');
|
||
if ($customviprecharge == 1) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '收银员暂无自定义赠送金额权限';
|
||
$this->ajaxReturn($data);
|
||
exit;
|
||
}
|
||
}
|
||
$vip = M('retail_vip')->where(array('id' => $vid, 'status' => 1))->find();
|
||
if (empty($vip)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '会员账户异常';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '门店状态异常';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$recharge = '';
|
||
if (!empty($recharge_dis)) {
|
||
$canrecharge = D('Vip')->checkRecharge($vid, $recharge_dis);
|
||
if (!$canrecharge) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '充值优惠信息有误,建议刷新后操作';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$recharge = M('vip_recharge')->where(array('id' => $recharge_dis, 'merchantid' => $store['merchantid']))->find();
|
||
if (empty($recharge) || $money < $recharge['money']) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '充值优惠信息有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
if ($pay_type == 1) {
|
||
if (empty($user_type)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数user_type';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
if ($user_type == 1) {
|
||
if (empty($rechargecode)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数rechargecode';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else if ($user_type == 2) {
|
||
if (empty($username) || empty($password)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数店长登录信息';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '参数user_type有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$res = $this->verifyUserPass($user_type, $storeid, $adminid, $rechargecode, $username, $password);
|
||
if ($res['status'] != 1) {
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$Order['pay_type'] = 3;
|
||
} else if ($pay_type == 2 || $pay_type == 3) {
|
||
if (empty($code) && empty($faceToken)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数code或faceToken';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
if ($pay_type == 2) {
|
||
$where['storeid'] = $storeid;
|
||
$where['code'] = $code;
|
||
$historyOrder = $PayOrderModel->getFind($where);
|
||
if (!empty($historyOrder)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$Order['pay_type'] = 2;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = "请扫描正确的付款码";
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else if ($pay_type == 3) {
|
||
$Order['pay_type'] = 2;
|
||
$where['storeid'] = $storeid;
|
||
$where['face_token'] = $faceToken;
|
||
$historyOrder = $PayOrderModel->getFind($where);
|
||
if (!empty($historyOrder)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '请用户重新刷脸支付';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
}
|
||
/* 判断支付 */
|
||
$judge_pay = $this->judge_pay($store['merchantid'], $storeid);
|
||
if ($judge_pay['status'] == 1) {
|
||
$pay_state = $judge_pay['pay_state'];
|
||
$config = $judge_pay['config'];
|
||
if ($Order['pay_type'] == 1 && in_array($config['wx_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['wx_pay_state'];
|
||
} else if ($Order['pay_type'] == 2 && in_array($config['al_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['al_pay_state'];
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家该支付未开启';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $judge_pay['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '充值方式参数有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$Order ['order_type'] = 2;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['trade_amount'] = $money;
|
||
$Order ['cdate'] = time();
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['state'] = 0;
|
||
$Order ['code'] = $code ? $code : 0;
|
||
$Order ['vid'] = $vid;
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['merchantid'] = $store['merchantid'];
|
||
$Order ['face_token'] = $faceToken;
|
||
$orderId = $PayOrderModel->addOrder($Order);
|
||
if ($orderId) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderId);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderId), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['id'] = $orderId;
|
||
$Order['recharge'] = $recharge;
|
||
$Order['custom_givemoney'] = $custom_givemoney; //自定义赠送金额
|
||
if ($pay_type == 2) {
|
||
//微信支付宝
|
||
if ($Order['pay_type'] == 1) {
|
||
//微信
|
||
A('Pay/WxPay')->toWxPayRecharge($Order, $config);
|
||
} else {
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPayRecharge($Order, $config);
|
||
}
|
||
} else {
|
||
//现金
|
||
$Order['pay_type'] = 3;//现金支付
|
||
$this->vipRecharge($Order, $store['merchantid'], $recharge, $user_type == 1 ? 3 : 2);
|
||
// 充值送次卡
|
||
A('Xcxapi/VipCard')->rechargeGiveCard($Order['merchantid'], $Order['vid'], $Order['trade_amount'], 2);
|
||
$save ['trade_no'] = $res ['transaction_id'];
|
||
$save ['order_state'] = 'SUCCESS';
|
||
$save ['tradedate'] = time();
|
||
$save ['mdate'] = time();
|
||
$PayOrderModel->updateOrder(array('id' => $orderId), $save);
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $orderId;
|
||
$data['msg'] = '充值成功';
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '订单创建失败请重试';
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '订单创建失败请重试';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
private function verifyUserPass($user_type, $storeid, $adminid, $rechargecode, $username, $password)
|
||
{
|
||
if ($user_type == 1) {
|
||
$cashier = M('retail_cashier')->where(array('id' => $adminid))->find();
|
||
$res['cashier'] = $cashier;
|
||
if (!empty($cashier) && $cashier['canrecharge'] == 2) {
|
||
if ($rechargecode == $cashier['rechargecode']) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '收银员有权限充值';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '对不起,您的充值码错误';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '对不起,您没有充值权限,请联系店长';
|
||
}
|
||
} else {
|
||
$manager = M('retail_manager')->where(array('storeid' => $storeid, 'status' => 1, 'mobile' => $username))->find();
|
||
if (!$manager) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '错误,未找到该店长,请确认';
|
||
} else {
|
||
$time = $manager['addtime'];
|
||
$CryptrModel = new \Addons\Api\Crypto ();
|
||
$orignPwd = $CryptrModel->encrypt($password, date('YmdHis', $time));
|
||
if ($orignPwd == $manager['password']) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '正确,店长登录退款';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '错误,密码错误';
|
||
}
|
||
}
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
|
||
/*
|
||
* 积分变动 用户信息变动,推送到微信11-30
|
||
*/
|
||
public function scoreset($score, $merchantid, $vid)
|
||
{
|
||
//根据用户获取数据
|
||
$vip['id'] = $vid;
|
||
$User = M('retail_vip')->where($vip)->find();
|
||
$token = $this->getToKen($merchantid);
|
||
$url = "https://api.weixin.qq.com/card/membercard/updateuser?access_token=" . $token;
|
||
$param['code'] = $User['cardnum_old'];
|
||
//获取数据的code
|
||
$maps['merchantid'] = $merchantid;
|
||
$card = M('wx_membercard')->where($maps)->find();
|
||
$param['card_id'] = $card['card_id'];
|
||
//获取用户
|
||
$param['add_bonus'] = $score;
|
||
//要使用余额 必须要有特殊权限 余额需要自己点击查看
|
||
//$param['add_balance'] = $userinfo['money'];
|
||
$json = json_encode($param);
|
||
$re = $this->curl_post($url, $json);
|
||
}
|
||
|
||
function curl_post($url, array $params = array(), $timeout)
|
||
{
|
||
$ch = curl_init();//初始化
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||
curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
|
||
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||
$data = curl_exec($ch);//运行curl
|
||
curl_close($ch);
|
||
return ($data);
|
||
}
|
||
|
||
/*
|
||
*
|
||
*/
|
||
public function getToKen($merchantid)
|
||
{
|
||
//获取会员卡信息
|
||
//获取token 根据门店id 查询
|
||
$map['merchantid'] = $merchantid;
|
||
$wechat = M('wxconfig')->where($map)->find();
|
||
if ($wechat['type'] == 1) {
|
||
$appid = $wechat['appid'];
|
||
$secret = $wechat['appsecret'];
|
||
//print_r($wechat);
|
||
$json_token = http_request('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret);
|
||
$escape_token = json_decode($json_token);//转义
|
||
$token = $escape_token->{'access_token'};//2个小时换一次,一天2000次
|
||
return $token;//返回token值
|
||
} elseif ($wechat['type'] == 2) {
|
||
$tokens = get_authorizer_access_token($merchantid);
|
||
return $tokens;
|
||
}
|
||
}
|
||
|
||
//充值赠送优惠券
|
||
public function givecoupon_old($vid, $money, $merchantid)
|
||
{
|
||
$merchanname = M('retail_merchant')->where(array('id' => $merchantid))->getField('name');
|
||
$time = time();
|
||
$where['merchantid'] = $merchantid;
|
||
$where['give_status'] = 2;
|
||
$where['money'] = array('elt', $money);
|
||
$where['status'] = 1;
|
||
$coupon = M('retail_mcoupon')->where($where)->order('money desc')->find();
|
||
file_put_contents('csss.txt', json_encode($coupon));
|
||
//判断是否已领取
|
||
$vipcou = M('retail_vipmcoupon')->where(array('vid' => $vid, 'mcouponid' => $coupon['id']))->find();
|
||
file_put_contents('cv.txt', json_encode($vipcou));
|
||
if (empty($vipcou)) {
|
||
if ($coupon['coupon_num'] > 0) {
|
||
$Ad['mcouponid'] = $coupon['id'];
|
||
$Ad['needmoney'] = $coupon['needmoney'];
|
||
$Ad['reducemoney'] = $coupon['reducemoney'];
|
||
$Ad['merchantid'] = $merchantid;
|
||
$Ad['canusestoreids'] = $coupon['storeids'];
|
||
$Ad['addtime'] = $time;
|
||
if ($coupon['coupontype'] == 1) {
|
||
$Ad['starttime'] = $coupon['starttime'];
|
||
$Ad['endtime'] = $coupon['endtime'];
|
||
} else if ($coupon['coupontype'] == 2) {
|
||
$Ad['starttime'] = time();
|
||
$Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + $coupon['daynum'] * 86400;
|
||
} else if ($coupon['coupontype'] == 3) {
|
||
$Ad['starttime'] = strtotime(date('Y-m-d') . ' 23:59:59') + 1;
|
||
$Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + ($coupon['daynum'] + 1) * 86400;
|
||
}
|
||
$Ad['vid'] = $vid;
|
||
$add = M('retail_vipmcoupon')->add($Ad);
|
||
if ($add) {
|
||
$save = M('retail_mcoupon')->where(array('id' => $coupon['id']))->setDec('coupon_num', 1);
|
||
//可以赠送优惠券
|
||
$fisrt = "尊敬的会员用户,赠送您一张" . $coupon['coupon_name'];
|
||
$remark = $merchanname . '提示:优惠券在' . date('Y-m-d', $coupon['starttime']) . '到' . date('Y-m-d', $coupon['endtime']) . '有效期内可以使用';
|
||
$Ad['coupon_name'] = $coupon['coupon_name'];
|
||
A('Vip/Mark')->launchcoupon($vid, $fisrt, $remark, $Ad);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//充值赠送优惠券2019-3-20
|
||
public function givecoupon($vid, $money, $merchantid)
|
||
{
|
||
$merchanname = M('retail_merchant')->where(array('id' => $merchantid))->getField('name');
|
||
$time = time();
|
||
$coupon = $this->coupon_recursion($merchantid, $money, $vid, $id = '');
|
||
if ($coupon) {
|
||
if ($coupon['coupon_num'] > 0) {
|
||
$Ad['mcouponid'] = $coupon['id'];
|
||
$Ad['needmoney'] = $coupon['needmoney'];
|
||
$Ad['reducemoney'] = $coupon['reducemoney'];
|
||
$Ad['merchantid'] = $merchantid;
|
||
$Ad['canusestoreids'] = $coupon['storeids'];
|
||
$Ad['addtime'] = $time;
|
||
if ($coupon['coupontype'] == 1) {
|
||
$Ad['starttime'] = $coupon['starttime'];
|
||
$Ad['endtime'] = $coupon['endtime'];
|
||
} else if ($coupon['coupontype'] == 2) {
|
||
$Ad['starttime'] = time();
|
||
$Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + $coupon['daynum'] * 86400;
|
||
} else if ($coupon['coupontype'] == 3) {
|
||
$Ad['starttime'] = strtotime(date('Y-m-d') . ' 23:59:59') + 1;
|
||
$Ad['endtime'] = strtotime(date('Y-m-d') . ' 23:59:59') + ($coupon['daynum'] + 1) * 86400;
|
||
}
|
||
$Ad['vid'] = $vid;
|
||
$add = M('retail_vipmcoupon')->add($Ad);
|
||
if ($add) {
|
||
$save = M('retail_mcoupon')->where(array('id' => $coupon['id']))->setDec('coupon_num', 1);
|
||
//可以赠送优惠券
|
||
$fisrt = "尊敬的会员用户,赠送您一张" . $coupon['coupon_name'];
|
||
$remark = $merchanname . '提示:优惠券在' . date('Y-m-d', $coupon['starttime']) . '到' . date('Y-m-d', $coupon['endtime']) . '有效期内可以使用';
|
||
$Ad['coupon_name'] = $coupon['coupon_name'];
|
||
A('Vip/Mark')->launchcoupon($vid, $fisrt, $remark, $Ad);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//充值送优惠券递归查询
|
||
public function coupon_recursion($merchantid, $money, $vid, $id)
|
||
{
|
||
$time = time();
|
||
$where['merchantid'] = $merchantid;
|
||
$where['recharge_state'] = 1; //开启
|
||
$where['money'] = array('elt', $money);
|
||
$where['status'] = 1;
|
||
$where['coupon_num'] = array('gt', 0);
|
||
if (!empty($id)) {
|
||
$where['id'] = array('not in', $id);
|
||
}
|
||
$coupon = M('retail_mcoupon')->where($where)->order('money desc')->find();
|
||
if ($coupon) {
|
||
$id[] = $coupon['id'];
|
||
if ($coupon['coupontype'] == 1) {
|
||
if ($time > $coupon['endtime']) {
|
||
return $this->coupon_recursion($merchantid, $money, $vid, $id);
|
||
}
|
||
}
|
||
$vipcou = M('retail_vipmcoupon')->where(array('vid' => $vid, 'mcouponid' => $coupon['id']))->find();
|
||
if (!empty($vipcou)) {
|
||
return $this->coupon_recursion($merchantid, $money, $vid, $id);
|
||
} else {
|
||
return $coupon;
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
return $coupon;
|
||
}
|
||
|
||
|
||
/*
|
||
* 2019-1-24 新下单支付接口 统一支付
|
||
* */
|
||
protected function newPlaceOrderPay_v2()
|
||
{
|
||
$guideid = I('post.guideid');//导购员
|
||
$storeid = I('post.storeid');
|
||
$adminid = I('post.adminid');
|
||
$code = I('post.code');
|
||
$merchantid = I('post.merchantid');
|
||
$orderInfo = $_POST['orderInfo'];
|
||
|
||
$payType = I('post.payType');
|
||
$vid = I("post.vid");
|
||
// $cardNum = I("post.cardnum");
|
||
//$discount = I("post.discount");
|
||
$couponid = I("post.mcouponid"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
//$couponMoney = I("post.reducemoney"); //使用优惠券时减免的金额,没有则为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
switch ($payType) {
|
||
case '1':
|
||
}
|
||
if (empty($storeid) || empty($code) || empty($adminid)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
//微信支付
|
||
//支付宝
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$pay_type = 2;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$pay_type = 1;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$config = D('Payset')->getFindConfig($storeid);//获取商户微信配置信息
|
||
if (empty($config)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付参数未配置';
|
||
$this->ajaxReturn($data);
|
||
} else if ($config['status'] == 1) {
|
||
//普通商户模式
|
||
$Order ['m_pay_type'] = 1;
|
||
} else if ($config['status'] == 3) {
|
||
//服务商模式
|
||
$Order ['m_pay_type'] = 2;
|
||
} else if ($config['status'] == 4) {
|
||
//新大陆模式
|
||
$Order ['m_pay_type'] = 3;
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付配置有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
$Order['pay_type'] = 5;
|
||
//银行卡支付 其他支付
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
|
||
$orderid = $PayOrderModel->addOrder($Order);
|
||
if ($orderid) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderid);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderid), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $orderInfo,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
// 'discount' => $discount,
|
||
// 'cardnum' => $cardNum,
|
||
// 'couponMoney' => $couponMoney,
|
||
// 'exchange_money' => $couponMoney,
|
||
'small_changes_money' => $small_changes_money,
|
||
'couponid' => $couponid,
|
||
'guideid' => $guideid,
|
||
'order_id' => $out_trade_no,
|
||
'pay_orderid' => $orderid,
|
||
'm_pay_type' => $Order['m_pay_type']
|
||
);
|
||
$create = A("Sellapi/Pay")->createBillOrder_v1($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderid), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderid;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($pay_type) {
|
||
case 1:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 2:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* 2019-2-12 新下单支付接口 统一支付
|
||
* */
|
||
public function newPlaceOrderPay_v3()
|
||
{
|
||
$guideid = I('post.guideId'); //导购员
|
||
$storeid = I('post.storeId'); //门店id
|
||
$adminid = I('post.adminId'); //收银员id
|
||
$code = I('post.code'); //付款码
|
||
$merchantid = I('post.merchantId'); //商户id
|
||
$orderInfo = $_POST['orderInfo']; //所购买的商品
|
||
$payType = I('post.payType'); //支付方式 1:现金 2:银行卡 3:微信支付 4:支付宝支付 5:会员卡余额支付 6:小程序商城微信支付 7:其他支付方式
|
||
$vid = I("post.vid"); //会员id
|
||
$cardNum = I("post.cardNum"); //会员卡号
|
||
$couponid = I("post.couponId"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
$password = I('post.password');
|
||
$discount = I('post.discount') ? I('post.discount') : 1; //收银机打折
|
||
if ($discount < 0.001 || $discount > 1 || round($discount, 3) != round($discount, 4)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '折扣值有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($storeid) || (empty($code) && ($payType == 3 || $payType == 4)) || empty($adminid) || ($payType == 5 && !$vid) || ($payType == 5 && empty($password))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$result['data'] = I('post.');
|
||
$result['codeempty'] = (empty($code) && ($payType == 3 || $payType == 4));
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$v_discount = 1;
|
||
$coupon = array();
|
||
if (!empty($vid)) {
|
||
$map['merchantid'] = $merchantid;
|
||
$map['status'] = 1;
|
||
$map['id'] = $vid;
|
||
$vip = M('retail_vip')
|
||
->where($map)
|
||
->field('id,balance,grade_integral,addtime,password')
|
||
->find();
|
||
if (!empty($vip)) {
|
||
//用来判断会员等级
|
||
$grade = M('retail_vip_integral')
|
||
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid))
|
||
->order('min_integral desc')
|
||
->find();
|
||
if (!empty($grade)) {
|
||
$v_discount = $grade['discount'];
|
||
}
|
||
if (!empty($couponid)) {
|
||
$c_map['v.isuse'] = 1; //未使用优惠券
|
||
$c_map['v.vid'] = $vid; //会员id
|
||
$c_map['v.starttime'] = array("LT", time());//今天在优惠券使用期范围内
|
||
$c_map['v.endtime'] = array("GT", time()); //今天在优惠券使用期范围内
|
||
$c_map['v.merchantid'] = $merchantid;
|
||
$c_map['v.id'] = $couponid;
|
||
$myCoupon = M("retail_vipmcoupon as v")
|
||
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
|
||
->field("v.id,v.needmoney,v.reducemoney,v.canusestoreids")
|
||
->where($c_map)
|
||
->find();
|
||
if (!empty($myCoupon)) {
|
||
if ($myCoupon['canusestoreids'] != 0) {
|
||
$canUseStore = explode(",", trim($myCoupon['canusestoreids'], ','));
|
||
if (!in_array($storeid, $canUseStore)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该优惠券不能在当前门店使用';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$coupon = $myCoupon;
|
||
} else {
|
||
$res['m'] = M()->_sql();
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券信息有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '会员信息异常';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
$cashier = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($cashier)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($discount < 1) {
|
||
if ($cashier['preferential'] != 1) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该收银员没有结算手动打折权限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($store['preferential'] != 1) {
|
||
$v_discount = 1;
|
||
}
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
//微信支付
|
||
//支付宝
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$payType = 4;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$payType = 3;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$judge_pay = $this->judge_pay($merchantid, $storeid);
|
||
if ($judge_pay['status'] == 1) {
|
||
$pay_state = $judge_pay['pay_state'];
|
||
$config = $judge_pay['config'];
|
||
if ($payType == 3 && in_array($config['wx_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['wx_pay_state'];
|
||
} else if ($payType == 4 && in_array($config['al_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['al_pay_state'];
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家该支付未开启';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $judge_pay['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
//银行卡支付 其他支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
if ($vid) {
|
||
$Order ['vid'] = $vid;
|
||
}
|
||
|
||
$orderId = $PayOrderModel->addOrder($Order);
|
||
if ($orderId) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderId);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderId), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $orderInfo,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'v_discount' => $v_discount,
|
||
'discount' => $discount,
|
||
'cardnum' => $cardNum,
|
||
'small_changes_money' => $small_changes_money,
|
||
'coupon' => $coupon,
|
||
'guideid' => $guideid,
|
||
'out_trade_no' => $out_trade_no,
|
||
'pay_orderid' => $orderId,
|
||
'm_pay_type' => $Order['m_pay_type']
|
||
);
|
||
$create = A("Sellapi/Pay")->createBillOrder_v2($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderId), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderId;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($payType) {
|
||
case 3:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 4:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 1:
|
||
case 7:
|
||
case 2:
|
||
//现金,银行卡,其他
|
||
$change = A('Sellapi/Pay')->changeOrderStatus($create['all_money'], $create['bill_id'], '', $payType);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $create['all_money'];
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $out_trade_no;
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $out_trade_no;
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
break;
|
||
case 5:
|
||
//会员卡
|
||
$this->newToVipPay_v1($Order, $create['bill_id'], $password, $vip);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
protected function newToVipPay_v1($Order, $bill_id, $password, $vipInfo)
|
||
{
|
||
$CryptrModel = new \Addons\Api\Crypto ();
|
||
$orignPwd = $CryptrModel->encrypt($password, date('YmdHis', $vipInfo['addtime']));
|
||
if ($orignPwd != $vipInfo['password']) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡密码错误';
|
||
} else {
|
||
$payMoney = $Order['trade_amount'];
|
||
if ($vipInfo['balance'] < $payMoney) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡余额不足,无法支付';
|
||
} else {
|
||
$pay = M('retail_vip')->where(array('id' => $vipInfo['id']))->setDec('balance', $payMoney);
|
||
$add1['money'] = $payMoney;
|
||
$add1['allmoney'] = $payMoney;
|
||
$add1['state'] = 1;
|
||
$add1['type'] = 2;
|
||
$add1['addtime'] = time();
|
||
$add1['vid'] = $vipInfo['id'];
|
||
$add1['remark'] = '收银机支付' . $payMoney . '元';
|
||
$add = M('recharge_order')->add($add1);
|
||
if ($pay) {
|
||
$res['status'] = 1;
|
||
$res['recharge_id'] = $add;
|
||
$change = A('Sellapi/Pay')->changeOrderStatus($payMoney, $bill_id, array('status' => 1, 'recharge_id' => $add), 5);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $payMoney;
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '系统出差啦,请重试';
|
||
}
|
||
}
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
//小程序退款 2019-1-05 $fee_state 1退还配送费 2不退还配送费
|
||
public function XcxRefund_old1()
|
||
{
|
||
$id = I('post.id');
|
||
$adminid = I('post.adminid');
|
||
$storeid = I('post.storeid');
|
||
$fee_state = I('post.fee_state');
|
||
$fee_state = $fee_state ? $fee_state : 1;
|
||
if (empty($storeid) || empty($id) || empty($adminid)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员不存在';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$order = M('retail_bill')
|
||
->where(array('id' => $id, 'paytype' => array('in', '5,6'), 'type' => 1, 'status' => array('in', '1,3'), 'refund_status' => 1, 'pay_state' => 1))
|
||
->find();
|
||
if (empty($order)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单不存在或已退款';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($order['order_genre'] == 2 || $order['order_genre'] == 3) {
|
||
A('Sellapi/GroupOrder')->GroupAndSecKillRefund_v1($order['id'], $adminid, $order['merchantid'], $order);
|
||
} else {
|
||
$res = A('Xcxapi/Pay')->XcxRefund($order, $adminid, $fee_state);
|
||
if ($res['status'] == 1) {
|
||
//退款成功,修改订单
|
||
$sellOrders = M('retail_sell')->where(array('id' => array('in', $order['sellid'])))->select();
|
||
$sell_ids = '';
|
||
foreach ($sellOrders as $val) {
|
||
M('retail_sell')->where(array('id' => array('in', $val['id'])))->save(array('is_refund' => 2, 'refund_num' => $val['num']));
|
||
unset($val['id']);
|
||
$val['refund_num'] = $val['num'];
|
||
$val['status'] = 2;
|
||
$val['is_refund'] = 3;
|
||
$addid = M('retail_sell')->add($val);
|
||
if ($sell_ids == '') {
|
||
$sell_ids = $addid;
|
||
} else {
|
||
$sell_ids .= ',' . $addid;
|
||
}
|
||
$less_stock = M('retail_goods')->where(array('id' => $val['goods_id']))->setDec('sell_num', $val['num']);//销售数量
|
||
|
||
if (!empty($val['skuinfo'])) {
|
||
$sku = json_decode($val['skuinfo'], true);
|
||
M("retail_goodsku")->where(array("id" => $sku[0]['id'], "status" => 2))->setInc('num', $val['num']);//需要修改规格库存
|
||
}
|
||
//加入库存明细
|
||
//根据商品id查询出商品现有库存(发生操作前)
|
||
$now_quantity = M('retail_goods')->where(array('id' => $id))->getField('goods_num');
|
||
$log['original_stock'] = $now_quantity; //商品原库存
|
||
$log['do_num'] = $val['num']; //需要操作的数量
|
||
$log['type'] = 1; //2为减库存 1添加
|
||
$log['goods_id'] = $val['goods_id']; //商品id
|
||
$log['sell_id'] = $addid; //sell id
|
||
$log['storeid'] = $storeid; //门店id
|
||
$log['present_stock'] = $now_quantity + $val['num']; //现库存
|
||
$log['merchantid'] = $order['merchantid']; //商户id
|
||
$log['addtime'] = time();
|
||
$log['remark'] = '退款增加';
|
||
M('retail_quantity_logs')->add($log);
|
||
M('retail_goods')->where(array('id' => $val['goods_id']))->setInc('goods_num', $val['num']);
|
||
}
|
||
if ($order['isneedsend'] == 2) {
|
||
$order['fee_state'] = $fee_state;
|
||
if ($fee_state == 2) {
|
||
$order['allmoney'] = $order['allmoney'] - $order['distribution_fee'];
|
||
}
|
||
}
|
||
$order['refund_num'] = $order['order_id'];
|
||
$order['order_id'] = $this->createOrderTradeNo($order['id']);
|
||
unset($order['id']);
|
||
$order['order_type'] = 2;
|
||
$order['refund_money'] = $order['allmoney'];
|
||
$order['refund_status'] = 2;
|
||
if (!empty($res['refund_no'])) {
|
||
$order['refund_no'] = $res['refund_no'];
|
||
}
|
||
$order['admin_id'] = $adminid;
|
||
$addOrder = M('retail_bill')->add($order);
|
||
$update = M('retail_bill')->where(array('id' => $id))->save(array('refund_status' => 2, 'refund_money' => $order['allmoney'], 'fee_state' => $fee_state));
|
||
if (!empty($order['vipid'])) {
|
||
A('Vip/Mark')->paysuccess($storeid, $order['vipid'], $order['allmoney'], '小程序退款');
|
||
}
|
||
if ($addOrder && $update) {
|
||
$result['status'] = 1;
|
||
$result['msg'] = '退款成功';
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '退款失败';
|
||
}
|
||
} else {
|
||
$result = $res;
|
||
$result["status"] = 0;
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/*
|
||
* 2019-3-1 新下单支付接口 统一支付动态码
|
||
* */
|
||
public function newPlaceOrderPay_v4()
|
||
{
|
||
$guideid = I('post.guideId'); //导购员
|
||
$storeid = I('post.storeId'); //门店id
|
||
$adminid = I('post.adminId'); //收银员id
|
||
$code = I('post.code'); //付款码
|
||
$merchantid = I('post.merchantId'); //商户id
|
||
$orderInfo = $_POST['orderInfo']; //所购买的商品
|
||
$payType = I('post.payType'); //支付方式 1:现金 2:银行卡 3:微信支付 4:支付宝支付 5:会员卡余额支付 6:小程序商城微信支付 7:其他支付方式
|
||
$vid = I("post.vid"); //会员id
|
||
$cardCode = I("post.cardCode"); //会员卡号或动态码
|
||
$couponid = I("post.couponId"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
$password = I('post.password');
|
||
$discount = I('post.discount') ? I('post.discount') : 1; //收银机打折
|
||
$vipPayType = I('post.vipLoginType'); //登录方式 1动态码支付 2密码支付
|
||
if ($discount < 0.001 || $discount > 1 || round($discount, 3) != round($discount, 4)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '折扣值有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($payType == 5 && $vipPayType == 1 && (empty($vid) || empty($cardCode))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($storeid) || (empty($code) && ($payType == 3 || $payType == 4)) || empty($adminid) || ($payType == 5 && !$vid) || ($payType == 5 && $vipPayType == 2 && empty($password))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$result['data'] = I('post.');
|
||
$result['codeempty'] = (empty($code) && ($payType == 3 || $payType == 4));
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$v_discount = 1;
|
||
$coupon = array();
|
||
if (!empty($vid)) {
|
||
$map['merchantid'] = $merchantid;
|
||
$map['status'] = 1;
|
||
$map['id'] = $vid;
|
||
if ($vipPayType == 2) {
|
||
$map['card_key|mobile_phone|cardnum'] = $cardCode;
|
||
}
|
||
$vip = M('retail_vip')
|
||
->where($map)
|
||
->field('id,balance,grade_integral,addtime,password')
|
||
->find();
|
||
if (!empty($vip)) {
|
||
//用来判断会员等级
|
||
$grade = M('retail_vip_integral')
|
||
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid))
|
||
->order('min_integral desc')
|
||
->find();
|
||
if (!empty($grade)) {
|
||
$v_discount = $grade['discount'];
|
||
}
|
||
if (!empty($couponid)) {
|
||
$c_map['v.isuse'] = 1; //未使用优惠券
|
||
$c_map['v.vid'] = $vid; //会员id
|
||
$c_map['v.starttime'] = array("LT", time());//今天在优惠券使用期范围内
|
||
$c_map['v.endtime'] = array("GT", time()); //今天在优惠券使用期范围内
|
||
$c_map['v.merchantid'] = $merchantid;
|
||
$c_map['v.id'] = $couponid;
|
||
$myCoupon = M("retail_vipmcoupon as v")
|
||
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
|
||
->field("v.id,v.needmoney,v.reducemoney,v.canusestoreids")
|
||
->where($c_map)
|
||
->find();
|
||
if (!empty($myCoupon)) {
|
||
if ($myCoupon['canusestoreids'] != 0) {
|
||
$canUseStore = explode(",", trim($myCoupon['canusestoreids'], ','));
|
||
if (!in_array($storeid, $canUseStore)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该优惠券不能在当前门店使用';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$coupon = $myCoupon;
|
||
} else {
|
||
$res['m'] = M()->_sql();
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券信息有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '会员信息异常';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
$cashier = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($cashier)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($discount < 1) {
|
||
if ($cashier['preferential'] != 1) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该收银员没有结算手动打折权限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($store['preferential'] != 1) {
|
||
$v_discount = 1;
|
||
}
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
//微信支付
|
||
//支付宝
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$payType = 4;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$payType = 3;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$judge_pay = $this->judge_pay($merchantid, $storeid);
|
||
if ($judge_pay['status'] == 1) {
|
||
$pay_state = $judge_pay['pay_state'];
|
||
$config = $judge_pay['config'];
|
||
if ($payType == 3 && in_array($config['wx_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['wx_pay_state'];
|
||
} else if ($payType == 4 && in_array($config['al_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['al_pay_state'];
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家该支付未开启';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $judge_pay['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
//银行卡支付 其他支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$goodsList = json_decode($orderInfo, true);
|
||
foreach ($goodsList as $key => $value) {
|
||
if (!empty($value['id']) && $value['id'] != 0) {
|
||
$goods = M('retail_goods')->where(array('status' => 0, 'id' => $value['id'], 'storeid' => $storeid))->find();
|
||
if (empty($goods)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '第' . ($key + 1) . '个商品信息有变动,请刷新后重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
if ($vid) {
|
||
$Order ['vid'] = $vid;
|
||
}
|
||
|
||
$orderId = $PayOrderModel->addOrder($Order);
|
||
if ($orderId) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderId);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderId), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $orderInfo,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'v_discount' => $v_discount,
|
||
'discount' => $discount,
|
||
'cardnum' => $vip ? $vip['cardnum'] : '',
|
||
'small_changes_money' => $small_changes_money,
|
||
'coupon' => $coupon,
|
||
'guideid' => $guideid,
|
||
'out_trade_no' => $out_trade_no,
|
||
'pay_orderid' => $orderId,
|
||
'm_pay_type' => $Order['m_pay_type']
|
||
);
|
||
$create = A("Sellapi/Pay")->createBillOrder_v2($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderId), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderId;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($payType) {
|
||
case 3:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 4:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPaybackups($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 1:
|
||
case 7:
|
||
case 2:
|
||
//现金,银行卡,其他
|
||
$change = A('Sellapi/Pay')->changeOrderStatus($create['all_money'], $create['bill_id'], '', $payType);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $create['all_money'];
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $out_trade_no;
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $out_trade_no;
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
break;
|
||
case 5:
|
||
//会员卡
|
||
$this->newToVipPay_v2($Order, $create['bill_id'], $password, $vip, $cardCode, $vipPayType);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
//新增加盟店店铺金额增加
|
||
public function newPlaceOrderPay_v5()
|
||
{
|
||
$guideid = I('post.guideId'); //导购员
|
||
$storeid = I('post.storeId'); //门店id
|
||
$adminid = I('post.adminId'); //收银员id
|
||
$code = I('post.code'); //付款码
|
||
$merchantid = I('post.merchantId'); //商户id
|
||
$orderInfo = $_POST['orderInfo']; //所购买的商品
|
||
$payType = I('post.payType'); //支付方式 1:现金 2:银行卡 3:微信支付 4:支付宝支付 5:会员卡余额支付 6:小程序商城微信支付 7:其他支付方式
|
||
$vid = I("post.vid"); //会员id
|
||
$cardCode = I("post.cardCode"); //会员卡号或动态码
|
||
$couponid = I("post.couponId"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
$password = I('post.password');
|
||
$discount = I('post.discount') ? I('post.discount') : 1; //收银机打折
|
||
$vipPayType = I('post.vipLoginType'); //登录方式 1动态码支付 2密码支付
|
||
if ($discount < 0.001 || $discount > 1 || round($discount, 3) != round($discount, 4)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '折扣值有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($payType == 5 && $vipPayType == 1 && (empty($vid) || empty($cardCode))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($storeid) || (empty($code) && ($payType == 3 || $payType == 4)) || empty($adminid) || ($payType == 5 && !$vid) || ($payType == 5 && $vipPayType == 2 && empty($password))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$result['data'] = I('post.');
|
||
$result['codeempty'] = (empty($code) && ($payType == 3 || $payType == 4));
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$v_discount = 1;
|
||
$coupon = array();
|
||
if (!empty($vid)) {
|
||
$map['merchantid'] = $merchantid;
|
||
$map['status'] = 1;
|
||
$map['id'] = $vid;
|
||
if ($vipPayType == 2) {
|
||
$map['card_key|mobile_phone|cardnum'] = $cardCode;
|
||
}
|
||
$vip = M('retail_vip')
|
||
->where($map)
|
||
->field('id,balance,grade_integral,addtime,password')
|
||
->find();
|
||
if (!empty($vip)) {
|
||
//用来判断会员等级
|
||
$grade = M('retail_vip_integral')
|
||
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid))
|
||
->order('min_integral desc')
|
||
->find();
|
||
if (!empty($grade)) {
|
||
$v_discount = $grade['discount'];
|
||
}
|
||
if (!empty($couponid)) {
|
||
$c_map['v.isuse'] = 1; //未使用优惠券
|
||
$c_map['v.vid'] = $vid; //会员id
|
||
$c_map['v.starttime'] = array("LT", time());//今天在优惠券使用期范围内
|
||
$c_map['v.endtime'] = array("GT", time()); //今天在优惠券使用期范围内
|
||
$c_map['v.merchantid'] = $merchantid;
|
||
$c_map['v.id'] = $couponid;
|
||
$myCoupon = M("retail_vipmcoupon as v")
|
||
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
|
||
->field("v.id,v.needmoney,v.reducemoney,v.canusestoreids")
|
||
->where($c_map)
|
||
->find();
|
||
if (!empty($myCoupon)) {
|
||
if ($myCoupon['canusestoreids'] != 0) {
|
||
$canUseStore = explode(",", trim($myCoupon['canusestoreids'], ','));
|
||
if (!in_array($storeid, $canUseStore)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该优惠券不能在当前门店使用';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$coupon = $myCoupon;
|
||
} else {
|
||
$res['m'] = M()->_sql();
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券信息有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '会员信息异常';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
$cashier = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($cashier)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($discount < 1) {
|
||
if ($cashier['preferential'] != 1) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该收银员没有结算手动打折权限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($store['preferential'] != 1) {
|
||
$v_discount = 1;
|
||
}
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
//微信支付
|
||
//支付宝
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
$historyOrder = $PayOrderModel->getFind(array('code' => $code, 'storeid' => $storeid));
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$payType = 4;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$payType = 3;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$config = D('Payset')->getFindConfig($storeid);//获取商户微信配置信息
|
||
if (empty($config)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付参数未配置';
|
||
$this->ajaxReturn($data);
|
||
} else if ($config['status'] == 1) {
|
||
//普通商户模式
|
||
$Order ['m_pay_type'] = 1;
|
||
} else if ($config['status'] == 3) {
|
||
//服务商模式
|
||
$Order ['m_pay_type'] = 2;
|
||
} else if ($config['status'] == 4) {
|
||
//新大陆模式
|
||
$Order ['m_pay_type'] = 3;
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家支付配置有误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
//银行卡支付 其他支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
if ($vid) {
|
||
$Order ['vid'] = $vid;
|
||
}
|
||
|
||
$orderId = $PayOrderModel->addOrder($Order);
|
||
if ($orderId) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderId);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderId), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $orderInfo,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'v_discount' => $v_discount,
|
||
'discount' => $discount,
|
||
'cardnum' => $vip ? $vip['cardnum'] : '',
|
||
'small_changes_money' => $small_changes_money,
|
||
'coupon' => $coupon,
|
||
'guideid' => $guideid,
|
||
'out_trade_no' => $out_trade_no,
|
||
'pay_orderid' => $orderId,
|
||
'm_pay_type' => $Order['m_pay_type']
|
||
);
|
||
$create = A("Sellapi/Pay")->createBillOrder_v2($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderId), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderId;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($payType) {
|
||
case 3:
|
||
//微信
|
||
A('Pay/WxPay')->toWxPaybackups_v1($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 4:
|
||
//支付宝
|
||
A('Pay/AliPay')->toAliPaybackups_v1($Order, $create['bill_id'], $config);
|
||
break;
|
||
case 1:
|
||
case 7:
|
||
case 2:
|
||
//现金,银行卡,其他
|
||
$change = A('Sellapi/Pay')->changeOrderStatus_v26($create['all_money'], $create['bill_id'], '', $payType);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $create['all_money'];
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $out_trade_no;
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $out_trade_no;
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
break;
|
||
case 5:
|
||
//会员卡
|
||
$this->newToVipPay_v3($Order, $create['bill_id'], $password, $vip, $cardCode, $vipPayType);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
protected function newToVipPay_v2($Order, $bill_id, $password, $vipInfo, $cardCode, $vipPayType)
|
||
{
|
||
if ($vipPayType == 1) {
|
||
$map = array(
|
||
'code' => $cardCode,
|
||
'status' => 1,
|
||
'state' => 0,
|
||
'merchantid' => $Order['merchantid'],
|
||
'use_storeid' => $Order['storeid']
|
||
);
|
||
$old = M('vip_dynamic_code')->where($map)->find();
|
||
if (empty($old) || $old['failure_time'] <= time()) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请会员刷新动态码';
|
||
$this->ajaxReturn($res);
|
||
} else {
|
||
M('vip_dynamic_code')->where($map)->save(array('status' => 2));
|
||
}
|
||
} else {
|
||
$CryptrModel = new \Addons\Api\Crypto ();
|
||
$orignPwd = $CryptrModel->encrypt($password, date('YmdHis', $vipInfo['addtime']));
|
||
if ($orignPwd != $vipInfo['password']) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡密码错误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
}
|
||
$payMoney = $Order['trade_amount'];
|
||
if ($vipInfo['balance'] < $payMoney) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡余额不足,无法支付';
|
||
} else {
|
||
$pay = M('retail_vip')->where(array('id' => $vipInfo['id']))->setDec('balance', $payMoney);
|
||
$add1['money'] = $payMoney;
|
||
$add1['allmoney'] = $payMoney;
|
||
$add1['state'] = 1;
|
||
$add1['type'] = 2;
|
||
$add1['addtime'] = time();
|
||
$add1['vid'] = $vipInfo['id'];
|
||
$add1['remark'] = '收银机支付' . $payMoney . '元';
|
||
$add = M('recharge_order')->add($add1);
|
||
if ($pay) {
|
||
$res['status'] = 1;
|
||
$res['recharge_id'] = $add;
|
||
$change = A('Sellapi/Pay')->changeOrderStatus($payMoney, $bill_id, array('status' => 1, 'recharge_id' => $add), 5);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $payMoney;
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '系统出差啦,请重试';
|
||
}
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
//2019-3-4加盟店
|
||
protected function newToVipPay_v3($Order, $bill_id, $password, $vipInfo, $cardCode, $vipPayType)
|
||
{
|
||
if ($vipPayType == 1) {
|
||
$map = array(
|
||
'code' => $cardCode,
|
||
'status' => 1,
|
||
'state' => 0,
|
||
'merchantid' => $Order['merchantid'],
|
||
'use_storeid' => $Order['storeid']
|
||
);
|
||
$old = M('vip_dynamic_code')->where($map)->find();
|
||
if (empty($old) || $old['failure_time'] <= time()) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请会员刷新动态码';
|
||
$this->ajaxReturn($res);
|
||
} else {
|
||
M('vip_dynamic_code')->where($map)->save(array('status' => 2));
|
||
}
|
||
} else {
|
||
$CryptrModel = new \Addons\Api\Crypto ();
|
||
$orignPwd = $CryptrModel->encrypt($password, date('YmdHis', $vipInfo['addtime']));
|
||
if ($orignPwd != $vipInfo['password']) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡密码错误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
}
|
||
$payMoney = $Order['trade_amount'];
|
||
if ($vipInfo['balance'] < $payMoney) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡余额不足,无法支付';
|
||
} else {
|
||
$pay = M('retail_vip')->where(array('id' => $vipInfo['id']))->setDec('balance', $payMoney);
|
||
$add1['money'] = $payMoney;
|
||
$add1['allmoney'] = $payMoney;
|
||
$add1['state'] = 1;
|
||
$add1['type'] = 2;
|
||
$add1['addtime'] = time();
|
||
$add1['vid'] = $vipInfo['id'];
|
||
$add1['remark'] = '收银机支付' . $payMoney . '元';
|
||
$add = M('recharge_order')->add($add1);
|
||
if ($pay) {
|
||
$res['status'] = 1;
|
||
$res['recharge_id'] = $add;
|
||
$change = A('Sellapi/Pay')->changeOrderStatus_v26($payMoney, $bill_id, array('status' => 1, 'recharge_id' => $add), 5);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $payMoney;
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '系统出差啦,请重试';
|
||
}
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
/*
|
||
* 2019-3-8 新下单支付接口 统一支付动态码 新版支付设置,增加新大陆支付
|
||
* */
|
||
public function newPlaceOrderPay_v6()
|
||
{
|
||
$guideid = I('post.guideId'); //导购员
|
||
$storeid = I('post.storeId'); //门店id
|
||
$adminid = I('post.adminId'); //收银员id
|
||
$code = I('post.code'); //付款码
|
||
$merchantid = I('post.merchantId'); //商户id
|
||
$orderInfo = $_POST['orderInfo']; //所购买的商品
|
||
$payType = I('post.payType'); //支付方式 1:现金 2:银行卡 3:微信支付 4:支付宝支付 5:会员卡余额支付 6:小程序商城微信支付 7:其他支付方式
|
||
$vid = I("post.vid"); //会员id
|
||
$cardCode = I("post.cardCode"); //会员卡号或动态码
|
||
$couponid = I("post.couponId"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
$password = I('post.password');
|
||
$discount = I('post.discount') ? I('post.discount') : 1; //收银机打折
|
||
$vipPayType = I('post.vipLoginType'); //登录方式 1动态码支付 2密码支付
|
||
$amountReceived = I('post.amountReceived') ? I('post.amountReceived') : 0; // 现金实收Amount received
|
||
$isZeroStorage = I('post.isZeroStorage') ? I('post.isZeroStorage') : 0; //是否存零 1是 0否
|
||
$faceToken = I('post.faceToken'); //刷脸支付参数
|
||
if ($discount < 0.001 || $discount > 1 || round($discount, 3) != round($discount, 4)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '折扣值有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7', '8');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($payType == 5 && $vipPayType == 1 && (empty($vid) || empty($cardCode))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($storeid) || (empty($faceToken) && $payType == 8) || (empty($code) && ($payType == 3 || $payType == 4)) || empty($adminid) || ($payType == 5 && !$vid) || ($payType == 5 && $vipPayType == 2 && empty($password))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$result['data'] = I('post.');
|
||
$result['codeempty'] = (empty($code) && ($payType == 3 || $payType == 4));
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$v_discount = 1;
|
||
$coupon = array();
|
||
if (!empty($vid)) {
|
||
$map['merchantid'] = $merchantid;
|
||
$map['status'] = 1;
|
||
$map['id'] = $vid;
|
||
if ($vipPayType == 2) {
|
||
$map['card_key|mobile_phone|cardnum'] = $cardCode;
|
||
}
|
||
$vip = M('retail_vip')
|
||
->where($map)
|
||
->field('id,balance,grade_integral,addtime,password')
|
||
->find();
|
||
if (!empty($vip)) {
|
||
//用来判断会员等级
|
||
$grade = M('retail_vip_integral')
|
||
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid))
|
||
->order('min_integral desc')
|
||
->find();
|
||
if (!empty($grade)) {
|
||
$v_discount = $grade['discount'];
|
||
}
|
||
if (!empty($couponid)) {
|
||
$c_map['v.isuse'] = 1; //未使用优惠券
|
||
$c_map['v.vid'] = $vid; //会员id
|
||
$c_map['v.starttime'] = array("LT", time());//今天在优惠券使用期范围内
|
||
$c_map['v.endtime'] = array("GT", time()); //今天在优惠券使用期范围内
|
||
$c_map['v.merchantid'] = $merchantid;
|
||
$c_map['v.id'] = $couponid;
|
||
$myCoupon = M("retail_vipmcoupon as v")
|
||
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
|
||
->field("v.id,v.needmoney,v.reducemoney,v.canusestoreids")
|
||
->where($c_map)
|
||
->find();
|
||
if (!empty($myCoupon)) {
|
||
if ($myCoupon['canusestoreids'] != 0) {
|
||
$canUseStore = explode(",", trim($myCoupon['canusestoreids'], ','));
|
||
if (!in_array($storeid, $canUseStore)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该优惠券不能在当前门店使用';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$coupon = $myCoupon;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券信息有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '会员信息异常';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
} else {
|
||
$vip = 0;
|
||
}
|
||
$cashier = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($cashier)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($discount < 1) {
|
||
if ($cashier['preferential'] != 1) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该收银员没有结算手动打折权限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($store['preferential'] != 1) {
|
||
$v_discount = 1;
|
||
}
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
case '8':
|
||
if ($payType == 3 || $payType == 4) {
|
||
//微信支付宝刷卡支付
|
||
$where['storeid'] = $storeid;
|
||
$where['code'] = $code;
|
||
$historyOrder = $PayOrderModel->getFind($where);
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$payType = 4;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$payType = 3;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else if ($payType == 8) {
|
||
$payType = 4;
|
||
$where['storeid'] = $storeid;
|
||
$where['face_token'] = $faceToken;
|
||
$historyOrder = $PayOrderModel->getFind($where);
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户重新刷脸支付';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
/* 判断支付 */
|
||
$judge_pay = $this->judge_pay($merchantid, $storeid);
|
||
if ($judge_pay['status'] == 1) {
|
||
$pay_state = $judge_pay['pay_state'];
|
||
$config = $judge_pay['config'];
|
||
if ($payType == 3 && in_array($config['wx_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['wx_pay_state'];
|
||
} else if ($payType == 4 && in_array($config['al_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['al_pay_state'];
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家该支付未开启';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $judge_pay['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
//银行卡支付 其他支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$goodsList = json_decode($orderInfo, true);
|
||
$vip['v_discount'] = $v_discount;
|
||
$verify = $this->goodsVerify($goodsList, $store, $vip);
|
||
$res['data'] = $verify;
|
||
if ($verify['status'] == 0) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $verify['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['face_token'] = $faceToken;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
$Order ['merchantid'] = $merchantid;
|
||
if ($vid) {
|
||
$Order ['vid'] = $vid;
|
||
}
|
||
$orderId = $PayOrderModel->addOrder($Order);
|
||
if ($orderId) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderId);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderId), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $verify['data'],
|
||
'order' => $verify,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'discount' => $discount,
|
||
'cardnum' => $vip ? $vip['cardnum'] : '',
|
||
'small_changes_money' => $small_changes_money,
|
||
'coupon' => $coupon,
|
||
'guideid' => $guideid,
|
||
'out_trade_no' => $out_trade_no,
|
||
'pay_orderid' => $orderId,
|
||
'm_pay_type' => $Order['m_pay_type'],
|
||
'disMoney' => $verify['disMoney'],
|
||
'allMoney' => $verify['allMoney'],
|
||
'amountReceived' => $payType == 1 ? $amountReceived : 0,
|
||
'isZeroStorage' => $payType == 1 ? $isZeroStorage : 0,
|
||
);
|
||
$create = A("Sellapi/NewPay")->createBillOrder_v3($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderId), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderId;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($payType) {
|
||
case 3:
|
||
//微信
|
||
if ($Order['m_pay_type'] == 3) {
|
||
//新大陆支付
|
||
A('Pay/PayContinent')->toContinentPay($Order, $create['bill_id'], $store['storetag']);
|
||
} else {
|
||
A('Pay/NewWxPay')->toWxPay($Order, $create['bill_id'], $config);
|
||
}
|
||
break;
|
||
case 4:
|
||
//支付宝
|
||
if ($Order['m_pay_type'] == 3) {
|
||
//新大陆支付
|
||
A('Pay/PayContinent')->toContinentPay($Order, $create['bill_id'], $store['storetag']);
|
||
} else {
|
||
A('Pay/NewAliPay')->toAliPay($Order, $create['bill_id'], $config);
|
||
}
|
||
|
||
break;
|
||
case 1:
|
||
case 7:
|
||
case 2:
|
||
//现金,银行卡,其他
|
||
$change = A('Sellapi/NewPay')->changeOrder($create['bill_id'], $payType);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $create['all_money'];
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $out_trade_no;
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $out_trade_no;
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
break;
|
||
case 5:
|
||
//会员卡
|
||
$this->newToVipPay_v4($Order, $create['bill_id'], $password, $vip, $cardCode, $vipPayType);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = $create['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* plus版本收银机下单2019-5-17
|
||
*/
|
||
public function newPlaceOrderPay_v7()
|
||
{
|
||
$guideid = I('post.guideId'); //导购员
|
||
$storeid = I('post.storeId'); //门店id
|
||
$adminid = I('post.adminId'); //收银员id
|
||
$code = I('post.code'); //付款码
|
||
$merchantid = I('post.merchantId'); //商户id
|
||
$orderInfo = $_POST['orderInfo']; //所购买的商品
|
||
$payType = I('post.payType'); //支付方式 1:现金 2:银行卡 3:微信支付 4:支付宝支付 5:会员卡余额支付 6:小程序商城微信支付 7:其他支付方式
|
||
$vid = I("post.vid"); //会员id
|
||
$cardCode = I("post.cardCode"); //会员卡号或动态码
|
||
$couponid = I("post.couponId"); //会员支付时使用的优惠券id(retail_vipmcoupon表的id) 没有为0
|
||
$small_changes_money = I('post.changes_money') ? I('post.changes_money') : 0;
|
||
$password = I('post.password');
|
||
$discount = I('post.discount') ? I('post.discount') : 1; //收银机打折
|
||
$vipPayType = I('post.vipLoginType'); //登录方式 1动态码支付 2密码支付
|
||
$amountReceived = I('post.amountReceived') ? I('post.amountReceived') : 0; // 现金实收Amount received
|
||
$isZeroStorage = I('post.isZeroStorage') ? I('post.isZeroStorage') : 0; //是否存零 1是 0否
|
||
$faceToken = I('post.faceToken'); //刷脸支付参数
|
||
if ($discount < 0.001 || $discount > 1 || round($discount, 3) != round($discount, 4)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '折扣值有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$arr = array('1', '2', '3', '4', '5', '6', '7', '8');
|
||
if (empty($payType) || !in_array($payType, $arr)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '支付方式有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($payType == 5 && $vipPayType == 1 && (empty($vid) || empty($cardCode))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($storeid) || (empty($faceToken) && $payType == 8) || (empty($code) && ($payType == 3 || $payType == 4)) || empty($adminid) || ($payType == 5 && !$vid) || ($payType == 5 && $vipPayType == 2 && empty($password))) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
$result['data'] = I('post.');
|
||
$result['codeempty'] = (empty($code) && ($payType == 3 || $payType == 4));
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$v_discount = 1;
|
||
$coupon = array();
|
||
if (!empty($vid)) {
|
||
$map['merchantid'] = $merchantid;
|
||
$map['status'] = 1;
|
||
$map['id'] = $vid;
|
||
if ($vipPayType == 2) {
|
||
$map['card_key|mobile_phone|cardnum'] = $cardCode;
|
||
}
|
||
$vip = M('retail_vip')
|
||
->where($map)
|
||
->field('id,balance,grade_integral,addtime,password,plus_type')
|
||
->find();
|
||
if (!empty($vip)) {
|
||
//用来判断会员等级
|
||
if ($vip['plus_type'] == 2) {//plus会员
|
||
$grade = M('retail_vip_integral')
|
||
->where(array('merchantid' => $merchantid, 'discount' => array('gt', 0)))
|
||
->order("discount asc")
|
||
->find();
|
||
} else { //常规会员
|
||
$grade = M('retail_vip_integral')
|
||
->where(array('min_integral' => array('ELT', $vip['grade_integral']), 'merchantid' => $merchantid, 'discount' => array('gt', 0)))
|
||
->order('min_integral desc')
|
||
->find();
|
||
}
|
||
if (!empty($grade)) {
|
||
$v_discount = $grade['discount'];
|
||
}
|
||
if (!empty($couponid)) {
|
||
$c_map['v.isuse'] = 1; //未使用优惠券
|
||
$c_map['v.vid'] = $vid; //会员id
|
||
$c_map['v.starttime'] = array("LT", time());//今天在优惠券使用期范围内
|
||
$c_map['v.endtime'] = array("GT", time()); //今天在优惠券使用期范围内
|
||
$c_map['v.merchantid'] = $merchantid;
|
||
$c_map['v.id'] = $couponid;
|
||
$myCoupon = M("retail_vipmcoupon as v")
|
||
->join('ls_retail_mcoupon as m on m.id=v.mcouponid')
|
||
->field("v.id,v.needmoney,v.reducemoney,v.canusestoreids")
|
||
->where($c_map)
|
||
->find();
|
||
if (!empty($myCoupon)) {
|
||
if ($myCoupon['canusestoreids'] != 0) {
|
||
$canUseStore = explode(",", trim($myCoupon['canusestoreids'], ','));
|
||
if (!in_array($storeid, $canUseStore)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该优惠券不能在当前门店使用';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$coupon = $myCoupon;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券信息有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '会员信息异常';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
} else {
|
||
$vip = 0;
|
||
}
|
||
$cashier = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($cashier)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '门店被禁用';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($discount < 1) {
|
||
if ($cashier['preferential'] != 1) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '该收银员没有结算手动打折权限';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if ($store['preferential'] != 1) {
|
||
$v_discount = 1;
|
||
}
|
||
}
|
||
$PayOrderModel = D('PayOrder');
|
||
switch ($payType) {
|
||
case '1':
|
||
//现金支付
|
||
$Order['pay_type'] = 3;
|
||
break;
|
||
case '3':
|
||
case '4':
|
||
case '8':
|
||
if ($payType == 3 || $payType == 4) {
|
||
//微信支付宝刷卡支付
|
||
$where['storeid'] = $storeid;
|
||
$where['code'] = $code;
|
||
$historyOrder = $PayOrderModel->getFind($where);
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户刷新付款码';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$text = substr($code, 0, 2);
|
||
if ($text >= 25 && $text <= 30) { //支付宝付款码支付
|
||
$payType = 4;
|
||
} else if ($text >= 10 && $text <= 15) { //微信的付款码支付
|
||
$payType = 3;
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = "请扫描正确的二维码";
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else if ($payType == 8) {
|
||
$payType = 4;
|
||
$where['storeid'] = $storeid;
|
||
$where['face_token'] = $faceToken;
|
||
$historyOrder = $PayOrderModel->getFind($where);
|
||
if (!empty($historyOrder)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请用户重新刷脸支付';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
if ($payType == 3) {
|
||
$Order['pay_type'] = 1;
|
||
} else {
|
||
$Order['pay_type'] = 2;
|
||
}
|
||
/* 判断支付 */
|
||
$judge_pay = $this->judge_pay($merchantid, $storeid);
|
||
if ($judge_pay['status'] == 1) {
|
||
$pay_state = $judge_pay['pay_state'];
|
||
$config = $judge_pay['config'];
|
||
if ($payType == 3 && in_array($config['wx_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['wx_pay_state'];
|
||
} else if ($payType == 4 && in_array($config['al_pay_state'], $pay_state)) {
|
||
$Order['m_pay_type'] = $config['al_pay_state'];
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商家该支付未开启';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $judge_pay['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
break;
|
||
case '5':
|
||
//会员卡余额支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
case '2':
|
||
case '7':
|
||
//银行卡支付 其他支付
|
||
$Order['pay_type'] = 5;
|
||
break;
|
||
default:
|
||
$result['status'] = 0;
|
||
$result['msg'] = '参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$goodsList = json_decode($orderInfo, true);
|
||
$vip['v_discount'] = $v_discount;
|
||
$verify = $this->goodsVerify_v1($goodsList, $store, $vip);
|
||
$res['data'] = $verify;
|
||
if ($verify['status'] == 0) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = $verify['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
//创建订单
|
||
$Order ['adminid'] = $adminid;
|
||
$Order ['order_type'] = 1;
|
||
$Order ['storeid'] = intval($store['id']);
|
||
$Order ['order_state'] = 'WAIT_BUYER_PAY';
|
||
$Order ['code'] = $code;
|
||
$Order ['face_token'] = $faceToken;
|
||
$Order ['cdate'] = time();
|
||
$Order ['state'] = 0;
|
||
$Order ['merchantid'] = $merchantid;
|
||
if ($vid) {
|
||
$Order ['vid'] = $vid;
|
||
}
|
||
$orderId = $PayOrderModel->addOrder($Order);
|
||
if ($orderId) {
|
||
$out_trade_no = $this->createOrderTradeNo($orderId);
|
||
$up = $PayOrderModel->updateOrder(array('id' => $orderId), array('out_trade_no' => $out_trade_no));
|
||
if ($up) {
|
||
$item = array(
|
||
'orderInfo' => $verify['data'],
|
||
'order' => $verify,
|
||
'storeid' => $storeid,
|
||
'merchantid' => $merchantid,
|
||
'paytype' => $payType,
|
||
'admin_id' => $adminid,
|
||
'vid' => $vid,
|
||
'discount' => $discount,
|
||
'cardnum' => $vip ? $vip['cardnum'] : '',
|
||
'small_changes_money' => $small_changes_money,
|
||
'coupon' => $coupon,
|
||
'guideid' => $guideid,
|
||
'out_trade_no' => $out_trade_no,
|
||
'pay_orderid' => $orderId,
|
||
'm_pay_type' => $Order['m_pay_type'],
|
||
'disMoney' => $verify['disMoney'],
|
||
'allMoney' => $verify['allMoney'],
|
||
'amountReceived' => $payType == 1 ? $amountReceived : 0,
|
||
'isZeroStorage' => $payType == 1 ? $isZeroStorage : 0,
|
||
);
|
||
$create = A("Sellapi/NewPay")->createBillOrder_v3($item);
|
||
if ($create['status'] == 1) {
|
||
$PayOrderModel->updateOrder(array('id' => $orderId), array('trade_amount' => $create['all_money']));
|
||
$Order['id'] = $orderId;
|
||
$Order['out_trade_no'] = $out_trade_no;
|
||
$Order['trade_amount'] = $create['all_money'];
|
||
$Order['merchantid'] = $item['merchantid'];
|
||
switch ($payType) {
|
||
case 3:
|
||
//微信
|
||
if ($Order['m_pay_type'] == 3) {
|
||
//新大陆支付
|
||
A('Pay/PayContinent')->toContinentPay($Order, $create['bill_id'], $store['storetag']);
|
||
} else {
|
||
A('Pay/NewWxPay')->toWxPay($Order, $create['bill_id'], $config);
|
||
}
|
||
break;
|
||
case 4:
|
||
//支付宝
|
||
if ($Order['m_pay_type'] == 3) {
|
||
//新大陆支付
|
||
A('Pay/PayContinent')->toContinentPay($Order, $create['bill_id'], $store['storetag']);
|
||
} else {
|
||
A('Pay/NewAliPay')->toAliPay($Order, $create['bill_id'], $config);
|
||
}
|
||
|
||
break;
|
||
case 1:
|
||
case 7:
|
||
case 2:
|
||
//现金,银行卡,其他
|
||
$change = A('Sellapi/NewPay')->changeOrder($create['bill_id'], $payType);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $create['all_money'];
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $out_trade_no;
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $out_trade_no;
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
$this->ajaxReturn($data);
|
||
break;
|
||
case 5:
|
||
//会员卡
|
||
$this->newToVipPay_v4($Order, $create['bill_id'], $password, $vip, $cardCode, $vipPayType);
|
||
break;
|
||
}
|
||
} else {
|
||
$result['create'] = $create;
|
||
$result['status'] = 0;
|
||
$result['msg'] = $create['msg'];
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '订单创建失败请重试';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
}
|
||
|
||
protected function goodsVerify($goodsList, $store, $vip)
|
||
{
|
||
$tempGoods = array();
|
||
$tempId = array();
|
||
$tempEndId = array();
|
||
foreach ($goodsList as $key => $val) {
|
||
if ($val['goods_type'] == 2) {
|
||
$tempGoods[] = $val;
|
||
$tempId[] = 0;
|
||
} else {
|
||
$index = array_search($val['id'], $tempId);
|
||
if ($index !== false) {
|
||
$tempGoods[$index]['num'] = round($tempGoods[$index]['num'] + $val['num'], 3);
|
||
} else {
|
||
$tempGoods[] = $val;
|
||
$tempId[] = $val['id'];
|
||
}
|
||
}
|
||
$tempEndId[] = $val['id'];
|
||
}
|
||
$endGoods = array();
|
||
$allMoney = 0;
|
||
$beforeMoney = 0;
|
||
foreach ($goodsList as $value) {
|
||
if ($value['goods_type'] == 2) {
|
||
if ($value['can_exchange_weigh'] == 1 && $value['num'] != intval($value['num']) || $value['can_exchange_weigh'] == 2 && round($value['num'], 3) != round($value['num'], 4)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '无码商品数量格式有误';
|
||
return $res;
|
||
}
|
||
$temp['goods_id'] = 0;
|
||
$temp['goods_type'] = 2;
|
||
$temp['yuan_price'] = $value['retail_price'];
|
||
$temp['price'] = $value['retail_price'];
|
||
$temp['purch_price'] = $value['retail_price'];
|
||
$temp['can_exchange_weigh'] = $value['can_exchange_weigh'];
|
||
$sell_number = 1;
|
||
$money = round($temp['price'] * $value['num'], 2);
|
||
} else {
|
||
$index = array_search($value['id'], $tempId);
|
||
if (empty($tempGoods[$index]['goods'])) {
|
||
$goods = M('retail_goods')->where(array('storeid' => $store['id'], 'status' => 0, 'id' => $value['id']))->find();
|
||
if (empty($goods)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品已下架或不存在';
|
||
return $res;
|
||
}
|
||
$tempGoods[$index]['goods'] = $goods;
|
||
} else {
|
||
$goods = $tempGoods[$index]['goods'];
|
||
}
|
||
if ($goods['can_exchange_weigh'] == 1 && $value['num'] != intval($value['num']) || $goods['can_exchange_weigh'] == 2 && round($value['num'], 3) != round($value['num'], 4)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品数量格式有误';
|
||
return $res;
|
||
}
|
||
if ((float)$goods['goods_num'] < (float)$tempGoods[$index]['num'] && $store['goods_empty_sell_status'] == 0 && empty($value['sku'])) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '库存不足' . $value['num'];
|
||
return $res;
|
||
} else if (!empty($value['sku']) && $goods['attribute'] == 1) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '规格已关闭';
|
||
return $res;
|
||
} else if (empty($value['sku']) && $goods['attribute'] == 2 && $goods['can_exchange_weigh'] == 1) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '开启规格,请刷新选择规格';
|
||
return $res;
|
||
} else {
|
||
if (!empty($value['sku'])) {
|
||
$sku = M('retail_sku_goods')->where(array('goods_id' => $value['id'], 'id' => $value['sku'][0]['id'], 'state' => 0))->find();
|
||
if (empty($sku)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格不存在,请刷新商品重试';
|
||
return $res;
|
||
} else if ((float)$sku['goods_num'] < (float)$value['num'] && $store['goods_empty_sell_status'] == 0) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '(' . $value['sku'][0]['name'] . ')' . '库存不足' . $value['num'];
|
||
return $res;
|
||
} else {
|
||
$temp['yuan_price'] = $sku['retail_price'];
|
||
$temp['good_img'] = $sku['goods_img'];
|
||
$temp['purch_price'] = $sku['purch_price'];
|
||
$temp['vip_price'] = $sku['store_mem_price'];
|
||
$sku['name'] = $value['sku'][0]['name'];
|
||
$temp['sku_json_info'] = json_encode($sku);
|
||
$temp['attribute'] = 2;
|
||
$money = round($value['num'] * $sku['retail_price'], 2);
|
||
if ($vip != 0 && $value['store_mem_status'] == 1) {
|
||
if (!round($sku['store_mem_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '(' . $value['sku'][0]['name'] . ')' . '会员价设置有误';
|
||
return $res;
|
||
}
|
||
$sku['retail_price'] = $sku['store_mem_price'];
|
||
}
|
||
if ($vip != 0 && $vip['v_discount'] != 1 && $goods['vip_retail_state'] == 1) {
|
||
$temp['price'] = round($sku['retail_price'] * $vip['v_discount'], 2);
|
||
$temp['price'] = $temp['price'] > 0.01 ? $temp['price'] : 0.01;
|
||
$temp['discount'] = $vip['v_discount'];
|
||
} else {
|
||
$temp['price'] = $sku['retail_price'];
|
||
}
|
||
$sell_number = $sku['sku_num'];
|
||
}
|
||
} else {
|
||
$temp['yuan_price'] = $goods['retail_price'];
|
||
$temp['vip_price'] = $goods['store_mem_price'];
|
||
$temp['good_img'] = $goods['good_image'];
|
||
$temp['purch_price'] = $goods['purch_price'];
|
||
$money = round($value['num'] * $goods['retail_price'], 2);
|
||
if ($vip != 0 && $value['store_mem_status'] == 1) {
|
||
if (!round($goods['store_mem_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '会员价设置有误';
|
||
return $res;
|
||
}
|
||
$goods['retail_price'] = $goods['store_mem_price'];
|
||
}
|
||
if ($vip != 0 && $vip['v_discount'] != 1 && $goods['vip_retail_state'] == 1) {
|
||
$temp['price'] = round($goods['retail_price'] * $vip['v_discount'], 2);
|
||
$temp['price'] = $temp['price'] > 0.01 ? $temp['price'] : 0.01;
|
||
$temp['discount'] = $vip['v_discount'];
|
||
} else {
|
||
$temp['price'] = $goods['retail_price'];
|
||
}
|
||
$sell_number = 1;
|
||
}
|
||
$temp['goods_id'] = $value['id'];
|
||
$temp['goods_name'] = $goods['goods_name'];
|
||
$temp['goods_number'] = $goods['good_number'];
|
||
$temp['class_id'] = $goods['goods_class_id'];
|
||
$temp['can_exchange_weigh'] = $goods['can_exchange_weigh'];
|
||
$temp['goods_type'] = 1;
|
||
}
|
||
}
|
||
$money = $money > 0.01 ? $money : 0.01;
|
||
$beforeMoney += $money;
|
||
if ($vip != 0) {
|
||
$temp['isvip'] = 1;
|
||
$temp['vid'] = $vip['id'];
|
||
}
|
||
$temp['type'] = 2;
|
||
$temp['paytype'] = 0;
|
||
$temp['num'] = $value['num'];
|
||
$temp['addtime'] = time();
|
||
$temp['storeid'] = $store['id'];
|
||
$temp['merchantid'] = $store['merchantid'];
|
||
$temp['allmoney'] = round($temp['price'] * $temp['num'], 2);
|
||
$temp['allmoney'] = $temp['allmoney'] > 0.01 ? $temp['allmoney'] : 0.01;
|
||
$temp['sell_number'] = $sell_number;
|
||
$endGoods[] = $temp;
|
||
$allMoney += $temp['allmoney'];
|
||
unset($temp);
|
||
}
|
||
// file_put_contents('./goodsVerify.txt',json_encode($endGoods));
|
||
$allMoney = round($allMoney, 2);
|
||
$disMoney = round($beforeMoney - $allMoney, 2);
|
||
$res['status'] = 1;
|
||
$res['msg'] = '验证成功';
|
||
$res['allMoney'] = $allMoney;
|
||
$res['disMoney'] = $disMoney;
|
||
$res['data'] = $endGoods;
|
||
return $res;
|
||
}
|
||
|
||
/*
|
||
* plus会员版本2019-5-15
|
||
*/
|
||
protected function goodsVerify_v1($goodsList, $store, $vip)
|
||
{
|
||
$tempGoods = array();
|
||
$tempId = array();
|
||
$tempEndId = array();
|
||
foreach ($goodsList as $key => $val) {
|
||
if ($val['goods_type'] == 2) {
|
||
$tempGoods[] = $val;
|
||
$tempId[] = 0;
|
||
} else {
|
||
$index = array_search($val['id'], $tempId);
|
||
if ($index !== false) {
|
||
$tempGoods[$index]['num'] = round($tempGoods[$index]['num'] + $val['num'], 3);
|
||
} else {
|
||
$tempGoods[] = $val;
|
||
$tempId[] = $val['id'];
|
||
}
|
||
}
|
||
$tempEndId[] = $val['id'];
|
||
}
|
||
$endGoods = array();
|
||
$allMoney = 0;
|
||
$beforeMoney = 0;
|
||
foreach ($goodsList as $value) {
|
||
if ($value['goods_type'] == 2) {
|
||
if ($value['can_exchange_weigh'] == 1 && $value['num'] != intval($value['num']) || $value['can_exchange_weigh'] == 2 && round($value['num'], 3) != round($value['num'], 4)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '无码商品数量格式有误';
|
||
return $res;
|
||
}
|
||
$temp['goods_id'] = 0;
|
||
$temp['goods_type'] = 2;
|
||
$temp['yuan_price'] = $value['retail_price'];
|
||
$temp['price'] = $value['retail_price'];
|
||
$temp['purch_price'] = $value['retail_price'];
|
||
$temp['can_exchange_weigh'] = $value['can_exchange_weigh'];
|
||
$sell_number = 1;
|
||
$money = round($temp['price'] * $value['num'], 2);
|
||
} else {
|
||
$index = array_search($value['id'], $tempId);
|
||
if (empty($tempGoods[$index]['goods'])) {
|
||
$goods = M('retail_goods')->where(array('storeid' => $store['id'], 'status' => 0, 'id' => $value['id']))->find();
|
||
if (empty($goods)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品已下架或不存在';
|
||
return $res;
|
||
}
|
||
$tempGoods[$index]['goods'] = $goods;
|
||
} else {
|
||
$goods = $tempGoods[$index]['goods'];
|
||
}
|
||
if ($goods['can_exchange_weigh'] == 1 && $value['num'] != intval($value['num']) || $goods['can_exchange_weigh'] == 2 && round($value['num'], 3) != round($value['num'], 4)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品数量格式有误';
|
||
return $res;
|
||
}
|
||
if ((float)$goods['goods_num'] < (float)$tempGoods[$index]['num'] && $store['goods_empty_sell_status'] == 0 && empty($value['sku'])) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '库存不足' . $value['num'];
|
||
return $res;
|
||
} else if (!empty($value['sku']) && $goods['attribute'] == 1) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '规格已关闭';
|
||
return $res;
|
||
} else if (empty($value['sku']) && $goods['attribute'] == 2 && $goods['can_exchange_weigh'] == 1) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '开启规格,请刷新选择规格';
|
||
return $res;
|
||
} else {
|
||
if (!empty($value['sku'])) {
|
||
$sku = M('retail_sku_goods')->where(array('goods_id' => $value['id'], 'id' => $value['sku'][0]['id'], 'state' => 0))->find();
|
||
if (empty($sku)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '规格不存在,请刷新商品重试';
|
||
return $res;
|
||
} else if ((float)$sku['goods_num'] < (float)$value['num'] && $store['goods_empty_sell_status'] == 0) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '(' . $value['sku'][0]['name'] . ')' . '库存不足' . $value['num'];
|
||
return $res;
|
||
} else {
|
||
$temp['yuan_price'] = $sku['retail_price'];
|
||
$temp['good_img'] = $sku['goods_img'];
|
||
$temp['purch_price'] = $sku['purch_price'];
|
||
$temp['vip_price'] = $sku['store_mem_price'];
|
||
$sku['name'] = $value['sku'][0]['name'];
|
||
$temp['sku_json_info'] = json_encode($sku);
|
||
$temp['attribute'] = 2;
|
||
$money = round($value['num'] * $sku['retail_price'], 2);
|
||
if (!empty($vip) && $vip['plus_type'] == 2) {//plus会员
|
||
if ($value['plus_mem_status'] == 1) {
|
||
if (!round($sku['plus_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '(' . $value['sku'][0]['name'] . ')' . 'Plus会员价设置有误';
|
||
return $res;
|
||
}
|
||
$sku['retail_price'] = $sku['plus_price'];
|
||
} else if ($value['store_mem_status'] == 1) {
|
||
if (!round($sku['store_mem_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '(' . $value['sku'][0]['name'] . ')' . '会员价设置有误';
|
||
return $res;
|
||
}
|
||
$sku['retail_price'] = $sku['store_mem_price'];
|
||
}
|
||
} else if (!empty($vip)) {//常规会员
|
||
if ($value['store_mem_status'] == 1) {
|
||
if (!round($sku['store_mem_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '(' . $value['sku'][0]['name'] . ')' . '会员价设置有误';
|
||
return $res;
|
||
}
|
||
$sku['retail_price'] = $sku['store_mem_price'];
|
||
}
|
||
}
|
||
if ($vip != 0 && $vip['v_discount'] != 1 && $goods['vip_retail_state'] == 1) {
|
||
$temp['price'] = round($sku['retail_price'] * $vip['v_discount'], 2);
|
||
$temp['price'] = $temp['price'] > 0.01 ? $temp['price'] : 0.01;
|
||
$temp['discount'] = $vip['v_discount'];
|
||
} else {
|
||
$temp['price'] = $sku['retail_price'];
|
||
}
|
||
$sell_number = $sku['sku_num'];
|
||
}
|
||
} else {
|
||
$temp['yuan_price'] = $goods['retail_price'];
|
||
$temp['vip_price'] = $goods['store_mem_price'];
|
||
$temp['good_img'] = $goods['good_image'];
|
||
$temp['purch_price'] = $goods['purch_price'];
|
||
$money = round($value['num'] * $goods['retail_price'], 2);
|
||
if (!empty($vip) && $vip['plus_type'] == 2) {//plus会员
|
||
if ($value['plus_mem_status'] == 1) { //开启plus会员价
|
||
if (!round($goods['plus_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . 'Plus会员价设置有误';
|
||
return $res;
|
||
}
|
||
$goods['retail_price'] = $goods['plus_price'];
|
||
} else if ($value['store_mem_status'] == 1) {
|
||
if (!round($goods['store_mem_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '会员价设置有误';
|
||
return $res;
|
||
}
|
||
$goods['retail_price'] = $goods['store_mem_price'];
|
||
}
|
||
} else if (!empty($vip)) {//常规会员
|
||
if ($value['store_mem_status'] == 1) {
|
||
if (!round($goods['store_mem_price'], 2)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商品' . $goods['goods_name'] . '会员价设置有误';
|
||
return $res;
|
||
}
|
||
$goods['retail_price'] = $goods['store_mem_price'];
|
||
}
|
||
}
|
||
|
||
if (!empty($vip) && $vip['v_discount'] != 1 && $goods['vip_retail_state'] == 1) {
|
||
$temp['price'] = round($goods['retail_price'] * $vip['v_discount'], 2);
|
||
$temp['price'] = $temp['price'] > 0.01 ? $temp['price'] : 0.01;
|
||
$temp['discount'] = $vip['v_discount'];
|
||
} else {
|
||
$temp['price'] = $goods['retail_price'];
|
||
}
|
||
$sell_number = 1;
|
||
}
|
||
$temp['goods_id'] = $value['id'];
|
||
$temp['goods_name'] = $goods['goods_name'];
|
||
$temp['goods_number'] = $goods['good_number'];
|
||
$temp['class_id'] = $goods['goods_class_id'];
|
||
$temp['can_exchange_weigh'] = $goods['can_exchange_weigh'];
|
||
$temp['goods_type'] = 1;
|
||
}
|
||
}
|
||
$money = $money > 0.01 ? $money : 0.01;
|
||
$beforeMoney += $money;
|
||
if ($vip != 0) {
|
||
$temp['isvip'] = 1;
|
||
$temp['vid'] = $vip['id'];
|
||
}
|
||
$temp['type'] = 2;
|
||
$temp['paytype'] = 0;
|
||
$temp['num'] = $value['num'];
|
||
$temp['addtime'] = time();
|
||
$temp['storeid'] = $store['id'];
|
||
$temp['merchantid'] = $store['merchantid'];
|
||
$temp['allmoney'] = round($temp['price'] * $temp['num'], 2);
|
||
$temp['allmoney'] = $temp['allmoney'] > 0.01 ? $temp['allmoney'] : 0.01;
|
||
$temp['sell_number'] = $sell_number;
|
||
$endGoods[] = $temp;
|
||
$allMoney += $temp['allmoney'];
|
||
unset($temp);
|
||
}
|
||
// file_put_contents('./goodsVerify.txt',json_encode($endGoods));
|
||
$allMoney = round($allMoney, 2);
|
||
$disMoney = round($beforeMoney - $allMoney, 2);
|
||
$res['status'] = 1;
|
||
$res['msg'] = '验证成功';
|
||
$res['allMoney'] = $allMoney;
|
||
$res['disMoney'] = $disMoney;
|
||
$res['data'] = $endGoods;
|
||
return $res;
|
||
}
|
||
|
||
protected function newToVipPay_v4($Order, $bill_id, $password, $vipInfo, $cardCode, $vipPayType)
|
||
{
|
||
if ($vipPayType == 1) {
|
||
$map = array(
|
||
'code' => $cardCode,
|
||
'status' => 1,
|
||
'state' => 0,
|
||
'merchantid' => $Order['merchantid'],
|
||
'use_storeid' => $Order['storeid']
|
||
);
|
||
$old = M('vip_dynamic_code')->where($map)->find();
|
||
if (empty($old) || $old['failure_time'] <= time()) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请会员刷新动态码';
|
||
$this->ajaxReturn($res);
|
||
} else {
|
||
M('vip_dynamic_code')->where($map)->save(array('status' => 2));
|
||
}
|
||
} else {
|
||
$CryptrModel = new \Addons\Api\Crypto ();
|
||
$orignPwd = $CryptrModel->encrypt($password, date('YmdHis', $vipInfo['addtime']));
|
||
if ($orignPwd != $vipInfo['password']) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡密码错误';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
}
|
||
$payMoney = $Order['trade_amount'];
|
||
if ($vipInfo['balance'] < $payMoney) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '会员卡余额不足,无法支付';
|
||
} else {
|
||
$pay = M('retail_vip')->where(array('id' => $vipInfo['id']))->setDec('balance', $payMoney);
|
||
$add1['storeid'] = $Order['storeid'];
|
||
$add1['merchantid'] = $Order['merchantid'];
|
||
$add1['billid'] = $bill_id;
|
||
$add1['adminid'] = $Order['adminid'];
|
||
$add1['money'] = $payMoney;
|
||
$add1['allmoney'] = $payMoney;
|
||
$add1['state'] = 1;
|
||
$add1['type'] = 2;
|
||
$add1['addtime'] = time();
|
||
$add1['vid'] = $vipInfo['id'];
|
||
$add1['remark'] = '收银机支付' . $payMoney . '元';
|
||
$add = M('recharge_order')->add($add1);
|
||
if ($pay) {
|
||
$res['status'] = 1;
|
||
$res['recharge_id'] = $add;
|
||
$change = A('Sellapi/NewPay')->changeOrder($bill_id, 5);
|
||
$save['order_state'] = 'SUCCESS';
|
||
$save['tradedate'] = time();
|
||
$save['trade_amount'] = $payMoney;
|
||
M('retail_pay_order')->where(array('id' => $Order['id']))->save($save);
|
||
if ($change) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '收款成功';
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['order_id'] = $Order['out_trade_no'];
|
||
$data['msg'] = '收款成功,订单状态修改失败,请联系管理员';
|
||
}
|
||
} else {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '系统出差啦,请重试';
|
||
}
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
/* 判断支付
|
||
* @param
|
||
* $merchantid
|
||
* @param
|
||
* $storeid
|
||
* @return array
|
||
* */
|
||
public function judge_pay($merchantid, $storeid)
|
||
{
|
||
/* 2091-4-2 */
|
||
$agent_id = D('Merchant')->get_agent_id($merchantid); // 获取代理商ID
|
||
if (!$agent_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '未知的商户信息';
|
||
return $res;
|
||
}
|
||
$pay_pattern = D('PayPattern')->get_pay_pattern($agent_id); // 获取代理商支付权限
|
||
if (!$pay_pattern) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无开启的支付模式';
|
||
return $res;
|
||
}
|
||
$config = D('Payset')->getFindConfig($storeid); // 获取商户微信配置信息
|
||
if (empty($config)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商家支付参数未配置';
|
||
return $res;
|
||
}
|
||
$pay_state = array();
|
||
if ($pay_pattern['general_pay'] == 1) {
|
||
array_push($pay_state, '1');
|
||
}
|
||
if ($pay_pattern['service_pay'] == 1) {
|
||
array_push($pay_state, '2');
|
||
}
|
||
if ($pay_pattern['new_continent_pay'] == 1) {
|
||
array_push($pay_state, '3');
|
||
}
|
||
$res['status'] = 1;
|
||
$res['pay_state'] = $pay_state;
|
||
$res['config'] = $config;
|
||
return $res;
|
||
}
|
||
|
||
public function getFacePayInitializeData()
|
||
{
|
||
$adminid = I('post.adminid'); //收银员id
|
||
$storeid = I('post.storeid'); //门店id
|
||
if (empty($storeid) || empty($adminid)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '缺少参数';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$admin = M('retail_cashier')->where(array('id' => $adminid, 'storeid' => $storeid))->find();
|
||
if (empty($admin)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '收银员账号有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$store = D('Store')->getFind(array('id' => $storeid, 'store_status' => 0)); //判断门店是否正常使用中
|
||
if (empty($store)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '门店状态异常';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
$config = D('Payset')->getFindConfig($storeid);//获取商户微信配置信息
|
||
if ($config['al_pay_state'] != 1 && $config['al_pay_state'] != 2) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商户未开启刷脸支付';
|
||
$this->ajaxReturn($data);
|
||
}
|
||
if ($config['al_pay_state'] == 1) {
|
||
$appid = $config['alipay_appid'];
|
||
$pid = $config['alipay_sellerid'];
|
||
} else {
|
||
$set = M('systemconfig')->where(array('partnerid' => array('gt', 0), 'status' => 1))->order('id asc')->find();
|
||
$appid = $set['alipay_appid'];
|
||
$pid = $config['alipay_sellerid'];
|
||
}
|
||
if (empty($appid) || empty($pid)) {
|
||
$data['status'] = 0;
|
||
$data['msg'] = '商户未配置刷脸支付';
|
||
} else {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '查询成功';
|
||
$data['appid'] = $appid;
|
||
$data['pid'] = $pid;
|
||
}
|
||
$this->ajaxReturn($data);
|
||
}
|
||
|
||
public function customer()
|
||
{
|
||
$keys = I('post.keys'); //设备机器参数
|
||
$merchantid = I('post.merchantid'); //商户id
|
||
if (!empty($keys) && !empty($merchantid)) {
|
||
$config = M('retail_payset')->where(array('merchantid' => $merchantid))->find();
|
||
vendor('AopSDK.AopClient');
|
||
$item = json_decode(urldecode($keys), true);
|
||
if ($config["al_pay_state"] == 1) {
|
||
if (empty($config['alipay_appid']) || empty($config['alipay_private_key']) || empty($config['alipay_public_key'])) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '商家支付宝参数未配置';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$aop = new \AopClient ();
|
||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||
$aop->appId = $config['alipay_appid'];
|
||
$aop->rsaPrivateKey = $config['alipay_private_key'];
|
||
$aop->alipayrsaPublicKey = $config['alipay_public_key'];
|
||
$aop->apiVersion = '1.0';
|
||
$aop->signType = 'RSA2';
|
||
$aop->postCharset = 'utf-8';
|
||
$aop->format = 'json';
|
||
} else {
|
||
$partnerid = M("retail_merchant")->where(array('id' => $merchantid))->getField("partnerid");
|
||
$AliPay = M("systemconfig")->where(array("partnerid" => $partnerid))->find();
|
||
if (empty($AliPay['alipay_appid']) || empty($AliPay['alipay_private_key']) || empty($AliPay['alipay_public_key'])) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '商家支付宝参数未配置';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$aop = new \AopClient ();
|
||
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
|
||
$aop->appId = $AliPay['alipay_appid'];
|
||
$aop->rsaPrivateKey = $AliPay['alipay_private_key'];
|
||
$aop->alipayrsaPublicKey = $AliPay['alipay_public_key'];
|
||
$aop->apiVersion = '1.0';
|
||
$aop->signType = 'RSA2';
|
||
$aop->postCharset = 'utf-8';
|
||
$aop->format = 'json';
|
||
}
|
||
vendor('AopSDK.request.ZolozAuthenticationCustomerSmilepayInitializeRequest');
|
||
$request = new \ZolozAuthenticationCustomerSmilepayInitializeRequest ();
|
||
$request->setBizContent(json_encode($item));
|
||
if ($config['al_pay_state'] == 1) {
|
||
$result = $aop->execute($request);
|
||
} else if ($config['al_pay_state'] == 2) {
|
||
$result = $aop->execute($request, "", $config['alipay_token']);
|
||
}
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '缺少参数';
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} |