|
|
@@ -3,6 +3,7 @@
|
|
|
namespace app\controller\api;
|
|
|
|
|
|
use app\extra\basic\Base;
|
|
|
+use app\extra\jhfPay\Utils;
|
|
|
use app\model\saas\SaasCart;
|
|
|
use app\model\saas\SaasOrder;
|
|
|
use app\model\saas\SaasOrderDetail;
|
|
|
@@ -11,6 +12,7 @@ use app\model\saas\SaasShopLog;
|
|
|
use app\model\saas\SaasUser;
|
|
|
use app\model\saas\SaasUserBuy;
|
|
|
use app\model\saas\SaasUserLog;
|
|
|
+use app\model\system\SystemUserMoney;
|
|
|
use LinFly\Annotation\Route\Controller;
|
|
|
use LinFly\Annotation\Route\Route;
|
|
|
use support\Request;
|
|
|
@@ -23,6 +25,31 @@ use WeChat\Contracts\Tools;
|
|
|
class Notify extends Base
|
|
|
{
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提现银行卡回调
|
|
|
+ */
|
|
|
+ #[Route(path: "withdraw",methods: "post")]
|
|
|
+ public function notifyWithdraw(Request $request): Response
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ echo getDateFull() . "===>提现银行卡异步返回\n";
|
|
|
+ $data = $this->jhfReturn($request->all(),"withdraw.succeeded");
|
|
|
+ if (empty($data)) return error("提现失败");
|
|
|
+ if ($data['status'] == "succeeded") // 成功了
|
|
|
+ {
|
|
|
+ $day = date("Y-m-d",strtotime("-1 day"));
|
|
|
+ $todayMoney = (new SystemUserMoney)->where("member_id",$data['member_id'])->where("day",$day)->select();
|
|
|
+ if ($todayMoney->count() > 0) {
|
|
|
+ $state = (new SystemUserMoney)->where("member_id",$data['member_id'])->where("day",$day)->update(['status' => 1,"withdraw_id" => $data['withdraw_id']]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return success("ok");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ return error($throwable->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 退款回调
|
|
|
* @param Request $request
|
|
|
@@ -31,32 +58,35 @@ class Notify extends Base
|
|
|
public function notifyRefund(Request $request)
|
|
|
{
|
|
|
try {
|
|
|
- echo getDateFull() . "===>退款申请返回\n";
|
|
|
- $payResp = $request->rawBody();
|
|
|
- $wechat = new \WePay\Refund($this->getWxConfig());
|
|
|
- if (empty($payResp)) return $wechat->getNotifySuccessReply();
|
|
|
- $data = $wechat->getNotify($payResp);
|
|
|
- if (empty($data)) return $wechat->getNotifySuccessReply();
|
|
|
- $orderSn = explode("-",$data['result']['out_refund_no']);
|
|
|
- $order = (new SaasOrder)->where("order_sn",$orderSn[0])->with(['shop' => function($query){
|
|
|
+ $data = $this->jhfReturn($request->all(),"refund.succeeded");
|
|
|
+ if (empty($data)) return error("支付失败");
|
|
|
+// $payResp = $request->rawBody();
|
|
|
+// $wechat = new \WePay\Refund($this->getWxConfig());
|
|
|
+// if (empty($payResp)) return $wechat->getNotifySuccessReply();
|
|
|
+// $data = $wechat->getNotify($payResp);
|
|
|
+// if (empty($data)) return $wechat->getNotifySuccessReply();
|
|
|
+// $orderSn = explode("-",$data['attach']);
|
|
|
+ $order = (new SaasOrder)->where("order_sn",$data['attach'])->with(['shop' => function($query){
|
|
|
$query->field('shop_id,shop_name,shop_address');
|
|
|
}])->findOrEmpty();
|
|
|
- if ($order->isEmpty()) return $wechat->getNotifySuccessReply();
|
|
|
- if ($order['status'] <> 4) return $wechat->getNotifySuccessReply();
|
|
|
+ if ($order->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
+ if ($order['status'] <> 4) return $this->getNotifySuccessReply();
|
|
|
$order->status = 6;
|
|
|
+ $order->refund_at = getDateFull();
|
|
|
$order->save();
|
|
|
(new SaasOrderDetail)->where("order_sn",$order['order_sn'])->update(['status' => 6]);
|
|
|
+ $orderMoney = (($order['money'] > $order['discount']) ? $order['discount'] : $order['money']);
|
|
|
// 商家账户额度退款
|
|
|
$shop = (new SaasShop)->where("shop_id",$order['shop_id'])->with(['wx' => function($query){
|
|
|
$query->field("shop_id,openid,is_msg");
|
|
|
}])->findOrEmpty();
|
|
|
if ($shop->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
- $shop->balance = Db::raw("balance-".$order['discount']);
|
|
|
- $shop->total_balance = Db::raw("total_balance-".$order['discount']);
|
|
|
+ $shop->balance = $shop['balance'] - $orderMoney;
|
|
|
+ $shop->total_balance = $shop['total_balance'] - $orderMoney;
|
|
|
$shop->save();
|
|
|
(new SaasShopLog)->insertGetId([
|
|
|
"shop_id" => $order['shop_id'],
|
|
|
- "money" => $order['discount'],
|
|
|
+ "money" => $orderMoney,
|
|
|
"balance" => $shop->balance,
|
|
|
"remark" => "订单退款【{$order['order_sn']}】",
|
|
|
"type" => 2
|
|
|
@@ -96,24 +126,26 @@ class Notify extends Base
|
|
|
public function notifyWx(Request $request)
|
|
|
{
|
|
|
try {
|
|
|
- echo getDateFull()."===>支付返回\n";
|
|
|
- $payResp = $request->rawBody();
|
|
|
- $data = $this->payReturn($payResp);
|
|
|
+ $data = $this->jhfReturn($request->all());
|
|
|
+ if (empty($data)) return error("支付失败");
|
|
|
+// $payResp = $request->rawBody();
|
|
|
+// $data = $this->payReturn($payResp);
|
|
|
$order = (new SaasOrder)->where("order_sn",$data['attach'])->with(['shop' => function($query){
|
|
|
$query->field('shop_id,shop_name,shop_address');
|
|
|
}])->findOrEmpty();
|
|
|
- if ($order->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
- if ($order['status'] <> 0) return $this->getNotifySuccessReply(); // 已支付或者是其他状态
|
|
|
+ if ($order->isEmpty()) return "success";
|
|
|
+ if ($order['status'] <> 0) return "success"; // 已支付或者是其他状态
|
|
|
$order->status = 1;
|
|
|
$order->pay_at = getDateFull();
|
|
|
$order->transaction_id = $data['transaction_id']??'';
|
|
|
+ $order->payment_id = $data['payment_id']??'';
|
|
|
$order->notify_status = 1;
|
|
|
$order->pay_type = 1;
|
|
|
$order->save();
|
|
|
$shop = (new SaasShop)->where("shop_id",$order['shop_id'])->with(['wx' => function($query){
|
|
|
$query->field("shop_id,openid,is_msg");
|
|
|
}])->findOrEmpty();
|
|
|
- if ($shop->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
+ if ($shop->isEmpty()) return "success";
|
|
|
$shop->balance = Db::raw("balance+".$order['money']);
|
|
|
$shop->total_balance = Db::raw("total_balance+".$order['money']);
|
|
|
$shop->save();
|
|
|
@@ -123,7 +155,7 @@ class Notify extends Base
|
|
|
"balance" => $shop->balance,
|
|
|
"remark" => "新订单【{$order['order_sn']}】"
|
|
|
]);
|
|
|
- events("create-order",['shop' => $order['shop_id'],'openid' => $order['openid'],"order" => $order['order_sn']]);
|
|
|
+ events("create-order",['shop' => $order['shop_id'],'print' => $order['print_id'],'openid' => $order['openid'],"order" => $order['order_sn']]);
|
|
|
// 推送消息-公众号
|
|
|
if (!empty($shop['wx'])) {
|
|
|
$obj = \We::WeChatTemplate([
|
|
|
@@ -149,9 +181,9 @@ class Notify extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $this->getNotifySuccessReply();
|
|
|
+ return "success";
|
|
|
} catch (\Throwable $throwable) {
|
|
|
- return error($throwable->getMessage());
|
|
|
+ return "success";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -164,11 +196,11 @@ class Notify extends Base
|
|
|
{
|
|
|
try {
|
|
|
echo getDateFull()."===>充值并支付支付返回\n";
|
|
|
- $payResp = $request->rawBody();
|
|
|
- $data = $this->payReturn($payResp);
|
|
|
+ $data = $this->jhfReturn($request->all());
|
|
|
+ if (empty($data)) return error("支付失败");
|
|
|
$orderBuy = (new SaasUserBuy)->where("order_sn",$data['attach'])->with(['orders'])->findOrEmpty();
|
|
|
- if ($orderBuy->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
- if ($orderBuy['status'] <> 0) return $this->getNotifySuccessReply(); // 已支付或者是其他状态
|
|
|
+ if ($orderBuy->isEmpty()) return "success";
|
|
|
+ if ($orderBuy['status'] <> 0) return "success"; // 已支付或者是其他状态
|
|
|
$orderMoney = 0;
|
|
|
$logData[0] = [
|
|
|
"openid" => $orderBuy['openid'],
|
|
|
@@ -196,12 +228,13 @@ class Notify extends Base
|
|
|
};
|
|
|
$orderBuy->status = 1;
|
|
|
$orderBuy->pay_at = getDateFull();
|
|
|
+ $orderBuy->payment_id = $data['payment_id']??'';
|
|
|
$orderBuy->transaction_id = $data['transaction_id']??'';
|
|
|
$orderBuy->save();
|
|
|
$shop = (new SaasShop)->where("shop_id",$orderBuy['shop_id'])->with(['wx' => function($query){
|
|
|
$query->field("shop_id,openid,is_msg");
|
|
|
}])->findOrEmpty();
|
|
|
- if ($shop->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
+ if ($shop->isEmpty()) return "success";
|
|
|
// 开通vip账户
|
|
|
$card = (new SaasUser)->where("card_no",$orderBuy['card_no'])->findOrEmpty();
|
|
|
$balanceMoney = $orderBuy['total_money'] - $orderMoney;
|
|
|
@@ -223,15 +256,15 @@ class Notify extends Base
|
|
|
if (!empty($orderBuy['orders']))
|
|
|
{
|
|
|
$order = (new SaasOrder)->where("order_sn",$orderBuy['order_sn'])->findOrEmpty();
|
|
|
- if ($order->isEmpty()) return $this->getNotifySuccessReply();
|
|
|
- if ($order['status'] <> 0) return $this->getNotifySuccessReply(); // 已支付或者是其他状态
|
|
|
+ if ($order->isEmpty()) return "success";
|
|
|
+ if ($order['status'] <> 0) return "success"; // 已支付或者是其他状态
|
|
|
$order->status = 1;
|
|
|
$order->pay_at = getDateFull();
|
|
|
$order->transaction_id = $data['transaction_id']??'';
|
|
|
$order->notify_status = 1;
|
|
|
$order->pay_type = 2;
|
|
|
$order->save();
|
|
|
- events("create-order",['shop' => $order['shop_id'],'openid' => $order['openid'],"order" => $order['order_sn']]);
|
|
|
+ events("create-order",['shop' => $order['shop_id'],'print' => $order['print_id'],'openid' => $order['openid'],"order" => $order['order_sn']]);
|
|
|
}
|
|
|
$shop->balance = Db::raw("balance+".$orderBuy['money']);
|
|
|
$shop->total_balance = Db::raw("total_balance+".$orderBuy['money']);
|
|
|
@@ -269,7 +302,7 @@ class Notify extends Base
|
|
|
}
|
|
|
}
|
|
|
(new SaasUserLog)->insertAll($logData);
|
|
|
- return $this->getNotifySuccessReply();
|
|
|
+ return "success";
|
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
|
}
|
|
|
@@ -283,13 +316,37 @@ class Notify extends Base
|
|
|
{
|
|
|
try {
|
|
|
echo getDateFull()."===>会员卡支付返回\n";
|
|
|
- $payResp = $request->rawBody();
|
|
|
- $data = $this->payReturn($payResp);
|
|
|
+ $data = $this->jhfReturn($request->all());
|
|
|
+ if (empty($data)) return error("支付失败");
|
|
|
+
|
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 第三方支付返回
|
|
|
+ * @param array $respData
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function jhfReturn(array $respData = [],string $return = "payment.succeeded"): array
|
|
|
+ {
|
|
|
+ if ($respData['type'] <> $return) return [];
|
|
|
+ $resCipher = Utils::aes_decrypt($respData['resCipher'], sConf("wechat.jhf_aeskey"));
|
|
|
+ $data = json_decode($resCipher,true);
|
|
|
+ if ($return == "withdraw.succeeded") {
|
|
|
+ print_r($data);
|
|
|
+ }
|
|
|
+ $data['attach'] = $data['order_no'];
|
|
|
+ $data['transaction_id'] = $data['out_trans_id']??'';
|
|
|
+ $data['payment_id'] = $data['payment_id']??'';
|
|
|
+ $data['withdraw_id'] = $data['withdraw_id']??'';
|
|
|
+ $data['member_id'] = $data['member_id']??'';
|
|
|
+ $data['status'] = $data['status']??'';
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
protected function payReturn($payResp)
|
|
|
{
|
|
|
$wechat = new \WeChat\Pay($this->getWxConfig());
|
|
|
@@ -306,7 +363,8 @@ class Notify extends Base
|
|
|
*/
|
|
|
protected function getNotifySuccessReply(): string
|
|
|
{
|
|
|
- return Tools::arr2xml(['return_code' => 'SUCCESS', 'return_msg' => 'OK']);
|
|
|
+// return Tools::arr2xml(['return_code' => 'SUCCESS', 'return_msg' => 'OK']);
|
|
|
+ return json(['return_code' => 'SUCCESS', 'return_msg' => 'OK']);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -328,36 +386,4 @@ class Notify extends Base
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- #[Route(path: "test",methods: "get")]
|
|
|
- public function testData()
|
|
|
- {
|
|
|
- try {
|
|
|
- $data = $this->_valid([
|
|
|
- "openid.default" => "otdgy3fYZ0JBHW7mbnxmdKTQJRUU",
|
|
|
- "shop.default" => "326945519114632",
|
|
|
- "order.default" => "202604022640934408406"
|
|
|
- ]);
|
|
|
- $cart = (new SaasCart)->where("shop_id",$data['shop'])->where("openid",$data['openid'])->order("create_at desc")->select();
|
|
|
- if ($cart->isEmpty()) return success('ok',['cart' => []]);
|
|
|
- $orderDetail = [];
|
|
|
- foreach ($cart->toArray() as $key=>$val)
|
|
|
- {
|
|
|
- unset($val['id']);
|
|
|
- $orderDetail[$key] = $val;
|
|
|
- $orderDetail[$key]['order_sn'] = $data['order'];
|
|
|
- if ($val['extension'] == "pdf") {
|
|
|
- $orderDetail[$key]['status'] = 1;
|
|
|
- } else {
|
|
|
- $orderDetail[$key]['status'] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- print_r($orderDetail);
|
|
|
- $state = (new SaasOrderDetail)->strict(false)->insertAll($orderDetail);
|
|
|
- return success("ok");
|
|
|
- } catch (\Throwable $throwable) {
|
|
|
- return error($throwable->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|