Browse Source

p2补充需求

master
chuan 2 months ago
parent
commit
2e9eff4ffb
  1. 44
      app/admin/controller/Admin.php
  2. 6
      app/admin/controller/Config.php
  3. 8
      app/admin/controller/Test.php
  4. 24
      app/admin/controller/document/Index.php
  5. 31
      app/admin/route/app.php
  6. 264
      app/admin/service/AdminService.php
  7. 25
      app/admin/service/AgentService.php
  8. 28
      app/admin/service/ConfigService.php
  9. 42
      app/admin/service/UserService.php
  10. 1
      app/admin/service/VideoService.php
  11. 70
      app/admin/service/document/IndexService.php
  12. 16
      app/home/controller/Document.php
  13. 5
      app/home/route/app.php
  14. 55
      app/home/service/DocumentService.php
  15. 96
      app/home/service/LoginService.php
  16. 16
      app/home/service/UserService.php
  17. 22
      app/home/service/VideoService.php
  18. 26
      app/model/AdminModel.php
  19. 8
      app/model/GroupLeaderWithUserModel.php
  20. 8
      app/model/InformationArticleModel.php
  21. 8
      app/model/SellerWithUserModel.php
  22. 10
      app/utility/RequestChatServer.php
  23. 6
      config/cache.php

44
app/admin/controller/Admin.php

@ -7,6 +7,13 @@ use think\Request;
// 用户管理
class Admin extends AdminBaseController
{
// 根据角色获取管理端账号列表
public function getUsersByRole()
{
$service = new AdminService();
$result = $service->getUsersByRole($this->request->param());
return json($result);
}
public function addUser()
{
@ -104,6 +111,22 @@ class Admin extends AdminBaseController
return json($returnData);
}
// 组长与用户添加chat好友
public function groupLeaderWithUser()
{
$service = new AdminService();
$result = $service->groupLeaderWithUser($this->request->param());
return json($result);
}
// 电销与加用户chat好友
public function sellerWithUser()
{
$service = new AdminService();
$result = $service->sellerWithUser($this->request->param());
return json($result);
}
// 获取用户访问页面的记录
public function getUserAccessLog()
{
@ -131,4 +154,25 @@ class Admin extends AdminBaseController
$returnData = (new AdminService())->sendEmailOrSms($this->request->param());
return json($returnData);
}
// 批量发送短信或邮件
public function batchSendEmailOrSms()
{
$returnData = (new AdminService())->batchSendEmailOrSms($this->request->param());
return json($returnData);
}
// 定时任务执行 批量发送短信
public function execBatchSendSms()
{
$returnData = (new AdminService())->execBatchSendSms();
return json($returnData);
}
// 定时任务窒执行 批量发送邮件
public function execBatchSendEmail()
{
$returnData = (new AdminService())->execBatchSendEmail();
return json($returnData);
}
}

6
app/admin/controller/Config.php

@ -57,6 +57,12 @@ class Config extends AdminBaseController
}
}
public function getConfigList()
{
$returnData = (new ConfigService())->getConfigList($this->request->param());
return json($returnData);
}
// 获取邮箱模板列表
public function emailTemplateList()
{

8
app/admin/controller/Test.php

@ -2,12 +2,16 @@
namespace app\admin\controller;
use app\admin\service\AdminService;
use app\model\AdminModel;
class Test extends AdminBaseController
{
public function index()
{
$customerIds = AdminModel::getCustomerIdsByAgentId(2);
print_r($customerIds);
$appNumber = env('APP_NUMBER');
$appRootPath = app()->getRootPath();
$appAppPath = app()->getAppPath();

24
app/admin/controller/document/Index.php

@ -42,4 +42,28 @@ class Index extends AdminBaseController
$result = $service->del($this->request->param());
return json($result);
}
// 咨询文章列表
public function informationArticleList()
{
$service = new IndexService();
$result = $service->informationArticleList($this->request->param());
return json($result);
}
// 咨询文章新增
public function informationArticleAdd()
{
$service = new IndexService();
$result = $service->informationArticleAdd($this->request->param());
return json($result);
}
// 咨询文章编辑
public function informationArticleEdit()
{
$service = new IndexService();
$result = $service->informationArticleEdit($this->request->param());
return json($result);
}
}

31
app/admin/route/app.php

@ -14,15 +14,16 @@ $header = [
//Route::get('/test', 'Test/index');
Route::post('/test', 'Test/index');
Route::post('/test_upload', 'Upload/uploadVideo');
Route::post('test_api', 'video/addVideoOnDemand');
Route::post('test_api', 'document.Index/informationArticleAdd');
Route::group('/', function () {
// 上传图片
Route::post('/upload', 'Upload/upload');
// 国家和地区
Route::post('/country', 'Country/getAll');
// 配置
Route::post('/set_config', 'Config/setConfig');
Route::post('/get_config', 'Config/getConfig');
Route::post('set_config', 'Config/setConfig'); // 创建或修改一个系统配置
Route::post('get_config', 'Config/getConfig'); // 获取单个系统配置值
Route::post('get_config_list', 'Config/getConfigList'); // 获取系统配置列表
Route::post('config/email_template_list', 'Config/emailTemplateList'); //获取邮箱模板列表
Route::post('config/edit_email_template', 'Config/editEmailTemplate'); //编辑邮箱模板
@ -187,10 +188,10 @@ Route::group('/', function () {
Route::post('/agent/customer_reception_edit', 'Agent/customerReceptionEdit'); // 客服开启接待用户、关闭接待用户设置
Route::post('agent/customer_user_list', 'Agent/customerUserList'); //获取客服下所有用户
Route::post('/agent/change_user_customer', 'Agent/changeUserCustomer')->middleware('admin_log'); //变更用户绑定的客服
Route::post('/agent/aws_ivs_list', 'Agent/awsIvsList'); //直播推流列表
Route::post('/agent/aws_ivs_add', 'Agent/awsIvsAdd')->middleware('admin_log'); //直播推流配置添加
Route::post('/agent/aws_ivs_edit', 'Agent/awsIvsEdit')->middleware('admin_log'); //直播推流配置编辑
Route::post('/agent/user_list_by_channel', 'Agent/userListByChannel'); //代理下某个渠道的注册用户列表
Route::post('agent/aws_ivs_list', 'Agent/awsIvsList'); //直播推流列表
Route::post('agent/aws_ivs_add', 'Agent/awsIvsAdd')->middleware('admin_log'); //直播推流配置添加
Route::post('agent/aws_ivs_edit', 'Agent/awsIvsEdit')->middleware('admin_log'); //直播推流配置编辑
Route::post('agent/user_list_by_channel', 'Agent/userListByChannel'); //代理下某个渠道的注册用户列表
Route::post('agent/stats_by_channel', 'Agent/statsByChannel'); //按天统计用户数据
// 用户管理
@ -218,6 +219,9 @@ Route::group('/', function () {
// 送会员
Route::post('admin/give_vip', 'Admin/giveVip')->middleware('admin_log'); //赠送用户vip
Route::post('admin/send_email_or_sms', 'Admin/sendEmailOrSms'); // 给用户发邮件或者短信
Route::post('admin/batch_send_email_or_sms', 'Admin/batchSendEmailOrSms'); // 批量给用户发邮件或者短信
Route::post('admin/exec_batch_send_sms', 'Admin/execBatchSendSms'); // 定时任务执行 - 批量发送短信
Route::post('admin/exec_batch_send_email', 'Admin/execBatchSendEmail'); // 定时任务执行 - 批量发送邮件
// 配置管理
// 外汇插针行情
@ -574,6 +578,10 @@ Route::group('/', function () {
Route::post('/document/doc_detail', 'document.Index/detail');
Route::post('/document/doc_edit', 'document.Index/edit')->middleware('admin_log');
Route::post('/document/doc_del', 'document.Index/del')->middleware('admin_log');
// 股票咨询文章
Route::post('document/information_article_list', 'document.Index/informationArticleList'); // 股票资讯文章列表
Route::post('document/information_article_add', 'document.Index/informationArticleAdd'); // 股票资讯文章新增
Route::post('document/information_article_edit', 'document.Index/informationArticleEdit'); // 股票资讯文章编辑
// 公告管理
Route::post('/document/announcement_index', 'document.Announcement/index');
Route::post('/document/announcement_add', 'document.Announcement/add')->middleware('admin_log');
@ -595,7 +603,8 @@ Route::group('/', function () {
//用户中心
Route::post('/account/update_info', 'Admin/updateInfo');
Route::post('account/update_info', 'Admin/updateInfo');
Route::post('account/get_users_by_role', 'Admin/getUsersByRole'); //根据角色名称获取账号列表
Route::post('/account/add', 'Admin/addUser')->middleware('admin_log'); // 创建管理端账号
Route::get('/account/get_user_info', 'Admin/getUserInfo');
Route::post('/account/update_password', 'Admin/updatePassword')->middleware('admin_log');
@ -606,8 +615,10 @@ Route::group('/', function () {
Route::post('/account/update_account', 'Admin/updateAccount');
Route::get('/account/get_perm_code', 'Admin/getPermCode');
Route::post('/account/get_translator_list', 'Admin/getTranslatorList'); //获取翻译员列表
Route::post('/account/translator_add_customer', 'Admin/translatorAddCustomer')->middleware('admin_log'); //翻译员添加客服好友
Route::post('/account/translator_bind_customer_list', 'Admin/translatorBindCustomerList')->middleware('admin_log'); // 翻译员绑定的客服列表
Route::post('account/translator_add_customer', 'Admin/translatorAddCustomer')->middleware('admin_log'); //翻译员添加客服chat好友
Route::post('account/translator_bind_customer_list', 'Admin/translatorBindCustomerList')->middleware('admin_log'); // 翻译员绑定的客服列表
Route::post('account/group_leader_with_user', 'Admin/groupLeaderWithUser'); // 组长与用户添加chat好友
Route::post('account/seller_with_user', 'Admin/sellerWithUser'); // 电销与用户添加chat好友
Route::post('admin/get_user_access_log', 'Admin/getUserAccessLog'); //获取用户访问页面的记录
Route::post('admin/get_admin_operation_log', 'Admin/getAdminOperationLog'); //获取管理员admin的操作记录

264
app/admin/service/AdminService.php

@ -2,36 +2,54 @@
namespace app\admin\service;
use app\admin\middleware\AdminLog;
use app\admin\validate\AdminValidate;
use app\home\service\BaseHomeService;
use app\model\AdminLogModel;
use app\model\AdminModel;
use app\model\AuthRoleModel;
use app\model\EmailTemplateModel;
use app\model\GroupLeaderWithUserModel;
use app\model\PurchaseVipLogModel;
use app\model\PurchaseVipModel;
use app\model\SmsTemplateModel;
use app\model\SellerWithUserModel;
use app\model\TranslatorCustomerModel;
use app\model\UserAccessLogModel;
use app\model\UserChatGroupModel;
use app\model\UserChatLinkModel;
use app\model\UserModel;
use app\model\UserStockLogModel;
use app\model\UserStockModel;
use phpDocumentor\Reflection\Type;
use think\facade\Cache;
use think\exception\ValidateException;
use app\utility\UnqId;
use think\facade\Config;
use think\facade\Db;
use think\facade\Log;
use think\facade\Queue;
use function Sodium\compare;
use think\facade\Request;
class AdminService extends AdminBaseService
{
const BATCH_SMS_LIST_KEY = "BATCH_SMS_LIST_KEY"; // 批量发送短信redis Key
const BATCH_SMS_CONTENT_KEY = "BATCH_SMS_CONTENT_KEY"; // 批量发送短信内容Key
const BATCH_EMAIL_LIST_KEY = "BATCH_EMAIL_LIST_KEY"; // 批量发送邮件redis Key
const BATCH_EMAIL_CONTENT_KEY = "BATCH_EMAIL_CONTENT_KEY"; // 邮件内容redis key
// 根据角色获取账号列表
public function getUsersByRole($param)
{
try {
if (!isset($param['role_name'])) {
return $this->toData('400', '缺少参数');
}
$role = AuthRoleModel::where(['name'=>$param['role_name']])->find();
if (empty($role)) {
return $this->toData('500', '没有目标角色信息');
}
// 根据角色查询账号列表
$users = AdminModel::where(['role_id'=>$role->id])->select()->toArray();
return $this->toData('0', 'ok', $users);
} catch (\Exception $e) {
return $this->toData('500', '系统错误', [$e->getMessage(), $e->getTrace()]);
}
}
public function addUser($param): array
{
@ -242,8 +260,9 @@ class AdminService extends AdminBaseService
$user['role_id'] = $param['role_id'];
$user['user_name'] = $param['user_name'];
$user['nick_name'] = $param['nick_name'];
$user['email'] = isset($param['email']) ? $param['email'] : null;
$user['remark'] = isset($param['remark']) ? $param['remark'] : null;
$user['email'] = $param['email'] ?? null;
$user['remark'] = $param['remark'] ?? null;
$user['parent_id'] = $param['parent_id'] ?? 0;
$user->save();
// 返回
return $this->toData('0', 'Modification successful.', []);
@ -532,6 +551,84 @@ class AdminService extends AdminBaseService
}
}
// 组长与用户添加chat好友
public function groupLeaderWithUser($param)
{
try {
if (empty($param['group_leader_id']) || empty($param['user_id'])) {
return $this->toData('400', '缺少参数');
}
$relation = GroupLeaderWithUserModel::where(['user_id'=>$param['user_id']])->find();
if (empty($relation)) {
$res = GroupLeaderWithUserModel::create([
'user_id' => $param['user_id'],
'group_leader_id' => $param['group_leader_id']
]);
if (empty($res->id)) {
return $this->toData('0', '操作失败');
}
}
$adminUserChat = UserChatLinkModel::where(['user_id'=>$param['group_leader_id'], 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find();
if (empty($adminUserChat)) {
return $this->toData('400', '管理端账号缺少chat信息');
}
$frontUserChat = UserChatLinkModel::where(['user_id'=>$param['user_id'], 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC])->find();
if (empty($frontUserChat)) {
return $this->toData('400', '用户账号缺少chat信息');
}
$chatFriendsData = [
'UserUuid' => $frontUserChat->chat_uuid,
'CustomerUuid' => $adminUserChat->chat_uuid,
];
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends';
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData);
return $this->toData('0', 'ok', $chatFriendsRes);
} catch (\Exception $e) {
return $this->toData('500', '系统错误', [$e->getMessage(), $e->getTrace()]);
}
}
// 电销与用户添加chat好友
public function sellerWithUser($param)
{
try {
if (empty($param['seller_id']) || empty($param['user_id'])) {
return $this->toData('400', '缺少参数');
}
$relation = SellerWithUserModel::where(['user_id'=>$param['user_id']])->find();
if (empty($relation)) {
$res = SellerWithUserModel::create([
'user_id' => $param['user_id'],
'seller_id' => $param['seller_id']
]);
if (empty($res->id)) {
return $this->toData('0', '操作失败');
}
}
$adminUserChat = UserChatLinkModel::where(['user_id'=>$param['seller_id'], 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find();
if (empty($adminUserChat)) {
return $this->toData('400', '管理端账号缺少chat信息');
}
$frontUserChat = UserChatLinkModel::where(['user_id'=>$param['user_id'], 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_PC])->find();
if (empty($frontUserChat)) {
return $this->toData('400', '用户账号缺少chat信息');
}
$chatFriendsData = [
'UserUuid' => $frontUserChat->chat_uuid,
'CustomerUuid' => $adminUserChat->chat_uuid,
];
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/eachOtherFriends';
$chatFriendsRes = (new \app\utility\RequestChatServer())->ReqChatServer($chatFriendsUrl, $chatFriendsData);
return $this->toData('0', 'ok', $chatFriendsRes);
} catch (\Exception $e) {
return $this->toData('500', '系统错误', [$e->getMessage(), $e->getTrace()]);
}
}
// 用户访问页面的记录
public function getUserAccessLog($param)
{
@ -698,4 +795,151 @@ class AdminService extends AdminBaseService
}
}
// 批量发送短信或邮件
public function batchSendEmailOrSms($param)
{
try {
// type: 1-短信,2-邮件
if (!in_array($param['type'], [1,2])) {
return $this->toData('400', '发送类型不在支持范围内');
}
// content: 发送的消息内容
if (empty($param['content'])) {
return $this->toData('400', '消息内容不能为空');
}
// user_ids: 要发送的用户ID, 数组格式
if (empty($param['user_ids']) || !is_array($param['user_ids'])) {
return $this->toData('400', '用户ID错误');
}
switch ($param['type']) {
case 1: // 发送短信
$userList = UserModel::where('user_id', 'in', $param['user_ids'])->column('phone_number', 'user_id');
if (empty($userList)) {
return $this->toData('500', '用户列表为空');
}
// 将短信内容存储在redis中
Cache::store('redis')->set(self::BATCH_SMS_CONTENT_KEY, $param['content']);
// 将用户手机号存储到redis list中
foreach ($userList as $phone) {
if (empty($phone)) {
continue;
}
Cache::store('redis')->lpush(self::BATCH_SMS_LIST_KEY, $phone);
}
break;
case 2: // 发送邮件
if (empty($param['title'])) {
return $this->toData('400', '邮件标题不能为空');
}
$userList = UserModel::where('user_id', 'in', $param['user_ids'])->column('email', 'user_id');
if (empty($userList)) {
return $this->toData('500', '用户列表为空');
}
// 将邮件内容存储在redis中
$buildContent = $param['title']."@".$param['content'];
Cache::store('redis')->set(self::BATCH_EMAIL_CONTENT_KEY, $buildContent);
// 将用邮箱存储到redis list中
foreach ($userList as $email) {
if (empty($email)) {
continue;
}
Cache::store('redis')->lpush(self::BATCH_EMAIL_LIST_KEY, $email);
}
break;
default:
return $this->toData('500', '操作类型错误', []);
}
return $this->toData('0', 'ok');
} catch (\Exception $e) {
return $this->toData('500', 'The system is busy', [$e->getMessage(), $e->getTrace()]);
}
}
// 定时任务处理匹批量发送短信
public function execBatchSendSms()
{
try {
// 每次处理2000个用户
$maxNum = 2000;
$smsLen = Cache::store('redis')->llen(self::BATCH_SMS_LIST_KEY);
if ($smsLen <= 0) {
return;
}
if ($smsLen < $maxNum) {
$maxNum = $smsLen;
}
$accessKey = env('SMS.ACCESS_KEY_ID');
$secret = env('SMS.ACCESS_KEY_SECRET');
if (empty($accessKey) || empty($secret)) {
Log::info("批量短信发送 - 短信配置数据未找到");
return;
}
$content = Cache::store('redis')->get(self::BATCH_SMS_CONTENT_KEY);
if (empty($content)) {
Log::info("批量短信发送 - 短信内容不能为空");
return;
}
$smsObj = new \app\utility\SendSms();
for ($i=1; $i<=$maxNum; $i++) {
$phone = Cache::store('redis')->rpop(self::BATCH_SMS_LIST_KEY);
if (empty($phone)) {
continue;
}
$from = 'Auto';
$bool = $smsObj->sendMessageToGlobe($phone, $content, $from, $accessKey, $secret);
if (!$bool) {
Log::info("批量短信发送 - 当前用户发送失败, phone=".$phone);
}
}
return $this->toData('0', 'ok');
} catch (\Exception $e) {
Log::info("批量短信发送异常:err==". $e->getMessage()." trace==".$e->getTraceAsString());
return $this->toData('500', 'The system is busy', [$e->getMessage(), $e->getTrace()]);
}
}
// 定时任务执行批量发送邮件任务
public function execBatchSendEmail(){
try {
// 每次处理2000个用户
$maxNum = 2000;
$emailLen = Cache::store('redis')->llen(self::BATCH_EMAIL_LIST_KEY);
if ($emailLen <= 0) {
return;
}
if ($emailLen < $maxNum) {
$maxNum = $emailLen;
}
$content = Cache::store('redis')->get(self::BATCH_EMAIL_CONTENT_KEY);
if (empty($content)) {
Log::info("批量邮件发送 - 邮件内容不能为空");
return;
}
// 邮件内容需要以@符号分割,然后获取到title 和 content
$splStr = explode('@', $content);
$title = $splStr[0];
$msg = $splStr[1];
$phpEmail = new \app\utility\SendEmail();
for ($i=1; $i<=$maxNum; $i++) {
$email = Cache::store('redis')->rpop(self::BATCH_EMAIL_LIST_KEY);
if (empty($email)) {
continue;
}
$emailTemplate['email'] = $email;
$title = trim($title);
$content = trim($msg);
$bool = $phpEmail->sendEmail($emailTemplate['email'], $title, $content);
if (!$bool) {
Log::info("批量发送邮件 - 当前用户发送失败, email=".$email);
}
}
return $this->toData('0', 'ok');
} catch (\Exception $e) {
Log::info("批量短信发送异常:err==". $e->getMessage()." trace==".$e->getTraceAsString());
return $this->toData('500', 'The system is busy', [$e->getMessage(), $e->getTrace()]);
}
}
}

25
app/admin/service/AgentService.php

@ -14,6 +14,7 @@ use app\model\StockTradeModel;
use app\model\UserChatLinkModel;
use app\model\UserModel;
use app\model\UserWithdrawalModel;
use think\facade\Log;
class AgentService extends AdminBaseService
{
@ -313,8 +314,21 @@ class AgentService extends AdminBaseService
]);
}
// 请求chat服务获取每个直播间的审核状态
$items = [];
if (!empty($list->items())) {
$httpClient = new \app\utility\RequestChatServer();
foreach ($list->items() as $v) {
$chatFriendsUrl = env('CHAT_SERVER.BASE_URL') . '/api/message/auditProcess/'.$v['agent_chat_group_id'];
$httpRes = $httpClient->ReqChatServer($chatFriendsUrl, [], 'GET');
$tmp = $v;
$tmp['review_status'] = $httpRes['data'];
$items[] = $tmp;
}
}
return $this->toData('0', 'success', [
'list' => $list->items(), // 当前页的数据
'list' => $items, // 当前页的数据
'page' => $list->currentPage(), // 当前页码
'total' => $list->total(), // 总记录数
'last_page' => $list->lastPage(), // 最后一页页码
@ -362,7 +376,9 @@ class AgentService extends AdminBaseService
'push_url' => $param['push_url'],
'secret_key' => $param['secret_key'],
'play_url' => $param['play_url'],
'agent_id' => $param['agent_id']
'agent_id' => $param['agent_id'],
'ad_content' => $param['ad_content'] ?? "",
'state' => $param['state'] ?? 1,
]);
return $this->toData('0', 'success', ['id' => $res->id]);
} catch (\Exception $exception) {
@ -376,6 +392,9 @@ class AgentService extends AdminBaseService
if (empty($param['id'])) {
return $this->toData('400', 'Missing param id');
}
if (!isset($param['state'])) {
return $this->toData('400', 'Parameter error');
}
if (empty($param['title']) || empty($param['anchor_name']) || empty($param['desc']) || empty($param['push_url']) || empty($param['secret_key']) || empty($param['play_url']) || empty($param['agent_id'])) {
return $this->toData('400', 'Parameter error');
}
@ -391,6 +410,8 @@ class AgentService extends AdminBaseService
$ckInfo->push_url = $param['push_url'];
$ckInfo->secret_key = $param['secret_key'];
$ckInfo->play_url = $param['play_url'];
$ckInfo->ad_content = $param['ad_content'] ?? '';
$ckInfo->state = $param['state'];
$ckInfo->save();
return $this->toData('0', 'success');
} catch (\Exception $exception) {

28
app/admin/service/ConfigService.php

@ -2,12 +2,40 @@
namespace app\admin\service;
use app\admin\service\AdminBaseService;
use app\model\ConfigModel;
use app\model\EmailTemplateModel;
use app\model\SmsTemplateModel;
use app\model\VideoOnDemandModel;
class ConfigService extends AdminBaseService
{
// 获取系统配置列表
public function getConfigList($param)
{
try {
if (empty($param['page']) || empty($param['limit'])) {
return $this->toData('400', '参错错误');
}
$where =[];
if (!empty($param['name'])) {
$where['name'] = $param['name'];
}
$list = ConfigModel::where($where)->order('id', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'SUCCESS', [
'list' => $list->items(),
'total' => $list->total(),
'page' => $list->currentPage(),
'last_page' => $list->lastPage(),
]);
} catch (\Exception $e) {
return $this->toData('500', '系统错误', [$e->getMessage(), $e->getTrace()]);
}
}
// 获取邮箱模板列表
public function emailTemplateList($param)
{

42
app/admin/service/UserService.php

@ -9,6 +9,8 @@ use app\model\AdminModel;
use app\model\AuthRoleModel;
use app\model\AwsS3Model;
use app\model\CountryModel;
use app\model\GroupLeaderWithUserModel;
use app\model\SellerWithUserModel;
use app\model\StockMarketModel;
use app\model\UserBankModel;
use app\model\UserChatGroupModel;
@ -266,12 +268,27 @@ class UserService extends AdminBaseService
->where('contract_id', 'USD')
->column('usable_num,frozen_num', 'user_id');
// 获取每个客服的名称
$customerNames = [];
// 获取用户绑定的客服信息
$customerIds = [];
if ($customerRelationList) {
$customerIds = array_values($customerRelationList);
$customerNames = AdminModel::where('id', 'in', $customerIds)->column('nick_name', 'id');
}
// 获取用户绑定的组长信息
$groupLeaderList = GroupLeaderWithUserModel::where('user_id', 'in', $userIdArr)->column('group_leader_id', 'user_id');
$groupLeaderIds = [];
if (!empty($groupLeaderList)) {
$groupLeaderIds = array_keys($groupLeaderList);
}
// 获取用户绑定的电销员信息
$sellerList = SellerWithUserModel::where('user_id', 'in', $userIdArr)->column('seller_id', 'user_id');
$sellerIds = [];
if (!empty($sellerList)) {
$sellerIds = array_keys($sellerList);
}
// 合并account账号,一次性查出account信息
$accountIds = array_merge($customerIds,$groupLeaderIds,$sellerIds);
$accountList = AdminModel::where('id', 'in', $accountIds)->column('user_name', 'id');
// 查询用户充值、提款冻结状态
$accountFrozenList = AccountFrozenModel::where('user_id', 'in', $userIdArr)->column('frozen_recharge,frozen_withdraw', 'user_id');
@ -305,10 +322,23 @@ class UserService extends AdminBaseService
->join([$subQuery => 'w'], 'a.user_id=w.user_id AND a.login_date=w.last_login_date')->column(['id', 'ip', 'country', 'city'], 'a.user_id');
foreach ($userList as $item) {
// 客服信息
$itmCustomerId = $customerRelationList[$item['user_id']] ?? 0; //当前用户关联的客服ID
$itmCustomerName = "";
if ($itmCustomerId) {
$itmCustomerName = $customerNames[$itmCustomerId] ?? ""; //当前客服的名称
$itmCustomerName = $accountList[$itmCustomerId] ?? ""; //当前客服的名称
}
// 组长信息
$groupLeaderId = $groupLeaderList[$item['user_id']] ?? 0; // 用户绑定的组长ID
$groupLeaderName = "";
if ($groupLeaderId) {
$groupLeaderName = $accountList[$groupLeaderId] ?? ""; //用户绑定的组长名称
}
// 电销员信息
$sellerId = $sellerList[$item['user_id']] ?? 0; // 电销员ID
$sellerName = "";
if ($sellerId) {
$sellerName = $accountList[$sellerId] ?? ""; // 电销员名称
}
$rows[] = [
@ -326,6 +356,10 @@ class UserService extends AdminBaseService
'base_label' => $item['base_label'],
'customer_id' => $itmCustomerId,
'customer_name' => $itmCustomerName,
'group_leader_id' => $groupLeaderId,
'group_leader_name' => $groupLeaderName,
'seller_id' => $sellerId,
'seller_name' => $sellerName,
'real_name_translation' => $realNameTranslation[$item['user_id']] ?? [],
'frozen_recharge' => $accountFrozenList[$item['user_id']]['frozen_recharge'] ?? 0,
'frozen_withdraw' => $accountFrozenList[$item['user_id']]['frozen_withdraw'] ?? 0,

1
app/admin/service/VideoService.php

@ -75,7 +75,6 @@ class VideoService extends AdminBaseService
$ckInfo->title = $param['title'];
$ckInfo->desc = $param['desc'];
$ckInfo->cover_url = $param['cover_url'];
$ckInfo->video_url = $param['video_url'];
$ckInfo->banner_url = $param['banner_url'];
$ckInfo->sort = $param['sort'];
$ckInfo->state = $param['state'];

70
app/admin/service/document/IndexService.php

@ -4,6 +4,7 @@ namespace app\admin\service\document;
use app\admin\service\AdminBaseService;
use app\model\DocumentModel;
use app\model\InformationArticleModel;
use app\model\LanguageSettingModel;
class IndexService extends AdminBaseService
@ -208,4 +209,73 @@ class IndexService extends AdminBaseService
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function informationArticleList($param)
{
try {
if (empty($param['page']) || empty($param['limit'])) {
return $this->toData('400', '参错错误');
}
$where = [];
if (isset($param['type'])) {
$where['type'] = $param['type'];
}
$list = InformationArticleModel::where($where)->order('id', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'Successful', [
'list' => $list->items(),
'total' => $list->total(),
'page' => $list->currentPage(),
'last_page' => $list->lastPage(),
]);
} catch (\Exception $e) {
return $this->toData('500', '系统繁忙', [$e->getMessage(), $e->getTrace()]);
}
}
public function informationArticleAdd($param)
{
try {
if (empty($param['lang']) || empty($param['type']) || empty($param['title']) || empty($param['content']) || empty($param['cover'])) {
return $this->toData('400', '参错错误');
}
if (!isset($param['state'])) {
return $this->toData('400', '参错错误');
}
InformationArticleModel::create($param);
return $this->toData('0', 'Successful');
} catch (\Exception $e) {
return $this->toData('500', '系统繁忙', [$e->getMessage(), $e->getTrace()]);
}
}
public function informationArticleEdit($param)
{
try {
if (empty($param['id']) || empty($param['lang']) || empty($param['type']) || empty($param['title']) || empty($param['content']) || empty($param['cover'])) {
return $this->toData('400', '参错错误');
}
if (!isset($param['state'])) {
return $this->toData('400', '参错错误');
}
$info = InformationArticleModel::where(['id'=>$param['id']])->find();
if (empty($info)) {
return $this->toData('400', '编辑的数据不存在');
}
$info->lang = $param['lang'];
$info->type = $param['type'];
$info->title = $param['title'];
$info->content = $param['content'];
$info->cover = $param['cover'];
$info->state = $param['state'];
$info->save();
return $this->toData('0', 'Successful');
} catch (\Exception $e) {
return $this->toData('500', '系统繁忙', [$e->getMessage(), $e->getTrace()]);
}
}
}

16
app/home/controller/Document.php

@ -2,6 +2,7 @@
namespace app\home\controller;
use app\home\service\DocumentService;
use app\model\DocumentModel;
use app\model\LanguageSettingModel;
use think\response\Json;
@ -204,4 +205,19 @@ class Document extends HomeBaseController
'data' => ['content' => $docChange['content'],'title'=>$docChange['title']],
]);
}
// 获取股票资讯文章
public function informationArticleList()
{
$returnData = (new DocumentService())->informationArticleList($this->request->post());
return json($returnData);
}
// 获取单个资讯详情
public function informationArticleDetails()
{
$returnData = (new DocumentService())->informationArticleDetails($this->request->post());
return json($returnData);
}
}

5
app/home/route/app.php

@ -60,6 +60,10 @@ Route::group('/',function (){
Route::post('/doc_detail', 'Document/detail');
Route::post('/doc', 'Document/getDoc');
// 股票资讯文章
Route::post('information_article_list', 'Document/informationArticleList'); // 获取股票资讯文章列表
Route::post('information_article_details', 'Document/informationArticleDetails'); //获取一条资讯详情
// 国家和地区
Route::post('/country', 'Country/getAll');
// 获取首页广告图
@ -292,6 +296,7 @@ Route::group('/',function (){
Route::post('get_ip', 'Login/getIP');
Route::get('get_news', 'News/index');
Route::post('test', 'Stock/stockAnalysis');
Route::post('test_api', 'Document/informationArticleList');
})->allowCrossDomain($header);

55
app/home/service/DocumentService.php

@ -0,0 +1,55 @@
<?php
namespace app\home\service;
use app\model\InformationArticleModel;
class DocumentService extends BaseHomeService
{
// 获取股票资讯文章
public function informationArticleList($param)
{
try {
if (empty($param['page']) || empty($param['limit'])) {
return $this->toData('400', '参错错误');
}
$where = ['state'=>1];
if (isset($param['type'])) {
$where['type'] = $param['type'];
}
$list = InformationArticleModel::where($where)->order('id', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'Successful', [
'list' => $list->items(),
'total' => $list->total(),
'page' => $list->currentPage(),
'last_page' => $list->lastPage(),
]);
} catch (\Exception $d) {
return $this->toData('500', 'The system is busy');
}
}
// 获取一条资讯详情
public function informationArticleDetails($param)
{
try {
if (empty($param['id'])) {
return $this->toData('400', '参错错误');
}
$info = InformationArticleModel::where(['id'=>$param['id']])->find();
if (empty($info)) {
return $this->toData('400', '数据为空');
}
$res = $info->toArray();
return $this->toData('0', 'Successful', $res);
} catch (\Exception $d) {
return $this->toData('500', 'The system is busy');
}
}
}

96
app/home/service/LoginService.php

@ -92,10 +92,10 @@ class LoginService extends BaseHomeService
// 获取客户端ip
$ip = $this->getClientRealIp();
$inviteCode = $param['invite_code'] ?? AdminModel::getDefaultAgentId(); // p2项目中如果注册时未填写邀请码,则将用户分配到这个默认的代理下
$agentCode = $param['agent_code'] ?? ''; // 代理
$chCode = $param['ch_code'] ?? ''; // 注册渠道标识码
$phone = $param['phone']; //p2定制需求-邮箱注册必须传手机号
$agentCode = $param['agent_code'] ?? ''; // 代理邀请码(该邀请码只限于管理端账号中)
$inviteCode = $param['invite_code'] ?? ''; // 邀请码 (该邀请码即可以是管理端账号的邀请码,也可以是用户表中的邀请码)
$chCode = $param['ch_code'] ?? ''; // 注册渠道标识码
$phone = $param['phone'];
$email = $param['email'];
// 邮件注册参数校验
@ -126,32 +126,27 @@ class LoginService extends BaseHomeService
return $this->toData('100300', 'The email has already been registered.', []);
}
// 判断邀请人是否存在
// 获取代理ID (后续要查询代理下的客服,将用户与其中一个客服绑定)
$agentId = 0;
if (!empty($agentCode)) {
$agentId = AdminModel::getIdByInviteCode($agentCode);
}
// 获取邀请码对应的账号ID(可以是管理端的账号,也可以是用户列表中的账号)
$parentAdminId = 0;
$parentUserId = 0;
if (!empty($inviteCode)) {
$agentId = AdminModel::getIdByInviteCode($inviteCode);
if ($agentId <= 0) {
$parentUserId = $this->getParentIdByInviteCode($inviteCode);
if ($parentUserId <= 0) {
return $this->toData('100400', 'The invitation code is invalid.', []);
}
$parentAdminId = AdminModel::getIdByInviteCode($inviteCode); // 先从管理端账号中查找是否存在邀请码对应的账号
if ($parentAdminId) {
$agentId = $parentAdminId;
} else {
$parentUserId = $this->getParentIdByInviteCode($inviteCode); // 再从用户账号中查找是否存在邀请码对应的账号
}
}
// 判断代理人是否存在
if (!empty($agentCode) || $agentId > 0) {
if ($agentId == 0) {
$agentId = AdminModel::getIdByInviteCode($agentCode);
if ($agentId <= 0) {
return $this->toData('100401', 'The invitation code is invalid.', []);
}
}
} else {
// 是否必须填写有效的邀请码
$inviteCodeIsRequired = env("REG_USER.INVITE_CODE_REQUIRED");
if ($parentUserId <= 0 && $inviteCodeIsRequired >= 1) {
return $this->toData('100402', 'The invitation code is invalid.', []);
// 如果没有传递代理邀请码,也没有根据invite_code找到管理端账号,则设置一个默认的代理
if (empty($agentId) && empty($parentAdminId)) {
$agentId = AdminModel::getDefaultAgentId();
if (empty($agentId)) {
return $this->toData('500', '缺少代理ID');
}
}
@ -223,8 +218,9 @@ class LoginService extends BaseHomeService
// 如果有代理,绑定到代理下一个客服(轮询客服绑定)
if ($agentId > 0 ) {
$customerIds = AdminModel::getCustomerIdsByAgentId($agentId); // 获取代理下的所有客服ID
Log::info("邮箱注册 - 客服列表:".json_encode($customerIds));
if (empty($customerIds)) {
return $this->toData('500', 'There is no customer service account under the current agent');
return $this->toData('500', '客服数据错误');
}
$counterKey = 'counter_of_bind_customer:'.$agentId;
$counterIndex = Cache::store('redis')->get($counterKey); //客服绑定计数器索引
@ -236,6 +232,7 @@ class LoginService extends BaseHomeService
$tagIndex = $counterIndex % count($customerIds);
$tagCustomerId = $customerIds[$tagIndex];
}
Log::info("邮箱注册 - 当前绑定客服ID:".$tagCustomerId);
if ($tagCustomerId > 0) {
$regUser->customer_id = $tagCustomerId;
$regUser->save();
@ -433,9 +430,8 @@ class LoginService extends BaseHomeService
try {
// 防止重复操作
$ip = $this->getClientRealIp();
$inviteCode = $param['invite_code'] ?? AdminModel::getDefaultAgentId(); // p2项目中如果注册时未填写邀请码,则将用户分配到这个默认的代理下
$agentCode = $param['agent_code'] ?? ''; // 代理
$agentCode = $param['agent_code'] ?? ''; // 代理邀请码(该邀请码只限于管理端账号中)
$inviteCode = $param['invite_code'] ?? ''; // 邀请码 (该邀请码即可以是管理端账号的邀请码,也可以是用户表中的邀请码)
$chCode = $param['ch_code'] ?? '';
// 短信注册参数校验
@ -466,32 +462,27 @@ class LoginService extends BaseHomeService
return $this->toData('100300', 'The phone number has already been registered.', []);
}
// 邀请人
$parentUserId = 0;
// 获取代理ID (后续要查询代理下的客服,将用户与其中一个客服绑定)
$agentId = 0;
if (!empty($agentCode)) {
$agentId = AdminModel::getIdByInviteCode($agentCode);
}
// 获取邀请码对应的账号ID(可以是管理端的账号,也可以是用户列表中的账号)
$parentAdminId = 0;
$parentUserId = 0;
if (!empty($inviteCode)) {
$agentId = AdminModel::getIdByInviteCode($inviteCode);
if ($agentId <= 0) {
$parentUserId = $this->getParentIdByInviteCode($inviteCode);
if ($parentUserId <= 0) {
return $this->toData('100400', 'The invitation code is invalid.', []);
}
$parentAdminId = AdminModel::getIdByInviteCode($inviteCode); // 先从管理端账号中查找是否存在邀请码对应的账号
if ($parentAdminId) {
$agentId = $parentAdminId;
} else {
$parentUserId = $this->getParentIdByInviteCode($inviteCode); // 再从用户账号中查找是否存在邀请码对应的账号
}
}
// 判断代理人是否存在
if (!empty($agentCode) || $agentId > 0) {
if ($agentId == 0) {
$agentId = AdminModel::getIdByInviteCode($agentCode);
if ($agentId <= 0) {
return $this->toData('100400', 'The invitation code is invalid.', []);
}
}
} else {
// 是否必须填写有效的邀请码
$inviteCodeIsRequired = env("REG_USER.INVITE_CODE_REQUIRED");
if ($parentUserId <= 0 && $inviteCodeIsRequired >= 1) {
return $this->toData('100400', 'The invitation code is invalid.', []);
// 如果没有传递代理邀请码,也没有根据invite_code找到管理端账号,则设置一个默认的代理
if (empty($agentId) && empty($parentAdminId)) {
$agentId = AdminModel::getDefaultAgentId();
if (empty($agentId)) {
return $this->toData('500', '缺少代理ID');
}
}
@ -560,7 +551,7 @@ class LoginService extends BaseHomeService
if ($agentId > 0 ) {
$customerIds = AdminModel::getCustomerIdsByAgentId($agentId); // 获取代理下的所有客服ID
if (empty($customerIds)) {
return $this->toData('500', 'There is no customer service account under the current agent', []);
return $this->toData('500', '客服数据错误');
}
$counterKey = 'counter_of_bind_customer:'.$agentId;
$counterIndex = Cache::store('redis')->get($counterKey); //客服绑定计数器索引
@ -572,6 +563,7 @@ class LoginService extends BaseHomeService
$tagIndex = $counterIndex % count($customerIds);
$tagCustomerId = $customerIds[$tagIndex];
}
Log::info("手机号注册 - 当前绑定的客服ID:".$tagCustomerId);
if ($tagCustomerId > 0) {
$regUser->customer_id = $tagCustomerId;
$regUser->save();

16
app/home/service/UserService.php

@ -8,6 +8,7 @@ use app\model\AwsIvsModel;
use app\model\AwsS3Model;
use app\model\CountryModel;
use app\model\FileModel;
use app\model\GroupLeaderWithUserModel;
use app\model\PurchaseVipLogModel;
use app\model\PurchaseVipModel;
use app\model\UserAccessLogModel;
@ -202,6 +203,19 @@ class UserService extends BaseHomeService
$group_chat_uuid = $agentGroup->group_uuid;
}
// 获取当前用户绑定的组长chat信息
$groupLeader = GroupLeaderWithUserModel::where('user_id', $userId)->find();
$groupLeaderChatUuid = 0;
$groupLeaderChatName = "";
if ($groupLeader) {
$groupLeaderChatInfo = UserChatLinkModel::where(['user_id'=>$groupLeader->group_leader_id, 'user_type'=>UserChatLinkModel::USER_CHAT_LINK_USER_TYPE_ADMIN])->find();
if ($groupLeaderChatInfo) {
$groupLeaderChatUuid = $groupLeaderChatInfo->chat_uuid;
$groupLeaderChatName = $groupLeaderChatInfo->chat_name;
}
}
// 检测用户是否为有效VIP [判断规则 - 用户购买过VIP, 每个VIP有效期30天]
$isVip = false;
$vipExpire = ""; //vip到期时间
@ -241,6 +255,8 @@ class UserService extends BaseHomeService
'customer_chat_avatar' => '/bs/image/default.jpeg',
'group_chat_name' => $group_chat_name,
'group_chat_uuid' => $group_chat_uuid,
'group_leader_chat_uuid' => $groupLeaderChatUuid,
'group_leader_chat_name' => $groupLeaderChatName,
'is_vip' => $isVip,
'vip_expire' => $vipExpire,
'customer_remark' => $info['customer_remark'],

22
app/home/service/VideoService.php

@ -17,18 +17,18 @@ class VideoService extends BaseHomeService
return $this->toData('400', '参错错误');
}
// 根据video_type 过滤数据
if (isset($param['video_type']) && $param['video_type'] > 0 ) {
$list = VideoOnDemandModel::where(['state'=>1,'video_type'=>$param['video_type']])->order('sort', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
} else {
$list = VideoOnDemandModel::where(['state'=>1])->order('sort', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
$where = ['state'=>1];
if (isset($param['video_type']) && $param['video_type'] > 0) {
$where['video_type'] = $param['video_type'];
}
if (isset($param['sub_type']) && $param['sub_type'] > 0) {
$where['sub_type'] = $param['sub_type'];
}
$list = VideoOnDemandModel::where($where)->order('sort', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'Successful', [
'list' => $list->items(), // 当前页的数据

26
app/model/AdminModel.php

@ -12,7 +12,6 @@ class AdminModel extends BaseModel
const ROLE_ID_ADMIN = 1; //超级管理员角色
const ROLE_ID_AGENT = 2; // 代理角色
const DEFAULT_AGENT_ID = 2; // 默认的代理ID(P2项目用户注册时,邀请码未填时,就分配给这个默认的代理下)
// 通过代理id 获取代理下面可以访问的所有用户id
public static function getUserIdsByAgentId($agentId)
{
@ -85,16 +84,31 @@ class AdminModel extends BaseModel
// 获取默认的代理ID
public static function getDefaultAgentId(): int
{
return self::DEFAULT_AGENT_ID;
$role = AuthRoleModel::where(['name'=>'代理'])->find();
if (empty($role)) {
return 0;
}
return $role->id;
}
// 根据代理ID获取其下属的所有客服ID (账号关系:代理 - 总监 - 组长 - 客服)
public static function getCustomerIdsByAgentId($agentId): array
{
$role = AuthRoleModel::where(['name'=>'客服'])->find();
if (empty($role)) {
// 获取代理下的所有总监ID
$directors = self::where(['parent_id' => $agentId])->column('id');
if (empty($directors)) {
return [];
}
// 获取总监下所有组长ID
$teamHeaders = self::where('parent_id', 'in', $directors)->column('id');
if (empty($teamHeaders)) {
return [];
}
// 获取组长下的客服ID
$customers = self::where('parent_id', 'in', $teamHeaders)->column('id');
if (empty($customers)) {
return [];
}
// p2项目中有客服接待开关,如果客服开启接待,则ext字段设置为1,否则为空或者2
return self::where(['role_id'=>$role->id,'parent_id'=>$agentId,'ext'=>1])->column('id');
return $customers;
}
}

8
app/model/GroupLeaderWithUserModel.php

@ -0,0 +1,8 @@
<?php
namespace app\model;
class GroupLeaderWithUserModel extends BaseModel
{
protected $name = 'group_leader_with_user';
}

8
app/model/InformationArticleModel.php

@ -0,0 +1,8 @@
<?php
namespace app\model;
class InformationArticleModel extends BaseModel
{
protected $name = 'information_article';
}

8
app/model/SellerWithUserModel.php

@ -0,0 +1,8 @@
<?php
namespace app\model;
class SellerWithUserModel extends BaseModel
{
protected $name = 'seller_with_user';
}

10
app/utility/RequestChatServer.php

@ -12,13 +12,17 @@ class RequestChatServer extends BaseHomeService
public function ReqChatServer(string $url, array $data, string $method = 'POST'): array
{
try {
if (!in_array($method, ['POST','PUT'])) {
if (!in_array($method, ['GET','POST','PUT'])) {
return $this->toData('500', '请求方法不在支持列表中');
}
Log::info("Guzzle请求: URL==".$url." 请求Param==".json_encode($data));
$resBody = [];
$client = new Client();
if ($method == 'PUT') {
if ($method == 'GET') {
$response = $client->get($url, [
'query' => $data,
]);
} elseif ($method == 'PUT') {
$response = $client->put($url, [
'json' => $data,
]);
@ -28,7 +32,7 @@ class RequestChatServer extends BaseHomeService
]);
}
$statusCode = $response->getStatusCode();
Log::error("Guzzle请求响应:code==".$statusCode." body==". $response->getBody());
Log::info("Guzzle请求响应:code==".$statusCode." body==". $response->getBody());
if ($statusCode == 200) {
$resBody = json_decode($response->getBody(), true); // 转换为数组
}

6
config/cache.php

@ -27,10 +27,10 @@ return [
// 更多的缓存连接
'redis' => [
'type' => 'redis',
'host' => env('REDIS.HOST', '172.31.120.245'),
'port' => env('REDIS.PORT', '6378'),
'host' => env('REDIS.HOST', '127.0.0.1'),
'port' => env('REDIS.PORT', '26379'),
'select' => env('REDIS.SELECT', '0'),
'password' => env('REDIS.PASSWORD', 'rfvtyujnbhg56'),
'password' => env('REDIS.PASSWORD', '7d00cb62-1d1c-4c86-b50a-ebf9f00cc9fd'),
],
],

Loading…
Cancel
Save