first commit
This commit is contained in:
156
app/api/logic/ArticleLogic.php
Normal file
156
app/api/logic/ArticleLogic.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
use app\common\model\decorate\{DecorateHint};
|
||||
use app\common\service\{FileService,UtilsService};
|
||||
|
||||
|
||||
/**
|
||||
* 文章逻辑
|
||||
* Class ArticleLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class ArticleLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 文章详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:09
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
//未传语言,则默认使用首个语言
|
||||
if($params['lang'] == ''){
|
||||
$first_lang = UtilsService::get_first_lang();
|
||||
$params['lang'] = $first_lang['symbol'];
|
||||
}
|
||||
// 文章详情
|
||||
$article = Article::getArticleDetailArr($params['id']);
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($article['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
|
||||
$article['content'] = get_file_domain($data_content);
|
||||
$article['title'] = $data_title;
|
||||
unset($article['langs']);
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提示内容详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:09
|
||||
*/
|
||||
public static function hintDetail($params)
|
||||
{
|
||||
//未传语言,则默认使用首个语言
|
||||
if($params['lang'] == ''){
|
||||
$first_lang = UtilsService::get_first_lang();
|
||||
$params['lang'] = $first_lang['symbol'];
|
||||
}
|
||||
$hint = DecorateHint::field(['content','langs'])->findOrEmpty($params['id'])->toArray();
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($hint['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
$hint['content'] = get_file_domain($data_content);
|
||||
unset($hint['langs']);
|
||||
|
||||
return $hint;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 加入收藏
|
||||
* @param $userId
|
||||
* @param $articleId
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:52
|
||||
*/
|
||||
public static function addCollect($articleId, $userId)
|
||||
{
|
||||
$where = ['user_id' => $userId, 'article_id' => $articleId];
|
||||
$collect = ArticleCollect::where($where)->findOrEmpty();
|
||||
if ($collect->isEmpty()) {
|
||||
ArticleCollect::create([
|
||||
'user_id' => $userId,
|
||||
'article_id' => $articleId,
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
} else {
|
||||
ArticleCollect::update([
|
||||
'id' => $collect['id'],
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 取消收藏
|
||||
* @param $articleId
|
||||
* @param $userId
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:59
|
||||
*/
|
||||
public static function cancelCollect($articleId, $userId)
|
||||
{
|
||||
ArticleCollect::update(['status' => YesNoEnum::NO], [
|
||||
'user_id' => $userId,
|
||||
'article_id' => $articleId,
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章分类
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 14:11
|
||||
*/
|
||||
public static function cate()
|
||||
{
|
||||
return ArticleCate::field('id,name')
|
||||
->where('is_show', '=', 1)
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
605
app/api/logic/FinanceLogic.php
Normal file
605
app/api/logic/FinanceLogic.php
Normal file
@@ -0,0 +1,605 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\setting\Language;
|
||||
use app\common\model\withdraw\WithdrawMethod;
|
||||
use app\common\model\withdraw\WithdrawWallet;
|
||||
use app\common\model\withdraw\WithdrawBank;
|
||||
use app\common\model\finance\{WithdrawRecord,RechargeRecord,UserFinance,UserTransferRecord};
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\service\{FileService,UtilsService,ConfigService};
|
||||
use app\common\model\user\{User,UserInfo};
|
||||
use think\facade\Config;
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 资金逻辑层
|
||||
* Class FinanceLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class FinanceLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbExceptionlimit
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/3/21 19:15
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
$field = 'id,sn,change_type as type,change_amount as amount,remark,action,create_time';
|
||||
$lists = UserFinance::field($field)
|
||||
->where([
|
||||
'user_id' => $params['user_id'],
|
||||
])
|
||||
->order(['create_time' => 'desc','id' => 'desc'])
|
||||
->limit(5)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
//查询语言
|
||||
$timeFormat = 'Y-m-d H:i:s';
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if (!$language->isEmpty()) {
|
||||
$timeFormat = $language['time_format'];
|
||||
}
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['create_time'] = date($timeFormat, strtotime($item['create_time']));
|
||||
}
|
||||
|
||||
$report['user_money'] = $user['user_money'];
|
||||
$report['user_point'] = $user['user_point'];
|
||||
// $report['used_money'] = UtilsService::get_used_money($params['user_id']);
|
||||
// if($report['used_money'] < 0) $report['used_money'] = 0;
|
||||
// $report['noused_money'] = UserFinance::where(['user_id' => $params['user_id'],'frozen' => 1])->sum('change_amount');
|
||||
// $report['exp_money'] = 0;
|
||||
|
||||
return [
|
||||
'fund_list' => $lists,
|
||||
'report' => $report
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 资金明细详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/9/20 17:09
|
||||
*/
|
||||
public static function detail(array $params)
|
||||
{
|
||||
$field = 'id,sn,change_type as type,change_amount as amount,remark,action,create_time';
|
||||
$record = UserFinance::field($field)
|
||||
->where(['id' => $params['id'],'user_id' => $params['user_id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
//查询语言
|
||||
$timeFormat = 'Y-m-d H:i:s';
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if (!$language->isEmpty()) {
|
||||
$timeFormat = $language['time_format'];
|
||||
}
|
||||
|
||||
$record['create_time'] = date($timeFormat, strtotime($record['create_time']));
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现方式
|
||||
* @param $lang
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdrawMethod($lang)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $lang])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
$field = 'id,type,name as text,is_qrcode,symbol,rate,precision,charge';
|
||||
$methods = WithdrawMethod::field($field)
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->whereIn('lang_id', [0,$language['id']])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $methods;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 提现钱包
|
||||
* @param $lang
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdrawWallet($lang, $userId)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $lang])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
$field = 'ww.id,ww.method_id,ww.account,ww.type';
|
||||
$field .= ',wm.name as method_name,wm.charge as method_charge,wm.rate as method_rate,wm.symbol as method_symbol,wm.precision as method_precision';
|
||||
$wallets = WithdrawWallet::alias('ww')
|
||||
->join('withdraw_method wm', 'wm.id = ww.method_id')
|
||||
->field($field)
|
||||
->where(['ww.user_id' => $userId])
|
||||
->whereIn('ww.lang_id', [0,$language['id']])
|
||||
->order(['wm.sort' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($wallets as &$wallet) {
|
||||
if($wallet['type'] == 2){
|
||||
$wallet['account'] = substr($wallet['account'],0,3).'******'.substr($wallet['account'],strlen($wallet['account'])-3,strlen($wallet['account']));
|
||||
$wallet['text'] = $wallet['method_name'].'('.$wallet['account'].')';
|
||||
}else{
|
||||
$wallet['account'] = substr($wallet['account'],0,4).'******'.substr($wallet['account'],strlen($wallet['account'])-4,strlen($wallet['account']));
|
||||
$wallet['text'] = $wallet['method_name'].'('.$wallet['account'].')';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $wallets;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现银行
|
||||
* @param $lang
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdrawBanks($lang)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $lang])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
$field = ['id','name'];
|
||||
$methods = WithdrawBank::field($field)
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->where(['lang_id' => $language['id']])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $methods;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 绑定提现钱包
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdrawWalletAdd(array $params)
|
||||
{
|
||||
try {
|
||||
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
$method = WithdrawMethod::where(['id' => $params['method_id']])->findOrEmpty();
|
||||
|
||||
$bank_name = '';
|
||||
$bank_id = '';
|
||||
if($method['type'] == 3){
|
||||
$bank = WithdrawBank::where(['id' => $params['bank_id']])->findOrEmpty();
|
||||
$bank_name = $bank['name'];
|
||||
$bank_id = $bank['id'];
|
||||
}
|
||||
|
||||
|
||||
$wallet = WithdrawWallet::create([
|
||||
'lang_id' => $method['lang_id'],
|
||||
'user_id' => $params['user_id'],
|
||||
'method_id' => $params['method_id'],
|
||||
'bank_id' => $bank_id,
|
||||
'type' => $method['type'],
|
||||
'name' => isset($params['name'])?$params['name']:'',
|
||||
'account' => $params['account'],
|
||||
'img' => isset($params['img'])?$params['img']:'',
|
||||
'bank_name' => $bank_name,
|
||||
]);
|
||||
|
||||
return [
|
||||
'from' => 'walletAdd'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现配置
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdrawConfig(array $params)
|
||||
{
|
||||
$config = ConfigService::get('website', 'trade');
|
||||
|
||||
$user = User::where(['id' => $params['user_id']]) -> findOrEmpty();
|
||||
|
||||
$is_withdraw = true;
|
||||
|
||||
// //判断提现次数(每24小时可提现n次)
|
||||
// $time24Hours = time() - 24 * 60 * 60;
|
||||
|
||||
//判断提现次数(每天可提现n次)
|
||||
$time24Hours = strtotime("today midnight");
|
||||
|
||||
$withdraw_num = WithdrawRecord::where(['user_id' => $params['user_id']])
|
||||
->where('status in (0,1)')
|
||||
->where("create_time > $time24Hours")
|
||||
->count();
|
||||
if($config['withdraw_num'] <= $withdraw_num){
|
||||
$is_withdraw = false;
|
||||
}
|
||||
|
||||
//查询实名认证状态
|
||||
$need_realname = 0;
|
||||
$userInfo = UserInfo::where(['user_id' => $params['user_id']]) -> findOrEmpty();
|
||||
if (!$userInfo->isEmpty() && $config['need_realname'] == 1) {
|
||||
if($userInfo['auth_card'] != 1) $need_realname = 1;
|
||||
}
|
||||
|
||||
//查询初始交易密码
|
||||
$need_set_pwd = 0;
|
||||
$pwd_pay = ConfigService::get('login', 'password_pay');
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($user['password_pay'] == create_password($pwd_pay, $passwordSalt)) {
|
||||
$need_set_pwd = 1;
|
||||
}
|
||||
|
||||
$balance = UtilsService::get_used_money($params['user_id']);
|
||||
if($balance < 0) $balance = 0;
|
||||
|
||||
$noused_money = $user['user_money'] - $balance;
|
||||
|
||||
//预输入上一次提现方式和提现地址
|
||||
$ahead['method_id'] = 0;
|
||||
$ahead['address'] = '';
|
||||
$withdrawRecord = WithdrawRecord::where(['user_id' => $params['user_id']])
|
||||
->order(['create_time' => 'desc', 'id' => 'desc'])
|
||||
->findOrEmpty();
|
||||
if(!$withdrawRecord->isEmpty()){
|
||||
$ahead['method_id'] = $withdrawRecord['method_id'];
|
||||
$ahead['address'] = $withdrawRecord['account'];
|
||||
}
|
||||
|
||||
return [
|
||||
'min' => $config['withdraw_min'],
|
||||
'max' => $config['withdraw_max'],
|
||||
'num' => $config['withdraw_num'],
|
||||
'is_withdraw' => $is_withdraw,
|
||||
'balance' => $balance,
|
||||
'noused_money' => $noused_money,
|
||||
'need_realname' => $need_realname,
|
||||
'need_set_pwd' => $need_set_pwd,
|
||||
'ahead' => $ahead,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdraw(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$method = WithdrawMethod::where(['id' => $params['method_id']])->findOrEmpty();
|
||||
|
||||
$order_amount_act = round($params['money'] * $method['rate'] , $method['precision']);
|
||||
|
||||
//手续费
|
||||
$charge = 0;
|
||||
if($method['charge'] > 0){
|
||||
$charge = round($params['money'] * $method['charge']/100,2);
|
||||
if($charge <= 0.01) $charge = 0;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'sn' => generate_sn(WithdrawRecord::class, 'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'method_id' => $method['id'],
|
||||
'amount' => $params['money'],
|
||||
'amount_act' => $order_amount_act,
|
||||
'rate' => $method['rate'],
|
||||
'symbol' => $method['symbol'],
|
||||
'charge' => $charge,//手续费
|
||||
'type' => $method['type'],
|
||||
'account' => $params['address'],
|
||||
];
|
||||
$order = WithdrawRecord::create($data);
|
||||
|
||||
//USDT发起 优盾代付
|
||||
if($method['type'] == 1){
|
||||
$udun = ConfigService::get('website', 'udun');
|
||||
|
||||
if($udun['is_open_df'] == 1 && $method['is_open_df'] == 1 && $order['amount'] - $udun['pay_min'] >= 0 && $order['amount'] - $udun['pay_max'] <= 0){
|
||||
$udunDispatch = UtilsService::get_udunDispatch();
|
||||
|
||||
$main_coin_type = $method['main_coin_type'];
|
||||
$coin_type = $method['coin_type'];
|
||||
|
||||
//验证地址合法性
|
||||
$result1 = $udunDispatch->checkAddress($main_coin_type,$order['account']);
|
||||
|
||||
if($result1['code'] == 200){
|
||||
//申请提币
|
||||
//提币金额 = (金额 - 手续费) x 汇率
|
||||
$amount_df = round(($order['amount']- $order['charge']) * $method['rate'] , $method['precision']);
|
||||
$result2 = $udunDispatch->withdraw($order['sn'],$main_coin_type,$coin_type,$order['account'],$amount_df);
|
||||
if($result2['code'] == 200){
|
||||
WithdrawRecord::update([
|
||||
'id' => $order['id'],
|
||||
'status2' => 1
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//记录日志
|
||||
UtilsService::user_finance_add(
|
||||
$data['user_id'],
|
||||
2,
|
||||
2,
|
||||
$data['amount'],
|
||||
$data['sn']
|
||||
);
|
||||
|
||||
//用户资金修改
|
||||
UtilsService::user_money_change($data['user_id'], 2, $data['amount'],'user_money');
|
||||
|
||||
//提现金额增加
|
||||
UtilsService::user_money_change($data['user_id'], 1, $data['amount'],'total_withdraw');
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'order_id' => (int)$order['id'],
|
||||
'from' => 'withdraw'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 提现记录详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function withdrawRecordDetail($params)
|
||||
{
|
||||
$field = 'id,method_id,sn,amount,amount_act,rate,charge,symbol,account,status,type,create_time,remark';
|
||||
$record = WithdrawRecord::field($field)
|
||||
->append(['method_name'])
|
||||
->where(['id' => $params['id'],'user_id' => $params['user_id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
//查询语言
|
||||
$timeFormat = 'Y-m-d H:i:s';
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if (!$language->isEmpty()) {
|
||||
$timeFormat = $language['time_format'];
|
||||
}
|
||||
|
||||
$record['create_time'] = date($timeFormat, strtotime($record['create_time']));
|
||||
|
||||
if($record['type'] == 2){
|
||||
$record['account'] = substr($record['account'],0,3).'******'.substr($record['account'],strlen($record['account'])-3,strlen($record['account']));
|
||||
$record['account'] = $record['method_name'].'('.$record['account'].')';
|
||||
}else{
|
||||
$record['account'] = substr($record['account'],0,4).'******'.substr($record['account'],strlen($record['account'])-4,strlen($record['account']));
|
||||
$record['account'] = $record['method_name'].'('.$record['account'].')';
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 充值记录详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function rechargeRecordDetail($params)
|
||||
{
|
||||
$field = 'id,method_id,sn,amount,amount_act,rate,symbol,status,create_time';
|
||||
$record = RechargeRecord::field($field)
|
||||
->append(['method_name'])
|
||||
->where(['id' => $params['id'],'user_id' => $params['user_id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
//查询语言
|
||||
$timeFormat = 'Y-m-d H:i:s';
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if (!$language->isEmpty()) {
|
||||
$timeFormat = $language['time_format'];
|
||||
}
|
||||
|
||||
$record['create_time'] = date($timeFormat, strtotime($record['create_time']));
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用户转账数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbExceptionlimit
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/3/21 19:15
|
||||
*/
|
||||
public static function transferIndex(array $params)
|
||||
{
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
$resUser['balance'] = UtilsService::get_used_money($params['user_id']);
|
||||
if($resUser['balance'] < 0) $resUser['balance'] = 0;
|
||||
|
||||
//查询初始交易密码
|
||||
$need_set_pwd = 0;
|
||||
$pwd_pay = ConfigService::get('login', 'password_pay');
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($user['password_pay'] == create_password($pwd_pay, $passwordSalt)) {
|
||||
$need_set_pwd = 1;
|
||||
}
|
||||
|
||||
$config = ConfigService::get('website', 'trade');
|
||||
$config['min'] = $config['transfer_min'];
|
||||
$config['max'] = $config['transfer_max'];
|
||||
|
||||
$config['need_set_pwd'] = $need_set_pwd;
|
||||
|
||||
return [
|
||||
'config' => $config,
|
||||
'user' => $resUser
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 转账
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function transfer(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//转出用户
|
||||
$userFrom = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
//转入用户
|
||||
$userTo = User::where(['account' => $params['account']])->findOrEmpty();
|
||||
|
||||
//转出用户记录
|
||||
$data = [
|
||||
'sn' => generate_sn(UserTransferRecord::class, 'sn'),
|
||||
'user_id' => $userFrom['id'],
|
||||
'user_id_from' => $userFrom['id'],
|
||||
'user_id_to' => $userTo['id'],
|
||||
'amount' => $params['money'],
|
||||
'type' => 2,
|
||||
];
|
||||
$orderFrom = UserTransferRecord::create($data);
|
||||
|
||||
//记录日志
|
||||
UtilsService::user_finance_add(
|
||||
$data['user_id'],
|
||||
19,
|
||||
2,
|
||||
$data['amount'],
|
||||
$data['sn']
|
||||
);
|
||||
|
||||
//用户资金修改
|
||||
UtilsService::user_money_change($data['user_id'], 2, $data['amount'],'user_money');
|
||||
|
||||
//转入用户记录
|
||||
$data = [
|
||||
'sn' => generate_sn(UserTransferRecord::class, 'sn'),
|
||||
'user_id' => $userTo['id'],
|
||||
'user_id_from' => $userFrom['id'],
|
||||
'user_id_to' => $userTo['id'],
|
||||
'amount' => $params['money'],
|
||||
'type' => 1,
|
||||
];
|
||||
$orderTo = UserTransferRecord::create($data);
|
||||
|
||||
//记录日志
|
||||
UtilsService::user_finance_add(
|
||||
$data['user_id'],
|
||||
20,
|
||||
1,
|
||||
$data['amount'],
|
||||
$data['sn']
|
||||
);
|
||||
|
||||
//用户资金修改
|
||||
UtilsService::user_money_change($data['user_id'], 1, $data['amount'],'user_money');
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'from' => 'transfer'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
350
app/api/logic/IndexLogic.php
Normal file
350
app/api/logic/IndexLogic.php
Normal file
@@ -0,0 +1,350 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
|
||||
use app\common\service\{FileService,UtilsService,ConfigService};
|
||||
use app\common\model\article\{Article,ArticleCate};
|
||||
use app\common\model\decorate\{DecorateSwiper,DecorateNav,DecorateHint};
|
||||
use app\common\model\item\Item;
|
||||
use app\common\model\user\{User,UserNotice};
|
||||
use app\common\model\setting\Language;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class IndexLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
//未传语言,则默认使用首个语言
|
||||
if($params['lang'] == ''){
|
||||
$first_lang = UtilsService::get_first_lang();
|
||||
$params['lang'] = $first_lang['symbol'];
|
||||
}
|
||||
|
||||
//轮播图
|
||||
$field1 = ['name','image','link','langs','image_ext'];
|
||||
$swipers = DecorateSwiper::field($field1)
|
||||
->where(['is_show' => 1,'loca' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($swipers as &$swiper) {
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($swiper['langs'],$params['lang']);
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
if($swiper['image_ext'] != ''){
|
||||
$swiper['image'] =$swiper['image_ext'];
|
||||
}else{
|
||||
$swiper['image'] = FileService::getFileUrl($data_image);
|
||||
}
|
||||
unset($swiper['langs']);
|
||||
}
|
||||
|
||||
//菜单按钮
|
||||
$field2 = ['name','image','link','langs','image_ext'];
|
||||
$navs = DecorateNav::field($field2)
|
||||
->where(['is_show' => 1,'loca' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($navs as &$nav) {
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($nav['langs'],$params['lang']);
|
||||
$data_name = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_name = $data['name'];
|
||||
}
|
||||
|
||||
$nav['name'] = $data_name;
|
||||
if($nav['image_ext'] != ''){
|
||||
$nav['image'] = $nav['image_ext'];
|
||||
}
|
||||
unset($nav['langs']);
|
||||
}
|
||||
|
||||
//滚动通知
|
||||
$field3 = ['id','langs'];
|
||||
$notice = Article::field($field3)
|
||||
->where(['is_show' => 1,'is_notice' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->findOrEmpty();
|
||||
|
||||
if(!$notice->isEmpty()){
|
||||
$notice['is_show'] = true;
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($notice['langs'],$params['lang']);
|
||||
$data_text = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_text = $data['content'];
|
||||
}
|
||||
$notice['text'] = strip_tags(html_entity_decode($data_text));
|
||||
unset($notice['langs']);
|
||||
|
||||
}else{
|
||||
$notice['is_show'] = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//合作伙伴
|
||||
$field4 = ['is_show','content','langs'];
|
||||
$partner = DecorateHint::field($field4)
|
||||
->findOrEmpty(4)->toArray();
|
||||
|
||||
if($partner['is_show']){
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($partner['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
$partner['content'] = get_file_domain($data_content);
|
||||
}
|
||||
unset($partner['langs']);
|
||||
|
||||
|
||||
//首页视频
|
||||
$field7 = ['is_show','content','image','langs'];
|
||||
$video = DecorateHint::field($field7)
|
||||
->findOrEmpty(6)->toArray();
|
||||
|
||||
if($video['is_show']){
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($video['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
preg_match_all("/<source[^<>]*src=[\"]([^\"]+)[\"][^<>]*>/im",get_file_domain($data_content),$matches);
|
||||
|
||||
$video['url'] = count($matches[1]) > 0?$matches[1][0]:'';
|
||||
$video['image'] = FileService::getFileUrl($data_image);
|
||||
|
||||
unset($video['content']);
|
||||
unset($video['langs']);
|
||||
}
|
||||
|
||||
//弹窗内容
|
||||
$field8 = ['id','langs'];
|
||||
$popup = Article::field($field8)
|
||||
->where(['is_show' => 1,'is_popup' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->findOrEmpty();
|
||||
|
||||
if(!$popup->isEmpty()){
|
||||
$popup['is_show'] = true;
|
||||
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($popup['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
$popup['content'] = get_file_domain($data_content);
|
||||
unset($popup['langs']);
|
||||
}else{
|
||||
$popup['is_show'] = false;
|
||||
}
|
||||
|
||||
//实时行情
|
||||
$markets = ConfigService::get('website', 'market');
|
||||
foreach ($markets as &$market) {
|
||||
//图片域名格式化
|
||||
$market['logo'] = FileService::getFileUrl($market['logo']);
|
||||
}
|
||||
|
||||
$unread_notice = 0;
|
||||
|
||||
if($params['user_id']!=0){
|
||||
$unread_notice = UserNotice::where(['user_id' => $params['user_id']])
|
||||
->where(['read' => 0])
|
||||
->count();
|
||||
}
|
||||
|
||||
//推荐项目
|
||||
$field_item = ['id','title','image','rate','cycle','progress','type','member_id','langs'];
|
||||
$items = Item::field($field_item)
|
||||
->append(['vip_name'])
|
||||
->where(['is_show' => 1,'is_index' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($items as &$item) {
|
||||
$item['progress'] = round($item['progress'],2);
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($item['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
$item['title'] = $data_title;
|
||||
$item['image'] = FileService::getFileUrl($data_image);
|
||||
unset($item['langs']);
|
||||
}
|
||||
|
||||
return [
|
||||
// 'article' => $article,
|
||||
'banner' => $swipers,
|
||||
'navs' => $navs,
|
||||
'notice' => $notice,
|
||||
'partner' => $partner,
|
||||
// 'articleCate' => $articleCate,
|
||||
// 'articles' => $articles,
|
||||
'video' => $video,
|
||||
'popup' => $popup,
|
||||
'market' => $markets,
|
||||
'unreadNotice' => $unread_notice,
|
||||
'kefu_logo' => FileService::getFileUrl(ConfigService::get('website', 'kefu_logo')),
|
||||
'show_kefu' => ConfigService::get('website', 'show_kefu'),
|
||||
'kefu_link' => ConfigService::get('website', 'kefu_link'),
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData($lang="")
|
||||
{
|
||||
$codeStr = ConfigService::get('login', 'country_code');
|
||||
$region_codes = ConfigService::get('website', 'regioncode');
|
||||
foreach ($region_codes as &$region_code) {
|
||||
//图片域名格式化
|
||||
$region_code['logo'] = FileService::getFileUrl($region_code['logo']);
|
||||
}
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 邀请码
|
||||
'invite_code' => ConfigService::get('login', 'invite_code', config('project.login.invite_code')),
|
||||
// 国家区号
|
||||
'region_code' => $region_codes,
|
||||
];
|
||||
// 网址信息
|
||||
$website = [
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
'shop_logo2' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo2')),
|
||||
'currency' => ConfigService::get('website', 'currency'),
|
||||
'currency2' => ConfigService::get('website', 'currency2'),
|
||||
'precision' => ConfigService::get('website', 'precision'),
|
||||
'down_link' => ConfigService::get('website', 'down_link'),
|
||||
'is_down' => ConfigService::get('website', 'is_down'),
|
||||
];
|
||||
|
||||
if($lang == ''){
|
||||
//查询首个语言
|
||||
$first_lang = UtilsService::get_first_lang();
|
||||
$website['lang'] = $first_lang['symbol'];
|
||||
$website['formatTime'] = $first_lang['time_format'];
|
||||
}else{
|
||||
$language = Language::where(['symbol' => $lang,'is_show' => 1])->findOrEmpty();
|
||||
$website['lang'] = $lang;
|
||||
$website['formatTime'] = $language['time_format'];
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'version'=> config('project.version')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 国家区号
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2023/9/21 18:37
|
||||
*/
|
||||
public static function getCountryCode()
|
||||
{
|
||||
$region_codes = ConfigService::get('website', 'regioncode');
|
||||
foreach ($region_codes as &$region_code) {
|
||||
//图片域名格式化
|
||||
$region_code['logo'] = FileService::getFileUrl($region_code['logo']);
|
||||
}
|
||||
return $region_codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 语言数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/10/13 10:53
|
||||
*/
|
||||
public static function getKefuLists()
|
||||
{
|
||||
$lists = ConfigService::get('website', 'kefu');
|
||||
foreach ($lists as &$list) {
|
||||
$list['logo'] = FileService::getFileUrl($list['logo']);
|
||||
}
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 行情数据
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2023/10/13 10:53
|
||||
*/
|
||||
public static function getMarketData()
|
||||
{
|
||||
//实时行情
|
||||
$markets = ConfigService::get('website', 'market');
|
||||
foreach ($markets as &$market) {
|
||||
//图片域名格式化
|
||||
$market['logo'] = FileService::getFileUrl($market['logo']);
|
||||
}
|
||||
return $markets;
|
||||
}
|
||||
|
||||
}
|
||||
324
app/api/logic/ItemLogic.php
Normal file
324
app/api/logic/ItemLogic.php
Normal file
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\{UtilsService,ConfigService,FileService};
|
||||
use app\common\model\item\{Item,ItemRecord};
|
||||
use app\common\model\finance\{UserFinance};
|
||||
use app\common\model\user\{User};
|
||||
use app\common\model\member\UserMember;
|
||||
use app\common\model\decorate\{DecorateHint};
|
||||
use app\common\model\setting\Language;
|
||||
use think\facade\Config;
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 项目逻辑
|
||||
* Class ItemLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class ItemLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
// 获取今天0点的时间戳
|
||||
$todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
|
||||
$field_item = ['id','title','image','rate','cycle','progress','type','member_id','langs'];
|
||||
$items = Item::field($field_item)
|
||||
->append(['vip_name'])
|
||||
->where(['is_show' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($items as &$item) {
|
||||
$item['progress'] = round($item['progress'],2);
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($item['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
$item['title'] = $data_title;
|
||||
$item['image'] = FileService::getFileUrl($data_image);
|
||||
unset($item['langs']);
|
||||
}
|
||||
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
$userMember = UserMember::where(['id' => $member_id])
|
||||
->field('id, name, logo, bg_img, text_color, money, level1_num, lh_min, lh_max, lh_num')
|
||||
->findOrEmpty();
|
||||
|
||||
$user_res['member'] = $userMember;
|
||||
$user_res['balance'] = $user['user_money'];
|
||||
$user_res['totalMoney'] = ItemRecord::where(['user_id' => $params['user_id'],'status' => 1])->sum('money');
|
||||
$user_res['todayIncome'] = UserFinance::where(['user_id' => $params['user_id'],'change_type' => 17])->where("create_time > $todayStart")->sum('change_amount');
|
||||
$user_res['totalIncome'] = $user['total_income_invest'];
|
||||
|
||||
return [
|
||||
'items' => $items,
|
||||
'user' => $user_res,
|
||||
// 服务器时间
|
||||
'server_date' => date('Y/m/d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 项目详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
try {
|
||||
// 获取今天0点的时间戳
|
||||
$todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
|
||||
$item = Item::field("id,type,title,image,content,min_money,max_money,point,rate,cycle,progress,langs,member_id")->append(['vip_name'])->where(['is_show' => 1])->findOrEmpty($params['id']);
|
||||
if($item->isEmpty()){
|
||||
throw new \Exception('network.parameterAbnormality');
|
||||
}
|
||||
$item['progress'] = round($item['progress'],2);
|
||||
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($item['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
$data_image = '';
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
$data_image = $data['image'];
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
|
||||
$item['title'] = $data_title;
|
||||
$item['image'] = FileService::getFileUrl($data_image);
|
||||
$item['content'] = get_file_domain($data_content);
|
||||
unset($item['langs']);
|
||||
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
//查询初始交易密码
|
||||
$need_set_pwd = 0;
|
||||
$pwd_pay = ConfigService::get('login', 'password_pay');
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($user['password_pay'] == create_password($pwd_pay, $passwordSalt)) {
|
||||
$need_set_pwd = 1;
|
||||
}
|
||||
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
$userMember = UserMember::where(['id' => $member_id])
|
||||
->field('id,item_num,item_add_rate')
|
||||
->findOrEmpty();
|
||||
|
||||
$user_res['member'] = $userMember;
|
||||
$user_res['balance'] = $user['user_money'];
|
||||
|
||||
//今日投资次数
|
||||
$user_res['today_order'] = ItemRecord::where("create_time > $todayStart")
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->count();
|
||||
|
||||
return [
|
||||
'item' => $item,
|
||||
'user' => $user_res,
|
||||
'need_set_pwd' => $need_set_pwd,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 合同详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function contract($params)
|
||||
{
|
||||
try {
|
||||
$itemRecord = ItemRecord::where(['id' => $params['id']])->findOrEmpty();
|
||||
if($itemRecord->isEmpty()){
|
||||
throw new \Exception('network.parameterAbnormality');
|
||||
}
|
||||
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
//合同内容
|
||||
$contract = DecorateHint::findOrEmpty(23)->toArray();
|
||||
|
||||
$end_time = date('Y-m-d', $itemRecord['end_time']);
|
||||
$date = date('Y-m-d', strtotime($itemRecord['create_time']));
|
||||
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($contract['langs'],$params['lang']);
|
||||
$content = get_file_domain($data['content']);
|
||||
|
||||
$content = str_replace('{sn}', $itemRecord['contract_no'], $content);
|
||||
$content = str_replace('{username}', $user['country_code'].' '.$user['account'], $content);
|
||||
$content = str_replace('{money}', $itemRecord['money'], $content);
|
||||
$content = str_replace('{rate}', $itemRecord['rate'], $content);
|
||||
$content = str_replace('{total_income}', $itemRecord['total_income'], $content);
|
||||
$content = str_replace('{date_e}', $end_time, $content);
|
||||
$content = str_replace('{date}', $date, $content);
|
||||
|
||||
return [
|
||||
'content' => $content,
|
||||
'type' => $itemRecord['type'],
|
||||
'cycle' => $itemRecord['cycle'],
|
||||
'contract_y_logo' => FileService::getFileUrl($contract['contract_y_logo']),
|
||||
'contract_b_logo' => FileService::getFileUrl($contract['contract_b_logo']),
|
||||
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 投资
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function invest(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 获取今天0点的时间戳
|
||||
// $todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
|
||||
$user = User::where(['id' => $params['user_id']]) -> findOrEmpty();
|
||||
|
||||
$item = Item::where(['is_show' => 1])->findOrEmpty($params['id']);
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($item['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
$data_image = '';
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
$data_image = $data['image'];
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
|
||||
$item['title'] = $data_title;
|
||||
$item['image'] = $data_image;
|
||||
$item['content'] = $data_content;
|
||||
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
$userMember = UserMember::where(['id' => $member_id])->findOrEmpty();
|
||||
|
||||
//判断加息率
|
||||
if($userMember['item_add_rate'] > 0) $item['rate'] = round($item['rate'] + $userMember['item_add_rate'],2);
|
||||
|
||||
//投资类型
|
||||
// 1每日付息到期还本
|
||||
// 2到期还本付息(日)
|
||||
// 3到期还本付息(时)
|
||||
// 4每时付息到期还本
|
||||
$end_time = time() + ($item['cycle'] * 24 * 60 * 60);//到期时间(天)
|
||||
$total_num = $item['cycle'];
|
||||
$wait_num = $item['cycle'];
|
||||
$total_income = round($params['money'] * $item['rate'] * $item['cycle'] / 100,2);//总收益(每日/时)
|
||||
|
||||
switch($item['type']){
|
||||
case 1:
|
||||
|
||||
break;
|
||||
case 2:
|
||||
$wait_num = 1;
|
||||
$total_income = round($params['money'] * $item['rate'] / 100,2);
|
||||
break;
|
||||
case 3:
|
||||
$wait_num = 1;
|
||||
$total_income = round($params['money'] * $item['rate'] / 100,2);
|
||||
$end_time = time() + ($item['cycle'] * 60 * 60);//到期时间(时)
|
||||
break;
|
||||
case 4:
|
||||
$end_time = time() + ($item['cycle'] * 60 * 60);//到期时间(时)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'sn' => generate_sn(ItemRecord::class, 'sn'),
|
||||
'contract_no' => generate_sn(ItemRecord::class, 'contract_no'),
|
||||
'user_id' => $params['user_id'],
|
||||
'item_id' => $item['id'],
|
||||
'item_title' => $item['title'],
|
||||
'item_image' => FileService::setFileUrl($item['image']),
|
||||
'item_langs' => $item['langs'],
|
||||
'money' => $params['money'],
|
||||
'point' => $item['point'],
|
||||
'rate' => $item['rate'],
|
||||
'cycle' => $item['cycle'],
|
||||
'total_num' => $total_num,
|
||||
'wait_num' => $wait_num,
|
||||
'total_income' => $total_income,
|
||||
'type' => $item['type'],
|
||||
'status' => 1,//状态1进行中2已结束
|
||||
'end_time' => $end_time,//到期时间
|
||||
];
|
||||
$order = ItemRecord::create($data);
|
||||
|
||||
//记录日志
|
||||
UtilsService::user_finance_add(
|
||||
$data['user_id'],
|
||||
16,
|
||||
2,
|
||||
$data['money'],
|
||||
$data['sn']
|
||||
);
|
||||
|
||||
//用户资金修改
|
||||
UtilsService::user_money_change($data['user_id'], 2, $data['money'],'user_money');
|
||||
//累积投资金额
|
||||
UtilsService::user_money_change($data['user_id'], 1, $data['money'],'total_invest');
|
||||
|
||||
//赠送积分
|
||||
if($item['point'] > 0){
|
||||
UtilsService::user_money_change($data['user_id'], 1, $item['point'],'user_point');
|
||||
}
|
||||
|
||||
//更新会员等级
|
||||
UtilsService::set_user_member($params['user_id']);
|
||||
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
100
app/api/logic/LanguageLogic.php
Normal file
100
app/api/logic/LanguageLogic.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\setting\Language;
|
||||
use app\common\model\setting\LanguagePag;
|
||||
|
||||
|
||||
/**
|
||||
* 文章逻辑
|
||||
* Class LanguageLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class LanguageLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 语言详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:09
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
// 语言详情
|
||||
$field = ['id','name_loc as name','symbol','precision'];
|
||||
$where = ['symbol' => $params['name']];
|
||||
$language = Language::field($field)
|
||||
->where($where)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 语言数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:53
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
$field = ['id','name_loc as name','symbol','precision','time_format'];
|
||||
$langs = Language::field($field)
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $langs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 语言包数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:53
|
||||
*/
|
||||
public static function getPagAllData($params)
|
||||
{
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
$field = ['type','name','value'];
|
||||
$pags = LanguagePag::field($field)
|
||||
->where(['lang' => $params['lang']])
|
||||
->order(['type' => 'asc','name' => 'asc', 'value' => 'asc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $pags;
|
||||
}
|
||||
|
||||
}
|
||||
507
app/api/logic/LoginLogic.php
Normal file
507
app/api/logic/LoginLogic.php
Normal file
@@ -0,0 +1,507 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\api\service\{UserTokenService, WechatUserService};
|
||||
use app\common\enum\{LoginEnum, user\UserTerminalEnum, YesNoEnum};
|
||||
use app\common\service\{
|
||||
UtilsService,
|
||||
ConfigService,
|
||||
FileService,
|
||||
wechat\WeChatConfigService,
|
||||
wechat\WeChatMnpService,
|
||||
wechat\WeChatOaService,
|
||||
wechat\WeChatRequestService
|
||||
};
|
||||
use app\common\model\user\{User,UserInfo,UserAuth,UserNotice};
|
||||
use app\common\model\decorate\DecorateHint;
|
||||
use think\facade\{Db,Config};
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class LoginLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 账号密码注册
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 15:37
|
||||
*/
|
||||
public static function register(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//查询IP注册数量
|
||||
$config_ip_num = ConfigService::get('login', 'ip_num');
|
||||
$count_ip = User::where(['register_ip' => request()->ip()])->count();
|
||||
if ($config_ip_num <= $count_ip) {
|
||||
throw new \Exception('login.ipExisted');
|
||||
}
|
||||
|
||||
$regioncodes = ConfigService::get('website', 'regioncode');
|
||||
$country_code = $params['country_code'];
|
||||
|
||||
$found = array_filter($regioncodes, function($object) use ($country_code) {
|
||||
return strpos($object['code'], $country_code) !== false;
|
||||
});
|
||||
if ($found === false) {
|
||||
throw new \Exception('network.parameterAbnormality');
|
||||
}
|
||||
$userSn = User::createUserSn();
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$password_pay_ = ConfigService::get('login', 'password_pay');
|
||||
$password_pay = create_password($password_pay_, $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
|
||||
|
||||
//判断上级
|
||||
//邀请码
|
||||
$top_sn = $params['invite_code'];
|
||||
|
||||
//判断邀请码是否填写
|
||||
$is_invite_code = ConfigService::get('login', 'invite_code');
|
||||
if($is_invite_code && $top_sn == '') throw new \Exception('login.inviteCodeEmpty');//请输入邀请码
|
||||
|
||||
$top_User = '';
|
||||
|
||||
if(isset($top_sn) && $top_sn != ''){
|
||||
if(!preg_match("/^-?\d+$/",$top_sn)) throw new \Exception('login.inviteCodeNoExist');//邀请码不存在
|
||||
|
||||
$top_User = User::where(['sn' => $top_sn,'is_sn' => 1])->findOrEmpty();
|
||||
if ($top_User->isEmpty()) {
|
||||
throw new \Exception('login.inviteCodeNoExist');//邀请码不存在
|
||||
}
|
||||
}
|
||||
|
||||
$mobile = $params['account'];
|
||||
if($params['login_way'] == 1){
|
||||
$mobile = $params['country_code'] . ' ' .$params['account'];
|
||||
}
|
||||
|
||||
$is_transfer = 0;
|
||||
$trade = ConfigService::get('website', 'trade');
|
||||
if($trade['is_transfer'] != 0) $is_transfer = 1;
|
||||
|
||||
$user = User::create([
|
||||
'sn' => $userSn,
|
||||
'avatar' => $avatar,
|
||||
'nickname' => '' . $userSn,
|
||||
'account' => $params['account'],
|
||||
'password' => $password,
|
||||
'password_pay' => $password_pay,
|
||||
'mobile' => $mobile,
|
||||
'country_code' => $params['country_code'],
|
||||
'channel' => $params['channel'],
|
||||
'is_transfer' => $is_transfer,
|
||||
'login_ip' => request()->ip(),
|
||||
'register_ip' => request()->ip(),
|
||||
'login_time' => time(),
|
||||
]);
|
||||
|
||||
//创建用户关系
|
||||
if ($top_User != "") {
|
||||
UtilsService::create_user_relation($user['id'],$top_User['id'],UtilsService::get_distribute_level());
|
||||
}
|
||||
|
||||
//创建系统消息记录
|
||||
UtilsService::create_user_notice($user['id']);
|
||||
|
||||
//创建初始会员等级
|
||||
UtilsService::set_user_member($user['id']);
|
||||
|
||||
//创建用户信息
|
||||
UserInfo::create(['user_id' => $user['id']]);
|
||||
|
||||
//设置token
|
||||
$userInfo = UserTokenService::setToken($user['id'], $params['channel']);
|
||||
Db::commit();
|
||||
|
||||
return [
|
||||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号/手机号登录,手机号验证码
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 19:26
|
||||
*/
|
||||
public static function login($params)
|
||||
{
|
||||
try {
|
||||
|
||||
$user = User::where(['account' => $params['account']])->findOrEmpty();
|
||||
|
||||
//更新登录信息
|
||||
$user->login_time = time();
|
||||
$user->login_ip = request()->ip();
|
||||
$user->save();
|
||||
|
||||
//设置token
|
||||
$userInfo = UserTokenService::setToken($user->id, $params['terminal']);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
|
||||
return [
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'sn' => $userInfo['sn'],
|
||||
'mobile' => $userInfo['mobile'],
|
||||
'avatar' => $avatar,
|
||||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $userInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 17:56
|
||||
*/
|
||||
public static function logout($userInfo)
|
||||
{
|
||||
//token不存在,不注销
|
||||
if (!isset($userInfo['token'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//设置token过期
|
||||
return UserTokenService::expireToken($userInfo['token']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户信息
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return User
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:19
|
||||
*/
|
||||
public static function updateUser($params, $userId)
|
||||
{
|
||||
return User::where(['id' => $userId])->update([
|
||||
'nickname' => $params['nickname'],
|
||||
'avatar' => FileService::setFileUrl($params['avatar']),
|
||||
'is_new_user' => YesNoEnum::NO
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新登录信息
|
||||
* @param $userId
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function updateLoginInfo($userId)
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$user->login_time = $time;
|
||||
$user->login_ip = request()->ip();
|
||||
$user->update_time = $time;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @notes 获取微信请求code的链接
|
||||
// * @param string $url
|
||||
// * @return string
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/20 19:47
|
||||
// */
|
||||
// public static function codeUrl(string $url)
|
||||
// {
|
||||
// return (new WeChatOaService())->getCodeUrl($url);
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 公众号登录
|
||||
// * @param array $params
|
||||
// * @return array|false
|
||||
// * @throws \GuzzleHttp\Exception\GuzzleException
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/20 19:47
|
||||
// */
|
||||
// public static function oaLogin(array $params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// //通过code获取微信 openid
|
||||
// $response = (new WeChatOaService())->getOaResByCode($params['code']);
|
||||
// $userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_OA);
|
||||
// $userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// // 更新登录信息
|
||||
// self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
// Db::commit();
|
||||
// return $userInfo;
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 小程序-静默登录
|
||||
// * @param array $params
|
||||
// * @return array|false
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/20 19:47
|
||||
// */
|
||||
// public static function silentLogin(array $params)
|
||||
// {
|
||||
// try {
|
||||
// //通过code获取微信 openid
|
||||
// $response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
// $userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
// $userInfo = $userServer->getResopnseByUserInfo('silent')->getUserInfo();
|
||||
|
||||
// if (!empty($userInfo)) {
|
||||
// // 更新登录信息
|
||||
// self::updateLoginInfo($userInfo['id']);
|
||||
// }
|
||||
|
||||
// return $userInfo;
|
||||
// } catch (\Exception $e) {
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 小程序-授权登录
|
||||
// * @param array $params
|
||||
// * @return array|false
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/20 19:47
|
||||
// */
|
||||
// public static function mnpLogin(array $params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// //通过code获取微信 openid
|
||||
// $response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
// $userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
// $userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// // 更新登录信息
|
||||
// self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
// Db::commit();
|
||||
// return $userInfo;
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 小程序端绑定微信
|
||||
// * @param array $params
|
||||
// * @return bool
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/20 19:46
|
||||
// */
|
||||
// public static function mnpAuthLogin(array $params)
|
||||
// {
|
||||
// try {
|
||||
// //通过code获取微信openid
|
||||
// $response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
// $response['user_id'] = $params['user_id'];
|
||||
// $response['terminal'] = UserTerminalEnum::WECHAT_MMP;
|
||||
|
||||
// return self::createAuth($response);
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 公众号端绑定微信
|
||||
// * @param array $params
|
||||
// * @return bool
|
||||
// * @throws \GuzzleHttp\Exception\GuzzleException
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/16 10:43
|
||||
// */
|
||||
// public static function oaAuthLogin(array $params)
|
||||
// {
|
||||
// try {
|
||||
// //通过code获取微信openid
|
||||
// $response = (new WeChatOaService())->getOaResByCode($params['code']);
|
||||
// $response['user_id'] = $params['user_id'];
|
||||
// $response['terminal'] = UserTerminalEnum::WECHAT_OA;
|
||||
|
||||
// return self::createAuth($response);
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 生成授权记录
|
||||
// * @param $response
|
||||
// * @return bool
|
||||
// * @throws \Exception
|
||||
// * @author 段誉
|
||||
// * @date 2022/9/16 10:43
|
||||
// */
|
||||
// public static function createAuth($response)
|
||||
// {
|
||||
// //先检查openid是否有记录
|
||||
// $isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
|
||||
// if (!$isAuth->isEmpty()) {
|
||||
// throw new \Exception('该微信已被绑定');
|
||||
// }
|
||||
|
||||
// if (isset($response['unionid']) && !empty($response['unionid'])) {
|
||||
// //在用unionid找记录,防止生成两个账号,同个unionid的问题
|
||||
// $userAuth = UserAuth::where(['unionid' => $response['unionid']])
|
||||
// ->findOrEmpty();
|
||||
// if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
|
||||
// throw new \Exception('该微信已被绑定');
|
||||
// }
|
||||
// }
|
||||
|
||||
// //如果没有授权,直接生成一条微信授权记录
|
||||
// UserAuth::create([
|
||||
// 'user_id' => $response['user_id'],
|
||||
// 'openid' => $response['openid'],
|
||||
// 'unionid' => $response['unionid'] ?? '',
|
||||
// 'terminal' => $response['terminal'],
|
||||
// ]);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 获取扫码登录地址
|
||||
// * @return array|false
|
||||
// * @author 段誉
|
||||
// * @date 2022/10/20 18:23
|
||||
// */
|
||||
// public static function getScanCode($redirectUri)
|
||||
// {
|
||||
// try {
|
||||
// $config = WeChatConfigService::getOpConfig();
|
||||
// $appId = $config['app_id'];
|
||||
// $redirectUri = UrlEncode($redirectUri);
|
||||
|
||||
// // 设置有效时间标记状态, 超时扫码不可登录
|
||||
// $state = MD5(time().rand(10000, 99999));
|
||||
// (new WebScanLoginCache())->setScanLoginState($state);
|
||||
|
||||
// // 扫码地址
|
||||
// $url = WeChatRequestService::getScanCodeUrl($appId, $redirectUri, $state);
|
||||
// return ['url' => $url];
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * @notes 网站扫码登录
|
||||
// * @param $params
|
||||
// * @return array|false
|
||||
// * @author 段誉
|
||||
// * @date 2022/10/21 10:28
|
||||
// */
|
||||
// public static function scanLogin($params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// // 通过code 获取 access_token,openid,unionid等信息
|
||||
// $userAuth = WeChatRequestService::getUserAuthByCode($params['code']);
|
||||
|
||||
// if (empty($userAuth['openid']) || empty($userAuth['access_token'])) {
|
||||
// throw new \Exception('获取用户授权信息失败');
|
||||
// }
|
||||
|
||||
// // 获取微信用户信息
|
||||
// $response = WeChatRequestService::getUserInfoByAuth($userAuth['access_token'], $userAuth['openid']);
|
||||
|
||||
// // 生成用户或更新用户信息
|
||||
// $userServer = new WechatUserService($response, UserTerminalEnum::PC);
|
||||
// $userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// // 更新登录信息
|
||||
// self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
// Db::commit();
|
||||
// return $userInfo;
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// self::$error = $e->getMessage();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
235
app/api/logic/MallLogic.php
Normal file
235
app/api/logic/MallLogic.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\{UtilsService,ConfigService,FileService};
|
||||
use app\common\model\finance\{UserFinance};
|
||||
use app\common\model\user\{User};
|
||||
use app\common\model\mall\{MallGoods,MallGoodsRecord};
|
||||
use app\common\model\setting\Language;
|
||||
use think\facade\Config;
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 项目逻辑
|
||||
* Class MallLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class MallLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function index(array $params)
|
||||
{
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
$user_res['point'] = $user['user_point'];
|
||||
|
||||
$goods_lists = MallGoods::field('id,title,image,price,num,langs')
|
||||
->where(['is_show' => 1,'type' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($goods_lists as &$goods) {
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($goods['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
}
|
||||
|
||||
$goods['title'] = $data_title;
|
||||
$goods['image'] = FileService::getFileUrl($goods['image']);
|
||||
unset($goods['langs']);
|
||||
}
|
||||
|
||||
//查询初始交易密码
|
||||
$need_set_pwd = 0;
|
||||
$pwd_pay = ConfigService::get('login', 'password_pay');
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($user['password_pay'] == create_password($pwd_pay, $passwordSalt)) {
|
||||
$need_set_pwd = 1;
|
||||
}
|
||||
|
||||
return [
|
||||
'lists' => $goods_lists,
|
||||
'user' => $user_res,
|
||||
'need_set_pwd' => $need_set_pwd
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 兑换
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function buy(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$goods = MallGoods::where(['is_show' => 1])->findOrEmpty($params['id']);
|
||||
$user_id = $params['user_id'];
|
||||
|
||||
$data = [
|
||||
'sn' => generate_sn(MallGoodsRecord::class, 'sn'),
|
||||
'user_id' => $user_id,
|
||||
'm_goods_id' => $goods['id'],
|
||||
'm_goods_title' => $goods['title'],
|
||||
'm_goods_image' => FileService::setFileUrl($goods['image']),
|
||||
'm_goods_langs' => $goods['langs'],
|
||||
'price' => $goods['price'],
|
||||
'money' => $goods['money'],
|
||||
'point' => $goods['point'],
|
||||
'type' => $goods['type'],
|
||||
'type2' => $goods['type2'],
|
||||
'status' => 1,//状态0进行中1已完成
|
||||
];
|
||||
$order = MallGoodsRecord::create($data);
|
||||
|
||||
//剩余数量-1
|
||||
MallGoods::update([
|
||||
'id' => $goods['id'],
|
||||
'num' => $goods['num'] - 1
|
||||
]);
|
||||
|
||||
//扣除积分
|
||||
if($goods['price'] > 0){
|
||||
//用户积分修改
|
||||
UtilsService::user_money_change($user_id, 2, $goods['price'],'user_point');
|
||||
}
|
||||
|
||||
//类型1现金
|
||||
switch ($goods['type2']) {
|
||||
case 1:
|
||||
if($goods['money'] > 0.01){
|
||||
//记录日志
|
||||
UtilsService::user_finance_add(
|
||||
$user_id,
|
||||
23,
|
||||
1,
|
||||
$goods['money'],
|
||||
$order['sn'],
|
||||
'',
|
||||
1//冻结
|
||||
);
|
||||
|
||||
//用户资金修改
|
||||
UtilsService::user_money_change($user_id, 1, $goods['money'],'user_money');
|
||||
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 抽奖数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function drawIndex(array $params)
|
||||
{
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
$user_res['point'] = $user['user_point'];
|
||||
|
||||
//单次抽奖消耗积分
|
||||
$config = ConfigService::get('website', 'trade');
|
||||
$config_res['point'] = $config['draw_point'];
|
||||
|
||||
$goods_lists = MallGoods::field('id,title as name,image as img,langs')
|
||||
->where(['is_show' => 1,'type' => 2])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($goods_lists as &$goods) {
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($goods['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
}
|
||||
|
||||
$goods['name'] = $data_title;
|
||||
$goods['img'] = FileService::getFileUrl($goods['img']);
|
||||
unset($goods['langs']);
|
||||
}
|
||||
|
||||
return [
|
||||
'prizeList' => $goods_lists,
|
||||
'user' => $user_res,
|
||||
'config' => $config_res,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 抽奖
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function draw(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//单次抽奖消耗积分
|
||||
$config = ConfigService::get('website', 'trade');
|
||||
$draw_point = $config['draw_point'];
|
||||
|
||||
$user = User::where(['id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
$goods_lists = MallGoods::where(['is_show' => 1,'type' => 2])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
//概率算法
|
||||
$lists = [];
|
||||
foreach($goods_lists as $index=>$item) {
|
||||
$lists[$index] = $item['win_rate'];
|
||||
}
|
||||
|
||||
$prizeIndex = UtilsService::get_draw_rand($goods_lists,$lists,$params['user_id'],$draw_point);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'index' => $prizeIndex
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
240
app/api/logic/PcLogic.php
Normal file
240
app/api/logic/PcLogic.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class PcLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData()
|
||||
{
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::findOrEmpty(4);
|
||||
// 最新资讯
|
||||
$newArticle = self::getLimitArticle('new', 7);
|
||||
// 全部资讯
|
||||
$allArticle = self::getLimitArticle('all', 5);
|
||||
// 热门资讯
|
||||
$hotArticle = self::getLimitArticle('hot', 8);
|
||||
|
||||
return [
|
||||
'page' => $decoratePage,
|
||||
'all' => $allArticle,
|
||||
'new' => $newArticle,
|
||||
'hot' => $hotArticle
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章
|
||||
* @param string $sortType
|
||||
* @param int $limit
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 9:53
|
||||
*/
|
||||
public static function getLimitArticle(string $sortType, int $limit = 0, int $cate = 0, int $excludeId = 0)
|
||||
{
|
||||
// 查询字段
|
||||
$field = [
|
||||
'id', 'cid', 'title', 'desc', 'abstract', 'image',
|
||||
'author', 'click_actual', 'click_virtual', 'create_time'
|
||||
];
|
||||
|
||||
// 排序条件
|
||||
$orderRaw = 'sort desc, id desc';
|
||||
if ($sortType == 'new') {
|
||||
$orderRaw = 'id desc';
|
||||
}
|
||||
if ($sortType == 'hot') {
|
||||
$orderRaw = 'click_actual + click_virtual desc, id desc';
|
||||
}
|
||||
|
||||
// 查询条件
|
||||
$where[] = ['is_show', '=', YesNoEnum::YES];
|
||||
if (!empty($cate)) {
|
||||
$where[] = ['cid', '=', $cate];
|
||||
}
|
||||
if (!empty($excludeId)) {
|
||||
$where[] = ['id', '<>', $excludeId];
|
||||
}
|
||||
|
||||
$article = Article::field($field)
|
||||
->where($where)
|
||||
->append(['click'])
|
||||
->orderRaw($orderRaw)
|
||||
->hidden(['click_actual', 'click_virtual']);
|
||||
|
||||
if ($limit) {
|
||||
$article->limit($limit);
|
||||
}
|
||||
|
||||
return $article->select()->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData()
|
||||
{
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
];
|
||||
|
||||
// 网站信息
|
||||
$website = [
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
'pc_logo' => FileService::getFileUrl(ConfigService::get('website', 'pc_logo')),
|
||||
'pc_title' => ConfigService::get('website', 'pc_title'),
|
||||
'pc_ico' => FileService::getFileUrl(ConfigService::get('website', 'pc_ico')),
|
||||
'pc_desc' => ConfigService::get('website', 'pc_desc'),
|
||||
'pc_keywords' => ConfigService::get('website', 'pc_keywords'),
|
||||
];
|
||||
|
||||
// 备案信息
|
||||
$copyright = ConfigService::get('copyright', 'config', []);
|
||||
|
||||
// 公众号二维码
|
||||
$oaQrCode = ConfigService::get('oa_setting', 'qr_code', '');
|
||||
$oaQrCode = empty($oaQrCode) ? $oaQrCode : FileService::getFileUrl($oaQrCode);
|
||||
// 小程序二维码
|
||||
$mnpQrCode = ConfigService::get('mnp_setting', 'qr_code', '');
|
||||
$mnpQrCode = empty($mnpQrCode) ? $mnpQrCode : FileService::getFileUrl($mnpQrCode);
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'version' => config('project.version'),
|
||||
'copyright' => $copyright,
|
||||
'admin_url' => request()->domain() . '/admin',
|
||||
'qrcode' => [
|
||||
'oa' => $oaQrCode,
|
||||
'mnp' => $mnpQrCode,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 资讯中心
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 16:55
|
||||
*/
|
||||
public static function getInfoCenter()
|
||||
{
|
||||
$data = ArticleCate::field(['id', 'name'])
|
||||
->with(['article' => function ($query) {
|
||||
$query->hidden(['content', 'click_virtual', 'click_actual'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->append(['click'])
|
||||
->limit(10);
|
||||
}])
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章详情
|
||||
* @param $userId
|
||||
* @param $articleId
|
||||
* @param string $source
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 15:18
|
||||
*/
|
||||
public static function getArticleDetail($userId, $articleId, $source = 'default')
|
||||
{
|
||||
// 文章详情
|
||||
$detail = Article::getArticleDetailArr($articleId);
|
||||
|
||||
// 根据来源列表查找对应列表
|
||||
$nowIndex = 0;
|
||||
$lists = self::getLimitArticle($source, 0, $detail['cid']);
|
||||
foreach ($lists as $key => $item) {
|
||||
if ($item['id'] == $articleId) {
|
||||
$nowIndex = $key;
|
||||
}
|
||||
}
|
||||
// 上一篇
|
||||
$detail['last'] = $lists[$nowIndex - 1] ?? [];
|
||||
// 下一篇
|
||||
$detail['next'] = $lists[$nowIndex + 1] ?? [];
|
||||
|
||||
// 最新资讯
|
||||
$detail['new'] = self::getLimitArticle('new', 8, $detail['cid'], $detail['id']);
|
||||
// 关注状态
|
||||
$detail['collect'] = ArticleCollect::isCollectArticle($userId, $articleId);
|
||||
// 分类名
|
||||
$detail['cate_name'] = ArticleCate::where('id', $detail['cid'])->value('name');
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
}
|
||||
393
app/api/logic/RechargeLogic.php
Normal file
393
app/api/logic/RechargeLogic.php
Normal file
@@ -0,0 +1,393 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\finance\RechargeRecord;
|
||||
use app\common\model\user\{User,UserUdun,UserTron,UserMember};
|
||||
use app\common\model\setting\Language;
|
||||
use app\common\model\setting\RechargeMethod;
|
||||
use app\common\model\withdraw\WithdrawWallet;
|
||||
use app\common\service\{ConfigService,UtilsService};
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 充值逻辑层
|
||||
* Class RechargeLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class RechargeLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 充值
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author BD
|
||||
* @date 2024/2/24 10:43
|
||||
*/
|
||||
public static function recharge(array $params)
|
||||
{
|
||||
try {
|
||||
$method = RechargeMethod::where(['id' => $params['id']])->findOrEmpty();
|
||||
|
||||
$order_amount_act = round($params['money'] * $method['rate'] , $method['precision']);
|
||||
|
||||
$account = $method['account'];
|
||||
|
||||
//充值类型为 自定义地址
|
||||
if($method['type'] == 7){
|
||||
$address = $params['address'];
|
||||
$addressArr = explode(PHP_EOL, $method['address']);
|
||||
if (!in_array($address, $addressArr)) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
if ($member_id < $method['member_id']) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
$account = $address;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'sn' => generate_sn(RechargeRecord::class, 'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'method_id' => $params['id'],
|
||||
'amount' => $params['money'],
|
||||
'amount_act' => $order_amount_act,
|
||||
'account' => $account,
|
||||
'voucher' => $params['voucher'],
|
||||
'rate' => $method['rate'],
|
||||
'symbol' => $method['symbol'],
|
||||
];
|
||||
|
||||
$order = RechargeRecord::create($data);
|
||||
|
||||
return [
|
||||
'order_id' => (int)$order['id'],
|
||||
'from' => 'recharge'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 充值配置
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/2/24 16:56
|
||||
*/
|
||||
public static function config($userId)
|
||||
{
|
||||
$config = ConfigService::get('website', 'trade');
|
||||
|
||||
//查询需要绑定提现账户才可提现
|
||||
$need_bing_wallet = 0;
|
||||
if ($config['need_bing_wallet'] == 1) {
|
||||
$count = WithdrawWallet::where(['user_id' => $userId])->count();
|
||||
if($count == 0){
|
||||
$need_bing_wallet = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return [
|
||||
'min' => $config['recharge_min'],
|
||||
'need_bing_wallet' => $need_bing_wallet
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 充值方式
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/10/13 10:53
|
||||
*/
|
||||
public static function getAllMethod(array $params)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
|
||||
$field = ['id','type','name','logo'];
|
||||
$methods = RechargeMethod::field($field)
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->whereIn('lang_id', [0,$language['id']])
|
||||
->where(" member_id = 0 OR ( member_id !=0 AND member_id <= $member_id ) ")
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $methods;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 充值方式详情
|
||||
* @param $id
|
||||
* @param $lang
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/9/20 17:09
|
||||
*/
|
||||
public static function methodDetail($id,$lang)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $lang])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
$field = ['id','type','name','logo','account','is_voucher','img as qrcode','bank_name','bank_username','symbol','rate','precision'];
|
||||
$method = RechargeMethod::field($field)
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->where(['id' => $id])
|
||||
->whereIn('lang_id', [0,$language['id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if (empty($method)) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
return $method;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 充值方式详情-优盾
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/9/20 17:09
|
||||
*/
|
||||
public static function methodDetailUdun(array $params)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
$method = RechargeMethod::where(['is_show' => YesNoEnum::YES])
|
||||
->where(['id' => $params['id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if (empty($method)) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
//查看是否创建地址
|
||||
$userUdun = UserUdun::where(['user_id' => $params['user_id'],'method_id' => $method['id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$address = "";
|
||||
$qrcode = "";
|
||||
$data = [];
|
||||
if (empty($userUdun)) {
|
||||
|
||||
//查看是否创建主钱包相同地址
|
||||
$userUdun2 = UserUdun::where(['user_id' => $params['user_id'],'main_coin_type' => $method['main_coin_type']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if (empty($userUdun2)) {
|
||||
|
||||
//没有创建则创建地址
|
||||
$udunDispatch = UtilsService::get_udunDispatch();
|
||||
|
||||
$result = $udunDispatch->createAddress($method['main_coin_type']);
|
||||
$address = $result['data']['address'];
|
||||
$qrcode = UtilsService::get_qrcode($address);
|
||||
}else{
|
||||
$address = $userUdun2['address'];
|
||||
$qrcode = $userUdun2['qrcode'];
|
||||
}
|
||||
//保存地址
|
||||
$data = [
|
||||
'user_id' => $params['user_id'],
|
||||
'method_id' => $method['id'],
|
||||
'address' => $address,
|
||||
'qrcode' => $qrcode,
|
||||
'main_coin_type' => $method['main_coin_type'],
|
||||
'coin_type' => $method['coin_type'],
|
||||
];
|
||||
|
||||
UserUdun::create($data);
|
||||
}else{
|
||||
$data['address'] = $userUdun['address'];
|
||||
$data['qrcode'] = $userUdun['qrcode'];
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'address' => $data['address'],
|
||||
'qrcode' => $data['qrcode'],
|
||||
'protocol' => $method['protocol'],
|
||||
'logo' => $method['logo'],
|
||||
'name' => $method['name'],
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 充值方式详情-波场
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/9/20 17:09
|
||||
*/
|
||||
public static function methodDetailTron(array $params)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
$method = RechargeMethod::where(['is_show' => YesNoEnum::YES])
|
||||
->where(['id' => $params['id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if (empty($method)) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
|
||||
//查看是否创建地址
|
||||
$userTron = UserTron::where(['user_id' => $params['user_id'],'method_id' => $method['id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
$data = [
|
||||
'user_id' => $params['user_id'],
|
||||
'method_id' => $method['id'],
|
||||
];
|
||||
if (empty($userTron)) {
|
||||
//创建地址
|
||||
$tronData = [
|
||||
'action' => 'reg'
|
||||
];
|
||||
|
||||
$response = UtilsService::usdt_request($tronData, 'POST');
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if($response['code'] == 200){
|
||||
$data['address'] = $response['data']['addr'];
|
||||
$data['qrcode'] = UtilsService::get_qrcode($data['address']);
|
||||
$data['key'] = $response['data']['key'];
|
||||
$data['last_time'] = time();
|
||||
UserTron::create($data);
|
||||
}else{
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
}else{
|
||||
$data['address'] = $userTron['address'];
|
||||
$data['qrcode'] = $userTron['qrcode'];
|
||||
// 更新最后使用时间
|
||||
UserTron::where(['id' => $userTron['id']])->update(['last_time' => time()]);
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'address' => $data['address'],
|
||||
'qrcode' => $data['qrcode'],
|
||||
'protocol' => $method['protocol'],
|
||||
'logo' => $method['logo'],
|
||||
'name' => $method['name'],
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 充值方式详情-自定义地址
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/9/20 17:09
|
||||
*/
|
||||
public static function methodDetailAddress(array $params)
|
||||
{
|
||||
try {
|
||||
//查询语言
|
||||
$language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
if ($language->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
$method = RechargeMethod::where(['is_show' => YesNoEnum::YES])
|
||||
->where(['id' => $params['id']])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if (empty($method)) {
|
||||
throw new \Exception('network.parameterAbnormality');//参数异常
|
||||
}
|
||||
//随机获取地址
|
||||
$addressArr = explode(PHP_EOL, $method['address']);
|
||||
|
||||
return [
|
||||
'avail_num' => $method['avail_num'],
|
||||
'address' => $addressArr[array_rand($addressArr)],
|
||||
'protocol' => $method['protocol'],
|
||||
'logo' => $method['logo'],
|
||||
'name' => $method['name'],
|
||||
'symbol' => $method['symbol'],
|
||||
'rate' => $method['rate'],
|
||||
'precision' => $method['precision'],
|
||||
'is_voucher' => $method['is_voucher'],
|
||||
'date' => date('Y-m-d'),
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取常用充值金额
|
||||
* @param $lang
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/10/13 10:53
|
||||
*/
|
||||
public static function getCommonMoney($lang)
|
||||
{
|
||||
$config = ConfigService::get('website', 'trade');
|
||||
return explode("\n", $config['common_money']);
|
||||
}
|
||||
|
||||
}
|
||||
519
app/api/logic/RobotLogic.php
Normal file
519
app/api/logic/RobotLogic.php
Normal file
@@ -0,0 +1,519 @@
|
||||
// <?php
|
||||
// namespace app\api\logic;
|
||||
|
||||
// use app\common\logic\BaseLogic;
|
||||
// use app\common\model\goods\{Goods,GoodsRecord};
|
||||
// use app\common\service\{UtilsService,ConfigService,FileService};
|
||||
// use app\common\model\member\UserMember;
|
||||
// use app\common\model\finance\{UserFinance};
|
||||
// use app\common\model\user\{User,UserRelation,UserKadan,UserGroupRule,UserGroupRecord};
|
||||
// use app\common\model\lh\{LhCoin,LhRecord};
|
||||
// use app\common\model\setting\Language;
|
||||
// use think\facade\{Db};
|
||||
|
||||
|
||||
// /**
|
||||
// * 抢单逻辑
|
||||
// * Class RobotLogic
|
||||
// * @package app\api\logic
|
||||
// */
|
||||
// class RobotLogic extends BaseLogic
|
||||
// {
|
||||
|
||||
// /**
|
||||
// * @notes 首页数据
|
||||
// * @param $params
|
||||
// * @return array
|
||||
// * @throws \think\db\exception\DataNotFoundException
|
||||
// * @throws \think\db\exception\DbException
|
||||
// * @throws \think\db\exception\ModelNotFoundException
|
||||
// * @author BD
|
||||
// * @date 2024/02/22 10:54
|
||||
// */
|
||||
// public static function getIndexData(array $params)
|
||||
// {
|
||||
// // 获取今天0点的时间戳
|
||||
// $todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
|
||||
// $user = User::where(['id' => $params['user_id']])
|
||||
// ->field('id,user_money as balance,total_income as totalIncome,is_lh')
|
||||
// ->findOrEmpty();
|
||||
|
||||
// //查询会员等级
|
||||
// $member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
// $userMember = UserMember::where(['id' => $member_id])
|
||||
// ->field('id, name, logo, bg_img, text_color, money, level1_num, lh_min, lh_max, lh_num')
|
||||
// ->findOrEmpty();
|
||||
|
||||
// $today_income = UserFinance::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id'],'change_type' => 13])
|
||||
// ->sum('change_amount');
|
||||
|
||||
// $today_order = LhRecord::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->count();
|
||||
|
||||
// $user['member'] = $userMember;
|
||||
// $user['todayIncome'] = $today_income;
|
||||
// $user['totalIncome'] = $user['totalIncome'];
|
||||
// $user['todayOrder'] = $today_order;
|
||||
// $user['todayTotalOrder'] = $userMember['lh_num'];
|
||||
|
||||
|
||||
|
||||
// $today_money = LhRecord::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->sum('money');
|
||||
// $user['todayMoney'] = $today_money;
|
||||
|
||||
// //今日量化过
|
||||
// if($user['todayMoney'] > 0){
|
||||
// //可量化总额金额 = 今日最后一次量化金额 * 可量化次数
|
||||
// $today_last_money = LhRecord::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->order('create_time desc')
|
||||
// ->findOrEmpty();
|
||||
// $user['totalyMoney'] = $today_last_money['money'] * $userMember['lh_num'];
|
||||
// }else{
|
||||
|
||||
// //查询今日量化情况,已量化、总可量化(根据会员等级最高量化金额,用户余额小于最高,则根据用户余额,用户余额小于最低,则根据最低)
|
||||
// //大于最大量化金额
|
||||
// if($user['balance'] >= $userMember['lh_max']){
|
||||
// $user['totalyMoney'] = $userMember['lh_max'];
|
||||
// //大于最小量化金额 小于最大量化金额
|
||||
// }elseif($user['balance'] > $userMember['lh_min'] && $user['balance'] < $userMember['lh_max']){
|
||||
// $user['totalyMoney'] = $user['balance'];
|
||||
// //小于最小量化金额
|
||||
// }else{
|
||||
// $user['totalyMoney'] = $userMember['lh_min'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// return [
|
||||
// 'user' => $user,
|
||||
// // 服务器时间
|
||||
// 'server_date' => date('Y/m/d H:i:s'),
|
||||
// ];
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @notes 量化
|
||||
// * @param $params
|
||||
// * @return array|false
|
||||
// * @throws \think\db\exception\DataNotFoundException
|
||||
// * @throws \think\db\exception\DbException
|
||||
// * @throws \think\db\exception\ModelNotFoundException
|
||||
// * @author BD
|
||||
// * @date 2024/02/22 10:54
|
||||
// */
|
||||
// public static function buy(array $params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// // 获取今天0点的时间戳
|
||||
// $todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
|
||||
// $user = User::where(['id' => $params['user_id']]) -> findOrEmpty();
|
||||
|
||||
// $coin = LhCoin::where(['is_show' => 1]) ->orderRaw(" RAND() ") -> findOrEmpty();
|
||||
// //查询会员等级
|
||||
// $member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
// $userMember = UserMember::where(['id' => $member_id])->findOrEmpty();
|
||||
|
||||
// //计算买入金额
|
||||
// $money = 0;
|
||||
|
||||
// //查询今日量化情况,总可量化(根据会员等级最高量化金额,用户余额小于最高,则根据用户余额,用户余额小于最低,则根据最低)
|
||||
// $today_money = LhRecord::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->sum('money');
|
||||
// $today_order = LhRecord::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->count();
|
||||
|
||||
// //今日量化
|
||||
// if($today_order > 0){
|
||||
// //买入金额为 今日最后一次量化金额
|
||||
// $today_last_money = LhRecord::where("create_time > $todayStart")
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->order('create_time desc')
|
||||
// ->findOrEmpty();
|
||||
// $money = $today_last_money['money'];
|
||||
// }else{
|
||||
// //查询可量化总额
|
||||
// $totalyMoney = 0;//总可量化金额
|
||||
// //大于最大量化金额
|
||||
// if($user['user_money'] >= $userMember['lh_max']){
|
||||
// $totalyMoney = $userMember['lh_max'];
|
||||
// //大于最小量化金额 小于最大量化金额
|
||||
// }elseif($user['user_money'] > $userMember['lh_min'] && $user['user_money'] < $userMember['lh_max']){
|
||||
// $totalyMoney = $user['user_money'];
|
||||
// //小于最小量化金额
|
||||
// }else{
|
||||
// $totalyMoney = $userMember['lh_min'];
|
||||
// }
|
||||
|
||||
// $money = $totalyMoney / $userMember['lh_num'];
|
||||
|
||||
// //最后一次,量化金额 = 可量化金额 - 已量化金额
|
||||
// if($userMember['lh_num'] - $today_order == 1){
|
||||
// $money = $totalyMoney - $today_money;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if($money <= 0){
|
||||
// throw new \Exception('network.parameterAbnormality');
|
||||
// }
|
||||
|
||||
// // //如果用户余额低于最大量化金额,则根据量化金额取值,否则根据用户余额取值
|
||||
// // if($userMember['lh_max'] > $user['user_money']){
|
||||
// // $userMember['lh_max'] = $user['user_money'];
|
||||
// // }
|
||||
|
||||
// // $money = mt_rand($userMember['lh_min'], $userMember['lh_max']);
|
||||
|
||||
// $rate = round($userMember['rate_min'] + mt_rand() / mt_getrandmax() * ($userMember['rate_max'] - $userMember['rate_min']), 2);
|
||||
|
||||
// //每次量化收益 = 最小-最大量化金额随机值 * 最小-最大量化收益率随机值 / 每日量化次数
|
||||
// $income = round(($money * $rate / 100), 2);
|
||||
|
||||
// $money_sale = round($coin['price'] + ($coin['price'] * $rate ) / 100, 4);
|
||||
|
||||
// $data = [
|
||||
// 'sn' => generate_sn(LhRecord::class, 'sn'),
|
||||
// 'user_id' => $params['user_id'],
|
||||
// 'coin_id' => $coin['id'],
|
||||
// 'coin_name' => $coin['name'],
|
||||
// 'coin_logo' => $coin['logo'],
|
||||
// 'coin_symbol' => $coin['symbol'],
|
||||
// 'coin_buy_name' => $coin['buy_name'],
|
||||
// 'coin_sale_name' => $coin['sale_name'],
|
||||
// 'money' => $money,
|
||||
// 'income' => $income,
|
||||
// 'money_buy' => $coin['price'],
|
||||
// 'money_sale' => $money_sale
|
||||
// ];
|
||||
// $order = LhRecord::create($data);
|
||||
|
||||
// //记录日志
|
||||
// UtilsService::user_finance_add(
|
||||
// $data['user_id'],
|
||||
// 13,
|
||||
// 1,
|
||||
// $data['income'],
|
||||
// $data['sn'],
|
||||
// '',
|
||||
// 1 //冻结
|
||||
// );
|
||||
|
||||
// //用户资金修改
|
||||
// UtilsService::user_money_change($data['user_id'], 1, $data['income'],'user_money');
|
||||
// UtilsService::user_money_change($data['user_id'], 1, $data['income'],'total_income');
|
||||
|
||||
// //团队收益奖励
|
||||
// UtilsService::team_reward_add($data['user_id'],$data['income'],2);
|
||||
|
||||
// Db::commit();
|
||||
// return [];
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// self::setError($e->getMessage());
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// /**
|
||||
// * @notes 抢单
|
||||
// * @param $params
|
||||
// * @return array|false
|
||||
// * @throws \think\db\exception\DataNotFoundException
|
||||
// * @throws \think\db\exception\DbException
|
||||
// * @throws \think\db\exception\ModelNotFoundException
|
||||
// * @author BD
|
||||
// * @date 2024/02/22 10:54
|
||||
// */
|
||||
// public static function grab(array $params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// $user = User::where(['id' => $params['user_id']]) -> findOrEmpty();
|
||||
|
||||
// $time24Hours = time() - 24 * 60 * 60;//24小时前
|
||||
|
||||
// //查看是否存在进行中的订单
|
||||
// $orderStatus3 = GoodsRecord::where(['user_id' => $params['user_id'],'status' => 3])->findOrEmpty();
|
||||
// if (!$orderStatus3->isEmpty()) {
|
||||
// throw new \Exception('network.parameterAbnormality');//派单中,请稍后重试
|
||||
// }
|
||||
// $orderStatus4 = GoodsRecord::where(['user_id' => $params['user_id'],'status' => 4])->findOrEmpty();
|
||||
// if (!$orderStatus4->isEmpty()) {
|
||||
// throw new \Exception('network.parameterAbnormality');//订单未支付,请先完成支付
|
||||
// }
|
||||
|
||||
// //判断24小时抢单次数
|
||||
// //分组模式下,抢单次数=分组订单,未分组,抢单次数=会员等级抢单次数
|
||||
// $today_order = GoodsRecord::where("create_time > $time24Hours")->where(['user_id' => $params['user_id']])->count();
|
||||
|
||||
// //判断用户分组
|
||||
// $userGroupRecord = UserGroupRecord::where(['user_id' => $params['user_id']])
|
||||
// ->order('id', 'desc')
|
||||
// ->findOrEmpty();
|
||||
|
||||
// if(!$userGroupRecord->isEmpty()) {
|
||||
// $userGroupRuleCount = UserGroupRule::where(['group_id' => $userGroupRecord['group_id']])->count();
|
||||
// if ($today_order >= $userGroupRuleCount) {
|
||||
// throw new \Exception('network.parameterAbnormality');//今日抢单次数已用完
|
||||
// }
|
||||
// }else{
|
||||
// //查询会员等级
|
||||
// $member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
// $userMember = UserMember::where(['id' => $member_id])->findOrEmpty();
|
||||
// if ($today_order >= $userMember['order']) {
|
||||
// throw new \Exception('network.parameterAbnormality');//今日抢单次数已用完
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// $language = Language::where(['symbol' => $params['lang']])->findOrEmpty();
|
||||
// if ($language->isEmpty()) {
|
||||
// throw new \Exception('network.parameterAbnormality');
|
||||
// }
|
||||
|
||||
// $data = [
|
||||
// 'sn' => generate_sn(GoodsRecord::class, 'sn'),
|
||||
// 'user_id' => $params['user_id'],
|
||||
// 'lang' => $params['lang'],
|
||||
// 'status' => 5,
|
||||
// ];
|
||||
|
||||
// //判断派单模式 1手动2自动
|
||||
// $config = ConfigService::get('website', 'trade');
|
||||
// //自动----------------------------------------------------------------------------------------
|
||||
// if($config['robot_model'] -2 == 0){
|
||||
// //查询会员等级
|
||||
// $member_id = UtilsService::get_user_member_id($data['user_id']);
|
||||
// $member = UserMember::where(['id' => $member_id])->findOrEmpty();
|
||||
|
||||
// $auto_status = false;
|
||||
// $total_money = 0;
|
||||
// $commission_cust = 0;//自定义佣金标识
|
||||
|
||||
// //判断是否有卡单订单
|
||||
// $total_order = GoodsRecord::where(['user_id' => $params['user_id']])->count();
|
||||
|
||||
// $kadan = UserKadan::where(['user_id' => $params['user_id'],'num' => $total_order + 1,'status' => 0])->findOrEmpty();
|
||||
// if (!$kadan->isEmpty()) {
|
||||
// //计算匹配金额
|
||||
// $total_money = $kadan['money'];
|
||||
// $commission_cust = $kadan['commission'];
|
||||
|
||||
// UserKadan::update([
|
||||
// 'id' => $kadan['id'],
|
||||
// 'status' => 1,
|
||||
// ]);
|
||||
|
||||
// $data['type'] = 3;
|
||||
|
||||
// $auto_status = true;
|
||||
|
||||
// //没有卡单订单
|
||||
// }else{
|
||||
|
||||
// //判断用户分组
|
||||
// $userGroupRecord = UserGroupRecord::where(['user_id' => $params['user_id']])
|
||||
// ->order('id', 'desc')
|
||||
// ->findOrEmpty();
|
||||
// if(!$userGroupRecord->isEmpty()) {
|
||||
// $userGroupRule = UserGroupRule::where(['group_id' => $userGroupRecord['group_id'],'num' => $today_order + 1])->findOrEmpty();
|
||||
|
||||
// //判断是否存在分组规则,不存在则进入手动派单
|
||||
// if(!$userGroupRule->isEmpty()){
|
||||
// //计算订单金额 金额类型1固定值2百分比
|
||||
// if($userGroupRule['money_type'] == 1){
|
||||
// $total_money = $userGroupRule['money'];
|
||||
// }else{
|
||||
// $total_money = round($user['user_money'] * $userGroupRule['money_percentage'] / 100,0);
|
||||
// }
|
||||
|
||||
// //计算订单佣金 佣金类型1固定值2百分比
|
||||
// if($userGroupRule['commission_type'] == 1){
|
||||
// $commission_cust = $userGroupRule['commission'];
|
||||
// }else{
|
||||
// $commission_cust = round($total_money * $userGroupRule['commission_percentage'] / 100,0);
|
||||
// }
|
||||
|
||||
// $data['type'] = 2;
|
||||
|
||||
// $auto_status = true;
|
||||
|
||||
// //用户分组规则金额百分比模式下,判断用户余额跟自动派单最低余额
|
||||
// if(($userGroupRule['money_type'] == 2) && ($user['user_money'] - $config['robot_range_min_money'] < 0)){
|
||||
// $auto_status = false;
|
||||
// }
|
||||
|
||||
// }else{
|
||||
// $auto_status = false;
|
||||
// }
|
||||
|
||||
// }else{
|
||||
|
||||
|
||||
// //会员自动派单订单
|
||||
// if($user['user_money'] - $config['robot_range_min_money'] >= 0){
|
||||
// //计算匹配金额
|
||||
// $total_money = round($user['user_money'] * rand($config['robot_range'][0],$config['robot_range'][1]) / 100,0);
|
||||
// $auto_status = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// if($auto_status){
|
||||
|
||||
// $goods = Goods::where("money <= $total_money")->group(" RAND() ")->findOrEmpty();
|
||||
|
||||
// if (!$goods->isEmpty()) {
|
||||
// //多语言替换
|
||||
// $data_langs = UtilsService::get_langs_data($goods['langs'],$params['lang']);
|
||||
// $goods['title'] = $data_langs['title'];
|
||||
|
||||
// //数量
|
||||
// $num = floor($total_money / $goods['money']);
|
||||
|
||||
// //计算佣金
|
||||
// $commission = $commission_cust > 0 ? $commission_cust : round($goods['money'] * $num * $member['commission']/100,2);
|
||||
|
||||
// if($commission > 0.01){
|
||||
// $data['goods_id'] = $goods['id'];
|
||||
// $data['goods_title'] = $goods['title'];
|
||||
// $data['goods_image'] = FileService::setFileUrl($goods['image']);
|
||||
// $data['unit_price'] = $goods['money'];
|
||||
// $data['num'] = $num;
|
||||
// $data['money'] = $goods['money'] * $num;
|
||||
// $data['commission'] = $commission;
|
||||
// $data['status'] = 4;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// $order = GoodsRecord::create($data);
|
||||
|
||||
// Db::commit();
|
||||
// return [
|
||||
// 'order_id' => $data['sn'],
|
||||
// 'status' => 5,
|
||||
// ];
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// self::setError($e->getMessage());
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @notes 获取进行中订单
|
||||
// * @param $params
|
||||
// * @return array
|
||||
// * @throws \think\db\exception\DataNotFoundException
|
||||
// * @throws \think\db\exception\DbException
|
||||
// * @throws \think\db\exception\ModelNotFoundException
|
||||
// * @author BD
|
||||
// * @date 2024/02/22 10:54
|
||||
// */
|
||||
// public static function grabIngRecord(array $params)
|
||||
// {
|
||||
// try {
|
||||
// $field = ['id','sn','goods_title as title','goods_image as image','unit_price','num','money','commission','status'];
|
||||
// $record = GoodsRecord::field($field)
|
||||
// ->where(['user_id' => $params['user_id']])
|
||||
// ->where('status = 5 OR status = 4')
|
||||
// ->order(['id' => 'desc'])
|
||||
// ->findOrEmpty()
|
||||
// ->toArray();
|
||||
|
||||
// return $record;
|
||||
// } catch (\Exception $e) {
|
||||
// self::setError($e->getMessage());
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @notes 订单支付
|
||||
// * @param array $params
|
||||
// * @return array|false
|
||||
// * @author BD
|
||||
// * @date 2024/02/22 10:54
|
||||
// */
|
||||
// public static function grabPay(array $params)
|
||||
// {
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// $order = GoodsRecord::where(['id' => $params['id'],'user_id' => $params['user_id']])->findOrEmpty();
|
||||
|
||||
// GoodsRecord::update([
|
||||
// 'id' => $order['id'],
|
||||
// 'status' => 1,
|
||||
// 'pay_time' => time()
|
||||
// ]);
|
||||
|
||||
// //支付扣除金额---------------------------------------------------------------------------------------------
|
||||
// //记录日志
|
||||
// UtilsService::user_finance_add(
|
||||
// $order['user_id'],
|
||||
// 7,
|
||||
// 2,
|
||||
// $order['money'],
|
||||
// $order['sn']
|
||||
// );
|
||||
|
||||
// //用户资金修改
|
||||
// UtilsService::user_money_change($params['user_id'], 2, $order['money'],'user_money');
|
||||
|
||||
// $commission = $order['commission'];
|
||||
|
||||
// //收益增加金额---------------------------------------------------------------------------------------------
|
||||
// //记录日志
|
||||
// UtilsService::user_finance_add(
|
||||
// $order['user_id'],
|
||||
// 9,
|
||||
// 1,
|
||||
// $commission,
|
||||
// $order['sn'],
|
||||
// '',
|
||||
// 1 //冻结
|
||||
// );
|
||||
|
||||
// //用户资金修改
|
||||
// UtilsService::user_money_change($params['user_id'], 1, $commission,'user_money');
|
||||
// UtilsService::user_money_change($params['user_id'], 1, $commission,'total_income');
|
||||
|
||||
// //团队收益奖励
|
||||
// UtilsService::team_reward_add($params['user_id'],$commission,2);
|
||||
|
||||
// //订单本金返还---------------------------------------------------------------------------------------------
|
||||
// //记录日志
|
||||
// UtilsService::user_finance_add(
|
||||
// $order['user_id'],
|
||||
// 8,
|
||||
// 1,
|
||||
// $order['money'],
|
||||
// $order['sn']
|
||||
// );
|
||||
|
||||
// //用户资金修改
|
||||
// UtilsService::user_money_change($params['user_id'], 1, $order['money'],'user_money');
|
||||
|
||||
// Db::commit();
|
||||
// return [
|
||||
// 'order_id' => (int)$order['id'],
|
||||
// 'from' => 'order'
|
||||
// ];
|
||||
// } catch (\Exception $e) {
|
||||
// Db::rollback();
|
||||
// self::setError($e->getMessage());
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
185
app/api/logic/SmsLogic.php
Normal file
185
app/api/logic/SmsLogic.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\service\{UtilsService};
|
||||
use app\common\model\decorate\{DecorateHint};
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\model\notice\EmailRecord;
|
||||
use app\common\cache\UserAccountSafeCache;
|
||||
use app\common\model\user\{User,UserInfo};
|
||||
use app\common\logic\BaseLogic;
|
||||
|
||||
|
||||
/**
|
||||
* 短信逻辑
|
||||
* Class SmsLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class SmsLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 发送验证码
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @author BD
|
||||
* @date 2024/9/21 17:29
|
||||
*/
|
||||
public static function sendCode($params)
|
||||
{
|
||||
try {
|
||||
$scene = NoticeEnum::getSceneByTag($params['scene']);
|
||||
if (empty($scene)) {
|
||||
throw new \Exception('network.parameterAbnormality');//场景值异常
|
||||
}
|
||||
|
||||
$result = event('Notice', [
|
||||
'scene_id' => $scene,
|
||||
'params' => [
|
||||
'mobile' => $params['mobile'],
|
||||
'country_code' => $params['country_code'],
|
||||
'code' => mt_rand(100000, 999999),
|
||||
]
|
||||
]);
|
||||
|
||||
return $result[0];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 发送邮件
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @author BD
|
||||
* @date 2024/9/21 17:29
|
||||
*/
|
||||
public static function sendEmail($params)
|
||||
{
|
||||
try {
|
||||
if(!filter_var($params['email'], FILTER_VALIDATE_EMAIL)){
|
||||
throw new \Exception('network.parameterAbnormality');//请输入正确的邮箱地址
|
||||
}
|
||||
//判断发送频率
|
||||
$time = time() - 1*60;//1分钟发送一次
|
||||
|
||||
$count = EmailRecord::where(['user_id' => $params['user_id']])->where("create_time > $time")->count();
|
||||
if($count > 0) throw new \Exception('captcha.validTips');//验证码5分钟内有效,请勿重复发送
|
||||
$count = EmailRecord::where(['ip' => request()->ip()])->where("create_time > $time")->count();
|
||||
if($count > 0) throw new \Exception('captcha.validTips');//验证码5分钟内有效,请勿重复发送
|
||||
|
||||
$email = DecorateHint::findOrEmpty(18)->toArray();
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($email['langs'],$params['lang']);
|
||||
$code = mt_rand(100000, 999999);
|
||||
$content = str_ireplace('{code}', $code, $data['content']);
|
||||
|
||||
$result = UtilsService::send_mail($params['email'],$data['text'],$content);
|
||||
if (!$result) {
|
||||
throw new \Exception('network.sendFailed');
|
||||
}
|
||||
|
||||
EmailRecord::create([
|
||||
'user_id' => $params['user_id'],
|
||||
'email' => $params['email'],
|
||||
'subject' => $data['text'],
|
||||
'content' => $content,
|
||||
'code' => $code,
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 发送邮件
|
||||
* @param $params
|
||||
* @return false|mixed
|
||||
* @author BD
|
||||
* @date 2024/9/21 17:29
|
||||
*/
|
||||
public static function sendEmailNoLogin($params)
|
||||
{
|
||||
try {
|
||||
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
|
||||
$userAccountSafeCache = new UserAccountSafeCache();
|
||||
if (!$userAccountSafeCache->isSafe()) {
|
||||
throw new \Exception('network.frequentOperation');
|
||||
//密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试
|
||||
}
|
||||
|
||||
if(!filter_var($params['email'], FILTER_VALIDATE_EMAIL)){
|
||||
$userAccountSafeCache->record();
|
||||
throw new \Exception('network.parameterAbnormality');//请输入正确的邮箱地址
|
||||
}
|
||||
//判断发送频率
|
||||
$time = time() - 1*60;//1分钟发送一次
|
||||
|
||||
$user = User::where(['mobile' => $params['mobile'],'country_code' => $params['country_code']])->findOrEmpty();
|
||||
if($user->isEmpty()) {
|
||||
$userAccountSafeCache->record();
|
||||
throw new \Exception('login.userNoExist');//用户不存在
|
||||
}
|
||||
|
||||
$userInfo = UserInfo::where(['user_id' => $user['id']])->findOrEmpty();
|
||||
if($userInfo->isEmpty()) {
|
||||
throw new \Exception('network.parameterAbnormality');
|
||||
}
|
||||
|
||||
if($userInfo['auth_email'] == 0){
|
||||
$userAccountSafeCache->record();
|
||||
throw new \Exception('pwd.emailNoExist');//该电子邮箱不存在
|
||||
}
|
||||
if($userInfo['email'] != $params['email']){
|
||||
$userAccountSafeCache->record();
|
||||
throw new \Exception('auth.emailError');//请输入正确的邮箱地址
|
||||
}
|
||||
|
||||
|
||||
$count = EmailRecord::where(['user_id' => $user['id']])->where("create_time > $time")->count();
|
||||
if($count > 0){
|
||||
throw new \Exception('captcha.validTips');//验证码5分钟内有效,请勿重复发送
|
||||
}
|
||||
$count = EmailRecord::where(['ip' => request()->ip()])->where("create_time > $time")->count();
|
||||
if($count > 0){
|
||||
throw new \Exception('captcha.validTips');//验证码5分钟内有效,请勿重复发送
|
||||
}
|
||||
|
||||
$email = DecorateHint::findOrEmpty(22)->toArray();
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($email['langs'],$params['lang']);
|
||||
$code = mt_rand(100000, 999999);
|
||||
$content = str_ireplace('{code}', $code, $data['content']);
|
||||
|
||||
$result = UtilsService::send_mail($params['email'],$data['text'],$content);
|
||||
if (!$result) {
|
||||
throw new \Exception('network.sendFailed');
|
||||
}
|
||||
|
||||
EmailRecord::create([
|
||||
'user_id' => $user['id'],
|
||||
'email' => $params['email'],
|
||||
'subject' => $data['text'],
|
||||
'content' => $content,
|
||||
'code' => $code,
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
|
||||
$userAccountSafeCache->relieve();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
137
app/api/logic/TeamLogic.php
Normal file
137
app/api/logic/TeamLogic.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\{UtilsService,ConfigService,FileService};
|
||||
use app\common\model\finance\{UserFinance};
|
||||
use app\common\model\user\{User,UserRelation,UserNotice};
|
||||
use app\common\model\item\{ItemRecord};
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 团队逻辑
|
||||
* Class TeamLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class TeamLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
$todayStart = strtotime("today midnight");
|
||||
|
||||
$distributes = ConfigService::get('website', 'distribute');
|
||||
|
||||
$distributeLevel = UtilsService::get_distribute_level();
|
||||
|
||||
//用户----------------------------------------------------------
|
||||
$user = User::where(['id' => $params['user_id']])
|
||||
->field('id,sn,avatar,total_income')
|
||||
->findOrEmpty();
|
||||
|
||||
$user['teamNum'] = UserRelation::where(['parent_id' => $params['user_id']])->where("level <= $distributeLevel")->count();
|
||||
|
||||
$user['teamNewNum'] = UserRelation::where(['parent_id' => $params['user_id']])->where("level <= $distributeLevel")->where("create_time > $todayStart")->count();
|
||||
|
||||
$user['teamCom'] = UserFinance::where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (11) ")
|
||||
->sum('change_amount');
|
||||
|
||||
//分销----------------------------------------------------------
|
||||
foreach ($distributes as &$distribute) {
|
||||
$level = $distribute['level'];
|
||||
$distribute['num'] = UserRelation::where(['parent_id' => $params['user_id'],'level' => $level])->count();
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => $user,
|
||||
'dis_list' => $distributes,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 首页数据2
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function getIndexReport(array $params)
|
||||
{
|
||||
|
||||
$distributeLevel = UtilsService::get_distribute_level();
|
||||
//报表----------------------------------------------------------
|
||||
|
||||
$where = " 1 = 1 ";
|
||||
$where2 = " 1 = 1 ";
|
||||
//0全部1今天2近7天3近30天4近60天
|
||||
switch ($params['time_type']) {
|
||||
case 1:
|
||||
$time = strtotime(date('Y-m-d 00:00:00'));
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
case 2:
|
||||
$time = strtotime("-7 days midnight");
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
case 3:
|
||||
$time = strtotime("-30 days midnight");
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
case 4:
|
||||
$time = strtotime("-60 days midnight");
|
||||
$where = " create_time > $time ";
|
||||
$where2 = " uf.create_time > $time ";
|
||||
break;
|
||||
}
|
||||
|
||||
//我
|
||||
|
||||
// //下级
|
||||
// $report_time['income'] = UserRelation::alias('ur')
|
||||
// ->join('user_finance uf', 'uf.user_id = ur.user_id')
|
||||
// ->where(['ur.parent_id' => $params['user_id']])
|
||||
// ->where(" ur.level <= $distributeLevel AND change_type IN (13) ")
|
||||
// ->where($where2)
|
||||
// ->sum('uf.change_amount');
|
||||
|
||||
// $report_time['income'] = $report_time['income'] + $income_my;
|
||||
|
||||
$report_time['teamNum'] = UserRelation::where(['parent_id' => $params['user_id']])->where("level <= $distributeLevel")->where($where)->count();
|
||||
$report_time['tasks'] = UserFinance::where($where)
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (15) ")
|
||||
->sum('change_amount');
|
||||
$report_time['invest'] = UserFinance::where($where)
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (17) ")
|
||||
->sum('change_amount');
|
||||
$report_time['recom'] = UserFinance::where($where)
|
||||
->where(['user_id' => $params['user_id']])
|
||||
->where(" change_type IN (11) ")
|
||||
->sum('change_amount');
|
||||
|
||||
$report_time['income'] = $report_time['invest'] +$report_time['tasks'] +$report_time['recom'];
|
||||
|
||||
|
||||
return $report_time;
|
||||
}
|
||||
|
||||
}
|
||||
1358
app/api/logic/UserLogic.php
Normal file
1358
app/api/logic/UserLogic.php
Normal file
File diff suppressed because it is too large
Load Diff
137
app/api/logic/UserMemberLogic.php
Normal file
137
app/api/logic/UserMemberLogic.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\member\{UserMember,UserMemberRecord};
|
||||
use app\common\model\user\{User,UserRelation};
|
||||
use app\common\model\item\{ItemRecord};
|
||||
use app\common\service\{ConfigService,UtilsService};
|
||||
use think\facade\{Db};
|
||||
|
||||
|
||||
/**
|
||||
* 会员逻辑
|
||||
* Class UserMemberLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class UserMemberLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
|
||||
$user['total_invest'] = ItemRecord::where(['user_id' => $params['user_id']])->sum('money');
|
||||
|
||||
$user['invite_count'] = UserRelation::where(['parent_id' => $params['user_id'],'level' => 1])->count();
|
||||
|
||||
//查询会员等级
|
||||
$member_id = UtilsService::get_user_member_id($params['user_id']);
|
||||
$userMember = UserMember::field('id,name')
|
||||
->where(['id' => $member_id])
|
||||
->where(['is_show' => 1])
|
||||
->findOrEmpty();
|
||||
|
||||
return [
|
||||
'user' => $user,
|
||||
'member' => $userMember,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @notes 会员列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function getAllData(array $params)
|
||||
{
|
||||
$field = ['id, name as text, logo, bg_img as image, text_color, money, level1_num,level1_vip_id, item_num, item_add_rate,mine_speed'];
|
||||
$members = UserMember::field($field)
|
||||
->append(['vip_name'])
|
||||
->where(['is_show' => 1])
|
||||
->order(['money' => 'asc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$config_mine = ConfigService::get('website', 'mine');
|
||||
foreach ($members as &$member) {
|
||||
$member['mine_speed'] = $member['mine_speed'].' '.$config_mine['symbol'].' / H';
|
||||
}
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 加入会员
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2024/02/22 10:54
|
||||
*/
|
||||
public static function join(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//判断会员等级是否存在
|
||||
$member = UserMember::where(['id' => $params['id']])->findOrEmpty();
|
||||
|
||||
$data = [
|
||||
'user_id' => $params['user_id'],
|
||||
'member_id' => $member['id'],
|
||||
];
|
||||
|
||||
$record = UserMemberRecord::create($data);
|
||||
|
||||
//记录日志
|
||||
UtilsService::user_finance_add(
|
||||
$data['user_id'],
|
||||
10,
|
||||
2,
|
||||
$member['price'],
|
||||
''
|
||||
);
|
||||
|
||||
//用户资金修改
|
||||
UtilsService::user_money_change($data['user_id'], 2, $member['price'],'user_money');
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'order_id' => $record['id'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user