add
This commit is contained in:
255
app/czg/app/controller/AccountController.php
Normal file
255
app/czg/app/controller/AccountController.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use ba\Date;
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use ba\Random;
|
||||
use app\common\model\User;
|
||||
use think\facade\Validate;
|
||||
use app\common\facade\Token;
|
||||
use app\common\model\UserScoreLog;
|
||||
use app\common\model\UserMoneyLog;
|
||||
use app\common\controller\Frontend;
|
||||
use app\api\validate\Account as AccountValidate;
|
||||
|
||||
class AccountController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['retrievePassword'];
|
||||
|
||||
protected array $noNeedPermission = ['verification', 'changeBind'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function overview(): void
|
||||
{
|
||||
$sevenDays = Date::unixTime('day', -6);
|
||||
$score = $money = $days = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$days[$i] = date("Y-m-d", $sevenDays + ($i * 86400));
|
||||
$tempToday0 = strtotime($days[$i]);
|
||||
$tempToday24 = strtotime('+1 day', $tempToday0) - 1;
|
||||
$score[$i] = UserScoreLog::where('user_id', $this->auth->id)
|
||||
->where('create_time', 'BETWEEN', $tempToday0 . ',' . $tempToday24)
|
||||
->sum('score');
|
||||
|
||||
$userMoneyTemp = UserMoneyLog::where('user_id', $this->auth->id)
|
||||
->where('create_time', 'BETWEEN', $tempToday0 . ',' . $tempToday24)
|
||||
->sum('money');
|
||||
$money[$i] = bcdiv($userMoneyTemp, 100, 2);
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'days' => $days,
|
||||
'score' => $score,
|
||||
'money' => $money,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员资料
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function profile(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->only(['id', 'avatar', 'username', 'nickname', 'gender', 'birthday', 'motto']);
|
||||
if (!isset($data['birthday'])) $data['birthday'] = null;
|
||||
|
||||
try {
|
||||
$validate = new AccountValidate();
|
||||
$validate->scene('edit')->check($data);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$model = $this->auth->getUser();
|
||||
$model->startTrans();
|
||||
try {
|
||||
$model->save($data);
|
||||
$model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success(__('Data updated successfully~'));
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'accountVerificationType' => get_account_verification_type()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过手机号或邮箱验证账户
|
||||
* 此处检查的验证码是通过 api/Ems或api/Sms发送的
|
||||
* 验证成功后,向前端返回一个 email-pass Token或着 mobile-pass Token
|
||||
* 在 changBind 方法中,通过 pass Token来确定用户已经通过了账户验证(用户未绑定邮箱/手机时通过账户密码验证)
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function verification(): void
|
||||
{
|
||||
$captcha = new Captcha();
|
||||
$params = $this->request->only(['type', 'captcha']);
|
||||
if ($captcha->check($params['captcha'], ($params['type'] == 'email' ? $this->auth->email : $this->auth->mobile) . "user_{$params['type']}_verify")) {
|
||||
$uuid = Random::uuid();
|
||||
Token::set($uuid, $params['type'] . '-pass', $this->auth->id, 600);
|
||||
$this->success('', [
|
||||
'type' => $params['type'],
|
||||
'accountVerificationToken' => $uuid,
|
||||
]);
|
||||
}
|
||||
$this->error(__('Please enter the correct verification code'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改绑定信息(手机号、邮箱)
|
||||
* 通过 pass Token来确定用户已经通过了账户验证,也就是以上的 verification 方法,同时用户未绑定邮箱/手机时通过账户密码验证
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function changeBind(): void
|
||||
{
|
||||
$captcha = new Captcha();
|
||||
$params = $this->request->only(['type', 'captcha', 'email', 'mobile', 'accountVerificationToken', 'password']);
|
||||
$user = $this->auth->getUser();
|
||||
|
||||
if ($user[$params['type']]) {
|
||||
if (!Token::check($params['accountVerificationToken'], $params['type'] . '-pass', $user->id)) {
|
||||
$this->error(__('You need to verify your account before modifying the binding information'));
|
||||
}
|
||||
} elseif (!isset($params['password']) || !verify_password($params['password'], $user->password, ['salt' => $user->salt])) {
|
||||
$this->error(__('Password error'));
|
||||
}
|
||||
|
||||
// 检查验证码
|
||||
if ($captcha->check($params['captcha'], $params[$params['type']] . "user_change_{$params['type']}")) {
|
||||
if ($params['type'] == 'email') {
|
||||
$validate = Validate::rule(['email' => 'require|email|unique:user'])->message([
|
||||
'email.require' => 'email format error',
|
||||
'email.email' => 'email format error',
|
||||
'email.unique' => 'email is occupied',
|
||||
]);
|
||||
if (!$validate->check(['email' => $params['email']])) {
|
||||
$this->error(__($validate->getError()));
|
||||
}
|
||||
$user->email = $params['email'];
|
||||
} elseif ($params['type'] == 'mobile') {
|
||||
$validate = Validate::rule(['mobile' => 'require|mobile|unique:user'])->message([
|
||||
'mobile.require' => 'mobile format error',
|
||||
'mobile.mobile' => 'mobile format error',
|
||||
'mobile.unique' => 'mobile is occupied',
|
||||
]);
|
||||
if (!$validate->check(['mobile' => $params['mobile']])) {
|
||||
$this->error(__($validate->getError()));
|
||||
}
|
||||
$user->mobile = $params['mobile'];
|
||||
}
|
||||
Token::delete($params['accountVerificationToken']);
|
||||
$user->save();
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Please enter the correct verification code'));
|
||||
}
|
||||
|
||||
public function changePassword(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$model = $this->auth->getUser();
|
||||
$params = $this->request->only(['oldPassword', 'newPassword']);
|
||||
|
||||
if (!verify_password($params['oldPassword'], $model->password, ['salt' => $model->salt])) {
|
||||
$this->error(__('Old password error'));
|
||||
}
|
||||
|
||||
$model->startTrans();
|
||||
try {
|
||||
$validate = new AccountValidate();
|
||||
$validate->scene('changePassword')->check(['password' => $params['newPassword']]);
|
||||
$model->resetPassword($this->auth->id, $params['newPassword']);
|
||||
$model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->auth->logout();
|
||||
$this->success(__('Password has been changed, please login again~'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分日志
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function integral(): void
|
||||
{
|
||||
$limit = $this->request->request('limit');
|
||||
$integralModel = new UserScoreLog();
|
||||
$res = $integralModel->where('user_id', $this->auth->id)
|
||||
->order('create_time desc')
|
||||
->paginate($limit);
|
||||
|
||||
$this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额日志
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function balance(): void
|
||||
{
|
||||
$limit = $this->request->request('limit');
|
||||
$moneyModel = new UserMoneyLog();
|
||||
$res = $moneyModel->where('user_id', $this->auth->id)
|
||||
->order('create_time desc')
|
||||
->paginate($limit);
|
||||
|
||||
$this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 找回密码
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function retrievePassword(): void
|
||||
{
|
||||
$params = $this->request->only(['type', 'account', 'captcha', 'password']);
|
||||
try {
|
||||
$validate = new AccountValidate();
|
||||
$validate->scene('retrievePassword')->check($params);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
if ($params['type'] == 'email') {
|
||||
$user = User::where('email', $params['account'])->find();
|
||||
} else {
|
||||
$user = User::where('mobile', $params['account'])->find();
|
||||
}
|
||||
if (!$user) {
|
||||
$this->error(__('Account does not exist~'));
|
||||
}
|
||||
|
||||
$captchaObj = new Captcha();
|
||||
if (!$captchaObj->check($params['captcha'], $params['account'] . 'user_retrieve_pwd')) {
|
||||
$this->error(__('Please enter the correct verification code'));
|
||||
}
|
||||
|
||||
if ($user->resetPassword($user->id, $params['password'])) {
|
||||
$this->success(__('Password has been changed~'));
|
||||
} else {
|
||||
$this->error(__('Failed to modify password, please try again later~'));
|
||||
}
|
||||
}
|
||||
}
|
||||
30
app/czg/app/controller/AdController.php
Normal file
30
app/czg/app/controller/AdController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
use app\utils\RedisUtils;
|
||||
use think\facade\Db;
|
||||
|
||||
class AdController extends Frontend
|
||||
{
|
||||
|
||||
|
||||
|
||||
public function state()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$info = Db::name('uni_ad_callback_record')->where([
|
||||
'user_id' => $this->getUserId(),
|
||||
'extra' => $params['extraKey']
|
||||
])->find();
|
||||
if (!$info && RedisUtils::isCanCash($this->getUserId()) && str_contains($params['extraKey'], 'cash')) {
|
||||
RedisUtils::setCanCashFlag($this->getUserId(), -1);
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
70
app/czg/app/controller/AliossController.php
Normal file
70
app/czg/app/controller/AliossController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
use ba\Random;
|
||||
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use think\facade\Db;
|
||||
use support\Log;
|
||||
|
||||
class AliossController extends Frontend
|
||||
{
|
||||
|
||||
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function upload()
|
||||
{
|
||||
$file = request()->file('file');
|
||||
if(empty($file)) {
|
||||
$this->error('参数不能为空');
|
||||
}
|
||||
$commoninfo = Db::connect(config('database.search_library'));
|
||||
$endpoint = $commoninfo->name('common_info')->where(['type' => 68])->find()['value'];
|
||||
$accessKeyId = $commoninfo->name('common_info')->where(['type' => 69])->find()['value'];
|
||||
$secretAccessKey = $commoninfo->name('common_info')->where(['type' => 70])->find()['value'];
|
||||
$bucket = $commoninfo->name('common_info')->where(['type' => 71])->find()['value'];
|
||||
$befor_url = $commoninfo->name('common_info')->where(['type' => 72])->find()['value'];
|
||||
|
||||
putenv('OSS_ACCESS_KEY_ID=' . $accessKeyId);
|
||||
putenv('OSS_ACCESS_KEY_SECRET='. $secretAccessKey);
|
||||
$provider = new EnvironmentVariableCredentialsProvider();
|
||||
|
||||
$object = date('Ymd') . '/' . uniqid() . '.' .$file->getOriginalExtension();
|
||||
try{
|
||||
$config = array(
|
||||
"provider" => $provider,
|
||||
"endpoint" => $endpoint,
|
||||
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V1,
|
||||
);
|
||||
$ossClient = new OssClient($config);
|
||||
// 以二进制模式读取文件内容
|
||||
$handle = fopen($file->getRealPath(), 'rb');
|
||||
$content = stream_get_contents($handle);
|
||||
fclose($handle);
|
||||
|
||||
// 上传二进制内容,明确指定Content-Type
|
||||
$options = [
|
||||
OssClient::OSS_CONTENT_LENGTH => strlen($content),
|
||||
OssClient::OSS_CONTENT_TYPE => $file->getMime(),
|
||||
// 禁用字符编码转换
|
||||
'Content-Encoding' => 'binary',
|
||||
];
|
||||
$res = $ossClient->putObject($bucket, $object, $content, $options);
|
||||
Log::write('上传文件结果' . json_encode($res));
|
||||
if(!empty($res['info'])) {
|
||||
return $this->ApiDataReturn(['data' => $befor_url . '/' . $object, 'msg' => 'success', 'code' => 0]);
|
||||
}else {
|
||||
$this->error('上传失败');
|
||||
}
|
||||
} catch(OssException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
22
app/czg/app/controller/AnnouncementController.php
Normal file
22
app/czg/app/controller/AnnouncementController.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
use app\czg\app\model\TbUser;
|
||||
|
||||
class AnnouncementController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
// 忘记密码
|
||||
public function index()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(\app\czg\app\model\Announcement::list($get['type']));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
31
app/czg/app/controller/BannerController.php
Normal file
31
app/czg/app/controller/BannerController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
|
||||
use app\czg\app\model\CommonInfo;
|
||||
use app\czg\app\model\Orders;
|
||||
use app\common\controller\Frontend;
|
||||
|
||||
class BannerController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['selectBannerList', 'test'];
|
||||
|
||||
// 查询所有banner图
|
||||
public function selectBannerList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['classify'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$banner = \app\api\model\Banner::where(['classify' => $get['classify'], 'state' => 1])->order('sort', 'desc')->select()->toArray();
|
||||
$this->success('ok', convertToCamelCase($banner));
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$qdAward = (new CommonInfo())->getByCode(915)['value'];
|
||||
$this->successWithData(bccomp($qdAward, "0") > 0);
|
||||
}
|
||||
|
||||
}
|
||||
94
app/czg/app/controller/CashController.php
Normal file
94
app/czg/app/controller/CashController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\WithDraw;
|
||||
use app\common\controller\Frontend;
|
||||
use app\exception\SysException;
|
||||
use app\utils\RedisUtils;
|
||||
use support\think\Cache;
|
||||
use app\api\model\Cash as CashModel;
|
||||
|
||||
class CashController extends Frontend
|
||||
{
|
||||
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
public function canCash()
|
||||
{
|
||||
$user_id = $this->auth->getUser()['user_id'];
|
||||
$comm = CommonInfo::where(['type' => 928])->find()->value;
|
||||
if($comm == 0) {
|
||||
$this->success('ok', true);
|
||||
}
|
||||
$redis_can_cash = Cache::get('cash:canCash:' . $user_id);
|
||||
if($redis_can_cash) {
|
||||
$this->success('ok', true);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkCanCash($userId)
|
||||
{
|
||||
$canCash = RedisUtils::isCanCash($userId);
|
||||
if (!$canCash) {
|
||||
$val = (new CommonInfo())->getByCode(928)['value'];
|
||||
if ($val == '1') {
|
||||
throw new SysException("您未观看激励广告,请先观看");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现接口
|
||||
*/
|
||||
public function withdraw()
|
||||
{
|
||||
$amount = $this->request->get('amount');
|
||||
$isAlipay = $this->request->get('isAlipay/d');
|
||||
$userId = $this->getUserId();
|
||||
self::checkCanCash($userId);
|
||||
$info = (new CommonInfo())->getByCode(930);
|
||||
if (!$info) {
|
||||
$this->error("当前时间段未开启提现功能");
|
||||
}
|
||||
$timeScope = explode('~', $info['value']); // 如 08:30~17:30
|
||||
$today = date('Y-m-d');
|
||||
|
||||
// 拼接今日的开始和结束时间
|
||||
$beginTime = strtotime($today . ' ' . $timeScope[0]);
|
||||
$endTime = strtotime($today . ' ' . $timeScope[1]);
|
||||
$now = time();
|
||||
|
||||
// 判断是否在时间范围内
|
||||
if ($now < $beginTime || $now > $endTime) {
|
||||
throw new SysException("提现时间为每天" . $info['value']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
debounce("withdraw:".$userId, 30);
|
||||
runWithLock("lock:withdraw:{$userId}", 300, function () use ($userId, $amount, $isAlipay) {
|
||||
WithDraw::goWithDraw($userId, $amount, '', false, $isAlipay == 1);
|
||||
});
|
||||
|
||||
$this->success('提现成功,将在三个工作日内到账,请耐心等待!');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询提现记录列表
|
||||
*/
|
||||
public function selectPayDetails()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$cashOut[ 'user_id'] = $this->auth->user_id;
|
||||
return $this->ApiDataReturn(CashModel::selectPayDetails($cashOut, $get, true, $this->auth->getUser()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
110
app/czg/app/controller/CommonController.php
Normal file
110
app/czg/app/controller/CommonController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use think\Response;
|
||||
use ba\ClickCaptcha;
|
||||
use think\facade\Config;
|
||||
use app\common\facade\Token;
|
||||
use app\common\library\Auth as UserAuth;
|
||||
|
||||
class CommonController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['getAppUseKv', 'getAppUseKv'];
|
||||
/**
|
||||
* 图形验证码
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function captcha(): Response
|
||||
{
|
||||
$captchaId = $this->request->request('id');
|
||||
$config = array(
|
||||
'codeSet' => '123456789', // 验证码字符集合
|
||||
'fontSize' => 22, // 验证码字体大小(px)
|
||||
'useCurve' => false, // 是否画混淆曲线
|
||||
'useNoise' => true, // 是否添加杂点
|
||||
'length' => 4, // 验证码位数
|
||||
'bg' => array(255, 255, 255), // 背景颜色
|
||||
);
|
||||
|
||||
$captcha = new Captcha($config);
|
||||
return $captcha->entry($captchaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点选验证码
|
||||
*/
|
||||
public function clickCaptcha(): void
|
||||
{
|
||||
$id = $this->request->request('id/s');
|
||||
$captcha = new ClickCaptcha();
|
||||
$this->success('', $captcha->creat($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 点选验证码检查
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function checkClickCaptcha(): void
|
||||
{
|
||||
$id = $this->request->post('id/s');
|
||||
$info = $this->request->post('info/s');
|
||||
$unset = $this->request->post('unset/b', false);
|
||||
$captcha = new ClickCaptcha();
|
||||
if ($captcha->check($id, $info, $unset)) $this->success();
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新 token
|
||||
* 无需主动删除原 token,由 token 驱动自行实现过期 token 清理,可避免并发场景下无法获取到过期 token 数据
|
||||
*/
|
||||
public function refreshToken(): void
|
||||
{
|
||||
$refreshToken = $this->request->post('refreshToken');
|
||||
$refreshToken = Token::get($refreshToken);
|
||||
|
||||
if (!$refreshToken || $refreshToken['expire_time'] < time()) {
|
||||
$this->error(__('Login expired, please login again.'));
|
||||
}
|
||||
|
||||
$newToken = Random::uuid();
|
||||
|
||||
// 管理员token刷新
|
||||
if ($refreshToken['type'] == AdminAuth::TOKEN_TYPE . '-refresh') {
|
||||
Token::set($newToken, AdminAuth::TOKEN_TYPE, $refreshToken['user_id'], (int)Config::get('buildadmin.admin_token_keep_time'));
|
||||
}
|
||||
|
||||
// 会员token刷新
|
||||
if ($refreshToken['type'] == UserAuth::TOKEN_TYPE . '-refresh') {
|
||||
Token::set($newToken, UserAuth::TOKEN_TYPE, $refreshToken['user_id'], (int)Config::get('buildadmin.user_token_keep_time'));
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'type' => $refreshToken['type'],
|
||||
'token' => $newToken
|
||||
]);
|
||||
}
|
||||
|
||||
public function getAppUseKv()
|
||||
{
|
||||
return $this->resultApi(\app\common\model\Common::getAppUseKv());
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
$type = $this->request->route('num');
|
||||
$data = convertToCamelCase(Db::connect(config('think-orm.search_library'))->name('common_info')->where('type', $type)->find());
|
||||
$this->success('ok', $data, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
153
app/czg/app/controller/CourseCollectController.php
Normal file
153
app/czg/app/controller/CourseCollectController.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\validate\CourseCollectValidate;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use think\facade\Db;
|
||||
use app\common\controller\Frontend;
|
||||
|
||||
class CourseCollectController extends Frontend
|
||||
{
|
||||
|
||||
protected array $noNeedPermission = [];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
private function insertOrder($params)
|
||||
{
|
||||
$userId = $this->getUserId();
|
||||
$model = DatabaseRoute::getDb('course_collect', $userId, true);
|
||||
$info = $model->where([
|
||||
'user_id' => $userId,
|
||||
'classify' => 3,
|
||||
'course_id' => $params['courseId'],
|
||||
])->order('create_time', 'desc')->limit(1)->find();
|
||||
if ($info) {
|
||||
// 更新记录
|
||||
$model
|
||||
->where([
|
||||
'course_collect_id' => $info['course_collect_id'],
|
||||
'user_id' => $userId,
|
||||
])
|
||||
->update([
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
'course_details_id' => $params['courseDetailsId'],
|
||||
]);
|
||||
} else {
|
||||
// 插入新记录
|
||||
$model->insert([
|
||||
'user_id' => $userId,
|
||||
'course_id' => $params['courseId'],
|
||||
'course_details_id' => $params['courseDetailsId'],
|
||||
'classify' => 3,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function upGoodNum($params, $isAdd)
|
||||
{
|
||||
$courseDetails = $course_d = DatabaseRoute::getDb('course_details', ['course_id' => $params['courseId']]);
|
||||
$courseDetails = $courseDetails->where([
|
||||
'course_id' => $params['courseId'],
|
||||
'course_details_id' => $params['courseDetailsId'],
|
||||
])->find();
|
||||
|
||||
if (!$courseDetails) {
|
||||
return; // 数据不存在,不处理
|
||||
}
|
||||
|
||||
$goodNum = isset($courseDetails['good_num']) ? (int)$courseDetails['good_num'] : 0;
|
||||
|
||||
if ($isAdd) {
|
||||
$goodNum += 1; // 点赞
|
||||
} else {
|
||||
$goodNum -= 1; // 取消点赞
|
||||
|
||||
}
|
||||
|
||||
if ($goodNum < 0) {
|
||||
return; // 防止出现负数
|
||||
}
|
||||
Db::connect(DatabaseRoute::getConnection('course_details', ['course_id' => $params['courseId']], true))->name('course_details')->where([
|
||||
'course_id' => $params['courseId'],
|
||||
'course_details_id' => $params['courseDetailsId'],
|
||||
])->update(['good_num' => $goodNum]);
|
||||
}
|
||||
|
||||
public function insertCourseCollect()
|
||||
{
|
||||
$userId = $this->getUserId();
|
||||
$data = $this->request->only(['classify', 'courseDetailsId', 'courseId', 'type']);
|
||||
// classify 1收藏 2点赞 3订单
|
||||
(new CourseCollectValidate())->scene('insertCourseCollect')->check($data);
|
||||
if ($data['classify'] === 3) {
|
||||
$this->insertOrder($data);
|
||||
} else {
|
||||
$where = [
|
||||
'user_id' => $userId,
|
||||
'classify' => $data['classify'],
|
||||
'course_id' => $data['courseId'],
|
||||
];
|
||||
|
||||
if ($data['classify'] === 2) {
|
||||
if(empty($data['courseDetailsId'])) {
|
||||
$this->error('courseDetailsId不能为空', [], -1);
|
||||
}
|
||||
$where[] = ['course_details_id', 'eq', $data['courseDetailsId']];
|
||||
}
|
||||
$model = DatabaseRoute::getDb('course_collect', $this->getUserId());
|
||||
$info = $model->where($where)->find();
|
||||
if ($data['type'] == 1) {
|
||||
if ($info == null) {
|
||||
$model = DatabaseRoute::getDb('course_collect', $this->getUserId(), true);
|
||||
$model->insert([
|
||||
'user_id' => $this->getUserId(),
|
||||
'create_time' => getNormalDate(),
|
||||
'update_time' => getNormalDate(),
|
||||
'course_id' => $data['courseId'],
|
||||
'course_details_id' => !empty($data['courseDetailsId'])?$data['courseDetailsId']:null,
|
||||
'classify' => $data['classify'],
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
if ($info) {
|
||||
DatabaseRoute::getDb('course_collect', $this->getUserId(), true)->where([
|
||||
'course_collect_id' => $info['course_collect_id']
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['classify'] == 2) {
|
||||
$this->upGoodNum($data, $data['type']);
|
||||
}
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
// app查询收藏短剧信息
|
||||
public function selectByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(\app\api\model\Course::selectByUserId($get, $this->auth->user_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 我的追剧和我的喜欢数量
|
||||
public function collectVideoSummary()
|
||||
{
|
||||
return $this->ApiDataReturn(\app\api\model\Course::collectVideoSummary($this->auth->user_id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +1,51 @@
|
||||
<?php
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\czg\app\model\Course;
|
||||
use app\model\Test;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
use app\common\controller\Frontend;
|
||||
use app\api\model\Course;
|
||||
|
||||
class CourseController extends BaseController
|
||||
class CourseController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['selectCourse', 'selectCourseDetailsList', 'viewCourse'];
|
||||
|
||||
public function selectCourse()
|
||||
{
|
||||
$post = $this->request->get();
|
||||
$res = Course::selectCourse($post);
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
|
||||
// 推荐视频
|
||||
public function selectCourseDetailsList()
|
||||
{
|
||||
if($this->auth->isLogin()) {
|
||||
$user_id = $this->auth->user_id;
|
||||
}else {
|
||||
$user_id = 0;
|
||||
}
|
||||
$post = $this->request->get();
|
||||
$res = Course::selectCourseDetailsList($post, $user_id);
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
// 获取抽奖红包提示
|
||||
public function getRedEnvelopeTips()
|
||||
{
|
||||
$user_id = $this->auth->user_id;
|
||||
$res = Course::getRedEnvelopeTips($user_id);
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
// 查看视频
|
||||
public function viewCourse()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$res = Course::viewCourse($get);
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
// 根据id查询短剧集数列表
|
||||
public function courseSets()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
|
||||
316
app/czg/app/controller/DiscSpinningController.php
Normal file
316
app/czg/app/controller/DiscSpinningController.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\DiscSpinningRecord;
|
||||
use app\api\model\Orders;
|
||||
use app\api\model\TbUser;
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\controller\Frontend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\CzgException;
|
||||
use app\exception\SysException;
|
||||
use app\queue\DiscReceiveQueue;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
use support\Log;
|
||||
use think\facade\Queue;
|
||||
|
||||
class DiscSpinningController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['draw'];
|
||||
|
||||
protected array $noNeedPermission = [];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖
|
||||
*/
|
||||
public function draw()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userInfo = $this->auth->getUser();
|
||||
Log::info('抽奖'. json_encode($userInfo));
|
||||
|
||||
debounce("user:disc-spinning:draw:".$userInfo['user_id'], 1);
|
||||
$userId = $userInfo['user_id'];
|
||||
$resp = [];
|
||||
runWithLock("user:disc-spinning:limit:user:lock:".$this->getUserId(), 60, function () use ($params, $userId, &$resp, $userInfo) {
|
||||
DatabaseRoute::transactionXa(function () use ($params, $userId, &$resp, $userInfo) {
|
||||
// 查询抽奖次数
|
||||
$count = DiscSpinningRecord::countDraw($userId);
|
||||
// 免费两次之后校验实名
|
||||
if ($count == 2 && !TbUser::checkEnable($userInfo)) {
|
||||
$this->error('请实名认证后继续抽奖');
|
||||
}
|
||||
|
||||
Log::info("用户id: $userId, 抽奖次数: $count");
|
||||
// 订单抽奖
|
||||
if (!isset($params['source']) || $params['source'] == 1) {
|
||||
|
||||
$drawCount = (new CommonInfo())->getByCodeToInt(901);
|
||||
if ($count >= $drawCount) {
|
||||
$this->error('当日可抽奖次数已超限');
|
||||
}
|
||||
|
||||
// 校验订单笔数
|
||||
$orders = Orders::selectOrdersByDay($userId);
|
||||
if (!$orders) {
|
||||
throw new SysException("无可用抽奖机会");
|
||||
}
|
||||
$params['sourceId'] = $orders['orders_id'];
|
||||
}else{
|
||||
$this->error("八嘎");
|
||||
}
|
||||
|
||||
if (!isset($params['sourceId'])) {
|
||||
throw new CzgException("异常请求");
|
||||
}
|
||||
|
||||
$draws = self::draws($count + 1, $orders['pay_money'], $params['sourceId'], $userId, $params['source']);
|
||||
$resp = $draws;
|
||||
// $this->receive($draws);
|
||||
});
|
||||
});
|
||||
pushQueue(DiscReceiveQueue::class, [
|
||||
'draws' => $resp
|
||||
]);
|
||||
$resp = convertToCamelCase($resp);
|
||||
$resp['img'] = $resp['imgUrl'];
|
||||
$this->successWithData($resp);
|
||||
}
|
||||
|
||||
public static function draws($drawCount, $orderAmount, $sourceId, $userId, $source)
|
||||
{
|
||||
$result = [
|
||||
'name' => '谢谢惠顾',
|
||||
'source_id' => $sourceId,
|
||||
'user_id' => $userId,
|
||||
'img_url' => '',
|
||||
'type' => 1,
|
||||
'number' => 1,
|
||||
'draw_day' => date('Y-m-d'),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'source' => $source == 1 ? 'order' : 'task'
|
||||
];
|
||||
|
||||
// 查询奖项
|
||||
$prizes = Db::name('disc_spinning')->where([
|
||||
'disc_type' => $source
|
||||
])->order('number', 'asc')->select()->toArray();
|
||||
|
||||
if (empty($prizes)) {
|
||||
DatabaseRoute::getDb('disc_spinning_record', $userId, true, true)->insert($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 获取最大概率
|
||||
$maxNumber = array_reduce($prizes, function ($carry, $prize) {
|
||||
return bccomp($prize['number'], $carry) > 0 ? $prize['number'] : $carry;
|
||||
}, '0');
|
||||
|
||||
// 最大值为 0,直接谢谢惠顾
|
||||
if (bccomp($maxNumber, '0') === 0) {
|
||||
$record = $result;
|
||||
DatabaseRoute::getDb('disc_spinning_record', $userId, true, true)->insert($record);
|
||||
return $record;
|
||||
}
|
||||
|
||||
// 获取随机数(整数)
|
||||
if ($maxNumber > 1) {
|
||||
$randomNum = rand(0, (int)$maxNumber - 1);
|
||||
} else {
|
||||
$randomNum = rand(0, (int)$maxNumber); // 或者其它默认值
|
||||
}
|
||||
|
||||
// 查询奖励金额列表(模拟 redis 逻辑)
|
||||
$amounts = Db::name('disc_spinning_amount')->where([
|
||||
'status' => 1,
|
||||
'type' => $source
|
||||
])->order('max_amount', 'asc')->select()->toArray();
|
||||
|
||||
// 按 num 分组
|
||||
$amountMaps = [];
|
||||
foreach ($amounts as $item) {
|
||||
$num = isset($item['num']) ? intval($item['num']) : 0;
|
||||
$amountMaps[$num][] = $item;
|
||||
}
|
||||
|
||||
// 按照 drawCount 向下查找匹配组
|
||||
$filteredAmounts = [];
|
||||
if (!empty($amountMaps)) {
|
||||
for ($i = $drawCount; $i >= 0; $i--) {
|
||||
if (isset($amountMaps["{$i}"])) {
|
||||
$filteredAmounts = $amountMaps["{$i}"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 抽奖逻辑
|
||||
$finalPrize = null;
|
||||
foreach ($prizes as $prize) {
|
||||
if (bccomp((string)$randomNum, $prize['number']) < 0) {
|
||||
if ($prize['type'] == 2) {
|
||||
// 金额类奖品
|
||||
$maxAmount = (new CommonInfo())->getByCodeToInt(900); // 最大金额限制
|
||||
$baseRandom = mt_rand() / mt_getrandmax();
|
||||
$baseRandom = bccomp($baseRandom, "1", 2) ? 0.99 : $baseRandom;
|
||||
$baseAmount = 0;
|
||||
$resultAmount = 0;
|
||||
|
||||
foreach ($filteredAmounts as $amount) {
|
||||
if ($baseRandom < $amount['random']) {
|
||||
$resultAmount = $baseAmount + (mt_rand() / mt_getrandmax()) * $amount['max_amount'];
|
||||
break;
|
||||
}
|
||||
$baseAmount = $amount['max_amount'];
|
||||
}
|
||||
|
||||
if ($resultAmount < 0.01) {
|
||||
$resultAmount = 0.01;
|
||||
}
|
||||
$randomFactor = mt_rand(50, 90) / 100; // 生成 0.5 到 0.9 的随机数
|
||||
$resultAmount = $resultAmount * $randomFactor;
|
||||
$resultAmount += $orderAmount;
|
||||
if ($resultAmount > $maxAmount) {
|
||||
$resultAmount = $maxAmount;
|
||||
}
|
||||
|
||||
|
||||
$finalPrize = [
|
||||
'name' => $prize['name'],
|
||||
'type' => 2,
|
||||
'number' => round($resultAmount, 2),
|
||||
'id' => $prize['id'],
|
||||
'url' => $prize['url'] ?? ''
|
||||
];
|
||||
break;
|
||||
} else {
|
||||
// 非金额奖品
|
||||
if ($source != 1) {
|
||||
$finalPrize = [
|
||||
'name' => $prize['name'],
|
||||
'type' => $prize['type'],
|
||||
'number' => 1,
|
||||
'id' => $prize['id'],
|
||||
'url' => $prize['url'] ?? ''
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$finalPrize) {
|
||||
// 没抽中任何奖品,默认“谢谢惠顾”
|
||||
$finalPrize = [
|
||||
'name' => '谢谢惠顾',
|
||||
'type' => 1,
|
||||
'number' => 1,
|
||||
'id' => null,
|
||||
'url' => ''
|
||||
];
|
||||
}
|
||||
|
||||
// 构建记录
|
||||
$record = [
|
||||
'id' => Random::generateRandomPrefixedId(19),
|
||||
'name' => $finalPrize['name'],
|
||||
'source_id' => $sourceId,
|
||||
'user_id' => $userId,
|
||||
'img_url' => $finalPrize['url'] ?? '',
|
||||
'type' => $finalPrize['type'],
|
||||
'number' => $finalPrize['number'],
|
||||
'draw_day' => date('Y-m-d'),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'source' => $source == 1 ? 'order' : 'task'
|
||||
];
|
||||
|
||||
// 保存
|
||||
DatabaseRoute::getDb('disc_spinning_record', $userId, true)->insert($record);
|
||||
|
||||
$record['discSpinningId'] = $finalPrize['id'];
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取大转盘抽奖次数
|
||||
*/
|
||||
public function drawCount()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['source'])) {
|
||||
$soure = 1;
|
||||
}else {
|
||||
$soure = $get['source'];
|
||||
}
|
||||
$user = $this->auth->getUser();
|
||||
$drawCount = (int)CommonInfo::where(['type' => 901])->find()->value;
|
||||
$data['sum'] = $drawCount;
|
||||
if(!empty($soure) && $soure != 1) {
|
||||
if($soure == 2) {
|
||||
$sourceType = 'taskW';
|
||||
}else {
|
||||
$sourceType = 'taskM';
|
||||
}
|
||||
$spinningCount = DatabaseRoute::getDb('disc_spinning_record', $user['user_id'])->where(['source' => $sourceType])->count();
|
||||
if($spinningCount != null && $spinningCount > 0) {
|
||||
$data['count'] = 0;
|
||||
}else {
|
||||
$i = DiscSpinningRecord::countTaskDisc($user['user_id'], $soure);
|
||||
$data['count'] = $i>0?1:0;
|
||||
}
|
||||
}else {
|
||||
$i = DatabaseRoute::getDb('disc_spinning_record', $user['user_id'])->where(['source' => 'order'])->where([
|
||||
'draw_day' => ['between', date('Y-m-d 00:00:00'), date('Y-m-d 11:59:59')]
|
||||
])->count();
|
||||
if($drawCount - $i > 0) {
|
||||
$data['count'] = DiscSpinningRecord::selectOrdersCountStatisticsByDay($user['user_id'], $drawCount - $i);
|
||||
}else {
|
||||
$data['count'] = 0;
|
||||
}
|
||||
}
|
||||
$this->success('ok', $data);
|
||||
}
|
||||
|
||||
|
||||
// 查询大转盘
|
||||
public function selectDiscSpinning()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['source'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$page = 1;
|
||||
$limit = 20;
|
||||
$db = Db::connect(config('database.search_library'));
|
||||
$list = $db->name('disc_spinning')
|
||||
->where(['disc_type' => $get['source']]);
|
||||
$count = $list->count();
|
||||
$list = $list->order('disc_type', 'asc')
|
||||
->order('odds', 'asc')
|
||||
->limit(page($page, $limit), $limit)
|
||||
->select()->toArray();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['odds'] = null;
|
||||
$v['number'] = null;
|
||||
$v['discType'] = null;
|
||||
$v['img'] = $v['url'];
|
||||
}
|
||||
$this->success('ok', [
|
||||
'currPage' => $page,
|
||||
'pageSize' => $limit,
|
||||
'records' => convertToCamelCase($list),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $limit),
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/czg/app/controller/DiscSpinningRecordController.php
Normal file
41
app/czg/app/controller/DiscSpinningRecordController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\Orders;
|
||||
use app\api\model\TbUser;
|
||||
use app\common\controller\Frontend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\CzgException;
|
||||
use app\queue\DiscReceiveQueue;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class DiscSpinningRecordController extends Frontend
|
||||
{
|
||||
// 查询大转盘抽奖记录
|
||||
public function selectDiscSpinningRecord()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['source']) || empty($get['page']) || empty($get['limit'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$user = $this->auth->getUser();
|
||||
$db = Db::connect(DatabaseRoute::getConnection('disc_spinning_record', ['user_id' => $user['user_id']]));
|
||||
$list = $db->name('disc_spinning_record')
|
||||
->where(['user_id' => $user['user_id']]);
|
||||
$count = $list->count();
|
||||
$list = $list->order('create_time', 'asc')
|
||||
->limit(page($get['page'], $get['limit']), $get['limit'])
|
||||
->select()->toArray();
|
||||
$this->success('ok', [
|
||||
'currPage' => $get['page'],
|
||||
'pageSize' => $get['limit'],
|
||||
'records' => convertToCamelCase($list),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
108
app/czg/app/controller/EmsController.php
Normal file
108
app/czg/app/controller/EmsController.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use ba\ClickCaptcha;
|
||||
use think\facade\Validate;
|
||||
use app\common\model\User;
|
||||
use app\common\library\Email;
|
||||
use app\common\controller\Frontend;
|
||||
use PHPMailer\PHPMailer\Exception as PHPMailerException;
|
||||
|
||||
class EmsController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['send'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
* event 事件:user_register=用户注册,user_change_email=用户修改邮箱,user_retrieve_pwd=用户找回密码,user_email_verify=验证账户
|
||||
* 不同的事件,会自动做各种必要检查,其中 验证账户 要求用户输入当前密码才能发送验证码邮件
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function send(): void
|
||||
{
|
||||
$params = $this->request->post(['email', 'event', 'captchaId', 'captchaInfo']);
|
||||
$mail = new Email();
|
||||
if (!$mail->configured) {
|
||||
$this->error(__('Mail sending service unavailable'));
|
||||
}
|
||||
|
||||
$validate = Validate::rule([
|
||||
'email' => 'require|email',
|
||||
'event' => 'require',
|
||||
'captchaId' => 'require',
|
||||
'captchaInfo' => 'require'
|
||||
])->message([
|
||||
'email' => 'email format error',
|
||||
'event' => 'Parameter error',
|
||||
'captchaId' => 'Captcha error',
|
||||
'captchaInfo' => 'Captcha error'
|
||||
]);
|
||||
if (!$validate->check($params)) {
|
||||
$this->error(__($validate->getError()));
|
||||
}
|
||||
|
||||
// 检查验证码
|
||||
$captchaObj = new Captcha();
|
||||
$clickCaptcha = new ClickCaptcha();
|
||||
if (!$clickCaptcha->check($params['captchaId'], $params['captchaInfo'])) {
|
||||
$this->error(__('Captcha error'));
|
||||
}
|
||||
|
||||
// 检查频繁发送
|
||||
$captcha = $captchaObj->getCaptchaData($params['email'] . $params['event']);
|
||||
if ($captcha && time() - $captcha['create_time'] < 60) {
|
||||
$this->error(__('Frequent email sending'));
|
||||
}
|
||||
|
||||
// 检查邮箱
|
||||
$userInfo = User::where('email', $params['email'])->find();
|
||||
if ($params['event'] == 'user_register' && $userInfo) {
|
||||
$this->error(__('Email has been registered, please log in directly'));
|
||||
} elseif ($params['event'] == 'user_change_email' && $userInfo) {
|
||||
$this->error(__('The email has been occupied'));
|
||||
} elseif (in_array($params['event'], ['user_retrieve_pwd', 'user_email_verify']) && !$userInfo) {
|
||||
$this->error(__('Email not registered'));
|
||||
}
|
||||
|
||||
// 通过邮箱验证账户
|
||||
if ($params['event'] == 'user_email_verify') {
|
||||
if (!$this->auth->isLogin()) {
|
||||
$this->error(__('Please login first'));
|
||||
}
|
||||
if ($this->auth->email != $params['email']) {
|
||||
$this->error(__('Please use the account registration email to send the verification code'));
|
||||
}
|
||||
// 验证账户密码
|
||||
$password = $this->request->post('password');
|
||||
if (!verify_password($password, $this->auth->password, ['salt' => $this->auth->salt])) {
|
||||
$this->error(__('Password error'));
|
||||
}
|
||||
}
|
||||
|
||||
// 生成一个验证码
|
||||
$code = $captchaObj->create($params['email'] . $params['event']);
|
||||
$subject = __($params['event']) . '-' . get_sys_config('site_name');
|
||||
$body = __('Your verification code is: %s', [$code]);
|
||||
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->addAddress($params['email']);
|
||||
$mail->isHTML();
|
||||
$mail->setSubject($subject);
|
||||
$mail->Body = $body;
|
||||
$mail->send();
|
||||
} catch (PHPMailerException) {
|
||||
$this->error($mail->ErrorInfo);
|
||||
}
|
||||
|
||||
$this->success(__('Mail sent successfully~'));
|
||||
}
|
||||
}
|
||||
34
app/czg/app/controller/HelpWordController.php
Normal file
34
app/czg/app/controller/HelpWordController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\HelpClassify;
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\controller\Frontend;
|
||||
use think\facade\Db;
|
||||
|
||||
class HelpWordController extends Frontend
|
||||
{
|
||||
|
||||
// 帮助中心
|
||||
public function selectHelpList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['types'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$word = new HelpClassify;
|
||||
$word->setConnection(Config('think-orm.search_library'));
|
||||
$result = $word
|
||||
->with('helpword')
|
||||
->where('types', $get['types'])->select()->toArray();
|
||||
$result = convertToCamelCase($result);
|
||||
foreach ($result as $k => $v) {
|
||||
$result[$k]['helpWordList'] = convertToCamelCase($v['helpword']);
|
||||
unset($result[$k]['helpword']);
|
||||
}
|
||||
$this->success('ok', $result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
84
app/czg/app/controller/IndexController.php
Normal file
84
app/czg/app/controller/IndexController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use ba\Tree;
|
||||
use Throwable;
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
use app\common\controller\Frontend;
|
||||
use app\common\library\token\TokenExpirationException;
|
||||
|
||||
class IndexController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['index'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 前台和会员中心的初始化请求
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(): void
|
||||
{
|
||||
// $menus = [];
|
||||
// if ($this->auth->isLogin()) {
|
||||
// $rules = [];
|
||||
// $userMenus = $this->auth->getMenus();
|
||||
//
|
||||
// // 首页加载的规则,验权,但过滤掉会员中心菜单
|
||||
// foreach ($userMenus as $item) {
|
||||
// if ($item['type'] == 'menu_dir') {
|
||||
// $menus[] = $item;
|
||||
// } elseif ($item['type'] != 'menu') {
|
||||
// $rules[] = $item;
|
||||
// }
|
||||
// }
|
||||
// $rules = array_values($rules);
|
||||
// } else {
|
||||
// // 若是从前台会员中心内发出的请求,要求必须登录,否则会员中心异常
|
||||
// $requiredLogin = $this->request->get('requiredLogin/b', false);
|
||||
// if ($requiredLogin) {
|
||||
//
|
||||
// // 触发可能的 token 过期异常
|
||||
// try {
|
||||
// $token = get_auth_token(['ba', 'user', 'token']);
|
||||
// $this->auth->init($token);
|
||||
// } catch (TokenExpirationException) {
|
||||
// $this->error(__('Token expiration'), [], 409);
|
||||
// }
|
||||
//
|
||||
// $this->error(__('Please login first'), [
|
||||
// 'type' => $this->auth::NEED_LOGIN
|
||||
// ], $this->auth::LOGIN_RESPONSE_CODE);
|
||||
// }
|
||||
//
|
||||
// $rules = Db::name('user_rule')
|
||||
// ->where('status', 1)
|
||||
// ->where('no_login_valid', 1)
|
||||
// ->where('type', 'in', ['route', 'nav', 'button'])
|
||||
// ->order('weigh', 'desc')
|
||||
// ->select()
|
||||
// ->toArray();
|
||||
// $rules = Tree::instance()->assembleChild($rules);
|
||||
// }
|
||||
//
|
||||
// $this->success('', [
|
||||
// 'site' => [
|
||||
// 'siteName' => get_sys_config('site_name'),
|
||||
// 'version' => get_sys_config('version'),
|
||||
// 'cdnUrl' => full_url(),
|
||||
// 'upload' => keys_to_camel_case(get_upload_config(), ['max_size', 'save_name', 'allowed_suffixes', 'allowed_mime_types']),
|
||||
// 'recordNumber' => get_sys_config('record_number'),
|
||||
// 'cdnUrlParams' => Config::get('buildadmin.cdn_url_params'),
|
||||
// ],
|
||||
// 'openMemberCenter' => Config::get('buildadmin.open_member_center'),
|
||||
// 'userInfo' => $this->auth->getUserInfo(),
|
||||
// 'rules' => $rules,
|
||||
// 'menus' => $menus,
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
29
app/czg/app/controller/InviteController.php
Normal file
29
app/czg/app/controller/InviteController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
|
||||
|
||||
use app\common\controller\Frontend;
|
||||
|
||||
class InviteController extends Frontend
|
||||
{
|
||||
|
||||
// 我的收益
|
||||
public function selectInviteMoney()
|
||||
{
|
||||
$res = \app\api\model\Invite::selectInviteMoney($this->auth->getUser());
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 查看我邀请的人员列表(查看所有邀请列表)
|
||||
public function selectInviteByUserIdLists()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$res = \app\api\model\Invite::selectInviteByUserIdLists($this->auth->getUser(), $get, 'api');
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ use app\common\facade\Token;
|
||||
use app\common\controller\Frontend;
|
||||
use app\api\validate\User as UserValidate;
|
||||
|
||||
class LoginController extends BaseController
|
||||
class LoginControllerController extends BaseController
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
@@ -50,7 +50,7 @@ class LoginController extends BaseController
|
||||
// 发送验证码
|
||||
public function sendMsg()
|
||||
{
|
||||
$get = $this->request->route();
|
||||
$get = $this->request->route->param();
|
||||
return $this->ApiDataReturn(Msg::sendMsg($get['phone'], $get['event']));
|
||||
}
|
||||
|
||||
|
||||
30
app/czg/app/controller/MessageController.php
Normal file
30
app/czg/app/controller/MessageController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\MessageInfo as MessageModel;
|
||||
use app\common\controller\Frontend;
|
||||
|
||||
class MessageController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['selectMessage', 'sendMessage'];
|
||||
|
||||
public function selectMessage()
|
||||
{
|
||||
return $this->ApiDataReturn(MessageModel::getList($this->request->get()));
|
||||
}
|
||||
public function sendMessage()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
return $this->ApiDataReturn(MessageModel::sendMessage($post, $this->auth->user_id));
|
||||
}
|
||||
|
||||
|
||||
public function selectMessageByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$get['user_id'] = $this->getUserId();
|
||||
return $this->ApiDataReturn(MessageModel::getList($get));
|
||||
}
|
||||
|
||||
}
|
||||
23
app/czg/app/controller/MoneyDetailsController.php
Normal file
23
app/czg/app/controller/MoneyDetailsController.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\controller\Frontend;
|
||||
|
||||
class MoneyDetailsController extends Frontend
|
||||
{
|
||||
|
||||
public function selectUserMoney()
|
||||
{
|
||||
return $this->ApiDataReturn(UserMoney::selectUserMoney($this->auth->user_id));
|
||||
}
|
||||
public function queryUserMoneyDetails()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(UserMoney::queryUserMoneyDetails($this->auth->user_id, $get));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -6,8 +6,8 @@ use app\api\model\Orders;
|
||||
use app\api\model\UserMoney;
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\czg\app\model\CommonInfo;
|
||||
use app\czg\app\model\TbUser;
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\TbUser;
|
||||
use app\enums\ErrEnums;
|
||||
use app\exception\SysException;
|
||||
use app\utils\RedisUtils;
|
||||
|
||||
38
app/czg/app/controller/TaskCenterController.php
Normal file
38
app/czg/app/controller/TaskCenterController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\TaskCenterRecord;
|
||||
use app\api\model\UserInfo;
|
||||
use app\api\model\UserSignRecord;
|
||||
use app\common\controller\Frontend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
class TaskCenterController extends Frontend
|
||||
{
|
||||
|
||||
|
||||
public function selectTaskCenter()
|
||||
{
|
||||
$user_id = $this->auth->getUser()['user_id'];
|
||||
return $this->ApiDataReturn(TaskCenterRecord::selectTaskCenter($user_id, $this->auth->getUser()['inviter_user_id']));
|
||||
}
|
||||
|
||||
public function taskReceive()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['id'])) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$id = $get['id'];
|
||||
$userId = $this->auth->getUser()['user_id'];
|
||||
if($id !== null && $id == 19) {
|
||||
TaskCenterRecord::addBlackUser($userId, '任务中心领取');
|
||||
}
|
||||
return $this->ApiDataReturn(TaskCenterRecord::taskReceive($userId, $id, $this->auth->getUser()['inviter_user_id']));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
42
app/czg/app/controller/UniCallBackController.php
Normal file
42
app/czg/app/controller/UniCallBackController.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\UniAdCallbackRecord;
|
||||
use app\api\model\WithDraw;
|
||||
use app\common\controller\Frontend;
|
||||
use app\exception\SysException;
|
||||
use app\utils\RedisUtils;
|
||||
use think\cache\driver\Redis;
|
||||
use think\facade\Db;
|
||||
use think\facade\Cache;
|
||||
use app\api\model\Cash as CashModel;
|
||||
use support\Log;
|
||||
|
||||
class UniCallBackController extends Frontend
|
||||
{
|
||||
|
||||
public function adCallBack()
|
||||
{
|
||||
$params = [
|
||||
'adpid' => $this->request->param('adpid'),
|
||||
'provider' => $this->request->param('provider'),
|
||||
'platform' => $this->request->param('platform'),
|
||||
'sign' => $this->request->param('sign'),
|
||||
'trans_id' => $this->request->param('trans_id'),
|
||||
'user_id' => $this->request->param('user_id'),
|
||||
'extra' => $this->request->param('extra', '') // 可选参数,默认空字符串
|
||||
];
|
||||
// 记录日志
|
||||
Log::write("接收到uni-ad广告完播回调,回调信息: " . json_encode($params));
|
||||
// 调用服务处理回调
|
||||
$result = UniAdCallbackRecord::adCallBack($params);
|
||||
// 返回成功响应
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
389
app/czg/app/controller/UserController.php
Normal file
389
app/czg/app/controller/UserController.php
Normal file
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\AddShortUrlResponseBody\data;
|
||||
use app\api\model\Msg;
|
||||
use app\api\model\TbUser;
|
||||
use app\api\model\UserInfo;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use app\exception\SysException;
|
||||
use app\utils\AliUtils;
|
||||
use app\utils\RedisUtils;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use ba\ClickCaptcha;
|
||||
use think\facade\Config;
|
||||
use app\common\facade\Token;
|
||||
use app\common\controller\Frontend;
|
||||
use app\api\validate\User as UserValidate;
|
||||
|
||||
class UserController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['checkIn', 'logout', 'realNameAuth', 'selectNewApp'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
|
||||
public function test()
|
||||
{
|
||||
p($this->auth->user_id);
|
||||
// Db::connect(DatabaseRoute::getConnection('course_collect', ['user_id' => 10]))
|
||||
// ->name('course_collect')
|
||||
// ->where('user_id', 10)
|
||||
// ->find();
|
||||
|
||||
// 查询
|
||||
// $user = new SysUser();
|
||||
// // 查询或者删除前设置分库连接
|
||||
// $user->setConnection($user::findbefore($user, ['user_id' => 1072634324253292306]));
|
||||
// $user = $user->where(['user_id' => 1072634324253292306]);
|
||||
//// $res = $user->delete();
|
||||
// $data = $user->find();
|
||||
// p($data);
|
||||
|
||||
|
||||
|
||||
// SysUser::update(['username' => 99999], ['user_id' => 130677]);
|
||||
// SysUser::create([
|
||||
// 'user_id' => rand(000000, 999999),
|
||||
// 'username' => '哎呀' . rand(000000, 999999),
|
||||
// ]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function bindAlipay()
|
||||
{
|
||||
$get = $this->request->param();
|
||||
$user = $this->auth->getUser();
|
||||
// 获取请求参数
|
||||
$userId = $user['user_id'];
|
||||
$zhiFuBao = $get['zhiFuBao'] ?? null;
|
||||
$certName = $get['certName'] ?? null;
|
||||
|
||||
// 验证参数不能为空
|
||||
if (empty($zhiFuBao) || empty($certName)) {
|
||||
$this->error("支付宝账号或姓名不能为空");
|
||||
}
|
||||
|
||||
// 包含*号直接返回成功(业务特殊处理)
|
||||
if (str_contains($zhiFuBao, '*') || str_contains($certName, '*')) {
|
||||
$this->success();
|
||||
}
|
||||
|
||||
$slave_db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId]));
|
||||
// 查询用户信息
|
||||
$userEntity = $slave_db->name('tb_user')
|
||||
->where('user_id', $userId)
|
||||
->find();
|
||||
|
||||
// 检查是否与原有信息一致
|
||||
if ($zhiFuBao == $userEntity['zhi_fu_bao'] && $certName == $userEntity['zhi_fu_bao_name']) {
|
||||
$this->success();
|
||||
}
|
||||
|
||||
// 检查支付宝账号是否已被其他用户绑定
|
||||
$count = $slave_db->name('tb_user')
|
||||
->where('user_id', '<>', $userId)
|
||||
->where('zhi_fu_bao_name', $certName)
|
||||
->where('zhi_fu_bao', $zhiFuBao)
|
||||
->count();
|
||||
|
||||
if ($count > 0) {
|
||||
$this->error("支付宝信息修改失败: 此支付宝账号已被绑定");
|
||||
}
|
||||
|
||||
// 检查实名认证信息是否匹配
|
||||
$userInfo = $slave_db->name('user_info')
|
||||
->where('user_id', $userId)
|
||||
->find();
|
||||
|
||||
if ($userInfo) {
|
||||
if (!empty($userInfo['cert_name']) && $certName != $userInfo['cert_name']) {
|
||||
$this->error("支付宝信息修改失败: 姓名与实名认证信息不相符");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取配置的限制次数
|
||||
$limitConfig = Db::name('common_info')
|
||||
->where('type', 924)
|
||||
->value('value');
|
||||
|
||||
// 获取当前时间戳(秒)
|
||||
$currentTime = time();
|
||||
// 获取本月最后一天的日期(如:2024-08-31)
|
||||
$lastDayOfMonth = date('Y-m-t');
|
||||
// 拼接本月最后一刻的时间(23:59:59)
|
||||
$endOfMonth = $lastDayOfMonth . ' 23:59:59';
|
||||
// 转换为时间戳
|
||||
$endTime = strtotime($endOfMonth);
|
||||
// 计算剩余秒数(若当前时间已过本月最后一刻,返回0)
|
||||
$remainingSeconds = max(0, $endTime - $currentTime);
|
||||
|
||||
// 检查支付宝账号每月绑定次数限制
|
||||
if (!\app\common\model\Common::isAccessAllowed($zhiFuBao, $certName, (int)$limitConfig, $remainingSeconds, true)) {
|
||||
$this->error("支付宝信息修改失败: 相同支付宝账号每月可绑定次数已用完");
|
||||
}
|
||||
|
||||
// 检查用户每月修改次数限制
|
||||
$updateLimitConfig = Db::name('common_info')
|
||||
->where('id', 925)
|
||||
->value('value');
|
||||
|
||||
if (!\app\common\model\Common::isAccessAllowed((string)$userId, "updateZFB", (int)$updateLimitConfig, $remainingSeconds)) {
|
||||
$this->error("支付宝信息修改失败: 每月可修改次数已用完,请联系管理员");
|
||||
}
|
||||
|
||||
// 更新用户支付宝信息
|
||||
$master_db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
$master_db->name('tb_user')
|
||||
->where('user_id', $userId)
|
||||
->update([
|
||||
'zhi_fu_bao' => $zhiFuBao,
|
||||
'zhi_fu_bao_name' => $certName,
|
||||
// 可添加更新时间字段
|
||||
'update_time' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$this->success('ok', 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function updatePhone()
|
||||
{
|
||||
$user_id = $this->auth->user_id;
|
||||
$post = $this->request->post();
|
||||
if(empty($post['phone']) || empty($post['msg'])) {
|
||||
$this->error('参数不正常');
|
||||
}
|
||||
|
||||
// 验证码
|
||||
if(Msg::checkCode($post['phone'], $post['msg'])) {
|
||||
$user = TbUser::GetByusername($post['phone']);
|
||||
if($user) {
|
||||
$this->error('手机号已经存在');
|
||||
}
|
||||
$db = DatabaseRoute::getDb('tb_user', $user_id, true)->where(['user_id' => $user_id])->update(['phone' => $post['phone']]);
|
||||
if($db) {
|
||||
$this->success('操作成功');
|
||||
}else {
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}else {
|
||||
$this->error('验证码错误');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 会员签入(登录和注册)
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function checkIn(): void
|
||||
{
|
||||
$openMemberCenter = Config::get('buildadmin.open_member_center');
|
||||
if (!$openMemberCenter) {
|
||||
$this->error(__('Member center disabled'));
|
||||
}
|
||||
|
||||
// 检查登录态
|
||||
if ($this->auth->isLogin()) {
|
||||
$this->success(__('You have already logged in. There is no need to log in again~'), [
|
||||
'type' => $this->auth::LOGGED_IN
|
||||
], $this->auth::LOGIN_RESPONSE_CODE);
|
||||
}
|
||||
|
||||
$userLoginCaptchaSwitch = Config::get('buildadmin.user_login_captcha');
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post(['tab', 'email', 'mobile', 'username', 'password', 'keep', 'captcha', 'captchaId', 'captchaInfo', 'registerType']);
|
||||
|
||||
// 提前检查 tab ,然后将以 tab 值作为数据验证场景
|
||||
if (!in_array($params['tab'] ?? '', ['login', 'register'])) {
|
||||
$this->error(__('Unknown operation'));
|
||||
}
|
||||
|
||||
$validate = new UserValidate();
|
||||
try {
|
||||
$validate->scene($params['tab'])->check($params);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
if ($params['tab'] == 'login') {
|
||||
if ($userLoginCaptchaSwitch) {
|
||||
$captchaObj = new ClickCaptcha();
|
||||
if (!$captchaObj->check($params['captchaId'], $params['captchaInfo'])) {
|
||||
$this->error(__('Captcha error'));
|
||||
}
|
||||
}
|
||||
$res = $this->auth->login($params['username'], $params['password'], !empty($params['keep']));
|
||||
} elseif ($params['tab'] == 'register') {
|
||||
$captchaObj = new Captcha();
|
||||
if (!$captchaObj->check($params['captcha'], $params[$params['registerType']] . 'user_register')) {
|
||||
$this->error(__('Please enter the correct verification code'));
|
||||
}
|
||||
$res = $this->auth->register($params['username'], $params['password'], $params['mobile'], $params['email']);
|
||||
}
|
||||
|
||||
if (isset($res) && $res === true) {
|
||||
$this->success(__('Login succeeded!'), [
|
||||
'userInfo' => $this->auth->getUserInfo(),
|
||||
'routePath' => '/user'
|
||||
]);
|
||||
} else {
|
||||
$msg = $this->auth->getError();
|
||||
$msg = $msg ?: __('Check in failed, please try again or contact the website administrator~');
|
||||
$this->error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'userLoginCaptchaSwitch' => $userLoginCaptchaSwitch,
|
||||
'accountVerificationType' => get_account_verification_type()
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$refreshToken = $this->request->post('refreshToken', '');
|
||||
if ($refreshToken) Token::delete((string)$refreshToken);
|
||||
$this->auth->logout();
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
|
||||
public function selectNewApp()
|
||||
{
|
||||
$this->n_success(['data' => apiconvertToCamelCase(Db::connect(get_slave_connect_name())->name('app')->order('version', 'desc')->select()->toArray())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实名接口
|
||||
*/
|
||||
public function realNameAuth()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
// (new UserValidate())->scene('realName')->check($params);
|
||||
$params['certNum'] = trim($params['certNum']);
|
||||
$params['certName'] = trim($params['certName']);
|
||||
$userId = $this->getUserId();
|
||||
$regex = '/^[0-9Xx*]+$/';
|
||||
if (!preg_match($regex, $params['certNum'])) {
|
||||
$this->success();
|
||||
}
|
||||
|
||||
$count = DatabaseRoute::getDb('user_info', $userId)->where([
|
||||
'cert_name' => $params['certName'],
|
||||
'cert_no' => $params['certNum'],
|
||||
])->count();
|
||||
if ($count) {
|
||||
$this->error('已完成实名认证,无需重复操作');
|
||||
}
|
||||
|
||||
$count = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params) {
|
||||
return $query->where([
|
||||
'cert_name' => $params['certName'],
|
||||
'cert_no' => $params['certNum'],
|
||||
]);
|
||||
})->count();
|
||||
if ($count >= 3) {
|
||||
$this->error('实名认证失败: 1个身份证号码最多绑定3个账号');
|
||||
}
|
||||
|
||||
RedisUtils::checkRealCount($userId);
|
||||
|
||||
$resp = AliUtils::verify($params['certName'], $params['certNum'], $params['accountNo'], $params['mobile']);
|
||||
$userInfo = UserInfo::getByUserIdOrSave($userId);
|
||||
$userInfo['cert_name'] = $params['certName'];
|
||||
$userInfo['cert_no'] = $params['certNum'];
|
||||
$userInfo['account_no'] = $params['accountNo'];
|
||||
$userInfo['mobile'] = $params['mobile'];
|
||||
$userInfo['bank_name'] = $resp['bankName'];
|
||||
$userInfo['province'] = $params['province'] ?? '';
|
||||
$userInfo['city'] = $params['city'] ?? '';
|
||||
$userInfo['bank_branch'] = $params['bankBranch'];
|
||||
$userInfo['resp_json'] = $resp['respJson'];
|
||||
$userInfo['update_time'] = getNormalDate();
|
||||
DatabaseRoute::getDb('user_info', $userId, true, true)->update($userInfo);
|
||||
|
||||
RedisUtils::setRealCount($userId);
|
||||
|
||||
// 校验实名黑名单
|
||||
$count = Db::name('tb_user_blacklist')->where([
|
||||
'id_card_no' => $params['certNum']
|
||||
])->count();
|
||||
if ($count) {
|
||||
DatabaseRoute::getDb('tb_user', $userId, true, true)->update([
|
||||
'status' => 0,
|
||||
'plat_form' => '异常行为用户:实名信息异常 在黑名单'
|
||||
]);
|
||||
throw new SysException("异常行为: 您的实名信息存在异常行为");
|
||||
}
|
||||
|
||||
$this->successWithData(1);
|
||||
}
|
||||
|
||||
public function selectUserById()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
// 获取用户详情
|
||||
$userInfo = DatabaseRoute::getDb('user_info', $user['user_id'])->find();
|
||||
$userInfo['resp_json'] = null; // 移除敏感字段
|
||||
|
||||
// 对用户详情中的敏感信息进行脱敏
|
||||
if (!empty($userInfo['account_no'])) {
|
||||
$userInfo['account_no'] = bankCard($userInfo['account_no']);
|
||||
}
|
||||
|
||||
if (!empty($userInfo['mobile'])) {
|
||||
$userInfo['mobile'] = maskPhoneNumber($userInfo['mobile']);
|
||||
}
|
||||
|
||||
if (!empty($userInfo['cert_no'])) {
|
||||
$userInfo['cert_no'] = idCardNum($userInfo['cert_no'], 3, 2);
|
||||
}
|
||||
|
||||
// 对支付宝信息进行脱敏
|
||||
if (!empty($user['zhi_fu_bao'])) {
|
||||
if (filter_var($user['zhi_fu_bao'], FILTER_VALIDATE_EMAIL)) {
|
||||
$user['zhi_fu_bao'] = email($user['zhi_fu_bao']);
|
||||
} else {
|
||||
$user['zhi_fu_bao'] = maskPhoneNumber($user['zhi_fu_bao']);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并用户信息和用户详情
|
||||
$map = array_merge($user, $userInfo);
|
||||
$map['user_id'] = (string)$map['user_id']; // 确保用户ID为字符串类型
|
||||
|
||||
// 如果支付宝姓名为空,使用实名认证姓名
|
||||
if (empty($user['zhi_fu_bao_name']) && !empty($userInfo['cert_name'])) {
|
||||
$map['zhi_fu_bao_name'] = $userInfo['cert_name'];
|
||||
}
|
||||
$this->success('ok', convertToCamelCase($map));
|
||||
}
|
||||
|
||||
public function updateUsers()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$user = $this->auth->getUser();
|
||||
$db_name = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $user['user_id']], true));
|
||||
$db_name->name('tb_user')->where(['user_id' => $user['user_id']])->update(['user_name' => $post['userName'], 'avatar' => $post['avatar']]);
|
||||
$this->success('ok');
|
||||
}
|
||||
|
||||
}
|
||||
24
app/czg/app/controller/UserPrizeExchangeController.php
Normal file
24
app/czg/app/controller/UserPrizeExchangeController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\Orders;
|
||||
use app\api\model\TbUser;
|
||||
use app\common\controller\Frontend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\CzgException;
|
||||
use app\queue\DiscReceiveQueue;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserPrizeExchangeController extends Frontend
|
||||
{
|
||||
// 查询大转盘抽奖记录
|
||||
public function page()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(\app\api\model\UserPrizeExchange::pages($get, $this->auth->user_id));
|
||||
}
|
||||
|
||||
}
|
||||
29
app/czg/app/controller/UserSignRecordController.php
Normal file
29
app/czg/app/controller/UserSignRecordController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\controller;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use ba\ClickCaptcha;
|
||||
use app\common\controller\Frontend;
|
||||
use app\api\validate\User as UserValidate;
|
||||
|
||||
class UserSignRecordController extends Frontend
|
||||
{
|
||||
|
||||
// 获取用户连续签到数据
|
||||
public function getUserSignData()
|
||||
{
|
||||
$user_id = $this->auth->user_id;
|
||||
$res = \app\api\model\UserSignRecord::getUserSignData($user_id, $this->auth->getUser());
|
||||
return $this->ApiDataReturn($res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -7,14 +7,15 @@ use app\common\controller\BaseController;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\SysException;
|
||||
use app\utils\RedisUtils;
|
||||
use app\api\validate\WuyouValidate;
|
||||
use app\utils\WuYouPayUtils;
|
||||
use ba\Random;
|
||||
use Orders;
|
||||
use app\api\model\Orders;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
|
||||
class Wuyou extends BaseController
|
||||
class WuyouController extends BaseController
|
||||
{
|
||||
protected array $noNeedLogin = ['payOrder', 'index', 'test', 'notify', 'queryOrder'];
|
||||
|
||||
292
app/czg/app/controller/user/User.php
Normal file
292
app/czg/app/controller/user/User.php
Normal file
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\user;
|
||||
|
||||
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\AddShortUrlResponseBody\data;
|
||||
use app\api\model\Msg;
|
||||
use app\api\model\TbUser;
|
||||
use app\api\model\UserInfo;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use app\exception\SysException;
|
||||
use app\utils\AliUtils;
|
||||
use app\utils\RedisUtils;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
use ba\Captcha;
|
||||
use ba\ClickCaptcha;
|
||||
use think\facade\Config;
|
||||
use app\common\facade\Token;
|
||||
use app\common\controller\Frontend;
|
||||
use app\api\validate\User as UserValidate;
|
||||
|
||||
class User extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['checkIn', 'logout', 'realNameAuth'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
|
||||
public function test()
|
||||
{
|
||||
p($this->auth->user_id);
|
||||
// Db::connect(DatabaseRoute::getConnection('course_collect', ['user_id' => 10]))
|
||||
// ->name('course_collect')
|
||||
// ->where('user_id', 10)
|
||||
// ->find();
|
||||
|
||||
// 查询
|
||||
// $user = new SysUser();
|
||||
// // 查询或者删除前设置分库连接
|
||||
// $user->setConnection($user::findbefore($user, ['user_id' => 1072634324253292306]));
|
||||
// $user = $user->where(['user_id' => 1072634324253292306]);
|
||||
//// $res = $user->delete();
|
||||
// $data = $user->find();
|
||||
// p($data);
|
||||
|
||||
|
||||
|
||||
// SysUser::update(['username' => 99999], ['user_id' => 130677]);
|
||||
// SysUser::create([
|
||||
// 'user_id' => rand(000000, 999999),
|
||||
// 'username' => '哎呀' . rand(000000, 999999),
|
||||
// ]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updatePhone()
|
||||
{
|
||||
$user_id = $this->auth->user_id;
|
||||
$post = $this->request->post();
|
||||
if(empty($post['phone']) || empty($post['msg'])) {
|
||||
$this->error('参数不正常');
|
||||
}
|
||||
|
||||
// 验证码
|
||||
if(Msg::checkCode($post['phone'], $post['msg'])) {
|
||||
$user = TbUser::GetByusername($post['phone']);
|
||||
if($user) {
|
||||
$this->error('手机号已经存在');
|
||||
}
|
||||
$db = DatabaseRoute::getDb('tb_user', $user_id, true)->where(['user_id' => $user_id])->update(['phone' => $post['phone']]);
|
||||
if($db) {
|
||||
$this->success('操作成功');
|
||||
}else {
|
||||
$this->error('操作失败');
|
||||
}
|
||||
}else {
|
||||
$this->error('验证码错误');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 会员签入(登录和注册)
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function checkIn(): void
|
||||
{
|
||||
$openMemberCenter = Config::get('buildadmin.open_member_center');
|
||||
if (!$openMemberCenter) {
|
||||
$this->error(__('Member center disabled'));
|
||||
}
|
||||
|
||||
// 检查登录态
|
||||
if ($this->auth->isLogin()) {
|
||||
$this->success(__('You have already logged in. There is no need to log in again~'), [
|
||||
'type' => $this->auth::LOGGED_IN
|
||||
], $this->auth::LOGIN_RESPONSE_CODE);
|
||||
}
|
||||
|
||||
$userLoginCaptchaSwitch = Config::get('buildadmin.user_login_captcha');
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post(['tab', 'email', 'mobile', 'username', 'password', 'keep', 'captcha', 'captchaId', 'captchaInfo', 'registerType']);
|
||||
|
||||
// 提前检查 tab ,然后将以 tab 值作为数据验证场景
|
||||
if (!in_array($params['tab'] ?? '', ['login', 'register'])) {
|
||||
$this->error(__('Unknown operation'));
|
||||
}
|
||||
|
||||
$validate = new UserValidate();
|
||||
try {
|
||||
$validate->scene($params['tab'])->check($params);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
if ($params['tab'] == 'login') {
|
||||
if ($userLoginCaptchaSwitch) {
|
||||
$captchaObj = new ClickCaptcha();
|
||||
if (!$captchaObj->check($params['captchaId'], $params['captchaInfo'])) {
|
||||
$this->error(__('Captcha error'));
|
||||
}
|
||||
}
|
||||
$res = $this->auth->login($params['username'], $params['password'], !empty($params['keep']));
|
||||
} elseif ($params['tab'] == 'register') {
|
||||
$captchaObj = new Captcha();
|
||||
if (!$captchaObj->check($params['captcha'], $params[$params['registerType']] . 'user_register')) {
|
||||
$this->error(__('Please enter the correct verification code'));
|
||||
}
|
||||
$res = $this->auth->register($params['username'], $params['password'], $params['mobile'], $params['email']);
|
||||
}
|
||||
|
||||
if (isset($res) && $res === true) {
|
||||
$this->success(__('Login succeeded!'), [
|
||||
'userInfo' => $this->auth->getUserInfo(),
|
||||
'routePath' => '/user'
|
||||
]);
|
||||
} else {
|
||||
$msg = $this->auth->getError();
|
||||
$msg = $msg ?: __('Check in failed, please try again or contact the website administrator~');
|
||||
$this->error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'userLoginCaptchaSwitch' => $userLoginCaptchaSwitch,
|
||||
'accountVerificationType' => get_account_verification_type()
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$refreshToken = $this->request->post('refreshToken', '');
|
||||
if ($refreshToken) Token::delete((string)$refreshToken);
|
||||
$this->auth->logout();
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function selectInviteCount()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 实名接口
|
||||
*/
|
||||
public function realNameAuth()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
// (new UserValidate())->scene('realName')->check($params);
|
||||
$params['certNum'] = trim($params['certNum']);
|
||||
$params['certName'] = trim($params['certName']);
|
||||
$userId = $this->getUserId();
|
||||
$regex = '/^[0-9Xx*]+$/';
|
||||
if (!preg_match($regex, $params['certNum'])) {
|
||||
$this->success();
|
||||
}
|
||||
|
||||
$count = DatabaseRoute::getDb('user_info', $userId)->where([
|
||||
'cert_name' => $params['certName'],
|
||||
'cert_no' => $params['certNum'],
|
||||
])->count();
|
||||
if ($count) {
|
||||
$this->error('已完成实名认证,无需重复操作');
|
||||
}
|
||||
|
||||
$count = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params) {
|
||||
return $query->where([
|
||||
'cert_name' => $params['certName'],
|
||||
'cert_no' => $params['certNum'],
|
||||
]);
|
||||
})->count();
|
||||
if ($count >= 3) {
|
||||
$this->error('实名认证失败: 1个身份证号码最多绑定3个账号');
|
||||
}
|
||||
|
||||
RedisUtils::checkRealCount($userId);
|
||||
|
||||
$resp = AliUtils::verify($params['certName'], $params['certNum'], $params['accountNo'], $params['mobile']);
|
||||
$userInfo = UserInfo::getByUserIdOrSave($userId);
|
||||
$userInfo['cert_name'] = $params['certName'];
|
||||
$userInfo['cert_no'] = $params['certNum'];
|
||||
$userInfo['account_no'] = $params['accountNo'];
|
||||
$userInfo['mobile'] = $params['mobile'];
|
||||
$userInfo['bank_name'] = $resp['bankName'];
|
||||
$userInfo['province'] = $params['province'] ?? '';
|
||||
$userInfo['city'] = $params['city'] ?? '';
|
||||
$userInfo['bank_branch'] = $params['bankBranch'];
|
||||
$userInfo['resp_json'] = $resp['respJson'];
|
||||
$userInfo['update_time'] = getNormalDate();
|
||||
DatabaseRoute::getDb('user_info', $userId, true, true)->update($userInfo);
|
||||
|
||||
RedisUtils::setRealCount($userId);
|
||||
|
||||
// 校验实名黑名单
|
||||
$count = Db::name('tb_user_blacklist')->where([
|
||||
'id_card_no' => $params['certNum']
|
||||
])->count();
|
||||
if ($count) {
|
||||
DatabaseRoute::getDb('tb_user', $userId, true, true)->update([
|
||||
'status' => 0,
|
||||
'plat_form' => '异常行为用户:实名信息异常 在黑名单'
|
||||
]);
|
||||
throw new SysException("异常行为: 您的实名信息存在异常行为");
|
||||
}
|
||||
|
||||
$this->successWithData(1);
|
||||
}
|
||||
|
||||
public function selectUserById()
|
||||
{
|
||||
$user = $this->auth->getUser();
|
||||
// 获取用户详情
|
||||
$userInfo = DatabaseRoute::getDb('user_info', $user['user_id'])->find();
|
||||
$userInfo['resp_json'] = null; // 移除敏感字段
|
||||
|
||||
// 对用户详情中的敏感信息进行脱敏
|
||||
if (!empty($userInfo['account_no'])) {
|
||||
$userInfo['account_no'] = bankCard($userInfo['account_no']);
|
||||
}
|
||||
|
||||
if (!empty($userInfo['mobile'])) {
|
||||
$userInfo['mobile'] = maskPhoneNumber($userInfo['mobile']);
|
||||
}
|
||||
|
||||
if (!empty($userInfo['cert_no'])) {
|
||||
$userInfo['cert_no'] = idCardNum($userInfo['cert_no'], 3, 2);
|
||||
}
|
||||
|
||||
// 对支付宝信息进行脱敏
|
||||
if (!empty($user['zhi_fu_bao'])) {
|
||||
if (filter_var($user['zhi_fu_bao'], FILTER_VALIDATE_EMAIL)) {
|
||||
$user['zhi_fu_bao'] = email($user['zhi_fu_bao']);
|
||||
} else {
|
||||
$user['zhi_fu_bao'] = maskPhoneNumber($user['zhi_fu_bao']);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并用户信息和用户详情
|
||||
$map = array_merge($user, $userInfo);
|
||||
$map['user_id'] = (string)$map['user_id']; // 确保用户ID为字符串类型
|
||||
|
||||
// 如果支付宝姓名为空,使用实名认证姓名
|
||||
if (empty($user['zhi_fu_bao_name']) && !empty($userInfo['cert_name'])) {
|
||||
$map['zhi_fu_bao_name'] = $userInfo['cert_name'];
|
||||
}
|
||||
$this->success('ok', convertToCamelCase($map));
|
||||
}
|
||||
|
||||
public function updateUsers()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$user = $this->auth->getUser();
|
||||
$db_name = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $user['user_id']]));
|
||||
$db_name->name('tb_user')->where(['user_id' => $user['user_id']])->update(['user_name' => $post['userName'], 'avatar' => $post['avatar']]);
|
||||
$this->success('ok');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use ba\Random;
|
||||
use think\Model;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\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']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\model;
|
||||
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\Common;
|
||||
use ba\Random;
|
||||
use think\cache\driver\Redis;
|
||||
use support\think\Cache;
|
||||
use think\facade\Db;
|
||||
use support\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) {
|
||||
Cach::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']);
|
||||
}
|
||||
// 调整集数范围
|
||||
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();
|
||||
$detailsId = array_flip(array_flip($detailsId)); // 去重
|
||||
}
|
||||
// 处理剧集列表
|
||||
$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;
|
||||
}
|
||||
}
|
||||
// 如果没有当前播放集,默认第一集
|
||||
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::info("请求剧集异常: " . $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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?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
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,602 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
use app\api\model\Invite;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\SysUser;
|
||||
use app\czg\app\model\CommonInfo;
|
||||
use app\czg\app\model\TbUser;
|
||||
use app\utils\RedisUtils;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,420 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,309 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\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('think-orm.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('think-orm.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('think-orm.db_map');
|
||||
// $count = 0;
|
||||
// foreach ($dbmap as $dbname) {
|
||||
// if(!in_array($dbname, config('think-orm.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('think-orm.db_map');
|
||||
// $data_list = [];
|
||||
// foreach ($dbmap as $dbname) {
|
||||
//
|
||||
// if(!in_array($dbname, config('think-orm.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('think-orm.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('think-orm.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('think-orm.db_map');
|
||||
foreach ($dbmap as $dbname) {
|
||||
if(!in_array($dbname, config('think-orm.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('think-orm.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\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
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\app\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;
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?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
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
<?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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
<?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 '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user