完成了基本调整调整
This commit is contained in:
@@ -18,7 +18,9 @@ use app\common\model\Partners as PartnersModel;
|
||||
use app\common\crypto\RsaUtil;
|
||||
use app\common\service\PartnersBalance;
|
||||
use app\common\model\qyt\Enterprise as EnterpriseModel;
|
||||
use app\common\service\QytDriver;
|
||||
use app\common\service\QytOil;
|
||||
use app\common\service\QytRefund;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use cores\exception\BaseException;
|
||||
use think\facade\Request;
|
||||
@@ -168,6 +170,14 @@ class OilCard extends Controller
|
||||
if($created){
|
||||
// 回填流水的订单ID(建单前尚不知 order_id)
|
||||
PartnersBalance::bindOrder($balanceLogId, (int)$OrderModel->order_id);
|
||||
// 司机档案(按身份证号归档并标记信息冲突;内部吞异常,不影响建单)
|
||||
QytDriver::touch([
|
||||
'order_id' => $OrderModel->order_id,
|
||||
'id_card' => $idCard,
|
||||
'driver_name' => $driverName,
|
||||
'mobile' => $mobile,
|
||||
'store_id' => $this->storeId,
|
||||
]);
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('partners_queue', json_encode(['order_id'=>$OrderModel->order_id],320));
|
||||
@@ -186,6 +196,76 @@ class OilCard extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款(整单全额)
|
||||
* 企油通侧:7.17 查司机支付凭证 -> 7.16 按订单金额调低额度;成功后回补合作商余额,并推送油卡变动通知(optType=refund)
|
||||
* @return Json
|
||||
*/
|
||||
public function refund()
|
||||
{
|
||||
$headers = Request::header();
|
||||
$data = json_decode(Request::instance()->getContent(), true);
|
||||
$appKey = $headers['appkey'] ?? '';
|
||||
$requestId = $headers['requestid'] ?? '';
|
||||
$method = $headers['method'] ?? '';
|
||||
if($method != 'syb.oil.oilCard.refund'){
|
||||
return $this->oilRenderError('12', '0005');
|
||||
}
|
||||
try {
|
||||
Db::name('request_log')->insert([
|
||||
'request_id' => $requestId,
|
||||
'app_key' => $appKey,
|
||||
'create_time' => time()
|
||||
]);
|
||||
} catch (\think\Exception $e) {
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
|
||||
return $this->oilRenderError('12', '0012');
|
||||
}
|
||||
return $this->oilRenderError('99', '9999');
|
||||
}
|
||||
$partners = PartnersModel::detail(['appKey' => $appKey]);
|
||||
if(!$partners){
|
||||
return $this->oilRenderError('02','0004');
|
||||
}
|
||||
$crypto = new RsaUtil($partners);
|
||||
$result = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
if ($result['code'] !== '00') {
|
||||
return $this->oilRenderError($result['code'], $result['errCode'], '', $result['errMessage'] ?? '');
|
||||
}
|
||||
$body = $result['data'];
|
||||
if($partners['orgNo'] != ($body['orgNo'] ?? '')){
|
||||
return $this->oilRenderError('12','0014');
|
||||
}
|
||||
$oilCardNo = trim((string)($body['oilCardNo'] ?? ''));
|
||||
if($oilCardNo === ''){
|
||||
return $this->oilRenderError('12','0001', '', '缺少必填请求参数 oilCardNo');
|
||||
}
|
||||
$reason = mb_substr(trim((string)($body['reason'] ?? '')), 0, 100);
|
||||
|
||||
// 只能退自己的订单
|
||||
$order = OrderModel::detail(['oilCardNo' => $oilCardNo, 'partners_id' => $partners['partners_id']]);
|
||||
if(!$order){
|
||||
return $this->oilRenderError('01','2036');
|
||||
}
|
||||
|
||||
$res = QytRefund::apply((int)$order['order_id'], 'api', (string)$appKey, $reason);
|
||||
// 已退款(含重复调用的幂等返回)或结果确认中:都按受理成功返回,由 refundStatus 区分
|
||||
// 确认中说明 7.16 已发出、上游可能已调额,不能告诉下游「失败」让它重试
|
||||
if ($res['ok'] || $res['status'] === QytRefund::CONFIRM) {
|
||||
return $this->oilRenderSuccess($res['data'], '00', $res['message']);
|
||||
}
|
||||
switch ($res['reason']) {
|
||||
case QytRefund::REASON_NOT_FOUND:
|
||||
return $this->oilRenderError('01', '2036', '', $res['message']);
|
||||
case QytRefund::REASON_PROCESSING:
|
||||
return $this->oilRenderError('01', '2032', '', $res['message']);
|
||||
case QytRefund::REASON_STATE:
|
||||
return $this->oilRenderError('01', '2048', '', $res['message']);
|
||||
default:
|
||||
return $this->oilRenderError('01', '2049', '', $res['message']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function createOrderNo(): string
|
||||
{
|
||||
// 获取当前时间戳到毫秒(13位)
|
||||
@@ -469,7 +549,11 @@ class OilCard extends Controller
|
||||
return $this->oilRenderError('12','0013', '', $validate->getError());
|
||||
}
|
||||
|
||||
$detail = OrderModel::detail(['oilCardNo' => $data['oilCardNo']]);
|
||||
// 只能查自己的订单(原先不校验归属,一个合作商可以查到别家的单)
|
||||
$detail = OrderModel::detail(['oilCardNo' => $data['oilCardNo'], 'partners_id' => $partners['partners_id']]);
|
||||
if(!$detail){
|
||||
return $this->oilRenderError('01','2036');
|
||||
}
|
||||
// 组装返回格式
|
||||
$result = [
|
||||
'mobile' => $detail['mobile'],
|
||||
@@ -482,6 +566,15 @@ class OilCard extends Controller
|
||||
'oil_time' => $detail['oil_time'],
|
||||
'use_status' => $detail['use_status'],
|
||||
'use_time' => $detail['use_time'],
|
||||
// 一单可多次加油:已加油金额 / 加油次数 / 剩余可加油(即可退)金额
|
||||
'used_amount' => number_format((float)$detail['used_amount'], 2, '.', ''),
|
||||
'used_num' => (int)$detail['used_num'],
|
||||
'remain_amount' => number_format(max(0, (float)$detail['total_price'] - (float)$detail['used_amount']
|
||||
- ((int)$detail['refund_status'] === 2 ? (float)$detail['refund_amount'] : 0)), 2, '.', ''),
|
||||
// 退款:0未退款 1退款中 2已退款 3退款失败 4退款结果确认中
|
||||
'refund_status' => (int)$detail['refund_status'],
|
||||
'refund_amount' => number_format((float)$detail['refund_amount'], 2, '.', ''),
|
||||
'refund_time' => $detail['refund_time'] ? date('Y-m-d H:i:s', (int)$detail['refund_time']) : '',
|
||||
];
|
||||
return $this->oilRenderSuccess($result);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user