mzeros 84856367e9 feat(openapi): 新增码速达API接口
- 添加AfterSales类处理售后服务相关接口
- 新增ContentTemplate控制器和模型用于内容模板管理
- 添加diandian渠道服务类
- 更新Feedov控制器和添加FeedovHfAuto命令类
- 新增autoCard视图用于自动发卡设置
2025-03-11 00:17:40 +08:00

242 lines
6.2 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\openapi\controller\maSuDaApi;
use app\channel\service\ChannelService;
use app\channel\service\ProductBaseService;
use app\gateway\service\CurlService;
use app\gateway\service\RedisService as redisObj;
use app\merchant\service\MerchantService;
use app\merchant\service\OrderHistoryService;
use app\merchant\service\OrderLastweekHistoryService;
use app\merchant\service\OrderService;
use app\merchant\service\ProductService;
use app\order\service\AfterSalesOrderService;
use app\order\service\Kami91OrderService;
use think\admin\Controller;
use app\core\Service as CoreService;
use think\exception\HttpResponseException;
use think\facade\Db;
use think\facade\Log;
use app\channel\service\ProductService as CProductService;
class AfterSales extends Controller
{
# 是否检测数据
// protected bool $check = false;
protected $merchant_id;
# code码定义
protected $code = array
(
# 成功
1 => 'ok',
# 小于0为失败
0 => '暂时未处理',
-1 => 'appid为空',
-2 => '产品错误',
-3 => 'appid无效',
-4 => '余额不足或者没有传入价格',
-5 => 'signature不能为空',
-6 => 'nonce不能为空',
-7 => 'time不能为空',
-8 => 'signature已失效',
-9 => 'signature验证失败',
-100 => '请求错误',
-101 => '订单不存在',
-102 => '订单号重复',
401 => '签名错误',
408 => '时间戳过期',
-103 => '正在处理中',
-104 => '锁卡失败',
-1000 => '系统维护中',
);
protected $secretKey = 'ez8bfsrgefga5nkx5zgccegrb25mct7w';
protected string $host_url = 'https://supplier-api.wanmahui.com/api/openplatform/gateway';
# 查询接口 一般用于查询数据,同步执行
# 提交接口 一般用于提交数据,异步执行
public function refund_created($data, $mid)
{
$AfterSalesOrderService = AfterSalesOrderService::instance();
$info = $AfterSalesOrderService->db()->where(['refund_id' => $data['refund_id']])->find();
if (!$info) {
$update = [];
$update['listdata'] = json_encode($data);
$update['mid'] = $mid;
$update['status'] = '1';
$update['merchant_order_id'] = $data['tid'];
$update['refund_id'] = $data['refund_id'];
$update['refund_fee'] = $data['refund_fee'];
// $update['dispute_type'] = $vo['dispute_type'];
// $update['refund_desc'] = $vo['desc'];
$update['create_at'] = $data['modified'];
$update['buyer_nick'] = $data['buyer_nick'];
$update['buyer_open_uid'] = $data['buyer_open_uid'];
$update['refund_phase'] = $data['refund_phase'];
$up = $AfterSalesOrderService->up(['refund_id' => $data['refund_id']], $update);
}
}
public function refund_get($data, $mid)
{
}
#更新备注
public function trade_memo($tid, $uid,$key,$flag,$desc = '')
{
$request = [
'method' => 'trade_memo',
'uid' => $uid,
'timestamp' => time(),
'tid' => $tid,
'flag' => $flag,
];
if($desc){
$request['memo'] = $desc;
}
$request['sign'] = $this->_sign($request, $key);
$response = $this->curl('POST', $this->host_url, $request);
$response = json_decode($response,true);
if($response['code'] == 10000){
return true;
}else{
return false;
}
}
public function _sign($request,$secretKey)
{
ksort($request);
if(isset($request['method'])){
unset($request['method']);
}
if(isset($request['appmid'])){
unset($request['appmid']);
}
$str = '';
foreach ($request as $k => $v){
$str .= $k . $v ;
}
$str = $secretKey.$str.$secretKey.$secretKey;
return md5($str);
}
protected static function log($data, $type = 'request'):void
{
\dever\Log::write('agiso', $type, $data);
// \dever\Log::write('jingdong', $type, $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 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();
}
/**
* 返回成功的消息
* @param mixed $info
* @param string $data
* @param integer $code
*/
protected function yes($data = '{-null-}', $info = 'ok', $code = 200)
{
if (is_string($data) && $data != 'ok' && $data != 'success') {
if ($data == '订单号重复') {
return $this->no(-102);
}
return $this->no(-100, $data);
}
$response = [
'code' => $code,
'message' => $info,
'data' => $data
];
throw new HttpResponseException(json($response));
}
/**
* 返回失败的消息
* @param mixed $info
* @param string $data
* @param integer $code
*/
protected function no($code = 0, $info = '', $data = null)
{
$msg = $this->code[$code] ?? 'error';
if ($info) {
$msg .= ':' . $info;
}
$response = [
'code' => $code,
'message' => $msg,
'data' => $data
];
throw new HttpResponseException(json($response));
}
}