mzeros b8c34de8c8 refactor(merchant): 优化账户数据处理和订单逻辑
- 添加 endsWithDoubleZero 函数,用于处理数值字符串末尾的两个零
- 修改 Core.php 中的 queue 方法,增加对卡库提单的特殊处理逻辑
-调整 Feedov.php 中的订单查询和充值逻辑,提高系统稳定性
- 优化数据库配置,连接测试数据库以确保数据安全
2025-02-15 19:00:17 +08:00

262 lines
7.6 KiB
PHP

<?php
namespace app\openapi\controller;
use app\merchant\service\OrderLastweekHistoryService;
use app\merchant\service\OrderService;
use dever\Log;
use think\exception\HttpResponseException;
/**
* 商户自动提单
* Class Qianmi
* @package app\channel\service
*/
class Feedov extends Core
{
protected $check = false;
# 查询订单
public function query()
{
$input = input();
$this->log($input, 'query');
$this->appid = input('app_key');
$this->appid = 'PT_' . $this->appid;
$this->product = 'query';
// $result['code'] = 0;
// $result['message'] = '测试成功';
// $result['data'] = [];
// $result['data']['status'] = 2;
// $result['data']['rsp_info'] = '充值成功';
//
// $result['data']['rsp_time'] = time();
// throw new HttpResponseException(json($result));
$this->getMerchant();
$result = array();
// $sign = $this->_sign($input, array('customerId', 'data', 'timestamp'));
// if ($sign && isset($input['data']) && isset($input['sign']) && $sign == $input['sign']) {
$order_id = '';
$merchant_order_id = $input['user_order_id'];
$orderService = OrderService::instance();
$order = $orderService->get($order_id, $merchant_order_id,$this->mid);
if (!$order) {
$orderHistoryService = OrderLastweekHistoryService::instance();
$order = $orderHistoryService->get($order_id, $merchant_order_id,$this->mid);
}
$result['code'] = 0;
if ($order) {
$result['message'] = '查询成功';
if ($order['status'] == 2) {
$data['status'] = 2;
$data['rsp_info'] = '充值成功';
if (isset($order['channel_callback_at']) && $order['channel_callback_at']) {
$data['rsp_time'] = strtotime($order['channel_callback_at']);
} else {
$data['rsp_time'] = time();
}
} elseif ($order['status'] == 3) {
$data['status'] = 3;
$data['rsp_info'] = '充值失败';
if (isset($order['channel_callback_at']) && $order['channel_callback_at']) {
$data['rsp_time'] = strtotime($order['channel_callback_at']);
} else {
$data['rsp_time'] = time();
}
} else {
$data['status'] = 1;
}
$result['data'] = $data;
} else {
$result['message'] = '订单不存在';
$result['data'] = [];
}
throw new HttpResponseException(json($result));
}
# 获取订单
public function charge()
{
$settingStatus = sysconf('settingStatus');
if ($settingStatus == 1) {
$response = [
'code' => 'FAIL',
'message' => '系统维护'
];
throw new HttpResponseException(json($response));
}
$this->input = $input = input();
/**/
$this->log($input, 'charge');
$result = array();
$this->appid = input('app_key');
$this->appid = 'PT_' . $this->appid;
$this->proid = input('outer_goods_code');
# 根据产品id 获取信息
$pinfo = \app\channel\service\ProductBaseService::instance()->getOne($this->proid);
if (!$pinfo) {
$response = [
'code' => 'FAIL',
'message' => '暂未配置商品'
];
throw new HttpResponseException(json($response));
}
$this->input['proid'] = $this->proid;
$this->product = $pinfo['key'];
if ($this->product != 'dhcz') {
if (!strstr($this->product, '_cash')) {
$this->input['cash'] = $pinfo['value'];
}
} else {
$this->proid = false;
}
# 从数据库中或者缓存中取出商户的信息,并验证是否有效
$this->getMerchant();
$datas = $input['datas'];
$this->input['order'] = $input['user_order_id'];
if(isset($pinfo['service']['type']) && $pinfo['service']['type'] == 2){
#说明为话费业务
$this->input['mobile'] = $input['target'];
// if(isset($this->input['datas']['amount']) && $input['datas']['amount']){
// $this->input['cash'] = $input['datas']['amount'];
// }
}else{
$this->input['account'] = $input['target'];
}
$data = $this->channel($this->mid, $this->product, true);
if (is_string($data) && $data != 'ok' && $data != 'success' && $data != 'yescard' && $data != '订单号重复') {
$response = [
'code' => 'FAIL',
'message' => $data
];
throw new HttpResponseException(json($response));
}
$response = [
'code' => 'SUCCESS'
];
throw new HttpResponseException(json($response));
// return
}
# 通知处理
public function notify($url,$param,$merchant = [])
{
$log['type'] = 'merchant_notify';
$log['request'] =$param;
if (!isset($log['request']['merchant_order_id'])) {
return 'error';
}
$merchant_order_id = $log['request']['merchant_order_id'];
if (isset($log['request']['status']) && ($log['request']['status'] == 2 || $log['request']['status'] == 3)) {
if ($log['request']['status'] == 2) {
$status = "9";
$rsp_info = "充值成功";
} else {
$status = "8";
$rsp_info = "充值失败";
}
$this->appid = $log['request']['appid'];
$order_id = $log['request']['order_id'];
if($url == ''){
$url = 'https://shop.task.mf178.cn/userapi/sgd/updateStatus';
}
$request = [];
if(!isset($merchant['agentId'])){
$this->getMerchant();
$merchant = $this->merchant;
}
$request['app_key'] = $merchant['agentId'];
$request['timestamp'] = time();
$data = [
'user_order_id' => $merchant_order_id,
'status' => $status,
'rsp_info' => $rsp_info
];
$request['data'] = json_encode($data);
$request['sign'] = $this->_sign($request, $merchant['agentkey']);
$response = $this->curl('post', $url, $request, true);
if ($response) {
$response = json_decode($response, true);
if (isset($response['code']) && $response['code'] == '0') {
return 'success';
}
}
}
return 'error';
}
# 记录日志
protected function log($data, $type = 'request')
{
Log::write('feedov', $type, $data);
}
private function _sign($request, $app_secret)
{
ksort($request);
$buff = '';
foreach ($request as $k => $v) {
if ($k != "sign") {
$buff .= $k . $v;
}
}
$buff .= $app_secret;
return md5($buff);
}
public function editSupplyGoodManageStock($param)
{
$request = [];
$request['app_key'] = $param['app_key'];
$request['timestamp'] = time();
$request['data'] = json_encode($param['data']);
$request['sign'] = $this->_sign($request, $param['app_secret']);
$url = 'https://shop.task.mf178.cn/userapi/sgd/editSupplyGoodManageStock';
return $this->curl('post', $url, $request, true);
}
}