硕顺crm后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.4 KiB

<?php
namespace app\api\controller;
use addons\qingdong\model\Order;
use app\common\controller\Api;
use EasyWeChat\Factory;
use think\Controller;
use think\Db;
use think\response\Json;
/**
* 示例接口
*/
class Pay extends Controller
{
public function test()
{
return ["code"=>200];
}
public function notify(){
// 创建 EasyWeChat 实例
$payment = config('payment');
$app = Factory::payment($payment);
// 处理支付回调通知
$response = $app->handlePaidNotify(function ($message, $fail) {
// 处理订单支付状态更新等业务逻辑
// 用户是否支付成功
if ($message['result_code'] === 'SUCCESS') {
$extra['transaction_id'] =
// 获取订单信息
$order_no = $message['out_trade_no']; // 假设订单号在回调通知中的字段名为 out_trade_no
$total_free = $message['total_fee']; // 假设订单金额在回调通知中的字段名为 total_fee
$orderModel = new Order();
$order = $orderModel->where("order_no","=",$order_no)->find();
if(!$order || $order['pay_status'] == 1){
return true;
}
$update = [
"pay_status" => 1,
"pay_way" => 1,
"pay_money" => round($total_free/100,2),
"pay_time" => time(),
"transaction_id" =>$message['transaction_id'],
];
$orderModel->where("id","=",$order['id'])->update($update);
//获取权限 更新当前企业的权限
$product = Db::name("product")->where("id",'=',$order['org_id'])->find();
if($product){
$group_id = $product['group_id'];
$expire_time = strtotime("+1 years");
$update2 = [
"group_id" => $group_id,
"expire_time" => $expire_time,
"is_pay" => 1,
"is_default" => 0,
];
Db::name("company")->where("id","=",$order['cid'])->update($update2);
}
}
// 返回 true 告诉 EasyWeChat 支付通知处理成功
return true;
});
return $response;
}
}