第一次更新,完成了初版调整

This commit is contained in:
2026-09-07 22:05:51 +08:00
parent b5a26a8848
commit 4d6a7e7aac
198 changed files with 6142 additions and 3856 deletions
+126 -188
View File
@@ -1,34 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// | 后台 · 下单平台(合作商)订单管理
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// | 企油通改造后:
// | list() 订单列表(含企油通批次号/运单号/发放态/加油明细)
// | detail() 订单详情 + 加油消费流水
// | share() 重新发放:把订单打回未提交态并重投 partners_queue,由 7.7 下发
// | qrCode() 获取司机免登加油地址(7.15),出参 qrCode 为 H5 URL
// | oilCallback() / useCallback() 重推「发放/加油」结果给下单平台
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\store\controller\partners;
use app\store\controller\Controller;
use app\store\model\partners\Order as OrderModel;
use app\store\model\Company as CompanyModel;
use app\common\service\IdingjuOil;
use app\store\model\order\QrCode as QrCodeModel;
use app\common\service\PartnersBalance;
use app\common\service\QueueService;
use app\common\service\QytOil;
use app\store\controller\Controller;
use app\store\model\order\QrCode as QrCodeModel;
use app\store\model\partners\Order as OrderModel;
use think\facade\Db;
use think\response\Json;
/**
* 余额明细
* Class Order
* @package app\store\controller\user
*/
class Order extends Controller
{
/**
* 订单明细
* 订单列表
* @return mixed
*/
public function list()
@@ -39,207 +36,148 @@ class Order extends Controller
}
/**
* 获取支付二维码
* 订单详情(含企油通加油消费流水)
* @return Json
*/
public function detail(): Json
{
$orderId = (int) $this->request->param('orderId');
$order = OrderModel::detail($orderId);
if (!$order) {
return $this->renderError('订单不存在');
}
$consume = Db::name('qyt_consume')
->where('order_id', $orderId)
->order('id', 'desc')
->select()
->toArray();
return $this->renderSuccess(['order' => $order, 'consume' => $consume]);
}
/**
* 获取司机免登加油地址(企油通 7.15)
* @return Json
* @throws \think\db\exception\DbException
*/
public function qrCode(): Json
{
$postData = $this->postForm();
$postData['order_id'] = $this->request->param('orderId');
$order = OrderModel::detail($postData['order_id']);
if($order['use_status'] != 0){
return $this->renderError('油券已核销');
}else {
$company = CompanyModel::detail(['orgNo' => $this->getCompany($order['goods_no'])]);
$IdingjuOil = new IdingjuOil();
// 对接平台接口
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$order['oilCardNo']], $company);
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
// 插入支付码记录
$QrCodeModel = new QrCodeModel();
$QrCodeModel->add([
'oilCardNo'=>$order['oilCardNo'],
'qrCode'=>$res['data']['useQrCodeUrl'],
'amount'=>$order['goods_price'],
'order_id'=>$order['order_id'],
'user_id'=>0,
'store_id'=>$order['store_id'],
]);
$res = [
'qrCode'=>$res['data']['useQrCodeUrl']
];
return $this->renderSuccess($res, '提交成功');
}else{
return $this->renderError($res['errMessage'] ?? $res['message']);
}
$orderId = (int) $this->request->param('orderId');
$order = OrderModel::detail($orderId);
if (!$order) {
return $this->renderError('订单不存在');
}
if ($order['use_status'] != 0) {
return $this->renderError('该单已加油核销');
}
if ($order['oil_status'] != 1) {
return $this->renderError('该单尚未发放成功,无法获取加油地址');
}
$h5Url = (new QytOil())->h5Url((string) $order['mobile']);
if (!$h5Url) {
return $this->renderError('生成加油地址失败,请检查企油通配置');
}
// 留痕
(new QrCodeModel())->add([
'oilCardNo' => $order['oilCardNo'],
'qrCode' => $h5Url,
'amount' => $order['goods_price'],
'order_id' => $order['order_id'],
'user_id' => 0,
'store_id' => $order['store_id'],
]);
return $this->renderSuccess(['qrCode' => $h5Url], '获取成功');
}
/**
* @param $goodsNo
* @return string
*/
public function getCompany($goodsNo): string
{
switch ($goodsNo) {
case 'djgdface100':
case 'djgdface200':
case 'djgdface300':
return 'umQZhIHKofyA';
case 'jmgxyyface100':
case 'jmgxyyface200':
case 'jmgxyyface300':
case 'jmgzface100':
case 'jmgzface200':
case 'jmgzface300':
case 'jmfjface100':
case 'jmfjface200':
case 'jmfjface300':
return 'HpWqXIgYvTBg';
case 'face003':
return 'NKJBgaaRNdiL'; // 测试参数
default:
return '';
}
}
/**
* 手动分油
* 重新发放(把订单打回未提交态并重投队列,由 partners:queue 调用企油通 7.7)
* @return Json
* @throws \think\db\exception\DbException
*/
public function share(): Json
{
$IdingjuOil = new IdingjuOil();
$postData = $this->request->param();
$postData['order_id'] = $this->request->param('orderId');
$order = OrderModel::detail($postData['order_id']);
if($order['oil_status'] != 0){
return $this->renderError('已分油');
}else {
if($order['oilCardType']) {
$data['amount'] = $order['total_price']; // 金额
$company = CompanyModel::detail(['orgNo' => $this->getCompany($order['goods_no'])]);
if (!$company) {
return $this->renderError('已分油');
}
// 对接平台接口
$res = $IdingjuOil->oilOilCardShare([
'goodsNo'=>$order['goods_no'],
'amount'=>$data['amount'],
'userNo'=>0,
'mobile'=>$order['mobile'],
'saleOrderNo'=>$order['oilCardNo'],
'oilCardType'=>$order['oilCardType']
], $company);
if ($res['code'] != 1) {
return $this->renderError($res['errMessage'] ?? $res['message']);
}
$IdingjuOil->saveLogStore("分油接口结果".json_encode($res,320));
// $item['company_id'] = $company['company_id'];
$item['shareNo'] = $res['data']['trade_no'] ?? '';
$item['qrCode'] = $res['data']['useUrl'] ?? '';
$item['oil_status_zsy'] = $res['data']['state'] ?? 0;
$item['oil_time'] = time();
$item['oil_status'] = $item['oil_status_zsy'] == 2 ? 1 : 0; // 已发券 为1
$r = $order->save($item);
$IdingjuOil->saveLogStore("保存分油结果".json_encode($r,320));
return $this->renderSuccess('分油成功');
}
$orderId = (int) $this->request->param('orderId');
$order = OrderModel::detail($orderId);
if (!$order) {
return $this->renderError('订单不存在');
}
if ($order['oil_status'] == 1) {
return $this->renderError('该单已发放成功,无需重发');
}
if ($order['use_status'] != 0) {
return $this->renderError('该单已加油核销,不可重发');
}
// 发放失败时余额已回补,重发需重新扣减合作商余额
$logId = PartnersBalance::deduct(
(int) $order['partners_id'],
(float) $order['total_price'],
(string) $order['partners_order_no'],
$orderId,
(int) $order['store_id']
);
if ($logId === false) {
return $this->renderError('合作商余额不足,请先充值后再重发');
}
// 仅允许从「发放失败(3)」重置为「未提交(0)」,避免与正在处理的单冲突
$reset = Db::name('partners_order')->where('order_id', $orderId)
->where('oil_status', 0)
->where('oil_status_zsy', 3)
->update(['oil_status_zsy' => 0, 'oil_text' => '后台重新发放', 'update_time' => time()]);
if (!$reset) {
// 状态已被其它进程改变 -> 回补刚扣的余额
PartnersBalance::refund(
(int) $order['partners_id'],
(float) $order['total_price'],
(string) $order['partners_order_no'],
$orderId,
(int) $order['store_id']
);
return $this->renderError('当前状态不允许重发(仅「发放失败」的订单可重发)');
}
(new QueueService())->push('partners_queue', json_encode(['order_id' => $orderId], 320));
return $this->renderSuccess('已提交重新发放,请稍后刷新查看结果');
}
/**
* 分油回调
* 重推「发放结果」给下单平台
* @return Json
* @throws \think\db\exception\DbException
*/
public function oilCallback(): Json
{
/*
$model = new OrderModel;
$list = $model->getAll([
['partners_id', '=', 4],
['oil_status', '=', 1],
['oil_callback', '=', 0],
])->toArray();
$queueService = new QueueService();
foreach ($list as $order){
// 存入队列处理
$queueService->push('notify_queue', json_encode([
'order_id' => $order['order_id'],
'type' => 'add',
'optType' => 'share_oil',
'retry_count' => 0,
], 320));
$orderId = (int) $this->request->param('orderId');
$order = OrderModel::detail($orderId);
if (!$order) {
return $this->renderError('订单不存在');
}
return $this->renderSuccess('回调成功');*/
$postData = $this->request->param();
$postData['order_id'] = $this->request->param('orderId');
$order = OrderModel::detail($postData['order_id']);
if($order['oil_status'] == 0){
return $this->renderError('未分油');
}else {
// 存入队列处理
$queueService = new QueueService();
$queueService->push('notify_queue', json_encode([
'order_id' => $order['order_id'],
'type' => 'add',
'optType' => 'share_oil',
'retry_count' => 0,
], 320));
return $this->renderSuccess('回调成功');
if ($order['oil_status'] != 1) {
return $this->renderError('该单未发放成功,无可回调内容');
}
(new QueueService())->push('notify_queue', json_encode([
'order_id' => $orderId,
'type' => 'add',
'optType' => 'share_oil',
'retry_count' => 0,
], 320));
return $this->renderSuccess('已重新推送发放结果');
}
/**
* 使用回调
* 重推「加油核销」结果给下单平台
* @return Json
* @throws \think\db\exception\DbException
*/
public function useCallback(): Json
{
/*
$model = new OrderModel;
$list = $model->getAll([
['partners_id', '=', 4],
['use_status', '=', 1],
['use_callback', '=', 0],
])->toArray();
$queueService = new QueueService();
foreach ($list as $order){
// 存入队列处理
$queueService->push('notify_queue', json_encode([
'order_id' => $order['order_id'],
'optType' => 'add_oil',
'retry_count' => 0,
], 320));
$orderId = (int) $this->request->param('orderId');
$order = OrderModel::detail($orderId);
if (!$order) {
return $this->renderError('订单不存在');
}
return $this->renderSuccess('回调成功');*/
$postData = $this->request->param();
$postData['order_id'] = $this->request->param('orderId');
$order = OrderModel::detail($postData['order_id']);
if($order['use_status'] == 0){
return $this->renderError('未使用');
}else {
// 通知对接公司
$queueService = new QueueService();
$queueService->push('notify_queue', json_encode([
'order_id' => $order['order_id'],
'optType' => 'add_oil',
'retry_count' => 0,
], 320));
return $this->renderSuccess('回调成功');
if ($order['use_status'] != 1) {
return $this->renderError('该单未加油核销,无可回调内容');
}
(new QueueService())->push('notify_queue', json_encode([
'order_id' => $orderId,
'type' => 'sub',
'optType' => 'add_oil',
'retry_count' => 0,
], 320));
return $this->renderSuccess('已重新推送加油结果');
}
}