1、合作商余额查询
2、分油账户司机可用额度
This commit is contained in:
@@ -24,6 +24,10 @@ use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\Express as ExpressModel;
|
||||
use app\common\enum\order\PayType as OrderPayTypeEnum;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use app\common\model\qyt\Enterprise as EnterpriseModel;
|
||||
use app\common\service\QytOil;
|
||||
use app\api\service\User as UserService;
|
||||
use think\facade\Db;
|
||||
use cores\exception\BaseException;
|
||||
use think\facade\Request;
|
||||
use think\response\Json;
|
||||
@@ -309,9 +313,77 @@ class Order extends Controller
|
||||
*/
|
||||
public function qrCode(): Json
|
||||
{
|
||||
// 企油通改造:小程序油品发放/核销链路已停用(上游定聚已下线)。
|
||||
// 保留接口避免小程序端报错,统一返回提示;如需恢复请改走 QytOil。
|
||||
return $this->renderError('该功能已停用');
|
||||
$orderGoodsId = (int)$this->request->param('orderGoodsId');
|
||||
[$order, $error] = $this->findOilOrder($orderGoodsId);
|
||||
if ($error !== '') {
|
||||
return $this->renderError($error);
|
||||
}
|
||||
// 免登链接要带本单企业的 creditcode(营业执照号),把登录固定到该企业
|
||||
$enterprise = EnterpriseModel::detail((int)$order['qyt_enterprise_id']);
|
||||
if (!$enterprise) {
|
||||
return $this->renderError('本单绑定的企油通企业不存在,无法获取加油地址');
|
||||
}
|
||||
if ($enterprise['status'] !== 'approved') {
|
||||
return $this->renderError('企业尚未通过企油通审核,暂时无法加油');
|
||||
}
|
||||
$h5Url = QytOil::forEnterprise($enterprise)->h5Url((string)$order['mobile']);
|
||||
if (!$h5Url) {
|
||||
return $this->renderError('获取加油地址失败,请稍后重试');
|
||||
}
|
||||
// 留痕
|
||||
(new QrCodeModel())->add([
|
||||
'oilCardNo' => $order['oilCardNo'],
|
||||
'qrCode' => $h5Url,
|
||||
'amount' => $order['goods_price'],
|
||||
'order_id' => (int)$order['mall_order_id'],
|
||||
'user_id' => (int)$order['user_id'],
|
||||
'store_id' => (int)$order['store_id'],
|
||||
]);
|
||||
return $this->renderSuccess(['qrCode' => $h5Url], '提交成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按订单商品行找到对应的企油通发放单,并校验是否还能加油
|
||||
*
|
||||
* 小程序单在支付成功后由 MallOil::create 建了一条 yoshop_partners_order
|
||||
* (source='mall',mall_order_goods_id 指回这里的订单商品行)。
|
||||
*
|
||||
* @param int $orderGoodsId
|
||||
* @return array [发放单, 错误信息]
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function findOilOrder(int $orderGoodsId): array
|
||||
{
|
||||
if ($orderGoodsId <= 0) {
|
||||
return [null, '缺少参数 orderGoodsId'];
|
||||
}
|
||||
$userId = (int)UserService::getCurrentLoginUserId();
|
||||
$orderGoods = Db::name('order_goods')->where('order_goods_id', '=', $orderGoodsId)->find();
|
||||
if (!$orderGoods) {
|
||||
return [null, '未找到订单商品'];
|
||||
}
|
||||
// 越权校验:只能取自己订单的加油地址
|
||||
if ((int)$orderGoods['user_id'] !== $userId) {
|
||||
return [null, '未找到订单商品'];
|
||||
}
|
||||
$order = Db::name('partners_order')
|
||||
->where('source', '=', 'mall')
|
||||
->where('mall_order_goods_id', '=', $orderGoodsId)
|
||||
->find();
|
||||
if (!$order) {
|
||||
return [null, '该订单还没有发放记录'];
|
||||
}
|
||||
if ((int)$order['oil_status'] !== 1) {
|
||||
return [null, '油费还在发放中,请稍后再试'];
|
||||
}
|
||||
if ((int)$order['refund_status'] === 2) {
|
||||
return [null, '该订单已退款,不能再加油'];
|
||||
}
|
||||
// 一单可以分多次加油:没加完的单继续给加油地址
|
||||
if ((float)$order['used_amount'] + 0.005 >= (float)$order['total_price']) {
|
||||
return [null, '该订单金额已全部加油'];
|
||||
}
|
||||
return [$order, ''];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,9 +393,10 @@ class Order extends Controller
|
||||
*/
|
||||
public function qrCodeImg(): Json
|
||||
{
|
||||
// 企油通改造:小程序油品发放/核销链路已停用(上游定聚已下线)。
|
||||
// 保留接口避免小程序端报错,统一返回提示;如需恢复请改走 QytOil。
|
||||
return $this->renderError('该功能已停用');
|
||||
// 企油通给的是 H5 免登链接,没有二维码图片接口。
|
||||
// 本商城跑在 H5(微信内置浏览器)下,走的是 qrCode + webview;
|
||||
// 本方法只在微信小程序环境下被调用,暂不支持。
|
||||
return $this->renderError('请在微信或浏览器中打开加油链接');
|
||||
}
|
||||
|
||||
public function getBase64($url){
|
||||
|
||||
Reference in New Issue
Block a user