2024-12-13 16:17:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\openapi\controller;
|
|
|
|
|
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
use app\merchant\service\OrderLastweekHistoryService;
|
|
|
|
use app\merchant\service\OrderService;
|
2024-12-13 16:17:54 +08:00
|
|
|
use dever\Log;
|
2024-12-20 16:14:52 +08:00
|
|
|
use think\exception\HttpResponseException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 商户自动提单
|
|
|
|
* Class Qianmi
|
|
|
|
* @package app\channel\service
|
|
|
|
*/
|
|
|
|
class Feedov extends Core
|
2024-12-13 16:17:54 +08:00
|
|
|
{
|
2024-12-20 16:14:52 +08:00
|
|
|
protected $check = false;
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2025-02-15 19:02:39 +08:00
|
|
|
public function __call($name, $arguments)
|
|
|
|
{
|
|
|
|
if(str_starts_with($name, 'charge_'))return $this->charge();
|
|
|
|
|
|
|
|
$this->error('请求' . $name . '错误', '{-null-}', -802);
|
|
|
|
}
|
|
|
|
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
# 查询订单
|
2024-12-13 16:17:54 +08:00
|
|
|
public function query()
|
|
|
|
{
|
2024-12-20 16:14:52 +08:00
|
|
|
$input = input();
|
|
|
|
$this->log($input, 'query');
|
2025-02-15 19:00:17 +08:00
|
|
|
$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();
|
2024-12-20 16:14:52 +08:00
|
|
|
|
|
|
|
$result = array();
|
|
|
|
// $sign = $this->_sign($input, array('customerId', 'data', 'timestamp'));
|
|
|
|
// if ($sign && isset($input['data']) && isset($input['sign']) && $sign == $input['sign']) {
|
|
|
|
|
2025-01-20 12:17:16 +08:00
|
|
|
$order_id = '';
|
|
|
|
$merchant_order_id = $input['user_order_id'];
|
|
|
|
$orderService = OrderService::instance();
|
2025-02-15 19:00:17 +08:00
|
|
|
$order = $orderService->get($order_id, $merchant_order_id,$this->mid);
|
2025-01-20 12:17:16 +08:00
|
|
|
if (!$order) {
|
|
|
|
$orderHistoryService = OrderLastweekHistoryService::instance();
|
2025-02-15 19:00:17 +08:00
|
|
|
$order = $orderHistoryService->get($order_id, $merchant_order_id,$this->mid);
|
2025-01-20 12:17:16 +08:00
|
|
|
}
|
2025-02-15 19:00:17 +08:00
|
|
|
$result['code'] = 0;
|
|
|
|
|
2025-01-20 12:17:16 +08:00
|
|
|
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();
|
2024-12-20 16:14:52 +08:00
|
|
|
}
|
2025-01-20 12:17:16 +08:00
|
|
|
|
|
|
|
} 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']);
|
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
} else {
|
2025-01-20 12:17:16 +08:00
|
|
|
$data['rsp_time'] = time();
|
2024-12-20 16:14:52 +08:00
|
|
|
}
|
2025-01-20 12:17:16 +08:00
|
|
|
} else {
|
|
|
|
$data['status'] = 1;
|
|
|
|
}
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
$result['data'] = $data;
|
2025-01-20 12:17:16 +08:00
|
|
|
} else {
|
|
|
|
$result['message'] = '订单不存在';
|
2025-02-15 19:00:17 +08:00
|
|
|
$result['data'] = [];
|
2025-01-20 12:17:16 +08:00
|
|
|
}
|
2024-12-20 16:14:52 +08:00
|
|
|
throw new HttpResponseException(json($result));
|
|
|
|
|
|
|
|
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
# 获取订单
|
|
|
|
public function charge()
|
2024-12-13 16:17:54 +08:00
|
|
|
{
|
2025-02-15 19:00:17 +08:00
|
|
|
$settingStatus = sysconf('settingStatus');
|
|
|
|
if ($settingStatus == 1) {
|
|
|
|
$response = [
|
|
|
|
'code' => 'FAIL',
|
|
|
|
'message' => '系统维护'
|
|
|
|
];
|
|
|
|
throw new HttpResponseException(json($response));
|
|
|
|
}
|
2024-12-20 16:14:52 +08:00
|
|
|
$this->input = $input = input();
|
|
|
|
|
|
|
|
/**/
|
|
|
|
$this->log($input, 'charge');
|
|
|
|
$result = array();
|
|
|
|
$this->appid = input('app_key');
|
2025-01-20 12:17:16 +08:00
|
|
|
$this->appid = 'PT_' . $this->appid;
|
2024-12-20 16:14:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
$this->proid = input('outer_goods_code');
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
|
2025-01-20 12:17:16 +08:00
|
|
|
# 根据产品id 获取信息
|
|
|
|
$pinfo = \app\channel\service\ProductBaseService::instance()->getOne($this->proid);
|
|
|
|
if (!$pinfo) {
|
2025-02-15 19:00:17 +08:00
|
|
|
$response = [
|
|
|
|
'code' => 'FAIL',
|
|
|
|
'message' => '暂未配置商品'
|
|
|
|
];
|
|
|
|
throw new HttpResponseException(json($response));
|
2025-01-20 12:17:16 +08:00
|
|
|
}
|
|
|
|
$this->input['proid'] = $this->proid;
|
|
|
|
$this->product = $pinfo['key'];
|
|
|
|
if ($this->product != 'dhcz') {
|
|
|
|
if (!strstr($this->product, '_cash')) {
|
|
|
|
$this->input['cash'] = $pinfo['value'];
|
2024-12-20 16:14:52 +08:00
|
|
|
}
|
2025-01-20 12:17:16 +08:00
|
|
|
} else {
|
|
|
|
$this->proid = false;
|
|
|
|
}
|
2024-12-20 16:14:52 +08:00
|
|
|
|
|
|
|
# 从数据库中或者缓存中取出商户的信息,并验证是否有效
|
|
|
|
$this->getMerchant();
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
$datas = $input['datas'];
|
2025-01-20 12:17:16 +08:00
|
|
|
$this->input['order'] = $input['user_order_id'];
|
2024-12-13 16:17:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
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'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-12-13 16:17:54 +08:00
|
|
|
|
|
|
|
$data = $this->channel($this->mid, $this->product, true);
|
|
|
|
|
2025-01-20 12:17:16 +08:00
|
|
|
if (is_string($data) && $data != 'ok' && $data != 'success' && $data != 'yescard' && $data != '订单号重复') {
|
2024-12-20 16:14:52 +08:00
|
|
|
$response = [
|
2025-01-20 12:17:16 +08:00
|
|
|
'code' => 'FAIL',
|
|
|
|
'message' => $data
|
2024-12-20 16:14:52 +08:00
|
|
|
];
|
|
|
|
throw new HttpResponseException(json($response));
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
$response = [
|
2025-01-20 12:17:16 +08:00
|
|
|
'code' => 'SUCCESS'
|
2024-12-20 16:14:52 +08:00
|
|
|
];
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
throw new HttpResponseException(json($response));
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
// return
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
# 通知处理
|
2025-02-15 19:00:17 +08:00
|
|
|
public function notify($url,$param,$merchant = [])
|
2024-12-20 16:14:52 +08:00
|
|
|
{
|
|
|
|
$log['type'] = 'merchant_notify';
|
2025-02-15 19:00:17 +08:00
|
|
|
$log['request'] =$param;
|
|
|
|
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
if (!isset($log['request']['merchant_order_id'])) {
|
2025-02-15 19:00:17 +08:00
|
|
|
return 'error';
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
2024-12-20 16:14:52 +08:00
|
|
|
$merchant_order_id = $log['request']['merchant_order_id'];
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
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'];
|
2025-02-15 19:00:17 +08:00
|
|
|
if($url == ''){
|
|
|
|
$url = 'https://shop.task.mf178.cn/userapi/sgd/updateStatus';
|
|
|
|
}
|
2024-12-20 16:14:52 +08:00
|
|
|
|
|
|
|
$request = [];
|
2025-02-15 19:00:17 +08:00
|
|
|
if(!isset($merchant['agentId'])){
|
|
|
|
$this->getMerchant();
|
|
|
|
$merchant = $this->merchant;
|
|
|
|
}
|
2024-12-20 16:14:52 +08:00
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
$request['app_key'] = $merchant['agentId'];
|
2025-01-20 12:17:16 +08:00
|
|
|
$request['timestamp'] = time();
|
2024-12-20 16:14:52 +08:00
|
|
|
$data = [
|
2025-01-20 12:17:16 +08:00
|
|
|
'user_order_id' => $merchant_order_id,
|
|
|
|
'status' => $status,
|
|
|
|
'rsp_info' => $rsp_info
|
2024-12-20 16:14:52 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$request['data'] = json_encode($data);
|
2025-02-15 19:00:17 +08:00
|
|
|
$request['sign'] = $this->_sign($request, $merchant['agentkey']);
|
|
|
|
|
|
|
|
|
2025-01-20 12:17:16 +08:00
|
|
|
$response = $this->curl('post', $url, $request, true);
|
2024-12-20 16:14:52 +08:00
|
|
|
if ($response) {
|
|
|
|
$response = json_decode($response, true);
|
|
|
|
if (isset($response['code']) && $response['code'] == '0') {
|
2025-02-15 19:00:17 +08:00
|
|
|
return 'success';
|
2024-12-20 16:14:52 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
2025-02-15 19:00:17 +08:00
|
|
|
return 'error';
|
2024-12-20 16:14:52 +08:00
|
|
|
}
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
# 记录日志
|
|
|
|
protected function log($data, $type = 'request')
|
|
|
|
{
|
|
|
|
Log::write('feedov', $type, $data);
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
private function _sign($request, $app_secret)
|
2024-12-13 16:17:54 +08:00
|
|
|
{
|
2024-12-20 16:14:52 +08:00
|
|
|
ksort($request);
|
2025-02-15 19:00:17 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
$buff = '';
|
|
|
|
foreach ($request as $k => $v) {
|
|
|
|
if ($k != "sign") {
|
|
|
|
$buff .= $k . $v;
|
|
|
|
}
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
$buff .= $app_secret;
|
2024-12-13 16:17:54 +08:00
|
|
|
|
2024-12-20 16:14:52 +08:00
|
|
|
return md5($buff);
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|
2025-02-15 19:00:17 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
2024-12-13 16:17:54 +08:00
|
|
|
}
|