feat(store_order): 增加支付功能并修复相关bug
This commit is contained in:
parent
6dbd3b328b
commit
5eebccb700
@ -130,7 +130,7 @@ class StoreOrderController extends BaseAdminController
|
|||||||
$addressId = (int)$this->request->post('address_id');
|
$addressId = (int)$this->request->post('address_id');
|
||||||
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||||
$params = $this->request->post();
|
$params = $this->request->post();
|
||||||
if ($auth_code==''&&$pay_type!=PayEnum::CASH_PAY) {
|
if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {
|
||||||
return $this->fail('支付条码不能为空');
|
return $this->fail('支付条码不能为空');
|
||||||
}
|
}
|
||||||
if (count($cartId) > 100) {
|
if (count($cartId) > 100) {
|
||||||
@ -159,7 +159,7 @@ class StoreOrderController extends BaseAdminController
|
|||||||
Redis::send('send-code-pay', ['number' => $order['number']]);
|
Redis::send('send-code-pay', ['number' => $order['number']]);
|
||||||
return $this->success('用户支付中');
|
return $this->success('用户支付中');
|
||||||
}
|
}
|
||||||
return $this->success('支付成功', ['out_trade_no'=>$result['out_trade_no'],'pay_type'=>PayEnum::WECHAT_PAY_BARCODE,'transaction_id'=>$result['transaction_id']]);
|
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
|
||||||
case PayEnum::ALIPAY_BARCODE:
|
case PayEnum::ALIPAY_BARCODE:
|
||||||
//支付宝条码支付
|
//支付宝条码支付
|
||||||
$result = PaymentLogic::ali_auth_code($auth_code, $order);
|
$result = PaymentLogic::ali_auth_code($auth_code, $order);
|
||||||
@ -170,7 +170,7 @@ class StoreOrderController extends BaseAdminController
|
|||||||
return $this->success('用户支付中');
|
return $this->success('用户支付中');
|
||||||
}
|
}
|
||||||
$result['create_time'] = $order['create_time'];
|
$result['create_time'] = $order['create_time'];
|
||||||
return $this->success('支付成功', ['out_trade_no'=>$result['out_trade_no'],'pay_type'=>PayEnum::ALIPAY_BARCODE,'transaction_id'=>$result['trade_no']]);
|
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no']]);
|
||||||
default:
|
default:
|
||||||
return $this->fail('支付方式错误');
|
return $this->fail('支付方式错误');
|
||||||
}
|
}
|
||||||
@ -179,17 +179,73 @@ class StoreOrderController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pay()
|
||||||
|
{
|
||||||
|
$order_id = (int)$this->request->post('order_id');
|
||||||
|
$pay_type = (int)$this->request->post('pay_type');
|
||||||
|
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||||
|
if ($auth_code == '' && $pay_type != PayEnum::CASH_PAY) {
|
||||||
|
return $this->fail('支付条码不能为空');
|
||||||
|
}
|
||||||
|
$params = $this->request->post();
|
||||||
|
$where = [
|
||||||
|
'id' => $order_id,
|
||||||
|
'paid' => 0,
|
||||||
|
];
|
||||||
|
$order = StoreOrder::where($where)->find();
|
||||||
|
if (!$order) {
|
||||||
|
return $this->fail('订单不存在或已支付');
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($pay_type) {
|
||||||
|
|
||||||
|
case PayEnum::CASH_PAY:
|
||||||
|
//现金支付
|
||||||
|
PayNotifyLogic::handle('cash_pay', $order['order_id']);
|
||||||
|
return $this->success('现金支付成功');
|
||||||
|
break;
|
||||||
|
case PayEnum::WECHAT_PAY_BARCODE:
|
||||||
|
//微信条码支付
|
||||||
|
$result = PaymentLogic::codepay($auth_code, $order);
|
||||||
|
if (PaymentLogic::hasError()) {
|
||||||
|
return $this->fail(PaymentLogic::getError(), $params);
|
||||||
|
}
|
||||||
|
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||||
|
Log::error(json_encode($result));
|
||||||
|
PayNotifyLogic::handle('wechat_common', $result['out_trade_no'], $result);
|
||||||
|
} else {
|
||||||
|
Redis::send('send-code-pay', ['number' => $order['number']]);
|
||||||
|
return $this->success('用户支付中');
|
||||||
|
}
|
||||||
|
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
|
||||||
|
case PayEnum::ALIPAY_BARCODE:
|
||||||
|
//支付宝条码支付
|
||||||
|
$result = PaymentLogic::ali_auth_code($auth_code, $order);
|
||||||
|
if (PaymentLogic::hasError()) {
|
||||||
|
return $this->fail(PaymentLogic::getError(), $params);
|
||||||
|
}
|
||||||
|
if ($result['msg'] !== 'Success') {
|
||||||
|
return $this->success('用户支付中');
|
||||||
|
}
|
||||||
|
$result['create_time'] = $order['create_time'];
|
||||||
|
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::ALIPAY_BARCODE, 'transaction_id' => $result['trade_no']]);
|
||||||
|
default:
|
||||||
|
return $this->fail('支付方式错误');
|
||||||
|
}
|
||||||
|
return $this->fail('支付失败');
|
||||||
|
}
|
||||||
|
|
||||||
public function writeoff_order()
|
public function writeoff_order()
|
||||||
{
|
{
|
||||||
$params = (new OrderValidate())->post()->goCheck('check');
|
$params = (new OrderValidate())->post()->goCheck('check');
|
||||||
$count = StoreOrder::where('verify_code',$params['verify_code'])->count();
|
$count = StoreOrder::where('verify_code', $params['verify_code'])->count();
|
||||||
if(empty($count)){
|
if (empty($count)) {
|
||||||
return $this->fail('无该核销码请检查');
|
return $this->fail('无该核销码请检查');
|
||||||
}
|
}
|
||||||
$res = OrderLogic::writeOff($params);
|
$res = OrderLogic::writeOff($params);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
return $this->success('核销成功');
|
return $this->success('核销成功');
|
||||||
}
|
}
|
||||||
return $this->fail('核销失败'.OrderLogic::getError());
|
return $this->fail('核销失败' . OrderLogic::getError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user