mzeros 82277cad87 refactor(app): 重构代码以支持移动网络提供商特定逻辑
- 移动网络提供商相关代码从 Core 控制器中提取并重新组织
- 在 Feihan 和 Jiyu 服务中添加新的充值方法
- 修改 Meicheng服务以支持新的移动网络提供商逻辑
- 优化 Port 控制器中的渠道余额检查逻辑
- 优化修复在签名前加字段导致异常报错,提炼到校验签名后判断
2024-12-26 23:00:55 +08:00

109 lines
2.8 KiB
PHP

<?php
namespace app\openapi\controller;
use app\channel\service\ChannelService;
use think\facade\Db;
class Port extends Core
{
protected $check = false;
#检测异常接口预警
public function check_notify()
{
$cur = time();
$time = 60*6;
$whereRaw = $cur . '-unix_timestamp(create_at) <=' . $time;
$data = DB::name('merchant_order')->field("id,merchant_order_id")->whereLike('merchant_callback_msg', 'error')->whereRaw('status = 2 and ' . $whereRaw)->select();
if($data->isEmpty()){
$this->yes('ok','暂无异常订单');
}
$errorOrder=[];
foreach ($data->toArray() as $vo) {
// var_dump($vo);die;
$errorOrder[] = $vo['merchant_order_id'];
}
if($errorOrder){
$errorMsg = implode("\n", $errorOrder);
$this->no(0 ,$errorMsg);
}
}
public function check_channel_balance()
{
$cid = [17];
$channel = DB::name('channel_list')->field("id,name,key")->where('status',1)->whereNotIn('id', $cid)->select();
if($channel->isEmpty()){
$this->yes('ok','暂无可用渠道');
}
$channelService = ChannelService::instance();
$day = input('day');
if (!$day) {
$day = date('Y-m-d', strtotime('-1 day'));
}
$tip_info=[];
foreach ($channel->toArray() as $vo){
try{
$account_data = $channelService->call('account', $vo['id'], $day);
if (is_array($account_data) && isset($account_data['account'])) {
$balance = $account_data['account'];
if(1< $balance && $balance < 10000){
$tip_info[] = $vo['name'].'余额不足,只剩下'.$balance;
}
}
}catch (\Exception $e){
}
}
if($tip_info && !empty($tip_info)){
$errorMsg = implode("\n", $tip_info);
$this->no(0 ,$errorMsg);
}
$this->yes('ok','暂时正常');
}
#检测异常订单error过期预警
public function check_orderparam()
{
$cur = time();
$time = 60*60*25;
$whereRaw = $cur . '-unix_timestamp(create_at) <=' . $time;
$data = DB::name('merchant_order')->field("id,merchant_order_id,mid")->whereLike('param', '%error%')->whereRaw( $whereRaw)->select();
if($data->isEmpty()){
$this->yes('ok','暂无异常订单信息');
}
$errorOrder=[];
foreach ($data->toArray() as $vo) {
if(!in_array($vo['mid'],$errorOrder)){
$errorOrder[] = $vo['mid'];
}
// var_dump($vo);die;
}
if($errorOrder){
$errorMsg = implode("\n", $errorOrder);
$this->no(0 ,$errorMsg);
}
}
}