Asynchronous notification and verification order method of calling SDK after payment in WeChat applet

不言
Release: 2018-06-27 11:58:06
Original
2433 people have browsed it

The following is a WeChat applet that uses the SDK’s asynchronous notification and verification method to process orders after payment. It has a good reference value and I hope it will be helpful to everyone

Asynchronous verification and order processing after the applet

$orderNo])->lock(true)->find(); // $order = Order::get(['order_no'=>$orderNo]); //如果未支付 if ($order->status == 1) { $service = new \app\api\service\Order(); //查询到该订单号的商品和库存量信息 $stockStatus = $service->checkOrderStock($order->id); //如果库存量有,更新订单状态,以及减去商品库存 if ($stockStatus['pass']) { $this->updateOrderStatus($order->id, true); $this->reduceStock($stockStatus); //如果没有库存,订单状态修改为已支付,但订单未处理 } else { $this->updateOrderStatus($order->id, false); } } Db::commit(); //返回给微信 return true; }catch (Exception $e){ Db::rollback(); return fasle; } }else{ //如果微信返回失败的处理信息,那我们这里依然返回true,向微信表明态度 return true; } } //支付成功,减去商品库存 private function reduceStock($stockStatus) { //遍历减去 foreach ($stockStatus['pStatusArray'] as $v) { //使用tp5的setDec方法 Product::where(['id'=>$v['id']])->setDec('stock',$v['count']); } } //success为真,则订单修改为PAID,如果为假则修改为已支付,但订单未处理的状态,对应枚举信息修改 private function updateOrderStatus($orderID,$success) { $status = $success?OrderStatusEnum::PAID:OrderStatusEnum::PAID_BUT_OUT_OF; Order::where(['id'=>$orderID])->update(['status'=>$status]); } }
Copy after login

The controller is as follows:

public function receiveNotify() { //1:检查库存量防止超卖 //2:更新status状态 //3:减库存 //如果成功处理,返回成功处理信息,否则返回没有成功处理信息 $notify = new WxNotify(); $notify->handle(); }
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Implementation of shopping cart function in WeChat mini program

Communication between pages in WeChat mini program Method

Introduction to defining global data and function reuse and templates in WeChat mini-program

The above is the detailed content of Asynchronous notification and verification order method of calling SDK after payment in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!