first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,480 @@
<?php
namespace app\adminapi\controller;
use app\adminapi\controller\BaseAdminController;
use app\common\model\finance\{RechargeRecord};
use app\common\model\user\{UserUdun,User};
use app\common\model\setting\RechargeMethod;
use app\common\service\{UtilsService,ConfigService};
use app\common\model\lh\{LhCoin};
use app\common\enum\YesNoEnum;
use think\facade\Db;
use Exception;
//清空数据
use app\common\model\withdraw\{WithdrawWallet,WithdrawMethod};
use app\common\model\setting\OperationLog;
use app\common\model\finance\{WithdrawRecord,UserFinance,UserTransferRecord};
use app\common\model\user\{UserTron,UserSigninRecord,UserSession,UserRelation,UserRelationAgent,UserKadan,UserGroupRecord,UserRewardRecord,UserNotice,UserInfo,UserLog,UserMineRecord};
use app\common\model\member\{UserMemberRecord};
use app\common\model\mall\{MallGoodsRecord};
use app\common\model\notice\{SmsLog,NoticeRecord,EmailRecord};
use app\common\model\goods\{GoodsRecord};
use app\common\model\auth\{AdminSession,AdminRole,AdminJobs,AdminDept,Admin,SystemRole,SystemRoleMenu};
use app\common\model\lh\{LhRecord};
use app\common\model\feedback\{FeedbackRecord};
use app\common\model\item\{ItemRecord};
/**
* 回调理控制器
* Class NotifyController
* @package app\adminapi\controller
*/
class NotifyController extends BaseAdminController
{
public array $notNeedLogin = ['market','clear','notify','test'];
/**
* @notes 清空数据,开发用,请注释掉
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/04/13 10:54
*/
// public function clear(){
// Db::startTrans();
// try {
// //用户提现钱包
// $withdrawWallets = WithdrawWallet::select()->toArray();
// foreach ($withdrawWallets as &$withdrawWallet) {
// WithdrawWallet::destroy($withdrawWallet['id'],true);
// }
// //用户提现记录
// $withdrawRecords = WithdrawRecord::select()->toArray();
// foreach ($withdrawRecords as &$withdrawRecord) {
// WithdrawRecord::destroy($withdrawRecord['id'],true);
// }
// //用户Udun
// $userUduns = UserUdun::select()->toArray();
// foreach ($userUduns as &$userUdun) {
// UserUdun::destroy($userUdun['id'],true);
// }
// //用户波场钱包
// $userTrons = UserTron::select()->toArray();
// foreach ($userTrons as &$userTron) {
// UserTron::destroy($userTron['id'],true);
// }
// //资金明细
// $userFinances = UserFinance::select()->toArray();
// foreach ($userFinances as &$userFinance) {
// UserFinance::destroy($userFinance['id'],true);
// }
// //用户
// $users = User::select()->toArray();
// foreach ($users as &$user) {
// User::destroy($user['id'],true);
// }
// //角色
// $systemRoles = SystemRole::where('id <> 6')->select()->toArray();
// foreach ($systemRoles as &$systemRole) {
// SystemRole::destroy($systemRole['id'],true);
// }
// //短信记录
// $smsLogs = SmsLog::select()->toArray();
// foreach ($smsLogs as &$smsLog) {
// SmsLog::destroy($smsLog['id'],true);
// }
// //充值记录
// $rechargeRecords = RechargeRecord::select()->toArray();
// foreach ($rechargeRecords as &$rechargeRecord) {
// RechargeRecord::destroy($rechargeRecord['id'],true);
// }
// //通知记录
// $noticeRecords = NoticeRecord::select()->toArray();
// foreach ($noticeRecords as &$noticeRecord) {
// NoticeRecord::destroy($noticeRecord['id'],true);
// }
// //量化记录
// $lhRecords = LhRecord::select()->toArray();
// foreach ($lhRecords as &$lhRecord) {
// LhRecord::destroy($lhRecord['id'],true);
// }
// // //管理员
// // $admins = Admin::select()->toArray();
// // foreach ($admins as &$admin) {
// // Admin::destroy($admin['id'],true);
// // }
// //用户转账记录
// UserTransferRecord::where('1 = 1')->delete();
// //用户签到
// UserSigninRecord::where('1 = 1')->delete();
// //用户会话
// UserSession::where('1 = 1')->delete();
// //奖励活动记录
// UserRewardRecord::where('1 = 1')->delete();
// //用户关系
// UserRelation::where('1 = 1')->delete();
// //用户代理关系
// UserRelationAgent::where('1 = 1')->delete();
// //用户消息
// UserNotice::where('1 = 1')->delete();
// //挖矿记录
// UserMineRecord::where('1 = 1')->delete();
// //会员记录
// UserMemberRecord::where('1 = 1')->delete();
// //用户操作
// UserLog::where('1 = 1')->delete();
// //卡单规则
// UserKadan::where('1 = 1')->delete();
// //用户信息
// UserInfo::where('1 = 1')->delete();
// //用户分组记录
// UserGroupRecord::where('1 = 1')->delete();
// //角色菜单关系
// SystemRoleMenu::where('role_id <> 6')->delete();
// //清空日志
// OperationLog::where('1 = 1')->delete();
// //奖品记录
// MallGoodsRecord::where('1 = 1')->delete();
// //抢单记录
// GoodsRecord::where('1 = 1')->delete();
// //项目记录
// ItemRecord::where('1 = 1')->delete();
// //意见反馈记录
// FeedbackRecord::where('1 = 1')->delete();
// //邮件发送记录
// EmailRecord::where('1 = 1')->delete();
// //管理员会话
// AdminSession::where('1 = 1')->delete();
// //角色关联
// AdminRole::where('role_id <> 0')->delete();
// //岗位关联
// AdminJobs::where('1 = 1')->delete();
// // //部门关联
// AdminDept::where('1 = 1')->delete();
// //波场配置
// ConfigService::set('website', 'tron', ['api_key'=>'','url'=>'']);
// //翻译配置
// $translation = ConfigService::get('website', 'translation');
// $translation['app_key'] = '';
// $translation['sec_key'] = '';
// ConfigService::set('website', 'translation', $translation);
// //短信宝配置
// $smsbao = ConfigService::get('sms', 'smsbao');
// $smsbao['sign'] = '';
// $smsbao['username'] = '';
// $smsbao['api_key'] = '';
// ConfigService::set('sms', 'smsbao', $smsbao);
// //邮箱配置
// ConfigService::set('website', 'email', ['host'=>'','port'=>'','smtp'=>'','charset'=>'','nickname'=>'','username'=>'','password'=>'']);
// //优盾配置
// ConfigService::set('website', 'udun', ['merchant_no'=>'','api_key'=>'','gateway_address'=>'','callUrl'=>'接口域名/adminapi/notify/notify','debug'=>'0','is_open_df'=>'0','pay_min'=>'10','pay_min'=>'10','pay_max'=>'100']);
// //前台链接
// ConfigService::set('website', 'front_link', '');
// Db::commit();
// return '清理成功';
// } catch (\Exception $e) {
// Db::rollback();
// print_r($e->getMessage());
// self::$error = $e->getMessage();
// return '清理失败,请查看日志';
// }
// }
/**
* @notes 更新行情数据
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/04/13 10:54
*/
public function market()
{
Db::startTrans();
try {
$marketData = UtilsService::curl_request('https://api.huobi.pro/market/tickers',[],'GET');
$marketData = json_decode($marketData,true);
if('ok' != $marketData['status']){
throw new \Exception('获取API失败');
}
$marketData = $marketData['data'];
//实时行情
$market = ConfigService::get('website', 'market');
//挖矿货币
$mine = ConfigService::get('website', 'mine');
//充值方式
$rechargeMethods = RechargeMethod::where(['is_show' => 1])
->where(" symbol_rate != '' AND type IN (1,5,7) ")
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
//提现方式
$withdrawMethods = WithdrawMethod::where(['is_show' => 1])
->where(" symbol_rate != '' AND type IN (1) ")
->order(['sort' => 'desc', 'id' => 'desc'])
->select()
->toArray();
foreach ($marketData as $market_data) {
foreach ($market as &$item) {
if($item['symbol'] == $market_data['symbol']){
$item['price'] = $market_data['close'];
$item['rise'] = round((($market_data['close']) - ($market_data['open']))/($market_data['open']) *100,2);
}
}
foreach ($rechargeMethods as &$rechargeMethod) {
if($rechargeMethod['symbol_rate'] == $market_data['symbol']){
RechargeMethod::update([
'id' => $rechargeMethod['id'],
'rate' => 1/$market_data['close'],
]);
}
}
foreach ($withdrawMethods as &$withdrawMethod) {
if($withdrawMethod['symbol_rate'] == $market_data['symbol']){
WithdrawMethod::update([
'id' => $withdrawMethod['id'],
'rate' => 1/$market_data['close'],
]);
}
}
if($mine['symbol_rate'] != '' & $mine['symbol_rate'] == $market_data['symbol']){
$mine['rate'] = 1/$market_data['close'];
}
}
ConfigService::set('website', 'market', $market);
if($mine['symbol_rate'] != '') ConfigService::set('website', 'mine', $mine);
Db::commit();
return 'success';
} catch (\Exception $e) {
Db::rollback();
return $e;
}
}
/**
* @notes 优盾钱包交易回调
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author BD
* @date 2024/04/13 10:54
*/
public function notify(){
Db::startTrans();
try {
$body = $_POST['body'];
$nonce = $_POST['nonce'];
$timestamp = $_POST['timestamp'];
$sign = $_POST['sign'];
//验证签名
$signCheck = UtilsService::udun_signature($body,$timestamp,$nonce);
if ($sign != $signCheck) {
throw new \Exception('签名错误');
return ;
}
$body = json_decode($body);
//$this->printLog("回调接收内容(tradeType):".$body->tradeType);
//$body->tradeType 1充币回调 2提币回调
if ($body->tradeType == 1) {
//$body->status 0待审核 1审核成功 2审核驳回 3交易成功 4交易失败
if($body->status == 3){
//业务处理
//查询钱包地址
$userUdun = UserUdun::where([
'address' => $body->address,
'main_coin_type' => $body->mainCoinType,
'coin_type' => $body->coinType
])
->findOrEmpty();
if ($userUdun->isEmpty()) {
throw new \Exception('地址不存在');
return ;
}
$method = RechargeMethod::where(['id' => $userUdun['method_id']])->findOrEmpty();
if ($method->isEmpty()) {
throw new \Exception('充值方式不存在');
return ;
}
$user = User::where(['id' => $userUdun['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
return ;
}
$money = ($body->amount) / pow(10,($body->decimals));
$order_amount_act = round($money / $method['rate'] , 2);
//判断最低充值金额
$config = ConfigService::get('website', 'trade');
if($order_amount_act < $config['recharge_min']){
return "success";
}
$data = [
'sn' => generate_sn(RechargeRecord::class, 'sn'),
'user_id' => $userUdun['user_id'],
'method_id' => $method['id'],
'amount' => $order_amount_act,
'amount_act' => round($money , $method['precision']),
'rate' => $method['rate'],
'symbol' => $method['symbol'],
'status' => 1,
];
$record = RechargeRecord::create($data);
//记录日志
UtilsService::user_finance_add(
$data['user_id'],
1,
1,
$data['amount'],
$data['sn'],
'',
1//冻结
);
//用户资金修改
UtilsService::user_money_change($data['user_id'], 1, $data['amount'],'user_money');
//充值金额增加
UtilsService::user_money_change($data['user_id'], 1, $data['amount'],'total_recharge');
//团队充值奖励
// UtilsService::team_reward_add($data['user_id'],$data['amount'],1);
//充值活动奖励
UtilsService::activity_reward_add($data['user_id'],$data['amount']);
//更新充值记录用户余额
$user = User::where(['id' => $data['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
//充值次数+1
User::update([
'id' => $user['id'],
'recharge_num' => $user['recharge_num'] + 1
]);
RechargeRecord::update([
'id' => $record['id'],
'user_money' => $user['user_money']
]);
Db::commit();
}
//无论业务方处理成功与否success,failed回调都认为成功
return "success";
}
elseif ($body->tradeType == 2) {
//$body->status 0待审核 1审核成功 2审核驳回 3交易成功 4交易失败
if($body->status == 0){
//业务处理
}
else if($body->status == 1){
//业务处理
}
else if($body->status == 3){
$record = WithdrawRecord::where(['account' => $body->address,'status' => 0,'status2' => 1,'sn' => $body->businessId])->findOrEmpty();
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
return;
}
WithdrawRecord::update([
'id' => $record['id'],
'status' => 1
]);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if (!$user->isEmpty()) {
//提现次数+1
User::update([
'id' => $user['id'],
'withdraw_num' => $user['withdraw_num'] + 1
]);
WithdrawRecord::update([
'id' => $record['id'],
'user_money' => $user['user_money'],
'remark_df' => '',
]);
}
Db::commit();
}
else if($body->status == 2 || $body->status == 4){
$record = WithdrawRecord::where(['account' => $body->address,'status' => 0,'status2' => 1,'sn' => $body->businessId])->findOrEmpty();
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
return;
}
WithdrawRecord::update([
'id' => $record['id'],
'status2' => 0,
'remark_df' => 'udun代付失败',
]);
Db::commit();
}
//无论业务方处理成功与否success,failed回调都认为成功
return "success";
}
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public function test(){
}
}