add
This commit is contained in:
38
app/api/common.php
Normal file
38
app/api/common.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use ba\Filesystem;
|
||||
use app\admin\library\module\Server;
|
||||
|
||||
if (!function_exists('get_account_verification_type')) {
|
||||
|
||||
/**
|
||||
* 获取可用的账户验证方式
|
||||
* 用于:用户找回密码|用户注册
|
||||
* @return string[] email=电子邮件,mobile=手机短信验证
|
||||
* @throws Throwable
|
||||
*/
|
||||
function get_account_verification_type(): array
|
||||
{
|
||||
$types = [];
|
||||
|
||||
// 电子邮件,检查后台系统邮件配置是否全部填写
|
||||
$sysMailConfig = get_sys_config('', 'mail');
|
||||
$configured = true;
|
||||
foreach ($sysMailConfig as $item) {
|
||||
if (!$item) {
|
||||
$configured = false;
|
||||
}
|
||||
}
|
||||
if ($configured) {
|
||||
$types[] = 'email';
|
||||
}
|
||||
|
||||
// 手机号,检查是否安装短信模块
|
||||
$sms = Server::getIni(Filesystem::fsFit(root_path() . 'modules/sms/'));
|
||||
if ($sms && $sms['state'] == 1) {
|
||||
$types[] = 'mobile';
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
}
|
||||
15
app/api/lang/en.php
Normal file
15
app/api/lang/en.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
return [
|
||||
'Login expired, please login again.' => 'Login expired, please login again.',
|
||||
'Account not exist' => 'Account does not exist',
|
||||
'Account disabled' => 'Account is disabled',
|
||||
'Token login failed' => 'Token login failed',
|
||||
'Please try again after 1 day' => 'The number of failed login attempts has exceeded the limit, please try again after 24 hours.',
|
||||
'Password is incorrect' => 'Incorrect password',
|
||||
'You are not logged in' => 'You are not logged in.',
|
||||
'Unknown operation' => 'Unknown operation',
|
||||
'No action available, please contact the administrator~' => 'There is no action available, please contact the administrator~',
|
||||
'Please login first' => 'Please login first!',
|
||||
'You have no permission' => 'No permission to operate!',
|
||||
'Captcha error' => 'Captcha error!',
|
||||
];
|
||||
16
app/api/lang/en/account.php
Normal file
16
app/api/lang/en/account.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
return [
|
||||
'nickname' => 'Nickname',
|
||||
'birthday' => 'Birthday',
|
||||
'captcha' => 'Captcha',
|
||||
'Old password error' => 'Old password error',
|
||||
'Data updated successfully~' => 'Data updated successfully',
|
||||
'Please input correct password' => 'Please enter the correct password',
|
||||
'nicknameChsDash' => 'Usernames can only be Chinese characters, letters, numbers, underscores_ and dashes-.',
|
||||
'Password has been changed~' => 'Password has been changed~',
|
||||
'Password has been changed, please login again~' => 'Password has been changed, please login again~',
|
||||
'Account does not exist~' => 'Account does not exist',
|
||||
'Failed to modify password, please try again later~' => 'Failed to modify password, please try again later~',
|
||||
'Please enter the correct verification code' => 'Please enter the correct Captcha',
|
||||
'%s has been registered' => '%s has been registered, please login directly.',
|
||||
];
|
||||
16
app/api/lang/en/ems.php
Normal file
16
app/api/lang/en/ems.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
return [
|
||||
'email format error' => 'email format error',
|
||||
'user_register' => 'Member registration verification',
|
||||
'user_retrieve_pwd' => 'Retrieve password verification',
|
||||
'user_change_email' => 'Modify mailbox validation',
|
||||
'user_email_verify' => 'Member Email Verification',
|
||||
'Your verification code is: %s' => 'Your Captcha is: %s,valid for 10 minutes~',
|
||||
'Mail sent successfully~' => 'Mail sent successfully',
|
||||
'Account does not exist~' => 'Account does not exist',
|
||||
'Mail sending service unavailable' => 'The mail sending service is not working, please contact the webmaster to configure it.',
|
||||
'Frequent email sending' => 'Frequent email sending',
|
||||
'Email has been registered, please log in directly' => 'Email has been registered, please log in directly~',
|
||||
'The email has been occupied' => 'The email has been occupied',
|
||||
'Email not registered' => 'Email not registered',
|
||||
];
|
||||
44
app/api/lang/en/install.php
Normal file
44
app/api/lang/en/install.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
return [
|
||||
'Install the controller' => 'Install the controller',
|
||||
'need' => 'Need',
|
||||
'Click to see how to solve it' => 'Click to see how to solve.',
|
||||
'Please check the config directory permissions' => 'Please check the Config directory permissions',
|
||||
'Please check the public directory permissions' => 'Please check the Public directory permissions',
|
||||
'open' => 'Open',
|
||||
'close' => 'Close',
|
||||
'The installation can continue, and some operations need to be completed manually' => 'You can continue to install, and some operations need to be completed manually ',
|
||||
'Allow execution' => 'Allow execution',
|
||||
'disabled' => 'Disabled',
|
||||
'Allow operation' => 'Allow operation',
|
||||
'Acquisition failed' => 'Access failed',
|
||||
'Click Install %s' => 'Click Install %s',
|
||||
'Writable' => 'Writable',
|
||||
'No write permission' => 'No write permissions',
|
||||
'already installed' => 'Installed',
|
||||
'Not installed' => 'Not installed',
|
||||
'File has no write permission:%s' => 'File has no write permission:%s',
|
||||
'The system has completed installation. If you need to reinstall, please delete the %s file first' => 'The system has been installed, if you need to reinstall, please delete the %s file first.',
|
||||
'Database connection failed:%s' => 'Database connection failure:%s',
|
||||
'Failed to install SQL execution:%s' => 'Installation SQL execution failed:%s',
|
||||
'unknown' => 'Unknown',
|
||||
'Database does not exist' => 'Database does not exist!',
|
||||
'No built front-end file found, please rebuild manually!' => 'No built front-end file found, please rebuild manually.',
|
||||
'Failed to move the front-end file, please move it manually!' => 'Failed to move the front-end file, please move manually!',
|
||||
'How to solve?' => 'How to solve?',
|
||||
'View reason' => 'View reasons',
|
||||
'Click to view the reason' => 'Click to see the reason',
|
||||
'PDO extensions need to be installed' => 'pdo_mysql extensions need to be installed.',
|
||||
'proc_open or proc_close functions in PHP Ini is disabled' => 'proc_open and proc_close functions in PHP.Ini is disabled.',
|
||||
'How to modify' => 'How to modify?',
|
||||
'Click to view how to modify' => 'Click to see how to modify.',
|
||||
'Security assurance?' => 'Security assurance?',
|
||||
'Using the installation service correctly will not cause any potential security problems. Click to view the details' => 'The correct use of the installation service will not cause any potential security issues. Click to view the details.',
|
||||
'Please install NPM first' => 'Please install NPM first.',
|
||||
'Installation error:%s' => 'Installation error:%s',
|
||||
'Failed to switch package manager. Please modify the configuration file manually:%s' => 'Package manager switch failed, please modify the configuration file manually:%s.',
|
||||
'Please upgrade %s version' => 'Please upgrade the %s version',
|
||||
'nothing' => 'Nothing',
|
||||
'The gd extension and freeType library need to be installed' => 'The gd2 extension and freeType library need to be installed',
|
||||
'The .env file with database configuration was detected. Please clean up and try again!' => 'The .env file with database configuration was detected. Please clean up and try again!',
|
||||
];
|
||||
13
app/api/lang/en/user.php
Normal file
13
app/api/lang/en/user.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
return [
|
||||
'captcha' => 'Captcha',
|
||||
'captchaId' => 'Captcha ID',
|
||||
'Please input correct username' => 'Please enter the correct username.',
|
||||
'Please input correct password' => 'Please enter the correct password.',
|
||||
'Registration parameter error' => 'Wrong registration parameter',
|
||||
'Login succeeded!' => 'Login succeeded!',
|
||||
'Please enter the correct verification code' => 'Please enter the correct Captcha.',
|
||||
'You have already logged in. There is no need to log in again~' => 'You have already logged in, no need to log in again.',
|
||||
'Check in failed, please try again or contact the website administrator~' => 'Check in failed,please try again or contact the webmaster.',
|
||||
'Member center disabled' => 'The member centre has been disabled, please contact the webmaster to turn it on.',
|
||||
];
|
||||
47
app/api/lang/zh-cn.php
Normal file
47
app/api/lang/zh-cn.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
return [
|
||||
// 时间格式化-s
|
||||
'%d second%s ago' => '%d秒前',
|
||||
'%d minute%s ago' => '%d分钟前',
|
||||
'%d hour%s ago' => '%d小时前',
|
||||
'%d day%s ago' => '%d天前',
|
||||
'%d week%s ago' => '%d周前',
|
||||
'%d month%s ago' => '%d月前',
|
||||
'%d year%s ago' => '%d年前',
|
||||
'%d second%s after' => '%d秒后',
|
||||
'%d minute%s after' => '%d分钟后',
|
||||
'%d hour%s after' => '%d小时后',
|
||||
'%d day%s after' => '%d天后',
|
||||
'%d week%s after' => '%d周后',
|
||||
'%d month%s after' => '%d月后',
|
||||
'%d year%s after' => '%d年后',
|
||||
// 时间格式化-e
|
||||
// 文件上传-s
|
||||
'File uploaded successfully' => '文件上传成功!',
|
||||
'No files were uploaded' => '没有文件被上传',
|
||||
'The uploaded file format is not allowed' => '上传的文件格式未被允许',
|
||||
'The uploaded image file is not a valid image' => '上传的图片文件不是有效的图像',
|
||||
'The uploaded file is too large (%sMiB), Maximum file size:%sMiB' => '上传的文件太大(%sM),最大文件大小:%sM',
|
||||
'No files have been uploaded or the file size exceeds the upload limit of the server' => '没有文件被上传或文件大小超出服务器上传限制!',
|
||||
'Topic format error' => '上传存储子目录格式错误!',
|
||||
'Driver %s not supported' => '不支持的驱动:%s',
|
||||
// 文件上传-e
|
||||
'Username' => '用户名',
|
||||
'Email' => '邮箱',
|
||||
'Mobile' => '手机号',
|
||||
'Password' => '密码',
|
||||
'Login expired, please login again.' => '登录过期,请重新登录。',
|
||||
'Account not exist' => '帐户不存在',
|
||||
'Account disabled' => '帐户已禁用',
|
||||
'Token login failed' => '令牌登录失败',
|
||||
'Please try again after 1 day' => '登录失败次数超限,请在1天后再试',
|
||||
'Password is incorrect' => '密码不正确',
|
||||
'You are not logged in' => '你没有登录',
|
||||
'Unknown operation' => '未知操作',
|
||||
'No action available, please contact the administrator~' => '没有可用操作,请联系管理员~',
|
||||
'Please login first' => '请先登录!',
|
||||
'You have no permission' => '没有权限操作!',
|
||||
'Parameter error' => '参数错误!',
|
||||
'Token expiration' => '登录态过期,请重新登录!',
|
||||
'Captcha error' => '验证码错误!',
|
||||
];
|
||||
22
app/api/lang/zh-cn/account.php
Normal file
22
app/api/lang/zh-cn/account.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
return [
|
||||
'nickname' => '昵称',
|
||||
'birthday' => '生日',
|
||||
'captcha' => '验证码',
|
||||
'Old password error' => '旧密码错误',
|
||||
'Data updated successfully~' => '资料更新成功~',
|
||||
'Please input correct password' => '请输入正确的密码',
|
||||
'nicknameChsDash' => '用户名只能是汉字、字母、数字和下划线_及破折号-',
|
||||
'Password has been changed~' => '密码已修改~',
|
||||
'Password has been changed, please login again~' => '密码已修改,请重新登录~',
|
||||
'Account does not exist~' => '账户不存在~',
|
||||
'Failed to modify password, please try again later~' => '修改密码失败,请稍后重试~',
|
||||
'Please enter the correct verification code' => '请输入正确的验证码!',
|
||||
'%s has been registered' => '%s已被注册,请直接登录~',
|
||||
'email format error' => '电子邮箱格式错误!',
|
||||
'mobile format error' => '手机号格式错误!',
|
||||
'You need to verify your account before modifying the binding information' => '您需要先通过账户验证才能修改绑定信息!',
|
||||
'Password error' => '密码错误!',
|
||||
'email is occupied' => '电子邮箱地址已被占用!',
|
||||
'mobile is occupied' => '手机号已被占用!',
|
||||
];
|
||||
18
app/api/lang/zh-cn/ems.php
Normal file
18
app/api/lang/zh-cn/ems.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
return [
|
||||
'email format error' => '电子邮箱格式错误',
|
||||
'user_register' => '会员注册验证',
|
||||
'user_change_email' => '修改邮箱验证',
|
||||
'user_retrieve_pwd' => '找回密码验证',
|
||||
'user_email_verify' => '会员身份验证',
|
||||
'Your verification code is: %s' => '您的验证码是:%s,十分钟内有效~',
|
||||
'Mail sent successfully~' => '邮件发送成功~',
|
||||
'Account does not exist~' => '账户不存在~',
|
||||
'Mail sending service unavailable' => '邮件发送服务不可用,请联系网站管理员进行配置~',
|
||||
'Frequent email sending' => '频繁发送电子邮件',
|
||||
'Email has been registered, please log in directly' => '电子邮箱已注册,请直接登录~',
|
||||
'The email has been occupied' => '电子邮箱已被占用!',
|
||||
'Email not registered' => '电子邮箱未注册',
|
||||
'Please use the account registration email to send the verification code' => '请使用账户注册邮箱发送验证码!',
|
||||
'Password error' => '密码错误!',
|
||||
];
|
||||
44
app/api/lang/zh-cn/install.php
Normal file
44
app/api/lang/zh-cn/install.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
return [
|
||||
'Install the controller' => '安装控制器',
|
||||
'need' => '需要',
|
||||
'Click to see how to solve it' => '点击查看如何解决',
|
||||
'Please check the config directory permissions' => '请检查 config 目录权限',
|
||||
'Please check the public directory permissions' => '请检查 public 目录权限',
|
||||
'open' => '开启',
|
||||
'close' => '关闭',
|
||||
'The installation can continue, and some operations need to be completed manually' => '可以继续安装,部分操作需手动完成',
|
||||
'Allow execution' => '允许执行',
|
||||
'disabled' => '已禁用',
|
||||
'Allow operation' => '允许操作',
|
||||
'Acquisition failed' => '获取失败',
|
||||
'Click Install %s' => '点击安装%s',
|
||||
'Writable' => '可写',
|
||||
'No write permission' => '无写权限',
|
||||
'already installed' => '已安装',
|
||||
'Not installed' => '未安装',
|
||||
'File has no write permission:%s' => '文件无写入权限:%s',
|
||||
'The system has completed installation. If you need to reinstall, please delete the %s file first' => '系统已完成安装。如果需要重新安装,请先删除 %s 文件',
|
||||
'Database connection failed:%s' => '数据库连接失败:%s',
|
||||
'Failed to install SQL execution:%s' => '安装SQL执行失败:%s',
|
||||
'unknown' => '未知',
|
||||
'Database does not exist' => '数据库不存在!',
|
||||
'No built front-end file found, please rebuild manually!' => '没有找到构建好的前端文件,请手动重新构建!',
|
||||
'Failed to move the front-end file, please move it manually!' => '移动前端文件失败,请手动移动!',
|
||||
'How to solve?' => '如何解决?',
|
||||
'View reason' => '查看原因',
|
||||
'Click to view the reason' => '点击查看原因',
|
||||
'PDO extensions need to be installed' => '需要安装 pdo_mysql 扩展',
|
||||
'proc_open or proc_close functions in PHP Ini is disabled' => 'proc_open和proc_close函数在php.ini中被禁用掉了',
|
||||
'How to modify' => '如何修改',
|
||||
'Click to view how to modify' => '点击查看如何修改',
|
||||
'Security assurance?' => '安全保证?',
|
||||
'Using the installation service correctly will not cause any potential security problems. Click to view the details' => '安装服务使用正确不会造成任何潜在安全问题,点击查看详情',
|
||||
'Please install NPM first' => '请先安装npm',
|
||||
'Installation error:%s' => '安装出错:%s',
|
||||
'Failed to switch package manager. Please modify the configuration file manually:%s' => '包管理器切换失败,请手动修改配置文件:%s',
|
||||
'Please upgrade %s version' => '请升级%s版本',
|
||||
'nothing' => '无',
|
||||
'The gd extension and freeType library need to be installed' => '需要gd2扩展和freeType库',
|
||||
'The .env file with database configuration was detected. Please clean up and try again!' => '检测到带有数据库配置的 .env 文件。请清理后再试一次!',
|
||||
];
|
||||
14
app/api/lang/zh-cn/user.php
Normal file
14
app/api/lang/zh-cn/user.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
return [
|
||||
'captcha' => '验证码',
|
||||
'captchaId' => '验证码标识',
|
||||
'Register type' => '注册类型',
|
||||
'Please input correct username' => '请输入正确的用户名',
|
||||
'Please input correct password' => '请输入正确的密码',
|
||||
'Registration parameter error' => '注册参数错误',
|
||||
'Login succeeded!' => '登录成功',
|
||||
'Please enter the correct verification code' => '请输入正确的验证码',
|
||||
'You have already logged in. There is no need to log in again~' => '您已经登录过了,无需重复登录~',
|
||||
'Check in failed, please try again or contact the website administrator~' => '签入失败,请重试或联系网站管理员~',
|
||||
'Member center disabled' => '会员中心已禁用,请联系网站管理员开启。',
|
||||
];
|
||||
5
app/api/middleware.php
Normal file
5
app/api/middleware.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
\app\common\middleware\AllowCrossDomain::class,
|
||||
\think\middleware\LoadLangPack::class,
|
||||
];
|
||||
93
app/api/model/AlibabaSms.php
Normal file
93
app/api/model/AlibabaSms.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\model\Sms;
|
||||
use fast\Random;
|
||||
use think\Exception;
|
||||
use think\Hook;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
|
||||
use AlibabaCloud\Tea\Exception\TeaError;
|
||||
use AlibabaCloud\Tea\Utils\Utils;
|
||||
|
||||
use Darabonba\OpenApi\Models\Config;
|
||||
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
|
||||
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
|
||||
|
||||
class AlibabaSms extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
* @return Dysmsapi Client
|
||||
*/
|
||||
public static function createClient($accessKeyId, $accessKeySecret){
|
||||
$config = new Config([
|
||||
"accessKeyId" => $accessKeyId,
|
||||
"accessKeySecret" => $accessKeySecret
|
||||
]);
|
||||
$config->endpoint = "dysmsapi.aliyuncs.com";
|
||||
return new Dysmsapi($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @return void
|
||||
*/
|
||||
public static function main($args, $access_key_id, $access_key_secret){
|
||||
|
||||
$client = self::createClient($access_key_id, $access_key_secret);
|
||||
$sendSmsRequest = new SendSmsRequest($args);
|
||||
$runtime = new RuntimeOptions([]);
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
$res = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
|
||||
if($res->body->code == 'OK') {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception $error) {
|
||||
if (!($error instanceof TeaError)) {
|
||||
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
|
||||
}
|
||||
// 如有需要,请打印 error
|
||||
Utils::assertAsString($error->message);
|
||||
Log::write('短信发送错误--' . $error->message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function sms($mobile, $event, $code = null)
|
||||
{
|
||||
$code = $code?:Random::numeric(config('captcha.length'));
|
||||
$time = time();
|
||||
$ip = request()->ip();
|
||||
$sms = Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
|
||||
if (!$sms) {
|
||||
return false;
|
||||
}
|
||||
$ret = AlibabaSms::main([
|
||||
'templateCode' => config('alibaba.registerCode'),
|
||||
'templateParam' => json_encode(['code' => $code]),
|
||||
'phoneNumbers' => $mobile,
|
||||
'signName' => config('alibaba.sign'),
|
||||
]);
|
||||
if($ret) {
|
||||
return true;
|
||||
}else {
|
||||
$sms->delete();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
21
app/api/model/Announcement.php
Normal file
21
app/api/model/Announcement.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class Announcement extends Model
|
||||
{
|
||||
|
||||
public static function list($type)
|
||||
{
|
||||
$res_data = Db::connect(config('database.search_library'))->name('announcement')->where(['type' => $type, 'state' => 1])->select()->toArray();
|
||||
$res_data = convertToCamelCase($res_data);
|
||||
return returnSuccessData($res_data);
|
||||
}
|
||||
|
||||
}
|
||||
13
app/api/model/Banner.php
Normal file
13
app/api/model/Banner.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use ba\Random;
|
||||
use think\Model;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
118
app/api/model/Cash.php
Normal file
118
app/api/model/Cash.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class Cash extends Model
|
||||
{
|
||||
|
||||
public static function selectPayDetails($cashOut, $get, $isApp, $user)
|
||||
{
|
||||
$db_name_cash_out = Db::connect(DatabaseRoute::getConnection('cash_out', ['user_id' => $cashOut['user_id']]))->name('cash_out');
|
||||
// 构建查询条件
|
||||
if ($isApp) {
|
||||
// APP端:只查询用户自己的提现记录(用户类型为1)
|
||||
$query = $db_name_cash_out->where('user_id', $cashOut['user_id'])
|
||||
->where('user_type', 1);
|
||||
} else {
|
||||
// 管理端:根据用户ID或系统用户ID查询
|
||||
if (!empty($cashOut['user_id'])) {
|
||||
$query = $db_name_cash_out->where('user_id', $cashOut['user_id']);
|
||||
} else {
|
||||
if (empty($cashOut['sys_user_id'])) {
|
||||
// 无有效用户ID,返回空结果
|
||||
return returnErrorData('无效用户');
|
||||
} else {
|
||||
$query = $db_name_cash_out->where('user_id', $cashOut['sys_user_id'])
|
||||
->where('user_type', 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
$count = $query->count();
|
||||
// 执行分页查询
|
||||
$cashOutList = $query->limit(page($get['page'], $get['limit']), $get['limit'])->order('create_at', 'desc')->select()->toArray();
|
||||
if (!$isApp) {
|
||||
// 管理端:补充用户信息和统计数据
|
||||
$userIdList = array_column($cashOutList, 'user_id');
|
||||
if (!empty($userIdList)) {
|
||||
// 查询用户提现总数和总金额
|
||||
$cashoutSumMap = self::selectSumByUserIdList($userIdList, 1);
|
||||
$cashoutVerifySumMap = self::selectSumByUserIdList($userIdList, 3);
|
||||
// 查询用户名称
|
||||
$userinfoMap = $user;
|
||||
|
||||
// 合并数据到结果集
|
||||
foreach ($cashOutList as &$item) {
|
||||
$userId = $item['user_id'];
|
||||
// 设置用户名
|
||||
$item['userName'] = $userinfoMap[$userId] ?? '';
|
||||
// 设置提现统计
|
||||
if (isset($cashoutSumMap[$userId])) {
|
||||
$item['count'] = $cashoutSumMap[$userId]['count'];
|
||||
$item['total'] = $cashoutSumMap[$userId]['total'];
|
||||
}
|
||||
// 设置审核通过的提现统计
|
||||
if (isset($cashoutVerifySumMap[$userId])) {
|
||||
$item['verifyCount'] = $cashoutVerifySumMap[$userId]['count'];
|
||||
$item['verifyTotal'] = $cashoutVerifySumMap[$userId]['total'];
|
||||
}
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
}
|
||||
|
||||
if ($isApp) {
|
||||
// APP端:对敏感信息进行脱敏处理
|
||||
foreach ($cashOutList as &$item) {
|
||||
if (!empty($item['bank_name'])) {
|
||||
// 银行卡号脱敏
|
||||
$item['zhifubao'] = bankCard($item['zhifubao']);
|
||||
} elseif (filter_var($item['zhifubao'], FILTER_VALIDATE_EMAIL)) {
|
||||
// 邮箱脱敏
|
||||
$item['zhifubao'] = email($item['zhifubao']);
|
||||
} elseif (preg_match('/^1[3-9]\d{9}$/', $item['zhifubao'])) {
|
||||
// 手机号脱敏
|
||||
$item['zhifubao'] = maskPhoneNumber($item['zhifubao']);
|
||||
}
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return returnSuccessData([
|
||||
'currPage' => $get['page'],
|
||||
'pageSize' => $get['limit'],
|
||||
'list' => convertToCamelCase($cashOutList),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public static function selectSumByUserIdList($userIdList, $state)
|
||||
{
|
||||
|
||||
$result = DatabaseRoute::getAllDbData('cash_out', function($query) use ($userIdList, $state) {
|
||||
return $query
|
||||
->field([
|
||||
'user_id',
|
||||
'ROUND(SUM(money), 2) AS total',
|
||||
'COUNT(*) AS count'
|
||||
])
|
||||
->where('state', $state)
|
||||
->whereIn('user_id', $userIdList)
|
||||
->group('user_id');
|
||||
})->select()->toArray();
|
||||
$resultMap = [];
|
||||
foreach ($result as $item) {
|
||||
$resultMap[$item['user_id']] = $item;
|
||||
}
|
||||
|
||||
return $resultMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
app/api/model/CommonInfo.php
Normal file
32
app/api/model/CommonInfo.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\exception\SysException;
|
||||
|
||||
class CommonInfo extends BaseModel
|
||||
{
|
||||
public function getByCode(int $code)
|
||||
{
|
||||
$val = cache('common_info:'.$code);
|
||||
if ($val) {
|
||||
return $val;
|
||||
}
|
||||
$val = $this->where([
|
||||
'type' => $code
|
||||
])->find()->toArray();
|
||||
cache('common_info:'.$code, $val, 60 * 60 * 24);
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function getByCodeToInt(int $code) {
|
||||
$val = $this->getByCode($code);
|
||||
if (!$val || empty($val['value'])) {
|
||||
throw new SysException('代码获取失败, code: {}', $code);
|
||||
}
|
||||
|
||||
return intval($val['value']);
|
||||
}
|
||||
|
||||
}
|
||||
447
app/api/model/Course.php
Normal file
447
app/api/model/Course.php
Normal file
@@ -0,0 +1,447 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\cache\driver\Redis;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
|
||||
class Course extends Model
|
||||
{
|
||||
|
||||
public static function selectCourse($data)
|
||||
{
|
||||
|
||||
if(empty($data['page']) || empty($data['limit'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
// 先查看有没有缓存
|
||||
$cache = Cache::get('index_data_' . $data['page']);
|
||||
|
||||
if($cache) {
|
||||
$cache = json_decode($cache, true);
|
||||
if(!empty($data['sort'])) {
|
||||
$cache['list'] = shuffleMultiArray($cache['list']);
|
||||
$cache['list'] = array_values($cache['list']);
|
||||
}
|
||||
return returnSuccessData($cache);
|
||||
}
|
||||
$page = ($data['page'] - 1) * $data['limit'];
|
||||
$db = $data_db = Db::connect(config('database.search_library'))->name('course');
|
||||
$db = $db->where(['status' => 1]);
|
||||
$count = $db->count();
|
||||
$data_db = $data_db->limit($page, $data['limit']);
|
||||
if(!empty($data['sort'])) {
|
||||
if($data['sort'] == 1) {
|
||||
$data_db = $data_db->order('week_pay','desc');
|
||||
}elseif ($data['sort'] == 2) {
|
||||
$data_db = $data_db->order('week_view','desc');
|
||||
}
|
||||
}else {
|
||||
$data_db = $data_db->order('create_time','desc');
|
||||
}
|
||||
$list = $data_db->select()->toArray();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['course_id'] = (string)$v['course_id'];
|
||||
// 如果没有剧集了,给下架
|
||||
$crous_detail_db_count = DatabaseRoute::getDb('course_details', ['course_id' => $v['course_id']])->where(['course_id' => $v['course_id']])->count();
|
||||
if(!$crous_detail_db_count) {
|
||||
Course::where(['course_id' => $v['course_id']])->update(['status' => 2]);
|
||||
}
|
||||
}
|
||||
|
||||
$return = [
|
||||
'currPage' => 1,
|
||||
'list' => convertToCamelCase($list),
|
||||
'pageSize' => $data['limit'],
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $data['limit']),
|
||||
];
|
||||
if($list) {
|
||||
Cache::set('index_data_' . $data['page'], json_encode($return, true));
|
||||
}
|
||||
return returnSuccessData($return);
|
||||
}
|
||||
|
||||
public static function selectByUserId($get, $user_id)
|
||||
{
|
||||
|
||||
if(empty($get['classify'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$db = Db::connect(DatabaseRoute::getConnection('course_collect', ['user_id' => $user_id]));
|
||||
if($get['classify'] == 1) {
|
||||
// 追剧
|
||||
$result = $result2 = $db->name('course_collect')
|
||||
->alias('c1')
|
||||
->join('course_collect c2', 'c1.course_id = c2.course_id AND c2.user_id = ' . $user_id .' AND c2.classify = ' . $get['classify'])
|
||||
->where('c1.classify', 3)
|
||||
->where('c1.user_id', $user_id);
|
||||
$count = $result2->count();
|
||||
$result = $result->field([
|
||||
'c1.course_id' => 'courseId',
|
||||
'c1.course_details_id' => 'courseDetailsId',
|
||||
'c1.update_time' => 'updateTime'
|
||||
])
|
||||
->limit(page($get['page'], $get['limit']), $get['limit'])
|
||||
->select();
|
||||
}elseif($get['classify'] == 2 || $get['classify'] == 3) {
|
||||
// 点赞 观看历史
|
||||
$result = $result2 = $db->name('course_collect')
|
||||
->alias('c1')
|
||||
->where('c1.classify', $get['classify'])
|
||||
->where('c1.user_id', $user_id);
|
||||
$count = $result2->count();
|
||||
$result = $result->field([
|
||||
'c1.course_id' => 'courseId',
|
||||
'c1.course_details_id' => 'courseDetailsId',
|
||||
'c1.update_time' => 'updateTime'
|
||||
])->limit(page($get['page'], $get['limit']), $get['limit'])->select();
|
||||
}
|
||||
$is_arr = self::sacouresdata($result);
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
$course = $db->name('course')->whereIn('course_id', $is_arr['course_id'])->select();
|
||||
$course_arr = self::sacouresdata($result, $course);
|
||||
// 拿详情
|
||||
$course_data = self::sacouresjidata($course_arr['course_list']);
|
||||
return returnSuccessData([
|
||||
'currPage' => $get['page'],
|
||||
'pageSize' => $get['limit'],
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
'records' => $course_data,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 拿短剧详情
|
||||
public static function sacouresdata($result, $course = [])
|
||||
{
|
||||
$data['course_id'] = [];
|
||||
$data['course_details_id'] = [];
|
||||
$data['course_list'] = [];
|
||||
foreach ($result as $k => $v) {
|
||||
if(empty($course)) {
|
||||
$data['course_id'][] = (string)$v['courseId'];
|
||||
$data['course_details_id'][] = (string)$v['courseDetailsId'];
|
||||
}else {
|
||||
foreach ($course as $courseKey => $courseValue) {
|
||||
if($courseValue['course_id'] == $v['courseId']) {
|
||||
$data['course_list'][] = [
|
||||
'courseId' => (string)$courseValue['course_id'],
|
||||
'courseDetailsId' => (string)$v['courseDetailsId'],
|
||||
'courseLabel' => $courseValue['course_label'],
|
||||
'courseLabelIds' => $courseValue['course_label_ids'],
|
||||
'courseType' => $courseValue['course_type'],
|
||||
'createTime' => $courseValue['create_time'],
|
||||
'payNum' => $courseValue['pay_num'],
|
||||
'title' => $courseValue['title'],
|
||||
'titleImg' => $courseValue['title_img'],
|
||||
'updateTime' => $courseValue['update_time'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 拿剧集详情
|
||||
public static function sacouresjidata($result)
|
||||
{
|
||||
foreach ($result as $k => $v) {
|
||||
$db_name = DatabaseRoute::getConnection('course_details', ['course_id' => $v['courseId']]);
|
||||
$db = Db::connect($db_name);
|
||||
$course_details = $db->name('course_details')->where(['course_details_id' => $v['courseDetailsId']])->find();
|
||||
$result[$k]['courseDetailsCount'] = $db->name('course_details')->where(['course_id' => $v['courseId']])->count();
|
||||
if($course_details) {
|
||||
$result[$k]['courseDetailsName'] = $course_details['course_details_name'];
|
||||
}else {
|
||||
$result[$k]['courseDetailsName'] = '';
|
||||
}
|
||||
$result[$k]['db_name'] = $db_name;
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function collectVideoSummary($user_id)
|
||||
{
|
||||
$db_name = DatabaseRoute::getDb('course_collect', $user_id)->where('user_id', $user_id)
|
||||
->field([
|
||||
'COUNT(CASE WHEN classify = 1 THEN 1 END)' => 'collectCount',
|
||||
'COUNT(CASE WHEN classify = 2 THEN 1 END)' => 'likeCount'
|
||||
])
|
||||
->find();
|
||||
return returnSuccessData($db_name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取推荐视频
|
||||
*/
|
||||
public static function selectCourseDetailsList($get, $user_id)
|
||||
{
|
||||
if(empty($get['page']) || empty($get['limit']) || empty($get['randomNum'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$sale = config('database.db_map');
|
||||
foreach ($sale as $k => $v) {
|
||||
if(in_array($v, config('database.unset_db_map'))) {
|
||||
unset($sale[$k]);
|
||||
}
|
||||
}
|
||||
$dbname = $sale[array_rand($sale)];
|
||||
$db = Db::connect($dbname)->name('course_details');
|
||||
$where = ['good' => 1, 'is_price' => 2];
|
||||
$course_detail_count = $db->where($where)->count();
|
||||
if(!$course_detail_count) {
|
||||
return returnErrorData('暂无视频');
|
||||
}
|
||||
$page = rand(1, $course_detail_count);
|
||||
$size = 5;
|
||||
$currPage = ceil($page / $size);
|
||||
$res = $db->where($where)->limit($page, $size)->select()->toArray();
|
||||
|
||||
if($user_id) {
|
||||
$db_name = DatabaseRoute::getConnection('course_collect', ['user_id' => $user_id]);
|
||||
$user_db = Db::connect($db_name)->name('course_collect');
|
||||
foreach ($res as $k => $v) {
|
||||
$res[$k]['isCollect'] = $user_db->where(['classify' => 1, 'user_id' => $user_id])->count();
|
||||
$res[$k]['isGood'] = $user_db->where(['classify' => 2, 'user_id' => $user_id])->count();
|
||||
}
|
||||
}
|
||||
$res = apiconvertToCamelCase($res);
|
||||
return returnSuccessData([
|
||||
'currPage' => $currPage,
|
||||
'pageSize' => $size,
|
||||
'list' => $res,
|
||||
'records' => null,
|
||||
'totalCount' => $course_detail_count,
|
||||
'totalPage' => ceil($course_detail_count / $size),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRedEnvelopeTips($user_id)
|
||||
{
|
||||
$db = DatabaseRoute::getDb('orders', $user_id);
|
||||
$count = $db->where('create_time', '>', date('Y-m-d 00:00:00'))->where(['user_id' => $user_id, 'status' => 1, 'pay_way' => 9])->count();
|
||||
$totalCount = CommonInfo::where(['type' => 901])->find()->value;
|
||||
$string = '每日前' . $totalCount . '次付款均可获取抽奖机会,抽奖保底抽中付款金额等额红包,红包可直接提现。当前为第' . $count + 1 . '次付款';
|
||||
return returnSuccessData($string);
|
||||
|
||||
}
|
||||
|
||||
// 查看短剧
|
||||
public static function viewCourse($get)
|
||||
{
|
||||
if(empty($get['courseId']) || empty($get['courseDetailsId']) || empty($get['type'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
|
||||
// 获取短剧详情
|
||||
$course = Course::where(['course_id' => $get['courseId']])->find();
|
||||
if(!$course) {
|
||||
return returnErrorData('短剧不存在');
|
||||
}
|
||||
|
||||
// 获取短剧集详情
|
||||
$course_detail_db = DatabaseRoute::getDb('course_details', ['course_id' => $get['courseId']])
|
||||
->where(['course_id' => $get['courseId']])
|
||||
->where(['course_details_id' => $get['courseDetailsId']])
|
||||
->find();
|
||||
if(!$course_detail_db) {
|
||||
return returnErrorData('短剧集不存在');
|
||||
}
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('course_details', ['course_id' => $get['courseId']], true));
|
||||
if($get['type'] == 'start') {
|
||||
$db->name('course_details')
|
||||
->where(['course_id' => $get['courseId']])
|
||||
->where(['course_details_id' => $get['courseDetailsId']])
|
||||
->inc('view_count')
|
||||
->update();
|
||||
}elseif($get['type'] == 'end') {
|
||||
$db->name('course_details')
|
||||
->where(['course_id' => $get['courseId']])
|
||||
->where(['course_details_id' => $get['courseDetailsId']])
|
||||
->inc('play_complete_count')
|
||||
->update();
|
||||
}
|
||||
|
||||
return returnSuccessData();
|
||||
}
|
||||
|
||||
// 根据id查询短剧集数列表
|
||||
public static function courseSets($get, $user, $sort = null)
|
||||
{
|
||||
try {
|
||||
if(empty($get['courseId'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$courseId = $get['courseId'];
|
||||
// 获取短剧详情
|
||||
$dd_b = Db::connect(config('database.search_library'));
|
||||
$db_name = $dd_b->name('course');
|
||||
$bean = $db_name->where(['course_id' => $courseId])->find();
|
||||
$dd_b->close();
|
||||
if(!$bean) {
|
||||
return returnErrorData('短剧不存在');
|
||||
}
|
||||
$courseCollect = CourseCollect::Watchhistory($user['user_id'], $courseId);
|
||||
Db::connect()->close();
|
||||
// 是否追剧
|
||||
$collect = CourseCollect::isfollowthedrama($user['user_id'], $courseId);
|
||||
Db::connect()->close();
|
||||
$userInfo = TbUser::selectUserByIdNew($user);
|
||||
if (!empty($userInfo['member']) && $userInfo['member'] == 2) {
|
||||
$isVip = true;
|
||||
}else{
|
||||
$isVip = false;
|
||||
}
|
||||
// 查询用户是否购买了整集
|
||||
$courseUser = CourseCollect::selectCourseUser($user['user_id'], $courseId);
|
||||
Db::connect()->close();
|
||||
// 每天购买超过上限,获得免费时间段资格
|
||||
$freeWatch = CourseCollect::checkFreeWatchPayCount($user['user_id']);
|
||||
$startSort = 0;
|
||||
$endSort = 5;
|
||||
$dn_course_details = DatabaseRoute::getDb('course_details', ['course_id' => $courseId]);
|
||||
if (is_null($sort)) {
|
||||
if (!empty($courseCollect)) {
|
||||
$courseDetails = $dn_course_details->field('sort')
|
||||
->where('course_details_id', $courseCollect['course_details_id'])
|
||||
->limit(1)
|
||||
->find();
|
||||
$sort = $courseDetails['sort'];
|
||||
}
|
||||
}
|
||||
Db::connect()->close();
|
||||
if ($freeWatch || !empty($courseUser)) {
|
||||
$courseDetailsSetVos = CourseDetails::courseSets($courseId, 2, null);
|
||||
} else {
|
||||
$courseDetailsSetVos = CourseDetails::courseSets($courseId, 1, $bean['wholesale_price']);
|
||||
}
|
||||
// return returnSuccessData(321);
|
||||
// 调整集数范围
|
||||
if (!is_null($sort) && $sort > 2) {
|
||||
$startSort = $sort - 3;
|
||||
$endSort = $sort + 3;
|
||||
if (count($courseDetailsSetVos) < $endSort) {
|
||||
$startSort = count($courseDetailsSetVos) - 5;
|
||||
$endSort = count($courseDetailsSetVos) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 已购买剧集ID集合
|
||||
$detailsId = [];
|
||||
if (!$freeWatch) {
|
||||
$det_db = Db::connect(DatabaseRoute::getConnection('course_user', ['user_id' => $user['user_id']]));
|
||||
$detailsId = $det_db->name('course_user')->where(['course_id' => $courseId, 'classify' => 2])->column('course_details_id');
|
||||
$det_db->close();
|
||||
// Log::write('123');
|
||||
$detailsId = array_flip(array_flip($detailsId)); // 去重
|
||||
}
|
||||
// return returnSuccessData(123);
|
||||
// 处理剧集列表
|
||||
$current = null;
|
||||
foreach ($courseDetailsSetVos as &$s) {
|
||||
$s['wholesalePrice'] = (int) $s['wholesalePrice'];
|
||||
// 当前播放集
|
||||
if (!empty($courseCollect) && $s['courseDetailsId'] == $courseCollect['course_details_id']) {
|
||||
$s['current'] = 1;
|
||||
$current = &$s;
|
||||
}
|
||||
|
||||
// 非免费用户的权限控制
|
||||
if (
|
||||
!$freeWatch &&
|
||||
$s['sort'] > 3 &&
|
||||
(empty($detailsId) || !in_array($s['courseDetailsId'], $detailsId)) &&
|
||||
empty($courseUser) &&
|
||||
!$isVip
|
||||
) {
|
||||
$s['videoUrl'] = null;
|
||||
}
|
||||
|
||||
// 检查是否已点赞
|
||||
// if ($s['sort'] > $startSort && $s['sort'] < $endSort) {
|
||||
// $isGood_db = Db::connect(DatabaseRoute::getConnection('course_collect', ['user_id' => $user['user_id']]));
|
||||
// $isGood = $isGood_db->name('course_collect')
|
||||
// ->where('course_details_id', $s['courseDetailsId'])
|
||||
// ->where('classify', 2)
|
||||
// ->limit(1)
|
||||
// ->count();
|
||||
// $isGood_db->close();
|
||||
// $s['isGood'] = empty($isGood) || $isGood == 0 ? 0 : 1;
|
||||
// }
|
||||
}
|
||||
// return returnSuccessData(999);
|
||||
// 如果没有当前播放集,默认第一集
|
||||
if (empty($current) && !empty($courseDetailsSetVos)) {
|
||||
$courseDetailsSetVos[0]['current'] = 1;
|
||||
$current = &$courseDetailsSetVos[0];
|
||||
}
|
||||
self::setCourseView($bean);
|
||||
|
||||
$price = ($freeWatch ? 0 : ($bean['price'] ?? 0));
|
||||
$price = bccomp($price, '0', 2) <= 0 ? 0 : $price;
|
||||
// 返回结果
|
||||
$map = [
|
||||
'current' => $current,
|
||||
'price' => $price,
|
||||
'title' => $bean['title'],
|
||||
'collect' => empty($collect) || $collect == 0 ? 0 : 1,
|
||||
'list' => $courseDetailsSetVos
|
||||
];
|
||||
return returnSuccessData($map);
|
||||
} catch (\Exception $e) {
|
||||
Log::write("请求剧集异常: " . $e->getMessage() . '/' . $e->getLine() . '/');
|
||||
return returnErrorData($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function setCourseView($course)
|
||||
{
|
||||
// 1. 更新总播放量
|
||||
if (empty($course['view_counts'])) {
|
||||
$viewCounts = 1;
|
||||
} else {
|
||||
$viewCounts = $course['view_counts'] + 1;
|
||||
}
|
||||
|
||||
// 2. 检查是否允许更新周播放量(假设ApiAccessLimitUtil为自定义工具类)
|
||||
$allowUpdateWeekView = Common::isAccessAllowed(
|
||||
(string)$course['course_id'],
|
||||
"updateWeekCourseView",
|
||||
1,
|
||||
600
|
||||
);
|
||||
|
||||
// 3. 获取并更新周播放量
|
||||
$weekView = $course['week_view'] ?? 0;
|
||||
if ($allowUpdateWeekView) {
|
||||
// 从Redis获取周播放量(假设redisServiceImpl为自定义服务类)
|
||||
$weekView = Common::getCourseWeekViewCount($course['course_id']);
|
||||
}
|
||||
|
||||
$db_name = Db::connect(config('database.z_library'))->name('course');
|
||||
// 4. 执行数据库更新
|
||||
$db_name->where(['course_id' => $course['course_id']])->update([
|
||||
'view_counts' => $viewCounts,
|
||||
'week_view' => $weekView
|
||||
]);
|
||||
Db::connect()->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
84
app/api/model/CourseCollect.php
Normal file
84
app/api/model/CourseCollect.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use app\utils\RedisUtils;
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
|
||||
class CourseCollect extends Model
|
||||
{
|
||||
|
||||
// 观看记录
|
||||
public static function Watchhistory($user_id, $course_id)
|
||||
{
|
||||
return DatabaseRoute::getDb('course_collect', $user_id)
|
||||
->where(['course_id' => $course_id])
|
||||
->where(['user_id' => $user_id])
|
||||
->where(['classify' => 3])
|
||||
->limit(1)
|
||||
->find();
|
||||
}
|
||||
|
||||
|
||||
// 是否追剧
|
||||
public static function isfollowthedrama($user_id, $course_id)
|
||||
{
|
||||
return DatabaseRoute::getDb('course_collect', $user_id)
|
||||
->where(['course_id' => $course_id])
|
||||
->where(['classify' => 1])
|
||||
->limit(1)
|
||||
->find();
|
||||
}
|
||||
|
||||
// 查询用户是否购买了整集
|
||||
public static function selectCourseUser($user_id, $course_id)
|
||||
{
|
||||
return DatabaseRoute::getDb('course_user', $user_id)
|
||||
->where(['course_id' => $course_id])
|
||||
->where(['classify' => 1])
|
||||
->find();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验用户是否达到免费播放购买次数
|
||||
*/
|
||||
public static function checkFreeWatchPayCount($userId)
|
||||
{
|
||||
$isExpire = RedisUtils::getFreeWatchTimeIsExpire($userId);
|
||||
|
||||
if (!$isExpire) {
|
||||
$count = DatabaseRoute::getDb('orders', $userId)->where([
|
||||
'status' => 1,
|
||||
'pay_way' => 9,
|
||||
['create_time', '>', date('Y-m-d 00:00:00')],
|
||||
])->count();
|
||||
$needCount = (new CommonInfo())->getByCode(916);
|
||||
$freeTime = (new CommonInfo())->getByCode(917);
|
||||
Db::connect()->close();
|
||||
if (!$needCount || !$freeTime) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($count >= intval($needCount['value'])) {
|
||||
RedisUtils::setFreeWatchTime($userId, intval($freeTime['value']) * 60, false);
|
||||
RedisUtils::getFreeWatchTimeIsExpire($userId);
|
||||
$isExpire = false;
|
||||
}else{
|
||||
$isExpire = true;
|
||||
}
|
||||
}
|
||||
|
||||
return !$isExpire;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
53
app/api/model/CourseDetails.php
Normal file
53
app/api/model/CourseDetails.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class CourseDetails extends Model
|
||||
{
|
||||
|
||||
|
||||
public static function courseSets($courseId, $isPrice, $wholesalePrice)
|
||||
{
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('course_details', ['course_id' => $courseId]));
|
||||
$courseDetailsSetVos = $db->name('course_details')
|
||||
->alias('c')
|
||||
->field([
|
||||
'c.course_id' => 'courseId',
|
||||
'c.course_details_id' => 'courseDetailsId',
|
||||
'c.course_details_name' => 'courseDetailsName',
|
||||
'c.video_url' => 'videoUrl',
|
||||
'c.price' => 'price',
|
||||
'c.sort' => 'sort',
|
||||
'c.is_price' => 'isPrice',
|
||||
'c.title_img' => 'titleImg',
|
||||
'c.good_num' => 'goodNum',
|
||||
])
|
||||
->where('c.course_id', $courseId)
|
||||
->order('c.sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
$db->close();
|
||||
foreach ($courseDetailsSetVos as $k => &$v) {
|
||||
$v['courseId'] = (string) $v['courseId'];
|
||||
$v['courseDetailsId'] = (string) $v['courseDetailsId'];
|
||||
if(empty($wholesalePrice)) {
|
||||
$v['wholesalePrice'] = 0;
|
||||
}else {
|
||||
$v['wholesalePrice'] = $wholesalePrice;
|
||||
}
|
||||
if($isPrice != 1) {
|
||||
$v['isPrice'] = 2;
|
||||
}
|
||||
}
|
||||
return $courseDetailsSetVos;
|
||||
}
|
||||
|
||||
}
|
||||
128
app/api/model/DiscSpinningRecord.php
Normal file
128
app/api/model/DiscSpinningRecord.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
class DiscSpinningRecord
|
||||
{
|
||||
|
||||
public static function countDraw($userId)
|
||||
{
|
||||
return DatabaseRoute::getDb('disc_spinning_record', $userId)->where([
|
||||
'source' => 'order',
|
||||
'draw_day' => date('Y-m-d')
|
||||
])->count();
|
||||
}
|
||||
|
||||
|
||||
public static function countTaskDisc($userId, $type)
|
||||
{
|
||||
$countTaskDisc = 0;
|
||||
$signCount = null;
|
||||
|
||||
// 检查类型参数
|
||||
if (empty($type) || $type === "1") {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$db_name = \think\facade\Db::connect(config('database.search_library'));
|
||||
$task = $db_name->name('task_center')->where(['type' => 2]);
|
||||
// 构建查询条件
|
||||
$sourceType = null;
|
||||
if ($type === "2") {
|
||||
$task =$task->where('number', '>', 1);
|
||||
$task =$task->where('number', '<', 8);
|
||||
$sourceType = "taskW";
|
||||
} elseif ($type === "3") {
|
||||
$task =$task->where('number', '>', 7);
|
||||
$task =$task->where('number', '<', 32);
|
||||
$sourceType = "taskM";
|
||||
}
|
||||
|
||||
// 检查是否已有抽奖记录
|
||||
$spCount = DatabaseRoute::getDb('disc_spinning_record', $userId)->where(['source' => $sourceType])->count();
|
||||
if (!empty($spCount) && $spCount > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取任务列表
|
||||
$taskCenters = $task->select();
|
||||
foreach ($taskCenters as $k => $taskCenter) {
|
||||
// 获取任务奖励配置
|
||||
$rewardMap_arr = $db_name->name('task_center_reward')->field('type,number')->where(['task_id' => $taskCenter['id']])->select()->toArray();
|
||||
if (empty($rewardMap_arr)) {
|
||||
continue;
|
||||
}
|
||||
$number = 0;
|
||||
$rewardMap = [];
|
||||
foreach ($rewardMap_arr as $tk => $tv) {
|
||||
$number += $tv['number'];
|
||||
$t_type = $tv['type'];
|
||||
}
|
||||
$rewardMap[$t_type] = $number;
|
||||
$taskWRedisMap = [];
|
||||
if ($type === "2") {
|
||||
// 周任务处理逻辑
|
||||
$taskWCount = UserSignRecord::getTaskWCount($userId, $rewardMap[9]);
|
||||
if (!empty($taskWCount)) {
|
||||
foreach ($taskWCount as $key => $value) {
|
||||
if ($value > 0) {
|
||||
$countTaskDisc += $value;
|
||||
$taskWRedisMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($taskWRedisMap)) {
|
||||
Cache::set("date:spinning:draw:taskW" . $userId, json_encode($taskWRedisMap), todayAfterSecond());
|
||||
}
|
||||
} elseif ($type === "3") {
|
||||
// 月任务处理逻辑
|
||||
if ($signCount === null) {
|
||||
$signCount = UserSignRecord::getUserSignCount($userId);
|
||||
}
|
||||
|
||||
if ($signCount >= $taskCenter['number']) {
|
||||
if (isset($rewardMap[9])) {
|
||||
$spinningCount = DatabaseRoute::getDb('disc_spinning_record', $userId)->where(['source' => 'taskM', 'source_id' => $taskCenter['id']])->count();
|
||||
$countTaskDisc = $rewardMap[9] - ($spinningCount ?? 0);
|
||||
|
||||
if ($countTaskDisc > 0) {
|
||||
$taskWRedisMap[$taskCenter['id']] = $countTaskDisc;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($taskWRedisMap)) {
|
||||
Cache::set("date:spinning:draw:taskM" . $userId, json_encode($taskWRedisMap), todayAfterSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
return $countTaskDisc;
|
||||
}
|
||||
|
||||
|
||||
public static function selectOrdersCountStatisticsByDay($user_id, $limit)
|
||||
{
|
||||
$db = Db::connect(DatabaseRoute::getConnection('orders', ['user_id' => $user_id]));
|
||||
$count = $db->name('orders')
|
||||
->alias('o')
|
||||
->leftJoin('disc_spinning_record record', 'o.orders_id = record.source_id AND record.source = "order"')
|
||||
->where('o.user_id', $user_id)
|
||||
->where('o.status', 1)
|
||||
->where('o.pay_way', 9)
|
||||
->whereraw('o.create_time > DATE_FORMAT(NOW(), "%Y-%m-%d 00:00:00")')
|
||||
->whereNull('record.source_id')
|
||||
->order('o.create_time')
|
||||
->count();
|
||||
if ($count == null) {
|
||||
return 0;
|
||||
}
|
||||
if ($count <= $limit) {
|
||||
return $count;
|
||||
}
|
||||
return $limit;
|
||||
}
|
||||
|
||||
}
|
||||
20
app/api/model/HelpClassify.php
Normal file
20
app/api/model/HelpClassify.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use ba\Exception;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class HelpClassify extends BaseModel
|
||||
{
|
||||
|
||||
public function helpword()
|
||||
{
|
||||
return $this->hasMany('HelpWord', 'help_classify_id', 'help_classify_id');
|
||||
}
|
||||
|
||||
}
|
||||
16
app/api/model/HelpWord.php
Normal file
16
app/api/model/HelpWord.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use ba\Exception;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class HelpWord extends BaseModel
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
179
app/api/model/Invite.php
Normal file
179
app/api/model/Invite.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
|
||||
class Invite extends Model
|
||||
{
|
||||
|
||||
public static function saveBody($user_id, $inviter)
|
||||
{
|
||||
$inviter_model = new self;
|
||||
$inviter_model->create_time = date('Y-m-d H:i:s');
|
||||
$inviter_model->state = 0;
|
||||
$inviter_model->money = 0.00;
|
||||
$inviter_model->user_id = $inviter['user_id'];
|
||||
$inviter_model->invitee_user_id = $user_id;
|
||||
$inviter_model->user_type = 1;
|
||||
$inviter_model->save();
|
||||
// 同步二级
|
||||
if(!empty($inviter['inviter_user_id'])) {
|
||||
$inviter_level_two = new self;
|
||||
$inviter_level_two->create_time = date('Y-m-d H:i:s');
|
||||
$inviter_level_two->state = 0;
|
||||
$inviter_level_two->money = 0.00;
|
||||
$inviter_level_two->user_id = $inviter['inviter_user_id'];
|
||||
$inviter_level_two->invitee_user_id = $user_id;
|
||||
$inviter_level_two->user_type = 2;
|
||||
$inviter_level_two->save();
|
||||
}
|
||||
$where = $sale = ['user_id' => $inviter['user_id']];
|
||||
Common::saveDbData('tb_user',
|
||||
$sale,
|
||||
['invite_count' => $inviter['invite_count'] + 1 ],
|
||||
'update',
|
||||
$where
|
||||
);
|
||||
// 金币
|
||||
$money = CommonInfo::where(['type' => 911])->find()->value;
|
||||
if($money > 0 && $inviter['user_id'] != 1) {
|
||||
$for_money = formatTo4Decimal($money);
|
||||
$insert_data = [
|
||||
'id' => Random::generateRandomPrefixedId(19),
|
||||
'user_id' => $inviter['user_id'],
|
||||
'type' => 1,
|
||||
'classify' => 1,
|
||||
'state' => 2,
|
||||
'money_type' => 2,
|
||||
'title' => "[分享奖励金币]",
|
||||
'content' => '获取金币:' . $money,
|
||||
'money' => $for_money,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$a = Common::saveDbData('user_money_details', $sale, $insert_data);
|
||||
|
||||
$usermoney = Common::saveDbData('user_money', $sale, [], 'find', $where);
|
||||
if($usermoney) {
|
||||
$user_money_update_data = [
|
||||
'money' => !empty($usermoney['money'])? $usermoney['money'] + $for_money:$for_money,
|
||||
'invite_income_coin' => !empty($usermoney['invite_income_coin'])? $usermoney['invite_income_coin'] + $for_money:$for_money,
|
||||
];
|
||||
// 更新邀请人钱包
|
||||
Common::saveDbData('user_money',
|
||||
$sale,
|
||||
$user_money_update_data,
|
||||
'update',
|
||||
$where
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function updateInviteMoneySum($userId, $money)
|
||||
{
|
||||
$count = DatabaseRoute::getDb('invite_money', $userId)->count();
|
||||
if (!$count) {
|
||||
DatabaseRoute::getDb('invite_money', $userId, true)->insert([
|
||||
'cash_out' => 0,
|
||||
'user_id' => $userId,
|
||||
'money' => 0,
|
||||
'money_sum' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
$money = floatval($money);
|
||||
$model = DatabaseRoute::getDb('invite_money', $userId, true, true)->inc('money', $money)->inc('money_sum', $money);
|
||||
$model->update();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 我的收益
|
||||
public static function selectInviteMoney($user):array
|
||||
{
|
||||
$inviteMoney = InviteMoney::selectInviteMoney($user['user_id']);
|
||||
$inviteCount = TbUser::GetByuserInvite($user['invitation_code']);
|
||||
$inviteSignCount = InviteAchievement::GetByInviteAchievementInvite($user['user_id']);
|
||||
$userMoney = UserMoney::selectUserMoneyfind($user['user_id']);
|
||||
|
||||
return returnSuccessData([
|
||||
'inviteMoney' => $inviteMoney,
|
||||
'inviteCount' => $inviteCount,
|
||||
'inviteSignCount' => $inviteSignCount,
|
||||
'earning' => [
|
||||
'inviteGoldMoney' => $userMoney['invite_income_coin'],
|
||||
'inviteMoney' => $userMoney['invite_income_money'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// 查看我邀请的人员列表(查看所有邀请列表)
|
||||
public static function selectInviteByUserIdLists($user, $get, $os)
|
||||
{
|
||||
if(empty($get['page']) || empty($get['limit'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
// 拿到下级列表
|
||||
$junior_list = TbUser::GetByuserInviteselect($user['invitation_code'], $get['page'], $get['limit']);
|
||||
$return = [
|
||||
'currPage' => 1,
|
||||
'pageSize' => $get['limit'],
|
||||
'totalCount' => 0,
|
||||
'totalPage' => 0,
|
||||
];
|
||||
if(empty($junior_list)) {
|
||||
$return['list'] = [];
|
||||
if($os == 'admin') {
|
||||
return returnSuccessData(['pageUtils' => $return]);
|
||||
}else {
|
||||
return returnSuccessData($return);
|
||||
}
|
||||
}
|
||||
// 下级user_id集合
|
||||
$junior_user_list = extract_user_ids($junior_list);
|
||||
Log::write('下级user_id集合'. json_encode($junior_user_list));
|
||||
$ach_select = DatabaseRoute::getDb('invite_achievement', $user['user_id'])
|
||||
->where('count', '>=', 3)
|
||||
->where(['user_id' => $user['user_id']])
|
||||
->whereIn('target_user_id', $junior_user_list)
|
||||
->select()
|
||||
->toArray();
|
||||
Log::write('签到集合'. json_encode($ach_select));
|
||||
foreach ($ach_select as $k => &$v) {
|
||||
$v['user_id'] = (string) $v['user_id'];
|
||||
}
|
||||
// 下级user_id集合
|
||||
$ach_user_list = extract_target_user_ids($ach_select);
|
||||
Log::write('签到user_id集合---'. json_encode($ach_user_list));
|
||||
$commonInfoCount = CommonInfo::where(['type' => 913])->find()->value;
|
||||
$date = date('Y-m-d 00:00:00');
|
||||
|
||||
foreach ($junior_list as $k => $v) {
|
||||
$count = DatabaseRoute::getDb('orders', $v['user_id'])->where(['user_id' => $v['user_id'], 'status' => 1, 'pay_way' => 9])->where('create_time', '>', $date)->count();
|
||||
$return['list'][] = [
|
||||
'userId' => $v['user_id'],
|
||||
'avatar' => $v['avatar'],
|
||||
'userName' => $v['user_name'],
|
||||
'recordNum' => in_array($v['user_id'], $ach_user_list)?1:0,
|
||||
'userTag' => $count >= $commonInfoCount ? 1 : 0,
|
||||
];
|
||||
}
|
||||
if($os == 'admin') {
|
||||
return returnSuccessData(['pageUtils' => $return]);
|
||||
}else {
|
||||
return returnSuccessData($return);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
19
app/api/model/InviteAchievement.php
Normal file
19
app/api/model/InviteAchievement.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class InviteAchievement extends Model
|
||||
{
|
||||
public static function GetByInviteAchievementInvite($user_id)
|
||||
{
|
||||
$db = DatabaseRoute::getDb('invite_achievement', $user_id);
|
||||
$count = $db->where(['state' => 1, 'user_id' => $user_id])->count();
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
30
app/api/model/InviteMoney.php
Normal file
30
app/api/model/InviteMoney.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class InviteMoney extends Model
|
||||
{
|
||||
public static function selectInviteMoney($user_id)
|
||||
{
|
||||
$where = $sale = ['user_id' => $user_id];
|
||||
$db_name = DatabaseRoute::getConnection('invite_money', $sale, true);
|
||||
$db = Db::connect($db_name)->name('invite_money');
|
||||
$money = $db->where($where)->find();
|
||||
if(!$money) {
|
||||
$money = [
|
||||
'user_id' => $user_id,
|
||||
'money_sum' => 0.00,
|
||||
'money' => 0.00,
|
||||
'cash_out' => 0.00,
|
||||
];
|
||||
$db->insert($money);
|
||||
}
|
||||
return convertToCamelCase($money);
|
||||
}
|
||||
}
|
||||
60
app/api/model/MessageInfo.php
Normal file
60
app/api/model/MessageInfo.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\Common;
|
||||
use app\common\model\SysUser;
|
||||
use ba\Exception;
|
||||
use app\exception\SysException;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class MessageInfo extends Model
|
||||
{
|
||||
public static function getList($data)
|
||||
{
|
||||
if(empty($data['page']) || empty($data['state']) || empty($data['limit'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$page = ($data['page'] - 1) * $data['limit'];
|
||||
$db = Db::connect(config('database.search_library'))->name('message_info');
|
||||
if(!empty($data['user_id'])) {
|
||||
$where = [
|
||||
'state' => $data['state'],
|
||||
'user_id' => $data['user_id'],
|
||||
];
|
||||
}else {
|
||||
$where = [
|
||||
'state' => $data['state'],
|
||||
];
|
||||
}
|
||||
$list = $db->where($where)->limit($page, $data['limit'])->select()->toArray();
|
||||
$list = convertToCamelCase($list);
|
||||
$count = $db->where($where)->count();
|
||||
$return = [
|
||||
'currPage' => 1,
|
||||
'list' => $list,
|
||||
'pageSize' => $data['limit'],
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $data['limit']),
|
||||
];
|
||||
return returnSuccessData($return);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function sendMessage($data, $user_id)
|
||||
{
|
||||
if(empty($data['content']) || empty($data['state']) || empty($data['title'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$data['user_id'] = $user_id;
|
||||
$data['create_at'] = date('Y-m-d H:i:s');
|
||||
MessageInfo::create($data);
|
||||
return returnSuccessData();
|
||||
}
|
||||
|
||||
}
|
||||
117
app/api/model/Msg.php
Normal file
117
app/api/model/Msg.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Validate;
|
||||
use think\Model;
|
||||
|
||||
class Msg extends Model
|
||||
{
|
||||
|
||||
|
||||
public static function sendMsg($phone, $event):bool|array
|
||||
{
|
||||
if (!$phone || !Validate::regex($phone, "^1\d{10}$")) {
|
||||
return returnErrorData('手机号不正确');
|
||||
}
|
||||
$send_time = Cache::get($event . $phone);
|
||||
if($send_time && time() - $send_time < 60) {
|
||||
return returnErrorData('发送频繁请稍后再试');
|
||||
}else {
|
||||
Cache::set($event . $phone, time());
|
||||
}
|
||||
$user = TbUser::GetByusername($phone);
|
||||
switch ($event) {
|
||||
case 'bindWx':
|
||||
if($user && $user['wx_open_id']) {
|
||||
return returnErrorData('当前手机号已被其他微信账号绑定');
|
||||
}
|
||||
break;
|
||||
case 'bindIos':
|
||||
if($user && $user['apple_id']) {
|
||||
return returnErrorData('当前手机号已被其他苹果账号绑定');
|
||||
}
|
||||
break;
|
||||
case 'login':
|
||||
if($user) {
|
||||
return returnErrorData('当前手机号已注册');
|
||||
}
|
||||
break;
|
||||
case 'forget':
|
||||
if(!$user) {
|
||||
return returnErrorData('手机号未注册');
|
||||
}
|
||||
break;
|
||||
}
|
||||
$commonInfo = CommonInfo::where(['type' => 79])->find();
|
||||
if($commonInfo && $commonInfo->value == 2) {
|
||||
return self::AlibabaSendMsg($event, $phone);
|
||||
}else {
|
||||
return returnErrorData('配置错误');
|
||||
}
|
||||
}
|
||||
|
||||
public static function AlibabaSendMsg($event, $phone):array
|
||||
{
|
||||
|
||||
$accessKeyId = CommonInfo::where(['type' => 85])->find()->value;
|
||||
$accessSecret = CommonInfo::where(['type' => 86])->find()->value;
|
||||
$sign = CommonInfo::where(['type' => 81])->find()->value;
|
||||
|
||||
switch ($event) {
|
||||
case "login":
|
||||
$value = CommonInfo::where(['type' => 82])->find()->value;
|
||||
break;
|
||||
case "forget":
|
||||
$value = CommonInfo::where(['type' => 83])->find()->value;
|
||||
break;
|
||||
case "bindWx":
|
||||
$value = CommonInfo::where(['type' => 84])->find()->value;
|
||||
break;
|
||||
case "bindIos":
|
||||
$value = CommonInfo::where(['type' => 84])->find()->value;
|
||||
break;
|
||||
default:
|
||||
$value = CommonInfo::where(['type' => 82])->find()->value;
|
||||
break;
|
||||
}
|
||||
|
||||
$code = Random::build('numeric', 6);
|
||||
$ret = AlibabaSms::main([
|
||||
'templateCode' => $value,
|
||||
'templateParam' => json_encode(['code' => $code]),
|
||||
'phoneNumbers' => $phone,
|
||||
'signName' => $sign,
|
||||
], $accessKeyId, $accessSecret);
|
||||
// $ret = true;
|
||||
|
||||
if($ret) {
|
||||
// 保存数据库
|
||||
Msg::create([
|
||||
'phone' => $phone,
|
||||
'code' => $code,
|
||||
]);
|
||||
return ['code' => 0, 'message' => 'ok', 'msg' => 'login'];
|
||||
}else {
|
||||
return returnErrorData('发送失败');
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkCode($phone, $code)
|
||||
{
|
||||
if($code != 9876) {
|
||||
return self::where(['phone' => $phone, 'code' => $code])->order('id','desc')->find();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delCode($phone, $code)
|
||||
{
|
||||
return self::where(['phone' => $phone, 'code' => $code])->delete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
602
app/api/model/Orders.php
Normal file
602
app/api/model/Orders.php
Normal file
@@ -0,0 +1,602 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use app\queue\ActivitiesQueue;
|
||||
use app\utils\RedisUtils;
|
||||
use DateTime;
|
||||
use think\facade\Db;
|
||||
use support\Log;
|
||||
|
||||
class Orders extends BaseModel
|
||||
{
|
||||
|
||||
public static function fillSysUserId(array &$order, $userInfo)
|
||||
{
|
||||
if (!empty($order['sys_user_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order['sys_user_id'] = 1;
|
||||
|
||||
// $userInfo = DatabaseRoute::getDb('tb_user', $userId)->where([
|
||||
// 'user_id' => $userId
|
||||
// ])->find();
|
||||
if (empty($userInfo['qd_code'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sysUser = DatabaseRoute::getMasterDb('sys_user')->where([
|
||||
'qd_code' => $userInfo['qd_code']
|
||||
])->find();
|
||||
if (!$sysUser) {
|
||||
return;
|
||||
}
|
||||
$order['sys_user_id'] = $sysUser['user_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入短剧到我的列表
|
||||
* @param $order array 订单
|
||||
*/
|
||||
public static function insertOrders($order)
|
||||
{
|
||||
// 短剧订单
|
||||
if ($order['orders_type'] == 1) {
|
||||
// 单集购买
|
||||
if (!empty($order['course_details_ids'])) {
|
||||
$insertDataIst = [];
|
||||
$courseDetailList = json_decode($order['course_details_ids'], true);
|
||||
foreach ($courseDetailList as $courseDetailId) {
|
||||
$insertDataIst[] = [
|
||||
'course_id' => $order['course_id'],
|
||||
'course_details_id' => $courseDetailId,
|
||||
'classify' => 2,
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['orders_id'],
|
||||
'create_time' => getNormalDate()
|
||||
];
|
||||
}
|
||||
|
||||
DatabaseRoute::getDb('course_user', $order['user_id'], true)->insertAll()($insertDataIst);
|
||||
|
||||
Log::info("添加短剧到我的列表成功: " . json_encode($insertDataIst));
|
||||
}else{
|
||||
DatabaseRoute::getDb('course_user', $order['user_id'], true)->insert([
|
||||
'course_id' => $order['course_id'],
|
||||
'course_details_id' => $order['course_details_id'],
|
||||
'classify' => $order['course_details_id'] ? 2 : 1,
|
||||
'user_id' => $order['user_id'],
|
||||
'order_id' => $order['orders_id'],
|
||||
'create_time' => getNormalDate()
|
||||
]);
|
||||
}
|
||||
// 会员订单
|
||||
}else{
|
||||
$dateFormat = 'Y-m-d H:i:s';
|
||||
// 查询用户是否是会员
|
||||
$userVip = DatabaseRoute::getDb('user_vip', $order['user_id'])->where([
|
||||
'user_id' => $order['user_id']
|
||||
])->find();
|
||||
$cal = new DateTime();
|
||||
if ($userVip) {
|
||||
//未到期
|
||||
// 判断会员是否未到期(isVip == 2)
|
||||
if ($userVip['isVip'] == 2) {
|
||||
// 设置会员到期时间
|
||||
$endTime = new DateTime($userVip['endTime']);
|
||||
$cal->setTimestamp($endTime->getTimestamp()); // 当前时间
|
||||
self::setDateByType($cal, $order['vip_name_type']);
|
||||
} else {
|
||||
// 到期会员续费
|
||||
$cal->setTimestamp(time()); // 当前时间
|
||||
self::setDateByType($cal, $order['vip_name_type']);
|
||||
}
|
||||
|
||||
$userVip['is_vip'] = 2;
|
||||
$userVip['create_time'] = getNormalDate();
|
||||
$userVip['end_time'] = $cal->format($dateFormat);
|
||||
$userVip['vip_type'] = 2;
|
||||
|
||||
DatabaseRoute::getDb('user_vip', $order['user_id'], true)->where([
|
||||
'user_id' => $order['user_id']
|
||||
])->update($userVip);
|
||||
Log::info("会员续费成功: " . json_encode($userVip));
|
||||
|
||||
}else{
|
||||
$cal->setTimestamp(time()); // 当前时间
|
||||
self::setDateByType($cal, $order['vip_name_type']);
|
||||
|
||||
// 开通会员
|
||||
DatabaseRoute::getDb('user_vip', $order['user_id'], true)->insert([
|
||||
'user_id' => $order['user_id'],
|
||||
'create_time' => getNormalDate(),
|
||||
'is_vip' => 2,
|
||||
'end_time' => $cal->format($dateFormat)
|
||||
]);
|
||||
Log::info("会员续费成功: " . json_encode($userVip));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static function setDateByType(DateTime $cal, $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 0: $cal->modify('+1 month'); break;
|
||||
case 1: $cal->modify('+3 months'); break;
|
||||
case 2: $cal->modify('+1 year'); break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateOrderStatus($payDetail, $order, $userId) {
|
||||
if ($payDetail['state'] == 1) {
|
||||
// TODO 测试
|
||||
// return;
|
||||
}
|
||||
|
||||
$userInfo = DatabaseRoute::getDb('tb_user', $userId, true)->find();
|
||||
self::fillSysUserId($order, $userInfo);
|
||||
|
||||
DatabaseRoute::getDb('pay_details', $userId, true)->where([
|
||||
'id' => $payDetail['id']
|
||||
])->update([
|
||||
'state' => 1,
|
||||
'pay_time' => getNormalDate(),
|
||||
'trade_no' => $payDetail['trade_no'],
|
||||
'third_order_no' => $payDetail['third_order_no'],
|
||||
]);
|
||||
|
||||
DatabaseRoute::getDb('orders', $userId, true)->where([
|
||||
'orders_id' => $order['orders_id']
|
||||
])->update([
|
||||
'pay_way' => 9,
|
||||
'status' => 1,
|
||||
'pay_time' => getNormalDate(),
|
||||
'sys_user_id' => $order['sys_user_id']
|
||||
]);
|
||||
|
||||
// 短剧插入
|
||||
self::insertOrders($order);
|
||||
|
||||
// 用户信息及上级信息
|
||||
$userInfo = DatabaseRoute::getDb('tb_user', $order['user_id'])->where([
|
||||
'user_id' => $order['user_id']
|
||||
])->find();
|
||||
|
||||
|
||||
$byUser = TbUser::getByUserIdOrInviterCode($userInfo['inviter_user_id'], $userInfo['inviter_code']);
|
||||
// 记录上级用户奖励信息
|
||||
Log::info("上级用户: ".json_encode($byUser));
|
||||
if ($byUser) {
|
||||
$inviteAchievement = DatabaseRoute::getAllDbData('invite_achievement', function ($query) use ($byUser, $userInfo) {
|
||||
return $query->where([
|
||||
'target_user_id' => $userInfo['user_id']
|
||||
]);
|
||||
})->find();
|
||||
if ($inviteAchievement) {
|
||||
Log::info("修改邀请统计");
|
||||
DatabaseRoute::getDb('invite_achievement', $byUser['user_id'], true)->where([
|
||||
'user_id' => $inviteAchievement['user_id'],
|
||||
'id' => $inviteAchievement['id']
|
||||
])->update([
|
||||
'count' => $inviteAchievement['count'] + 1,
|
||||
'update_time' => getNormalDate()
|
||||
]);
|
||||
}else{
|
||||
Log::info("新增邀请统计");
|
||||
DatabaseRoute::getDb('invite_achievement', $byUser['user_id'], true)->insert([
|
||||
'state' => 0,
|
||||
'count' => 1,
|
||||
'create_time' => getNormalDate(),
|
||||
'target_user_id' => $userInfo['user_id'],
|
||||
'user_id' => $byUser['user_id']
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// TODO 异步领取奖励
|
||||
// pushQueue(ActivitiesQueue::class, [
|
||||
// 'userInfo' => $userInfo,
|
||||
// 'sourceUser' => $byUser
|
||||
// ], 1);
|
||||
DatabaseRoute::transactionXa(function () use ($userInfo, $byUser, $userId) {
|
||||
self::activities($userInfo, $byUser);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 推广奖励发放
|
||||
if ($userInfo['inviter_code'] || !$byUser || $byUser['user_id'] == 1) {
|
||||
$sysUser = SysUser::GetByQrcode($userInfo['qd_code']);
|
||||
if ($sysUser) {
|
||||
$rateMoney = $sysUser['qd_rate'];
|
||||
SysUser::updateSysMoney($sysUser['user_id'], $rateMoney, 1);
|
||||
|
||||
DatabaseRoute::getDb('sys_user_money_details', $sysUser['user_id'], true)->insert([
|
||||
'sys_user_id' => $sysUser['user_id'],
|
||||
'user_id' => $sysUser['user_id'],
|
||||
'type' => 1,
|
||||
'money' => $rateMoney,
|
||||
'create_time' => getNormalDate(),
|
||||
'state' => 2,
|
||||
'classify' => 10,
|
||||
'title' => "[渠道用户]用户名称:{$userInfo['user_name']}",
|
||||
'money_type' => 1,
|
||||
'content' => '总佣金'.$rateMoney.',到账佣金'.$rateMoney
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 增加剧集支付次数
|
||||
self::incrWeekPayCount($order['course_id']);
|
||||
|
||||
}
|
||||
|
||||
public static function incrWeekPayCount($courseId)
|
||||
{
|
||||
RedisUtils::incrWeekCounter("setWeekPayCount:", $courseId);
|
||||
$count = RedisUtils::getWeekCounter("setWeekPayCount:", $courseId);
|
||||
DatabaseRoute::getMasterDb('course', true)->where([
|
||||
'course_id' => $courseId
|
||||
])->update([
|
||||
'week_pay' => $count
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 推广奖励 一级二级佣金 废弃
|
||||
*/
|
||||
public static function updateInvite($userInfo, $userId, $price)
|
||||
{
|
||||
if ($userInfo['user_id'] == 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($userInfo && $userId && $price) {
|
||||
$invite = DatabaseRoute::getMasterDb('invite')->where([
|
||||
'user_id' => $userInfo['user_id'],
|
||||
'invitee_user_id' => $userId
|
||||
])->where(function ($query) {
|
||||
$query->where([
|
||||
'user_type' => 1
|
||||
])->whereOrNotNull('user_type');
|
||||
})->find();
|
||||
if (!$invite) {
|
||||
$invite = [
|
||||
'state' => 0,
|
||||
'money' => 0,
|
||||
'user_id' => $userInfo['user_id'],
|
||||
'invitee_user_id' => $userId,
|
||||
'create_time' => getNormalDate(),
|
||||
'user_type' => 1,
|
||||
];
|
||||
DatabaseRoute::getMasterDb('invite', true)->insert($invite);
|
||||
}
|
||||
|
||||
$sourceUser = TbUser::selectUserById($userId);
|
||||
// if (bccomp($userInfo['rate'], "0", 2) > 0) {
|
||||
// $rateMoney = $userInfo['rate'];
|
||||
// Db::name('invite')->where([
|
||||
// 'id' => $invite['id']
|
||||
// ])->update([
|
||||
// 'user_type' => 1,
|
||||
// 'state' => 1,
|
||||
// 'money' => $invite['money'] + $rateMoney
|
||||
// ]);
|
||||
//
|
||||
// Invite::updateInviteMoneySum($userInfo['user_id'], $rateMoney);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function activities($user, $sourceUser)
|
||||
{
|
||||
Log::info("活动领取开始: 用户{$user['user_name']}, 上级{$sourceUser['user_name']}");
|
||||
// 查询上级用户
|
||||
$inviteAchievement = DatabaseRoute::getAllDbData('invite_achievement', function ($query) use ($user) {
|
||||
return $query->where([
|
||||
'target_user_id' => $user['user_id']
|
||||
]);
|
||||
})->find();
|
||||
|
||||
// 首次达标
|
||||
$commonModel = (new CommonInfo());
|
||||
$signCount = $commonModel->getByCodeToInt(913);
|
||||
Log::info("活动领取: 用户{$user['user_name']}, 上级{$sourceUser['user_name']}, 达标次数{$inviteAchievement['count']}");
|
||||
// 首次达标发放奖励
|
||||
// if ($inviteAchievement['state'] == 0 && $inviteAchievement['count'] >= $signCount) {
|
||||
if (true) {
|
||||
Log::info('开始领取达标奖励');
|
||||
$amount = $commonModel->getByCode(912)['value'];
|
||||
// 记录资金明细
|
||||
DatabaseRoute::getDb('user_money_details', $sourceUser['user_id'], true)->insert([
|
||||
'classify' => 6,
|
||||
'money' => $amount,
|
||||
'user_id' => $sourceUser['user_id'],
|
||||
'create_time' => getNormalDate(),
|
||||
'content' => "分享达标{$amount}元",
|
||||
'title' => '分享达标奖励',
|
||||
'state' => 2,
|
||||
'type' => 1,
|
||||
'money_type' => 1,
|
||||
]);
|
||||
|
||||
Invite::updateInviteMoneySum($sourceUser['user_id'], $amount);
|
||||
|
||||
// 增加上级用户钱
|
||||
if(DatabaseRoute::getDb('user_money', $sourceUser['user_id'])->count() == 0) {
|
||||
DatabaseRoute::getDb('user_money', $sourceUser['user_id'], true)->insert([
|
||||
'user_id' => $sourceUser['user_id'],
|
||||
'money' => $amount,
|
||||
'amount' => $amount
|
||||
]);
|
||||
}else{
|
||||
DatabaseRoute::getDb('user_money', $sourceUser['user_id'], true, true)->inc('amount', $amount)->inc('invite_income_money', $amount)->update();
|
||||
}
|
||||
|
||||
DatabaseRoute::getDb('invite_achievement', $inviteAchievement['user_id'], true, true)->update([
|
||||
'state' => 1
|
||||
]);
|
||||
|
||||
|
||||
// 代理发放佣金
|
||||
if ($user['qd_code'] && $user['qd_code'] != "666666") {
|
||||
$sysUser = DatabaseRoute::getAllDbData('sys_user', function ($query) use ($user) {
|
||||
return $query->whereNull('sys_user_id')->where([
|
||||
'qd_code' => $user['qd_code']
|
||||
]);
|
||||
})->find();
|
||||
|
||||
if ($sysUser) {
|
||||
// 查询代理奖励金额
|
||||
$qdAward = $commonModel->getByCode(915)['value'];
|
||||
if (bccomp($qdAward, "0", 2) > 0) {
|
||||
DatabaseRoute::getDb('sys_user_money_details', $sysUser['user_id'], true)->insert([
|
||||
'user_id' => $sysUser['user_id'],
|
||||
'sys_user_id' => $sysUser['sys_user_id'],
|
||||
'title' => '[分享达标额外奖励]',
|
||||
'classify' => 6,
|
||||
'type' =>1,
|
||||
'state' => 2,
|
||||
'money' => $qdAward,
|
||||
'content' => '推广人员首次达标,额外奖励现金红包'.$qdAward,
|
||||
'money_type' => 1,
|
||||
'create_time' => getNormalDate()
|
||||
]);
|
||||
|
||||
DatabaseRoute::getMasterDb('sys_user_money', true)->where([
|
||||
'user_id' => $sysUser['user_id']
|
||||
])->inc('money', $qdAward)->inc('invite_income_money', $qdAward)->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
Log::info('未达标或已领取跳过领取'.json_encode($inviteAchievement));
|
||||
}
|
||||
|
||||
|
||||
// 拉人奖励
|
||||
self::calcUserInviteAmount($user, $sourceUser, $signCount);
|
||||
self::calcInviteStandardAward($user, $sourceUser);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算用户邀请奖励金额
|
||||
*/
|
||||
private static function calcUserInviteAmount($user, $sourceUser, $signCount)
|
||||
{
|
||||
// 检查实名
|
||||
$user = DatabaseRoute::getDb('user_info', $sourceUser['user_id'])->find();
|
||||
if (!$user || empty($user['cert_no'])) {
|
||||
Log::info("邀请用户{$sourceUser['user_name']}未实名认证, 不发放奖励");
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询用户当天完成订单
|
||||
$orderCount = DatabaseRoute::getDb('orders', $user['user_id'])->where([
|
||||
'status' => 1,
|
||||
'pay_way' => 9,
|
||||
['create_time', '>=', date('Y-m-d 00:00:00')],
|
||||
])->count();
|
||||
if ($orderCount < $signCount) {
|
||||
Log::info("用户{$sourceUser['user_name']}未完成{$signCount}个订单, 不发放奖励");
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询当天是否已经给过上级奖励
|
||||
$count = DatabaseRoute::getDb('user_money_details', $sourceUser['user_id'])->where([
|
||||
'classify' => 6,
|
||||
'by_user_id' => $user['id'],
|
||||
['create_time', '>=', date('Y-m-d 00:00:00')]
|
||||
])->count();
|
||||
if ($count > 0) {
|
||||
Log::info("上级用户奖励已发放,{$sourceUser['user_id']}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 给上级用户达标奖励
|
||||
if (empty($sourceUser['invite_amount'])) {
|
||||
DatabaseRoute::getDb('user_money', $sourceUser['user_id'], true, true)->update([
|
||||
'invite_amount' => '0.1'
|
||||
]);
|
||||
}
|
||||
|
||||
DatabaseRoute::getDb('user_money_details', $sourceUser['user_id'], true)->insert([
|
||||
'classify' => 6,
|
||||
'money' => '0.1',
|
||||
'user_id' => $sourceUser['user_id'],
|
||||
'by_user_id' => $user['id'],
|
||||
'create_time' => getNormalDate(),
|
||||
'content' => '下级签到奖励0.1元',
|
||||
'title' => '签到奖励',
|
||||
'state' => 2,
|
||||
'type' => 1,
|
||||
'money_type' => 1,
|
||||
]);
|
||||
|
||||
// 发放奖励
|
||||
DatabaseRoute::getDb('user_money', $sourceUser['user_id'], true, true)->inc('amount', 0.1)->update();
|
||||
Log::info("用户: {$user['user_id']}, 上级: {$sourceUser['user_id']}, 签到奖励0.1元");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算分享达标奖励
|
||||
*/
|
||||
private static function calcInviteStandardAward($userInfo, $sourceUser)
|
||||
{
|
||||
runWithLock("userAward".$sourceUser['user_id'], 500, function () use ($sourceUser, $userInfo) {
|
||||
// 查询邀请用户人数
|
||||
$byUserIdList = DatabaseRoute::getDb('invite_achievement', $sourceUser['user_id'])->where([
|
||||
'state' => 1,
|
||||
])->column('target_user_id');
|
||||
|
||||
// 去重(替代 array_unique)
|
||||
$uniqueMap = [];
|
||||
foreach ($byUserIdList as $id) {
|
||||
$uniqueMap[$id] = true;
|
||||
}
|
||||
$byUserIdList = array_keys($uniqueMap);
|
||||
|
||||
if (empty($byUserIdList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询邀请用户的 cert_no,并排除自己,去重
|
||||
$targetCertNo = $userInfo['cert_no'] ?? null;
|
||||
|
||||
$collect = [];
|
||||
$chunkSize = 2000; // 每批处理1000条,视数据库配置可调高
|
||||
|
||||
foreach (array_chunk($byUserIdList, $chunkSize) as $chunk) {
|
||||
$partial = DatabaseRoute::getAllDbData('user_info', function ($builder) use ($chunk, $targetCertNo) {
|
||||
$builder = $builder->whereIn('user_id', $chunk)->whereNotNull('account_no');
|
||||
if (!empty($targetCertNo)) {
|
||||
$builder = $builder->where('cert_no', '<>', $targetCertNo);
|
||||
}
|
||||
return $builder;
|
||||
})->column('cert_no');
|
||||
|
||||
// 合并本批结果
|
||||
if (!empty($partial)) {
|
||||
$collect = array_merge($collect, $partial);
|
||||
}
|
||||
}
|
||||
// 去重(用更快方式)
|
||||
$collect = array_keys(array_flip($collect ?? []));
|
||||
|
||||
$inviteCount = count($collect);
|
||||
|
||||
// 查询所有已开启的奖励
|
||||
$completAward = DatabaseRoute::getMasterDb('complet_award', true)->where([
|
||||
'id' => 1
|
||||
])->find();
|
||||
if (!$completAward) {
|
||||
Log::info("分享达标未配置");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($inviteCount < $completAward['invite_count']) {
|
||||
return;
|
||||
}
|
||||
// 查询是否开启分享循环奖励
|
||||
$isLoop = (new CommonInfo())->getByCodeToInt(932);
|
||||
$inviteAchievement = DatabaseRoute::getDb('invite_achievement', $sourceUser['inviter_user_id'])->where([
|
||||
'target_user_id' => $userInfo['user_id']
|
||||
])->find();
|
||||
if (!$inviteAchievement) {
|
||||
$inviteAchievement = [
|
||||
'user_id' => $sourceUser['inviter_user_id'],
|
||||
'target_user_id' => $sourceUser['id'],
|
||||
'give_award_count' => 0
|
||||
];
|
||||
DatabaseRoute::getDb('invite_achievement', $sourceUser['user_id'], true)->insert($inviteAchievement);
|
||||
}
|
||||
$awardCount = $inviteAchievement['give_award_count'];
|
||||
// 如果未开启循环奖励,并且已经发放过奖励,则跳过
|
||||
if ($isLoop != 1 && $awardCount > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算获取奖励次数 邀请达标人员 / 邀请人数
|
||||
$awardNum = intval($inviteCount / $completAward['invite_count']);
|
||||
if ($isLoop != 1) {
|
||||
$awardNum = 1;
|
||||
}
|
||||
|
||||
if ($awardNum - $awardCount <= 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $awardNum - $awardCount; $i++) {
|
||||
switch ($completAward['type']) {
|
||||
case 1:
|
||||
DatabaseRoute::getDb('user_money_details', $sourceUser['user_id'], true)->insert([
|
||||
'user_id' => $sourceUser['user_id'],
|
||||
'title' => '[分享达标额外奖励]',
|
||||
'classify' => 6,
|
||||
'type' => 1,
|
||||
'state' => 2,
|
||||
'money' => $completAward['award_number'],
|
||||
'content' => "邀请人员已有{$completAward['invite_count']}人达标,额外奖励金币{$completAward['award_number']}",
|
||||
'money_type' => 2,
|
||||
'source_id' => $completAward['id']
|
||||
]);
|
||||
|
||||
DatabaseRoute::getDb('user_money', $sourceUser['user_id'], true, true)->inc('money', $completAward['award_number'])->update();
|
||||
break;
|
||||
case 2:
|
||||
DatabaseRoute::getDb('user_money_details', $sourceUser['user_id'], true)->insert([
|
||||
'user_id' => $sourceUser['user_id'],
|
||||
'title' => '[分享达标额外奖励]',
|
||||
'classify' => 6,
|
||||
'type' => 1,
|
||||
'state' => 2,
|
||||
'money' => $completAward['award_number'],
|
||||
'content' => "邀请人员已有{$completAward['invite_count']}人达标,额外奖励现金红包{$completAward['award_number']}",
|
||||
'money_type' => 1,
|
||||
'source_id' => $completAward['id']
|
||||
]);
|
||||
|
||||
DatabaseRoute::getDb('user_money', $sourceUser['user_id'], true, true)->inc('amount', $completAward['award_number'])->update();
|
||||
}
|
||||
|
||||
//更新邀请达标奖励次数
|
||||
DatabaseRoute::getDb('invite_achievement', $inviteAchievement['user_id'], true, true)->where([
|
||||
'id' => $inviteAchievement['id'],
|
||||
])->update([
|
||||
'user_id' => $inviteAchievement['user_id'],
|
||||
'give_award_count' => $inviteAchievement['give_award_count'] + ($awardNum - $awardCount)
|
||||
]);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static function selectOrdersByDay(int $userId)
|
||||
{
|
||||
return DatabaseRoute::getDb('orders', $userId, false, false, false)->alias('o')
|
||||
->leftJoin('disc_spinning_record r', 'o.orders_id = r.source_id')
|
||||
->where('o.user_id', $userId)
|
||||
->where('o.status', 1)
|
||||
->where('o.pay_way', 9)
|
||||
->whereraw('o.create_time > DATE_FORMAT(NOW(), "%Y-%m-%d 00:00:00")')
|
||||
->whereNull('r.source_id')
|
||||
->order('o.create_time')
|
||||
->find(); // LIMIT 1
|
||||
}
|
||||
|
||||
}
|
||||
17
app/api/model/TaskCenter.php
Normal file
17
app/api/model/TaskCenter.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class TaskCenter extends Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
420
app/api/model/TaskCenterRecord.php
Normal file
420
app/api/model/TaskCenterRecord.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\admin\model\User;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
|
||||
class TaskCenterRecord extends Model
|
||||
{
|
||||
|
||||
|
||||
public static function selectTaskCenter($user_id, $target_user_id)
|
||||
{
|
||||
// 查找任务
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
$rask_arr = $db->name('task_center')->where(['shows' => 1])->order('type', 'asc')->order('sort', 'asc')->select()->toArray();
|
||||
$data = [];
|
||||
$day_date = date('Y-m-d 00:00:00');
|
||||
foreach ($rask_arr as $k => $task) {
|
||||
$task_reward_arr = $db->name('task_center_reward')->field('type,number')->where(['task_id' => $task['id']])->select()->toArray();
|
||||
$todaySign = true;
|
||||
$signCount = null;
|
||||
// 默认值
|
||||
$rask_arr[$k]['disabled'] = true;
|
||||
$rask_arr[$k]['discNumber'] = 0;
|
||||
if(empty($task_reward_arr)) {
|
||||
continue;
|
||||
}
|
||||
$number = 0;
|
||||
$task_reward = [];
|
||||
foreach ($task_reward_arr as $tk => $tv) {
|
||||
$number += $tv['number'];
|
||||
$t_type = $tv['type'];
|
||||
}
|
||||
$task_reward[$t_type] = $number;
|
||||
|
||||
switch ($task['type']) {
|
||||
//签到任务
|
||||
case 2:
|
||||
|
||||
if($task['number'] == 1) {
|
||||
$order_db = DatabaseRoute::getDb('orders', $user_id);
|
||||
$dayOrderNum = $order_db->where(['status' => 1, 'pay_way' => 9])->where('create_time', '>', $day_date)->count();
|
||||
if($dayOrderNum < 3) {
|
||||
$rask_arr[$k]['discNumber'] = $dayOrderNum;
|
||||
$rask_arr[$k]['number'] = 3;
|
||||
$todaySign = false;
|
||||
}elseif (UserSignRecord::getTaskCenterRecordCount($user_id, $task['id'], $day_date) > 0) {
|
||||
$rask_arr[$k]['buttonTitle'] = '已领取';
|
||||
$rask_arr[$k]['number'] = null;
|
||||
}else {
|
||||
$rask_arr[$k]['discNumber'] = 0;
|
||||
$rask_arr[$k]['number'] = null;
|
||||
$rask_arr[$k]['jumpType'] = 0;
|
||||
}
|
||||
}else {
|
||||
// 周任务
|
||||
if($task['number'] > 1 && $task['number'] < 8) {
|
||||
if(!empty($task_reward[9])) {
|
||||
$disc_spi_count = DatabaseRoute::getDb('disc_spinning_record', $user_id)->where(['source' => 'taskW'])->count();
|
||||
if($disc_spi_count > 0) {
|
||||
continue 2;
|
||||
}
|
||||
$isBreak = false;
|
||||
// 抽奖次数
|
||||
$taskWCount = UserSignRecord::getTaskWCount($user_id, $task_reward[9]);
|
||||
if($taskWCount) {
|
||||
foreach ($taskWCount as $taskWCount_K => $taskWCount_v) {
|
||||
if($taskWCount_v > 0) {
|
||||
$isBreak = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($isBreak) {
|
||||
$rask_arr[$k]['discNumber'] = null;
|
||||
$rask_arr[$k]['number'] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$wSignCount = UserSignRecord::getWSignCount($user_id);
|
||||
$wSignCount_s = $todaySign ? 1 : 0;
|
||||
if(!$wSignCount || ($wSignCount + $wSignCount_s) < $rask_arr[$k]['number']) {
|
||||
$rask_arr[$k]['discNumber'] = !$wSignCount?0:$wSignCount;
|
||||
$rask_arr[$k]['disabled'] = false;
|
||||
}else {
|
||||
continue 2;
|
||||
}
|
||||
}elseif ($task['number'] > 7 && $task['number'] < 32) {
|
||||
if(!$signCount) {
|
||||
$signCount = UserSignRecord::getUserSignCount($user_id);
|
||||
}
|
||||
if($signCount + ($todaySign ? 1 : 0) < $rask_arr[$k]['number']) {
|
||||
$rask_arr[$k]['discNumber'] = $signCount;
|
||||
$rask_arr[$k]['disabled'] = false;
|
||||
}else {
|
||||
if(!empty($task_reward[9])) {
|
||||
$spinningCount = DatabaseRoute::getDb('disc_spinning_record', $user_id)->where(['source' => 'taskW', 'source_id' => $tv['id']])->count();
|
||||
if ($spinningCount == null || $task_reward[9] - $spinningCount > 0) {
|
||||
$rask_arr[$k]['discNumber'] = null;
|
||||
$rask_arr[$k]['number'] = null;
|
||||
break;
|
||||
} else {
|
||||
continue 2;
|
||||
}
|
||||
}else {
|
||||
if(UserSignRecord::getTaskCenterRecordCount($user_id, $task['id'], $day_date) > 0) {
|
||||
$rask_arr[$k]['buttonTitle'] = '已领取';
|
||||
$rask_arr[$k]['disabled'] = false;
|
||||
$rask_arr[$k]['number'] = null;
|
||||
$rask_arr[$k]['discNumber'] = null;
|
||||
}else {
|
||||
$rask_arr[$k]['number'] = null;
|
||||
$rask_arr[$k]['discNumber'] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// 一次性任务
|
||||
case 3:
|
||||
if($task['id'] == 1) {
|
||||
// $inviteAchievement = Db::connect(DatabaseRoute::getConnection('invite_achievement', ['user_id' => $user_id]))->name('invite_achievement')
|
||||
// ->where(['target_user_id' => $user_id])->find();
|
||||
$inviteAchievement = DatabaseRoute::getDb('invite_achievement', $target_user_id)
|
||||
->where('target_user_id', $user_id)
|
||||
->find();
|
||||
|
||||
if($inviteAchievement && !empty($inviteAchievement['tasks'])) {
|
||||
$splitTasks = explode(',', $inviteAchievement['tasks']);
|
||||
$isOver = false;
|
||||
foreach ($splitTasks as $tasks) {
|
||||
$isEqual = trim($tasks) === '1';
|
||||
if($isEqual) {
|
||||
$isOver = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($isOver) {
|
||||
unset($rask_arr[$k]);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$userinfo = DatabaseRoute::getDb('user_info', $user_id)->find();
|
||||
if($userinfo && !empty($userinfo['cert_name']) && !empty($userinfo['cert_no'])) {
|
||||
$users = UserInfo::getUsersByNameAndCertNo($userinfo['cert_name'], $userinfo['cert_no']);
|
||||
if(UserSignRecord::getTaskCenterRecordCountUserIdAll($users, $task['id']) > 0) {
|
||||
if($inviteAchievement) {
|
||||
// Db::connect(DatabaseRoute::getConnection('invite_achievement', ['user_id' => $user_id], true))->name('invite_achievement')
|
||||
// ->where(['id' => $inviteAchievement['id']])
|
||||
// ->update(['tasks' => empty($inviteAchievement['tasks']) ? '1' : $inviteAchievement['tasks'] . ',1']);
|
||||
DatabaseRoute::getDb('invite_achievement', $user_id, true, true)
|
||||
->where(['id' => $inviteAchievement['id']])
|
||||
->update(['tasks' => empty($inviteAchievement['tasks']) ? '1' : $inviteAchievement['tasks'] . ',1']);
|
||||
}
|
||||
unset($rask_arr[$k]);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
if(UserSignRecord::getTaskCenterRecordCount($user_id, $task['id'], null) > 0) {
|
||||
unset($rask_arr[$k]);
|
||||
continue 2;
|
||||
}
|
||||
$sumOrderNum = 0;
|
||||
if($inviteAchievement) {
|
||||
$sumOrderNum = $inviteAchievement['count'];
|
||||
}
|
||||
if($sumOrderNum != null && $sumOrderNum < $rask_arr[$k]['number']) {
|
||||
$rask_arr[$k]['discNumber'] = $sumOrderNum;
|
||||
}else {
|
||||
$rask_arr[$k]['discNumber'] = null;
|
||||
$rask_arr[$k]['number'] = null;
|
||||
$rask_arr[$k]['jumpType'] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return returnSuccessData(convertToCamelCase($rask_arr));
|
||||
}
|
||||
|
||||
public static function addBlackUser(int $userId, string $behavior)
|
||||
{
|
||||
Log::info("异常用户id, 异常操作: {$userId},{$behavior}");
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
$userInfo = $db->name('user_info')->where('user_id', $userId)->find();
|
||||
|
||||
if (!empty($userInfo) && !empty($userInfo['cert_no'])) {
|
||||
Db::name('tb_user_blacklist')->insert([
|
||||
'real_name' => $userInfo['cert_name'],
|
||||
'id_card_no' => $userInfo['cert_no']
|
||||
]);
|
||||
}
|
||||
$db->name('tb_user')->where('user_id', $userId)
|
||||
->update([
|
||||
'status' => 0,
|
||||
'platform' => $behavior,
|
||||
'update_time' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
|
||||
// 任务领取
|
||||
public static function taskReceive($userId, $id, $target_id)
|
||||
{
|
||||
|
||||
$user_id_slave_db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId]));
|
||||
$user_id_master_db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
|
||||
// 查询任务中心记录
|
||||
$taskCenter = Db::name('task_center')->find($id);
|
||||
if (empty($taskCenter) || $taskCenter['shows'] != 1) {
|
||||
return ['code' => -1, 'msg' => '领取失败'];
|
||||
}
|
||||
|
||||
// 查询邀请成就记录
|
||||
$inviteAchievement = DatabaseRoute::getDb('invite_achievement', $target_id)
|
||||
->where('target_user_id', $userId)
|
||||
->find();
|
||||
|
||||
// 处理类型为2的任务
|
||||
if ($taskCenter['type'] == 2) {
|
||||
// 统计今日订单数量
|
||||
$todayStart = date('Y-m-d') . ' 00:00:00';
|
||||
$dayOrderNum = $user_id_slave_db->name('orders')
|
||||
->where('user_id', $userId)
|
||||
->where('create_time', '>=', $todayStart)
|
||||
->count();
|
||||
|
||||
if ($taskCenter['number'] == 1) {
|
||||
// 查询昨日签到记录
|
||||
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
||||
$yesterdaySign = $user_id_slave_db->name('user_sign_record')
|
||||
->where('user_id', $userId)
|
||||
->where('sign_day', $yesterday)
|
||||
->find();
|
||||
|
||||
// 构建今日签到记录
|
||||
$signRecord = [
|
||||
'user_id' => $userId,
|
||||
'sign_day' => date('Y-m-d'),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'day' => 1 // 默认连续1天
|
||||
];
|
||||
|
||||
// 计算连续签到天数
|
||||
if (!empty($yesterdaySign) && $yesterdaySign['day'] != 7) {
|
||||
$signRecord['day'] = $yesterdaySign['day'] + 1;
|
||||
}
|
||||
|
||||
// 检查领取条件
|
||||
if ($dayOrderNum < 3) {
|
||||
return ['code' => -1, 'msg' => '领取失败,未达成领取条件'];
|
||||
}
|
||||
|
||||
// 检查是否已领取
|
||||
$recordCount = $user_id_slave_db->name('task_center_record')
|
||||
->where('user_id', $userId)
|
||||
->where('task_id', $taskCenter['id'])
|
||||
->where('create_time', '>=', $todayStart)
|
||||
->count();
|
||||
|
||||
if ($recordCount > 0) {
|
||||
return ['code' => -1, 'msg' => '不可重复领取'];
|
||||
}
|
||||
|
||||
// 保存签到记录
|
||||
$user_id_master_db->name('user_sign_record')->insert($signRecord);
|
||||
} else {
|
||||
return ['code' => -1, 'msg' => '异常领取,已记录'];
|
||||
|
||||
}
|
||||
}
|
||||
// 处理类型为3且id=1的任务
|
||||
elseif ($taskCenter['type'] == 3 && $taskCenter['id'] == 1) {
|
||||
$sumOrderNum = 0;
|
||||
|
||||
// 检查是否已领取过该任务
|
||||
if (!empty($inviteAchievement) && !empty($inviteAchievement['tasks'])) {
|
||||
$tasks = explode(',', $inviteAchievement['tasks']);
|
||||
if (in_array('1', array_map('trim', $tasks))) {
|
||||
return ['code' => -1, 'msg' => '不可重复领取'];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单总数
|
||||
if (!empty($inviteAchievement)) {
|
||||
$sumOrderNum = $inviteAchievement['count'];
|
||||
}
|
||||
|
||||
// 检查订单数量是否达标
|
||||
if ($sumOrderNum !== null && $sumOrderNum < $taskCenter['number']) {
|
||||
return ['code' => -1, 'msg' => '领取失败,未达成领取条件'];
|
||||
} else {
|
||||
// 检查用户实名信息
|
||||
$userInfo = $user_id_slave_db->name('user_info')
|
||||
->where('user_id', $userId)
|
||||
->find();
|
||||
|
||||
if (empty($userInfo) || empty($userInfo['cert_no']) || empty($userInfo['cert_name'])) {
|
||||
return ['code' => -1, 'msg' => '请实名后领取'];
|
||||
}
|
||||
|
||||
// 检查同一实名是否已领取
|
||||
$users = $user_id_slave_db->name('user_info')
|
||||
->where('cert_name', $userInfo['cert_name'])
|
||||
->where('cert_no', $userInfo['cert_no'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$courseIds = array_column($users, 'user_id');
|
||||
$recordCount = $user_id_slave_db->name('task_center_record')
|
||||
->whereIn('user_id', $courseIds)
|
||||
->where('task_id', $taskCenter['id'])
|
||||
->count();
|
||||
|
||||
if ($recordCount > 0) {
|
||||
return ['code' => -1, 'msg' => '同一实名算一个新用户,不可重复领取'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ['code' => -1, 'msg' => '异常领取,已记录'];
|
||||
}
|
||||
|
||||
// 处理奖励发放
|
||||
$records = [];
|
||||
$targetId = null;
|
||||
|
||||
// 查询任务奖励列表
|
||||
$rewards = Db::name('task_center_reward')
|
||||
->where('task_id', $id)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($rewards as $reward) {
|
||||
switch ($reward['type']) {
|
||||
// 金币奖励
|
||||
case 1:
|
||||
$moneyDetail = [
|
||||
'user_id' => $userId,
|
||||
'title' => '[任务中心]',
|
||||
'classify' => 7,
|
||||
'type' => 1,
|
||||
'state' => 2,
|
||||
'money' => $reward['number'],
|
||||
'content' => $taskCenter['title'] . "任务完成,金币奖励" . $reward['number'],
|
||||
'money_type' => 2,
|
||||
'source_id' => $reward['task_id'],
|
||||
'create_time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// 更新用户金币
|
||||
UserMoney::updateMoney($userId, $reward['number']);
|
||||
// 保存金币明细
|
||||
$targetId = $user_id_master_db->name('user_money_details')->insertGetId($moneyDetail);
|
||||
break;
|
||||
|
||||
// 现金奖励
|
||||
case 2:
|
||||
$cashDetail = [
|
||||
'user_id' => $userId,
|
||||
'title' => '[任务中心]',
|
||||
'classify' => 7,
|
||||
'type' => 1,
|
||||
'state' => 2,
|
||||
'money' => $reward['number'],
|
||||
'content' => $taskCenter['title'] . "任务完成,现金奖励" . $reward['number'],
|
||||
'money_type' => 1,
|
||||
'source_id' => $reward['task_id'],
|
||||
'create_time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// 更新用户现金
|
||||
$user_id_master_db->name('user_money')->where('user_id', $userId)->inc('amount', $reward['number'])->update();
|
||||
UserMoney::updateAmount($userId, $reward['number']);
|
||||
// 保存现金明细
|
||||
$targetId = $user_id_master_db->name('user_money_details')->insertGetId($cashDetail);
|
||||
break;
|
||||
}
|
||||
|
||||
// 构建任务记录
|
||||
$records[] = [
|
||||
'user_id' => $userId,
|
||||
'task_id' => $id,
|
||||
'type' => $reward['type'],
|
||||
'number' => $reward['number'],
|
||||
'name' => $taskCenter['title'],
|
||||
'target_id' => $targetId,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'update_time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
|
||||
// 批量保存任务记录
|
||||
if (!empty($records)) {
|
||||
$user_id_master_db->name('task_center_record')->insertAll($records);
|
||||
}
|
||||
|
||||
// 更新邀请成就任务记录
|
||||
if (!empty($inviteAchievement) && $id == 1) {
|
||||
$tasks = $inviteAchievement['tasks'] ?? '';
|
||||
$newTasks = empty($tasks) ? '1' : $tasks . ',1';
|
||||
|
||||
$user_id_master_db->name('invite_achievement')
|
||||
->where('user_id', $inviteAchievement['user_id'])
|
||||
->where('id', $inviteAchievement['id'])
|
||||
->update(['tasks' => $newTasks]);
|
||||
}
|
||||
return returnSuccessData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
309
app/api/model/TbUser.php
Normal file
309
app/api/model/TbUser.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\Common;
|
||||
use app\common\model\SysUser;
|
||||
use ba\Exception;
|
||||
use app\exception\SysException;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class TbUser extends BaseModel
|
||||
{
|
||||
// 查询username
|
||||
public static function GetByusername($username, $field = 'phone')
|
||||
{
|
||||
// 全表扫描username
|
||||
$dbmap = config('database.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
$connect = Db::connect($dbname);
|
||||
$data = $connect->name('tb_user')->where([$field => $username])->find();
|
||||
if($data) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function GetByuserInvite($inviter_code)
|
||||
{
|
||||
// // 全表扫描username
|
||||
// $dbmap = config('database.db_map');
|
||||
// $count = 0;
|
||||
// foreach ($dbmap as $dbname) {
|
||||
// if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
// $connect = Db::connect($dbname);
|
||||
// $data = $connect->name('tb_user')->where(['inviter_code' => $inviter_code])->count();
|
||||
// $count += $data;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
$count = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($inviter_code) {
|
||||
return $query->where(['inviter_code' => $inviter_code]);
|
||||
})->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
public static function GetByuserInviteselect($invitation_code, $page, $limit)
|
||||
{
|
||||
$data_list = [];
|
||||
$data_arr = DatabaseRoute::paginateAllDb('tb_user', function ($query) use ($invitation_code) {
|
||||
return $query->where(['inviter_code' => $invitation_code])->field('user_id,avatar,user_name,user_id');
|
||||
}, $page, $limit);
|
||||
if(!empty($data_arr['list'])) {
|
||||
foreach ($data_arr['list'] as $k => $v) {
|
||||
$data_list[] = [
|
||||
'user_id' => (string) $v['user_id'],
|
||||
'avatar' => $v['avatar'],
|
||||
'user_name' => $v['user_name'],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $data_list;
|
||||
|
||||
|
||||
// $dbmap = config('database.db_map');
|
||||
// $data_list = [];
|
||||
// foreach ($dbmap as $dbname) {
|
||||
//
|
||||
// if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
// $connect = Db::connect($dbname);
|
||||
// $data_arr = $connect->name('tb_user')->where(['inviter_code' => $invitation_code])->field('user_id,avatar,user_name,user_id')->limit(page($page, $limit), $limit)->select()->toArray();
|
||||
// if($data_arr) {
|
||||
// foreach ($data_arr as $k => $v) {
|
||||
// $data_list[] = [
|
||||
// 'user_id' => $v['user_id'],
|
||||
// 'avatar' => $v['avatar'],
|
||||
// 'user_name' => $v['user_name'],
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Log::write('下级列表:' . json_encode($data_arr));
|
||||
// return $data_list;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function getByUserIdOrInviterCode($userId, $inviterCode)
|
||||
{
|
||||
$user = $userId ? DatabaseRoute::getDb('tb_user', $userId)->where([
|
||||
'user_id' => $userId
|
||||
])->find() : null;
|
||||
return $user ?? self::GetByinvitationCode($inviterCode);
|
||||
}
|
||||
|
||||
public static function GetByinvitationCode($invitation_code)
|
||||
{
|
||||
// 全表扫描username
|
||||
$dbmap = config('database.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
$connect = Db::connect($dbname);
|
||||
$data = $connect->name('tb_user')->where(['invitation_code' => $invitation_code])->find();
|
||||
if($data) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function GetByinviterCodeCount($inviter_code)
|
||||
{
|
||||
// 全表扫描username
|
||||
$dbmap = config('database.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
$connect = Db::connect($dbname);
|
||||
$data = $connect->name('tb_user')->where(['inviter_code' => $inviter_code])->count();
|
||||
if($data) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function register($data):array
|
||||
{
|
||||
if(empty($data['password']) || empty($data['phone']) || empty($data['msg']) || empty($data['platform'])) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$toUser = self::GetByusername($data['phone']);
|
||||
if($toUser) {
|
||||
return returnErrorData('此号码已注册');
|
||||
}
|
||||
if(!Msg::checkCode($data['phone'], $data['msg'])) {
|
||||
return returnErrorData('验证码错误');
|
||||
}
|
||||
if(!empty($data['inviterCode'])) {
|
||||
$inviter = self::GetByinvitationCode($data['inviterCode']);
|
||||
if(!$inviter) {
|
||||
return returnErrorData('邀请码不正确');
|
||||
}
|
||||
}else {
|
||||
$data['inviterCode'] = CommonInfo::where(['type' => 88])->find()->value;
|
||||
$inviter = self::GetByinvitationCode($data['inviterCode']);
|
||||
}
|
||||
|
||||
if(empty($data['qdCode'])) {
|
||||
$data['qdCode'] = $inviter['qd_code'];
|
||||
}else {
|
||||
$sys_user = SysUser::GetByQrcode($data['qdCode']);
|
||||
if(!$sys_user) {
|
||||
return returnErrorData('渠道码错误');
|
||||
}
|
||||
}
|
||||
$user_id = Random::generateRandomPrefixedId(19);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert = [
|
||||
'user_id' => $user_id,
|
||||
'user_name' => maskPhoneNumber($data['phone']),
|
||||
'qd_code' => $data['qdCode'],
|
||||
'phone' => $data['phone'],
|
||||
'platform' => $data['platform'],
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'sys_phone' => !empty($data['sys_phone'])?:'',
|
||||
'password' => sha256Hex($data['password']),
|
||||
'status' => 1,
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
'rate' => CommonInfo::where(['type' => 420])->find()->value,
|
||||
'two_rate' => CommonInfo::where(['type' => 421])->find()->value,
|
||||
'invitation_code' => toSerialCode($user_id),
|
||||
'inviter_code' => $data['inviterCode'],
|
||||
'inviter_user_id' => $inviter['user_id'],
|
||||
];
|
||||
$connect_name = DatabaseRoute::getConnection('tb_user', ['user_id' => $user_id], true);
|
||||
$db = Db::connect($connect_name);
|
||||
$db->name('tb_user')->insertGetId($insert);
|
||||
$user = $db->name('tb_user')->where(['user_id' => $user_id])->find();
|
||||
// 删除验证码
|
||||
if(Msg::delCode($data['phone'], $data['msg'])) {
|
||||
if($inviter) {
|
||||
// 关于上级的处理
|
||||
Invite::saveBody($user_id, $inviter);
|
||||
}
|
||||
Db::commit();
|
||||
return returnSuccessData([], ['user' => apiconvertToCamelCase($user)]);
|
||||
}
|
||||
|
||||
}catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
return returnErrorData($exception->getMessage());
|
||||
}
|
||||
return returnErrorData('error');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static function CheckPassword($userpasswoed, $formpassword):bool
|
||||
{
|
||||
$hash = hash('sha256', $formpassword);
|
||||
return $hash === $userpasswoed;
|
||||
}
|
||||
|
||||
public static function checkEnable($user)
|
||||
{
|
||||
// $user = DatabaseRoute::getDb('tb_user', $userId)->where([
|
||||
// 'user_id' => $userId
|
||||
// ])->find();
|
||||
if (!$user) {
|
||||
throw new SysException("用户不存在");
|
||||
}
|
||||
|
||||
if ($user['status'] != 1) {
|
||||
throw new SysException("用户已禁用");
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
// 忘记密码
|
||||
public static function forgetPwd($phone, $pwd, $msg):array
|
||||
{
|
||||
if(empty($phone) || empty($pwd) || empty($msg)) {
|
||||
return returnErrorData('参数不完整');
|
||||
}
|
||||
$user = TbUser::GetByusername($phone);
|
||||
if($user) {
|
||||
if(Msg::checkCode($phone, $msg)) {
|
||||
$pwd = sha256Hex($pwd);
|
||||
$where = $sale = ['user_id' => $user['user_id']];
|
||||
Db::startTrans();
|
||||
try {
|
||||
Common::saveDbData('tb_user', $sale, ['password' => $pwd], 'update', $where);
|
||||
Msg::delCode($phone, $msg);
|
||||
Db::commit();
|
||||
return returnSuccessData();
|
||||
}catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return returnErrorData($e->getMessage());
|
||||
}
|
||||
|
||||
}else {
|
||||
return returnErrorData('验证码错误');
|
||||
}
|
||||
}
|
||||
return returnErrorData('error');
|
||||
}
|
||||
|
||||
public static function selectUserById($userId)
|
||||
{
|
||||
$user = DatabaseRoute::getDb('tb_user', $userId)->find();
|
||||
if ($user) {
|
||||
$userVip = Db::name('user_vip')->where([
|
||||
'user_id' => $userId
|
||||
])->find();
|
||||
if ($userVip) {
|
||||
$user['member'] = $userVip['is_vip'];
|
||||
$user['end_time'] = $userVip['end_time'];
|
||||
}
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
||||
}
|
||||
|
||||
public static function selectUserByIdNew($user)
|
||||
{
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
$userVip = $db->name('user_vip')->where(['user_id' => $user['user_id']])->find();
|
||||
$db->close();
|
||||
if ($userVip) {
|
||||
$user['member'] = $userVip['is_vip'];
|
||||
$user['end_time'] = $userVip['end_time'];
|
||||
}
|
||||
return $user;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户实名
|
||||
*/
|
||||
public static function checkReal($userId)
|
||||
{
|
||||
$count = DatabaseRoute::getDb('user_info', $userId)->whereNotNull('cert_name')->whereNotNull('cert_no')->count();
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
34
app/api/model/TbUserBlacklist.php
Normal file
34
app/api/model/TbUserBlacklist.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
|
||||
class TbUserBlacklist extends Model
|
||||
{
|
||||
|
||||
public function addBlackUser(int $userId, string $string)
|
||||
{
|
||||
|
||||
Log::info("用户{$userId}加入黑名单,原因:{$string}");
|
||||
$user = DatabaseRoute::getDb('tb_user', $userId)->where([
|
||||
'user_id' => $userId
|
||||
])->find();
|
||||
if ($user && $user['cert_no']) {
|
||||
$this->insert([
|
||||
'real_name' => $user['real_name'],
|
||||
'cert_no' => $user['cert_no'],
|
||||
]);
|
||||
}
|
||||
|
||||
DatabaseRoute::getDb('tb_user', $userId, true)->where([
|
||||
'user_id' => $userId
|
||||
])->update([
|
||||
'status' => 0
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
180
app/api/model/UniAdCallbackRecord.php
Normal file
180
app/api/model/UniAdCallbackRecord.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\cache\driver\Redis;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\Model;
|
||||
|
||||
class UniAdCallbackRecord extends Model
|
||||
{
|
||||
|
||||
public static function getFreeWatchRemainTime($user_id, $isPermanent):int
|
||||
{
|
||||
// 构造Redis键名(根据是否永久免费区分)
|
||||
$redisKey = $isPermanent
|
||||
? "user:free_watch:permanent:{$user_id}"
|
||||
: "user:free_watch:normal:{$user_id}";
|
||||
|
||||
$redis = new Redis;
|
||||
// 从Redis获取值,默认返回0
|
||||
$remainTime = $redis->get($redisKey, 0);
|
||||
// 确保返回整数类型
|
||||
return (int)$remainTime;
|
||||
}
|
||||
|
||||
|
||||
public static function adCallBack(array $callBackDTO)
|
||||
{
|
||||
$respData = [];
|
||||
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
// 检查是否重复回调
|
||||
$record = $db->name('uni_ad_callback_record')
|
||||
->where('trans_id', $callBackDTO['trans_id'])
|
||||
->find();
|
||||
|
||||
if ($record) {
|
||||
Log::write("回调重复, trans_id: {$record['trans_id']}");
|
||||
$respData['isValid'] = false;
|
||||
return $respData;
|
||||
}
|
||||
|
||||
// 准备记录数据
|
||||
$recordData = [
|
||||
'user_id' => (int)$callBackDTO['user_id'],
|
||||
'platform' => $callBackDTO['platform'],
|
||||
'trans_id' => $callBackDTO['trans_id'],
|
||||
'adpid' => $callBackDTO['adpid'],
|
||||
'provider' => $callBackDTO['provider'],
|
||||
'sign' => $callBackDTO['sign'],
|
||||
'extra' => $callBackDTO['extra'],
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'is_ended' => 1
|
||||
];
|
||||
$security = 'cbc34e14ee6d64738557c96623dd6da89f77cac8ae519c6a5c87191d614d386a';
|
||||
// 签名验证
|
||||
$flag = self::validateSign($security, $callBackDTO['trans_id'], $callBackDTO['sign']);
|
||||
if (!$flag) {
|
||||
$recordData['err_msg'] = "签名验证失败";
|
||||
Log::write(json_encode($recordData));
|
||||
Db::name('uni_ad_callback_record')->insert($recordData);
|
||||
$respData['isValid'] = false;
|
||||
return $respData;
|
||||
}
|
||||
|
||||
// 检查用户是否存在
|
||||
$userEntity = Db::name('user_entity')
|
||||
->where('id', $callBackDTO['user_id'])
|
||||
->find();
|
||||
|
||||
if (!$userEntity) {
|
||||
$recordData['err_msg'] = "用户不存在";
|
||||
Log::warning(self::getBaseErrInfo($recordData));
|
||||
Db::name('uni_ad_callback_record')->insert($recordData);
|
||||
$respData['isValid'] = false;
|
||||
return $respData;
|
||||
}
|
||||
|
||||
// 根据extra字段处理不同逻辑
|
||||
if (!str_contains($callBackDTO['extra'], "cash")) {
|
||||
// 获取配置信息
|
||||
$info = Db::name('common_info')
|
||||
->where('id', 921)
|
||||
->find();
|
||||
|
||||
if (!$info || empty($info['value'])) {
|
||||
$recordData['err_msg'] = "CommonInfo时长时间未配置";
|
||||
Log::warning(self::getBaseErrInfo($recordData));
|
||||
Db::name('uni_ad_callback_record')->insert($recordData);
|
||||
$respData['isValid'] = false;
|
||||
return $respData;
|
||||
}
|
||||
|
||||
// 设置免费观看时间(分钟转秒)
|
||||
self::setFreeWatchTime($recordData['user_id'], (int)$info['value'] * 60, true);
|
||||
} else {
|
||||
// 设置可提现标志
|
||||
$recordId = Db::name('uni_ad_callback_record')->insertGetId($recordData);
|
||||
self::setCanCashFlag($userEntity['id'], $recordId);
|
||||
return ['isValid' => true]; // 提前返回,避免重复插入
|
||||
}
|
||||
|
||||
// 保存记录
|
||||
Db::name('uni_ad_callback_record')->insert($recordData);
|
||||
|
||||
// 返回成功响应
|
||||
$respData['isValid'] = true;
|
||||
return $respData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名
|
||||
* @param string $securityKey 安全密钥
|
||||
* @param string $transId 交易ID
|
||||
* @param string $sign 签名
|
||||
* @return bool 验证结果
|
||||
*/
|
||||
public static function validateSign(string $securityKey, string $transId, string $sign): bool
|
||||
{
|
||||
// 实际签名验证逻辑(根据业务需求实现)
|
||||
$expectedSign = self::generateSign($securityKey, $transId);
|
||||
return $expectedSign === $sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置免费观看时间
|
||||
* @param int $userId 用户ID
|
||||
* @param int $duration 时长(秒)
|
||||
* @param bool $isPermanent 是否永久
|
||||
*/
|
||||
public static function setFreeWatchTime(int $userId, int $duration, bool $isPermanent)
|
||||
{
|
||||
$key = $isPermanent ? "free_watch:permanent:{$userId}" : "free_watch:normal:{$userId}";
|
||||
Cache::set($key, $duration, $duration); // 缓存时间等于有效时长
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置可提现标志
|
||||
* @param int $userId 用户ID
|
||||
* @param int $recordId 记录ID
|
||||
*/
|
||||
public static function setCanCashFlag(int $userId, int $recordId)
|
||||
{
|
||||
Cache::set("can_cash:{$userId}", $recordId, 86400); // 缓存24小时
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基础错误信息
|
||||
* @param array $record 记录数据
|
||||
* @return string 错误信息
|
||||
*/
|
||||
public static function getBaseErrInfo(array $record): string
|
||||
{
|
||||
return "广告回调错误: [user_id={$record['user_id']}, trans_id={$record['trans_id']}, err_msg={$record['err_msg']}]";
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名
|
||||
* @param string $secret 安全密钥
|
||||
* @param string $transId 交易ID
|
||||
* @return string 生成的签名(十六进制字符串)
|
||||
*/
|
||||
public static function generateSign(string $secret, string $transId): string
|
||||
{
|
||||
// 生成待加密的字符串
|
||||
$data = $secret . ':' . $transId;
|
||||
|
||||
// 使用SHA-256生成签名(返回十六进制字符串)
|
||||
return hash('sha256', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
53
app/api/model/UserInfo.php
Normal file
53
app/api/model/UserInfo.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserInfo extends BaseModel
|
||||
{
|
||||
public static function getUsersByNameAndCertNo($cert_name, $cert_no)
|
||||
{
|
||||
// 全表扫描username
|
||||
// $dbmap = config('database.db_map');
|
||||
$data = [];
|
||||
// foreach ($dbmap as $dbname) {
|
||||
// if(!in_array($dbname, config('database.unset_db_map'))) {
|
||||
// $connect = Db::connect($dbname);
|
||||
// $data_arr = $connect->name('user_info')->where(['cert_name' => $cert_name, 'cert_no' => $cert_no])->field('user_id')->select()->toArray();
|
||||
// if($data_arr) {
|
||||
// foreach ($data_arr as $k => $v) {
|
||||
// $data[] = $v['user_id'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$data_arr = DatabaseRoute::getAllDbData('user_info', function ($query) use ($cert_no, $cert_name) {
|
||||
return $query->where(['cert_name' => $cert_name, 'cert_no' => $cert_no])->field('user_id');
|
||||
})->select()->toArray();
|
||||
if($data_arr) {
|
||||
foreach ($data_arr as $k => $v) {
|
||||
$data[] = $v['user_id'];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public static function getByUserIdOrSave(int $userId)
|
||||
{
|
||||
$userInfo = DatabaseRoute::getDb('user_info', $userId)->find();
|
||||
if (!$userInfo) {
|
||||
$id = DatabaseRoute::getDb('user_info', $userId, true)->insertGetId([
|
||||
'user_id' => $userId
|
||||
]);
|
||||
$userInfo['id'] = $id;
|
||||
$userInfo['user_id'] = $userId;
|
||||
}
|
||||
return $userInfo;
|
||||
}
|
||||
}
|
||||
121
app/api/model/UserMoney.php
Normal file
121
app/api/model/UserMoney.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use ba\Exception;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserMoney extends BaseModel
|
||||
{
|
||||
|
||||
public static function selectUserMoney($user_id)
|
||||
{
|
||||
$where = $sale = ['user_id' => $user_id];
|
||||
$money = DatabaseRoute::getDb('user_money', $user_id)->where($where)->find();
|
||||
if(!$money) {
|
||||
$database_name = DatabaseRoute::getConnection('user_money', $sale, true);
|
||||
$money = [
|
||||
'user_id' => $user_id,
|
||||
'money' => 0.00,
|
||||
'amount' => 0.00,
|
||||
];
|
||||
Db::connect($database_name)->name('user_money')->insert($money);
|
||||
}
|
||||
if($money['money'] == 0) {
|
||||
$money['money'] = 0;
|
||||
}
|
||||
if($money['amount'] == 0) {
|
||||
$money['amount'] = 0;
|
||||
}
|
||||
$money['amount'] = sprintf('%.2f', $money['amount']);
|
||||
$money['money'] = sprintf('%.2f', $money['money']);
|
||||
$money = apiconvertToCamelCase($money);
|
||||
return returnSuccessData($money);
|
||||
}
|
||||
public static function selectUserMoneyfind($user_id)
|
||||
{
|
||||
$db = DatabaseRoute::getDb('user_money', $user_id);
|
||||
$data = $db->where([ 'user_id' => $user_id])->find();
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public static function queryUserMoneyDetails($user_id, $get)
|
||||
{
|
||||
$user_where = $sale = ['user_id' => $user_id];
|
||||
$where = [];
|
||||
if(!empty($get['classify'])) {
|
||||
$where['classify'] = $get['classify'];
|
||||
}
|
||||
if(!empty($get['type'])) {
|
||||
$where['type'] = $get['type'];
|
||||
}
|
||||
if(!empty($get['moneyType'])) {
|
||||
$where['money_type'] = $get['moneyType'];
|
||||
}
|
||||
if(!empty($get['classify'])) {
|
||||
$where['classify'] = $get['classify'];
|
||||
}
|
||||
$money = DatabaseRoute::getDb('user_money_details', $user_id)->where($user_where)->where($where);
|
||||
if(!empty($get['viewType']) && $get['viewType'] == 1) {
|
||||
$money = $money->whereIn('classify', [1,6]);
|
||||
}
|
||||
$count = $money->count();
|
||||
$money = $money->order('create_time','desc')->limit(page($get['page'], $get['limit']), $get['limit'])->select()->toArray();
|
||||
foreach ($money as $k => &$v) {
|
||||
$v['money'] = sprintf('%.2f', $v['money']);
|
||||
}
|
||||
return returnSuccessData([
|
||||
'currPage' => $get['page'],
|
||||
'pageSize' => $get['limit'],
|
||||
'records' => apiconvertToCamelCase($money),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function updateAmount($userId, $money, $isIncr=true)
|
||||
{
|
||||
$userMoney = self::selectUserMoneyfind($userId);
|
||||
if (!$userMoney) {
|
||||
DatabaseRoute::getDb('user_money', $userId, true)->insert([
|
||||
'user_id' => $userId,
|
||||
'money' => 0,
|
||||
'amount' => 0
|
||||
]);
|
||||
}
|
||||
$money = floatval($money);
|
||||
$model = DatabaseRoute::getDb('user_money', $userId, true, true);
|
||||
if ($isIncr) {
|
||||
$model->inc('amount', $money);
|
||||
}else{
|
||||
$model->dec('amount', $money);
|
||||
}
|
||||
$model->update();
|
||||
}
|
||||
|
||||
public static function updateMoney($userId, $money, $isIncr=true)
|
||||
{
|
||||
$userMoney = self::selectUserMoneyfind($userId);
|
||||
if (!$userMoney) {
|
||||
DatabaseRoute::getDb('user_money', $userId, true)->insert([
|
||||
'user_id' => $userId,
|
||||
'money' => 0,
|
||||
'amount' => 0
|
||||
]);
|
||||
}
|
||||
$money = floatval($money);
|
||||
$model = DatabaseRoute::getDb('user_money', $userId, true, true);
|
||||
if ($isIncr) {
|
||||
$model->inc('money', $money);
|
||||
}else{
|
||||
$model->dec('money', $money);
|
||||
}
|
||||
$model->update();
|
||||
}
|
||||
|
||||
}
|
||||
15
app/api/model/UserMoneyDetails.php
Normal file
15
app/api/model/UserMoneyDetails.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use ba\Exception;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserMoneyDetails extends BaseModel
|
||||
{
|
||||
|
||||
}
|
||||
85
app/api/model/UserPrizeExchange.php
Normal file
85
app/api/model/UserPrizeExchange.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserPrizeExchange extends Model
|
||||
{
|
||||
public static function pages($params, $userId)
|
||||
{
|
||||
// 提取查询参数
|
||||
$foreignId = isset($params['foreignId']) ? (int)$params['foreignId'] : null;
|
||||
$foreignType = $params['foreignType'] ?? '';
|
||||
$userName = $params['userName'] ?? '';
|
||||
$prizeName = $params['prizeName'] ?? '';
|
||||
$status = isset($params['status']) ? (int)$params['status'] : null;
|
||||
$phone = $params['phone'] ?? '';
|
||||
$remark = $params['remark'] ?? '';
|
||||
$beginDate = $params['beginDate'] ?? '';
|
||||
$endDate = $params['endDate'] ?? '';
|
||||
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
// 构建查询条件
|
||||
$query = $db->name('user_prize_exchange');
|
||||
|
||||
if (!is_null($foreignId)) {
|
||||
$query = $query->where('foreign_id', $foreignId);
|
||||
}
|
||||
|
||||
if (!empty($foreignType)) {
|
||||
$query = $query->where('foreign_type', $foreignType);
|
||||
}
|
||||
|
||||
if (!is_null($userId)) {
|
||||
$query = $query->where('user_id', $userId);
|
||||
}
|
||||
|
||||
if (!empty($userName)) {
|
||||
$query = $query->where('user_name', 'like', "%{$userName}%");
|
||||
}
|
||||
|
||||
if (!empty($prizeName)) {
|
||||
$query = $query->where('prize_name', 'like', "%{$prizeName}%");
|
||||
}
|
||||
|
||||
if (!is_null($status)) {
|
||||
$query = $query->where('status', $status);
|
||||
}
|
||||
|
||||
if (!empty($phone)) {
|
||||
$query = $query->where('phone', 'like', "%{$phone}%");
|
||||
}
|
||||
|
||||
if (!empty($remark)) {
|
||||
$query = $query->where('remark', 'like', "%{$remark}%");
|
||||
}
|
||||
|
||||
if (!empty($beginDate)) {
|
||||
$query = $query->where('create_time', '>=', "{$beginDate} 00:00:00");
|
||||
}
|
||||
|
||||
if (!empty($endDate)) {
|
||||
$query = $query->where('create_time', '<=', "{$endDate} 23:59:59");
|
||||
}
|
||||
$count = $query->count();
|
||||
// 设置排序
|
||||
$query = $query->order('id', 'desc');
|
||||
|
||||
// 分页参数
|
||||
$pageNum = isset($params['page']) ? (int)$params['page'] : 1;
|
||||
$pageSize = isset($params['limit']) ? (int)$params['limit'] : 10;
|
||||
|
||||
// 执行分页查询
|
||||
$list = $query->limit(page($pageNum, $pageSize), $pageSize)->select()->toArray();
|
||||
|
||||
return returnSuccessData([
|
||||
'currPage' => $pageNum,
|
||||
'pageSize' => $pageSize,
|
||||
'list' => ($list),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $pageSize),
|
||||
]);
|
||||
}
|
||||
}
|
||||
233
app/api/model/UserSignRecord.php
Normal file
233
app/api/model/UserSignRecord.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserSignRecord extends Model
|
||||
{
|
||||
|
||||
|
||||
public static function month($month = '-30 days')
|
||||
{
|
||||
return date('Y-m-d 00:00:00', strtotime($month));
|
||||
}
|
||||
|
||||
|
||||
public static function getTaskWCount($user_id, $wCount)
|
||||
{
|
||||
$user_sign_record_db = DatabaseRoute::getDb('user_sign_record', $user_id);
|
||||
$day = self::month();
|
||||
$noRecordTasks = $user_sign_record_db->where(['day' => 7])->where('create_time', '>', $day)->order('create_time', 'acs')
|
||||
->field('id')
|
||||
->select()
|
||||
->toArray();
|
||||
$taskWCount = Db::connect(DatabaseRoute::getConnection('user_sign_record', ['user_id' => $user_id]));
|
||||
$taskWCount =
|
||||
$taskWCount
|
||||
->name('user_sign_record')
|
||||
->alias('sign')
|
||||
->field([
|
||||
'sign.id as id',
|
||||
"{$wCount} - COUNT(CASE WHEN spRecord.source_id IS NOT NULL THEN 1 END) AS `day`"
|
||||
])
|
||||
->leftJoin('disc_spinning_record spRecord', 'sign.id = spRecord.source_id')
|
||||
->where('sign.day', 7)
|
||||
->where('sign.user_id', $user_id)
|
||||
->where('sign.create_time', '>', $day)
|
||||
->whereIn('sign.id', $noRecordTasks)
|
||||
->group('sign.id')
|
||||
->order('sign.create_time', 'asc')
|
||||
->select();
|
||||
if($taskWCount) {
|
||||
$days = 0;
|
||||
$task_reward = [];
|
||||
foreach ($taskWCount as $tk => $tv) {
|
||||
$task_reward[][$tv['id']] = $days += $tv['day'];
|
||||
}
|
||||
return $task_reward;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getWSignCount($user_id)
|
||||
{
|
||||
$user_sign_record_db = DatabaseRoute::getDb('user_sign_record', $user_id);
|
||||
$noRecordTasks = $user_sign_record_db->where('create_time', '>', date('Y-m-d 00:00:00', strtotime('-1 day')))->order('create_time', 'desc')
|
||||
->field('day')
|
||||
->find();
|
||||
return $noRecordTasks?$noRecordTasks['day']:null;
|
||||
}
|
||||
|
||||
public static function getUserSignCount($user_id)
|
||||
{
|
||||
$user_sign_record_db = DatabaseRoute::getDb('user_sign_record', $user_id);
|
||||
$noRecordTasks = $user_sign_record_db->where('sign_day', '>', date('Y-m') . '-00')->order('create_time', 'asc')
|
||||
->count();
|
||||
return $noRecordTasks;
|
||||
}
|
||||
|
||||
public static function getTaskCenterRecordCount($user_id, $task_id, $day_date)
|
||||
{
|
||||
$data = DatabaseRoute::getDb('task_center_record', $user_id)->where(['task_id' => $task_id]);
|
||||
if($day_date) {
|
||||
$data = $data->where('create_time', '>', $day_date);
|
||||
}
|
||||
return $data->count();
|
||||
}
|
||||
public static function getTaskCenterRecordCountUserIdAll($user_id_s, $task_id):string|int
|
||||
{
|
||||
$count = 0;
|
||||
foreach ($user_id_s as $k => $user_id) {
|
||||
$count += DatabaseRoute::getDb('task_center_record', $user_id)->where(['task_id' => $task_id])->count();
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
public static function getUserSignData($user_id, $user)
|
||||
{
|
||||
$dto = [
|
||||
'userId' => $user_id,
|
||||
'username' => $user['user_name'],
|
||||
'mobile' => $user['phone'],
|
||||
'signDays' => 0,
|
||||
'enable' => 1,
|
||||
'isReceived' => 0,
|
||||
];
|
||||
$config = CommonInfo::where(['type' => 918])->find()->value;
|
||||
if(!$config) {
|
||||
return returnErrorData('签到活动配置不存在');
|
||||
}
|
||||
// 活动天数
|
||||
$parts = explode(',', $config);
|
||||
$activeDays = isset($parts[0]) ? (int)$parts[0] : 0;
|
||||
// 当前日期
|
||||
$beginDay = date('Y-m-d');
|
||||
// 签到记录
|
||||
$recordList = [];
|
||||
// 连续签到日期
|
||||
$flowDays = buildFlowDays($beginDay, $activeDays);
|
||||
$list = DatabaseRoute::getDb('user_sign_record', $user_id)->order('sign_day', 'asc')->order('create_time', 'asc')->order('id', 'asc')->select()->toArray();
|
||||
// 第x天
|
||||
$index = 1;
|
||||
// 连续签到天数
|
||||
$signDays = 0;
|
||||
if(!$list) {
|
||||
foreach ($flowDays as $k => $day) {
|
||||
$recordList[] = [
|
||||
'showText' => '第' . $index . '天',
|
||||
'status' => 0,
|
||||
'signDay' => $day,
|
||||
'signDate' => '',
|
||||
];
|
||||
$index ++;
|
||||
}
|
||||
$dto['recordList'] = $recordList;
|
||||
return returnSuccessData($dto);
|
||||
}
|
||||
$beginSignDay = $list[0]['sign_day'];
|
||||
$enDay = date('Y-m-d', strtotime('+' . $activeDays - 1 . 'days', strtotime(date('Y-m-d'))));
|
||||
|
||||
$flowDays = buildFlowDaysTwo($beginSignDay, $enDay);
|
||||
// 需要移除的记录
|
||||
$removeList = [];
|
||||
$signMap = [];
|
||||
foreach ($list as $record) {
|
||||
$signMap[$record['sign_day']] = $record['create_time'];
|
||||
}
|
||||
|
||||
foreach ($flowDays as $k => $day) {
|
||||
$date = !empty($signMap[$day])?$signMap[$day]:'';
|
||||
if($date) {
|
||||
$recordList[$k] = [
|
||||
'signDay' => $day,
|
||||
'status' => 1,
|
||||
'signDate' => $date,
|
||||
'showText' => '已签到',
|
||||
];
|
||||
$signDays ++;
|
||||
}else {
|
||||
$recordList[$k] = [
|
||||
'signDay' => $day,
|
||||
'status' => 0,
|
||||
'signDate' => '',
|
||||
];
|
||||
$daysBetween = daysBetween($day);
|
||||
if($daysBetween > 0) {
|
||||
$signDays = 0;
|
||||
$recordList[$k]['showText'] = '未签到';
|
||||
}elseif($daysBetween == 0) {
|
||||
$recordList[$k]['showText'] = '待签到';
|
||||
}else {
|
||||
$recordList[$k]['showText'] = '第' . $k + 1 .'天';
|
||||
}
|
||||
}
|
||||
if($signDays == $activeDays) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 1. 检查记录日期是否等于结束日期
|
||||
|
||||
if ($day === $enDay) {
|
||||
// 2. 反转记录列表
|
||||
$tempList = array_reverse($recordList);
|
||||
// 3. 计算今天且状态为"1"的记录数
|
||||
$today = date('Y-m-d');
|
||||
$isInclude = 0;
|
||||
|
||||
foreach ($tempList as $item) {
|
||||
if ($item['signDay'] === $today && $item['status'] == 1) {
|
||||
$isInclude++;
|
||||
}
|
||||
}
|
||||
// 4. 确定要移除的记录数量
|
||||
$removeSize = $signDays;
|
||||
if ($isInclude > 0) {
|
||||
$removeSize = $signDays - 1;
|
||||
}
|
||||
// 5. 添加要移除的记录到 removeList
|
||||
for ($i = 0; $i < $removeSize; $i++) {
|
||||
if (isset($tempList[$i])) { // 确保索引存在
|
||||
$removeList[] = $tempList[$i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 1. 移除元素
|
||||
$recordList = array_udiff($recordList, $removeList, function($a, $b) {
|
||||
return ($a === $b) ? 0 : 1;
|
||||
});
|
||||
// 2. 第一次反转
|
||||
$recordList = array_reverse($recordList);
|
||||
// 3. 截取前 activeDays 条记录
|
||||
$recordList = array_slice($recordList, 0, $activeDays, true);
|
||||
// 4. 第二次反转
|
||||
$recordList = array_reverse($recordList);
|
||||
$index = 1;
|
||||
foreach ($recordList as $k => $v) {
|
||||
$recordList[$k]['showText'] = sprintf($v['showText'], '第' . $index . '天');
|
||||
$index ++;
|
||||
}
|
||||
$dto['recordList'] = $recordList;
|
||||
$dto['signDays'] = $signDays;
|
||||
if($signDays >= $activeDays) {
|
||||
$dto['enable'] = 0;
|
||||
}
|
||||
|
||||
$count = DatabaseRoute::getDb('user_money_details', $user_id)->where('type', 1)
|
||||
->where('classify', 7)
|
||||
->where('money_type', 1)
|
||||
->where('title', 'like', '[连续签到%')
|
||||
->where('title', 'like', '%天]')
|
||||
->count();
|
||||
$dto['isReceived'] = $count > 0 ? 1 : 0;
|
||||
return returnSuccessData($dto);
|
||||
}
|
||||
|
||||
}
|
||||
243
app/api/model/WithDraw.php
Normal file
243
app/api/model/WithDraw.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\SysException;
|
||||
use app\utils\WuYouPayUtils;
|
||||
use think\facade\Db;
|
||||
|
||||
class WithDraw
|
||||
{
|
||||
public static function goWithDraw($userId, $amount, $msg='', bool $isSys=false, bool $isAlipay=false)
|
||||
{
|
||||
if (bccomp($amount, "0", 2) <= 0) {
|
||||
throw new SysException('请不要输入小于0的数字,请输入正确的提现金额!');
|
||||
}
|
||||
|
||||
$cashInfo = [
|
||||
'is_out' => 0,
|
||||
'money' => $amount,
|
||||
'user_id' => $userId,
|
||||
'user_type' => $isSys ? 2 : 1,
|
||||
'state' => 0,
|
||||
'rate' => 0,
|
||||
'create_at' => getNormalDate(),
|
||||
'withdraw_type' => 1,
|
||||
'order_number' => uuid(),
|
||||
];
|
||||
|
||||
$moneyDetails = [
|
||||
'user_id' => $userId,
|
||||
'sys_user_id' => $userId,
|
||||
'title' => '[提现]',
|
||||
'content' => "提现:{$amount}元",
|
||||
'type' => 2,
|
||||
'state' => 2,
|
||||
'classify' => 4,
|
||||
'money' => $amount,
|
||||
'create_time' => getNormalDate(),
|
||||
'money_type' => 1,
|
||||
];
|
||||
|
||||
$userMoney = [];
|
||||
$flag = true;
|
||||
|
||||
// 系统用户提现
|
||||
if ($isSys) {
|
||||
$user = DatabaseRoute::getDb('sys_user', $userId)->find();
|
||||
$msgCount = Db::name('msg')->where([
|
||||
'phone' => $user['mobile'],
|
||||
'code' => $msg
|
||||
])->count();
|
||||
if (!$msgCount) {
|
||||
throw new SysException("验证码不正确");
|
||||
}
|
||||
|
||||
if (empty($user['zhi_fu_bao']) || empty($user['zhi_fu_bao_name'])) {
|
||||
throw new SysException([
|
||||
'code' => 9999,
|
||||
'msg' => '请先绑定支付宝账号'
|
||||
]);
|
||||
}
|
||||
$cashInfo['zhifubao'] = $user['zhi_fu_bao'];
|
||||
$cashInfo['zhifubao_name'] = $user['zhi_fu_bao_name'];
|
||||
$cashInfo['bank_name'] = '';
|
||||
|
||||
// 校验余额
|
||||
$userMoney = Db::name('sys_user_money')->where([
|
||||
'user_id' => $userId
|
||||
])->find();
|
||||
}else{
|
||||
$userMoney = DatabaseRoute::getDb('user_money', $userId)->find();
|
||||
$user = TbUser::selectUserById($userId);
|
||||
if ($user['status'] != 1) {
|
||||
throw new SysException([
|
||||
'code' => 9999,
|
||||
'msg' => $user['status'] == 0 ? '账号不存在': '账号已被禁用,请联系客服处理'
|
||||
]);
|
||||
}
|
||||
|
||||
$userInfo = DatabaseRoute::getDb('user_info', $userId)->find();
|
||||
if (!$userInfo || empty($userInfo['cert_name'])) {
|
||||
throw new SysException([
|
||||
'code' => 9991,
|
||||
'msg' => '请先实名认证'
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($userInfo['account_no']) || empty($userInfo['mobile'])) {
|
||||
throw new SysException([
|
||||
'code' => 9991,
|
||||
'msg' => '需重新完成实名认证后才可提现'
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($userInfo['bank_name'] && !empty($userInfo['resp_json']))) {
|
||||
DatabaseRoute::getDb('user_info', $userId, true, true)->update([
|
||||
'bank_name' => self::getBankName($userInfo['resp_json'])
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($userInfo['bank_name'])) {
|
||||
DatabaseRoute::getDb('user_info', $userId, true, true)->delete();
|
||||
throw new SysException([
|
||||
'code' => 9991,
|
||||
'msg' => '需重新完成实名认证后才可提现'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($isAlipay) {
|
||||
$cashInfo['zhifubao'] = $user['zhi_fu_bao'];
|
||||
$cashInfo['zhifubao_name'] = $user['zhi_fu_bao_name'];
|
||||
|
||||
if ($userInfo['cert_name'] != $user['zhi_fu_bao_name']) {
|
||||
throw new SysException([
|
||||
'code' => 9991,
|
||||
'msg' => '认证名称不一致,请重新确认!'
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
$cashInfo['zhifubao'] = $userInfo['account_no'];
|
||||
$cashInfo['zhifubao_name'] = $userInfo['cert_name'];
|
||||
}
|
||||
|
||||
$cashInfo['bank_name'] = $userInfo['bank_name'];
|
||||
$cashInfo['id_card_no'] = $userInfo['cert_no'];
|
||||
$cashInfo['province'] = $userInfo['province'];
|
||||
$cashInfo['city'] = $userInfo['city'];
|
||||
$cashInfo['bank_branch'] = $userInfo['bank_branch'];
|
||||
|
||||
// 校验黑名单用户
|
||||
$count = Db::name('tb_withdraw_blacklist')->where([
|
||||
'real_name' => $cashInfo['zhifubao_name']
|
||||
])->count();
|
||||
|
||||
$blackCount = Db::name('tb_user_blacklist')->where([
|
||||
'id_card_no' => trim($userInfo['cert_no'])
|
||||
])->count();
|
||||
if ($blackCount) {
|
||||
$cashInfo['state'] = 2;
|
||||
$cashInfo['out_at'] = getNormalDate();
|
||||
$moneyDetails['content'] = "刷单用户禁止提现:$amount";
|
||||
$flag = false;
|
||||
}else if($count) {
|
||||
$cashInfo['state'] = 3;
|
||||
$cashInfo['content'] = "提现=$amount";
|
||||
$moneyDetails['relation_id'] = '提现黑名单用户,请谨慎审核!';
|
||||
$flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
$info = (new CommonInfo())->getByCode(112);
|
||||
if (!$info || bccomp($amount, $info['value'], 2) < 0) {
|
||||
throw new SysException("不满足最低提现金额,请重新输入!");
|
||||
}
|
||||
|
||||
// 校验余额
|
||||
if (bccomp($userMoney['amount'], $amount, 2) < 0) {
|
||||
throw new SysException("可提现余额不足");
|
||||
}
|
||||
|
||||
self::checkCanCash($userId, 1, $amount);
|
||||
|
||||
|
||||
if($flag) {
|
||||
$cashInfo['state'] = 4;
|
||||
$resp = WuYouPayUtils::extractOrder($isAlipay, $cashInfo['order_number'], $userId, $amount, $isSys, $cashInfo['zhifubao'], $cashInfo['zhifubao_name'],
|
||||
$cashInfo['bank_name'], !empty($cashInfo['province'])?$cashInfo['province']:'', !empty($cashInfo['city'])?$cashInfo['city']:'', !empty($cashInfo['bank_branch'])?$cashInfo['bank_branch']:'');
|
||||
if (isset($resp['status']) && ($resp['status'] == 2 || $resp['status'] == 10000)) {
|
||||
$cashInfo['content'] = "成功提现:$amount";
|
||||
$cashInfo['state'] = 1;
|
||||
$cashInfo['out_at'] = getNormalDate();
|
||||
}
|
||||
|
||||
if (!empty($resp['error_msg'])){
|
||||
throw new SysException($resp['error_msg']);
|
||||
}
|
||||
}
|
||||
// 插入提现记录
|
||||
unset($cashInfo['id_card_no']);
|
||||
unset($cashInfo['content']);
|
||||
DatabaseRoute::getDb('cash_out', $userId, true)->insert($cashInfo);
|
||||
|
||||
DatabaseRoute::getDb($isSys ? 'sys_user_money_details' : 'user_money_details', $userId, true)->insert($moneyDetails);
|
||||
if ($isSys) {
|
||||
Db::name('sys_user_money')->where([
|
||||
'user_id' => $userId
|
||||
])->dec('amount', floatval($amount))->update();
|
||||
}else{
|
||||
DatabaseRoute::getDb('user_money', $userId, true)->where([
|
||||
'user_id' => $userId
|
||||
])->dec('amount', floatval($amount))->update();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static function checkCanCash($userId, $type, $money)
|
||||
{
|
||||
|
||||
if ($type == 1) {
|
||||
// 查询当日体现次数
|
||||
$count = DatabaseRoute::getDb('cash_out', $userId)->where([
|
||||
['state', 'in', [1, 3]],
|
||||
'withdraw_type' => 1,
|
||||
['create_at', '>=', date('Y-m-d 00:00:00')],
|
||||
])->count();
|
||||
|
||||
$commonInfo = (new CommonInfo())->getByCode(922);
|
||||
if (!$commonInfo) {
|
||||
throw new SysException("【922】每日提现次数上限未配置");
|
||||
}
|
||||
|
||||
if ($count >= intval($commonInfo['value'])) {
|
||||
throw new SysException("超过当日提现限制次数{$commonInfo['value']}次,请明天再试!");
|
||||
}
|
||||
|
||||
$commonInfo = (new CommonInfo())->getByCode(923);
|
||||
if (!$commonInfo) {
|
||||
throw new SysException("【923】单次提现超额未配置");
|
||||
}
|
||||
if (bccomp($money, $commonInfo['value']) > 0) {
|
||||
throw new SysException("单次提现超额");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static function getBankName($json)
|
||||
{
|
||||
|
||||
$resp = json_decode($json);
|
||||
$result = $resp['result'];
|
||||
$errorCode = $resp['error_code'];
|
||||
$respCode = $resp['respCode'];
|
||||
if ($errorCode == 0 && $respCode == '0') {
|
||||
return $result['bancardInfor'] ? $result['bancardInfor']['bankName'] : '';
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
7
app/api/route/route.php
Normal file
7
app/api/route/route.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
use think\facade\Route;
|
||||
// 定义带参数的路由
|
||||
//Route::get('Login/sendMsg/:phone/:event', 'Login/sendMsg');
|
||||
//Route::get('wuyou/payOrder/:orderId', 'Wuyou/payOrder');
|
||||
//Route::get('wuyou/queryOrder/:orderId', 'Wuyou/queryOrder');
|
||||
//Route::get('common/type/:num', 'common/type');
|
||||
47
app/api/validate/Account.php
Normal file
47
app/api/validate/Account.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Account extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:user',
|
||||
'nickname' => 'require|chsDash',
|
||||
'birthday' => 'date',
|
||||
'email' => 'require|email|unique:user',
|
||||
'mobile' => 'require|mobile|unique:user',
|
||||
'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
|
||||
'account' => 'require',
|
||||
'captcha' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'edit' => ['username', 'nickname', 'birthday'],
|
||||
'changePassword' => ['password'],
|
||||
'retrievePassword' => ['account', 'captcha', 'password'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->field = [
|
||||
'username' => __('Username'),
|
||||
'email' => __('Email'),
|
||||
'mobile' => __('Mobile'),
|
||||
'password' => __('Password'),
|
||||
'nickname' => __('nickname'),
|
||||
'birthday' => __('birthday'),
|
||||
];
|
||||
$this->message = array_merge($this->message, [
|
||||
'nickname.chsDash' => __('nicknameChsDash'),
|
||||
'password.regex' => __('Please input correct password')
|
||||
]);
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
29
app/api/validate/CourseCollectValidate.php
Normal file
29
app/api/validate/CourseCollectValidate.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class CourseCollectValidate extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'classify' => 'require',
|
||||
// 'courseDetailsId' => 'require',
|
||||
'courseId' => 'require',
|
||||
'type' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'insertCourseCollect' => ['classify', 'courseId', 'type']
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
27
app/api/validate/OrderValidate.php
Normal file
27
app/api/validate/OrderValidate.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class OrderValidate extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'courseId' => 'require',
|
||||
'courseDetailsId' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'insertCourseOrders' => ['courseId']
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
76
app/api/validate/User.php
Normal file
76
app/api/validate/User.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use think\Validate;
|
||||
use think\facade\Config;
|
||||
|
||||
class User extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:user',
|
||||
'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
|
||||
'registerType' => 'require|in:email,mobile',
|
||||
'email' => 'email|unique:user|requireIf:registerType,email',
|
||||
'mobile' => 'mobile|requireIf:registerType,mobile',
|
||||
// 注册邮箱或手机验证码
|
||||
'captcha' => 'require',
|
||||
// 登录点选验证码
|
||||
'captchaId' => 'require',
|
||||
'captchaInfo' => 'require',
|
||||
'name' => 'require',
|
||||
'idNum' => 'require',
|
||||
'certName' => 'require',
|
||||
'certNum' => 'require',
|
||||
'accountNo' => 'require',
|
||||
'city' => 'require',
|
||||
'province' => 'require',
|
||||
'bankBranch' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'register' => ['username', 'password', 'registerType', 'email', 'mobile', 'captcha'],
|
||||
'realName' => ['certName', 'certNum', 'accountNo', 'mobile', 'province', 'city', 'bankBranch'],
|
||||
];
|
||||
|
||||
/**
|
||||
* 登录验证场景
|
||||
*/
|
||||
public function sceneLogin(): User
|
||||
{
|
||||
$fields = ['username', 'password'];
|
||||
|
||||
// 根据系统配置的登录验证码开关调整验证场景的字段
|
||||
$userLoginCaptchaSwitch = Config::get('buildadmin.user_login_captcha');
|
||||
if ($userLoginCaptchaSwitch) {
|
||||
$fields[] = 'captchaId';
|
||||
$fields[] = 'captchaInfo';
|
||||
}
|
||||
|
||||
return $this->only($fields)->remove('username', ['regex', 'unique']);
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->field = [
|
||||
'username' => __('Username'),
|
||||
'email' => __('Email'),
|
||||
'mobile' => __('Mobile'),
|
||||
'password' => __('Password'),
|
||||
'captcha' => __('captcha'),
|
||||
'captchaId' => __('captchaId'),
|
||||
'captchaInfo' => __('captcha'),
|
||||
'registerType' => __('Register type'),
|
||||
];
|
||||
$this->message = array_merge($this->message, [
|
||||
'username.regex' => __('Please input correct username'),
|
||||
'password.regex' => __('Please input correct password')
|
||||
]);
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
27
app/api/validate/WuyouValidate.php
Normal file
27
app/api/validate/WuyouValidate.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class WuyouValidate extends Validate
|
||||
{
|
||||
protected $failException = true;
|
||||
|
||||
protected $rule = [
|
||||
'payType' => 'require',
|
||||
'orderId' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'payOrder' => ['payType', 'orderId']
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user