|
@@ -5,6 +5,8 @@ namespace app\controller\mini;
|
|
|
use app\extra\basic\Base;
|
|
use app\extra\basic\Base;
|
|
|
use app\model\saas\SaasGoods;
|
|
use app\model\saas\SaasGoods;
|
|
|
use app\model\saas\SaasOrderLife;
|
|
use app\model\saas\SaasOrderLife;
|
|
|
|
|
+use app\model\saas\SaasOrderLog;
|
|
|
|
|
+use app\model\saas\SaasStore;
|
|
|
use LinFly\Annotation\Route\Controller;
|
|
use LinFly\Annotation\Route\Controller;
|
|
|
use LinFly\Annotation\Route\Route;
|
|
use LinFly\Annotation\Route\Route;
|
|
|
use support\Request;
|
|
use support\Request;
|
|
@@ -26,15 +28,51 @@ class Notify extends Base
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
$param = $request->post();
|
|
$param = $request->post();
|
|
|
- echo getDateFull()."==webhook==\n";
|
|
|
|
|
- print_r($param);
|
|
|
|
|
if (empty($param['event'])) return error("参数错误");
|
|
if (empty($param['event'])) return error("参数错误");
|
|
|
if (empty($param['content'])) return error("参数错误");
|
|
if (empty($param['content'])) return error("参数错误");
|
|
|
- $return = match ($param['event']) {
|
|
|
|
|
- "verify_webhook" => ['challenge' => $param['content']['challenge']],
|
|
|
|
|
- default => [],
|
|
|
|
|
- };
|
|
|
|
|
- print_r($return);
|
|
|
|
|
|
|
+ switch ($param['event']) {
|
|
|
|
|
+ case "verify_webhook":
|
|
|
|
|
+ $return = ['challenge' => $param['content']['challenge']];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "life_trade_order_notify": // 支付成功
|
|
|
|
|
+ $resp = json_decode($param['content'], true);
|
|
|
|
|
+ if ($resp['action'] == "pay_success") {
|
|
|
|
|
+ $order = (new SaasOrderLife)->where("order_id",$resp['order']['order_id'])->findOrEmpty();
|
|
|
|
|
+ if ($order->isEmpty()) {
|
|
|
|
|
+ $store = (new SaasStore)->where("store_id",$resp['order']['account_id'])->findOrEmpty();
|
|
|
|
|
+ $order->insertGetId([
|
|
|
|
|
+ "agent_id" => $store['agent_id']??'',
|
|
|
|
|
+ "store_id" => $store['store_id']??'',
|
|
|
|
|
+ "order_id" => $resp['order']['order_id'],
|
|
|
|
|
+ "pay_amount" => $resp['order']['pay_amount'],
|
|
|
|
|
+ "order_amount" => $resp['order']['original_amount'],
|
|
|
|
|
+ "pay_at" => getDateFull("",$resp['order']['pay_time'])
|
|
|
|
|
+ ]);
|
|
|
|
|
+ (new SaasOrderLog)->insertGetId([
|
|
|
|
|
+ "order_id" => $resp['order']['order_id'],
|
|
|
|
|
+ "title" => "发起订单",
|
|
|
|
|
+ "remark" => "下单并完成支付"
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $return = [];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "life_trade_certificate_notify": // 退款
|
|
|
|
|
+ $resp = json_decode($param['content'], true);
|
|
|
|
|
+ if ($resp['action'] == "refund_success") {
|
|
|
|
|
+ $order = (new SaasOrderLife)->where("order_id",$resp['order']['order_id'])->findOrEmpty();
|
|
|
|
|
+ if (!$order->isEmpty()) {
|
|
|
|
|
+ $order->status = 4;
|
|
|
|
|
+ $order->refund_at = getDateFull();
|
|
|
|
|
+ $order->save();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $return = [];
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ $return = [];
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
return json($return);
|
|
return json($return);
|
|
|
} catch (\Throwable $e) {
|
|
} catch (\Throwable $e) {
|
|
|
return error($e->getMessage());
|
|
return error($e->getMessage());
|