first commit
This commit is contained in:
350
app/api/logic/IndexLogic.php
Normal file
350
app/api/logic/IndexLogic.php
Normal file
@@ -0,0 +1,350 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
|
||||
use app\common\service\{FileService,UtilsService,ConfigService};
|
||||
use app\common\model\article\{Article,ArticleCate};
|
||||
use app\common\model\decorate\{DecorateSwiper,DecorateNav,DecorateHint};
|
||||
use app\common\model\item\Item;
|
||||
use app\common\model\user\{User,UserNotice};
|
||||
use app\common\model\setting\Language;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class IndexLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData(array $params)
|
||||
{
|
||||
//未传语言,则默认使用首个语言
|
||||
if($params['lang'] == ''){
|
||||
$first_lang = UtilsService::get_first_lang();
|
||||
$params['lang'] = $first_lang['symbol'];
|
||||
}
|
||||
|
||||
//轮播图
|
||||
$field1 = ['name','image','link','langs','image_ext'];
|
||||
$swipers = DecorateSwiper::field($field1)
|
||||
->where(['is_show' => 1,'loca' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($swipers as &$swiper) {
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($swiper['langs'],$params['lang']);
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
if($swiper['image_ext'] != ''){
|
||||
$swiper['image'] =$swiper['image_ext'];
|
||||
}else{
|
||||
$swiper['image'] = FileService::getFileUrl($data_image);
|
||||
}
|
||||
unset($swiper['langs']);
|
||||
}
|
||||
|
||||
//菜单按钮
|
||||
$field2 = ['name','image','link','langs','image_ext'];
|
||||
$navs = DecorateNav::field($field2)
|
||||
->where(['is_show' => 1,'loca' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($navs as &$nav) {
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($nav['langs'],$params['lang']);
|
||||
$data_name = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_name = $data['name'];
|
||||
}
|
||||
|
||||
$nav['name'] = $data_name;
|
||||
if($nav['image_ext'] != ''){
|
||||
$nav['image'] = $nav['image_ext'];
|
||||
}
|
||||
unset($nav['langs']);
|
||||
}
|
||||
|
||||
//滚动通知
|
||||
$field3 = ['id','langs'];
|
||||
$notice = Article::field($field3)
|
||||
->where(['is_show' => 1,'is_notice' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->findOrEmpty();
|
||||
|
||||
if(!$notice->isEmpty()){
|
||||
$notice['is_show'] = true;
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($notice['langs'],$params['lang']);
|
||||
$data_text = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_text = $data['content'];
|
||||
}
|
||||
$notice['text'] = strip_tags(html_entity_decode($data_text));
|
||||
unset($notice['langs']);
|
||||
|
||||
}else{
|
||||
$notice['is_show'] = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//合作伙伴
|
||||
$field4 = ['is_show','content','langs'];
|
||||
$partner = DecorateHint::field($field4)
|
||||
->findOrEmpty(4)->toArray();
|
||||
|
||||
if($partner['is_show']){
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($partner['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
$partner['content'] = get_file_domain($data_content);
|
||||
}
|
||||
unset($partner['langs']);
|
||||
|
||||
|
||||
//首页视频
|
||||
$field7 = ['is_show','content','image','langs'];
|
||||
$video = DecorateHint::field($field7)
|
||||
->findOrEmpty(6)->toArray();
|
||||
|
||||
if($video['is_show']){
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($video['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
preg_match_all("/<source[^<>]*src=[\"]([^\"]+)[\"][^<>]*>/im",get_file_domain($data_content),$matches);
|
||||
|
||||
$video['url'] = count($matches[1]) > 0?$matches[1][0]:'';
|
||||
$video['image'] = FileService::getFileUrl($data_image);
|
||||
|
||||
unset($video['content']);
|
||||
unset($video['langs']);
|
||||
}
|
||||
|
||||
//弹窗内容
|
||||
$field8 = ['id','langs'];
|
||||
$popup = Article::field($field8)
|
||||
->where(['is_show' => 1,'is_popup' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->findOrEmpty();
|
||||
|
||||
if(!$popup->isEmpty()){
|
||||
$popup['is_show'] = true;
|
||||
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($popup['langs'],$params['lang']);
|
||||
$data_content = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_content = $data['content'];
|
||||
}
|
||||
$popup['content'] = get_file_domain($data_content);
|
||||
unset($popup['langs']);
|
||||
}else{
|
||||
$popup['is_show'] = false;
|
||||
}
|
||||
|
||||
//实时行情
|
||||
$markets = ConfigService::get('website', 'market');
|
||||
foreach ($markets as &$market) {
|
||||
//图片域名格式化
|
||||
$market['logo'] = FileService::getFileUrl($market['logo']);
|
||||
}
|
||||
|
||||
$unread_notice = 0;
|
||||
|
||||
if($params['user_id']!=0){
|
||||
$unread_notice = UserNotice::where(['user_id' => $params['user_id']])
|
||||
->where(['read' => 0])
|
||||
->count();
|
||||
}
|
||||
|
||||
//推荐项目
|
||||
$field_item = ['id','title','image','rate','cycle','progress','type','member_id','langs'];
|
||||
$items = Item::field($field_item)
|
||||
->append(['vip_name'])
|
||||
->where(['is_show' => 1,'is_index' => 1])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($items as &$item) {
|
||||
$item['progress'] = round($item['progress'],2);
|
||||
//多语言替换
|
||||
$data = UtilsService::get_langs_data($item['langs'],$params['lang']);
|
||||
$data_title = '';
|
||||
$data_image = '';
|
||||
|
||||
if(count($data) > 0){
|
||||
$data_title = $data['title'];
|
||||
$data_image = $data['image'];
|
||||
}
|
||||
|
||||
$item['title'] = $data_title;
|
||||
$item['image'] = FileService::getFileUrl($data_image);
|
||||
unset($item['langs']);
|
||||
}
|
||||
|
||||
return [
|
||||
// 'article' => $article,
|
||||
'banner' => $swipers,
|
||||
'navs' => $navs,
|
||||
'notice' => $notice,
|
||||
'partner' => $partner,
|
||||
// 'articleCate' => $articleCate,
|
||||
// 'articles' => $articles,
|
||||
'video' => $video,
|
||||
'popup' => $popup,
|
||||
'market' => $markets,
|
||||
'unreadNotice' => $unread_notice,
|
||||
'kefu_logo' => FileService::getFileUrl(ConfigService::get('website', 'kefu_logo')),
|
||||
'show_kefu' => ConfigService::get('website', 'show_kefu'),
|
||||
'kefu_link' => ConfigService::get('website', 'kefu_link'),
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData($lang="")
|
||||
{
|
||||
$codeStr = ConfigService::get('login', 'country_code');
|
||||
$region_codes = ConfigService::get('website', 'regioncode');
|
||||
foreach ($region_codes as &$region_code) {
|
||||
//图片域名格式化
|
||||
$region_code['logo'] = FileService::getFileUrl($region_code['logo']);
|
||||
}
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 邀请码
|
||||
'invite_code' => ConfigService::get('login', 'invite_code', config('project.login.invite_code')),
|
||||
// 国家区号
|
||||
'region_code' => $region_codes,
|
||||
];
|
||||
// 网址信息
|
||||
$website = [
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
'shop_logo2' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo2')),
|
||||
'currency' => ConfigService::get('website', 'currency'),
|
||||
'currency2' => ConfigService::get('website', 'currency2'),
|
||||
'precision' => ConfigService::get('website', 'precision'),
|
||||
'down_link' => ConfigService::get('website', 'down_link'),
|
||||
'is_down' => ConfigService::get('website', 'is_down'),
|
||||
];
|
||||
|
||||
if($lang == ''){
|
||||
//查询首个语言
|
||||
$first_lang = UtilsService::get_first_lang();
|
||||
$website['lang'] = $first_lang['symbol'];
|
||||
$website['formatTime'] = $first_lang['time_format'];
|
||||
}else{
|
||||
$language = Language::where(['symbol' => $lang,'is_show' => 1])->findOrEmpty();
|
||||
$website['lang'] = $lang;
|
||||
$website['formatTime'] = $language['time_format'];
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'version'=> config('project.version')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 国家区号
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2023/9/21 18:37
|
||||
*/
|
||||
public static function getCountryCode()
|
||||
{
|
||||
$region_codes = ConfigService::get('website', 'regioncode');
|
||||
foreach ($region_codes as &$region_code) {
|
||||
//图片域名格式化
|
||||
$region_code['logo'] = FileService::getFileUrl($region_code['logo']);
|
||||
}
|
||||
return $region_codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 语言数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author BD
|
||||
* @date 2023/10/13 10:53
|
||||
*/
|
||||
public static function getKefuLists()
|
||||
{
|
||||
$lists = ConfigService::get('website', 'kefu');
|
||||
foreach ($lists as &$list) {
|
||||
$list['logo'] = FileService::getFileUrl($list['logo']);
|
||||
}
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 行情数据
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2023/10/13 10:53
|
||||
*/
|
||||
public static function getMarketData()
|
||||
{
|
||||
//实时行情
|
||||
$markets = ConfigService::get('website', 'market');
|
||||
foreach ($markets as &$market) {
|
||||
//图片域名格式化
|
||||
$market['logo'] = FileService::getFileUrl($market['logo']);
|
||||
}
|
||||
return $markets;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user