1105 lines
36 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\openapi\controller;
require_once(__DIR__ . "/../../../extend/sdk/taobao/UpdateOrders.php");
use app\channel\service\ChannelService;
use app\gateway\service\AuthService;
2024-09-29 15:43:18 +08:00
use app\gateway\service\RedisService;
use app\merchant\service\MerchantService;
2024-09-30 21:25:57 +08:00
use app\merchant\service\MerchantMappingProductService;
2024-09-29 15:43:18 +08:00
use app\merchant\service\OrderHistoryService;
use app\merchant\service\OrderLastHistoryService;
use app\merchant\service\OrderLastweekHistoryService;
2024-09-29 15:43:18 +08:00
use app\merchant\service\OrderService;
use app\merchant\service\OrderTwoHistoryService;
use app\setting\service\BlackCardService;
use dever\Log;
use think\admin\Controller;
use think\exception\HttpResponseException;
2024-09-29 15:43:18 +08:00
/**
* taobao接口核心控制器
* Class Core
* @package app\openapi\service
*/
class Coretb extends Controller
{
# 是否检测数据
protected bool $check = true;
# 商户appid
protected string $appid = '';
# 商户id
protected int $mid = 0;
# 商户信息
protected array $merchant = array();
# token key
protected string $key = '';
# product key
protected string $product = 'query';
# proid
protected $proid = 0;
2024-09-29 15:43:18 +08:00
# bizType
protected string $bizType = '';
# input
protected array $input = array();
# sign_type
protected int $sign_type = 1;
protected array $header = [
'Content-type' =>'text/xml; charset=GBK'
];
protected array $options=[
'encoding' => 'GBK',
];
# code码定义
protected array $code = array
(
# 成功
1 => 'ok',
# 淘宝错误代码
'9999' => '未知错误',
'0101' => '缺少必需参数',
'0102' => '签名失败',
'0104' => '找不到对应的订单',
'0302' => '购买数量非法',
'0303' => '商品库存不足',
'0304' => '商品维护中',
'0305' => '找不到对应的商品',
'0501' => '厂商例行维护,无法充值',
'0503' => '充值失败 ',
'0901' => '非法的订单状态转换',
# 小于0为失败
-1 => 'appid为空',
-2 => '产品错误',
-3 => 'appid无效',
-4 => '余额不足或者没有传入价格',
-5 => 'signature不能为空',
-6 => 'nonce不能为空',
-7 => 'time不能为空',
-8 => 'signature已失效',
-9 => 'signature验证失败',
-100 => '请求错误',
-101 => '订单不存在',
-102 => '订单号重复',
-1000 => '系统维护中',
);
public function initialize(): void
{
parent::initialize();
$this->sign_type = sysconf('sign_type');
if ($this->check) {
$this->check();
}
}
public function charsetToUTF8($mixed)
{
if (is_array($mixed)) {
foreach ($mixed as $k => $v) {
if (is_array($v)) {
$mixed[$k] = $this->charsetToUTF8($v);
} else {
$encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
if ($encode == 'EUC-CN' || $encode == 'GBK' || $encode == 'GB2312' || $encode == 'CP936' || $encode == 'BIG-5') {
$mixed[$k] = iconv($encode, 'UTF-8', $v);
}
}
}
} else {
$encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
if ($encode == 'EUC-CN' || $encode == 'GBK' || $encode == 'GB2312' || $encode == 'CP936' || $encode == 'BIG-5') {
$mixed = iconv($encode, 'UTF-8', $mixed);
}
}
return $mixed;
}
public function charsetToGBK($mixed)
{
if (is_array($mixed)) {
foreach ($mixed as $k => $v) {
if (is_array($v)) {
$mixed[$k] = $this->charsetToGBK($v);
} else {
$encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
if ($encode == 'UTF-8') {
$mixed[$k] = iconv('UTF-8', 'GBK', $v);
}
}
}
} else {
$encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
//var_dump($encode);
if ($encode == 'UTF-8') {
$mixed = iconv('UTF-8', 'GBK', $mixed);
}
}
return $mixed;
}
# 获取输入的信息
public function input(): void
{
$this->input = input();
$this->input = $this->charsetToUTF8($this->input);
Log::write('openapi', 'taobao_request', $this->input);#写入到日志里
$this->agentId = $this->input['app_key'];
if (!$this->agentId) {
$this->noTB('9999');
}
$inputData = $this->input ;
$this->proid = $this->input['cardId'];
$OrderSnapJson = explode("|||",$this->input['tbOrderSnap']) ;
if(isset($OrderSnapJson[1]) ) {
$OrderSnapArray = json_decode($OrderSnapJson[1], true);
}
if ($this->proid) {
if($this->proid == 111){
if(isset($OrderSnapArray) && is_array($OrderSnapArray)){
if(isset($OrderSnapArray['outerId']) && $OrderSnapArray['outerId']){
$this->proid = $OrderSnapArray['outerId'];
}
}
}
# 根据产品id 获取信息
$pinfo = \app\channel\service\ProductBaseService::instance()->getOne($this->proid);
if (!$pinfo) {
$this->noTB('0305');
// var_dump(1);die;
}
$this->input['proid'] = $this->proid;
$this->product = $pinfo['key'];
// $this->input['cash'] = $pinfo['value'] * $this->input['cardNum'];
$this->input['cash'] = $pinfo['value'] ;
} else {
$this->noTB('0305');
}
$this->order = $this->input['tbOrderNo'];
$this->input['num'] = $this->input['cardNum'];
$this->input['order'] = $this->order;
$this->input['notify'] = $this->input['notifyUrl'];
# 从数据库中或者缓存中取出商户的信息,并验证是否有效
$this->getMerchant();
$this->input['By_OpenUid'] = $this->get_nick($this->input['order']);
if($this->input['By_OpenUid'] != 'error'){
$check_black = $this->check_black($this->input['By_OpenUid']);
if($check_black != 'ok'){
$tempNum=2;
while($tempNum>0){
2024-09-29 15:43:18 +08:00
$msg = $this->tradeUpdate("该订单买家已经被拉入黑名单 ,停止发货--REAPI 系统自动化",5);
if($msg=='error'){
$tempNum--;
2024-09-29 15:43:18 +08:00
}else{
$tempNum=0;
2024-09-29 15:43:18 +08:00
}
}
$this->noTB('0503', 'submit' ,$this->input['order']);
}
$this->check_limitbuy($this->input['By_OpenUid']);
}
if(isset($OrderSnapArray) && is_array($OrderSnapArray)){
if(isset($OrderSnapArray['buyerIp']) && $OrderSnapArray['buyerIp']){
$this->check_ip_limitbuy($OrderSnapArray['buyerIp']);
}
if(isset($OrderSnapArray['buyerIpv6']) && $OrderSnapArray['buyerIpv6']){
$this->check_ip_limitbuy($OrderSnapArray['buyerIpv6']);
}
}
$this->input['account'] = $this->input['customer']??'更正账号';
if(!$this->input['account'] || $this->input['account'] == '' || $this->input['account'] == '0' || $this->input['account'] == 0){
$this->input['account'] = '更正账号';
}
2024-09-29 15:43:18 +08:00
2024-09-29 15:43:18 +08:00
}
public function input_coop(): void
{
$this->input = input();
$this->input = $this->charsetToUTF8($this->input);
Log::write('openapi', 'taobao_coop_request', $this->input);#写入到日志里
#
$this->agentId = $this->input['supplierId'];
if (!$this->agentId) {
$this->noTB('9999');
}
$inputData = $this->input ;
$this->mappingid = $inputData['spuId'];
$this->bizType = $inputData['bizType'];
if(isset($this->input['properties'])){
$this->input['properties']=urldecode($this->input['properties']);
$propertiesArray1 = explode("^",$this->input['properties']) ;
$propertiesArray = array();
foreach($propertiesArray1 as $key=>$value){
$temp=explode(":", $value);
2024-09-29 15:43:18 +08:00
if(!$temp)continue;
$propertiesArray[$temp[0]]=$temp[1];
}
2024-09-30 21:25:57 +08:00
if(isset($propertiesArray['card_id'])){
$this->proid = $propertiesArray['card_id'];
}else{
$this->proid = $propertiesArray['itemOuterId'];
}
2024-09-29 15:43:18 +08:00
if($this->proid == '111' && isset($propertiesArray['skuOuterId'])){
$this->proid = $propertiesArray['skuOuterId'];
}
}
if ($this->proid) {
# 根据产品id 获取信息
$pinfo = \app\channel\service\ProductBaseService::instance()->getOne($this->proid);
if (!$pinfo) {
$this->noTB('0305');
}
$this->input['proid'] = $this->proid;
$this->product = $pinfo['key'];
$this->input['cash'] = $pinfo['value'] ;
} else {
$this->noTB('0305');
}
$this->order = $this->input['tbOrderNo'];
$this->input['num'] = $this->input['buyNum'];
$this->input['order'] = $this->order;
$this->input['notify'] = $this->input['notifyUrl'];
# 从数据库中或者缓存中取出商户的信息,并验证是否有效
$this->getMerchant();
if(isset($this->input['buyerId'])){
$check_black = $this->check_black($this->input['buyerId']);
if($check_black != 'ok'){
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
}
$this->check_limitbuy($this->input['buyerId'],true);
}
$this->input['account'] = $this->input['accountVal'];
}
#检测是否为限购
public function check_limitbuy($By_OpenUid,$is_coop = false){
2024-09-29 15:43:18 +08:00
$other_param = $this->merchant['other_param'];
if(!$other_param){
return ;
}
$array = json_decode($other_param,true);
2024-09-29 15:43:18 +08:00
if(is_array($array)){
if(isset($array['limitbuy_min_num'])){
# 使用redis记录并按分钟限制订单
$min = $array['limitbuy_min_num'][0]??0; #每隔几分钟
$num = $array['limitbuy_min_num'][1]??0; #限制规则
if($min && $num){
$redis = RedisService::getInstance();
$redis_key = $this->merchant['id'].'_['.$By_OpenUid.']_LimitM';
$countS = $redis->get($redis_key);
if(!$countS){
$redis->set($redis_key,1,$min*60);
}else{
# 检测是否超过限制
$new_num = $countS + 1;
if($new_num >$num){
#超出,需要退款
$tempNum=2;
while($tempNum>0){
$msg = $this->tradeUpdate("该订单买家在{$min} 分钟内采购了 {$countS} 笔,超过限制 规则每{$min}分钟限制 {$num} 笔,停止发货--REAPI 系统自动化",5);
if($msg=='error'){
$tempNum--;
}else{
$tempNum=0;
}
}
if($is_coop){
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
}
$this->noTB('0503', 'submit' ,$this->input['order']);
}else{
#未触发,设置redis继续发货
$redis->set($redis_key,$new_num,$min*60);
}
}
}
}
# 检测是否为限购如果为限购则需要检测是否超过限制如果超过限制则需要退款如果未超过限制则需要发货使用redis进行优化处理
if(isset($array['limitbuy_num']) || isset($array['limitbuy_amount'])){
$redis = RedisService::getInstance();
$redis_key = $this->merchant['id'].'_['.$By_OpenUid.']_LimitBuy';
$data = $redis->get($redis_key);
$n_cash = $this->input['cash']??0;
#计算当天还有多少秒
$remainingSeconds = 86400 - (time() + 8 * 3600) % 86400;
if(!$data){
$new_data = [
'buy_num'=>1,
'buy_cash'=>$n_cash
];
$redis->set($redis_key,$new_data,$remainingSeconds);
}else{
$new_num = $data['buy_num']+1;
$new_total_cash = $data['buy_cash']+$n_cash;
if(isset($array['limitbuy_num'])){
if($data['buy_num']>=$array['limitbuy_num']){
$tempNum=2;
while($tempNum>0){
$msg = $this->tradeUpdate("该订单买家今日已采购了 {$data['buy_num']} 笔,本笔超过限制 每天 限制{$array['limitbuy_num']} ,停止发货--REAPI 系统自动化",5);
2024-09-29 15:43:18 +08:00
if($msg=='error'){
$tempNum--;
}else{
$tempNum=0;
}
}
if($is_coop){
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
}
2024-09-29 15:43:18 +08:00
$this->noTB('0503', 'submit' ,$this->input['order']);
2024-09-29 15:43:18 +08:00
}else{
$new_data = [
'buy_num'=>$new_num,
'buy_cash'=>$new_total_cash
];
$redis->set($redis_key,$new_data,$remainingSeconds);
2024-09-29 15:43:18 +08:00
}
}
if(isset($array['limitbuy_amount'])){
2024-09-29 15:43:18 +08:00
if($new_total_cash>$array['limitbuy_amount']){
$tempNum=2;
while($tempNum>0){
$msg = $this->tradeUpdate("该订单因为同账号累计金额为{$new_total_cash},超过每天限制{$array['limitbuy_amount']},停止发货--REAPI 系统自动化",5);
2024-09-29 15:43:18 +08:00
if($msg=='error'){
$tempNum--;
}else{
$tempNum=0;
}
}
2024-09-29 15:43:18 +08:00
if($is_coop){
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
}
2024-09-29 15:43:18 +08:00
$this->noTB('0503', 'submit' ,$this->input['order']);
2024-09-29 15:43:18 +08:00
}else{
$new_data = [
'buy_num'=>$new_num,
'buy_cash'=>$new_total_cash
];
$redis->set($redis_key,$new_data,$remainingSeconds);
2024-09-29 15:43:18 +08:00
}
}
}
}
}
2024-09-29 15:43:18 +08:00
#查询 param 中json数据 By_OpenUid 出现次数counO create_at data(Y-
// $count = OrderService::instance()->db()->where(['status'=>'2','mid'=>$this->mid])->whereBetween('create_at',[date('Y-m-d 00:00:00',time()),date('Y-m-d 23:59:59',time())])->whereLike('param',"%".$By_OpenUid."%")->count();
// if(isset($array['limitbuy_num'])){
//
// if($count>=$array['limitbuy_num']){
//
// $tempNum=2;
// while($tempNum>0){
// $msg = $this->tradeUpdate("该订单买家今日采购了 {$count} 笔,超过限制 {$array['limitbuy_num']} ,停止发货--REAPI 系统自动化",5);
//
// if($msg=='error'){
// $tempNum--;
// }else{
// $tempNum=0;
// }
// }
//
// if($is_coop){
// $this->noTB('0503', 'submit_coop' ,$this->input['order']);
// }
//
//
// $this->noTB('0503', 'submit' ,$this->input['order']);
// }
// }
//
// if(isset($array['limitbuy_amount'])){
// $cash = OrderService::instance()->db()->where(['status'=>'2','mid'=>$this->mid])->whereBetween('create_at',[date('Y-m-d 00:00:00',time()),date('Y-m-d 23:59:59',time())])->whereLike('param',"%".$By_OpenUid."%")->sum('cash');
// if(!$cash){
// $cash = 0;
// }
// $cash = $cash +$this->input['cash'];
//
//
// if($cash>=$array['limitbuy_amount']){
//
// $tempNum=2;
// while($tempNum>0){
// $msg = $this->tradeUpdate("该订单因为同IP累计金额为{$cash},超过限制{$array['limitbuy_amount']},停止发货--REAPI 系统自动化",5);
//
// if($msg=='error'){
// $tempNum--;
// }else{
// $tempNum=0;
// }
// }
//
// if($is_coop){
// $this->noTB('0503', 'submit_coop' ,$this->input['order']);
// }
//
//
// $this->noTB('0503', 'submit' ,$this->input['order']);
// }
// }
//
//
// }
2024-09-29 15:43:18 +08:00
}
public function check_ip_limitbuy($ip,$is_coop = false){
#查询 param 中json数据 By_OpenUid 出现次数counO create_at data(Y-
$count = OrderService::instance()->db()->where(['status'=>'2','mid'=>$this->mid])->whereBetween('create_at',[date('Y-m-d 00:00:00',time()),date('Y-m-d 23:59:59',time())])->whereLike('param',"%".$ip."%")->count();
$other_param = $this->merchant['other_param'];
if(!$other_param){
return ;
}
$array = json_decode($other_param,true);
if(is_array($array)){
if(isset($array['limitbuy_ip_num'])){
if($count>=$array['limitbuy_ip_num']){
$tempnum=2;
while($tempnum>0){
$msg = $this->tradeUpdate("该订单因为IP超出购买限制停止发货--REAPI 系统自动化",5);
if($msg=='error'&&$tempnum>0){
$tempnum--;
}else{
$tempnum=0;
}
}
if($is_coop){
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
}
//
$this->noTB('0503', 'submit' ,$this->input['order']);
}
$cash = OrderService::instance()->db()->where(['status'=>'2','mid'=>$this->mid])->whereBetween('create_at',[date('Y-m-d 00:00:00',time()),date('Y-m-d 23:59:59',time())])->whereLike('param',"%".$ip."%")->sum('cash');
$cash = $cash +$this->input['cash'];
if(isset($array['limitbuy_ip_amount']) && $cash>$array['limitbuy_ip_amount']){
$tempnum=2;
while($tempnum>0){
$msg = $this->tradeUpdate("该订单因为同IP累计金额为{$cash},超过限制{$array['limitbuy_ip_amount']},停止发货--REAPI 系统自动化",5);
if($msg=='error'&&$tempnum>0){
$tempnum--;
}else{
$tempnum=0;
}
}
if($is_coop){
$this->noTB('0503', 'submit_coop' ,$this->input['order']);
}
//
$this->noTB('0503', 'submit' ,$this->input['order']);
}
}
}
// return 'ok';
}
public function tradeUpdate($beizhu,$flag = 1)
{
$request = [];
$other_param = json_decode($this->merchant['other_param'], true);
if(!str_contains($this->merchant['other_param'], "reapi_appkey")){
return 'ok';
}
$request['agentId'] = $other_param['reapi_appkey'];
$request['agentkey'] = $other_param['reapi_appsecret'];
$request['access_token'] = $this->merchant['access_token'];
$request['merchant_order_id'] = $this->order;
$request['beizhu'] = $beizhu;
$request['flag'] = $flag;
$request['reset'] = "false";
$response = $this->taobaosdk('tradeUpdate', $request);
$json = json_encode($response);
$array = json_decode($json, true);
if (isset($array['Trade']['tid']) && $array['Trade']['tid'] == $this->order ) {
return 'ok';
} else {
return 'error';
}
}
#获取买家id
public function get_nick($merchant_order_id)
{
$Seesionkey = $this->merchant['refresh_token'];#淘宝此token为直充系统授权token
$request = [];
$request['agentId'] = $this->agentId;
$request['agentkey'] = $this->agentkey;
if(isset($this->merchant['other_param']) && $this->merchant['other_param'] && str_contains($this->merchant['other_param'], "reapi_appkey"))
{
$other_param = json_decode($this->merchant['other_param'], true);
$request['agentId'] = $other_param['reapi_appkey'];
$request['agentkey'] = $other_param['reapi_appsecret'];
$Seesionkey = $this->merchant['access_token'];
}
$request['tid'] = $merchant_order_id;
$request['access_token'] = $Seesionkey;
$response = $this->taobaosdk('getByTrade',$request);
$json = json_encode($response);
$array = json_decode($json,true);
if(is_array($array)){
if(isset($array['open_uid']) && $array['open_uid']){
return $array['open_uid'];
}
}
Log::write('openapi', 'taobao_getnick', $json);#写入到日志里
return 'error';
}
#检测是否黑名单
public function check_black($By_OpenUid)
{
$check = BlackCardService::instance()->check($By_OpenUid);
if (!$check ) {
return $By_OpenUid . '已被列入黑名单';
}
return 'ok';
}
/**
* 检测输入信息是否合法
*/
protected function check()
{
}
# 检测开放或者维护时间
protected function checkOpenTime($opentime): void
{
if ($opentime && strstr($opentime, ':')) {
$opentime = str_replace(':', '', $opentime);
if (str_contains($opentime, '-')) {
$value = explode('-', $opentime);
$cur = intval(date('Hi'));
$value[0] = intval($value[0]);
$value[1] = intval($value[1]);
if ($value[1] < $value[0]) {
if ($cur >= $value[0] || $cur < $value[1]) {
$this->noTB('0501');
}
} else {
if ($cur >= $value[0] && $cur < $value[1]) {
$this->noTB('0501');
}
}
}
}
}
# 查找订单
protected function getOrder($order_id, $merchant_order_id = false)
{
$orderService = OrderService::instance();
$order = $orderService->get($order_id, $merchant_order_id, $this->mid);
// if (!$order) {
// $orderLastweekHistoryService = OrderLastweekHistoryService::instance();
// $order = $orderLastweekHistoryService->get($order_id, $merchant_order_id, $this->mid);
// }
// if (!$order) {
// $orderLastHistoryService = OrderLastHistoryService::instance();
// $order = $orderLastHistoryService->get($order_id, $merchant_order_id, $this->mid);
// }
// if (!$order) {
// $orderTwoHistoryService = OrderTwoHistoryService::instance();
// $order = $orderTwoHistoryService->get($order_id, $merchant_order_id, $this->mid);
// }
// if (!$order) {
// $orderHistoryService = OrderHistoryService::instance();
// $order = $orderHistoryService->get($order_id, $merchant_order_id, $this->mid);
// }
2024-09-29 15:43:18 +08:00
return $order;
}
# 调取服务
protected function channel($merchant, $product, $async = false, $param = false, $order = '')
{
if (!$param) {
$param = $this->input;
}
// if ($product == 'cardbuy') {
// $async = false;
// }
// var_dump($param);die;
return ChannelService::instance()->use($merchant, $product, $param, $async, $order);
}
# 记录日志
protected function log($data)
{
Log::write('gateway', 'callback', $data);
}
# 获取商户信息
##发送回调
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 getMerchant(): void
{
$this->merchant = MerchantService::instance()->get('PT_'.$this->agentId);
$this->mid = $this->merchant['id'];
// $this->agentId = $this->merchant['agentId'];
$this->agentkey = $this->merchant['agentkey'];
$this->callnotify = $this->merchant['notify_url'];
// $this->signkey = $this->merchant['other_key'];
}
# 通用签名方法,如果有渠道不同的签名方式,需要单独实现
public static function Sign(array $params,string $appSecret) : string
{
ksort($params);
$stringToBeSigned = $appSecret;
foreach ($params as $k => $v)
{
if(!is_array($v) && !str_starts_with($v, "@"))
{
$stringToBeSigned .= "$k$v";
}
}
unset($k, $v);
$stringToBeSigned .= $appSecret;
return strtoupper(md5($stringToBeSigned));
}
# 调取服务
/**
* 返回淘宝下单失败的消息
* @param integer $code
* @param string $qudao
* @param string $OrderNo
* @param string $error_msg
*/
protected function noTB($code = 0 ,$qudao = 'submit', $OrderNo = '', $error_msg = '')
{
$failedReason = $this->code[$code] ?? 'error';
if ($error_msg) {
$failedReason = $error_msg;
}
$failedReason= iconv("UTF-8", "gbk", $failedReason);
$root_node = '';
$msg = [];
if ($code == '0104' || $code == '0302' || $code == '0303' || $code == '0304' || $code == '0305') {
$coopOrderStatus = 'ORDER_FAILED';
}elseif ($code == '0503') {
$coopOrderStatus = 'FAILED';
} else {
$coopOrderStatus = 'GENERAL_ERROR';
}
// var_dump($failedReason);die;
switch ($qudao) {
case 'submit_coop':
// $data = $this->getOrder('', $OrderNo);
if($code == '0503'){
$failedReason = '订单已退款';
$code = 'STATUS_REFUNDED';
}
$msg = array(
'tbOrderNo' => $OrderNo,
'bizType' =>$this->bizType,
'coopOrderStatus' => $coopOrderStatus,
'coopOrderNo' => '',
'errCode' => $code,
'errDesc' => $failedReason,
);
$root_node = 'response';
break;
case 'submit':
$msg = [
'tbOrderNo' => $OrderNo,
'coopOrderSuccessTime' => '',
'coopOrderStatus' => $coopOrderStatus,
'failedReason' => $failedReason,
'coopOrderNo' => '',
'failedCode' => $code,
'coopOrderSnap' => '',
];
$root_node = 'gamezctoporder';
break;
case 'query':
$this->options['root_node'] = 'gamezctopquery';
$msg = array(
'tbOrderNo' => $OrderNo,
'coopOrderSuccessTime' =>'',
'coopOrderStatus' => $coopOrderStatus,
'failedReason' => $failedReason,
'coopOrderNo' => '',
'failedCode' => $code,
'coopOrderSnap' => '',
);
break;
default:
break;
}
$msg = $this->charsetToGBK($msg);
// var_dump($msg);die;
throw new HttpResponseException(xml($msg,200, ['Content-type' =>'text/xml; charset=GBK'],['root_node'=>$root_node,'encoding' => 'GBK',]));
}
/**
* 返回成功的消息
* @param string $data
* @param string $qudao
* @param string $OrderNo
* @param mixed $info
* @return mixed
*/
protected function yesTB(mixed $data = '{-null-}', $qudao = '', $OrderNo = '', $info = false)
{
if (is_string($data) && $data != 'ok' && $data != 'success'&& $data != 'yescard' && $data != '订单号重复 ' ) {
// if ($data == '订单号重复') {
// return $this->noTB('JDI_00006', $OrderNo);
//
// } else
// if (strstr($data, '已被列入黑名单')) {
// $this->blackks($OrderNo);
// }
return $this->noTB('9999', 'submit' ,$OrderNo);
}
$root_node = '';
switch ($qudao) {
case 'submit_coop':
$data = $this->getOrder('', $OrderNo);
$msg = array(
'tbOrderNo' => $OrderNo,
'bizType' =>$this->bizType,
'coopOrderStatus' => 'UNDERWAY',
'coopOrderNo' => $data['order_id'],
'errCode' => '',
'errDesc' => '',
);
$root_node = 'response';
break;
case 'submit':
$data = $this->getOrder('', $OrderNo);
$msg = array(
'tbOrderNo' => $OrderNo,
'coopOrderSuccessTime' =>'',
'coopOrderStatus' => 'UNDERWAY',
'failedReason' => '',
'coopOrderNo' => $data['order_id'],
'failedCode' => '',
'coopOrderSnap' => '',
);
$root_node = 'gamezctoporder';
break;
case 'query':
$msg = array(
'tbOrderNo' => $OrderNo,
'coopOrderSuccessTime' => '',
'coopOrderStatus' => '',
'failedReason' => '',
'coopOrderNo' => '',
'failedCode' => '',
'coopOrderSnap' => '',
);
if ($data['status'] == '2') {
$msg['coopOrderStatus'] = 'SUCCESS';
$msg['coopOrderSnap'] = json_decode($data['param'], true)['tbOrderSnap'];
$msg['coopOrderSuccessTime'] = $data['channel_callback_at'];
} elseif ($data['status'] == '3') {
$msg['coopOrderStatus'] = 'FAILED';//tbOrderSnap
$msg['failedReason'] = '充值失败';
$msg['failedCode'] = '0503';
} else {
$msg['coopOrderStatus'] = 'UNDERWAY';
}
$root_node = 'gamezctopquery';
break;
case 'query_coop':
$msg = array(
'tbOrderNo' => $OrderNo,
'bizType' =>$this->bizType,
'coopOrderStatus' => '',
'coopOrderNo' => '',
'errCode' => '',
'errDesc' => '',
);
if ($data['status'] == '2') {
$msg['coopOrderStatus'] = 'SUCCESS';
$msg['coopOrderNo'] = $data['order_id'];
} elseif ($data['status'] == '3') {
$msg['coopOrderStatus'] = 'FAILED';//tbOrderSnap
$msg['coopOrderNo'] = $data['order_id'];
$msg['errDesc'] = 'STATUS_REFUNDED';
$msg['errCode'] = '0503';
} else {
$msg['coopOrderStatus'] = 'UNDERWAY';
$msg['coopOrderNo'] = $data['order_id'];
}
$root_node = 'response';
break;
default:
break;
}
$msg = $this->charsetToGBK($msg);
throw new HttpResponseException(xml($msg,200, ['Content-type' =>'text/xml; charset=GBK'],['root_node'=>$root_node,'encoding' => 'GBK',]));
}
public static function doaction($merchant, $request, $requestParam, $apiParams)
{
$orderobj = new \UpdateOrders;
$senddata = $orderobj->doaction($merchant, $request, $requestParam, $apiParams);
return $senddata;
}
public static function taobaosdk($type, $request)
{
$orderobj = new \UpdateOrders;
switch ($type){
case "getToken":
$data = $orderobj->getToken($request);
break;
case "refundsList":
$data = $orderobj->refundsList($request);
break;
case "refundInfo":
$data = $orderobj->refundInfo($request);
break;
case "itemDownshelf":
$data = $orderobj->itemDownshelf($request);
break;
case "itemUpshelf":
$data = $orderobj->itemUpshelf($request);
break;
case "refundSp":
$data = $orderobj->refundSp($request);
break;
case "refundAgree":
$data = $orderobj->refundAgree($request);
break;
case "tradeUpdate":
$data = $orderobj->tradeUpdate($request);
break;
case "refundRefuse":
$data = $orderobj->refundRefuse($request);
break;
case "getByTrade":
$data = $orderobj->getByTrade($request);
break;
case "getRefundStatus":
$data = $orderobj->getRefundStatus($request);
break;
}
return $data;
}
# 记录日志
# 队列
protected function queue($key, $value = false)
{
$redis = RedisService::getInstance();
if (!$value) {
return $redis->pop($key);
} else {
return $redis->push($key, $value);
}
}
#crul
#发送回调
}