|
|
@@ -420,7 +420,48 @@ class DouYinService
|
|
|
throw new \Exception($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+ public static function sendRefundCreate($order_number)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // $params['order_number']
|
|
|
+ $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $order_number)->findOrEmpty();
|
|
|
+ if($order->isEmpty()){
|
|
|
+ throw new \Exception('订单不存在');
|
|
|
+ }
|
|
|
+ $orderInfo = $order->toArray();
|
|
|
+ $douyinRefundOrder = DouyinRefundOrder::where('order_number', $order_number)->order('id', 'desc')->findOrEmpty();
|
|
|
|
|
|
+ //通过后向抖音申请退款
|
|
|
+ //getClientToken()
|
|
|
+ $url = config('douyin.host').'api/trade_basic/v1/developer/refund_create/';
|
|
|
+ $data = [
|
|
|
+ "order_id" => $orderInfo['transaction_id'],
|
|
|
+ "out_refund_no" => $douyinRefundOrder->refund_number,
|
|
|
+ "cp_extra" => $orderInfo['id'].'|'.$douyinRefundOrder->id,
|
|
|
+ "order_entry_schema" => [
|
|
|
+ "path" => "page/index/index",
|
|
|
+ "params" => json_encode(['refund_number'=>$douyinRefundOrder->refund_number])
|
|
|
+ ],
|
|
|
+ "refund_total_amount " => $douyinRefundOrder->refund_amount * 100,
|
|
|
+ "notify_url" => config('douyin.refundNotifyUrl'),
|
|
|
+ "refund_reason" => [
|
|
|
+ [
|
|
|
+ "code" => 101,
|
|
|
+ "text" => "不想要了"
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $res = http_request($url,$data,['Content-Type' => 'application/json;charset=utf-8','access_token' => self::getClientToken()]);
|
|
|
+ if(isset($res['err_msg']) && $res['err_msg'] === 'success'){
|
|
|
+ $douyinRefundOrder->transaction_id = $res['data']['refund_id'];
|
|
|
+ $douyinRefundOrder->save();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::info($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
public static function refundNotify($params)
|
|
|
{
|
|
|
Db::startTrans();
|
|
|
@@ -452,6 +493,46 @@ class DouYinService
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 扩展点回调提交订单
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ * @throws \Exception
|
|
|
+ * @author liugc <466014217@qq.com>
|
|
|
+ * @date 2025/6/4 14:03
|
|
|
+ */
|
|
|
+ public static function submitOrderNotify($params)
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['out_refund_no'])->findOrEmpty();
|
|
|
+ if($douyinRefundOrder->isEmpty()){
|
|
|
+ throw new \Exception('退款订单不存在');
|
|
|
+ }
|
|
|
+ if($douyinRefundOrder->refund_status == 0){
|
|
|
+ if($params['status'] === 'SUCCESS'){
|
|
|
+ $douyinRefundOrder->refund_status = 3;
|
|
|
+ DouyinOrder::where('order_number', $douyinRefundOrder->order_number)->update([
|
|
|
+ 'order_status' => 4,
|
|
|
+ 'pay_status' => 3,
|
|
|
+ ]);
|
|
|
+ }elseif($params['status'] === 'FAIL'){
|
|
|
+ $douyinRefundOrder->refund_status = 4;
|
|
|
+ }else{
|
|
|
+ throw new \Exception('退款状态未知');
|
|
|
+ }
|
|
|
+ $douyinRefundOrder->save();
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static function byteAuthorization($privateKeyStr, $data, $appId, $nonceStr, $timestamp, $keyVersion) {
|
|
|
$byteAuthorization = '';
|
|
|
// 读取私钥
|
|
|
@@ -504,48 +585,7 @@ class DouYinService
|
|
|
return json_decode($cache_data, true)['access_token'];
|
|
|
}
|
|
|
|
|
|
- public static function sendRefundCreate($order_number)
|
|
|
- {
|
|
|
- try {
|
|
|
- // $params['order_number']
|
|
|
- $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $order_number)->findOrEmpty();
|
|
|
- if($order->isEmpty()){
|
|
|
- throw new \Exception('订单不存在');
|
|
|
- }
|
|
|
- $orderInfo = $order->toArray();
|
|
|
- $douyinRefundOrder = DouyinRefundOrder::where('order_number', $order_number)->order('id', 'desc')->findOrEmpty();
|
|
|
|
|
|
- //通过后向抖音申请退款
|
|
|
- //getClientToken()
|
|
|
- $url = config('douyin.host').'api/trade_basic/v1/developer/refund_create/';
|
|
|
- $data = [
|
|
|
- "order_id" => $orderInfo['transaction_id'],
|
|
|
- "out_refund_no" => $douyinRefundOrder->refund_number,
|
|
|
- "cp_extra" => $orderInfo['id'].'|'.$douyinRefundOrder->id,
|
|
|
- "order_entry_schema" => [
|
|
|
- "path" => "page/index/index",
|
|
|
- "params" => json_encode(['refund_number'=>$douyinRefundOrder->refund_number])
|
|
|
- ],
|
|
|
- "refund_total_amount " => $douyinRefundOrder->refund_amount * 100,
|
|
|
- "notify_url" => config('douyin.refundNotifyUrl'),
|
|
|
- "refund_reason" => [
|
|
|
- [
|
|
|
- "code" => 101,
|
|
|
- "text" => "不想要了"
|
|
|
- ]
|
|
|
- ]
|
|
|
- ];
|
|
|
- $res = http_request($url,$data,['Content-Type' => 'application/json;charset=utf-8','access_token' => self::getClientToken()]);
|
|
|
- if(isset($res['err_msg']) && $res['err_msg'] === 'success'){
|
|
|
- $douyinRefundOrder->transaction_id = $res['data']['refund_id'];
|
|
|
- $douyinRefundOrder->save();
|
|
|
- }
|
|
|
- return true;
|
|
|
- } catch (\Exception $e) {
|
|
|
- Log::info($e->getMessage());
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
}
|