FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0) - 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION - vendor/示例资源已gitignore
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\utils\Password;
|
||||
use app\expose\utils\Rsa;
|
||||
use app\expose\utils\Str;
|
||||
use app\model\Basic;
|
||||
use loong\oauth\facade\Auth;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\control\expose\helper\Uploads;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\user\utils\enum\UserPermission;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class PluginUser extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
public function parent()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'puid');
|
||||
}
|
||||
public function wallet()
|
||||
{
|
||||
return $this->hasOne(PluginFinanceWallet::class, 'uid', 'id');
|
||||
}
|
||||
public function getHeadimgAttr($value, $data)
|
||||
{
|
||||
if(empty($value)){
|
||||
return '';
|
||||
}
|
||||
return Uploads::url($data['channels_uid'], $value);
|
||||
}
|
||||
public function setHeadimgAttr($value, $data)
|
||||
{
|
||||
return Uploads::path($data['channels_uid'], $value);
|
||||
}
|
||||
public function setPasswordAttr($value)
|
||||
{
|
||||
return $value ? Password::encrypt($value) : $value;
|
||||
}
|
||||
public static function options($where = [])
|
||||
{
|
||||
$models = self::where($where)->field('id,nickname,mobile')->select();
|
||||
$data = [];
|
||||
foreach ($models as $item) {
|
||||
$data[] = [
|
||||
'label' => $item->nickname,
|
||||
'value' => $item->id,
|
||||
'tips' => "UID:{$item->id},M:{$item->mobile}"
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public static function genUser($id)
|
||||
{
|
||||
$id = (int)$id;
|
||||
return str_replace(['+', '/'], ['-', '_'], Rsa::encryptNumber($id));
|
||||
}
|
||||
public static function getUidByUser($user)
|
||||
{
|
||||
return Rsa::decryptNumber(str_replace(['-', '_'], ['+', '/'], $user));
|
||||
}
|
||||
public static function getTokenInfo($model, $twofa = false)
|
||||
{
|
||||
$request = request();
|
||||
/* 重组用户信息 */
|
||||
$User = new \stdClass;
|
||||
$User->user = self::genUser($model->id);
|
||||
$User->nickname = $model->nickname;
|
||||
$User->headimg = $model->headimg;
|
||||
$User->id = $model->id;
|
||||
$User->username = $model->username;
|
||||
$User->username_time = $model->username_time ? 30 - ceil((time() - strtotime($model->username_time)) / 86400) : 0;
|
||||
$User->mobile = Str::mask($model->mobile);
|
||||
$User->email = Str::mask($model->email);
|
||||
$User->password = $model->password ? 1 : 0;
|
||||
$User->create_time = $model->create_time;
|
||||
$User->last_login_time = $model->login_time;
|
||||
$User->last_login_ip = $model->login_ip;
|
||||
$User->twofa_state = $model->twofa_state;
|
||||
$User->activation_time = $model->activation_time;
|
||||
$PluginUserWechat = PluginUserWechat::where(['uid' => $model->id])->field('openid,unionid,mp_openid,nickname,headimg,subscribe')->find();
|
||||
if ($PluginUserWechat) {
|
||||
$User->wechat = $PluginUserWechat;
|
||||
}
|
||||
$User->permissions = [];
|
||||
if ($model->mobile) {
|
||||
$User->permissions[] = UserPermission::MOBILE['value'];
|
||||
}
|
||||
if ($model->email) {
|
||||
$User->permissions[] = UserPermission::EMAIL['value'];
|
||||
}
|
||||
if ($model->twofa_state) {
|
||||
$User->permissions[] = UserPermission::TWOFA['value'];
|
||||
}
|
||||
if ($model->username) {
|
||||
$User->permissions[] = UserPermission::USERNAME['value'];
|
||||
}
|
||||
if ($model->password) {
|
||||
$User->permissions[] = UserPermission::PASSWORD['value'];
|
||||
}
|
||||
if ($model->realname) {
|
||||
$User->permissions[] = UserPermission::REALNAME['value'];
|
||||
}
|
||||
if ($model->mobile && $model->realname) {
|
||||
$User->permissions[] = UserPermission::BUY['value'];
|
||||
}
|
||||
$pluginConfig = glob(base_path("plugin/*/api/{$request->app}/PublicController.php"));
|
||||
foreach ($pluginConfig as $path) {
|
||||
$plugin_name = basename(dirname(dirname(dirname($path))));
|
||||
if ($plugin_name == 'user') {
|
||||
continue;
|
||||
}
|
||||
$class = 'plugin\\' . $plugin_name . "\\api\\{$request->app}\\PublicController";
|
||||
if (!class_exists($class)) {
|
||||
continue;
|
||||
}
|
||||
$plugin = new $class;
|
||||
if (method_exists($plugin, 'appendUserInfo')) {
|
||||
$plugin->appendUserInfo($User, $model);
|
||||
}
|
||||
}
|
||||
/* 生成token */
|
||||
$data = new \stdClass;
|
||||
$data->uid = $model->id;
|
||||
$data->channels_uid = $model->channels_uid;
|
||||
$data->username = $model->username;
|
||||
$data->mobile = $model->mobile;
|
||||
$data->email = $model->email;
|
||||
$data->twofa_state = $model->twofa_state;
|
||||
if ($twofa) {
|
||||
if ($twofa === true) {
|
||||
$data->twofa = [
|
||||
'expire' => time() + (config('oauth.expire') / 2),
|
||||
'time' => time(),
|
||||
];
|
||||
} else {
|
||||
$data->twofa = $twofa;
|
||||
}
|
||||
}
|
||||
$User->token = Auth::setPrefix('CONTROL')->encrypt($data);
|
||||
if ($request->token) {
|
||||
Auth::setPrefix('CONTROL')->refresh($request->token, 60);
|
||||
}
|
||||
return $User;
|
||||
}
|
||||
public static function onAfterRead($model)
|
||||
{
|
||||
if (empty($model->nickname)) {
|
||||
if (!empty($model->mobile)) {
|
||||
$model->nickname = 'FM-' . substr($model->mobile, -4);
|
||||
} else {
|
||||
$model->nickname = '未命名的用户';
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function onBeforeWrite($model)
|
||||
{
|
||||
if (empty($model->nickname)) {
|
||||
if (!empty($model->mobile)) {
|
||||
$model->nickname = 'FM-' . substr($model->mobile, -4);
|
||||
} else {
|
||||
$model->nickname = 'FM-' . Str::random();
|
||||
}
|
||||
} else {
|
||||
$model->nickname = iconv('UTF-8', 'UTF-8//IGNORE', $model->nickname);
|
||||
}
|
||||
}
|
||||
public static function onAfterInsert($model)
|
||||
{
|
||||
$PluginFinanceWallet = new PluginFinanceWallet;
|
||||
$PluginFinanceWallet->channels_uid = $model->channels_uid;
|
||||
$PluginFinanceWallet->uid = $model->id;
|
||||
$PluginFinanceWallet->save();
|
||||
Event::emit(EventName::USER_REGISTER['value'], $model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\finance\utils\enum\BillScene;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use think\facade\Db;
|
||||
|
||||
class PluginUserBill extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
'num' => 'float',
|
||||
'before' => 'float',
|
||||
'after' => 'float',
|
||||
],
|
||||
];
|
||||
}
|
||||
public static function consume($order)
|
||||
{
|
||||
$uid = $order->uid;
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
if ($wallet->balance < $order->money) {
|
||||
throw new \Exception('余额不足');
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'form_id' => $order->id,
|
||||
'num' => $order->money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance - $order->money,
|
||||
'remarks' => $order->title . ' 订单号:' . $order->trade_no,
|
||||
'action' => MoneyAction::DECREASE['value'],
|
||||
'scene' => $order->type,
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance - ' . $order->money);
|
||||
$wallet->balance_used = Db::raw('balance_used + ' . $order->money);
|
||||
$wallet->save();
|
||||
}
|
||||
public static function expend($uid, $money, $title)
|
||||
{
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'num' => $money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance - $money,
|
||||
'remarks' => $title,
|
||||
'action' => MoneyAction::DECREASE['value'],
|
||||
'scene' => BillScene::ADMIN['value'],
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance - ' . $money);
|
||||
$wallet->balance_sum = Db::raw('balance_sum - ' . $money);
|
||||
$wallet->save();
|
||||
}
|
||||
public static function income($uid, $money, $title)
|
||||
{
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'num' => $money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance + $money,
|
||||
'remarks' => $title,
|
||||
'action' => MoneyAction::INCREASE['value'],
|
||||
'scene' => BillScene::ADMIN['value'],
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance + ' . $money);
|
||||
$wallet->balance_sum = Db::raw('balance_sum + ' . $money);
|
||||
$wallet->save();
|
||||
}
|
||||
protected function sceneExternal()
|
||||
{
|
||||
return $this->visible(['id', 'create_time', 'num', 'before', 'after', 'remarks', 'action', 'scene', 'action_text', 'scene_text']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\expose\helper\Config;
|
||||
use app\expose\utils\Str;
|
||||
use app\model\Basic;
|
||||
use loong\oauth\utils\Str as UtilsStr;
|
||||
use plugin\finance\expose\helper\Account;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
|
||||
class PluginUserInvitationCode extends Basic
|
||||
{
|
||||
// 关联创建者用户
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'uid');
|
||||
}
|
||||
|
||||
// 关联使用邀请码的用户
|
||||
public function useUser()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'use_uid');
|
||||
}
|
||||
|
||||
public static function addCode($uid, $num = 1, $channels_uid = 0)
|
||||
{
|
||||
$needNum = $num;
|
||||
$finalCodes = [];
|
||||
while ($needNum > 0) {
|
||||
$codes = [];
|
||||
for ($i = 0; $i < $needNum * 2; $i++) {
|
||||
$code = UtilsStr::random(6);
|
||||
//转大写
|
||||
$codes[] = strtoupper($code);
|
||||
}
|
||||
$codes = array_unique($codes);
|
||||
$exists = self::whereIn('code', $codes)
|
||||
->column('code');
|
||||
$available = array_values(array_diff($codes, $exists));
|
||||
$take = array_slice($available, 0, $needNum);
|
||||
$finalCodes = array_merge($finalCodes, $take);
|
||||
$needNum -= count($take);
|
||||
}
|
||||
$insertData = [];
|
||||
foreach ($finalCodes as $code) {
|
||||
$insertData[] = [
|
||||
'uid' => $uid,
|
||||
'code' => $code,
|
||||
'channels_uid' => $channels_uid,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
self::insertAll($insertData);
|
||||
return $finalCodes;
|
||||
}
|
||||
|
||||
|
||||
public function onAfterUpdate($model)
|
||||
{
|
||||
if ($model->status == 'used') {
|
||||
$register = new Config('register', 'user', $model->channels_uid);
|
||||
if ($register->invite_reward_points) {
|
||||
Account::incPoints($model->uid, $model->channels_uid, $register->invite_reward_points, PointsBillScene::INVITE['value'], 0, '邀请奖励积分');
|
||||
}
|
||||
PluginUserInvitationCode::where('id', $model->id)->update(['points' => $register->invite_reward_points]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserPoints extends Basic
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
|
||||
class PluginUserPointsBill extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserTwofaSecret extends Basic
|
||||
{
|
||||
protected function sceneExternal()
|
||||
{
|
||||
return $this->visible(['id','totp_app','is_default','create_time','totp_app_text']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserVip extends Basic
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginUserWechat extends Basic
|
||||
{
|
||||
public static function onBeforeWrite($model)
|
||||
{
|
||||
if(!empty($model->nickname)){
|
||||
$model->nickname= iconv('UTF-8', 'UTF-8//IGNORE', $model->nickname);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user