mzeros 0cfae47bab feat(携号转网): 实现携号转网接口并集成到充值系统
- 新增 Baidumnpapi 类处理百度携号转网 API
- 在 Core 中添加携号转网相关的逻辑和接口
- 修改设置页面,增加携号转网配置选项- 新增商户余额监控和预警功能
- 优化订单处理流程,支持携号转网
2024-12-22 17:41:42 +08:00

182 lines
4.5 KiB
PHP

<?php
namespace app\private_api\controller\merchantApi;
use app\channel\service\ChannelService;
use app\core\Service;
use app\gateway\service\RedisService;
use app\merchant\service\MerchantLogService;
/**
* 接口处理
* Class Handle
* @package app\gateway\api
*/
class Order extends Core
{
# 是否检测数据
protected bool $check = false;
#手动提单
public function HanderSubmit()
{
$this->input();
if(!$this->input['mid']){
$this->no(-1);
}
$this->mid = $this->input['mid'];
$this->product = $this->input['product_key'];
$this->getMerchant();
$param['cash'] = $this->input['cash'];
$param['mobile'] = $this->input['account'];
if($this->product == 'dhcz_mnp'){
$this->getMnp_isp($this->input['account']);
if(isset($this->input['mnp_isp'])){
$param['mnp_isp'] = $this->input['mnp_isp'];
}
}
$param['product'] =$this->product;
$param['order'] = $this->input['order_no'];
$data = ChannelService::instance()->use($this->mid, $this->product, $param, true);
$this->yes($data);
}
#检测运营商并更新运营商
public function getMnp_isp($mobile)
{
$settingPhoneMNPStatus = sysconf('settingPhoneMNPStatus');
if ($settingPhoneMNPStatus == 1) {
$mnp_cid = sysconf('PhoneMnp_cid');
if($mnp_cid){
$mnp_isp = ChannelService::instance()->call('phone_mnp', $mnp_cid, $mobile);
if($mnp_isp == 1){
$this->product = 'ydcz';
$this->input['mnp_isp'] = '移动';
$this->Kou_Mnp($mobile);
return $this->product ;
}elseif($mnp_isp == 2){
$this->product = 'ltcz';
$this->input['mnp_isp'] = '联通';
$this->Kou_Mnp($mobile);
return $this->product ;
}elseif($mnp_isp == 3){
$this->product = 'dxcz';
$this->input['mnp_isp'] = '电信';
$this->Kou_Mnp($mobile);
return $this->product ;
}
}
}
$isp = Service::instance()->isp($this->input['mobile']);
if ($isp == 1) {
$this->product = 'ydcz';
} elseif ($isp == 2) {
$this->product = 'ltcz';
} elseif ($isp == 3) {
$this->product = 'dxcz';
}
return $this->product ;
}
public function Kou_Mnp($mobile)
{
$new_cash = 0.002;
if ($this->merchant['account_surplus'] >= $new_cash) {
$account_type = 1;
} elseif ($this->merchant['credit_surplus'] >= $new_cash) {
$account_type = 2;
}
$redis = RedisService::getInstance();
// 记录扣费到 Redis
// 根据 this->mid 分别记录不同用户的调用次数
$redis_key = 'merchant_cash_deduction:' . $this->mid;
$deduction_count = $redis->incr($redis_key,1);
if ($deduction_count % 10 == 0) {
$new_cash = $new_cash*10;
MerchantLogService::instance()->add($this->mid, $new_cash, $account_type, 3, 'API扣费: 业务余额扣除 - 10次调用携号转网');
// 重置 Redis 中的调用次数
$redis->set($redis_key, 0);
}
}
protected function maketime($v): float|false|int|string
{
if (!$v) {
return '';
}
if (is_numeric($v)) {
return $v;
}
if (is_array($v)) {
$v = $v[1];
}
if (strstr($v, ' ')) {
$t = explode(' ', $v);
$v = $t[0];
$s = explode(':', $t[1]);
} else {
$s = array(0, 0, 0);
}
if (!isset($s[1])) {
$s[1] = 0;
}
if (!isset($s[2])) {
$s[2] = 0;
}
if (strstr($v, '-')) {
$t = explode('-', $v);
} elseif (strstr($v, '/')) {
$u = explode('/', $v);
$t[0] = $u[2];
$t[1] = $u[0];
$t[2] = $u[1];
}
if (!isset($t)) {
$t = array(0, 0, 0);
}
if (!isset($t[1])) {
$t[1] = 0;
}
if (!isset($t[2])) {
$t[2] = 0;
}
$v = mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]);
return $v;
}
}