REAPI/app/robot/controller/TaobaoAfterSalesBot.php
2024-09-29 15:43:18 +08:00

1010 lines
34 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\robot\controller;
use app\channel\service\ChannelService;
use app\channel\service\ProductService;
use app\gateway\service\CurlService;
use app\gateway\service\RedisService as redisObj;
use app\kami\service\LockCardService;
use app\merchant\service\MerchantService;
use app\merchant\service\OrderHistoryService;
use app\merchant\service\OrderLastHistoryService;
//use app\merchant\service\OrderLastweekHistoryService;
use app\merchant\service\OrderService;
use app\merchant\service\OrderTwoHistoryService;
use app\openapi\controller\Coretb;
use app\order\service\AfterSalesOrderService;
use app\order\service\Kami91OrderService;
use app\robot\controller\api\Qqbot;
use think\admin\Controller;
use app\core\Service as CoreService;
use think\exception\HttpResponseException;
use think\facade\Db;
use think\facade\Log;
class TaobaoAfterSalesBot extends Controller
{
protected $status_map=array(
-1=>'暂无订单',
-2=>'暂无卡密',
1=>'成功'
);
public function robot_tk(){
$input = input();
$mid = $input['mid'];
$info = Db::name('order_tk')->where(['status' => '1', 'mid' => $mid])->order('create_at', 'asc')->find();
if (!$info) {
$json = [
'code' => -1,
'msg' => '暂无订单需要处理'
];
throw new HttpResponseException(json($json));
}
$json = [];
$json['code'] = '1';
$json['order_id'] = $info['order_id'];
$json['tid'] = $info['merchant_order_id'];
throw new HttpResponseException(json($json));
}
/*
*查询订单获取卡密
* mid:商户id
* merchant_order_id商户订单号
**/
public function order_query(){
$input = input();
$mid = $input['mid'];
$merchant_order_id = $input['merchant_order_id'];
$json=[];
$info = Db::name('merchant_order')->where(['merchant_order_id' => $merchant_order_id, 'mid' => $mid])->find();
if (!$info) {
$info = Db::name('merchant_order_lastweek_history')->where(['merchant_order_id' => $merchant_order_id, 'mid' => $mid])->find();
}
if (!$info) {
$info = Db::name('merchant_order_last_history')->where(['merchant_order_id' => $merchant_order_id, 'mid' => $mid])->find();
}
if (!$info) {
$info = Db::name('merchant_order_two_history')->where(['merchant_order_id' => $merchant_order_id, 'mid' => $mid])->find();
}
if (!$info) {
$info = Db::name('merchant_order_history')->where(['merchant_order_id' => $merchant_order_id, 'mid' => $mid])->find();
}
if (!$info) {
$json = [
'code' => -1,
'msg' => $this->status_map[-1],
];
throw new HttpResponseException(json($json));
}
if (strpos($info['response'], 'kami') !== false) {
#
$channelService = ChannelService::instance();
$channelInfo = $channelService->get($info['cid']);
$kami=json_decode($info['response'],true)['kami'];
$cardno = $kami['cardno'];
$cardpwd = $kami['cardpwd'];
$expire_time = $kami['expired'];
if($channelInfo['suoka_status'] == 1){
$suoka = $channelService->call('lockCard', $info['cid'], $info);
if($suoka == 'ok' || $suoka == 'old_ok'){
$json=[
'code'=>1,
'msg'=>'锁卡成功',
'merchant_order_id'=>$merchant_order_id,
'cardno'=>$cardno,
'cardpwd'=>$cardpwd,
'channel' => $channelInfo['key'],
'suoka_status' => 2
];
}else{
$json=[
'code'=>1,
'msg'=>'锁卡失败',
'merchant_order_id'=>$merchant_order_id,
'cardno'=>$cardno,
'cardpwd'=>$cardpwd,
'channel' => $channelInfo['key'],
'suoka_status' => 3
];
}
}elseif($channelInfo['suoka_status'] == 2){
$LockCardService = LockCardService::instance();
$suoka = $LockCardService->call('suoka', $info['cid'],$cardno,$cardpwd,$info['pid'],$info['cash']);
if($suoka == 'ok' || $suoka == 'old_ok'){
$json=[
'code'=>1,
'msg'=>'锁卡成功',
'merchant_order_id'=>$merchant_order_id,
'channel' => $channelInfo['key'],
'cardno'=>$cardno,
'cardpwd'=>$cardpwd,
'suoka_status' => 2
];
}elseif($suoka == 'use_error'){
$json=[
'code'=>1,
'msg'=>'已使用',
'merchant_order_id'=>$merchant_order_id,'channel' => $channelInfo['key'],
'cardno'=>$cardno,
'cardpwd'=>$cardpwd,
'suoka_status' =>3
];
}else{
$json=[
'code'=>1,
'msg'=>'锁卡失败',
'merchant_order_id'=>$merchant_order_id,
'channel' => $channelInfo['key'],
'cardno'=>$cardno,
'cardpwd'=>$cardpwd,
'suoka_status' => 3
];
}
} else{
$json=[
'code'=>1,
'msg'=>'不支持锁卡',
'merchant_order_id'=>$merchant_order_id,
'cardno'=>$cardno,
'cardpwd'=>$cardpwd,
'channel' => $channelInfo['key'],
'suoka_status' => 4
];
}
} else {
$json = [
'code' => -2,
'msg' => $this->status_map[-2]
];
throw new HttpResponseException(json($json));
}
throw new HttpResponseException(json($json));
}
/**
* 锁卡
**/
public function suoka(){
$input = input();
$mid = $input['mid'];
$merchant_order_id = $input['merchant_order_id'];
$order = Db::name('merchant_order')->where(['merchant_order_id' => $merchant_order_id, 'mid' => $mid])->find();
$channelService = ChannelService::instance();
$LockCardService = LockCardService::instance();
$channelInfo = $channelService->get($order['cid']);
$response = json_decode($order['response'], true);
if($channelInfo['suoka_status'] == 1){
if (isset($response['kami'])) {
$suoka = $channelService->call('lockCard', $order['cid'], $order);
if($suoka == 'ok' || $suoka == 'old_ok'){
$json=[
'code'=>1,
'msg'=>'锁卡成功',
'merchant_order_id'=>$merchant_order_id
];
}else{
$json=[
'code'=>-1,
'msg'=>'锁卡失败',
'merchant_order_id'=>$merchant_order_id
];
// Log::write('queue', 'taobao_sh', $spRefund);#写入到日志里
}
}
}elseif($channelInfo['suoka_status'] == 2){
if (isset($response['kami'])) {
$cardno = $response['kami']['cardno'];
$cardpwd = $response['kami']['cardpwd'];
$expire_time = $response['kami']['expired'];
$suoka = $LockCardService->call('suoka', $order['cid'],$cardno,$cardpwd,$order['pid'],$order['cash']);
if($suoka == 'ok' || $suoka == 'old_ok'){
$json=[
'code'=>1,
'msg'=>'锁卡成功',
'merchant_order_id'=>$merchant_order_id
];
}elseif($suoka == 'use_error'){
$json=[
'code'=>-2,
'msg'=>'已使用',
'merchant_order_id'=>$merchant_order_id
];
}else{
$json=[
'code'=>-1,
'msg'=>'锁卡失败',
'merchant_order_id'=>$merchant_order_id
];
}
}
} else{
$json=[
'code'=>-3,
'msg'=>'不支持锁卡',
'merchant_order_id'=>$merchant_order_id
];
}
throw new HttpResponseException(json($json));
}
public function getNeedLockCardInfo(){
$input = input();
$mid = $input['mid'];
$aftersalesservice = AfterSalesOrderService::instance();
// $json['chanel'] = 'Zhongmaokami';
// $json['card_kind'] = '1';
// $json['code'] = '1';
// $json['order_id'] = 'C202405104378895658943964';
// $json['tid'] = '3882255041167148442';
// $json['cardno'] = 'ZQ5012593498';
// $json['cardpwd'] = '536816369959138';
// $json['lockcard_url'] = '#';
// $json['cash'] = '50';
//
//
// throw new HttpResponseException(json($json));
$found = false;
// $tstart=
while (!$found) {
$info = $aftersalesservice->db()->where(['status' => '9','mid'=>$mid])->whereNotNull('order_id')->order('create_at','asc')->find();
if(!$info){
$json = [
'code' => -1,
'msg' => '暂无订单需要处理'
];
throw new HttpResponseException(json($json));
}
$order = $this->getOrder($info['order_id']);
$response = json_decode($order['response'], true);
if (isset($response['kami'])) {
$found = true;
$cardno = $response['kami']['cardno'];
$cardpwd = $response['kami']['cardpwd'];
$cid = $order['cid'];
$pid = $order['pid'];
$suokaData = $this->getSuoKaData($order['cid'], $order['pid'], $order['cash']);
if ($suokaData == 'error'){
$update =['status' => '7'];
$aftersalesservice->db()->where(['order_id' => $info['order_id']])->update($update);
$found = false;
}
}else{
$update =['status' => '7'];
$aftersalesservice->db()->where(['order_id' => $info['order_id']])->update($update);
}
// if()
}
// var_dump($order);die;
$json = $suokaData;
$json['code'] = '1';
$json['order_id'] = $info['order_id'];
$json['tid'] = $info['merchant_order_id'];
$json['cardno'] = $cardno;
$json['cardpwd'] = $cardpwd;
$json['lockcard_url'] = '#';
$json['cash'] = $order['cash'];
throw new HttpResponseException(json($json));
}
protected function getOrder($order_id, $merchant_order_id = false ,$mid = false)
{
$orderService = OrderService::instance();
$order = $orderService->get($order_id, $merchant_order_id ,$mid);
// if (!$order) {
// $orderLastweekHistoryService = OrderLastweekHistoryService::instance();
// $order = $orderLastweekHistoryService->get($order_id, $merchant_order_id ,$mid);
// }
if (!$order) {
$orderLastHistoryService = OrderLastHistoryService::instance();
$order = $orderLastHistoryService->get($order_id, $merchant_order_id ,$mid);
}
if (!$order) {
$orderTwoHistoryService = OrderTwoHistoryService::instance();
$order = $orderTwoHistoryService->get($order_id, $merchant_order_id ,$mid);
}
if (!$order) {
$orderHistoryService = OrderHistoryService::instance();
$order = $orderHistoryService->get($order_id, $merchant_order_id ,$mid);
}
return $order;
}
public function getSuoKaData($cid,$pid,$cash)
{
$suokaData = [];
$ChannelService = ChannelService::instance();
$channelInfo = $ChannelService->get($cid);
if(!$channelInfo){
return 'error';
}
$suokaData['chanel'] = $channelInfo['key'];
$suokaData['card_kind'] = $this->get_card_kind($pid, $cash);
return $suokaData;
}
public function contactbuyer()
{
$order_id = input('order_id');
$aftersalesservice = AfterSalesOrderService::instance();
$afterOrder = $aftersalesservice->db()->field('mid,order_id,merchant_order_id,buyer_open_uid')->where(['order_id' => $order_id])->findOrEmpty();
$merchant = MerchantService::instance()->get($afterOrder['mid']);
// $request = [];
$other_param = json_decode($merchant['other_param'], true);
// $request['agentId'] = $other_param['reapi_appkey'];
$appkey = $other_param['reapi_appkey'];
$openuid = $afterOrder['buyer_open_uid'];
// $request['agentkey'] = $other_param['reapi_appsecret'];
// $request['access_token'] = $merchant['access_token'];
// $aliim_url = "aliim:sendmsg?&touid=&siteid=cntaobao&status=2&portalId=&gid=&itemsId=&scene=&toRole=&source=light&client=false&encryptuid=&bizdomain=taobao&openappkey=34598038&openuid=AAFr_s_xAOVdyqRLzmmtdyEy&sceneparam=[object%20Object]";
$aliim_url = "aliim:sendmsg?&openappkey={$appkey}&openuid=".$openuid;
$this->redirect($aliim_url);
}
protected function getUrl($url)
{
$host = sysconf('system_host');
if (!$host) {
if (isset($_SERVER['SERVER_PORT']) && isset($_SERVER['HTTP_HOST'])) {
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$host = $protocol.$_SERVER['HTTP_HOST'];
} else {
$host = 'http://111.229.70.26';
}
}
return $host . $url;
}
public function refuse()
{
}
#============================================================================================================
public function get_card_kind($pid,$cash)
{
$ChanelProductService = ProductService::instance();
$info = $ChanelProductService->getInfo($pid);
if ($info) {
if (isset($info['gid_rule']) && $info['gid_rule']) {
$rule = json_decode($info['gid_rule'], true);
if (isset($rule[$cash]) && $rule[$cash]) {
$gid = $rule[$cash];
return $gid;
}
}
if (isset($info['gid']) && $info['gid']) {
return $info['gid'];
}
}
}
public function getrefundInfo(){
$input = input();
$mid = $input['mid'];
$aftersalesservice = AfterSalesOrderService::instance();
$found = false;
// $tstart=
while (!$found) {
// create_at 2024-04-04 00:00:26
$info = $aftersalesservice->db()->where(['status' => '8','mid'=>$mid])->whereNotNull('order_id')->order('create_at','asc')->find();
if(!$info){
$json = [
'code' => -1,
'msg' => '暂无订单需要处理'
];
throw new HttpResponseException(json($json));
}
$order = $this->getOrder($info['order_id']);
if(strtotime($order['create_at']) < strtotime('2024-04-05 00:00:00')){
$update =['status' => '7'];
$aftersalesservice->db()->where(['order_id' => $info['order_id']])->update($update);
$merchant = MerchantService::instance()->get($order['mid']);
$request = [];
$other_param = json_decode($merchant['other_param'], true);
$request['agentId'] = $other_param['reapi_appkey'];
$request['agentkey'] = $other_param['reapi_appsecret'];
$request['access_token'] = $merchant['access_token'];
$this->tradeUpdate($order['order_id'], $request,6);
$found = false;
}else{
$response = json_decode($order['response'], true);
if (isset($response['kami'])) {
$found = true;
$cardno = $response['kami']['cardno'];
$cardpwd = $response['kami']['cardpwd'];
$cid = $order['cid'];
$pid = $order['pid'];
$suokaData = $this->getSuoKaData($order['cid'], $order['pid'], $order['cash']);
if ($suokaData == 'error'){
$update =['status' => '7'];
$aftersalesservice->db()->where(['order_id' => $info['order_id']])->update($update);
$found = false;
}
}else{
$update =['status' => '7'];
$aftersalesservice->db()->where(['order_id' => $info['order_id']])->update($update);
}
}
// if()
}
// var_dump($order);die;
$json = $suokaData;
$json['code'] = '1';
$json['order_id'] = $info['order_id'];
$json['tid'] = $info['merchant_order_id'];
$json['cardno'] = $cardno;
$json['cardpwd'] = $cardpwd;
// http://111.229.70.26/robot/TaobaoAfterSalesBot/contactbuyer?order_id=
// B202404196645084354434432
$json['qn_url'] = 'https://qn.taobao.com/home.htm/trade-platform/refund-list/detail?disputeId='.$info['refund_id'] .'&type=1';
// $json['qn_url'] = $this->getUrl('/robot/TaobaoAfterSalesBot/contactbuyer?order_id=' . $info['order_id'] );
$json['cash'] = $order['cash'];
throw new HttpResponseException(json($json));
}
public function tradeUpdate($merchant_order_id,$request,$beizhu = 1)
{
$request['merchant_order_id'] = $merchant_order_id;
$request['flag'] = 1;
if($beizhu == 1){
$request['flag'] = 4;
$request['beizhu'] = "卡密已使用,已经自动操作拒绝退款--Reapi系统自动化";
}elseif($beizhu == 2){
$request['beizhu'] = "卡密未激活,机器人暂不支持锁卡,请人工操作锁卡并退款--Reapi系统自动化";
}elseif ($beizhu == 3){
$request['beizhu'] = "此订单不存在中控系统中,可能属于早期订单,请人工核实处理--Reapi系统自动化";
}elseif ($beizhu == 4){
$request['beizhu'] = "未在千牛里找到订单号,请人工核实处理--Reapi系统自动化";
}elseif ($beizhu == 5){
$request['flag'] = 2;
$request['beizhu'] = "机器人暂不支持此渠道,请人工处理--Reapi系统自动化";
}elseif ($beizhu == 6){
$request['beizhu'] = "此订单为早期订单,机器人暂不支持,请人工处理--Reapi系统自动化";
}elseif ($beizhu == 7){
$request['flag'] = 3;
$request['beizhu'] = "卡密未激活,机器人已经锁卡,并自动退款--Reapi系统自动化";
}elseif ($beizhu == 8){
$request['beizhu'] = "卡密未激活,机器人已经锁卡,自动退款退款失败,请人工操作--Reapi系统自动化";
}
$request['reset'] = "false";
// $request['access_token'] = $merchant['access_token'];
$response = Coretb::taobaosdk('tradeUpdate', $request);
$json = json_encode($response);
$array = json_decode($json, true);
if (isset($array['Trade']['tid']) && $array['Trade']['tid'] == $merchant_order_id) {
return 'ok';
} else {
return 'error';
}
}
public function verifyCode(){
$img = input('imgId');
$path = root_path();
$path = $path . "extend/" . 'yzm' . DIRECTORY_SEPARATOR;
$image_path = $path.$img;
$image_data = file_get_contents($image_path);
$base64_data = base64_encode($image_data);
// print_r($base64_data);die;
$host = "https://yzmcolor.market.alicloudapi.com";
$path = "/yzmSpeed";
$method = "POST";
$appcode = "5f8716f9b70d4cf8a2350ead55a8f40c";
$bodys = "v_pic=".$base64_data;
$type = 'application/x-www-form-urlencoded';
$response = $this->send_aliapi($host,$path,$method,$appcode,$bodys,$type);
if(str_contains($response, "查询成功")){
$start = '"v_code":"';
$end = '","errCode';
$substr = substr($response, strlen($start)+strpos($response, $start),(strlen($response) - strpos($response, $end))*(-1));
echo $substr;die;
}else{
$path = "/api/decode_yzm_v2";
$param = ['img_base64' => $base64_data];
$bodys = json_encode($param);
$type = 'application/json';
$response = $this->send_aliapi($host,$path,$method,$appcode,$bodys,$type);
if(str_contains($response, "请求成功")){
$start = 'yzm":"';
$end = '","success';
$substr = substr($response, strlen($start)+strpos($response, $start),(strlen($response) - strpos($response, $end))*(-1));
echo $substr;die;
}else{
var_dump($response);
\dever\Log::write('robot', 'taobao_verifyCode', $response);
echo 'error';die;
// Log::write($response)
}
// \dever\Log::write('robot', 'taobao_verifyCode', $response);
// echo 'error';die;
// Log::write($response)
}
}
public function send_aliapi($host,$path,$method,$appcode,$bodys,$type)
{
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//根据API的要求定义相对应的Content-Type
array_push($headers, "Content-Type".":".$type."; charset=UTF-8");
// $querys = "";
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos("$".$host, "https://"))
{
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
$response = curl_exec($curl);
return $response;
}
public function robotHandleStatus()
{
// sRet = HTTP.Get(ReapiNeedkfURL&"?tip=1&order_id="&系统订单号, {}, 60000)
$input = input();
$tip = $input['tip'];
$order_id = $input['order_id'];
$order = $this->getOrder($order_id);
$merchant_order_id = $order['merchant_order_id'];
$aftersalesservice = AfterSalesOrderService::instance();
$merchant = MerchantService::instance()->get($order['mid']);
$request = [];
$other_param = json_decode($merchant['other_param'], true);
$request['agentId'] = $other_param['reapi_appkey'];
$request['agentkey'] = $other_param['reapi_appsecret'];
$request['access_token'] = $merchant['access_token'];
#==================================================
$send = new Qqbot($this->app);
$url = 'send_group_msg';
#
$param = array();
$atqq = '785557837';#需要艾特的qq
$atqq1 = '386892273';
$param['group_id'] = '770225115';#群组号
switch ($tip){
case "1":
$this->tradeUpdate($merchant_order_id, $request,2);
//
$msg = $merchant_order_id.'锁卡失败人工处理';
$update = [
'status' => '7'
];
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "]".$msg ;
// $response = $send->send($url, $param);
// if (isset($response['status']) && $response['status'] == 'ok') {
//
// } else {
// \dever\Log::write('robot', 'taobaoRobot', $msg);
// }
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "2":
$msg = $merchant_order_id.'未找到卡号,请人工核实';
$update = [
'status' => '7'
];
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "]".$msg ;
// $response = $send->send($url, $param);
// if (isset($response['status']) && $response['status'] == 'ok') {
//
// } else {
// \dever\Log::write('robot', 'taobaoRobot', $msg);
// }
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "4":
$this->tradeUpdate($merchant_order_id, $request);
// $msg = $merchant_order_id.'未找到卡号,请人工核实';
$update = [
'status' => '5'
];
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "5":
$this->tradeUpdate($merchant_order_id, $request,4);
$msg = $merchant_order_id.'未找到订单号,请人工核实';
$update = [
'status' => '7'
];
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "]".$msg ;
// $response = $send->send($url, $param);
// if (isset($response['status']) && $response['status'] == 'ok') {
//
// } else {
// \dever\Log::write('robot', 'taobaoRobot', $msg);
// }
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "6":
$this->tradeUpdate($merchant_order_id, $request,5);
$msg = $merchant_order_id.'机器人暂不支持此渠道,请人工核实处理';
$update = [
'status' => '7'
];
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "]".$msg ;
// $response = $send->send($url, $param);
// if (isset($response['status']) && $response['status'] == 'ok') {
//
// } else {
// \dever\Log::write('robot', 'taobaoRobot', $msg);
// }
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "7":
$update = [
'status' => '3'
];
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "8":
$aftersalesOrder = $aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->findOrEmpty();
$spRefund = $this->refundsp($aftersalesOrder,$request);
if($spRefund == 'true'){
$request['sub_code'] =$merchant['sub_code'];
$caozuo_refunf = $this->refundtk($aftersalesOrder,$request,0);
if($caozuo_refunf != 'error'){
$this->tradeUpdate($merchant_order_id, $request,7);
$update['status'] = '2';
}else{
$this->tradeUpdate($merchant_order_id, $request,8);
// Log::write('queue', 'taobao_sh', $caozuo_refunf);#写入到日志里
$update['status'] = '7';
}
}else{
$this->tradeUpdate($merchant_order_id, $request,8);
$update['status'] = '7';
}
// $update = [
// 'status' => '2'
// ];
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
case "9":
$update = [
'status' => '9'
];
$aftersalesservice->db()->where(['merchant_order_id' => $merchant_order_id])->update($update);
break;
}
}
public function refundsp($vo,$request)
{
$request['caozuo_name'] = '系统自动处理';
$request['refundId'] = $vo['refund_id'];
$request['phase'] = $vo['refund_phase'];
$RefundVersion = json_decode($vo['infodata'],true);
$RefundVersion = $RefundVersion['refund_version'];
$request['RefundVersion'] = $RefundVersion;
$request['RefundMsg'] = '未使用,同意退款';#默认同意
$request['RefundStatus'] = 'true';
// $request['access_token'] = $merchant['access_token'];
$response = Coretb::taobaosdk('refundSp', $request);
$json = json_encode($response);
$array = json_decode($json, true);
if($array['is_success'] == 'true'){
return 'true';
}else{
\dever\Log::write('queue', 'taobao_sp', $array);#写入到日志里
return 'error';
}
#判断响应是否成功
}
public function refundtk($vo,$request,$num = 0)
{
$RefundVersion = $this->refundget($vo,$request);
if($RefundVersion != 'error'){
$cash = $vo['refund_fee'] * 100;
$request['refund_infos'] = $vo['refund_id'].'|'.$cash.'|'.$RefundVersion .'|'.$vo['refund_phase'];
$response = Coretb::taobaosdk('refundAgree', $request);
$json = json_encode($response);
$array = json_decode($json, true);
if(isset($array['sub_msg']) ){
if(str_contains($array['sub_msg'], "未审核状态")){
while ($num<1) {
$num++;
sleep(3);
return $this->refundtk($vo,$request,$num,);
}
}
}
if (isset($array['succ'])) {
if(isset($array['message']) && $array['message']=='操作成功'){
return 'ok';
}else{
Log::write('queue', 'taobao_tk', $array);#写入到日志里
return 'error';
}
} else {
Log::write('queue', 'taobao_tk', $array);#写入到日志里
return 'error';
}
}else {
Log::write('queue', 'taobao_tk', $RefundVersion);#写入到日志里
return 'error';
}
}
public function refundget($vo,$request)
{
if(isset($request['sub_code'])){
unset($request['sub_code']);
}
$request['refundId'] = $vo['refund_id'];
// $request['access_token'] = $merchant['access_token'];
$response = Coretb::taobaosdk('refundInfo', $request);
$json = json_encode($response);
$array = json_decode($json, true);
if (isset($array['refund'])) {
$array = $array['refund'];
$RefundVersion = $array['refund_version'];
return $RefundVersion;
} else {
return 'error';
}
}
# 是否检测数据
// protected bool $check = false;
# 查询接口 一般用于查询数据,同步执行
# 提交接口 一般用于提交数据,异步执行
public function send($url, $param)
{
$geturl = 'http://127.0.0.1:7374/' . $url;
return http_post($geturl, $param);
}
public function send_post($notify_url, $post_data, $type): mixed
{
$postdate = http_build_query($post_data);
$options = array(
'http' => array(
'method' => $type,
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdate,
'timeout' => 15 * 60 // 超时时间(单位:s
)
);
$context = stream_context_create($options);
return file_get_contents($notify_url, false, $context);
}
protected function curl($method, $url, $param = array(), $json = false, $header = false):mixed
{
if ($param) {
$log['type'] = 'request';
$log['url'] = $url;
$log['param'] = $param;
$this->log($log);
}
$curl = CurlService::getInstance($url, $param, $method, $json, $header);
$curl->setTimeOut(3600);
return $curl->result();
}
protected static function log($data, $type = 'request'):void
{
\dever\Log::write('kami91', $type, $data);
// \dever\Log::write('jingdong', $type, $data);
}
}