后台
This commit is contained in:
217
app/czg/controller/AjaxController.php
Normal file
217
app/czg/controller/AjaxController.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use Throwable;
|
||||
use ba\Terminal;
|
||||
use think\Response;
|
||||
use ba\TableManager;
|
||||
use think\facade\Db;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Event;
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\library\Upload;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class AjaxController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['*'];
|
||||
|
||||
/**
|
||||
* 无需登录的方法
|
||||
* terminal 内部自带验权
|
||||
*/
|
||||
protected array $noNeedLogin = ['terminal'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function upload(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('upload'));
|
||||
$file = $this->request->file('file');
|
||||
$driver = $this->request->param('driver', 'local');
|
||||
$topic = $this->request->param('topic', 'default');
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$attachment = $upload
|
||||
->setFile($file)
|
||||
->setDriver($driver)
|
||||
->setTopic($topic)
|
||||
->upload(null, $this->auth->id);
|
||||
unset($attachment['create_time'], $attachment['quote']);
|
||||
} catch (Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success(__('File uploaded successfully'), [
|
||||
'file' => $attachment ?? []
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取省市区数据
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function area(): void
|
||||
{
|
||||
$this->success('', get_area());
|
||||
}
|
||||
|
||||
public function buildSuffixSvg(): Response
|
||||
{
|
||||
$suffix = $this->request->param('suffix', 'file');
|
||||
$background = $this->request->param('background');
|
||||
$content = build_suffix_svg((string)$suffix, (string)$background);
|
||||
return response($content, 200, ['Content-Length' => strlen($content)])->contentType('image/svg+xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已脱敏的数据库连接配置列表
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function getDatabaseConnectionList(): void
|
||||
{
|
||||
$quickSearch = $this->request->get("quickSearch/s", '');
|
||||
$connections = config('database.connections');
|
||||
$desensitization = [];
|
||||
foreach ($connections as $key => $connection) {
|
||||
$connection = TableManager::getConnectionConfig($key);
|
||||
$desensitization[] = [
|
||||
'type' => $connection['type'],
|
||||
'database' => substr_replace($connection['database'], '****', 1, strlen($connection['database']) > 4 ? 2 : 1),
|
||||
'key' => $key,
|
||||
];
|
||||
}
|
||||
|
||||
if ($quickSearch) {
|
||||
$desensitization = array_filter($desensitization, function ($item) use ($quickSearch) {
|
||||
return preg_match("/$quickSearch/i", $item['key']);
|
||||
});
|
||||
$desensitization = array_values($desensitization);
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'list' => $desensitization,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表主键字段
|
||||
* @param ?string $table
|
||||
* @param ?string $connection
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function getTablePk(?string $table = null, ?string $connection = null): void
|
||||
{
|
||||
if (!$table) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
$table = TableManager::tableName($table, true, $connection);
|
||||
if (!TableManager::phinxAdapter(false, $connection)->hasTable($table)) {
|
||||
$this->error(__('Data table does not exist'));
|
||||
}
|
||||
|
||||
$tablePk = Db::connect(TableManager::getConnection($connection))
|
||||
->table($table)
|
||||
->getPk();
|
||||
$this->success('', ['pk' => $tablePk]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据表列表
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function getTableList(): void
|
||||
{
|
||||
$quickSearch = $this->request->get("quickSearch/s", '');
|
||||
$connection = $this->request->request('connection');// 数据库连接配置标识
|
||||
$samePrefix = $this->request->request('samePrefix/b', true);// 是否仅返回项目数据表(前缀同项目一致的)
|
||||
$excludeTable = $this->request->request('excludeTable/a', []);// 要排除的数据表数组(表名无需带前缀)
|
||||
|
||||
$outTables = [];
|
||||
$dbConfig = TableManager::getConnectionConfig($connection);
|
||||
$tables = TableManager::getTableList($connection);
|
||||
|
||||
if ($quickSearch) {
|
||||
$tables = array_filter($tables, function ($comment) use ($quickSearch) {
|
||||
return preg_match("/$quickSearch/i", $comment);
|
||||
});
|
||||
}
|
||||
|
||||
$pattern = '/^' . $dbConfig['prefix'] . '/i';
|
||||
foreach ($tables as $table => $comment) {
|
||||
if ($samePrefix && !preg_match($pattern, $table)) continue;
|
||||
|
||||
$table = preg_replace($pattern, '', $table);
|
||||
if (!in_array($table, $excludeTable)) {
|
||||
$outTables[] = [
|
||||
'table' => $table,
|
||||
'comment' => $comment,
|
||||
'connection' => $connection,
|
||||
'prefix' => $dbConfig['prefix'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'list' => $outTables,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据表字段列表
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function getTableFieldList(): void
|
||||
{
|
||||
$table = $this->request->param('table');
|
||||
$clean = $this->request->param('clean', true);
|
||||
$connection = $this->request->request('connection');
|
||||
if (!$table) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
$connection = TableManager::getConnection($connection);
|
||||
$tablePk = Db::connect($connection)->name($table)->getPk();
|
||||
$this->success('', [
|
||||
'pk' => $tablePk,
|
||||
'fieldList' => TableManager::getTableColumns($table, $clean, $connection),
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeTerminalConfig(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Change terminal config'));
|
||||
if (Terminal::changeTerminalConfig()) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Failed to modify the terminal configuration. Please modify the configuration file manually:%s', ['/config/buildadmin.php']));
|
||||
}
|
||||
}
|
||||
|
||||
public function clearCache(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Clear cache'));
|
||||
$type = $this->request->post('type');
|
||||
if ($type == 'tp' || $type == 'all') {
|
||||
Cache::clear();
|
||||
} else {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
Event::trigger('cacheClearAfter', $this->app);
|
||||
$this->success(__('Cache cleaned~'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function terminal(): void
|
||||
{
|
||||
(new Terminal())->exec();
|
||||
}
|
||||
}
|
||||
116
app/czg/controller/AliossController.php
Normal file
116
app/czg/controller/AliossController.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
|
||||
use OSS\OssClient;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
class AliossController extends Backend
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
// 获取阿里云oss存储相关配置
|
||||
public function getCredentials()
|
||||
{
|
||||
$commoninfo = Db::connect(config('database.search_library'));
|
||||
$configItems = $commoninfo->name('common_info')->whereIn('type', [66, 67, 69, 70])
|
||||
->column('value', 'type');
|
||||
AlibabaCloud::accessKeyClient($configItems[69], $configItems[70])
|
||||
->regionId('cn-nanjing')
|
||||
->asDefaultClient();
|
||||
try {
|
||||
$result = AlibabaCloud::rpc()->product('Sts')
|
||||
->options([
|
||||
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V1
|
||||
])
|
||||
->version('2015-04-01')
|
||||
->action('AssumeRole')
|
||||
->method('POST')
|
||||
->host($configItems[66]) // Endpoint
|
||||
->scheme('https')
|
||||
->options([
|
||||
'query' => [
|
||||
'RoleArn' => $configItems[67], // 角色ARN
|
||||
'RoleSessionName' => 'test', // 会话名称
|
||||
'DurationSeconds' => 3600, // 凭证有效期(秒)
|
||||
],
|
||||
])
|
||||
->request();
|
||||
// 获取响应中的凭证信息。
|
||||
$credentials = $result['Credentials'];
|
||||
$this->n_success(['data' => [
|
||||
'accessKeyId' => $credentials['AccessKeyId'],
|
||||
'accessKeySecret' => $credentials['AccessKeySecret'],
|
||||
'expiration' => $credentials['Expiration'],
|
||||
'securityToken' => $credentials['SecurityToken'],
|
||||
]]);
|
||||
} catch (ClientException $e) {
|
||||
// 处理客户端异常。
|
||||
echo $e->getErrorMessage() . PHP_EOL;
|
||||
} catch (ServerException $e) {
|
||||
// 处理服务端异常。
|
||||
echo $e->getErrorMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
70
app/czg/controller/AnnouncementController.php
Normal file
70
app/czg/controller/AnnouncementController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class AnnouncementController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
|
||||
public function list()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$where = [];
|
||||
if (!empty($params['title'])) {
|
||||
$where[] = ['title', '=', $params['title']];
|
||||
}
|
||||
|
||||
if (!empty($params['type'])) {
|
||||
$where[] = ['type', '=', $params['type']];
|
||||
}
|
||||
|
||||
if (!empty($params['state'])) {
|
||||
$where[] = ['state', '=', $params['state']];
|
||||
}
|
||||
|
||||
if (!empty($params['id'])) {
|
||||
$where[] = ['id', '=', $params['id']];
|
||||
}
|
||||
|
||||
$this->successWithData(apiconvertToCamelCase(Db::name('announcement')->where($where)->select()->toArray()));
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['create_time'] = getNormalDate();
|
||||
Db::name('announcement')->insert($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
Db::name('announcement')->where([
|
||||
'id' => $params['id']
|
||||
])->update($params);
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
Db::name('announcement')->delete([
|
||||
'id' => $id
|
||||
]);
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
48
app/czg/controller/AppinfoController.php
Normal file
48
app/czg/controller/AppinfoController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class AppinfoController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function list()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$list = Db::name('app')->paginate([
|
||||
'page' => $params['page'],
|
||||
'list_rows' => $params['limit']
|
||||
]);
|
||||
$this->successWithData([
|
||||
'records' => convertToCamelCase($list->items()), // 当前页数据
|
||||
'totalCount' => $list->total(), // 总记录数
|
||||
'currPage' => $list->currentPage(),
|
||||
'last_page' => $list->lastPage(),
|
||||
'pageSize' => $params['limit']
|
||||
]);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
if (empty($params['id'])) {
|
||||
$params['create_at'] = getNormalDate();
|
||||
Db::name('app')->insert($params);
|
||||
}else {
|
||||
Db::name('app')->where([
|
||||
'id' => $params['id']
|
||||
])->update($params);
|
||||
}
|
||||
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
99
app/czg/controller/BannerController.php
Normal file
99
app/czg/controller/BannerController.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class BannerController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
|
||||
public function selectBannerPage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$info = cache('banner'.$params['page'].$params['limit']);
|
||||
if ($info) {
|
||||
$this->successWithData($info);
|
||||
}
|
||||
$info = DatabaseRoute::paginateDb('banner', function ($query) use ($params) {
|
||||
if (!empty($params['classify'])) {
|
||||
$query->where([
|
||||
'classify' => $params['classify']
|
||||
]);
|
||||
}
|
||||
|
||||
if (!empty($params['state'])) {
|
||||
// $query->where([
|
||||
// 'state' => $params['state']
|
||||
// ]);
|
||||
}
|
||||
return $query;
|
||||
}, $params['page'], $params['limit']);
|
||||
cache('banner'.$params['page'].$params['limit'], $info, -1);
|
||||
$this->successWithData($info);
|
||||
|
||||
}
|
||||
|
||||
public function updateBannerById()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
unset($params['course']);
|
||||
Db::name('banner')->where([
|
||||
'id' => $params['id']
|
||||
])->update($params);
|
||||
deleteRedisKeysByPattern('banner*');
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function insertBanner()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['state'] = 2;
|
||||
$params['create_time'] = getNormalDate();
|
||||
unset($params['id']);
|
||||
Db::name('banner')->insert($params);
|
||||
deleteRedisKeysByPattern('banner*');
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
public function deleteBannerById()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$params['ids'] = explode(',', $params['ids']);
|
||||
foreach ($params['ids'] as $id) {
|
||||
Db::name('banner')->delete([
|
||||
'id' => $id
|
||||
]);
|
||||
}
|
||||
deleteRedisKeysByPattern('banner*');
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
// 隐藏banner图
|
||||
public function updateBannerStateById()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['id'])) {
|
||||
$this->error('参数不玩这');
|
||||
}
|
||||
$id = $get['id'];
|
||||
$banner = Db::connect(get_slave_connect_name())->name('banner')->where(['id' => $id])->find();
|
||||
if(!$banner) {
|
||||
$this->error('记录不存在');
|
||||
}
|
||||
Db::connect(get_master_connect_name())->name('banner')->where(['id' => $id])->update([
|
||||
'state' => $banner['state'] == 1 ? 2 : 1,
|
||||
]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
270
app/czg/controller/CashController.php
Normal file
270
app/czg/controller/CashController.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\PayDetails;
|
||||
use app\api\model\CommonInfo;
|
||||
use app\api\model\WithDraw;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\exception\SysException;
|
||||
use think\facade\Db;
|
||||
|
||||
class CashController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
public function selectUserRechargeByUserId()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->successWithData(DatabaseRoute::paginateAllDb('pay_details', function ($query) use ($params) {
|
||||
$query->alias('s')
|
||||
->leftJoin('tb_user u', 'u.user_id = s.user_id')
|
||||
->field([
|
||||
's.id', 's.classify',
|
||||
's.order_id' => 'orderId',
|
||||
's.money',
|
||||
's.user_id' => 'userId',
|
||||
's.pay_diamond' => 'payDiamond',
|
||||
's.diamond',
|
||||
's.state',
|
||||
's.create_time' => 'createTime',
|
||||
's.pay_time' => 'payTime',
|
||||
'u.user_name' => 'userName',
|
||||
'u.phone',
|
||||
]);
|
||||
// 动态条件拼接
|
||||
if (!empty($params['startTime']) && !empty($params['endTime'])) {
|
||||
$query->whereBetween('s.create_time', [$params['startTime'], $params['endTime']]);
|
||||
}
|
||||
|
||||
if (!empty($params['userName'])) {
|
||||
$query->whereLike('u.user_name', '%' . $params['userName'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($params['orderId'])) {
|
||||
$query->whereLike('s.order_id', '%' . $params['orderId'] . '%');
|
||||
}
|
||||
|
||||
if (isset($params['userId'])) {
|
||||
$query->where('u.user_id', $params['userId']);
|
||||
}
|
||||
|
||||
if (isset($params['state']) && $params['state'] !== -1) {
|
||||
$query->where('s.state', $params['state']);
|
||||
} else {
|
||||
$query->where('s.state', '<>', -1);
|
||||
}
|
||||
|
||||
|
||||
return $query;
|
||||
}, $params['page'], $params['limit'], 's.create_time'));
|
||||
}
|
||||
|
||||
|
||||
public function statisticsIncomeMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
// 调用统计服务方法
|
||||
$sumMoney = \app\admin\model\Cash::statisticsIncomeMoney($get['time'], $get['flag'], null);
|
||||
$courseMoney = \app\admin\model\Cash::statisticsIncomeMoney($get['time'], $get['flag'], 1);
|
||||
$vipMoney = \app\admin\model\Cash::statisticsIncomeMoney($get['time'], $get['flag'], 2);
|
||||
|
||||
// 构建返回数据
|
||||
$map = [
|
||||
'sumMoney' => is_null($sumMoney) ? 0.00 : $sumMoney,
|
||||
'courseMoney' => is_null($courseMoney) ? 0.00 : $courseMoney,
|
||||
'vipMoney' => is_null($vipMoney) ? 0.00 : $vipMoney
|
||||
];
|
||||
$this->n_success(['data' => $map]); ;
|
||||
}
|
||||
|
||||
// 财务提现统计
|
||||
public function statisticsCashMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$time = $get['time'];
|
||||
$flag = $get['flag'];
|
||||
// 验证时间格式并转换为时间戳
|
||||
$timestamp = strtotime($time);
|
||||
if ($timestamp === false) {
|
||||
$this->error('无效的时间格式,请使用 yyyy-MM-dd 格式');
|
||||
}
|
||||
|
||||
// 初始化开始和结束时间(默认按日)
|
||||
$startTime = date('Y-m-d 00:00:00', $timestamp);
|
||||
$endTime = date('Y-m-d 23:59:59', $timestamp);
|
||||
|
||||
// 根据flag调整时间范围
|
||||
if ($flag == 2) {
|
||||
// 按月:当月第一天 00:00:00 至 当月最后一天 23:59:59
|
||||
$startTime = date('Y-m-01 00:00:00', $timestamp); // 当月1号
|
||||
$lastDay = date('t', $timestamp); // 获取当月总天数(t是原生格式化符)
|
||||
$endTime = date('Y-m-' . $lastDay . ' 23:59:59', $timestamp);
|
||||
} elseif ($flag == 3) {
|
||||
// 按年:当年第一天 00:00:00 至 当年最后一天 23:59:59
|
||||
$startTime = date('Y-01-01 00:00:00', $timestamp); // 当年1月1号
|
||||
$endTime = date('Y-12-31 23:59:59', $timestamp); // 当年12月31号
|
||||
}
|
||||
|
||||
$sumMoney = DatabaseRoute::getAllDbData('cash_out', function($query) use ($startTime, $endTime) {
|
||||
$query->where(['state' => 1]);
|
||||
$query->whereBetween('create_at', [$startTime, $endTime]);
|
||||
return $query;
|
||||
})->sum('money');
|
||||
|
||||
$countMoney = DatabaseRoute::getAllDbData('cash_out', function($query) use ($startTime, $endTime) {
|
||||
$query->whereBetween('create_at', [$startTime, $endTime]);
|
||||
return $query;
|
||||
})->count();
|
||||
|
||||
$stayMoney = DatabaseRoute::getAllDbData('cash_out', function($query) use ($startTime, $endTime) {
|
||||
$query->where(['state' => 0]);
|
||||
$query->whereBetween('create_at', [$startTime, $endTime]);
|
||||
return $query;
|
||||
})->count();
|
||||
|
||||
$map = [
|
||||
// 金额字段,若为null则赋值0.00(保留两位小数)
|
||||
'sumMoney' => is_null($sumMoney) ? 0.00 : (float)$sumMoney,
|
||||
// 计数字段,若为null则赋值0(整数)
|
||||
'countMoney' => is_null($countMoney) ? 0 : (int)$countMoney,
|
||||
// 待处理金额字段,处理逻辑同上
|
||||
'stayMoney' => is_null($stayMoney) ? 0 : (int)$stayMoney
|
||||
];
|
||||
$this->n_success(['data' => $map]);
|
||||
}
|
||||
|
||||
// 查询所有用户充值信息列表
|
||||
public function selectUserRecharge()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(!empty($get['state']) && $get['state'] == -1) {
|
||||
$get['state'] = null;
|
||||
}
|
||||
$get['startTime'] = date('Y-m-d 00:00:00', strtotime($get['startTime']));
|
||||
$get['endTime'] = date('Y-m-d 23:59:59', strtotime($get['endTime']));
|
||||
$this->n_success(['data' => \app\admin\model\Cash::selectPayDetails($get)]);
|
||||
}
|
||||
|
||||
|
||||
public function payMember()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$time = $get['time'];$flag = $get['flag'];$payClassify = empty($get['payClassify'])?null:$get['payClassify'];
|
||||
// 1. 统计总支付金额(不指定分类)
|
||||
$sumMoney = PayDetails::selectSumPayByClassify(null, $flag, $time, $payClassify);
|
||||
|
||||
// 2. 按支付渠道分别统计(1-8对应不同渠道)
|
||||
$channelMoneys = [
|
||||
1 => PayDetails::selectSumPayByClassify(1, $flag, $time, $payClassify), // 微信App
|
||||
2 => PayDetails::selectSumPayByClassify(2, $flag, $time, $payClassify), // 微信公众号
|
||||
3 => PayDetails::selectSumPayByClassify(3, $flag, $time, $payClassify), // 微信小程序
|
||||
4 => PayDetails::selectSumPayByClassify(4, $flag, $time, $payClassify), // 支付宝App
|
||||
5 => PayDetails::selectSumPayByClassify(5, $flag, $time, $payClassify), // 支付宝H5
|
||||
6 => PayDetails::selectSumPayByClassify(6, $flag, $time, $payClassify), // 抖音
|
||||
7 => PayDetails::selectSumPayByClassify(7, $flag, $time, $payClassify), // 苹果
|
||||
8 => PayDetails::selectSumPayByClassify(8, $flag, $time, $payClassify) // 快手
|
||||
];
|
||||
|
||||
// 3. 构建结果映射(处理null值,默认为0.00)
|
||||
$result = [
|
||||
'sumMoney' => $sumMoney ?? 0.00,
|
||||
'weiXinAppMoney' => $channelMoneys[1] ?? 0.00,
|
||||
'weiXinGZHMoney' => $channelMoneys[2] ?? 0.00,
|
||||
'weiXinXCXMoney' => $channelMoneys[3] ?? 0.00,
|
||||
'zhiFuBaoAppMoney' => $channelMoneys[4] ?? 0.00,
|
||||
'zhiFuBaoH5Money' => $channelMoneys[5] ?? 0.00,
|
||||
'dyMoney' => $channelMoneys[6] ?? 0.00,
|
||||
'iosMoney' => $channelMoneys[7] ?? 0.00,
|
||||
'ksMoney' => $channelMoneys[8] ?? 0.00
|
||||
];
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
public static function send($userInfo, $title, $content)
|
||||
{
|
||||
if (!empty($userInfo['client_id'])) {
|
||||
|
||||
}
|
||||
|
||||
Db::name('message_info')->insert([
|
||||
'content' => $content,
|
||||
'title' => $title,
|
||||
'state' => 5,
|
||||
'is_see' => 0,
|
||||
'user_name' => $userInfo['user_name'],
|
||||
'user_id' => $userInfo['user_id']
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function sendMsg()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
if ($params['flag'] == 1) {
|
||||
$userInfo = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params) {
|
||||
return $query->where([
|
||||
'phone' => $params['phone']
|
||||
]);
|
||||
})->find();
|
||||
|
||||
if (!$userInfo) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
$this->send($userInfo, $params['title'], $params['content']);
|
||||
|
||||
}else{
|
||||
$userList = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params) {
|
||||
return $query;
|
||||
})->list();
|
||||
$chunks = array_chunk($userList, ceil(count($userList) / 3));
|
||||
pushQueue($chunks[0]);
|
||||
pushQueue($chunks[1]);
|
||||
pushQueue($chunks[2]);
|
||||
|
||||
}
|
||||
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 用户提现记录
|
||||
public function selectPayDetails()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$cashOut = [];
|
||||
if(isset($get['userId'])) {
|
||||
$cashOut['userId'] = $get['userId'];
|
||||
}
|
||||
$res = \app\admin\model\Cash::selectCashOutList($get['page'], $get['limit'], $cashOut);
|
||||
$this->n_success(['data' => $res]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提现接口
|
||||
*/
|
||||
public function withdraw()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$userId = $get['userId'] ?? null;
|
||||
$money = $get['money'] ?? null;
|
||||
$msg = $get['msg'] ?? null;
|
||||
// 验证验证码是否为空
|
||||
if (empty($msg)) {
|
||||
$this->error('请输入验证码');
|
||||
}
|
||||
debounce("withdraw:".$userId, 30);
|
||||
runWithLock("lock:withdraw:{$userId}", 300, function () use ($userId, $money, $msg) {
|
||||
WithDraw::goWithDraw($userId, $money, $msg, true, true);
|
||||
});
|
||||
$this->success('提现成功,将在三个工作日内到账,请耐心等待!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
325
app/czg/controller/CashOutAuditController.php
Normal file
325
app/czg/controller/CashOutAuditController.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\facade\Token;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use app\utils\WuYouPayUtils;
|
||||
use extend\ba\Random;
|
||||
use think\facade\Db;
|
||||
use think\Collection;
|
||||
|
||||
class CashOutAuditController extends Backend
|
||||
{
|
||||
|
||||
protected array $noNeedPermission = ['page', 'alipaytransfersummaryquery'];
|
||||
|
||||
// 提现列表
|
||||
public function page()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$cashOut = [];
|
||||
if (!empty($params)) {
|
||||
$cashOut = array_intersect_key($params, array_flip([
|
||||
'user_id', 'user_name', 'zhifubao_name', 'zhifubao',
|
||||
'bank_name', 'user_type', 'state', 'start_time', 'end_time'
|
||||
]));
|
||||
}
|
||||
$cashOutList = DatabaseRoute::paginateAllDb('cash_out', function ($query) use($cashOut) {
|
||||
if (!empty($cashOut['user_id'])) {
|
||||
$query->where('user_id', $cashOut['user_id']);
|
||||
}
|
||||
// 用户名模糊查询(对应Java的userName匹配zhifubaoName)
|
||||
if (!empty($cashOut['user_name'])) {
|
||||
$query->whereLike('zhifubao_name', "%{$cashOut['user_name']}%");
|
||||
}
|
||||
// 支付宝姓名模糊查询
|
||||
if (!empty($cashOut['zhifubao_name'])) {
|
||||
$query->whereLike('zhifubao_name', "%{$cashOut['zhifubao_name']}%");
|
||||
}
|
||||
// 支付宝账号模糊查询
|
||||
if (!empty($cashOut['zhifubao'])) {
|
||||
$query->whereLike('zhifubao', "%{$cashOut['zhifubao']}%");
|
||||
}
|
||||
// 银行名称模糊查询
|
||||
if (!empty($cashOut['bank_name'])) {
|
||||
$query->whereLike('bank_name', "%{$cashOut['bank_name']}%");
|
||||
}
|
||||
// 用户类型条件
|
||||
if (isset($cashOut['user_type']) && $cashOut['user_type'] !== '') {
|
||||
$query->where('user_type', $cashOut['user_type']);
|
||||
}
|
||||
// 状态条件
|
||||
if (isset($cashOut['state']) && $cashOut['state'] !== '') {
|
||||
$query->where('state', $cashOut['state']);
|
||||
}
|
||||
// 时间范围条件
|
||||
$startTime = isset($cashOut['start_time']) ? $cashOut['start_time'] : '';
|
||||
$endTime = isset($cashOut['end_time']) ? $cashOut['end_time'] : '';
|
||||
if ($startTime && $endTime) {
|
||||
$query->whereBetween('create_at', $startTime, $endTime);
|
||||
} elseif ($startTime) {
|
||||
$query->where('create_at', '>=', $startTime);
|
||||
} elseif ($endTime) {
|
||||
$query->where('create_at', '<=', $endTime);
|
||||
}
|
||||
return $query;
|
||||
}, $params['page'], $params['limit'], 'create_at');
|
||||
|
||||
// 补充关联数据
|
||||
if (!empty($cashOutList['list'])) {
|
||||
// 提取所有用户ID
|
||||
$userIdList = Collection::make($cashOutList['list'])->column('user_id');
|
||||
$userIdList = array_unique(array_filter($userIdList)); // 去重并过滤空值
|
||||
if($userIdList) {
|
||||
$countInfoList_n = [];
|
||||
foreach ($userIdList as $k => $user_id) {
|
||||
$db_name = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $user_id]));
|
||||
$userNameMap[] = $db_name->name('tb_user')->where(['user_id' => $user_id])->field('user_id, user_name')
|
||||
->select()
|
||||
->column('user_name', 'user_id');
|
||||
|
||||
$countInfoList[] = $db_name
|
||||
->query("SELECT user_id as userId,
|
||||
ROUND(SUM(CASE WHEN state = 1 THEN money ELSE 0 END), 2) AS total,
|
||||
COUNT(CASE WHEN state = 1 THEN 1 END) AS count,
|
||||
ROUND(SUM(CASE WHEN state = 3 THEN money ELSE 0 END), 2) AS verifyTotal,
|
||||
COUNT(CASE WHEN state = 3 THEN 1 END) AS verifyCount
|
||||
FROM cash_out
|
||||
WHERE user_id=" . $user_id . "
|
||||
GROUP BY user_id")[0];
|
||||
}
|
||||
$countInfoMap = [];
|
||||
foreach ($countInfoList as $item) {
|
||||
|
||||
$countInfoMap[$item['userId']] = $item;
|
||||
}
|
||||
|
||||
// 补充字段到结果集
|
||||
foreach ($cashOutList['list'] as &$item) {
|
||||
// 补充用户名
|
||||
$item['user_name'] = $userNameMap[$item['user_id']] ?? '';
|
||||
|
||||
// 补充统计信息
|
||||
if (isset($countInfoMap[$item['user_id']])) {
|
||||
$countInfo = $countInfoMap[$item['user_id']];
|
||||
$item['total'] = $countInfo['total'];
|
||||
$item['count'] = $countInfo['count'];
|
||||
$item['verify_count'] = $countInfo['verifyCount'];
|
||||
$item['verify_total'] = $countInfo['verifyTotal'];
|
||||
} else {
|
||||
$item['total'] = 0;
|
||||
$item['count'] = 0;
|
||||
$item['verify_count'] = 0;
|
||||
$item['verify_total'] = 0;
|
||||
}
|
||||
}
|
||||
unset($item); // 解除引用
|
||||
}
|
||||
}
|
||||
$this->n_success(['page' => $cashOutList]);
|
||||
}
|
||||
|
||||
//
|
||||
public function alipaytransfersummaryquery()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
// 校验支付宝账户名
|
||||
if (empty($get['alipayAccountName'])) {
|
||||
$this->error('支付宝账号不能为空');
|
||||
}
|
||||
$alipayAccountName = $get['alipayAccountName'];
|
||||
// 初始化返回数据结构
|
||||
$data = [
|
||||
'alipayAccountName' => $alipayAccountName,
|
||||
'sum' => 0.00,
|
||||
'count' => 0,
|
||||
'list' => []
|
||||
];
|
||||
|
||||
$cashOutList = DatabaseRoute::getAllDbData('cash_out', function ($query) use($alipayAccountName) {
|
||||
return $query->where('state', 1)
|
||||
->where('zhifubao_name', $alipayAccountName);
|
||||
})->select()->toArray();
|
||||
// 无记录则直接返回
|
||||
if (empty($cashOutList)) {
|
||||
$this->n_success($data);
|
||||
}
|
||||
// 按用户ID分组(替代Java的Collectors.groupingBy)
|
||||
$groupedByUserId = [];
|
||||
foreach ($cashOutList as $record) {
|
||||
$userId = $record['user_id'];
|
||||
$groupedByUserId[$userId][] = $record;
|
||||
}
|
||||
|
||||
|
||||
// 处理每个用户的汇总数据
|
||||
foreach ($groupedByUserId as $userId => $userRecords) {
|
||||
// 计算该用户的提现总金额
|
||||
$subSum = array_sum(array_column($userRecords, 'money'));
|
||||
|
||||
// 初始化用户记录
|
||||
$record = [
|
||||
'userId' => $userId,
|
||||
'userName' => '未知',
|
||||
'inviterCode' => '',
|
||||
'phone' => '',
|
||||
'zhiFuBaoName' => implode(' / ', array_unique(array_column($userRecords, 'zhifubao_name'))),
|
||||
'zhiFuBao' => implode(' / ', array_unique(array_column($userRecords, 'zhifubao'))),
|
||||
'subTotal' => $subSum,
|
||||
'subCount' => count($userRecords)
|
||||
];
|
||||
|
||||
// 查询用户信息
|
||||
$userEntity = Db::name('user')
|
||||
->where('user_id', $userId)
|
||||
->find();
|
||||
|
||||
// 补充用户信息
|
||||
if ($userEntity) {
|
||||
$record['userId'] = $userEntity['user_id'];
|
||||
$record['userName'] = $userEntity['user_name'];
|
||||
$record['inviterCode'] = $userEntity['inviter_code'];
|
||||
$record['phone'] = $userEntity['phone'];
|
||||
}
|
||||
|
||||
// 添加到结果列表
|
||||
$data['list'][] = $record;
|
||||
|
||||
// 更新总统计
|
||||
$data['sum'] += $subSum;
|
||||
$data['count'] += count($userRecords);
|
||||
}
|
||||
$this->n_success($data);
|
||||
}
|
||||
|
||||
|
||||
public function audit()
|
||||
{
|
||||
$cashOut = $this->request->post();
|
||||
// 1. 验证审核状态
|
||||
$isAgree = $cashOut['isAgree'] ?? null;
|
||||
|
||||
if ($isAgree === null) {
|
||||
$this->error("请选择同意或者拒绝!");
|
||||
}
|
||||
// 拒绝时必须填写原因
|
||||
if ($isAgree == 0 && trim($cashOut['refund'] ?? '') === '') {
|
||||
$this->error("请输入拒绝原因!");
|
||||
}
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('cash_out', ['user_id' => $cashOut['userId']], true));
|
||||
|
||||
// 2. 查询提现申请实体
|
||||
$entity = $db->name('cash_out')
|
||||
->where('user_id', $cashOut['userId'])
|
||||
->where('id', $cashOut['id'])
|
||||
->find();
|
||||
if (!$entity) {
|
||||
$this->error("提现申请不存在!");
|
||||
}
|
||||
|
||||
// 3. 验证申请状态(必须为待审核状态:state=3)
|
||||
if ($entity['state'] != 3) {
|
||||
$this->error("提现申请状态无效,请刷新后重试!");
|
||||
}
|
||||
|
||||
// 4. 根据审核结果更新状态
|
||||
if ($isAgree == 1) {
|
||||
$entity['state'] = 0; // 同意
|
||||
} else {
|
||||
$entity['state'] = 2; // 拒绝
|
||||
$entity['refund'] = $cashOut['refund']; // 拒绝原因
|
||||
}
|
||||
|
||||
// 5. 验证用户/代理信息是否存在
|
||||
$isUser = true;
|
||||
if ($entity['user_type'] == 2) {
|
||||
$isUser = false; // 代理用户
|
||||
}
|
||||
|
||||
if ($isUser) {
|
||||
// 普通用户
|
||||
$user = $db->name('tb_user')->where('user_id', $entity['user_id'])->find();
|
||||
if (!$user) {
|
||||
$this->error("提现用户信息不存在!");
|
||||
}
|
||||
} else {
|
||||
// 代理用户
|
||||
$sysUser = $db->name('sys_user')->where('user_id', $entity['user_id'])->find();
|
||||
if (!$sysUser) {
|
||||
$this->error("提现代理信息不存在!");
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 拒绝时退回金额并返回
|
||||
if ($isAgree == 0) {
|
||||
\app\admin\model\Cash::backCashAmount($entity, $db);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
// 7. 同意时处理提现逻辑
|
||||
$isHistoryData = false;
|
||||
// 历史数据判断(无银行名称的普通用户)
|
||||
if ($isUser && trim($entity['bank_name'] ?? '') === '') {
|
||||
$isHistoryData = true;
|
||||
}
|
||||
|
||||
// 更新状态为处理中
|
||||
$entity['state'] = 4;
|
||||
$db->name('cash_out')
|
||||
->where('user_id', $entity['user_id'])
|
||||
->where('id', $entity['id'])
|
||||
->update([
|
||||
'state' => 4
|
||||
]);
|
||||
|
||||
// 生成订单号(为空时)
|
||||
if (trim($entity['order_number'] ?? '') === '') {
|
||||
$entity['order_number'] = Random::generateRandomPrefixedId(19);
|
||||
$db->name('cash_out')
|
||||
->where('id', $entity['id'])
|
||||
->update(['order_number' => $entity['order_number']]);
|
||||
}
|
||||
|
||||
// 8. 调用支付接口执行提现
|
||||
$baseResp = WuYouPayUtils::extractOrder(
|
||||
$isHistoryData,
|
||||
$entity['order_number'],
|
||||
$entity['user_id'],
|
||||
$entity['money'],
|
||||
$isUser,
|
||||
$entity['zhifubao'] ?? '',
|
||||
$entity['zhifubao_name'] ?? '',
|
||||
$entity['bank_name'] ?? '',
|
||||
empty($entity['province']) ? '1' : $entity['province'],
|
||||
empty($entity['city']) ? '1' : $entity['city'],
|
||||
empty($entity['bank_branch']) ? '1' : $entity['bank_branch']
|
||||
);
|
||||
|
||||
// 9. 根据支付结果更新状态
|
||||
$updateData = [];
|
||||
if (isset($baseResp['status']) && ($baseResp['status'] == 2 || $baseResp['status'] == 10000)) {
|
||||
$entity['state'] = 1; // 提现成功
|
||||
} elseif (!empty($baseResp['error_msg'])) {
|
||||
$entity['state'] = 2; // 提现失败
|
||||
if (strpos($baseResp['error_msg'], '收款人账户号出款属性不匹配') !== false) {
|
||||
$entity['refund'] = "提现失败,请检查收款账号与收款人姓名后重试。";
|
||||
} else {
|
||||
$entity['refund'] = $baseResp['error_msg'];
|
||||
}
|
||||
\app\admin\model\Cash::backCashAmount($entity, $db); // 失败时退回金额
|
||||
} elseif (!empty($baseResp['msg'])) {
|
||||
$entity['state'] = 2; // 提现失败
|
||||
$entity['refund'] = "提现失败,请检查收款账号与收款人姓名后重试。";
|
||||
\app\admin\model\Cash::backCashAmount($entity, $db); // 失败时退回金额
|
||||
}
|
||||
// 调用用户ID更新方法(原updateByUserId)
|
||||
\app\admin\model\Cash::updateByUserId($entity, $db);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
44
app/czg/controller/CommonController.php
Normal file
44
app/czg/controller/CommonController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class CommonController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function info()
|
||||
{
|
||||
$condition = $this->request->param();
|
||||
$this->successWithData(Db::name('common_info')->where([
|
||||
'condition_from' => $condition['condition']
|
||||
])->select()->toArray());
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['create_at'] = getNormalDate();
|
||||
Db::name('common_info')->where([
|
||||
'id' => $params['id']
|
||||
])->update(convertKeysCamelToSnakeRecursive($params));
|
||||
|
||||
$info = Db::name('common_info')->where([
|
||||
'id' => $params['id']
|
||||
])->find();
|
||||
cache('common_info:'.$info['type'], null);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function type()
|
||||
{
|
||||
$get = $this->request->param();
|
||||
if(empty($get['num'])) {
|
||||
$this->error('type 不能为空');
|
||||
}
|
||||
$data = convertToCamelCase(Db::connect(config('database.search_library'))->name('common_info')->where('type', $get['num'])->find());
|
||||
$this->success('ok', $data);
|
||||
}
|
||||
}
|
||||
34
app/czg/controller/CompletAwardController.php
Normal file
34
app/czg/controller/CompletAwardController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
|
||||
use OSS\OssClient;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
class CompletAwardController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['insertCompletAward'];
|
||||
public function insertCompletAward()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
$post['create_time'] = date('Y-m-d H:i:s');
|
||||
$data = [];
|
||||
foreach ($post as $k => $v) {
|
||||
$data[toSnakeCase($k)] = $v;
|
||||
}
|
||||
unset($data['invite_img']);
|
||||
unset($data['id']);
|
||||
$db->name('complet_award')->insert($data);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
62
app/czg/controller/CourseClassificationController.php
Normal file
62
app/czg/controller/CourseClassificationController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class CourseClassificationController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'selectCourseClassification', 'updateCourseClassification', 'insertCourseClassification', 'updateDelete'];
|
||||
|
||||
public function selectCourseClassification()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
if (!isset($params['page'])) {
|
||||
$params['page'] = 1;
|
||||
}
|
||||
if (!isset($params['limit'])) {
|
||||
$params['limit'] = 10;
|
||||
}
|
||||
|
||||
$this->n_success(['data' => DatabaseRoute::paginateDb('course_classification', function ($query) use ($params) {
|
||||
if (isset($params['classificationName'])) {
|
||||
$query->whereLike('classification_name', '%' . $params['classificationName'] . '%');
|
||||
}
|
||||
return $query->where([
|
||||
'is_delete' => 0
|
||||
]);
|
||||
}, $params['page'], $params['limit'])]);
|
||||
}
|
||||
|
||||
public function insertCourseClassification()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['is_delete'] = 0;
|
||||
Db::name('course_classification')->insert($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function updateCourseClassification()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
Db::name('course_classification')->where([
|
||||
'classification_id' => $params['classification_id']
|
||||
])->update($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function updateDelete()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
Db::name('course_classification')->where([
|
||||
'classification_id' => $params['id']
|
||||
])->delete();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
23
app/czg/controller/CourseCollectController.php
Normal file
23
app/czg/controller/CourseCollectController.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\UserIntegral;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class CourseCollectController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['selectByUserId'];
|
||||
|
||||
|
||||
public function selectByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(\app\api\model\Course::selectByUserId($get, $this->auth->user_id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
139
app/czg/controller/CourseController.php
Normal file
139
app/czg/controller/CourseController.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class CourseController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney'];
|
||||
|
||||
|
||||
public function selectCourse()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$res = \app\api\model\Course::selectCourse($params);
|
||||
$this->successWithData($res['data']);
|
||||
}
|
||||
|
||||
public function insertCourse()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['is_delete'] = 0;
|
||||
$params['create_time'] = getNormalDate();
|
||||
$params['course_id'] = Random::generateRandomPrefixedId();
|
||||
$params['banner_id'] = empty($params['banner_id']) ? null : $params['banner_id'];
|
||||
if ($params['course_type'] == 2 || $params['course_type'] == 3) {
|
||||
$copy = unserialize(serialize($params));
|
||||
unset($copy['remark']);
|
||||
$id = Db::name('course')->insert($copy);
|
||||
DatabaseRoute::getDb('course_details', $id, true)->insert([
|
||||
'course_id' => $id,
|
||||
'video_url' => $params['remark'] ?? '',
|
||||
'view_count' => 0,
|
||||
'play_complete_count' => 0,
|
||||
]);
|
||||
}else {
|
||||
unset($params['remark']);
|
||||
$id = Db::name('course')->insert($params);
|
||||
}
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function updateCourse()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
unset($params['banner_id']);
|
||||
Db::name('course')->where([
|
||||
'course_id' => $params['course_id']
|
||||
])->update($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function selectCourseById()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$where = [
|
||||
'course_id' => $params['id']
|
||||
];
|
||||
if (!empty($params['good'])) {
|
||||
if ($params['good'] == 1) {
|
||||
$where['good'] = $params['good'];
|
||||
}else{
|
||||
$where['good'] = $params['good'];
|
||||
}
|
||||
}
|
||||
$this->successWithData(DatabaseRoute::paginateDb('course_details', function ($query) use($where) {
|
||||
$query->where($where);
|
||||
return $query->order('sort', false);
|
||||
}, $params['page'], $params['limit'], [
|
||||
'course_id' => $params['id']
|
||||
]));
|
||||
|
||||
}
|
||||
|
||||
public function updateDelete()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
Db::name('course')->where([
|
||||
'course_id' => $params['id']
|
||||
])->delete();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function updateCourseStatus()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$params['ids'] = explode(',', $params['ids']);
|
||||
foreach ($params['ids'] as $id) {
|
||||
Db::name('course')->where([
|
||||
'course_id' => $id
|
||||
])->update([
|
||||
'status' => $params['status']
|
||||
]);
|
||||
}
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function updateCourseDetails()
|
||||
{
|
||||
$param = $this->request->param();
|
||||
$param['ids'] = explode(',', $param['ids']);
|
||||
foreach ($param['ids'] as $id) {
|
||||
DatabaseRoute::getAllDbData('course_details', function ($query) use ($id, $param) {
|
||||
return $query->where([
|
||||
'course_details_id' => $id
|
||||
]);
|
||||
})->update([
|
||||
'is_price' => bccomp($param['price'],0, 4) == 0 ? 2 : 1,
|
||||
'content' => $param['content'],
|
||||
'title_img' => $param['titleImg'],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function deleteCourseDetailsByIds()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$params['ids'] = explode(',', $params['ids']);
|
||||
foreach ($params['ids'] as $id) {
|
||||
DatabaseRoute::getAllDbData('course_details', function ($query) use ($id) {
|
||||
return $query->where([
|
||||
'course_details_id' => $id
|
||||
]);
|
||||
})->delete();
|
||||
}
|
||||
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
56
app/czg/controller/CourseDetailsController.php
Normal file
56
app/czg/controller/CourseDetailsController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class CourseDetailsController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney'];
|
||||
|
||||
public function insertCourseDetails()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['create_time'] = getNormalDate();
|
||||
$params['course_details_id'] = Random::generateRandomPrefixedId();
|
||||
if (empty($params['good_num'])) {
|
||||
$params['good_num'] = 0;
|
||||
}
|
||||
DatabaseRoute::getDb('course_details', [
|
||||
'course_id' => $params['course_id']
|
||||
], true)->insert($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function updateCourseDetails()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$db = Db::connect(DatabaseRoute::getConnection('course_details', ['course_id' => $params['course_id']], true));
|
||||
$course_details_id = $params['course_details_id'];
|
||||
unset($params['course_id']);
|
||||
unset($params['course_details_id']);
|
||||
$db->name('course_details')->where('course_details_id', $course_details_id)->update($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function deleteCourseDetails()
|
||||
{
|
||||
$ids = $this->request->param('ids');
|
||||
$ids = explode(',', $ids);
|
||||
foreach ($ids as $id) {
|
||||
DatabaseRoute::deleteAllDbDirect('course_details', function ($query) use ($id) {
|
||||
return $query->where([
|
||||
'course_details_id' => $id
|
||||
]);
|
||||
});
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
20
app/czg/controller/DashboardController.php
Normal file
20
app/czg/controller/DashboardController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class DashboardController extends Backend
|
||||
{
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$this->success('', [
|
||||
'remark' => get_route_remark()
|
||||
]);
|
||||
}
|
||||
}
|
||||
122
app/czg/controller/DiscSpinningAmountController.php
Normal file
122
app/czg/controller/DiscSpinningAmountController.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
class DiscSpinningAmountController extends Backend
|
||||
{
|
||||
|
||||
|
||||
protected array $noNeedPermission = ['selectDiscSpinningAmount', 'insertDiscSpinningAmount', 'updateDiscSpinningAmount', 'deleteDiscSpinningAmount'];
|
||||
|
||||
// 查询现金红包 抽奖配置
|
||||
public function selectDiscSpinningAmount()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['page'])) {
|
||||
$get['page'] = 1;
|
||||
}
|
||||
if(empty($get['limit'])) {
|
||||
$get['limit'] = 20;
|
||||
}
|
||||
$db = Db::connect(get_slave_connect_name());
|
||||
$count = $db->name('disc_spinning_amount')->where('type', $get['type'])->count();
|
||||
// 构建查询条件
|
||||
$res = $db->name('disc_spinning_amount')
|
||||
->where('type', $get['type'])
|
||||
->order('status', 'desc')
|
||||
->order('num', 'asc')
|
||||
->order('random', 'asc')
|
||||
->order('max_amount', 'asc')
|
||||
->limit(page($get['page'], $get['limit']))
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($res as $k => &$v) {
|
||||
$scaleFactor = 100;
|
||||
$intValue = (int)round($v['max_amount'] * $scaleFactor, 0);
|
||||
$v['max_amount'] = $intValue / $scaleFactor;
|
||||
|
||||
$intValue = (int)round($v['random'] * $scaleFactor, 0);
|
||||
$v['random'] = $intValue / $scaleFactor;
|
||||
|
||||
}
|
||||
// 转换为前端需要的格式
|
||||
$data = [
|
||||
'totalCount' => $count,
|
||||
'pageSize' => $get['limit'],
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
'currPage' => $get['page'],
|
||||
'list' => null,
|
||||
'records' => $res
|
||||
];
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
// 添加现金红包 抽奖配置
|
||||
public function insertDiscSpinningAmount()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
// 保存数据到数据库
|
||||
$result = Db::name('disc_spinning_amount')->insert([
|
||||
'name' => $post['name'],
|
||||
'random' => $post['random'],
|
||||
'max_amount' => $post['maxAmount'],
|
||||
'type' => $post['type'],
|
||||
'status' => $post['status'],
|
||||
'num' => $post['num'] ?? 0,
|
||||
]);
|
||||
if (!$result) {
|
||||
$this->error("保存转盘金额配置失败");
|
||||
}
|
||||
// 删除Redis缓存(使用Cache门面)
|
||||
$cacheKey = "spinning:amount:{$post['type']}";
|
||||
Cache::delete($cacheKey);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
// 修改现金红包 抽奖配置
|
||||
public function updateDiscSpinningAmount()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
// 保存数据到数据库
|
||||
Db::name('disc_spinning_amount')->where(['id' => $post['id']])->update([
|
||||
'name' => $post['name'],
|
||||
'random' => $post['random'],
|
||||
'max_amount' => $post['maxAmount'],
|
||||
'type' => $post['type'],
|
||||
'status' => $post['status'],
|
||||
'num' => $post['num'],
|
||||
]);
|
||||
// if (!$result) {
|
||||
// $this->error("保存转盘金额配置失败");
|
||||
// }
|
||||
// 删除Redis缓存(使用Cache门面)
|
||||
$cacheKey = "spinning:amount:{$post['type']}";
|
||||
Cache::delete($cacheKey);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function deleteDiscSpinningAmount()
|
||||
{
|
||||
$post = $this->request->param();
|
||||
// 保存数据到数据库
|
||||
$result = Db::name('disc_spinning_amount')->where(['id' => $post['id']])->delete();
|
||||
if (!$result) {
|
||||
$this->error("保存转盘金额配置失败");
|
||||
}
|
||||
// 删除Redis缓存(使用Cache门面)
|
||||
$cacheKey = "spinning:amount";
|
||||
Cache::delete($cacheKey);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
126
app/czg/controller/DiscSpinningController.php
Normal file
126
app/czg/controller/DiscSpinningController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class DiscSpinningController extends Backend
|
||||
{
|
||||
|
||||
protected array $noNeedPermission = ['selectDiscSpinning', 'updateDiscSpinning', 'deleteDiscSpinning', 'insertDiscSpinning'];
|
||||
|
||||
// 查询大转盘
|
||||
public function selectDiscSpinning()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$db = Db::connect(get_slave_connect_name());
|
||||
$count = $db->name('disc_spinning')->where(['disc_type' => $get['source']])->count();
|
||||
$res = $db->name('disc_spinning')->where(['disc_type' => $get['source']])->limit(page($get['page'], $get['limit']), $get['limit'])->order('disc_type', 'asc')->order('odds', 'asc')->select()->toArray();
|
||||
$this->n_success(['data' => [
|
||||
'totalCount' => $count,
|
||||
'pageSize' => $get['limit'],
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
'currPage' => $get['page'],
|
||||
'list' => null,
|
||||
'records' => $res
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
// 修改大转盘
|
||||
public function updateDiscSpinning()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
// if(empty($post['name']) || empty($post['url']) || empty($post['type']) || empty($post['odds']) || empty($post['discType']) || empty($post['id'])) {
|
||||
// $this->error('参数不完整');
|
||||
// }
|
||||
|
||||
// 查询指定类型的奖品列表(按type和id升序排列)
|
||||
$prizes = Db::name('disc_spinning')
|
||||
->where('disc_type', $post['discType'])
|
||||
->order('type', 'asc')
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 处理奖品概率累加
|
||||
$upPrizes = [];
|
||||
$number = 0; // 概率累加值(PHP使用浮点数,需注意精度问题)
|
||||
|
||||
foreach ($prizes as $key => $prize) {
|
||||
// 如果是当前编辑的奖品,使用传入的数据覆盖
|
||||
if ($prize['id'] == $post['id']) {
|
||||
$prizes[$key] = $post;
|
||||
$prize = $post;
|
||||
}
|
||||
|
||||
// 累加概率
|
||||
$number += $prize['odds'];
|
||||
$prizes[$key]['number'] = $number; // 记录累加后的概率值
|
||||
|
||||
// 添加到结果列表
|
||||
$upPrizes[] = convertKeysCamelToSnakeRecursive($prizes[$key]);
|
||||
}
|
||||
|
||||
// 验证概率总和是否超过100
|
||||
if ($number > 100) {
|
||||
$this->error("中奖概率总和 不可超过100");
|
||||
}
|
||||
|
||||
\app\admin\model\DiscSpinning::updateBatchById($upPrizes);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
// 删除大转盘
|
||||
public function deleteDiscSpinning()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if(empty($post['id'])) {
|
||||
$this->error('id不能为空');
|
||||
}
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
if($db->name('disc_spinning')->where(['id' => $post['id']])->delete()) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
// 转盘添加抽奖项
|
||||
public function insertDiscSpinning()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if(empty($post['name']) || empty($post['url']) || empty($post['type']) || empty($post['odds']) || empty($post['discType'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
// 查询指定类型的奖品列表(按type和id升序排列)
|
||||
$prizes = Db::name('disc_spinning')
|
||||
->where('disc_type', $post['discType'])
|
||||
->order('type', 'asc')
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
// 计算当前奖品总概率
|
||||
$totalOdds = 0;
|
||||
foreach ($prizes as &$prize) {
|
||||
$totalOdds += $prize['odds'];
|
||||
$prize['number'] = $totalOdds;
|
||||
}
|
||||
unset($prize); // 释放引用
|
||||
// 计算新增奖品后的总概率
|
||||
$newTotalOdds = $totalOdds + $post['odds'];
|
||||
// 验证概率总和是否超过100
|
||||
if ($newTotalOdds > 100) {
|
||||
$this->error("中奖概率总和 不可超过100");
|
||||
}
|
||||
// 设置创建时间(使用当前时间戳)
|
||||
$post['create_time'] = date('Y-m-d H:i:s');
|
||||
$post['number'] = $post['odds'];
|
||||
\app\admin\model\DiscSpinning::updateBatchById($prizes);
|
||||
Db::name('disc_spinning')->insert($post);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
78
app/czg/controller/ExtSysController.php
Normal file
78
app/czg/controller/ExtSysController.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\CommonInfo;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class ExtSysController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function friendConfig()
|
||||
{
|
||||
$code = 999;
|
||||
$commonInfo = cache('common_info:'.$code);
|
||||
if (!$commonInfo) {
|
||||
$commonInfo = CommonInfo::where([
|
||||
'type' => $code
|
||||
])->find();
|
||||
if($commonInfo) {
|
||||
$commonInfo = $commonInfo->toArray();
|
||||
}
|
||||
cache('common_info:'.$code, $commonInfo, 60 * 60 * 24);
|
||||
}
|
||||
if (!$commonInfo) {
|
||||
$this->success();
|
||||
}
|
||||
|
||||
$this->successWithData([
|
||||
'imageUrl' => $commonInfo['value'],
|
||||
'tips' => $commonInfo['max']
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function friendConfigSave()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
if (empty($params['imageUrl'])) {
|
||||
$this->error('顶部图片地址不能为空');
|
||||
}
|
||||
|
||||
if (empty($params['tips'])) {
|
||||
$this->error('邀请文案不能为空');
|
||||
}
|
||||
|
||||
if (strlen($params['tips']) > 20) {
|
||||
$this->error('邀请文案不能大于20个字符');
|
||||
}
|
||||
|
||||
$commonInfo = (new CommonInfo())->getByCode(999);
|
||||
if ($commonInfo) {
|
||||
Db::name('common_info')->where([
|
||||
'id' => $commonInfo['id']
|
||||
])->update([
|
||||
'max' => $params['tips'],
|
||||
'value' => $params['imageUrl']
|
||||
]);
|
||||
}else{
|
||||
Db::name('common_info')->insert([
|
||||
'code' => 999,
|
||||
'max' => $params['tips'],
|
||||
'value' => $params['imageUrl'],
|
||||
'min' => '邀请好友配置',
|
||||
'is_app_use' => 1,
|
||||
'create_at' => getNormalDate()
|
||||
]);
|
||||
}
|
||||
cache('common_info:999', Db::name('common_info')->where([
|
||||
'type' => 999
|
||||
])->find());
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
119
app/czg/controller/HelpWordController.php
Normal file
119
app/czg/controller/HelpWordController.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\SysCaptcha;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Random;
|
||||
use think\facade\Db;
|
||||
|
||||
class HelpWordController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['selectHelpClassifyList', 'deleteHelpClassify', 'insertHelpClassify', 'selectHelpWordList'];
|
||||
public function selectHelpClassifyList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$page = $get['page'] ?? 1;
|
||||
$limit = $get['limit'] ?? 10;
|
||||
$types = $get['types'] ?? null;
|
||||
$helpClassifyName = $get['helpClassifyName'] ?? null;
|
||||
$parentId = $get['parentId'] ?? null;
|
||||
$db = Db::connect(get_slave_connect_name());
|
||||
// 构建查询
|
||||
$query = $db->name('help_classify');
|
||||
$query = $query->when($types !== null, function ($query) use ($types) {
|
||||
return $query->where('types', $types);
|
||||
});
|
||||
$query = $query->when(!empty($helpClassifyName), function ($query) use ($helpClassifyName) {
|
||||
return $query->where('help_classify_name', $helpClassifyName);
|
||||
});
|
||||
|
||||
$query = $query->when($parentId !== null, function ($query) use ($parentId) {
|
||||
return $query->where('parent_id', $parentId);
|
||||
});
|
||||
$count = $query->count();
|
||||
$res = $query->order('sort', 'asc')->limit(page($page, $limit), $limit)->select()->toArray();
|
||||
$data = [
|
||||
'totalCount' => $count,
|
||||
'pageSize' => $limit,
|
||||
'totalPage' => ceil($count / $limit),
|
||||
'currPage' => $page,
|
||||
'list' => $res,
|
||||
'records' => $res
|
||||
];
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
// 删除帮助分类
|
||||
public function deleteHelpClassify()
|
||||
{
|
||||
$post = $this->request->param();
|
||||
if(empty($post['helpClassifyId'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
$db->name('help_classify')->where(['help_classify_id' => $post['helpClassifyId']])->delete();
|
||||
$this->success();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 添加帮助分类
|
||||
public function insertHelpClassify()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$createTime = date('Y-m-d H:i:s');
|
||||
if(empty($post['helpClassifyName']) || !isset($post['sort']) || empty($post['state']) || empty($post['types'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
Db::name('help_classify')->insert([
|
||||
'help_classify_id' => Random::generateRandomPrefixedId(),
|
||||
'help_classify_name' => $post['helpClassifyName'],
|
||||
'sort' => $post['sort'],
|
||||
'types' => $post['types'],
|
||||
'create_time' => $createTime,
|
||||
]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
public function selectHelpWordList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$helpClassifyId = $get['helpClassifyId'] ?? null;
|
||||
$helpWordTitle = $get['helpWordTitle'] ?? null;
|
||||
$page = $get['page'] ?? null;
|
||||
$limit = $get['limit'] ?? null;
|
||||
$query = Db::name('help_word');
|
||||
// 条件筛选
|
||||
if (!is_null($helpClassifyId)) {
|
||||
$query->where('help_classify_id', $helpClassifyId);
|
||||
}
|
||||
if (!empty($helpWordTitle)) {
|
||||
$query->where('help_word_title', $helpWordTitle);
|
||||
}
|
||||
// 排序和分页
|
||||
$list = $query->order('sort', 'asc')
|
||||
->page($page, $limit)
|
||||
->limit(page($page, $limit), $limit)
|
||||
->select()
|
||||
->toArray();
|
||||
// 获取总数(用于分页信息)
|
||||
$count = $query->count();
|
||||
$this->n_success(['data' => [
|
||||
'totalCount' => $count,
|
||||
'pageSize' => $get['limit'],
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
'currPage' => $get['page'],
|
||||
'list' => $list,
|
||||
]]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
18
app/czg/controller/IndetcodeController.php
Normal file
18
app/czg/controller/IndetcodeController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\SysCaptcha;
|
||||
use support\Request;
|
||||
|
||||
class IndetcodeController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function getCode(Request $request)
|
||||
{
|
||||
$data = $request->get();
|
||||
if(empty($data['uuid']))$this->error('参数不完整');
|
||||
$this->success('ok', SysCaptcha::getCode($data['uuid'], $request));
|
||||
}
|
||||
}
|
||||
133
app/czg/controller/IndexController.php
Normal file
133
app/czg/controller/IndexController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use Throwable;
|
||||
use ba\ClickCaptcha;
|
||||
use think\facade\Config;
|
||||
use think\facade\Validate;
|
||||
use app\common\facade\Token;
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class IndexController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['logout', 'login'];
|
||||
protected array $noNeedPermission = ['index'];
|
||||
|
||||
/**
|
||||
* 后台初始化请求
|
||||
* @return void
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(): void
|
||||
{
|
||||
$adminInfo = $this->auth->getInfo();
|
||||
$adminInfo['super'] = $this->auth->isSuperAdmin();
|
||||
unset($adminInfo['token'], $adminInfo['refresh_token']);
|
||||
|
||||
$menus = $this->auth->getMenus();
|
||||
if (!$menus) {
|
||||
$this->error(__('No background menu, please contact super administrator!'));
|
||||
}
|
||||
$this->success('', [
|
||||
'adminInfo' => $adminInfo,
|
||||
'menus' => $menus,
|
||||
'siteConfig' => [
|
||||
'siteName' => get_sys_config('site_name'),
|
||||
'version' => get_sys_config('version'),
|
||||
'apiUrl' => Config::get('buildadmin.api_url'),
|
||||
'upload' => keys_to_camel_case(get_upload_config(), ['max_size', 'save_name', 'allowed_suffixes', 'allowed_mime_types']),
|
||||
'cdnUrl' => full_url(),
|
||||
'cdnUrlParams' => Config::get('buildadmin.cdn_url_params'),
|
||||
],
|
||||
'terminal' => [
|
||||
'phpDevelopmentServer' => str_contains($_SERVER['SERVER_SOFTWARE'], 'Development Server'),
|
||||
'npmPackageManager' => Config::get('terminal.npm_package_manager'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
* @return void
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function login(): void
|
||||
{
|
||||
// 检查登录态
|
||||
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);
|
||||
}
|
||||
|
||||
$captchaSwitch = Config::get('buildadmin.admin_login_captcha');
|
||||
|
||||
// 检查提交
|
||||
if ($this->request->isPost()) {
|
||||
$username = $this->request->post('username');
|
||||
$password = $this->request->post('password');
|
||||
$keep = $this->request->post('keep');
|
||||
|
||||
$rule = [
|
||||
'username|' . __('Username') => 'require|length:3,30',
|
||||
'password|' . __('Password') => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
|
||||
];
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
];
|
||||
if ($captchaSwitch) {
|
||||
$rule['captchaId|' . __('CaptchaId')] = 'require';
|
||||
$rule['captchaInfo|' . __('Captcha')] = 'require';
|
||||
|
||||
$data['captchaId'] = $this->request->post('captchaId');
|
||||
$data['captchaInfo'] = $this->request->post('captchaInfo');
|
||||
}
|
||||
$validate = Validate::rule($rule);
|
||||
if (!$validate->check($data)) {
|
||||
$this->error($validate->getError());
|
||||
}
|
||||
|
||||
if ($captchaSwitch) {
|
||||
$captchaObj = new ClickCaptcha();
|
||||
if (!$captchaObj->check($data['captchaId'], $data['captchaInfo'])) {
|
||||
$this->error(__('Captcha error'));
|
||||
}
|
||||
}
|
||||
|
||||
AdminLog::instance()->setTitle(__('Login'));
|
||||
|
||||
$res = $this->auth->login($username, $password, (bool)$keep);
|
||||
if ($res === true) {
|
||||
$this->success(__('Login succeeded!'), [
|
||||
'userInfo' => $this->auth->getInfo()
|
||||
]);
|
||||
} else {
|
||||
$msg = $this->auth->getError();
|
||||
$msg = $msg ?: __('Incorrect user name or password!');
|
||||
$this->error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'captcha' => $captchaSwitch
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员注销
|
||||
* @return void
|
||||
*/
|
||||
public function logout(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$refreshToken = $this->request->post('refreshToken', '');
|
||||
if ($refreshToken) Token::delete((string)$refreshToken);
|
||||
$this->auth->logout();
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
}
|
||||
83
app/czg/controller/IntegralController.php
Normal file
83
app/czg/controller/IntegralController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\UserIntegral;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class IntegralController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['selectByUserId', 'details'];
|
||||
|
||||
|
||||
public function selectByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId is not empty');
|
||||
}
|
||||
|
||||
$data = Db::connect(get_slave_connect_name())->name('user_integral')->where(['user_id' => $get['userId']])->find();
|
||||
$data = [
|
||||
'user_id' => (string)$get['userId'],
|
||||
'integral_num' => !empty($data['integral_num'])?$data['integral_num']:'0',
|
||||
];
|
||||
$this->n_success(['data' => convertToCamelCase($data)]);
|
||||
}
|
||||
|
||||
public function details()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId is not empty');
|
||||
}
|
||||
$this->n_success(['data' => UserIntegral::selectUserIntegralDetailsByUserId($get['page'], $get['limit'], $get['userId'])]);
|
||||
}
|
||||
|
||||
public function updateUserIntegral()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$userId = $post['userId'] ?? $this->error('参数不完整');
|
||||
$type = $post['type'] ?? $this->error('参数不完整');
|
||||
$integral = $post['integral'] ?? $this->error('参数不完整');
|
||||
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
if(UserIntegral::updateIntegral($type, $userId, $integral, $db)) {
|
||||
// 记录积分变动明细
|
||||
$details['classify'] = 2;
|
||||
$details['content'] = $type == 1
|
||||
? "系统增加积分:{$integral}"
|
||||
: "系统减少积分:{$integral}";
|
||||
|
||||
$currentTime = time();
|
||||
$details['create_time'] = date('Y-m-d H:i:s', $currentTime);
|
||||
|
||||
$details['num'] = $integral;
|
||||
$details['type'] = $type;
|
||||
$details['user_id'] = $userId;
|
||||
$db->name('user_integral_details')->insert($details);
|
||||
Db::commit();
|
||||
}
|
||||
$this->success();
|
||||
}catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
31
app/czg/controller/InviteAwardController.php
Normal file
31
app/czg/controller/InviteAwardController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class InviteAwardController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
|
||||
public function selectInviteAwardList()
|
||||
{
|
||||
$inviteList = Db::name('invite_award')->order('invite_count', 'asc')->select();
|
||||
$this->successWithData(buildPageInfo(convertToCamelCase($inviteList->toArray()), true));
|
||||
}
|
||||
|
||||
public function deleteInviteAward()
|
||||
{
|
||||
$post = $this->request->param();
|
||||
$inviteAwardId = !empty($post['inviteAwardId'])?$post['inviteAwardId']:$this->error('参数不完整');
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
if($db->name('invite_award')->where(['invite_award_id' => $inviteAwardId])->delete()) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
}
|
||||
29
app/czg/controller/InviteController.php
Normal file
29
app/czg/controller/InviteController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\UserIntegral;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class InviteController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['selectInviteByUserIdLists'];
|
||||
|
||||
|
||||
public function selectInviteByUserIdLists()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
$user = DatabaseRoute::getDb('tb_user', $get['userId'])->find();
|
||||
if(empty($user)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
return $this->ApiDataReturn(\app\api\model\Invite::selectInviteByUserIdLists($user, $get, 'admin'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
28
app/czg/controller/LoginController.php
Normal file
28
app/czg/controller/LoginController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\Msg;
|
||||
use app\api\model\TbUser;
|
||||
use app\common\model\SysUser;
|
||||
use think\facade\Db;
|
||||
use think\Request;
|
||||
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 LoginController extends Frontend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
// 发送验证码
|
||||
public function sendMsg()
|
||||
{
|
||||
$get = $this->request->route->param();
|
||||
return $this->ApiDataReturn(Msg::sendMsg($get['phone'], $get['event']));
|
||||
}
|
||||
}
|
||||
85
app/czg/controller/MessageController.php
Normal file
85
app/czg/controller/MessageController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\MessageInfo;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class MessageController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney', 'selectMessageByUserId'];
|
||||
|
||||
|
||||
public function page()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$pageInfo = DatabaseRoute::paginateDb('message_info', function ($query) use ($params) {
|
||||
if (!empty($params['state'])) {
|
||||
$query->where([
|
||||
'state' => $params['state']
|
||||
]);
|
||||
}
|
||||
return $query;
|
||||
}, $params['page'], $params['limit']);
|
||||
foreach ($pageInfo['list'] as &$info) {
|
||||
if (!empty($info['user_id'])) {
|
||||
$info['userEntity'] = DatabaseRoute::getDb('tb_user', $info['user_id'])->find();
|
||||
}
|
||||
}
|
||||
|
||||
$this->successWithData($pageInfo);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['create_at'] = getNormalDate();
|
||||
Db::name('message_info')->insert(convertKeysCamelToSnakeRecursive($params));
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
Db::name('message_info')->where([
|
||||
'id' => $params['id']
|
||||
])->update($params);
|
||||
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
Db::name('message_info')->delete([
|
||||
'id' => $params['id']
|
||||
]);
|
||||
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function selectMessageByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$this->n_success(['data' => MessageInfo::selectMessageList($get)]);
|
||||
}
|
||||
|
||||
public function selectMessageByType()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$this->n_success(['data' => MessageInfo::selectMessageList($get)]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
156
app/czg/controller/ModuleController.php
Normal file
156
app/czg/controller/ModuleController.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use Throwable;
|
||||
use ba\Exception;
|
||||
use think\facade\Config;
|
||||
use app\admin\model\AdminLog;
|
||||
use app\admin\library\module\Server;
|
||||
use app\admin\library\module\Manage;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class ModuleController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['state', 'dependentInstallComplete'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$this->success('', [
|
||||
'sysVersion' => Config::get('buildadmin.version'),
|
||||
'installed' => Server::installedList(root_path() . 'modules' . DIRECTORY_SEPARATOR),
|
||||
]);
|
||||
}
|
||||
|
||||
public function state(): void
|
||||
{
|
||||
$uid = $this->request->get("uid/s", '');
|
||||
if (!$uid) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
$this->success('', [
|
||||
'state' => Manage::instance($uid)->getInstallState()
|
||||
]);
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Install module'));
|
||||
$uid = $this->request->get("uid/s", '');
|
||||
$token = $this->request->get("token/s", '');
|
||||
$orderId = $this->request->get("orderId/d", 0);
|
||||
if (!$uid) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
$res = [];
|
||||
try {
|
||||
$res = Manage::instance($uid)->install($token, $orderId);
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
} catch (Throwable $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success('', [
|
||||
'data' => $res,
|
||||
]);
|
||||
}
|
||||
|
||||
public function dependentInstallComplete(): void
|
||||
{
|
||||
$uid = $this->request->get("uid/s", '');
|
||||
if (!$uid) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
try {
|
||||
Manage::instance($uid)->dependentInstallComplete('all');
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
} catch (Throwable $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function changeState(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Change module state'));
|
||||
$uid = $this->request->post("uid/s", '');
|
||||
$state = $this->request->post("state/b", false);
|
||||
if (!$uid) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
$info = [];
|
||||
try {
|
||||
$info = Manage::instance($uid)->changeState($state);
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
} catch (Throwable $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success('', [
|
||||
'info' => $info,
|
||||
]);
|
||||
}
|
||||
|
||||
public function uninstall(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Unload module'));
|
||||
$uid = $this->request->get("uid/s", '');
|
||||
if (!$uid) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
try {
|
||||
Manage::instance($uid)->uninstall();
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
} catch (Throwable $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function update(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Update module'));
|
||||
$uid = $this->request->get("uid/s", '');
|
||||
$token = $this->request->get("token/s", '');
|
||||
$orderId = $this->request->get("orderId/d", 0);
|
||||
if (!$token || !$uid) {
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
try {
|
||||
Manage::instance($uid)->update($token, $orderId);
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
} catch (Throwable $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function upload(): void
|
||||
{
|
||||
AdminLog::instance()->setTitle(__('Upload install module'));
|
||||
$file = $this->request->get("file/s", '');
|
||||
$token = $this->request->get("token/s", '');
|
||||
if (!$file) $this->error(__('Parameter error'));
|
||||
if (!$token) $this->error(__('Please login to the official website account first'));
|
||||
|
||||
$info = [];
|
||||
try {
|
||||
$info = Manage::instance()->upload($token, $file);
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
} catch (Throwable $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success('', [
|
||||
'info' => $info
|
||||
]);
|
||||
}
|
||||
}
|
||||
52
app/czg/controller/MoneyDetailsController.php
Normal file
52
app/czg/controller/MoneyDetailsController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\SysUserMoney;
|
||||
use app\admin\model\SysUserMoneyDetails;
|
||||
use app\admin\model\User;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class MoneyDetailsController extends Backend
|
||||
{
|
||||
|
||||
protected array $noNeedPermission = ['selectUserMoney', 'queryUserMoneyDetails', 'selectSysUserMoney'];
|
||||
|
||||
public function selectUserMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId is not empty');
|
||||
}
|
||||
|
||||
$this->n_success(['data' => User::selectUserMoneyByUserId($get['userId'])]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function queryUserMoneyDetails()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$page = $get['page'];
|
||||
$limit = $get['limit'];
|
||||
$userId = $get['userId'] ?? '';
|
||||
$classify = $get['classify'] ?? null;
|
||||
|
||||
$this->n_success(['data' => SysUserMoneyDetails::queryUserMoneyDetails($page, $limit, $get['sysUserId'] ?? '', $userId, $classify, null, null, null)]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function selectSysUserMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId is not empty');
|
||||
}
|
||||
$this->n_success(['data' => SysUserMoney::selectSysUserMoneyByUserId($get['userId'])]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
498
app/czg/controller/OrderController.php
Normal file
498
app/czg/controller/OrderController.php
Normal file
@@ -0,0 +1,498 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\TbUser;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use ba\Exception;
|
||||
|
||||
class OrderController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
public function deleteOrders($ids)
|
||||
{
|
||||
$idS = explode(",", $ids);
|
||||
foreach ($idS as $id) {
|
||||
DatabaseRoute::deleteAllDbDirect('orders', function ($query) use ($id) {
|
||||
return $query->where([
|
||||
'orders_id' => $id
|
||||
]);
|
||||
});
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function selectOrders()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$this->successWithData(DatabaseRoute::paginateAllDb('orders', function ($query) use ($params) {
|
||||
// 动态拼接查询条件
|
||||
if (!empty($params['userName'])) {
|
||||
$query->whereLike('u.user_name', '%' . $params['userName'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($params['qdCode'])) {
|
||||
$query->where('s.qd_code', $params['qdCode']);
|
||||
}
|
||||
|
||||
if (!empty($params['sysUserName'])) {
|
||||
$query->whereLike('s.username', '%' . $params['sysUserName'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($params['ordersNo'])) {
|
||||
$query->whereLike('o.orders_no', '%' . $params['ordersNo'] . '%');
|
||||
}
|
||||
|
||||
if (isset($params['status']) && $params['status'] !== -1) {
|
||||
$query->where('o.status', $params['status']);
|
||||
}
|
||||
|
||||
if (!empty($params['userId'])) {
|
||||
$query->where('o.user_id', $params['userId']);
|
||||
}
|
||||
|
||||
if (!empty($params['ordersType'])) {
|
||||
$query->where('o.orders_type', $params['ordersType']);
|
||||
}
|
||||
|
||||
if (!empty($params['courseId'])) {
|
||||
$query->where('o.course_id', $params['courseId']);
|
||||
}
|
||||
|
||||
if (!empty($params['sysUserId'])) {
|
||||
$query->where('o.sys_user_id', $params['sysUserId']);
|
||||
}
|
||||
|
||||
// 时间范围
|
||||
if (!empty($params['startTime']) && !empty($params['endTime'])) {
|
||||
$query->whereBetween('o.create_time', [$params['startTime'], $params['endTime']]);
|
||||
} elseif (!empty($params['startTime'])) {
|
||||
$query->where('o.create_time', '>=', $params['startTime']);
|
||||
} elseif (!empty($params['endTime'])) {
|
||||
$query->where('o.create_time', '<=', $params['endTime']);
|
||||
}
|
||||
|
||||
// 排序
|
||||
$query->order('o.create_time', 'desc');
|
||||
return $query->alias('o')
|
||||
->field('o.*, u.user_name as userName, s.username as sysUserName, s.qd_code as qdCode')
|
||||
->leftJoin('tb_user u', 'o.user_id = u.user_id')
|
||||
->leftJoin('sys_user s', 's.user_id = o.sys_user_id');
|
||||
}, $params['page'], $params['limit']));
|
||||
}
|
||||
|
||||
private function sumOrder($params)
|
||||
{
|
||||
// 总收益
|
||||
return DatabaseRoute::getAllDbData('orders', function ($query) use ($params) {
|
||||
// 条件拼接
|
||||
if (!empty($params['sysUserId']) && $params['sysUserId'] != 1) {
|
||||
$query->where('sys_user_id', $params['sysUserId']);
|
||||
}
|
||||
|
||||
if (isset($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
|
||||
if (isset($params['courseId'])) {
|
||||
$query->where('course_id', $params['courseId']);
|
||||
}
|
||||
|
||||
if (isset($params['ordersType'])) {
|
||||
$query->where('orders_type', $params['ordersType']);
|
||||
}
|
||||
|
||||
if (isset($params['flag']) && !empty($params['time'])) {
|
||||
switch ((int)$params['flag']) {
|
||||
case 1:
|
||||
// 按日
|
||||
$query->whereRaw("DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(:time, '%Y-%m-%d')", ['time' => $params['time']]);
|
||||
break;
|
||||
case 2:
|
||||
// 按月
|
||||
$query->whereRaw("DATE_FORMAT(create_time, '%Y-%m') = DATE_FORMAT(:time, '%Y-%m')", ['time' => $params['time']]);
|
||||
break;
|
||||
case 3:
|
||||
// 按年
|
||||
$query->whereRaw("DATE_FORMAT(create_time, '%Y') = DATE_FORMAT(:time, '%Y')", ['time' => $params['time']]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$query->where('pay_way', 9)
|
||||
->where('status', 1); // 强制条件
|
||||
return $query;
|
||||
})->sum('pay_money');
|
||||
}
|
||||
|
||||
|
||||
public function selectCourseOrdersMoneyCount()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
|
||||
$params['ordersType'] = 1;
|
||||
$params['time'] = date('Y-m-d 00:00:00');
|
||||
// 总收益
|
||||
$sumMoney = $this->sumOrder($params);
|
||||
$params['flag'] = 3;
|
||||
$yearMoney = $this->sumOrder($params);
|
||||
$params['flag'] = 2;
|
||||
$monthMoney = $this->sumOrder($params);
|
||||
$params['flag'] = 1;
|
||||
$dayMoney = $this->sumOrder($params);
|
||||
$this->successWithData([
|
||||
'sumMoney' => $sumMoney ?? 0,
|
||||
'yearMoney' => $yearMoney ?? 0,
|
||||
'monthMoney' => $monthMoney ?? 0,
|
||||
'dayMoney' => $dayMoney ?? 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// 订单数量统计
|
||||
public function selectOrdersCountStatisticsByYear()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$startTime = $get['startTime'];
|
||||
$endTime = $get['endTime'];
|
||||
|
||||
// 初始化结果数组
|
||||
$ordersCountList = [];
|
||||
$ordersDaiFuKuanCountList = [];
|
||||
$ordersYiZhiFuCountList = [];
|
||||
$ordersYiTuiKuanLunCountList = [];
|
||||
$dateList = [];
|
||||
|
||||
// 日期处理
|
||||
$currentDate = strtotime($startTime);
|
||||
$endDate = strtotime($endTime);
|
||||
|
||||
// 循环遍历日期范围
|
||||
while ($currentDate <= $endDate) {
|
||||
$date = date('Y-m-d', $currentDate);
|
||||
|
||||
// 总订单数
|
||||
$ordersCount = \app\admin\model\Order::selectOrdersCountStatisticsByYear(1, $date, null);
|
||||
$ordersCountList[] = $ordersCount;
|
||||
|
||||
// 0待支付
|
||||
$ordersDaiFuKuanCount = \app\admin\model\Order::selectOrdersCountStatisticsByYear(1, $date, 0);
|
||||
$ordersDaiFuKuanCountList[] = $ordersDaiFuKuanCount;
|
||||
|
||||
// 1已支付
|
||||
$ordersJinXinCount = \app\admin\model\Order::selectOrdersCountStatisticsByYear(1, $date, 1);
|
||||
$ordersYiZhiFuCountList[] = $ordersJinXinCount;
|
||||
|
||||
// 2已退款
|
||||
$ordersQuXiaoCount = \app\admin\model\Order::selectOrdersCountStatisticsByYear(1, $date, 2);
|
||||
$ordersYiTuiKuanLunCountList[] = $ordersQuXiaoCount;
|
||||
|
||||
// 记录日期
|
||||
$dateList[] = $date;
|
||||
|
||||
// 日期加1天
|
||||
$currentDate = strtotime('+1 day', $currentDate);
|
||||
}
|
||||
$result = [
|
||||
'ordersCountList' => $ordersCountList,
|
||||
'ordersDaiFuKuanCountList' => $ordersDaiFuKuanCountList,
|
||||
'ordersYiZhiFuCountList' => $ordersYiZhiFuCountList,
|
||||
'ordersYiTuiKuanLunCountList' => $ordersYiTuiKuanLunCountList,
|
||||
'year' => $dateList
|
||||
];
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
// 统计分销金币
|
||||
public function selectFenXiaoMoney()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$admin = $this->auth->getAdmin();
|
||||
$sysUserId = $admin['user_id'];
|
||||
$flag = $get['flag'];
|
||||
$time = $get['time'];
|
||||
|
||||
// 1. 分别查询一级、二级和渠道分销金额
|
||||
$oneMoney = \app\admin\model\Order::selectFenXiaoMoney(1, $sysUserId, $flag, $time);
|
||||
$twoMoney = \app\admin\model\Order::selectFenXiaoMoney(2, $sysUserId, $flag, $time);
|
||||
$qdMoney = \app\admin\model\Order::selectFenXiaoMoney(3, $sysUserId, $flag, $time);
|
||||
|
||||
// 2. 计算总分销金额(使用BCMath确保精度)
|
||||
$sumMoney = bcadd(
|
||||
bcadd($oneMoney, $twoMoney, 2), // 一级 + 二级
|
||||
$qdMoney, // + 渠道
|
||||
2 // 精度保留两位小数
|
||||
);
|
||||
|
||||
$result = [
|
||||
'oneMoney' => $oneMoney,
|
||||
'twoMoney' => $twoMoney,
|
||||
'qdMoney' => $qdMoney,
|
||||
'sumMoney' => $sumMoney
|
||||
];
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
// 订单统计
|
||||
public function selectOrdersCount()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$admin = $this->auth->getAdmin();
|
||||
$sysUserId = $admin['user_id'];
|
||||
$flag = $get['flag'];
|
||||
$time = $get['time'];
|
||||
|
||||
// 1. 短剧订单统计(数量)
|
||||
$sumCourseOrdersCount = \app\admin\model\Order::selectOrdersCount(null, 1, $flag, $time, $sysUserId);
|
||||
$daiCourseKeOrdersCount = \app\admin\model\Order::selectOrdersCount(0, 1, $flag, $time, $sysUserId);
|
||||
$wanCourseKeOrdersCount = \app\admin\model\Order::selectOrdersCount(1, 1, $flag, $time, $sysUserId);
|
||||
$tuiCourseOrdersCount = \app\admin\model\Order::selectOrdersCount(2, 1, $flag, $time, $sysUserId);
|
||||
|
||||
// 2. 短剧订单统计(金额)
|
||||
$sumCourseOrdersMoney = \app\admin\model\Order::selectOrdersMoney(null, 1, $flag, $time, null, $sysUserId);
|
||||
$daiCourseOrdersMoney = \app\admin\model\Order::selectOrdersMoney(0, 1, $flag, $time, null, $sysUserId);
|
||||
$wanCourseOrdersMoney = \app\admin\model\Order::selectOrdersMoney(1, 1, $flag, $time, null, $sysUserId);
|
||||
$tuiCourseOrdersMoney = \app\admin\model\Order::selectOrdersMoney(2, 1, $flag, $time, null, $sysUserId);
|
||||
|
||||
// 3. 会员订单统计(数量)
|
||||
$sumMemberOrdersCount = \app\admin\model\Order::selectOrdersCount(null, 2, $flag, $time, $sysUserId);
|
||||
$daiMemberKeOrdersCount = \app\admin\model\Order::selectOrdersCount(0, 2, $flag, $time, $sysUserId);
|
||||
$wanMemberKeOrdersCount = \app\admin\model\Order::selectOrdersCount(1, 2, $flag, $time, $sysUserId);
|
||||
$tuiMemberOrdersCount = \app\admin\model\Order::selectOrdersCount(2, 2, $flag, $time, $sysUserId);
|
||||
|
||||
// 4. 会员订单统计(金额)
|
||||
$sumMemberOrdersMoney = \app\admin\model\Order::selectOrdersMoney(null, 2, $flag, $time, null, $sysUserId);
|
||||
$daiMemberOrdersMoney = \app\admin\model\Order::selectOrdersMoney(0, 2, $flag, $time, null, $sysUserId);
|
||||
$wanMemberOrdersMoney = \app\admin\model\Order::selectOrdersMoney(1, 2, $flag, $time, null, $sysUserId);
|
||||
$tuiMemberOrdersMoney = \app\admin\model\Order::selectOrdersMoney(2, 2, $flag, $time, null, $sysUserId);
|
||||
|
||||
// 5. 提现统计
|
||||
$timestamp = strtotime($time); // 将日期字符串转为时间戳
|
||||
$beginOfDay = date('Y-m-d 00:00:00', $timestamp); // 当天开始时间
|
||||
$endOfDay = date('Y-m-d 23:59:59', $timestamp); // 当天结束时间
|
||||
|
||||
$cashCount = DatabaseRoute::getAllDbData('cash_out', function ($query) use($sysUserId, $beginOfDay) {
|
||||
if (!is_null($sysUserId)) {
|
||||
$query->where(['sys_user_id' => $sysUserId]);
|
||||
}
|
||||
$query->where('state', 1)->where('create_at', '>', $beginOfDay);
|
||||
return $query;
|
||||
})->count();
|
||||
|
||||
|
||||
$cashSum = DatabaseRoute::getAllDbData('cash_out', function ($query) use($sysUserId, $beginOfDay, $endOfDay) {
|
||||
if (!is_null($sysUserId)) {
|
||||
$query->where(['sys_user_id' => $sysUserId]);
|
||||
}
|
||||
$query->whereBetween('create_at', [$beginOfDay, $endOfDay]);
|
||||
return $query;
|
||||
})->sum('money') ?? 0;
|
||||
|
||||
|
||||
|
||||
$cashSum = number_format($cashSum, 2, '.', ''); // 保留两位小数
|
||||
|
||||
// 6. 奖励金额统计
|
||||
$signInAwardMoney = \app\admin\model\Order::selectSignInAwardMoney($flag, $time, $sysUserId);
|
||||
$shareAwardMoney = \app\admin\model\Order::selectShareAwardMoney($flag, $time, $sysUserId);
|
||||
$newUserTaskDoneAwardMoney = \app\admin\model\Order::selectNewUserTaskDoneAwardMoney($flag, $time, $sysUserId);
|
||||
$inviteTaskDoneAwardMoney = \app\admin\model\Order::selectInviteTaskDoneAwardMoney($flag, $time, $sysUserId);
|
||||
|
||||
// 7. 组装结果
|
||||
$result = [
|
||||
// 短剧订单数量
|
||||
'sumCourseOrdersCount' => $sumCourseOrdersCount ?? 0,
|
||||
'daiCourseKeOrdersCount' => $daiCourseKeOrdersCount ?? 0,
|
||||
'wanCourseKeOrdersCount' => $wanCourseKeOrdersCount ?? 0,
|
||||
'tuiCourseOrdersCount' => $tuiCourseOrdersCount ?? 0,
|
||||
// 短剧订单金额
|
||||
'sumCourseOrdersMoney' => $sumCourseOrdersMoney ?? 0.00,
|
||||
'daiCourseOrdersMoney' => $daiCourseOrdersMoney ?? 0.00,
|
||||
'wanCourseOrdersMoney' => $wanCourseOrdersMoney ?? 0.00,
|
||||
'tuiCourseOrdersMoney' => $tuiCourseOrdersMoney ?? 0.00,
|
||||
// 会员订单数量
|
||||
'sumMemberOrdersCount' => $sumMemberOrdersCount ?? 0,
|
||||
'daiMemberKeOrdersCount' => $daiMemberKeOrdersCount ?? 0,
|
||||
'wanMemberKeOrdersCount' => $wanMemberKeOrdersCount ?? 0,
|
||||
'tuiMemberOrdersCount' => $tuiMemberOrdersCount ?? 0,
|
||||
// 会员订单金额
|
||||
'sumMemberOrdersMoney' => $sumMemberOrdersMoney ?? 0.00,
|
||||
'daiMemberOrdersMoney' => $daiMemberOrdersMoney ?? 0.00,
|
||||
'wanMemberOrdersMoney' => $wanMemberOrdersMoney ?? 0.00,
|
||||
'tuiMemberOrdersMoney' => $tuiMemberOrdersMoney ?? 0.00,
|
||||
// 提现数据
|
||||
'cashCount' => $cashCount ?? 0,
|
||||
'cashSum' => $cashSum,
|
||||
// 奖励金额
|
||||
'signInAwardMoney' => $signInAwardMoney ?? 0.00,
|
||||
'shareAwardMoney' => $shareAwardMoney ?? 0.00,
|
||||
'newUserTaskDoneAwardMoney' => $newUserTaskDoneAwardMoney ?? 0.00,
|
||||
'inviteTaskDoneAwardMoney' => $inviteTaskDoneAwardMoney ?? 0.00,
|
||||
];
|
||||
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
public function queryByTradeNo()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if (empty($get['outTradeNo'])) {
|
||||
$this->error('参数不能为空');
|
||||
}
|
||||
$outTradeNo = $get['outTradeNo'];
|
||||
$tradeNo = null;
|
||||
$userId = null;
|
||||
try {
|
||||
// 解析外部交易号(提现回调格式:xxx-xxx:xxx)
|
||||
if (strpos($outTradeNo, '-') !== false && strpos($outTradeNo, ':') !== false) {
|
||||
$parts = explode('-', $outTradeNo);
|
||||
$tradeNo = $parts[0];
|
||||
$userIdPart = explode(':', $parts[1])[0];
|
||||
$userId = (int)$userIdPart;
|
||||
}
|
||||
// 解析支付回调格式(xxx-xxx)
|
||||
elseif (strpos($outTradeNo, '-') !== false) {
|
||||
$parts = explode('-', $outTradeNo);
|
||||
$tradeNo = $parts[0];
|
||||
$userId = (int)$parts[1];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error("交易订单号不合法");
|
||||
}
|
||||
|
||||
// 验证解析结果
|
||||
if (empty($tradeNo) || $userId === null) {
|
||||
$this->error("交易订单号不合法");
|
||||
}
|
||||
|
||||
// 初始化汇总数据
|
||||
$data = [];
|
||||
|
||||
// 查询用户基本信息
|
||||
$user = TbUser::selectUserById($userId);
|
||||
$data['user_info'] = $user ?: [];
|
||||
|
||||
// 查询用户实名认证信息
|
||||
$realNameAuth = \app\api\model\UserInfo::getByUserIdOrSave($userId);
|
||||
$data['auth_info'] = $realNameAuth ?: [];
|
||||
|
||||
// 初始化提现统计(success:成功, fail:失败, auditing:审核中, other:其他)
|
||||
$withdrawTotal = [
|
||||
'success' => ['total' => 0.00, 'count' => 0],
|
||||
'fail' => ['total' => 0.00, 'count' => 0],
|
||||
'auditing' => ['total' => 0.00, 'count' => 0],
|
||||
'other' => ['total' => 0.00, 'count' => 0],
|
||||
];
|
||||
|
||||
// 初始化支付统计(success:成功, fail:失败, unpaid:未支付)
|
||||
$payTotal = [
|
||||
'success' => ['total' => 0.00, 'count' => 0],
|
||||
'fail' => ['total' => 0.00, 'count' => 0],
|
||||
'unpaid' => ['total' => 0.00, 'count' => 0],
|
||||
];
|
||||
|
||||
|
||||
// 查询提现记录并统计
|
||||
$cashOutList = DatabaseRoute::getDb('cash_out', $userId)->select()->toArray();
|
||||
if (!empty($cashOutList)) {
|
||||
// 按状态分组统计总金额和数量
|
||||
$cashOutSum = []; // 金额统计:[状态 => 总金额]
|
||||
$cashOutCount = []; // 数量统计:[状态 => 总条数]
|
||||
|
||||
foreach ($cashOutList as $cash) {
|
||||
$state = $cash['state'];
|
||||
$money = (float)$cash['money'];
|
||||
|
||||
// 累加金额
|
||||
if (!isset($cashOutSum[$state])) {
|
||||
$cashOutSum[$state] = 0.00;
|
||||
}
|
||||
$cashOutSum[$state] += $money;
|
||||
|
||||
// 累加数量
|
||||
if (!isset($cashOutCount[$state])) {
|
||||
$cashOutCount[$state] = 0;
|
||||
}
|
||||
$cashOutCount[$state]++;
|
||||
}
|
||||
|
||||
// 更新成功/失败/审核中状态的统计
|
||||
$withdrawTotal['success'] = [
|
||||
'total' => $cashOutSum[1] ?? 0.00,
|
||||
'count' => $cashOutCount[1] ?? 0
|
||||
];
|
||||
$withdrawTotal['fail'] = [
|
||||
'total' => $cashOutSum[2] ?? 0.00,
|
||||
'count' => $cashOutCount[2] ?? 0
|
||||
];
|
||||
$withdrawTotal['auditing'] = [
|
||||
'total' => $cashOutSum[3] ?? 0.00,
|
||||
'count' => $cashOutCount[3] ?? 0
|
||||
];
|
||||
|
||||
// 统计其他状态(排除1/2/3)
|
||||
$otherStates = [1, 2, 3];
|
||||
$otherMoney = 0.00;
|
||||
$otherCount = 0;
|
||||
foreach ($cashOutList as $cash) {
|
||||
if (!in_array($cash['state'], $otherStates)) {
|
||||
$otherMoney += (float)$cash['money'];
|
||||
$otherCount++;
|
||||
}
|
||||
}
|
||||
$withdrawTotal['other'] = [
|
||||
'total' => $otherMoney,
|
||||
'count' => $otherCount
|
||||
];
|
||||
}
|
||||
$data['withdraw_total'] = $withdrawTotal;
|
||||
|
||||
// 查询支付记录并统计
|
||||
$payDetailsList = DatabaseRoute::getDb('pay_details', $userId)->select()->toArray();
|
||||
if (!empty($payDetailsList)) {
|
||||
// 按状态分组统计总金额和数量
|
||||
$paySum = []; // 金额统计:[状态 => 总金额]
|
||||
$payCount = []; // 数量统计:[状态 => 总条数]
|
||||
|
||||
foreach ($payDetailsList as $pay) {
|
||||
$state = $pay['state'];
|
||||
$money = (float)$pay['money'];
|
||||
|
||||
// 累加金额
|
||||
if (!isset($paySum[$state])) {
|
||||
$paySum[$state] = 0.00;
|
||||
}
|
||||
$paySum[$state] += $money;
|
||||
|
||||
// 累加数量
|
||||
if (!isset($payCount[$state])) {
|
||||
$payCount[$state] = 0;
|
||||
}
|
||||
$payCount[$state]++;
|
||||
}
|
||||
|
||||
// 更新支付统计(1:成功, 2:失败, 0:未支付)
|
||||
$payTotal['success'] = [
|
||||
'total' => $paySum[1] ?? 0.00,
|
||||
'count' => $payCount[1] ?? 0
|
||||
];
|
||||
$payTotal['fail'] = [
|
||||
'total' => $paySum[2] ?? 0.00,
|
||||
'count' => $payCount[2] ?? 0
|
||||
];
|
||||
$payTotal['unpaid'] = [
|
||||
'total' => $paySum[0] ?? 0.00,
|
||||
'count' => $payCount[0] ?? 0
|
||||
];
|
||||
}
|
||||
$data['pay_total'] = $payTotal;
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
63
app/czg/controller/PayClassifyController.php
Normal file
63
app/czg/controller/PayClassifyController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class PayClassifyController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function selectPayClassifyList()
|
||||
{
|
||||
$infos = Db::name('pay_classify')->select()->toArray();
|
||||
foreach ($infos as $k => &$v) {
|
||||
$v['pay_classify_id'] = (string) $v['pay_classify_id'];
|
||||
}
|
||||
$this->successWithData([
|
||||
'currPage' => 1,
|
||||
'pageSize' => count($infos),
|
||||
'totalCount' => count($infos),
|
||||
'totalPage' => 1,
|
||||
'list' => convertToCamelCase($infos)
|
||||
]);
|
||||
}
|
||||
|
||||
public function updatePayClassify()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
if (empty($params['payClassifyId'])) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
unset($params['memberId']);
|
||||
Db::name('pay_classify')->where([
|
||||
'pay_classify_id' => $params['payClassifyId']
|
||||
])->update(convertKeysCamelToSnakeRecursive($params));
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function insertPayClassify()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['create_time'] = getNormalDate();
|
||||
unset($params['memberId']);
|
||||
unset($params['payClassifyId']);
|
||||
Db::name('pay_classify')->insert(convertKeysCamelToSnakeRecursive($params));
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function deletePayClassify()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
if (empty($params['payClassifyId'])) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
Db::name('pay_classify')->delete([
|
||||
'pay_classify_id' => $params['payClassifyId']
|
||||
]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
38
app/czg/controller/SdkController.php
Normal file
38
app/czg/controller/SdkController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\admin\model\UserIntegral;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class SdkController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['getSdkList'];
|
||||
|
||||
|
||||
public function getSdkList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
$sdkINfo = [
|
||||
'sdkRemarks' => $get['sdkRemarks'] ?? null,
|
||||
'status' => $get['status'] ?? null,
|
||||
'typeId' => $get['typeId'] ?? null,
|
||||
'nickName' => $get['nickName'] ?? null,
|
||||
'sdkContent' => $get['sdkContent'] ?? null,
|
||||
];
|
||||
$this->n_success(['data' => [
|
||||
'list' => [],
|
||||
'totalCount' => 0,
|
||||
'totalPage' => 0,
|
||||
'currPage' => 1,
|
||||
'pageSize' => 0,
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
242
app/czg/controller/SysController.php
Normal file
242
app/czg/controller/SysController.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\Msg;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\facade\Token;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
use think\Http;
|
||||
|
||||
class SysController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function login()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
if(empty($data['username']) || empty($data['password']) || empty($data['uuid']) || empty($data['captcha']) || empty($data['adminType'])){
|
||||
$this->n_error('参数不完整');
|
||||
}
|
||||
$uuid = $data['uuid'];
|
||||
$connect = Db::connect(get_slave_connect_name());
|
||||
$captcha = $connect->name('sys_captcha')->where(['uuid' => $uuid, 'code' => $data['captcha']])->find();
|
||||
if(!$captcha) {
|
||||
$this->n_error('验证码错误', [], 500);
|
||||
}
|
||||
$ext_time = strtotime($captcha['expire_time']);
|
||||
if(time() > $ext_time) {
|
||||
$this->n_error('验证码已经过期', [], 500);
|
||||
}
|
||||
$res = $this->auth->login($data['username'], $data['password']);
|
||||
if (isset($res) && $res === true) {
|
||||
$user = $this->auth->getAdmin();
|
||||
if($data['adminType'] == 1 && $user['is_channel'] != null && $user['is_channel'] == 1) {
|
||||
$this->n_error('代理账号请登录代理端', [], 500);
|
||||
}
|
||||
if($data['adminType'] == 2 && $user['is_channel'] == null) {
|
||||
$this->n_error('管理员请登录管理端', [], 500);
|
||||
}
|
||||
$this->n_success([
|
||||
'token' => $this->auth->getToken()
|
||||
]);
|
||||
} else {
|
||||
$msg = $this->auth->getError();
|
||||
$msg = $msg ?: __('Check in failed, please try again or contact the website administrator~');
|
||||
$this->n_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员注销
|
||||
* @return void
|
||||
*/
|
||||
public function logout(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$refreshToken = $this->request->post('refreshToken', '');
|
||||
if ($refreshToken) Token::delete((string)$refreshToken);
|
||||
$this->auth->logout();
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 邀请好友奖励分页
|
||||
* @return void
|
||||
*/
|
||||
public function invitefriendaward()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$subQuery = DatabaseRoute::getAllDbData('user_money_details', function ($query) use ($params) {
|
||||
return $query->field('user_id, SUM(money) as awardAmount, SUM(IF(title = "签到奖励", 1, 0)) as signInNum')
|
||||
->where('classify', 6)->group('user_id');
|
||||
})->buildSql();
|
||||
|
||||
$result = DatabaseRoute::paginateAllDb('tb_user', function ($query) use ($subQuery , $params) {
|
||||
$query->alias('t1')
|
||||
->field([
|
||||
't1.user_id as userId',
|
||||
't1.user_name as userName',
|
||||
't1.phone',
|
||||
't1.avatar',
|
||||
'IFNULL(t2.signInNum, 0) as signInNum',
|
||||
'IFNULL(t2.awardAmount, 0) as awardAmount'
|
||||
])
|
||||
->leftJoin("{$subQuery} t2", 't1.user_id = t2.user_id');
|
||||
if(!empty($params['keywords'])) {
|
||||
$query->where('t1.user_name', $params['keywords'])->whereOr('t1.phone', $params['keywords']);
|
||||
}
|
||||
$query->order('t2.signInNum', 'desc');
|
||||
$query->order('t1.user_id', 'asc');
|
||||
return $query;
|
||||
}, (int)$params['page'], (int)$params['limit']);
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
/**
|
||||
* 奖励详情
|
||||
* @return void
|
||||
*/
|
||||
public function invitefrienddetail()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userId = $params['userId'];
|
||||
$result = DatabaseRoute::paginateAllDb('user_money_details', function ($query) use ($params, $userId) {
|
||||
$query->alias('t1')
|
||||
->field([
|
||||
't1.by_user_id AS userId',
|
||||
't1.money AS amount',
|
||||
't2.phone AS userPhone',
|
||||
't1.create_time AS createTime'
|
||||
])
|
||||
->leftJoin('tb_user t2', 't1.by_user_id = t2.user_id')
|
||||
->where('t1.user_id', $userId)
|
||||
->where('t1.classify', 6)
|
||||
->whereNotNull('t1.by_user_id')
|
||||
->whereNotNull('t2.user_id')
|
||||
->order('t1.create_time', 'desc')
|
||||
->order('t1.by_user_id', 'asc');
|
||||
return $query;
|
||||
}, (int)$params['page'], (int)$params['limit'], 'createTime');
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请好友奖励-签到人数分页
|
||||
* @return void
|
||||
*/
|
||||
public function signindetailpage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userId = $params['userId'];
|
||||
// 先获取总数
|
||||
$count = DatabaseRoute::getAllDbData('user_money_details', function ($query) use($userId) {
|
||||
return $query->alias('t')
|
||||
->field('t.by_user_id')
|
||||
->where('t.user_id', $userId)
|
||||
->where('t.classify', 6)
|
||||
->where('t.title', '签到奖励')
|
||||
->group('t.by_user_id');
|
||||
})->count();
|
||||
$v_db_name = config('database.connections.' . get_slave_connect_name() . '.database');
|
||||
$result = DatabaseRoute::paginateAllDbBySqlAutoCount(function () use($userId, $v_db_name) {
|
||||
return "select
|
||||
t1.by_user_id as userId,
|
||||
t1.createTime,
|
||||
t2.user_name as userName,
|
||||
t2.phone,
|
||||
t3.cert_name as realName,
|
||||
t3.cert_no as idCardNo,
|
||||
t3.bank_name as bankName,
|
||||
t3.account_no as bankCardNo,
|
||||
t3.mobile,
|
||||
t3.province,
|
||||
t3.city,
|
||||
t3.bank_branch as bankBranch
|
||||
from (
|
||||
SELECT
|
||||
t.by_user_id,
|
||||
MIN( t.create_time ) as createTime
|
||||
FROM
|
||||
" . $v_db_name . ".v_user_money_details t
|
||||
WHERE 1=1
|
||||
AND t.user_id = ".$userId."
|
||||
AND t.classify = 6
|
||||
AND t.title = '签到奖励'
|
||||
GROUP BY t.by_user_id
|
||||
) t1
|
||||
LEFT JOIN " . $v_db_name . ".v_tb_user t2 on t1.by_user_id = t2.user_id
|
||||
LEFT JOIN " . $v_db_name . ".v_user_info t3 on t1.by_user_id = t3.user_id
|
||||
order by t1.createTime desc,t1.by_user_id asc";
|
||||
}, $params['page'], $params['limit'], null, $count);
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖次数查询-分页
|
||||
* @return void
|
||||
*/
|
||||
public function lotterypage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$keywords = $params['keywords'];
|
||||
$v_db_name = config('database.connections.' . get_slave_connect_name() . '.database');
|
||||
$result = DatabaseRoute::paginateAllDb('tb_user', function ($query) use($keywords, $v_db_name) {
|
||||
return $query->alias('t1')
|
||||
->field([
|
||||
't1.user_id as userId',
|
||||
't1.avatar',
|
||||
't1.user_name as userName',
|
||||
't1.phone',
|
||||
// 今日解锁订单数
|
||||
'(SELECT COUNT(1) FROM '. $v_db_name .'.v_orders WHERE STATUS = 1 AND pay_way = 9 AND user_id = t1.user_id AND pay_time >= DATE_FORMAT(CURDATE(), "%Y-%m-%d 00:00:00") AND pay_time <= DATE_FORMAT(CURDATE(), "%Y-%m-%d 23:59:59")) as todayUnlocked',
|
||||
// 今日抽奖次数
|
||||
'(SELECT COUNT(1) FROM '. $v_db_name .'.v_disc_spinning_record WHERE user_id = t1.user_id AND DATE_FORMAT(create_time, "%Y-%m-%d") = CURDATE()) as todayDrawCount'
|
||||
])
|
||||
->where(function ($query) use ($keywords) {
|
||||
$query->where('t1.user_name', $keywords)
|
||||
->whereOr('t1.phone', $keywords);
|
||||
})
|
||||
->order('todayUnlocked', 'desc')
|
||||
->order('t1.user_id', 'asc');
|
||||
}, $params['page'], $params['limit']);
|
||||
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖详情-分页
|
||||
* @return void
|
||||
*/
|
||||
public function lotterydetailpage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userId = $params['userId'];
|
||||
// 先获取总数
|
||||
$count = Db::connect(get_slave_connect_name())->query("select
|
||||
count(*) count
|
||||
from v_disc_spinning_record t1
|
||||
where t1.user_id = ".$userId);
|
||||
$count = $count[0]['count'];
|
||||
$v_db_name = config('database.connections.' . get_slave_connect_name() . '.database');
|
||||
$result = DatabaseRoute::paginateAllDbBySqlAutoCount(function () use($userId, $v_db_name) {
|
||||
return "select
|
||||
t1.id,
|
||||
t1.name,
|
||||
t1.number,
|
||||
t1.create_time
|
||||
from ". $v_db_name .".v_disc_spinning_record t1
|
||||
where t1.user_id = " . $userId . "
|
||||
order by t1.id desc";
|
||||
}, $params['page'], $params['limit'], null, $count);
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
public function sendMsg()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(Msg::sendMsg($get['phone'], $get['event']));
|
||||
}
|
||||
}
|
||||
56
app/czg/controller/TaskCenterController.php
Normal file
56
app/czg/controller/TaskCenterController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class TaskCenterController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
|
||||
public function selectTaskCenter()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->successWithData(DatabaseRoute::paginateDb('task_center', function ($query) use ($params) {
|
||||
return $query->order('sort');
|
||||
}, $params['page'], $params['limit'], null, true));
|
||||
}
|
||||
|
||||
public function updateTaskCenter()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['update_time'] = getNormalDate();
|
||||
unset($params['disc_number']);
|
||||
unset($params['disabled']);
|
||||
Db::name('task_center')->where([
|
||||
'id' => $params['id']
|
||||
])->update($params);
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
public function insertTaskCenter()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['create_time'] = getNormalDate();
|
||||
unset($params['is_trusted']);
|
||||
Db::name('task_center')->insert($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function deleteTaskCenter()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
Db::name('task_center')->delete([
|
||||
'id' => $id
|
||||
]);
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
69
app/czg/controller/TaskCenterRewardController.php
Normal file
69
app/czg/controller/TaskCenterRewardController.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class TaskCenterRewardController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
|
||||
public function selectTaskCenterReward()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->successWithData(DatabaseRoute::paginateDb('task_center_reward', function ($query) use ($params) {
|
||||
if (!empty($params['taskId'])) {
|
||||
$query->where([
|
||||
'task_id' => $params['taskId']
|
||||
]);
|
||||
}
|
||||
return $query->order('id', false);
|
||||
|
||||
}, $params['page'] ?? 1, $params['limit'] ?? 10));
|
||||
}
|
||||
|
||||
public function updateTaskCenterReward()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$info = Db::name('task_center_reward')->where([
|
||||
'id' => $params['id']
|
||||
]);
|
||||
|
||||
if (!empty($info['total_number']) && !empty($params['total_number']) && $info['total_number'] != $params['total_number']) {
|
||||
$surplusNumber = $params['total_number'] - $info['total_number'];
|
||||
$surplusNumber = $surplusNumber > 0 ?? $params['total_number'];
|
||||
$params['total_number'] = $surplusNumber;
|
||||
}
|
||||
|
||||
$params['update_time'] = getNormalDate();
|
||||
Db::name('task_center_reward')->where([
|
||||
'id' => $params['id']
|
||||
])->update($params);
|
||||
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function insertTaskCenterReward()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params = convertKeysCamelToSnakeRecursive($params);
|
||||
$params['surplus_number'] = $params['total_number'];
|
||||
unset($params['is_trusted']);
|
||||
unset($params['id']);
|
||||
Db::name('task_center_reward')->insert($params);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function deleteTaskCenterReward()
|
||||
{
|
||||
$id = $this->request->param('id');
|
||||
Db::name('task_center_reward')->delete([
|
||||
'id' => $id
|
||||
]);
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
97
app/czg/controller/UrlAddressController.php
Normal file
97
app/czg/controller/UrlAddressController.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\facade\Db;
|
||||
|
||||
class UrlAddressController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
|
||||
public function selectUrlAddress()
|
||||
{
|
||||
$info = Db::name('url_address')->order('num', 'asc')->limit(1)->find();
|
||||
if ($info) {
|
||||
$info['num'] = $info['num'] ? $info['num'] + 1 : 1;
|
||||
Db::name('url_address')->where([
|
||||
'url_id' => $info['url_id']
|
||||
])->update([
|
||||
'num' => $info['num']
|
||||
]);
|
||||
}
|
||||
|
||||
$this->successWithData(convertToCamelCase($info));
|
||||
|
||||
}
|
||||
|
||||
public function selectUrlAddressList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$page = $get['page']; // 页码,默认1
|
||||
$limit = $get['limit']; // 每页条数,默认10
|
||||
$urlAddress = $get['urlAddress']; // URL地址关键词
|
||||
$status = $get['status']; // 状态值
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
// 构建查询
|
||||
$query = $db->name('url_address');
|
||||
if(!empty($urlAddress)) {
|
||||
$query->where('url_address', 'like', "%{$urlAddress}%");
|
||||
}
|
||||
if(!empty($status)) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
$count = $query->count();
|
||||
$info = $query->limit(page($page, $limit), $limit)->select()->toArray();
|
||||
$this->n_success(['data' => [
|
||||
'totalCount' => $count,
|
||||
'pageSize' => $get['limit'],
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
'currPage' => $get['page'],
|
||||
'list' => $info,
|
||||
'records' => null
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
public function updateUrlAddress()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
|
||||
$url_id = $post['urlId'] ?? null;
|
||||
$data['num'] = $post['num'] ?? null;
|
||||
$data['url_address'] = $post['urlAddress'] ?? null;
|
||||
$data['status'] = $post['status'] ?? null;
|
||||
Db::name('url_address')->where(['url_id' => $url_id])->update($data);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
// 创建域名
|
||||
public function insertUrlAddress()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$data['num'] = $post['num'] ?? null;
|
||||
$data['url_address'] = $post['urlAddress'] ?? null;
|
||||
$data['status'] = $post['status'] ?? null;
|
||||
$data['create_time'] = date('Y-m-d H:i:s');
|
||||
Db::name('url_address')->insert($data);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function deleteUrlAddress()
|
||||
{
|
||||
$param = $this->request->get();
|
||||
if(empty($param['addressId'])) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
Db::name('url_address')->where(['url_id' => $param['addressId']])->delete();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
542
app/czg/controller/UserController.php
Normal file
542
app/czg/controller/UserController.php
Normal file
@@ -0,0 +1,542 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\TbUser;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\User as UserModel;
|
||||
|
||||
class UserController extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var UserModel
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
protected array $withJoinTable = ['userGroup'];
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['last_login_time', 'login_failure', 'password', 'salt'];
|
||||
|
||||
protected string|array $quickSearchField = ['username', 'nickname', 'id'];
|
||||
|
||||
protected array $noNeedPermission = [
|
||||
'courseMessage',
|
||||
'userMessage',
|
||||
'selectUserOnLineCount',
|
||||
'homeMessage',
|
||||
'selectUserCountStatisticsByTime',
|
||||
'selectUserList',
|
||||
'updateUserStatusByUserId',
|
||||
'inviteAmount',
|
||||
'selectUserByInvitationCode',
|
||||
'getuserinfo',
|
||||
'deleteUserByUserId',
|
||||
];
|
||||
protected array $noNeedLogin = ['userListExcel'];
|
||||
public function initialize(): void
|
||||
{
|
||||
// $this->model = new UserModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(): void
|
||||
{
|
||||
if ($this->request->param('select')) {
|
||||
$this->select();
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('password,salt')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
$this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function add(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$passwd = $data['password']; // 密码将被排除不直接入库
|
||||
$data = $this->excludeFields($data);
|
||||
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
// 模型验证
|
||||
if ($this->modelValidate) {
|
||||
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||
if (class_exists($validate)) {
|
||||
$validate = new $validate();
|
||||
if ($this->modelSceneValidate) $validate->scene('add');
|
||||
$validate->check($data);
|
||||
}
|
||||
}
|
||||
$result = $this->model->save($data);
|
||||
$this->model->commit();
|
||||
|
||||
if (!empty($passwd)) {
|
||||
$this->model->resetPassword($this->model->id, $passwd);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Added successfully'));
|
||||
} else {
|
||||
$this->error(__('No rows were added'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function edit(): void
|
||||
{
|
||||
$pk = $this->model->getPk();
|
||||
$id = $this->request->param($pk);
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$password = $this->request->post('password', '');
|
||||
if ($password) {
|
||||
$this->model->resetPassword($id, $password);
|
||||
}
|
||||
parent::edit();
|
||||
}
|
||||
|
||||
unset($row->salt);
|
||||
$row->password = '';
|
||||
$this->success('', [
|
||||
'row' => $row
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写select
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function select(): void
|
||||
{
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('password,salt')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($res as $re) {
|
||||
$re->nickname_text = $re->username . '(ID:' . $re->id . ')';
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 短剧分析
|
||||
public function courseMessage()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$admin = $this->auth->getAdmin();
|
||||
$pageUtils = \app\admin\model\User::queryCourseOrder($get['page'], $get['limit'], $get['type'], completeStartTime($get['date']), $admin['user_id']);
|
||||
$this->n_success(['data' => $pageUtils]);
|
||||
}
|
||||
|
||||
// 用户分析
|
||||
public function userMessage()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$admin = $this->auth->getAdmin();
|
||||
// 补全开始时间(调用之前实现的函数)
|
||||
$date = completeStartTime($get['date']); // 假设已实现该函数
|
||||
$qdCode = $admin['qd_code'];
|
||||
$sumUserCount = \app\admin\model\User::queryUserCount($get['type'], $date, null, $qdCode);
|
||||
$h5Count = \app\admin\model\User::queryUserCount($get['type'], $date, "h5", $qdCode);
|
||||
$appCount = \app\admin\model\User::queryUserCount($get['type'], $date, "app", $qdCode);
|
||||
$wxCount = \app\admin\model\User::queryUserCount($get['type'], $date, "小程序", $qdCode);
|
||||
$dyCount = \app\admin\model\User::queryUserCount($get['type'], $date, "抖音", $qdCode);
|
||||
$giveMemberCount = \app\admin\model\User::userMessage($date, $get['type'], $qdCode, 1);
|
||||
$moneyMemberCount = \app\admin\model\User::userMessage($date, $get['type'], $qdCode, 2);
|
||||
$memberCount = \app\admin\model\User::userMessage($date, $get['type'], $qdCode, null);
|
||||
$userCount = $sumUserCount - $memberCount;
|
||||
$this->n_success(['data' => [
|
||||
'sumUserCount' => $sumUserCount,
|
||||
'h5Count' => $h5Count,
|
||||
'appCount' => $appCount,
|
||||
'wxCount' => $wxCount,
|
||||
'dyCount' => $dyCount,
|
||||
'memberCount' => $memberCount,
|
||||
'giveMemberCount' => $giveMemberCount,
|
||||
'moneyMemberCount' => $moneyMemberCount,
|
||||
'userCount' => $userCount,
|
||||
]]);
|
||||
}
|
||||
|
||||
// 当前在线人数统计
|
||||
public function selectUserOnLineCount()
|
||||
{
|
||||
$admin = $this->auth->getAdmin();
|
||||
$qdCode = $admin['qd_code'];
|
||||
$selectUserOnLineCount = DatabaseRoute::getAllDbData('tb_user', function($query)use($qdCode) {
|
||||
if($query) {
|
||||
$query->where(['qd_code' => $qdCode]);
|
||||
}
|
||||
return $query->where('on_line_time', '>=', Db::raw('DATE_SUB(NOW(), INTERVAL 10 MINUTE)'));
|
||||
})->count();
|
||||
$this->n_success(['data' => $selectUserOnLineCount]);
|
||||
}
|
||||
|
||||
// 用户统计
|
||||
public function homeMessage()
|
||||
{
|
||||
$admin = $this->auth->getAdmin();
|
||||
$qdCode = $admin['qd_code'];
|
||||
$data = [];
|
||||
$data['totalUsers'] = \app\admin\model\User::queryUserCount(0, null, null, $qdCode);
|
||||
$data['newToday'] = \app\admin\model\User::queryUserCount(1, null, null, $qdCode);
|
||||
$data['newMonth'] = \app\admin\model\User::queryUserCount(2, null, null, $qdCode);
|
||||
$data['newYear'] = \app\admin\model\User::queryUserCount(3, null, null, $qdCode);
|
||||
$data['totalRevenue'] = \app\admin\model\User::queryPayMoney(0, $qdCode);
|
||||
$data['todayRevenue'] = \app\admin\model\User::queryPayMoney(1, $qdCode);
|
||||
$data['monthRevenue'] = \app\admin\model\User::queryPayMoney(2, $qdCode);
|
||||
$data['yearRevenue'] = \app\admin\model\User::queryPayMoney(3, $qdCode);
|
||||
$map = \app\admin\model\User::queryPayAndExtractInfo();
|
||||
$data['todayPayAmount'] = isset($map['payAmount'])
|
||||
? round((float)$map['payAmount'], 2, PHP_ROUND_HALF_UP)
|
||||
: 0.00;
|
||||
$data['todayPayCount'] = isset($map['payCount'])
|
||||
? (int)$map['payCount']
|
||||
: 0;
|
||||
$data['todayExtractAmount'] = isset($map['extractAmount'])
|
||||
? round((float)$map['extractAmount'], 2, PHP_ROUND_HALF_UP)
|
||||
: 0.00;
|
||||
|
||||
$data['todayExtractCount'] = isset($map['extractCount'])
|
||||
? (int)$map['extractCount']
|
||||
: 0;
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
// 用户增长折线图
|
||||
public function selectUserCountStatisticsByTime()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$startTime = $get['startTime'];
|
||||
$endTime = $get['endTime'];
|
||||
|
||||
// 初始化结果数组
|
||||
$userCountList = [];
|
||||
$dateList = [];
|
||||
|
||||
// 日期处理
|
||||
$currentDate = strtotime($startTime);
|
||||
$endDate = strtotime($endTime);
|
||||
|
||||
// 循环遍历日期范围
|
||||
while ($currentDate <= $endDate) {
|
||||
$date = date('Y-m-d', $currentDate);
|
||||
|
||||
// 查询当日用户注册数量
|
||||
$userCount = \app\admin\model\User::queryUserCount(1, $date, null, null);
|
||||
|
||||
// 记录数据
|
||||
$userCountList[] = $userCount;
|
||||
$dateList[] = $date;
|
||||
|
||||
// 日期加1天
|
||||
$currentDate = strtotime('+1 day', $currentDate);
|
||||
}
|
||||
|
||||
// 构建结果数据
|
||||
$result = [
|
||||
'userCountList' => $userCountList,
|
||||
'year' => $dateList // 注:原Java代码中使用year变量,但实际存储的是日期列表
|
||||
];
|
||||
|
||||
$this->n_success(['data' => $result]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 查询所有用户列表
|
||||
public function selectUserList()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
p(2312);
|
||||
$vipType = $params['vipType'] ?? null;
|
||||
$member = $params['member'] ?? null;
|
||||
$status = $params['status'] ?? null;
|
||||
$page = $params['page'] ?? null;
|
||||
$limit = $params['limit'] ?? null;
|
||||
$phone = $params['phone'] ?? null;
|
||||
$sysUserName = $params['sysUserName'] ?? null;
|
||||
$userName = $params['userName'] ?? null;
|
||||
$sex = $params['sex'] ?? null;
|
||||
$platform = $params['platform'] ?? null;
|
||||
$sysPhone = $params['sysPhone'] ?? null;
|
||||
$inviterCode = $params['inviterCode'] ?? null;
|
||||
$invitationCode = $params['invitationCode'] ?? null;
|
||||
$qdCode = $params['qdCode'] ?? null;
|
||||
$startTime = $params['startTime'] ?? null;
|
||||
$endTime = $params['endTime'] ?? null;
|
||||
$delegate = $params['delegate'] ?? null;
|
||||
$this->n_success(['data' => \app\admin\model\User::selectUserPage(
|
||||
$page, $limit, $phone, $sex, $platform, $sysPhone, $status, $member,
|
||||
$inviterCode, $userName, $invitationCode, $startTime, $endTime, $qdCode, $sysUserName, $vipType, $delegate
|
||||
)]);
|
||||
}
|
||||
|
||||
// 修改用户状态
|
||||
public function updateUserStatusByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
if(empty($get['status']) && $get['status'] == null) {
|
||||
$this->error('status 不能为空');
|
||||
}
|
||||
$status = $get['status'];
|
||||
$userId = $get['userId'];
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
// 查询用户是否存在
|
||||
$user = $db->name('tb_user')->where(['user_id' => $userId])->find();
|
||||
if (is_null($user)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
|
||||
// 根据状态执行不同操作
|
||||
switch ($status) {
|
||||
case 1:
|
||||
// 状态1:设置状态为1,并调用upUserBlack方法(拉黑)
|
||||
\app\admin\model\User::upUserBlack($user, 1, $db);
|
||||
break;
|
||||
case 2:
|
||||
// 状态2:直接更新状态为2
|
||||
$db->name('tb_user')->where('user_id', $userId)
|
||||
->update(['status' => 2]);
|
||||
break;
|
||||
case 0:
|
||||
// 状态0:调用upUserBlack方法(解封)
|
||||
\app\admin\model\User::upUserBlack($user, 0, $db);
|
||||
break;
|
||||
default:
|
||||
// 无效状态
|
||||
$this->error('状态不正确');
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
// 更新用户邀请奖励金额
|
||||
public function inviteAmount()
|
||||
{
|
||||
$userInviteDTO = $this->request->post();
|
||||
// 验证用户ID不能为空
|
||||
if (empty($userInviteDTO['userId'])) {
|
||||
$this->error('用户id不能为空');
|
||||
}
|
||||
|
||||
// 验证邀请奖励金额必须大于0
|
||||
$inviteAmount = $userInviteDTO['inviteAmount'] ?? null;
|
||||
if (is_null($inviteAmount) || bccomp($inviteAmount, 0) <= 0) {
|
||||
$this->error('邀请奖励金额必须大于0');
|
||||
}
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userInviteDTO['userId']], true))->name('tb_user');
|
||||
// 查询用户是否存在
|
||||
$userEntity = $db->where(['user_id' => $userInviteDTO['userId']])->find($userInviteDTO['userId']);
|
||||
if (is_null($userEntity)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
// 更新用户邀请奖励金额
|
||||
$db->where(['user_id' => $userInviteDTO['userId']])->update(['invite_amount' => $inviteAmount]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
public function updatePwd()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId']) || empty($get['pwd'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$userId = $get['userId'];
|
||||
$pwd = $get['pwd'];
|
||||
$db = Db::connect(DatabaseRoute::getConnection('sys_user', ['user_id' => $userId]));
|
||||
$user = $db->name('sys_user')->where(['user_id' => $userId])->find();
|
||||
if(!$user) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
$db = Db::connect(DatabaseRoute::getConnection('sys_user', ['user_id' => $userId], true));
|
||||
$user = $db->name('sys_user')->where(['user_id' => $userId])->update(['password' => shiro_simple_hash_hex_salt('sha256', $pwd, $user['salt'])]);
|
||||
if($user) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
public function deleteUserByUserId()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if(empty($post['userId'])) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
$userId = $post['userId'];
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
$user = $db->name('tb_user')->where(['user_id' => $userId])->delete();
|
||||
if($user) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
|
||||
public function getuserinfo()
|
||||
{
|
||||
$userId = $this->request->get('userId');
|
||||
if(empty($userId)) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId]));
|
||||
$user = $db->name('tb_user')->where(['user_id' => $userId])->find();
|
||||
if(!$user) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
|
||||
$inviteMoney = \app\admin\model\User::selectInviteMoneyByUserId($userId, $db);
|
||||
if(empty($inviteMoney)) {
|
||||
$inviteMoney = [
|
||||
'user_id' => $userId,
|
||||
'money_sum' => 0.00,
|
||||
'money' => 0.00,
|
||||
'cash_out' => 0.00,
|
||||
];
|
||||
Db::connect(DatabaseRoute::getConnection('invite_money', ['user_id' => $userId], true), true)->name('invite_money')->insert($inviteMoney);
|
||||
}
|
||||
$money = $inviteMoney['money'];
|
||||
|
||||
// 获取当前日期(格式:YYYY-MM-DD HH:mm:ss)
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
// 查询本月充值(复用之前的instantselectSumPay方法)
|
||||
$consume = \app\admin\model\User::instantselectSumPay(date('Y-m'), $userId, $db);
|
||||
|
||||
// 查询本月提现(假设monthIncome方法已实现)
|
||||
$income = \app\admin\model\User::monthIncome(date('Y-m'), $userId, $db);
|
||||
|
||||
// 查询邀请人数(复用之前的countUsersByInviterCode方法)
|
||||
$count = \app\admin\model\User::queryInviterCount($user['invitation_code']);
|
||||
|
||||
// 查询VIP信息
|
||||
$userVip = \app\admin\model\User::selectUserVipByUserId($userId);
|
||||
if ($userVip) {
|
||||
$user['member'] = $userVip['is_vip'];
|
||||
$user['end_time'] = $userVip['end_time'];
|
||||
$user['vip_type'] = $userVip['vip_type'];
|
||||
}
|
||||
|
||||
// 组装结果数据
|
||||
$resultData = [
|
||||
'userEntity' => $user,
|
||||
'money' => $money,
|
||||
'consume' => $consume,
|
||||
'income' => $income,
|
||||
'count' => $count
|
||||
];
|
||||
$this->n_success(['data' => $resultData]);
|
||||
|
||||
}
|
||||
|
||||
public function userListExcel()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$startTime = $get['startTime'] ?? null;
|
||||
$endTime = $get['endTime'] ?? null;
|
||||
$this->n_success(\app\admin\model\User::userListExcel($startTime, $endTime));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 获取用户详细信息
|
||||
public function selectUserByInvitationCode()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['invitationCode'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$invitationCode = $get['invitationCode'];
|
||||
$userEntity = TbUser::GetByusername($invitationCode, 'invitation_code');
|
||||
if(empty($userEntity)) {
|
||||
$this->error('用户信息不存在');
|
||||
}
|
||||
$userId = $userEntity['user_id'];
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('invite_money', ['user_id' => $userId]));
|
||||
// 查询用户钱包
|
||||
$inviteMoney = \app\admin\model\User::selectInviteMoneyByUserId($userId, $db);
|
||||
$money = $inviteMoney['money'];
|
||||
// 获取当前时间(格式:Y-m-d H:i:s)
|
||||
$currentDate = date('Y-m-d H:i:s');
|
||||
// 查询本月充值总额
|
||||
$consume = \app\admin\model\User::instantselectSumPay($currentDate, $userId, $db);
|
||||
$income = \app\admin\model\User::monthIncome($currentDate, $userId, $db);
|
||||
//查询邀请人数
|
||||
$count = \app\admin\model\User::queryInviterCount($userEntity['invitation_code']);
|
||||
$userVip = \app\admin\model\User::selectUserVipByUserId($userId);
|
||||
if ($userVip) {
|
||||
$userEntity['member'] = $userVip['is_vip'];
|
||||
$userEntity['end_time'] = $userVip['end_time'];
|
||||
$userEntity['vip_type'] = $userVip['vip_type'];
|
||||
}
|
||||
$data = [
|
||||
'userEntity' => $userEntity,
|
||||
'money' => $money,
|
||||
'consume' => $consume,
|
||||
'income' => $income,
|
||||
'count' => $count
|
||||
];
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
84
app/czg/controller/UserInfoController.php
Normal file
84
app/czg/controller/UserInfoController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserInfoController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function list()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$result = DatabaseRoute::paginateAllDb('user_info', function ($query) use ($params) {
|
||||
if (!empty($params['phone'])) {
|
||||
$user = DatabaseRoute::getAllDbData('tb_user', function ($q) use ($params) {
|
||||
return $q->where('phone', $params['phone']);
|
||||
})->find();
|
||||
$userId = $user ? $user['user_id'] : -99999;
|
||||
$query->where('user_id', $userId);
|
||||
}
|
||||
|
||||
if (!empty($name)) {
|
||||
$query->whereLike('cert_name', "%{$name}%");
|
||||
}
|
||||
|
||||
return $query;
|
||||
}, $params['page'], $params['limit'], 'id', 'id');
|
||||
|
||||
// 用户信息补全
|
||||
$userInfoList = $result['list'];
|
||||
$userIds = array_column($userInfoList, 'user_id');
|
||||
|
||||
if (!empty($userIds)) {
|
||||
$userMap = DatabaseRoute::getAllDbData('tb_user', function ($query) use ($params, $userIds) {
|
||||
return $query
|
||||
->whereIn('user_id', $userIds);
|
||||
})->select();
|
||||
|
||||
foreach ($userInfoList as &$item) {
|
||||
$user = $userMap[$item['user_id']] ?? null;
|
||||
$item['name'] = $user['user_name'] ?? null;
|
||||
$item['phone'] = $user['phone'] ?? null;
|
||||
}
|
||||
unset($item);
|
||||
|
||||
$result['list'] = $userInfoList;
|
||||
}
|
||||
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
|
||||
public function update()
|
||||
{
|
||||
$params = input();
|
||||
if (empty($params['userId'])) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$params['update_time'] = getNormalDate();
|
||||
DatabaseRoute::getDb('user_info', $params['userId'], true, true)->update([
|
||||
'cert_name' => $params['certName'] ?? '',
|
||||
'cert_no' => $params['certNo'] ?? '',
|
||||
'account_no' => $params['accountNo'] ?? '',
|
||||
'mobile' => $params['mobile'] ?? '',
|
||||
'bank_name' => $params['bankName'] ?? '',
|
||||
]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
if (empty($params['userId'])) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
DatabaseRoute::getDb('user_info', $params['userId'], true, true)->delete();
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
84
app/czg/controller/UserPrizeExchangeController.php
Normal file
84
app/czg/controller/UserPrizeExchangeController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserPrizeExchangeController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
protected array $noNeedPermission = ['statisticsIncomeMoney', 'statisticsCashMoney'];
|
||||
|
||||
|
||||
public function page()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->successWithData(DatabaseRoute::paginateDb('user_prize_exchange', function ($query) use ($params) {
|
||||
if (!empty($params['foreignId'])) {
|
||||
$query->where('foreign_id', $params['foreignId']);
|
||||
}
|
||||
if (!empty($params['foreignType'])) {
|
||||
$query->where('foreign_type', $params['foreignType']);
|
||||
}
|
||||
if (!empty($params['userId'])) {
|
||||
$query->where('user_id', $params['userId']);
|
||||
}
|
||||
if (!empty($params['userName'])) {
|
||||
$query->where('user_name', 'like', "%". $params['userName']."%");
|
||||
}
|
||||
if (!empty($params['prizeName'])) {
|
||||
$query->where('prize_name', 'like', "%" . $params['prizeName'] . "%");
|
||||
}
|
||||
if (!empty($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
if (!empty($params['phone'])) {
|
||||
$query->where('phone', 'like', "%". $params['phone'] ."%");
|
||||
}
|
||||
if (!empty($params['remark'])) {
|
||||
$query->where('remark', 'like', "%" . $params['remark'] . "%");
|
||||
}
|
||||
|
||||
if (!empty($params['beginDate'])) {
|
||||
$query->where('create_time', '>=', $params['beginDate'] . ' 00:00:00');
|
||||
}
|
||||
if (!empty($params['endDate'])) {
|
||||
$query->where('create_time', '<=', $params['endDate'] . ' 23:59:59');
|
||||
}
|
||||
$query->order('id', false);
|
||||
}));
|
||||
}
|
||||
|
||||
public function deliver()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
if (empty($params['id'])) {
|
||||
$this->error('兑奖id不能为空');
|
||||
}
|
||||
|
||||
$info = Db::name('user_prize_exchange')->where([
|
||||
'id' => $params['id']
|
||||
])->find();
|
||||
if (!$info) {
|
||||
$this->error('兑奖订单不存在');
|
||||
}
|
||||
|
||||
Db::name('user_prize_exchange')->where([
|
||||
'id' => $params['id']
|
||||
])->update([
|
||||
'status' => 1,
|
||||
'address' => $params['address'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'update_time' => getNormalDate()
|
||||
]);
|
||||
|
||||
$this->success();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
128
app/czg/controller/VipDetailsController.php
Normal file
128
app/czg/controller/VipDetailsController.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\SysCaptcha;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
|
||||
class VipDetailsController extends Backend
|
||||
{
|
||||
protected array $noNeedPermission = ['selectVipDetailsList'];
|
||||
public function sendVip()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$userId = $data['userId'] ?? null;
|
||||
$num = $data['num'] ?? null;
|
||||
$userVip = \app\admin\model\User::selectUserVipByUserId($userId);
|
||||
|
||||
// 获取当前时间戳
|
||||
$currentTime = time();
|
||||
|
||||
// 如果用户已有 VIP 记录
|
||||
if ($userVip) {
|
||||
// 如果当前是 VIP 会员(假设 is_vip=2 表示 VIP)
|
||||
if ($userVip['is_vip'] == 2) {
|
||||
// 从现有结束时间开始叠加(转换为时间戳)
|
||||
$endTime = strtotime($userVip['end_time']);
|
||||
} else {
|
||||
// 非 VIP 从当前时间开始
|
||||
$endTime = $currentTime;
|
||||
}
|
||||
} else {
|
||||
// 新建 VIP 记录
|
||||
$userVip = [
|
||||
'user_id' => $userId,
|
||||
'create_time' => date('Y-m-d H:i:s', $currentTime)
|
||||
];
|
||||
$endTime = $currentTime;
|
||||
}
|
||||
|
||||
// 设置 VIP 类型和状态
|
||||
$userVip['vip_type'] = 1;
|
||||
$userVip['is_vip'] = 2;
|
||||
|
||||
// 计算新的结束时间(增加指定天数,每天 86400 秒)
|
||||
$endTime += $num * 86400;
|
||||
$userVip['end_time'] = date('Y-m-d H:i:s', $endTime);
|
||||
$db = Db::connect(get_master_connect_name())->name('user_vip');
|
||||
// 保存或更新记录
|
||||
if (isset($userVip['vip_id'])) {
|
||||
// 更新记录
|
||||
$db->where('vip_id', $userVip['vip_id'])
|
||||
->update($userVip);
|
||||
} else {
|
||||
// 插入新记录
|
||||
$db->insert($userVip);
|
||||
}
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function selectVipDetailsList()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$page = $get['page'] ?? null;
|
||||
$limit = $get['limit'] ?? null;
|
||||
$db = Db::connect(get_slave_connect_name())->name('vip_details');
|
||||
$count = $db->count();
|
||||
$data = $db->limit(page($page, $limit), $limit)->select()->toArray();
|
||||
$this->n_success(['data' => [
|
||||
'currPage' => $get['page'],
|
||||
'pageSize' => $get['limit'],
|
||||
'list' => array_map(function ($item) {
|
||||
$item['id'] = (string)$item['id'];
|
||||
return $item;
|
||||
}, $data),
|
||||
'totalCount' => $count,
|
||||
'totalPage' => ceil($count / $get['limit']),
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
public function insertVipDetails()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$data['vip_name_type'] = $post['vipNameType'] ?? null;
|
||||
$data['money'] = $post['money'] ?? null;
|
||||
$data['pay_diamond'] = $post['payDiamond'] ?? null;
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
$res = $db->name('vip_details')->insert($data);
|
||||
if($res) {
|
||||
$this->success('成功');
|
||||
}else {
|
||||
$this->error('失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateVipDetails()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
$id = $post['id'] ?? null;
|
||||
$data['vip_name_type'] = $post['vipNameType'] ?? null;
|
||||
$data['money'] = $post['money'] ?? null;
|
||||
$data['pay_diamond'] = $post['payDiamond'] ?? null;
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
$res = $db->name('vip_details')->where(['id' => $id])->update($data);
|
||||
$this->success('成功');
|
||||
}
|
||||
|
||||
public function deleteVipDetails()
|
||||
{
|
||||
$post = $this->request->param();
|
||||
if(empty($post['id'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$id = $post['id'];
|
||||
$db = Db::connect(get_master_connect_name());
|
||||
$res = $db->name('vip_details')->where(['id' => $id])->delete();
|
||||
$this->success('成功');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user