作者 张关杰

merge develop

正在显示 67 个修改的文件 包含 2379 行增加758 行删除

要显示太多修改。

为保证性能只显示 67 of 67+ 个文件。

... ... @@ -4,6 +4,7 @@
/storage
/vendor
/uploads
composer.json
.env
.env.backup
.phpunit.result.cache
... ...
... ... @@ -43,46 +43,104 @@ class ShareUser extends Command
protected function user_operator_record(){
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_share_list = $ayr_share_model->list();
foreach ($ayr_share_list as $k => $v){
$ayr_release = new AyrReleaseModel();
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]);
foreach ($ayr_share_list as $v){
$time = Carbon::now()->modify('-7 days')->toDateString();
//创建时间小于7天前的当前时间
if($v['created_at'] > $time){
continue;
}
//查询当前用户是否有未推送的博文
$ayr_release = new AyrReleaseModel();
$release_info = $ayr_release->read(['schedule_date'=>['>',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
$release_info = $this->release_info($ayr_release,$v);
//有推文时,直接跳出循环
if($release_info !== false){
continue;
}
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
//查询7天是否发送博文
$release_info = $this->release_seven_info($ayr_release);
//有发送博文,则跳出循环
if($release_info == false){
if($release_info !== false){
continue;
}
//删除用户第三方配置
$ayr_share_helper = new AyrShareHelper();
$data_profiles = [
'title'=>$v['title'],
'profileKey'=>$v['profile_key']
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
$this->error++;
if(!empty($v['profile_key'])){
$this->del_profiles($v);
continue;
}
//更新数据库
$data = [
'title'=>null,
'bind_plat_from'=>null,
'profile_key'=>null,
'ref_id'=>null,
];
$res = $ayr_share_model->edit($data,['id'=>$v['id']]);
if($res == false){
$this->error++;
}
$this->save_ayr_share($ayr_share_model,$v);
}
return $this->error;
}
/**
* @name :(删除第三方配置)del_profiles
* @author :lyh
* @method :post
* @time :2023/6/14 16:10
*/
public function del_profiles($v){
$ayr_share_helper = new AyrShareHelper();
$data_profiles = [
'title'=>$v['title'],
'profileKey'=>$v['profile_key']
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
echo '第三方删除失败';
return true;
}
return true;
}
/**
* @name :(更新数据库)save_ayr_share
* @author :lyh
* @method :post
* @time :2023/6/14 16:14
*/
public function save_ayr_share(&$ayr_share_model,$v){
//更新数据库
$data = [
'title'=>'',
'bind_platforms'=>'',
'profile_key'=>'',
'ref_id'=>'',
];
$res = $ayr_share_model->edit($data,['id'=>$v['id']]);
if($res == false){
echo '更新数据库失败';
return true;
}
return true;
}
/**
* @name :(查询是否有定时发送报文)info
* @author :lyh
* @method :post
* @time :2023/6/14 16:17
*/
public function release_info(&$ayr_release,$v){
//查询当前用户是否有未推送的博文
$release_info = $ayr_release->read(['schedule_date'=>['>',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
return $release_info;
}
/**
* @param $ayr_release
* @name :(7天内无发送记录)release_seven_info
* @author :lyh
* @method :post
* @time :2023/6/14 16:28
*/
public function release_seven_info(&$ayr_release){
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
return $release_info;
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficStatistics;
use App\Models\CustomerVisit\CustomerVisit;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;
class Logic
{
/**
* @param int $type 统计类型
* @return array
*/
public function getMonths(int $type = TrafficStatistics::TYPE_SOURCE)
{
$date = getPreviousMonthsDate();
$TrafficStatistics = new TrafficStatistics();
$lists = $TrafficStatistics->getMonthsLists($type, $date);
if (!empty($lists)) {
$dd = [];
$lists->map(function ($item) use (&$dd) {
$dd[] = $item->year . '-' . str_pad($item->month, 2, '0', STR_PAD_LEFT);
});
$date = array_diff($date, $dd);
}
return $date;
}
/**
* @param array $column 统计数据
* @param int $type 统计类型
* @param string|null $date 日期 格式:Y-m
* @param string $message
* @return array
* @throws Throwable
*/
public function save(array $column, int $type = TrafficStatistics::TYPE_SOURCE, string $date = null, $message = '统计当月访问来源数据')
{
DB::beginTransaction();
// 获取当天的IP|PV数量
$customerVisit = new CustomerVisit();
$ip_count = $customerVisit->getMonthIPCount($date);
$pv_count = $customerVisit->getMonthPVCount($date);
$column['pvnum'] = $pv_count;
$column['ipnum'] = $ip_count;
$date = $date ?? date('Y-m');
// 统计数据并插入到数据库
$dd = explode('-', $date);
$year = $dd[0];
$month = $dd[1];
$column['year'] = $year;
$column['month'] = $month;
$trafficStatistics = new TrafficStatistics();
$isRes = $trafficStatistics->getMonth($type, $year, $month);
if ($isRes) {
$trafficStatistics = $isRes;
}
foreach ($column as $key => $value) {
$trafficStatistics->$key = $value;
}
$res = $trafficStatistics->save();
if ($res) {
DB::commit();
$meg = "{$date} - {$message}成功!";
} else {
DB::rollBack();
$meg = "{$date} - {$message}失败!";
}
return ['status' => $res, 'msg' => $meg];
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficTrends;
use App\Models\CustomerVisit\CustomerVisit;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Throwable;
class StatisticsDayTrend extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statistics_day_trend';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计当天流量趋势数据';
/**
* @return void
* @throws GuzzleException
* @throws Throwable
*/
public function handle()
{
$date = getPreviousDaysDate();
$trafficTrends = new TrafficTrends();
$lists = $trafficTrends->getDaysLists($date);
if (!empty($lists)) {
$date = array_diff($date, $lists->pluck('day')->all());
}
if (!empty($date)) {
foreach ($date as $value) {
echo $this->statistics_day_trend($value);
}
}
echo $this->statistics_day_trend();
}
/**
* 统计当天流量趋势数据PV|IP数量
* @return int|mixed
* @throws GuzzleException|Throwable
*/
protected function statistics_day_trend($date = null)
{
DB::beginTransaction();
$date = $date ?? date('Y-m-d');
// 获取当天的IP|PV数量
$customerVisit = new CustomerVisit();
$ip_count = $customerVisit->getDayIPCount($date);
$pv_count = $customerVisit->getDayPVCount($date);
// 统计数据并插入到数据库
$trafficTrends = new TrafficTrends();
$isRes = $trafficTrends->getDay($date);
if ($isRes) {
$trafficTrends = $isRes;
}
$trafficTrends->day = $date;
$trafficTrends->pvnum = $pv_count;
$trafficTrends->ipnum = $ip_count;
$res = $trafficTrends->save();
if ($res) {
DB::commit();
$this->info($date . ' - 统计当天流量趋势数据PV|IP数量成功');
} else {
DB::rollBack();
$this->error++;
$this->info($date . ' - 统计当天流量趋势数据PV|IP数量失败');
}
return $this->error;
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficStatistics;
use App\Models\CustomerVisit\CustomerVisit;
use Illuminate\Console\Command;
use Throwable;
class StatisticsDistribution extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statistics_distribution';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计当月地域分布数据';
public $logic;
public function __construct()
{
parent::__construct();
$this->logic = new Logic();
}
/**
* 定时执行
* @return void
* @throws Throwable
*/
public function handle()
{
$date = $this->logic->getMonths(TrafficStatistics::TYPE_DISTRIBUTION);
if (!empty($date)) {
foreach ($date as $value) {
echo $this->statistics_distribution($value);
}
}
echo $this->statistics_distribution();
}
/**
* 统计当天流量趋势数据PV|IP数量
* @param string|null $date
* @return int|mixed
* @throws Throwable
*/
protected function statistics_distribution(string $date = null)
{
$customerVisit = new CustomerVisit();
$type = TrafficStatistics::TYPE_DISTRIBUTION;
$top = json_encode($customerVisit->getCountryCount($date) ?? []);
$res = $this->logic->save(compact('top', 'type'), $type, $date, '统计当月地域分布数据');
if (!$res['status']) {
$this->info($res['msg']);
$this->error++;
}
$this->info($res['msg']);
return $this->error;
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficStatistics;
use App\Models\CustomerVisit\CustomerVisit;
use Illuminate\Console\Command;
use Throwable;
class StatisticsPage extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statistics_page';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计当月受访页面数据';
public $logic;
public function __construct()
{
parent::__construct();
$this->logic = new Logic();
}
/**
* 定时执行
* @return void
*/
public function handle()
{
$date = $this->logic->getMonths(TrafficStatistics::TYPE_PAGE);
if (!empty($date)) {
foreach ($date as $value) {
echo $this->statistics_page($value);
}
}
echo $this->statistics_page();
}
/**
* 统计当月受访页面数据
* @param null $date
* @return int|mixed
* @throws Throwable
*/
protected function statistics_page($date = null)
{
$customerVisit = new CustomerVisit();
$top = json_encode($customerVisit->getPageCount($date) ?? []);
$type = TrafficStatistics::TYPE_PAGE;
$res = $this->logic->save(compact('top', 'type'), $type, $date, '统计当月受访页面数据');
if (!$res['status']) {
$this->info($res['msg']);
$this->error++;
}
$this->info($res['msg']);
return $this->error;
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficStatistics;
use App\Models\CustomerVisit\CustomerVisit;
use Illuminate\Console\Command;
use Throwable;
class StatisticsSource extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statistics_source';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计当月访问来源数据';
public $logic;
public function __construct()
{
parent::__construct();
$this->logic = new Logic();
}
/**
* @return void
* @throws Throwable
*/
public function handle()
{
$date = $this->logic->getMonths();
if (!empty($date)) {
foreach ($date as $value) {
echo $this->statistics_source($value);
}
}
echo $this->statistics_source();
}
/**
* 统计当天流量趋势数据
* @param string|null $date
* @return int|mixed
* @throws Throwable
*/
protected function statistics_source(string $date = null)
{
// 获取当天的IP|PV数量
$customerVisit = new CustomerVisit();
$top = json_encode($customerVisit->getUrlCount($date) ?? []);
$type = TrafficStatistics::TYPE_SOURCE;
$res = $this->logic->save(compact('top', 'type'), $type, $date);
if (!$res['status']) {
$this->info($res['msg']);
$this->error++;
}
$this->info($res['msg']);
return $this->error;
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficStatistics;
use App\Models\CustomerVisit\CustomerVisit;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Throwable;
class StatisticsTerminal extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statistics_terminal';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计当月访问终端数据';
public $logic;
public function __construct()
{
parent::__construct();
$this->logic = new Logic();
}
/**
* @return void
* @throws Throwable
*/
public function handle()
{
$date = $this->logic->getMonths(TrafficStatistics::TYPE_TERMINAL);
if (!empty($date)) {
foreach ($date as $value) {
echo $this->statistics_terminal($value);
}
}
echo $this->statistics_terminal();
}
/**
* 统计当月访问终端数据
* @param string|null $date
* @return int|mixed
* @throws Throwable
*/
protected function statistics_terminal(string $date = null)
{
$customerVisit = new CustomerVisit();
$pcnum = $customerVisit->getTerminalPcCount($date);
$mbnum = $customerVisit->getTerminalMobileCount($date);
$top = json_encode($customerVisit->getCountryCount($date) ?? []);
$type = TrafficStatistics::TYPE_TERMINAL;
$res = $this->logic->save(compact('top', 'type', 'pcnum', 'mbnum'), $type, $date, '统计当月访问终端数据');
if (!$res['status']) {
$this->info($res['msg']);
$this->error++;
}
$this->info($res['msg']);
return $this->error;
}
}
... ...
<?php
namespace App\Console\Commands\Bside\Statistics;
use App\Models\Bside\Statistics\TrafficStatistics;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
use Throwable;
class StatisticsTrend extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'statistics_trend';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计当月流量趋势数据';
public $logic;
public function __construct()
{
parent::__construct();
$this->logic = new Logic();
}
/**
* 定时执行
* @return void
* @throws GuzzleException|Throwable
*/
public function handle()
{
$date = $this->logic->getMonths(TrafficStatistics::TYPE_TREND);
if (!empty($date)) {
foreach ($date as $value) {
echo $this->statistics_trend($value);
}
}
echo $this->statistics_trend();
}
/**
* 统计当天流量趋势数据
* @param string|null $date
* @return int|mixed
* @throws GuzzleException|Throwable
*/
protected function statistics_trend(string $date = null)
{
$domain = request()->getHttpHost(); //'www.wowstainless.com';
$sta_date = !is_null($date) ? $date . "-01" : date('Y-m-01');
$inquiry = getInquiryInformation($domain, $sta_date);
$innum = $inquiry['count'] ?? 0;
$top = json_encode($inquiry['lists'] ?? []);
$type = TrafficStatistics::TYPE_TREND;
$res = $this->logic->save(compact('top', 'type', 'innum'), $type, $date, '统计当月流量趋势数据');
if (!$res['status']) {
$this->info($res['msg']);
$this->error++;
}
$this->info($res['msg']);
return $this->error;
}
}
... ...
... ... @@ -4,11 +4,8 @@ namespace App\Console\Commands\Domain;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use Carbon\Carbon;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
class DomainTime extends Command
... ... @@ -43,7 +40,7 @@ class DomainTime extends Command
* 更新域名|证书到期时间
* @return int|mixed|void
* @throws AsideGlobalException
* @throws BsideGlobalException
* @throws BsideGlobalException|GuzzleException
*/
protected function update_domain_time()
{
... ...
... ... @@ -54,7 +54,7 @@ class RankData extends BaseCommands
continue;
}
//收录数
$indexed_pages_num = $site_res[$item['api_no']];
$indexed_pages_num = $site_res[$item['api_no']] ?? 0;
$this->save_rank($item['project_id'], $res, $indexed_pages_num);
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Console\Commands\YesterdayCount;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\CustomerVisit\CustomerVisitItem;
use App\Models\Project\DeployBuild;
use Carbon\Carbon;
... ... @@ -41,28 +42,97 @@ class Yesterday extends Command
$yesterday = Carbon::yesterday()->toDateString();
foreach ($list as $v){
$arr = [];
$arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_domain']);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
}else{
$arr['inquiry_num'] = count($inquiry_list['data']['total']);
}
//统计时间
$arr['date'] = $yesterday;
$rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
if(empty($rank_info)){
$arr['compliance_day'] = 0;
}else{
$arr['compliance_day'] = $rank_info->compliance_day;
}
//pv统计
$arr['pv_num'] = $this->pv_num($yesterday,$v['test_domain']);
//ip统计
$arr['ip_num'] = $this->ip_num($yesterday,$v['test_domain']);
//服务达标天数
$arr['compliance_day'] = $this->compliance_day($yesterday);
//剩余服务时常
$arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
//项目id
$arr['project_id'] = $v['project_id'];
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
//询盘统计
$arr = $this->inquiry($arr,$v['test_domain']);
$data[] = $arr;
}
//判断数据是否存在
DB::table('gl_count')->insert($data);
echo $this->error;
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function pv_num($yesterday,$domain){
$pv = DB::table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
return $pv;
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function ip_num($yesterday,$domain){
$ip = DB::table('gl_customer_visit')->whereDate('updated_date', $yesterday)->where('domain',$domain)->count();
return $ip;
}
/**
* @param $arr
* @param $domain
* @name :(询盘统计)inquiry
* @author :lyh
* @method :post
* @time :2023/6/14 15:44
*/
public function inquiry($arr,$domain){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
}else{
$arr['inquiry_num'] = $inquiry_list['data']['total'];
//询盘国家统计
$countryData = $inquiry_list['data']['data'];
$countryArr = [];
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']]++;
}else{
$countryArr[$v1['country']] = 0;
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
}
return $arr;
}
/**
* @param $yesterday
* @name :(服务达标天数)compliance_day
* @author :lyh
* @method :post
* @time :2023/6/14 15:48
*/
public function compliance_day($yesterday){
//服务达标天数
$rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
if(empty($rank_info)){
$compliance_day = 0;
}else{
$compliance_day = $rank_info->compliance_day;
}
return $compliance_day;
}
}
... ...
... ... @@ -27,7 +27,23 @@ class Kernel extends ConsoleKernel
$schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
$schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
$schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1); // 更新域名|证书结束时间,每天凌晨1点执行一次
// // 更新域名|证书结束时间,每天凌晨1点执行一次
// $schedule->command('domain_time')->dailyAt('01:00')->withoutOverlapping(1);
// // B站 - 网站数据统计
// // 获取当前月份最后一天
// $lastDay = date('Y-m-t');
// // 统计当月访问来源数据,每月最后一天23:59点执行一次
// $schedule->command('statistics_source')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
// // 统计当月地域分布数据,每月最后一天23:59点执行一次
// $schedule->command('statistics_distribution')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
// // 统计当月受访页面数据,每月最后一天23:59点执行一次
// $schedule->command('statistics_page')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
// // 统计当月访问终端数据,每月最后一天23:59点执行一次
// $schedule->command('statistics_terminal')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
// // 统计当月流量趋势数据,每月最后一天23:59点执行一次
// $schedule->command('statistics_trend')->monthlyOn($lastDay, '23:59')->withoutOverlapping(1);
// // 统计当天流量趋势数据,每天23:59点执行一次
// $schedule->command('statistics_day_trend')->dailyAt('23:59')->withoutOverlapping(1);
}
/**
... ...
... ... @@ -18,4 +18,6 @@ final class Common extends Enum
//端
const A='a';
const B='b';
const MANAGE_TOKEN = 'manage_token:';
}
... ...
<?php
namespace App\Helper;
class AliSms
{
private $_msg = array( //状态对照
1 => "发送成功",
0 => "其他系统错误",
-1 => "短信余额不足",
-2 => "资金账户被锁定",
-3 => "用户被锁定",
-4 => "号码在黑名单内",
-5 => "用户名或密码不正确",
-6 => "号码不正确",
-7 => "接口连接失败",
-8 => "号码格式错误",
-9 => "通道编号错误",
-10 => "定时发送时间不正确",
-11 => "没有输入短信内容",
-12 => "短信内容超出长度限制",
-15 => "内容含非法关键字",
-16 => "超出发送时间范围",
-17 => "通道被关闭",
-18 => "短信内容没有签名",
-30 => "手机未认证",
-31 => "身份未认证",
-32 => "请勿重复发送",
-33 => "验证码已过期,请重新获取",
-34 => "手机号码格式不正确",
-35 => "验证码不正确",
);
// 保存错误信息
public $error;
public $_code = "";
public $_name = "";
public $_key_str = ""; // cache full name.
protected $_expire = 600; // 验证码过期时间(s)
public $_key = [
];
// Access Key ID
private $accessKeyId = '';
// Access Key Secret
private $accessKeySecret = '';
// 签名
private $signName = '';
// 模版ID
public $templateCode = '';
public function __construct($config = array())
{
$config = array(
'accessKeyId' => config('aliyunsms.access_key'),
'accessKeySecret' => config('aliyunsms.access_secret'),
'signName' => config('aliyunsms.sign_name'),
'templateCode' => config('aliyunsms.login_sms_temp'),
);
// 配置参数
$this->accessKeyId = $config['accessKeyId'];
$this->accessKeySecret = $config['accessKeySecret'];
$this->signName = $config['signName'];
$this->templateCode = $config['templateCode'];
}
/**
* 规范化字符串以符合阿里云短信接口
* @param $string
* @return mixed|string
*/
private function percentEncode($string)
{
$string = urlencode($string);
$string = preg_replace('/\+/', '%20', $string);
$string = preg_replace('/\*/', '%2A', $string);
$string = preg_replace('/%7E/', '~', $string);
return $string;
}
/**
* 签名
*
* @param unknown $parameters
* @param unknown $accessKeySecret
* @return string
*/
private function computeSignature($parameters, $accessKeySecret)
{
ksort($parameters);
$canonicalizedQueryString = '';
foreach ($parameters as $key => $value) {
$canonicalizedQueryString .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($value);
}
$stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret . '&', true));
return $signature;
}
/**
* 发送验证码 https://help.aliyun.com/document_detail/44364.html?spm=5176.doc44368.6.126.gSngXV
*
* @param unknown $mobile
* @param unknown $verify_code
*
*/
public function send_sms($mobile, $paramstring)
{
$params = array(
// 公共参数
'SignName' => $this->signName,
'Format' => 'JSON',
'Version' => '2016-09-27',
'AccessKeyId' => $this->accessKeyId,
'SignatureVersion' => '1.0',
'SignatureMethod' => 'HMAC-SHA1',
'SignatureNonce' => uniqid(),
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
// 接口参数
'Action' => 'SingleSendSms',
'TemplateCode' => $this->templateCode,
'RecNum' => $mobile,
'ParamString' => $paramstring,
);
// 计算签名并把签名结果加入请求参数
$params['Signature'] = $this->computeSignature($params, $this->accessKeySecret);
// 发送请求
$url = 'https://sms.aliyuncs.com/?' . http_build_query($params);
$result = http_get($url); //TODO:上线前打开
if (isset($result['Code'])) {
$this->error = $this->getErrorMessage($result['Code']);
return false;
}
return true;
}
/**
* 发送验证码 https://help.aliyun.com/document_detail/44364.html?spm=5176.doc44368.6.126.gSngXV
*
* @param unknown $mobile
* @param unknown $verify_code
*
*/
public function send_verify($mobile)
{
if ($this->checkMobile($mobile) === false) {
$this->error = $this->_msg[-34];
return -34;
}
$session = cache($this->_key_str . $mobile);
if ($session && time() - $session['time'] < 60) {
if ($session['code'] == null) {
return true;
} else {
$this->error = $this->_msg[-32];
return -32;
}
}
$this->_code = rand(1000, 9999);
$params = array(
// 公共参数
'SignName' => $this->signName,
'Format' => 'JSON',
'Version' => '2016-09-27',
'AccessKeyId' => $this->accessKeyId,
'SignatureVersion' => '1.0',
'SignatureMethod' => 'HMAC-SHA1',
'SignatureNonce' => uniqid(),
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
// 接口参数
'Action' => 'SingleSendSms',
'TemplateCode' => $this->templateCode,
'RecNum' => $mobile,
'ParamString' => '{"msgcode":"' . $this->_code . '"}',
);
// 计算签名并把签名结果加入请求参数
$params['Signature'] = $this->computeSignature($params, $this->accessKeySecret);
// 发送请求
$url = 'https://sms.aliyuncs.com/?' . http_build_query($params);
$result = http_get($url); //TODO:上线前打开
// $result =1;
if ($result) {
$session = array();
$session['code'] = $this->_code; // 把校验码保存到session
$session['time'] = time(); // 验证码创建时间
cache($this->_key_str . $mobile, $session, $this->_expire);
} else {
return $this->error = $this->_msg[0];
}
if (isset($result['Code'])) {
$this->error = $this->getErrorMessage($result['Code']);
return false;
}
return true;
}
/**
* 验证手机号码
*/
public function checkMobile($tel)
{
if (preg_match("/^1[3,4,6,5,8,7,9][0-9]{1}[0-9]{8}$/", $tel)) {
//验证通过
return true;
} else {
$this->error = $this->_msg[-34];
//手机号码格式不对
return false;
}
}
/**
* 验证码是否正确
* @param string $key 手机号码
* @param int|string $code 验证码
* @param int|string $type 类型 reg-注册时获取 sms-快速登录时 pwd-修改密码时 bind-绑定手机时 unbind-解绑时
* @return boolean 验证短信验证码是否正确
*/
public function check($key, $code, $type = 'reg')
{
$this->_key_str = $type . '_' . $key;
$session = cache($this->_key_str);
if (empty($code) || empty($session)) {
$this->error = $this->_msg[-33] . $this->_key_str;
return false;
}
if (time() - $session['time'] > $this->_expire) {
cache($this->_key_str, null);
$this->error = $this->_msg[-33] . $this->_key_str;
return false;
}
if ($code == $session['code']) {
return true;
}
$this->error = $this->_msg[-35] . $this->_key_str;
return false;
}
/**
* 验证成功后调用清空验证码
*/
public function afterCheck()
{
cache($this->_key_str, null);
}
/**
* 获取详细错误信息
*
* @param unknown $status
*/
public function getErrorMessage($status)
{
$message = array(
'InvalidDayuStatus.Malformed' => '账户短信开通状态不正确',
'InvalidSignName.Malformed' => '短信签名不正确或签名状态不正确',
'InvalidTemplateCode.MalFormed' => '短信模板Code不正确或者模板状态不正确',
'InvalidRecNum.Malformed' => '目标手机号不正确,单次发送数量不能超过100',
'InvalidParamString.MalFormed' => '短信模板中变量不是json格式',
'InvalidParamStringTemplate.Malformed' => '短信模板中变量与模板内容不匹配',
'InvalidSendSms' => '1小时只能请求7次,谢谢',
'InvalidDayu.Malformed' => '变量不能是url,可以将变量固化在模板中',
);
if (isset($message[$status])) {
return $message[$status];
}
return $status;
}
private function _addlog($name, $title)
{
$this->_keys["code"] = $this->_code;
// addlog($this->_keys, $title, 1, $this->_url);
}
}
... ...
... ... @@ -85,7 +85,7 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
'domain'=>$domain,
'privateKey'=>$this->private_key,
'profileKey'=>$data['profileKey'],
// 'logout'=>true
'logout'=>true
];
$url = $this->path.'/api/profiles/generateJWT';
return $this->http_click('post',$url,$param);
... ...
... ... @@ -142,13 +142,13 @@ class Country
'con_flag' => '',
],
'zh-CN' => [
'cn' => [
'text' => '中文(简体)',
'lang_text' => '简体中文',
'con_flag' => 'con_flag/zh.jfif',
'shop_lang' => 'zh-cn',
],
'zh-TW' => [
'tw' => [
'text' => '中文(繁体)',
'lang_text' => '繁体中文',
'con_flag' => 'con_flag/zh.jfif',
... ... @@ -680,7 +680,7 @@ class Country
public function set_country(){
$data = [];
foreach ($this->tls_list as $k=>$v){
$data[] = ['name'=>$v['text'],'alias'=>$k];
$data[] = ['name'=>$v['text'],'alias'=>$k,'image'=>$k.'.png','con_flag'=>$v['con_flag'],'lang_text'=>$v['lang_text']];
}
$webCountry = new WebSettingCountry();
$webCountry->insert($data);
... ...
<?php
use App\Utils\LogUtils;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Carbon;
define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
/**
* 生成路由标识
* @param $string
... ... @@ -28,7 +30,8 @@ if (!function_exists('generateRoute')) {
* @author zbj
* @date 2023/4/27
*/
function errorLog($title, $params, Throwable $exception){
function errorLog($title, $params, Throwable $exception)
{
$exceptionMessage = "错误CODE:" . $exception->getCode() .
"-----错误message:" . $exception->getMessage() .
'------错误文件:' . $exception->getFile() .
... ... @@ -37,15 +40,15 @@ function errorLog($title, $params, Throwable $exception){
LogUtils::error($title, $params, $exceptionMessage);
}
if(!function_exists('http_post')){
if (!function_exists('http_post')) {
/**
* 发送http post请求
* @param type $url
* @param type $post_data
*/
function http_post($url, $post_data,$header = [])
function http_post($url, $post_data, $header = [])
{
if(empty($header)){
if (empty($header)) {
$header = array(
"Accept: application/json",
"Content-Type:application/json;charset=utf-8",
... ... @@ -64,22 +67,22 @@ if(!function_exists('http_post')){
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
if (curl_errno($ch)) {
\Illuminate\Support\Facades\Log::write(print_r(curl_errno($ch),1),'debug---1');
\Illuminate\Support\Facades\Log::info(print_r(curl_errno($ch), 1), 'debug---1');
}
curl_close($ch);
return json_decode($res, true);
}
}
if(!function_exists('http_get')){
if (!function_exists('http_get')) {
/**
* 发送http get请求
* @param type $url
* @return type
*/
function http_get($url,$header = [])
function http_get($url, $header = [])
{
if(empty($header)){
if (empty($header)) {
$header[] = "content-type: application/json;
charset = UTF-8";
}
... ... @@ -92,13 +95,14 @@ if(!function_exists('http_get')){
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
$access_txt = curl_exec($ch1);
\Illuminate\Support\Facades\Log::info($access_txt);
curl_close($ch1);
return json_decode($access_txt, true);
}
}
if(!function_exists('_get_child')){
if (!function_exists('_get_child')) {
/**
* 菜单权限->得到子级数组
* @param int
... ... @@ -110,7 +114,7 @@ if(!function_exists('_get_child')){
foreach ($arr as $k => $v) {
$v = (array)$v;
if ($v['pid'] == $my_id) {
$v['sub'] = _get_child($v['id'],$arr);
$v['sub'] = _get_child($v['id'], $arr);
$new_arr[] = $v;
}
}
... ... @@ -119,7 +123,6 @@ if(!function_exists('_get_child')){
}
if (!function_exists('checkDomain')) {
/**
* 检查并补全域名协议
... ... @@ -130,12 +133,12 @@ if (!function_exists('checkDomain')) {
function checkDomain($value)
{
$urlParts = parse_url(strtolower($value));
if(empty($urlParts['host'])){
if (empty($urlParts['host'])) {
$urlParts = parse_url('https://' . $value);
}
$host = $urlParts['host'] ?? '';
$host = $urlParts['host'] ?? '';
$scheme = $urlParts['scheme'] ?? 'https';
if(!in_array($scheme, ['http', 'https'])){
if (!in_array($scheme, ['http', 'https'])) {
return false;
}
if (preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $host)) {
... ... @@ -147,7 +150,6 @@ if (!function_exists('checkDomain')) {
}
/**
* 把返回的数据集转换成Tree
* @param $list array 数据列表
... ... @@ -158,20 +160,21 @@ if (!function_exists('checkDomain')) {
* @param bool $empty_child 当子数据不存在,是否要返回空子数据
* @return array
*/
function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$empty_child=true) {
function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0, $empty_child = true)
{
// 如果是数字,则是root
if(is_numeric($pk)){
$root = $pk;
$pk = 'id';
if (is_numeric($pk)) {
$root = $pk;
$pk = 'id';
}
// 创建Tree
$tree = array();
if(is_array($list)) {
if (is_array($list)) {
// 创建基于主键的数组引用
$refer = array();
foreach ($list as $key => $data) {
if($empty_child){
$list[$key][$child] = [];
if ($empty_child) {
$list[$key][$child] = [];
}
$refer[$data[$pk]] =& $list[$key];
}
... ... @@ -180,9 +183,9 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
} else {
if (isset($refer[$parentId])) {
$refer[$parentId][$child][] = & $list[$key];
$refer[$parentId][$child][] = &$list[$key];
}
}
}
... ... @@ -198,14 +201,15 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em
* @author:dc
* @time 2022/1/11 10:13
*/
function tree_to_list($tree, $child='_child'){
$lists = [];
foreach ($tree as $item){
$c = $item[$child]??[];
function tree_to_list($tree, $child = '_child')
{
$lists = [];
foreach ($tree as $item) {
$c = $item[$child] ?? [];
unset($item[$child]);
$lists[] = $item;
if ($c){
$lists = array_merge($lists,tree_to_list($c, $child));
if ($c) {
$lists = array_merge($lists, tree_to_list($c, $child));
}
}
return $lists;
... ... @@ -233,10 +237,10 @@ if (!function_exists('object_to_array')) {
*/
function object_to_array($data)
{
if(is_object($data)){
if (is_object($data)) {
$data = (array)$data;
}else{
foreach ($data as $k => $v){
} else {
foreach ($data as $k => $v) {
$data[$k] = object_to_array($v);
}
}
... ... @@ -244,3 +248,159 @@ if (!function_exists('object_to_array')) {
}
}
if (!function_exists('getPreviousDaysDate')) {
/**
* 获取当前指定前几天日期,默认获取前三天日期
* @param int $day
* @return array
*/
function getPreviousDaysDate(int $day = 3)
{
$days = [];
while ($day > 0) {
$days[] = date("Y-m-d", strtotime("-{$day} days"));
$day -= 1;
}
return $days;
}
}
if (!function_exists('getPreviousMonthsDate')) {
/**
* 获取当前指定前几天日期,默认获取前三天日期
* @param int $month
* @return array
*/
function getPreviousMonthsDate(int $month = 3)
{
$months = [];
while ($month > 0) {
$months[] = date("Y-m", strtotime("-{$month} months"));
$month -= 1;
}
return $months;
}
}
if (!function_exists('getInquiryInformation')) {
/**
* 获取第三方询盘信息
* @return array|string
* @throws GuzzleException
*/
function getInquiryInformation($domain, $sta_date)
{
$token = md5($domain . date("Y-m-d"));
$source = '1,3';
$url = "https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain={$domain}&token={$token}&source={$source}&sta_date={$sta_date}";
$client = new Client(['verify' => false]);
$http = $client->get($url);
$data = [];
if ($http->getStatusCode() != 200) {
return $data;
}
$content = $http->getBody()->getContents();
$json = json_decode($content, true);
if ($json['status'] != 200) {
return $content;
}
$data['count'] = $json['data']['count'];
$data['lists'] = $json['data']['data'];
return $data;
}
}
if (!function_exists('stringUnderlineLowercase')) {
/**
* 正则 - 名字转为小写并将空格转为下划线
* @param $name
* @return string
*/
function stringUnderlineLowercase($name)
{
return trim(strtolower(preg_replace('/[^a-zA-Z0-9]/', '_', $name)));
}
}
if (!function_exists('checkIsGreaterMonth')) {
/**
* 判断传入日期是否大于当月
* @param $date
* @return bool
*/
function checkIsGreaterMonth($date)
{
// 传入日期的时间戳
$timestamp = strtotime($date);
// 当前月份的时间戳
$nowMonth = strtotime(date('Y-m'));
// 判断传入日期是否大于当前月份
return $timestamp > $nowMonth;
}
}
if (!function_exists('checkIsMonth')) {
/**
* 判断传入日期是否是当月
* @param $date
* @return bool
*/
function checkIsMonth($date)
{
// 获取当前时间戳
$now = time();
// 获取当月的起始时间戳和结束时间戳
$firstDay = strtotime(date('Y-m-01', $now));
$lastDay = strtotime(date('Y-m-t', $now));
// 传入日期的时间戳
$timestamp = strtotime($date);
// 判断传入日期是否在当月范围内
return $timestamp >= $firstDay && $timestamp <= $lastDay;
}
}
if (!function_exists('getDateDays')) {
/**
* 返回当月到今天的天数
* @param string|null $date 日期,格式:Y-m
* @return array
*/
function getDateDays(string $date = null)
{
list($year, $month, $day) = explode('-', date('Y-m-d'));
// 获取当前月的第一天
$first_day_of_month = "{$year}-{$month}-01";
// 获取今天的日期
$today = "{$year}-{$month}-{$day}";
if (!is_null($date)) {
$dd = explode('-', $date);
if (!checkIsGreaterMonth($date) && !checkIsMonth($date)) {
$year = $dd[0];
$month = $dd[1];
$first_day_of_month = "{$year}-{$month}-01";
return getDateArray("{$year}-{$month}-" . date("t", strtotime($first_day_of_month)));
}
}
$day_timestamp = strtotime($today) - strtotime($first_day_of_month);
return getDateArray("{$year}-{$month}-" . date('d', $day_timestamp));
}
}
if (!function_exists('getDateArray')) {
/**
* 获取当月获取日期
* @param string $date 日期,格式:Y-m-d
* @return array
*/
function getDateArray(string $date)
{
list($year, $month, $day) = explode('-', date($date));
$i = 1;
$days = [];
while ($i <= $day) {
$days[] = "{$year}-{$month}-" . str_pad($i, 2, "0", STR_PAD_LEFT);
$i++;
}
return $days;
}
}
... ...
... ... @@ -11,15 +11,19 @@ use Illuminate\Http\Request;
use function App\Helper\send_openai_msg;
/**
* @name:ai指令
* @remark :ai指令
* @name :AiCommandController
* @author :lyh
* @time :2023/6/17 16:27
*/
class AiCommandController extends BaseController
{
/**
* @name :指令列表
* @return void
* @author :liyuhang
* @method
* @param AiCommandModel $aiCommandModel
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/17 16:27
*/
public function lists(AiCommandModel $aiCommandModel){
$lists = $aiCommandModel->lists($this->map,$this->page,$this->row,$this->order);
... ... @@ -27,10 +31,11 @@ class AiCommandController extends BaseController
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
* @param AiCommandLogic $aiCommandLogic
* @name :info
* @author :lyh
* @method :post
* @time :2023/6/17 16:27
*/
public function info(AiCommandLogic $aiCommandLogic){
$this->request->validate([
... ... @@ -41,11 +46,14 @@ class AiCommandController extends BaseController
$aiCommandLogic->ai_info();
$this->response('success');
}
/**
* @name
* @return void
* @author :liyuhang
* @method
* @param AiCommandRequest $request
* @param AiCommandLogic $aiCommandLogic
* @name :add
* @author :lyh
* @method :post
* @time :2023/6/17 16:27
*/
public function add(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){
$request->validated();
... ... @@ -54,10 +62,12 @@ class AiCommandController extends BaseController
}
/**
* @name
* @return void
* @author :liyuhang
* @method
* @param AiCommandRequest $request
* @param AiCommandLogic $aiCommandLogic
* @name :edit
* @author :lyh
* @method :post
* @time :2023/6/17 16:28
*/
public function edit(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){
$request->validate([
... ... @@ -70,10 +80,11 @@ class AiCommandController extends BaseController
}
/**
* @name
* @return void
* @author :liyuhang
* @method
* @param AiCommandLogic $aiCommandLogic
* @name :del
* @author :lyh
* @method :post
* @time :2023/6/17 16:27
*/
public function del(AiCommandLogic $aiCommandLogic){
$this->request->validate([
... ...
... ... @@ -6,14 +6,20 @@ use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Ai\AiLog as AiLogModel;
/**
* @remark :ai发送记录
* @name :AiLogController
* @author :lyh
* @time :2023/6/17 16:26
*/
class AiLogController extends BaseController
{
/**
* @name :ai日志列表
* @return void
* @author :liyuhang
* @method
* @param AiLogModel $aiLogModel
* @name :(ai发送日志列表)lists
* @author :lyh
* @method :post
* @time :2023/6/17 16:25
*/
public function lists(AiLogModel $aiLogModel){
$lists = $aiLogModel->lists($this->map,$this->page,$this->row,$this->order);
... ...
... ... @@ -3,7 +3,9 @@
namespace App\Http\Controllers\Aside;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Http\Controllers\Controller;
use App\Models\User\User as UserModel;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Exceptions\HttpResponseException;
... ... @@ -21,7 +23,7 @@ class BaseController extends Controller
protected $order = 'id';
protected $map = [];//处理后的参数
protected $uid = 0;
protected $user = [];//当前登录用户详情
protected $manage = [];//当前登录用户详情
/**
* 获取所有参数
*/
... ... @@ -30,14 +32,12 @@ class BaseController extends Controller
$this->request = $request;
$this->param = $this->request->all();
$this->token = $this->request->header('token');
if(!empty($this->token) && !empty(Cache::get($this->token))){
$info = Cache::get($this->token);
$this->user = $info;
$this->get_param();
if(!empty($this->token) && !empty(Cache::get(Common::MANAGE_TOKEN . $this->token))){
$info = Cache::get(Common::MANAGE_TOKEN . $this->token);
$this->manage = $info;
$this->uid = $info['id'];
//参数处理
$this->get_param();
}
}
... ... @@ -64,10 +64,13 @@ class BaseController extends Controller
$this->header['token'] = $this->token;
return response()->json($response,200,$this->header);
}
/**
* @name :参数过滤
* @author :liyuhang
* @method
* @remark :请求参数处理
* @name :get_param
* @author :lyh
* @method :post
* @time :2023/6/17 16:34
*/
public function get_param(){
$param = $this->param;
... ... @@ -105,11 +108,18 @@ class BaseController extends Controller
}
}
}
/**
* @name 统一返回参数
* @return JsonResponse
* @author :liyuhang
* @method
* @param $msg
* @param string $code
* @param $data
* @param $result_code
* @param $type
* @remark :统一返回
* @name :response
* @author :lyh
* @method :post
* @time :2023/6/17 16:34
*/
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
... ... @@ -128,10 +138,11 @@ class BaseController extends Controller
/**
* @param $data
* @name :返回参数统一处理
* @return array|string
* @author :liyuhang
* @method
* @remark :统一返回参数处理
* @name :_extents
* @author :lyh
* @method :post
* @time :2023/6/17 16:34
*/
protected function _extents($data) {
... ... @@ -150,6 +161,12 @@ class BaseController extends Controller
case 'image':
$v['image_link'] = url('/a/image/' . $v);
break;
case 'operator_id':
if(!empty($v)){
$name = (new UserModel())->read(['id'=>$v],['id','name']);
$data['operator_name'] = (isset($name['name']) && !empty($name['name'])) ? $name['name'] : '无名称';
}
break;
}
}
}
... ... @@ -159,6 +176,4 @@ class BaseController extends Controller
}
... ...
... ... @@ -73,6 +73,7 @@ class ServerInformationController extends BaseController
*/
public function edit(ServerInformationRequest $serverInformationRequest, ServerInformationLogic $serverInformationLogic)
{
$serverInformationRequest->validate([
'id' => 'required|integer',
], [
... ...
... ... @@ -3,18 +3,9 @@
namespace App\Http\Controllers\Aside\Devops;
use App\Enums\Common\Code;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Devops\ServerInformationLogic;
use App\Http\Requests\Aside\Devops\ServerInformationRequest;
use App\Models\Devops\ServerInformation;
use App\Models\Devops\ServerInformationLog;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ServerInformationLogController extends BaseController
{
... ...
... ... @@ -2,8 +2,8 @@
namespace App\Http\Controllers\Aside;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Models\Manage\Manage;
/**
* Class IndexController
... ... @@ -11,16 +11,25 @@ use Illuminate\Http\Request;
* @author zbj
* @date 2023/4/19
*/
class IndexController extends Controller
class IndexController extends BaseController
{
/**
* 首页
* @param Request $request
* 用户菜单
* @param MenuLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author zbj
* @date 2023/6/21
*/
public function index(Request $request)
public function get_menu(MenuLogic $logic)
{
if($this->manage['id'] == Manage::ADMINISTRATOR_ID){ //超级管理员
$menus = $logic->getAllMenu();
}else{
$menus = $logic->getMenuByGroupId($this->manage['gid']);
}
return $this->success($menus);
}
}
... ...
... ... @@ -18,27 +18,22 @@ class LoginController extends BaseController
function login(Request $request, LoginLogic $logic)
{
if ($request->isMethod('POST')) {
$request->validate([
'mobile' => ['required', new Mobile()],
'password' => 'required',
], [
'mobile.required' => '请输入手机号',
'password.required' => '请输入密码',
]);
$logic->login();
return $this->success();
}
if($logic->manage()){
return redirect(route('admin.home.white'));
}
return view('admin.login');
$request->validate([
'mobile' => ['required', new Mobile()],
'password' => 'required',
], [
'mobile.required' => '请输入手机号',
'password.required' => '请输入密码',
]);
$data = $logic->login();
return $this->success($data);
}
public function logout(LoginLogic $logic)
{
return $logic->logout();
$logic->logout();
return $this->success();
}
}
... ...
... ... @@ -13,17 +13,20 @@ use App\Models\Mail\Mail as MailModel;
*/
class MailController extends BaseController
{
public function lists(){
$mailModel = new MailModel();
$lists = $mailModel->lists($this->map,$this->page,$this->row,$this->order);
public function lists(MailLogic $mailLogic){
if(isset($this->map['title']) && !empty($this->map['title'])){
$this->map['title'] = ['like','%'.$this->map['title'].'%'];
}
$lists = $mailLogic->mail_lists($this->map,$this->page,$this->row,$this->order);
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
* @param MailLogic $mailLogic
* @name :info
* @author :lyh
* @method :post
* @time :2023/6/17 16:25
*/
public function info(MailLogic $mailLogic){
$this->request->validate([
... ... @@ -37,10 +40,12 @@ class MailController extends BaseController
/**
* @name :添加站内信
* @return void
* @author :liyuhang
* @method
* @param MailRequest $mailRequest
* @param MailLogic $mailLogic
* @name :add
* @author :lyh
* @method :post
* @time :2023/6/17 16:25
*/
public function add(MailRequest $mailRequest,MailLogic $mailLogic){
$mailRequest->validated();
... ... @@ -49,10 +54,12 @@ class MailController extends BaseController
}
/**
* @name :编辑站内信
* @return void
* @author :liyuhang
* @method
* @param MailRequest $mailRequest
* @param MailLogic $mailLogic
* @name :edit
* @author :lyh
* @method :post
* @time :2023/6/17 16:24
*/
public function edit(MailRequest $mailRequest,MailLogic $mailLogic){
$mailRequest->validate([
... ... @@ -65,16 +72,18 @@ class MailController extends BaseController
}
/**
* @name :逻辑删除站内信
* @return void
* @author :liyuhang
* @method
* @param MailLogic $mailLogic
* @name :del
* @author :lyh
* @method :post
* @time :2023/6/17 16:24
*/
public function del(MailLogic $mailLogic){
$this->request->validate([
'id'=>'required'
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空'
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$mailLogic->mail_del();
$this->response('success');
... ...
... ... @@ -27,7 +27,7 @@ class DeptController extends BaseController
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'pid', 'title'],0);
return view("admin.dept", ["list" => Arr::listToTree($data)]);
return $this->success(Arr::listToTree($data));
}
public function info(Request $request, DeptLogic $logic){
... ...
... ... @@ -22,7 +22,7 @@ class GroupController extends BaseController
public function list(Request $request, GroupLogic $logic)
{
$list = $logic->getList();
return view("admin.group", ["list" => $list]);
return $this->success($list);
}
public function info(Request $request, GroupLogic $logic){
... ...
... ... @@ -21,8 +21,18 @@ class ManageController extends BaseController
public function list(Request $request, ManageLogic $logic)
{
$list = $logic->getList();
return view("admin.manage", ["list" => $list]);
$map = [];
if(!empty($this->param['search'])){
$map[] = ['name|mobile', 'like', "%{$this->param['search']}%"];
}
if(!empty($this->param['dept_id'])){
$map[] = ['dept_id', $this->param['dept_id']];
}
if(!empty($this->param['gid'])){
$map[] = ['gid', $this->param['gid']];
}
$list = $logic->getList($map);
return $this->success($list);
}
public function info(Request $request, ManageLogic $logic){
... ...
... ... @@ -6,8 +6,11 @@ use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Http\Requests\Aside\Manage\MenuRequest;
use App\Models\Manage\Menu;
use App\Rules\Ids;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
/**
* 后台菜单
... ... @@ -23,8 +26,22 @@ class MenuController extends BaseController
{
$map = [];
$sort = ['id' => 'desc'];
$list = $logic->getList($map, $sort, ['*'],0);
return view("admin.menu", ["list" => Arr::listToTree($list)]);
$list = $logic->getList($map, $sort, ['id', 'pid', 'title', 'icon', 'type'],0);
return $this->success(Arr::listToTree($list));
}
public function routes(Request $request){
//已绑定菜单的路由
$menu_route = array_filter(Menu::pluck('route_name')->toArray());
//路由
$list = [];
$routes = Route::getRoutes()->getRoutesByName();
foreach ($routes as $name => $route) {
if(Str::startsWith($name, 'admin.') && !Str::endsWith($name, '.white') && !in_array($name, $menu_route)){
$list[] = $name;
}
}
return $this->success($list);
}
public function info(Request $request, MenuLogic $logic){
... ...
<?php
namespace App\Http\Controllers\Aside\Project;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Project\OptimizeLogic;
/**
* @remark :优化方案设置
* @name :OptimizeController
* @author :lyh
* @time :2023/6/20 14:33
*/
class OptimizeController extends BaseController
{
/**
* @remark :授权域名
* @name :empowerDomain
* @author :lyh
* @method :post
* @time :2023/6/20 15:10
*/
public function empowerDomain(OptimizeLogic $optimizeLogic){
$this->request->validate([
'id'=>'required',
'gsc_id'=>'required'
],[
'id.required' => '审核域名ID不能为空',
'gsc_id.required' => 'GSC账号ID不能为空'
]);
$optimizeLogic->empowerDomain();
$this->response('success');
}
/**
* @remark :优化设置
* @name :save
* @author :lyh
* @method :post
* @time :2023/6/20 14:33
*/
public function save(){
$this->response('success');
}
}
... ...
... ... @@ -4,7 +4,9 @@ namespace App\Http\Controllers\Aside\Project;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Project\ProcessRecordsLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Requests\Aside\Project\ProcessRecordsRequest;
use App\Http\Requests\Aside\Project\ProjectRequest;
use App\Models\InquirySet;
use App\Rules\Ids;
... ... @@ -24,13 +26,16 @@ class ProjectController extends BaseController
public function list(ProjectLogic $logic)
{
$map = [];
if(!empty($this->param['type'])){
$map[] = ['type', $this->param['type']];
}
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
$map[] = ['title|company', $this->param['search']];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort);
return view("admin.project", ["list" => $data]);
return $this->success($data);
}
public function info(Request $request, ProjectLogic $logic){
... ... @@ -78,4 +83,45 @@ class ProjectController extends BaseController
$data = $logic->saveInquirySet($this->param);
return $this->success($data);
}
/**
* 数据源
* @param ProjectLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @author zbj
* @date 2023/6/20
*/
public function data_source(ProjectLogic $logic){
$data = $logic->dataSource();
return $this->success($data);
}
/**
* 进程记录
* @author zbj
* @date 2023/6/25
*/
public function get_process_records(Request $request, ProcessRecordsLogic $logic){
$request->validate([
'project_id'=>'required'
],[
'project_id.required' => '项目ID不能为空'
]);
$data = $logic->getInfo($this->param['project_id']);
return $this->success($data);
}
/**
* 保存进程记录
* @author zbj
* @date 2023/6/25
*/
public function save_process_records(ProcessRecordsRequest $request, ProcessRecordsLogic $logic){
$this->param['operator_id'] = $this->manage['id'];
$data = $logic->save($this->param);
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Project;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Project\GscLogic;
use App\Http\Requests\Aside\User\GscRequest;
/**
* @remark :优化gsc账号
* @name :ProjectGscController
* @author :lyh
* @time :2023/6/19 11:25
*/
class ProjectGscController extends BaseController
{
/**
* @remark :gsc账号列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/19 11:25
*/
public function lists(GscLogic $gscLogic){
$lists = $gscLogic->GscLists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :根据gsc账号获取域名
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/19 10:48
*/
public function domainLists(GscLogic $gscLogic){
$this->request->validate([
'gsc_id'=>'required'
],[
'gsc_id.required' => 'GSC账号ID不能为空'
]);
$lists = $gscLogic->DomainLists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :获取gsc账号详情
* @name :read
* @author :lyh
* @method :post
* @time :2023/6/19 16:55
*/
public function read(GscLogic $gscLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'GSC账号ID不能为空'
]);
$info = $gscLogic->GscRead();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :添加/编辑gsc账号
* @name :add
* @author :lyh
* @method :post
* @time :2023/6/19 16:28
*/
public function save(GscRequest $gscRequest,GscLogic $gscLogic){
if(isset($this->param['id'])){
$gscRequest->validate([
'id'=>'required'
],[
'id.required' => 'GSC账号ID不能为空'
]);
}
$gscRequest->validated();
$gscLogic->GscSave();
$this->response('success');
}
/**
* @remark :逻辑删除gsc账号
* @name :del
* @author :lyh
* @method :post
* @time :2023/6/19 16:30
*/
public function del(GscLogic $gscLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'GSC账号ID不能为空'
]);
$gscLogic->GscDel();
$this->response('success');
}
}
... ...
... ... @@ -5,10 +5,12 @@ namespace App\Http\Controllers\Aside\Task;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Task\TaskFollowLogic;
use App\Http\Logic\Aside\Task\TaskLogic;
use App\Http\Logic\Aside\Task\TaskOwnerLogic;
use App\Http\Requests\Aside\Task\TaskFollowRequest;
use App\Http\Requests\Aside\Task\TaskRequest;
use App\Models\Task\Task;
use Illuminate\Support\Facades\Request;
use App\Models\Task\TaskOwner;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
... ... @@ -26,12 +28,19 @@ class TaskController extends BaseController
{
$map = [];
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
$map[] = ['content', 'like', "%{$this->param['search']}%"];
}
if(!empty($this->param['created_manage_id'])){
$map[] = ['created_manage_id', $this->param['created_manage_id']];
}
if(!empty($this->param['owner_manage_id'])){
$map[] = ['id', 'in', TaskOwner::where('manage_id', $this->param['owner_manage_id'])->pluck('task_id')];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort);
$data = $logic->getList($map, $sort, ['id', 'project_id', 'workload', 'priority', 'content', 'attachment', 'status', 'end_at', 'created_manage_id']);
return view("admin.task", ["list" => $data]);
return $this->success($data);
}
public function info(Request $request, TaskLogic $logic){
... ... @@ -46,6 +55,7 @@ class TaskController extends BaseController
public function save(TaskRequest $request, TaskLogic $logic)
{
$this->param['created_manage_id'] = $this->manage->id;
$data = $logic->save($this->param);
return $this->success($data);
}
... ...
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\DeptLogic;
/**
* @remark :b端用户组织架构
* @name :ProjectDeptController
* @author :lyh
* @time :2023/6/17 16:23
*/
class ProjectDeptController extends BaseController
{
/**
* @name :(组织部门)lists
* @author :lyh
* @method :post
* @time :2023/6/17 16:13
*/
public function lists(DeptLogic $deptLogic){
if(isset($this->param['pid'])){
$this->map['pid'] = $this->param['pid'];
}
if(isset($this->map['title']) && !empty($this->map['title'])){
$this->map['title'] = ['like','%'.$this->map['title'].'%'];
}
$lists = $deptLogic->DeptLists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(部门详情)read
* @author :lyh
* @method :post
* @time :2023/6/17 16:13
*/
public function read(DeptLogic $deptLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$info = $deptLogic->DeptRead();
$this->response('success',Code::SUCCESS,$info);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\ProjectGroupLogic;
use App\Http\Requests\Aside\User\ProjectGroupRequest;
use App\Models\ProjectGroup as ProjectGroupModel;
class ProjectGroupController extends BaseController
{
/**
* @name:用户组列表
*/
public function lists(ProjectGroupModel $projectGroupModel){
$lists = $projectGroupModel->lists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :添加用户组
* @return void
* @author :liyuhang
* @method
*/
public function add(ProjectGroupRequest $request,ProjectGroupLogic $projectGroupLogic){
$request->validated();
$projectGroupLogic->group_add();
$this->response('success');
}
/**
* @name :编辑用户组
* @return void
* @author :liyuhang
* @method
*/
public function edit(ProjectGroupRequest $request,ProjectGroupLogic $projectGroupLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectGroupLogic->group_edit();
$this->response('success');
}
/**
* @name :用户组详情
* @return void
* @author :liyuhang
* @method
*/
public function info(ProjectGroupLogic $projectGroupLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectGroupLogic->group_info();
$this->success('success');
}
/**
* @name :删除用户组
* @return void
* @author :liyuhang
* @method
*/
public function del(ProjectGroupLogic $projectGroupLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectGroupLogic->group_del();
$this->success('success');
}
}
... ... @@ -10,25 +10,54 @@ use App\Models\User\ProjectMenu;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use Illuminate\Http\Request;
/**
* @remark :b端菜单管理
* @name :ProjectMenuController
* @author :lyh
* @time :2023/6/17 16:23
*/
class ProjectMenuController extends BaseController
{
/**
* @name :用户菜单列表
* @return json
* @author :liyuhang
* @method
* @remark :用户菜单列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/21 17:24
*/
public function lists(){
$menuModel = new ProjectMenuModel();
if(isset($this->param['pid'])){
$this->map['pid'] = $this->param['pid'];
}
//是否为权限菜单
if(isset($this->param['is_role'])){
$this->map['is_role'] = $this->param['is_role'];
}
$lists = $menuModel->lists($this->map,$this->page,$this->row,$this->order,['*']);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
* @remark :添加菜单时获取菜单列表
* @name :list
* @author :lyh
* @method :post
* @time :2023/6/21 17:24
*/
public function list(ProjectMenuLogic $projectMenuLogic){
$lists = $projectMenuLogic->MenuList();
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @param ProjectMenuLogic $projectMenuLogic
* @remark :详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/6/21 17:23
*/
public function info(ProjectMenuLogic $projectMenuLogic){
$this->request->validate([
... ... @@ -41,10 +70,13 @@ class ProjectMenuController extends BaseController
}
/**
* @name :添加菜单
* @return void
* @author :liyuhang
* @method
* @param ProjectRoleRequest $request
* @param ProjectMenuLogic $projectMenuLogic
* @remark :添加菜单
* @name :add
* @author :lyh
* @method :post
* @time :2023/6/21 17:23
*/
public function add(ProjectRoleRequest $request,ProjectMenuLogic $projectMenuLogic){
$request->validated();
... ... @@ -53,10 +85,13 @@ class ProjectMenuController extends BaseController
}
/**
* @name :编辑菜单
* @return void
* @author :liyuhang
* @method
* @param ProjectRoleRequest $request
* @param ProjectMenuLogic $projectMenuLogic
* @remark :编辑菜单
* @name :edit
* @author :lyh
* @method :post
* @time :2023/6/21 17:22
*/
public function edit(ProjectRoleRequest $request,ProjectMenuLogic $projectMenuLogic){
$request->validate([
... ... @@ -69,10 +104,12 @@ class ProjectMenuController extends BaseController
}
/**
* @name :删除菜单
* @return void
* @author :liyuhang
* @method
* @param ProjectMenuLogic $projectMenuLogic
* @remark :删除菜单
* @name :del
* @author :lyh
* @method :post
* @time :2023/6/21 17:22
*/
public function del(ProjectMenuLogic $projectMenuLogic){
$this->request->validate([
... ...
... ... @@ -9,6 +9,12 @@ use App\Http\Requests\Aside\User\ProjectRoleRequest;
use App\Models\User\ProjectRole as ProjectRoleModel;
use Illuminate\Http\Request;
/**
* @remark :b端用户角色设置管理
* @name :ProjectRoleController
* @author :lyh
* @time :2023/6/17 16:22
*/
class ProjectRoleController extends BaseController
{
/**
... ...
... ... @@ -9,13 +9,21 @@ use App\Http\Requests\Aside\User\UserRequest;
use App\Models\User\User as UserModel;
use Illuminate\Http\Request;
/**
* @remark :b端用户管理
* @name :ProjectUserController
* @author :lyh
* @time :2023/6/17 16:24
*/
class ProjectUserController extends BaseController
{
/**
* @name :用户列表
* @return void
* @author :liyuhang
* @method
* @remark :用户列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/25 9:27
*/
public function lists(){
$userModel = new UserModel();
... ... @@ -25,10 +33,12 @@ class ProjectUserController extends BaseController
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
* @param UserLogic $userLogic
* @remark :用户详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/6/25 9:27
*/
public function info(UserLogic $userLogic){
$this->request->validate([
... ... @@ -36,14 +46,18 @@ class ProjectUserController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
$userLogic->user_info();
$this->response('success');
$info = $userLogic->user_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加用户
* @return void
* @author :liyuhang
* @method
* @param UserRequest $request
* @param UserLogic $userLogic
* @remark :添加用户
* @name :add
* @author :lyh
* @method :post
* @time :2023/6/25 9:27
*/
public function add(UserRequest $request,UserLogic $userLogic){
$request->validated();
... ... @@ -52,10 +66,13 @@ class ProjectUserController extends BaseController
}
/**
* @name : 编辑
* @return void
* @author :liyuhang
* @method
* @param UserRequest $request
* @param UserLogic $userLogic
* @remark :编辑用户
* @name :edit
* @author :lyh
* @method :post
* @time :2023/6/25 9:28
*/
public function edit(UserRequest $request,UserLogic $userLogic){
$request->validate([
... ... @@ -68,10 +85,12 @@ class ProjectUserController extends BaseController
}
/**
* @name :批量删除
* @return void
* @author :liyuhang
* @method
* @param UserLogic $userLogic
* @remark :编辑用户
* @name :del
* @author :lyh
* @method :post
* @time :2023/6/25 9:28
*/
public function del(UserLogic $userLogic){
$this->request->validate([
... ...
... ... @@ -14,7 +14,6 @@ class AiCommandController extends BaseController
public $chat_url = 'v2/openai_chat';
/**
* @name :ai生成
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -38,8 +37,7 @@ class AiCommandController extends BaseController
}
/**
* @name :写入日志
* @return void
* @name :写入日志
* @author :liyuhang
* @method
*/
... ...
... ... @@ -15,7 +15,7 @@ use App\Models\AyrShare\AyrShare as AyrShareModel;
class AyrShareController extends BaseController
{
//生成名称前缀
const TITLE = 'global_so_';
const TITLE = 'globalso';
/**
* @name :(社交列表)lists
* @author :lyh
... ... @@ -24,7 +24,7 @@ class AyrShareController extends BaseController
*/
public function lists(AyrShareModel $ayrShareModel,AyrShareLogic $ayrShareLogic){
//授权配置列表
$share_list = $ayrShareModel->platforms;
$share_list = $ayrShareModel->iconImage();
$lists = $ayrShareModel->lists($this->map,$this->page,$this->row,'id',['id','name','title','profile_key','bind_platforms','operator_id','created_at','updated_at']);
foreach ($lists['list'] as $k => $v){
if(!empty($v['profile_key'])){
... ... @@ -68,8 +68,11 @@ class AyrShareController extends BaseController
$res = false;
}
}else{
$ayrShareLogic->ayr_share_edit(['bind_platforms'=>''],$this->param['id']);
$res = true;
if(!empty($info['bind_platforms'])){
$ayrShareLogic->ayr_share_edit(['bind_platforms'=>''],$this->param['id']);
return true;
}
$res = false;
}
$this->response('success',Code::SUCCESS,['is_true'=>$res]);
}
... ... @@ -81,8 +84,10 @@ class AyrShareController extends BaseController
*/
public function create_account(AyrShareRequest $ayrShareRequest,AyrShareLogic $ayrShareLogic){
$ayrShareRequest->validated();
//验证参数及
$ayrShareLogic->AyrVerify();
$param = [
'title'=>self::TITLE.$this->user['project_id'].':'.$this->param['name'],
'title'=>self::TITLE . ':' . $this->user['project_id'] . '-' . $this->param['name'],
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
... ... @@ -91,7 +96,7 @@ class AyrShareController extends BaseController
$this->response('同步绑定失败');
}
//执行数据库操作
$ayrShareLogic->ayr_share_add($res);
$ayrShareLogic->ayr_share_save($res);
$this->response('success');
}
... ... @@ -108,15 +113,17 @@ class AyrShareController extends BaseController
'id.required' => 'ID不能为空'
]);
$info = $ayrShareLogic->ayr_share_info();
$data = [
if(!empty($info['title'])){
$data = [
// 'title'=>$info['title'],
'profileKey'=>$info['profile_key']
];
//发送请求删除社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->deleted_profiles($data);
if($res['status'] == 'fail'){
$this->response('同步删除失败');
'profileKey'=>$info['profile_key']
];
//发送请求删除社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->deleted_profiles($data);
if($res['status'] == 'fail'){
$this->response('同步删除失败');
}
}
$ayrShareLogic->ayr_share_del();
$this->response('success');
... ...
... ... @@ -5,14 +5,13 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bside\Nav\NavRequest;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Requests\Scene;
use App\Models\User\User as UserModel;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Validator;
class BaseController extends Controller
{
... ... @@ -22,7 +21,7 @@ class BaseController extends Controller
protected $page = 1;//当前页
protected $row = 20;//每页条数
protected $header = [];//设置请求头参数
protected $order = 'id';
protected $order = 'created_at';
protected $map = [];//处理后的参数
protected $uid = 0;
protected $user = [];//当前登录用户详情
... ... @@ -45,8 +44,7 @@ class BaseController extends Controller
}
}
/**
* @name 参数过滤
* @return void
* @name :参数过滤
* @author :liyuhang
* @method
*/
... ... @@ -89,13 +87,12 @@ class BaseController extends Controller
}
break;
default:
if(!empty($v)){
$this->map[$k] = $v;
}
$this->map[$k] = $v;
break;
}
}
}
/**
* @name :统一返回参数
* @return JsonResponse
... ... @@ -172,8 +169,8 @@ class BaseController extends Controller
break;
case 'operator_id':
if(!empty($v)){
$name = (new UserModel())->read(['operator_id'=>$v],['id','name']);
$data['operator_name'] = (isset($name['name']) && !empty($name['name'])) ? $name['name'] : '无名称';
$name = (new UserModel())->read(['id'=>$v],['id','name']);
$data['operator_name'] = (isset($name['name']) && !empty($name['name'])) ? $name['name'] : '管理员';
}
break;
}
... ... @@ -209,5 +206,30 @@ class BaseController extends Controller
return \Illuminate\Support\Facades\Request::isMethod('post');
}
/**
* @name :(获取当前登录用户域名并通知更新)projectUrl
* @author :lyh
* @method :post
* @time :2023/6/6 14:09
*/
public function projectUrlNotify($str = ''){
$urlStr = 'api/updateHtmlNotify?model='.$str;
$domain = $this->getProjectDomain();
if(!empty($domain)){
$url = $domain.$urlStr;
return http_get($url);
}
return false;
}
public function getProjectDomain(){
$project = (new ProjectLogic())->getInfo($this->user['project_id']);
if(!empty($project['deploy_optimize']['domain'])){
return $project['deploy_optimize']['domain'];
}
if(!empty($project['deploy_build']['test_domain'])){
return $project['deploy_build']['test_domain'];
}
return '';
}
}
... ...
... ... @@ -8,12 +8,12 @@ use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
use App\Http\Requests\Bside\Blog\BlogCategoryRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\RouteMap;
class BlogCategoryController extends BaseController
{
/**
* @name :博客分类列表
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -26,6 +26,9 @@ class BlogCategoryController extends BaseController
$blogModel = new BlogModel();
foreach ($lists['list'] as $k => $v){
$v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['alias'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG_CATE, $v['id'], $this->user['project_id']);
$v['url'] = $this->getProjectDomain() . RouteMap::PATH_BLOG_CATE . '/' . $v['alias'];
$v['hasChildren'] = (($blogCategoryModel->read(['pid'=>$v['id']])) != false) ? true : false;
$lists['list'][$k] = $v;
}
}
... ... @@ -33,8 +36,18 @@ class BlogCategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
*/
public function categoryTopList(BlogCategoryLogic $blogCategoryLogic){
$list = $blogCategoryLogic->categoryTopList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前分类详情
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -45,11 +58,12 @@ class BlogCategoryController extends BaseController
'id.required' => 'ID不能为空'
]);
$info = $blogCategoryLogic->info_blog_category();
$info['alias'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG_CATE, $info['id'], $this->user['project_id']);
$info['url'] = $this->getProjectDomain() . RouteMap::PATH_BLOG_CATE . '/' . $info['alias'];
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加分类
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -62,7 +76,6 @@ class BlogCategoryController extends BaseController
/**
* @name :编辑分类
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -79,7 +92,6 @@ class BlogCategoryController extends BaseController
/**
* @name :编辑状态/与排序
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -95,7 +107,6 @@ class BlogCategoryController extends BaseController
/**
* @name :删除分类
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -9,12 +9,14 @@ use App\Http\Logic\Bside\Blog\BlogLabelLogic;
use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\RouteMap;
class BlogController extends BaseController
{
//通知别名
public $updateModelView = 'blog';
/**
* @name :博客列表
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -29,15 +31,27 @@ class BlogController extends BaseController
$v = $blogCategoryLogic->get_category_name($v);
//获取标签名称
$v = $blogLabelLogic->get_label_name($v);
$v['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $v['id'], $this->user['project_id']);
$v['url'] = $this->getProjectDomain() . $v['route'];
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :根据状态数量
* @name :getStatusNumber
* @author :lyh
* @method :post
* @time :2023/6/19 9:39
*/
public function getStatusNumber(BlogLogic $blogLogic){
$data = $blogLogic->getStatusNumber();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name :获取分页列表
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
... ... @@ -48,7 +62,6 @@ class BlogController extends BaseController
}
/**
* @name :获取当前博客详情
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -59,24 +72,25 @@ class BlogController extends BaseController
'id.required' => 'ID不能为空'
]);
$info = $blogLogic->blog_info();
$info['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $info['id'], $this->user['project_id']);
$info['url'] = $this->getProjectDomain() . $info['route'];
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加博客
* @return void
* @author :liyuhang
* @method
*/
public function add(BlogRequest $request,BlogLogic $blogLogic){
$request->validated();
$blogLogic->blog_add();
//TODO::写入日志
//TODO::通知网站更新
$this->projectUrlNotify($this->updateModelView);
$this->response('success');
}
/**
* @name :编辑博客
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -87,13 +101,13 @@ class BlogController extends BaseController
'id.required' => 'ID不能为空'
]);
$blogLogic->blog_edit();
//TODO::写入日志
//TODO::通知网站更新
$this->projectUrlNotify($this->updateModelView);
$this->response('success');
}
/**
* @name :编辑新闻seo
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -114,7 +128,6 @@ class BlogController extends BaseController
}
/**
* @name :编辑博客状态/排序
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -132,7 +145,6 @@ class BlogController extends BaseController
/**
* @name :删除博客(批量逻辑删除)
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -13,7 +13,6 @@ class BlogLabelController extends BaseController
{
/**
* @name :博客标签列表
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -32,13 +31,11 @@ class BlogLabelController extends BaseController
public function add(BlogLabelRequest $request,BlogLabelLogic $blogLabelLogic){
$request->validated();
$blogLabelLogic->add_blog_label();
//TODO::写入日志
$this->response('success');
}
/**
* @name :编辑标签
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -49,13 +46,11 @@ class BlogLabelController extends BaseController
'id.required' => 'ID不能为空'
]);
$blogLabelLogic->edit_blog_label();
//TODO::写入日志
$this->response('success');
}
/**
* @name :编辑标签状态/排序
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -66,13 +61,11 @@ class BlogLabelController extends BaseController
'id.required' => 'ID不能为空',
]);
$blogLabelLogic->status_blog_label();
//TODO::写入日志
$this->response('success');
}
/**
* @name :删除标签(批量删除)
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -3,18 +3,17 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Helper\AyrShare as AyrShareHelper;
use App\Helper\Country;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use App\Http\Logic\Bside\User\UserLogic;
use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Project\Project;
use App\Models\Project\Project as ProjectModel;
use App\Models\SmsLog;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User as UserModel;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Mrgoon\AliSms\AliSms;
/***
* 当前为公共类 所有方法均不需要验证登录token
... ... @@ -23,30 +22,25 @@ class ComController extends BaseController
{
/**
* @name :管理员登录
* @return void
* @author :liyuhang
* @method
*/
public function login(){
$this->request->validate([
'mobile'=>['required'],
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
'password'=>['required'],
],[
'mobile.required'=>'电话号码必须填写',
'password.required'=>'内容必须填写',
'mobile.max' => 'mobile不大于12字符.',
'mobile.regex' => '请输入正确的手机号码',
]);
$userModel = new UserModel();
$res = $userModel->login($this->param);
if($res === false){
$this->response('当前用户不存在或者被禁用,登录失败',Code::USER_ERROR,[]);
}
$userLogic = new UserLoginLogic();
$res = $userLogic->login();
$this->response('请求成功',Code::SUCCESS,$res);
}
/**
* @name :获取当前用户权限菜单列表
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -71,7 +65,6 @@ class ComController extends BaseController
/**
* @name :获取当前项目详情
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -85,7 +78,6 @@ class ComController extends BaseController
/**
* @name :登录用户编辑资料/修改密码
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -97,12 +89,9 @@ class ComController extends BaseController
'password.required'=>'密码必须填写',
'name.required'=>'名称必须填写',
]);
$userModel = new UserModel();
$userLogic = new UserLogic();
$this->param['id'] = $this->uid;
$rs = $userModel->edits($this->param);
if($rs === false){
$this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR);
}
$userLogic->edits($this->param);
$this->response('编辑成功');
}
... ... @@ -120,60 +109,40 @@ class ComController extends BaseController
$this->response('success');
}
/**
* @name : (测试定时任务)检测用户是否无操作记录
* @author :lyh
* @method :post
* @time :2023/5/12 14:55
* 发送登录短信
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
protected function ceShi(){
$this->error = 0;
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_share_list = $ayr_share_model->list($this->map);
if(!empty($ayr_share_list)){
foreach ($ayr_share_list as $k => $v){
//查询当前用户是否有未推送的博文
$ayr_release = new AyrReleaseModel();
$release_info = $ayr_release->read(['schedule_date'=>['>',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
//有推文时,直接跳出循环
if($release_info !== false){
continue;
}
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
//有发送博文,则跳出循环
if($release_info == false){
continue;
}
//删除用户第三方配置
$ayr_share_helper = new AyrShareHelper();
$data_profiles = [
'title'=>$v['title'],
'profileKey'=>$v['profile_key']
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
$this->error++;
continue;
}
//更新数据库
$data = [
'title'=>null,
'bind_plat_from'=>null,
'profile_key'=>null,
'ref_id'=>null,
];
$res = $ayr_share_model->edit($data,['id'=>$v['id']]);
if($res == false){
$this->error++;
}
}
public function sendLoginSms(Request $request)
{
$this->request->validate([
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
],[
'mobile.required' => '手机号码不能为空',
'mobile.regex' => '请输入正确的手机号码',
]);
$mobile = $request->input('mobile');
$user = UserModel::where(['mobile' => $mobile])->first();
if (empty($user)) {
$this->response('请输入正确的手机号码!', Code::USER_LOGIN_ERROE);
}
return $this->error;
$last_sms = SmsLog::getLastLog($mobile, SmsLog::TYPE_LOGIN);
if ($last_sms && $last_sms->use = SmsLog::USE_USABLE && time() - strtotime($last_sms->created_at) < 60) {
$this->response('请不要重复发送短信!', Code::USER_LOGIN_ERROE);
}
$template = config('aliyunsms.login_sms_temp');
$code['code'] = rand(100000,999999);
$ali_sms = new AliSms();
$send = $ali_sms->sendSms(strval($mobile), $template, $code);
if (empty($send->Code) && $send->Code != 'OK') {
$this->response('发送失败, 请稍后重试!', Code::USER_LOGIN_ERROE);
}
SmsLog::createLog($mobile, $code['code']);
$this->response('success');
}
public function ceshi(){
return $this->request->route()->getAction();
}
}
... ...
... ... @@ -30,9 +30,14 @@ class CustomController extends BaseController
// 每页数量
$limit = intval($this->param['limit']??20);
$name = request()->get('name');
$map = [];
if($name){
$map[] = ['name','like','%'.htmlspecialchars($name).'%'];
}
$lists = CustomLogic::instance()->getList(
[],
$map,
[],
['id','name','title','status','url','keywords','description','created_at','updated_at'],
$limit
... ...
... ... @@ -35,7 +35,7 @@ class CountController extends BaseController
//TODO::30天pv,ip统计
$data['visit_data'] = $countLogic->visit_data_count();
//TODO::询盘国家统计
$data['country_data'] = $countLogic->inquiry_country_count();
$data['country_data'] = json_decode($data['yesterday']['country']);
//TODO::来源排名
$data['referrer_count'] = $countLogic->referrer_count();
//TODO::访问国家前10
... ... @@ -44,42 +44,4 @@ class CountController extends BaseController
$data['enterprise_service'] = $countLogic->enterprise_service();
return $this->response('success',Code::SUCCESS,$data);
}
/***
* @name :(手动获取昨日数据统计)yesterday
* @author :lyh
* @method :post
* @time :2023/5/24 9:13
*/
public function yesterday(){
$deployModel = new DeployBuild();
$list = $deployModel->list();
$data = [];
$yesterday = Carbon::yesterday()->toDateString();
foreach ($list as $v){
$arr = [];
$arr['yesterday_pv_num'] = DB::table('gl_customer_visit_item')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$arr['yesterday_ip_num'] = DB::table('gl_customer_visit')->whereDate('date', $yesterday)->where('domain',$v['test_domain'])->count();
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($v['test_domain']);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
}else{
$arr['inquiry_num'] = count($inquiry_list['data']['total']);
}
$arr['date'] = $yesterday;
$rank_info = DB::table('gl_rank_data')->where(['updated_date'=>$yesterday,'lang'=>''])->select(['compliance_day'])->first();
if(empty($rank_info)){
$arr['compliance_day'] = 0;
}else{
$arr['compliance_day'] = $rank_info->compliance_day;
}
$arr['service_day'] = $v['service_duration'] - Common::getDaysToTargetDate($v['created_at']);
$arr['project_id'] = $v['project_id'];
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
$data[] = $arr;
}
DB::table('gl_count')->insert($data);
$this->response('success');
}
}
... ...
... ... @@ -14,35 +14,62 @@ class MailController extends BaseController
const STATUS_ONE = 1; //状态为已读状态
/**
* @name :当前用户站内信列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
$mailModel = new MailModel();
//获取当前用户下的所有站内信
$this->map['user_list'] = ['like','%,'.$this->uid.',%'];
$this->map['user_list'] = ['or',null];
$lists = $mailModel->lists($this->map,$this->page,$this->row);
$lists = $mailModel->where('status',0)
->where('user_list','like','%,'.$this->uid.',%')->orWhere('user_list', '')->select(['*'])->orderBy($this->order,'desc')
->paginate($this->row, ['*'], 'page', $this->page);
if(!empty($lists)){
$lists = $lists->toArray();
}
$mailUserModel = new MailUserModel();
$lists['unreadNum'] = $this->unreadNum($mailUserModel,$lists['total']);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$mailUserModel = new MailUserModel();
//获取用户已读还是未读
$info = $mailUserModel->read(['mail_id'=>$v['id'],'user_id'=>$this->uid]);
if($info !== false){
$v['read_status'] = $this::STATUS_ONE;//
}else{
$v['read_status'] = $this::STATUS_ZERO;
}
$lists['list'][$k] = $v;
}
//验证未读还是已读
$lists['list'] = $this->verifyRead($mailUserModel,$lists['list']);
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(验证已读还是未读)verifyRead
* @author :lyh
* @method :post
* @time :2023/6/17 15:02
*/
public function verifyRead(&$mailUserModel,$list){
foreach ($list as $k => $v){
//获取用户已读还是未读
$info = $mailUserModel->read(['mail_id'=>$v['id'],'user_id'=>$this->uid]);
if($info !== false){
$v['read_status'] = $this::STATUS_ONE;//
}else{
$v['read_status'] = $this::STATUS_ZERO;
}
$lists[$k] = $v;
}
return $lists;
}
/**
* @name :(未读数量)readNum
* @author :lyh
* @method :post
* @time :2023/6/17 13:58
*/
public function unreadNum(&$mailUserModel,$total){
//已读数量
$count = $mailUserModel->where(['user_id'=>$this->uid])->count();
$num = $total - $count;
return $num;
}
/**
* @name :获取站内信详情
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -79,21 +79,25 @@ class NavController extends BaseController
// todo::需要配合 c端来
return $this->success([
[
'url' => '/',
'url' => '',
'name' => '首页'
],
[
'url' => '/list',
'name' => '列表'
'url' => 'news',
'name' => '新闻'
],
[
'url' => '/page',
'name' => '单页'
'url' => 'products',
'name' => '产品'
],
[
'url' => '/goods',
'name' => '商品'
'url' => 'search',
'name' => '搜索页'
],
[
'url' => 'blog',
'name' => '博客'
]
]);
}
... ...
... ... @@ -8,12 +8,12 @@ use App\Http\Logic\Bside\News\NewsCategoryLogic;
use App\Http\Requests\Bside\News\NewsCategoryRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap;
class NewsCategoryController extends BaseController
{
/**
* @name :新闻分类列表
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -26,6 +26,9 @@ class NewsCategoryController extends BaseController
$newsModel = new NewsModel();
foreach ($lists['list'] as $k => $v){
$v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$v['alias'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS_CATE, $v['id'], $this->user['project_id']);
$v['url'] = $this->getProjectDomain() . RouteMap::PATH_NEWS_CATE . '/' . $v['alias'];
$v['hasChildren'] = (($newsCategory->read(['pid'=>$v['id']])) != false) ? true : false;
$lists['list'][$k] = $v;
}
}
... ... @@ -33,8 +36,18 @@ class NewsCategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
*/
public function categoryTopList(NewsCategoryLogic $newsCategoryLogic){
$list = $newsCategoryLogic->categoryTopList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前分类详情
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -45,11 +58,12 @@ class NewsCategoryController extends BaseController
'id.required' => 'ID不能为空'
]);
$info = $newsCategoryLogic->info_news_category();
$info['alias'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS_CATE, $info['id'], $this->user['project_id']);
$info['url'] = $this->getProjectDomain() . RouteMap::PATH_NEWS_CATE . '/' . $info['alias'];
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加分类
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -62,7 +76,6 @@ class NewsCategoryController extends BaseController
/**
* @name :编辑分类
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -78,7 +91,6 @@ class NewsCategoryController extends BaseController
/**
* @name :编辑状态/排序
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -94,7 +106,6 @@ class NewsCategoryController extends BaseController
/**
* @name :删除分类
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -3,23 +3,23 @@
namespace App\Http\Controllers\Bside\News;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsCategoryLogic;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\News\News as NewsModel;
use App\Models\RouteMap;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* @name:新闻管理
*/
class NewsController extends BaseController
{
public $updateModelView = 'news';
/**
* @name :获取新闻列表
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -30,6 +30,8 @@ class NewsController extends BaseController
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v = $newsCategoryLogic->get_category_name($v);
$v['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $v['id'], $this->user['project_id']);
$v['url'] = $this->getProjectDomain() . $v['route'];
$lists['list'][$k] = $v;
}
}
... ... @@ -37,8 +39,20 @@ class NewsController extends BaseController
}
/**
* @remark :根据状态数量
* @name :getStatusNumber
* @author :lyh
* @method :post
* @time :2023/6/19 9:39
*/
public function getStatusNumber(NewsLogic $newsLogic){
$data = $newsLogic->getStatusNumber();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name :添加新闻时获取分类列表
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -48,7 +62,6 @@ class NewsController extends BaseController
}
/**
* @name :获取详情
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -59,6 +72,8 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$info = $newsLogic->news_info();
$info['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $info['id'], $this->user['project_id']);
$info['url'] = $this->getProjectDomain() . $info['route'];
$this->response('success',Code::SUCCESS,$info);
}
/**
... ... @@ -70,12 +85,13 @@ class NewsController extends BaseController
public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){
$newsRequest->validated();
$newsLogic->news_add();
$this->response('success');
//TODO::通知网站更新
$res = $this->projectUrlNotify($this->updateModelView);
$this->response('success',Code::SUCCESS,$res);
}
/**
* @name :编辑
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -86,12 +102,13 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$newsLogic->news_edit();
$this->response('success');
//TODO::通知网站更新
$res = $this->projectUrlNotify($this->updateModelView);
$this->response('success',Code::SUCCESS,$res);
}
/**
* @name :编辑新闻seo
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -113,7 +130,6 @@ class NewsController extends BaseController
/**
* @name :编辑状态/与排序
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -130,7 +146,6 @@ class NewsController extends BaseController
}
/**
* @name :删除新闻(逻辑删除)
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -73,6 +73,8 @@ class ProductController extends BaseController
public function save(ProductRequest $request, ProductLogic $logic)
{
$data = $logic->save($this->param);
//通知更新界面
$this->projectUrlNotify('product');
return $this->success($data);
}
... ... @@ -88,4 +90,9 @@ class ProductController extends BaseController
return $this->success($data);
}
public function getStatusNumber(ProductLogic $logic){
$data = $logic->getStatusNumber();
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -188,7 +188,7 @@ class RankDataController extends BaseController
'video_position' => 0,
];
$client = new Client([
'base_uri' => 'http://45.136.131.71:8000',
'base_uri' => 'http://rank.waimaoq.com',
'timeout' => '20'
]);
... ... @@ -208,7 +208,7 @@ class RankDataController extends BaseController
$data = [
'position' => 0,
];
$res = HttpUtils::get('http://45.136.131.71:8000/luminati_rank', $param);
$res = HttpUtils::get('http://rank.waimaoq.com/luminati_rank', $param);
if ($res) {
$res = Arr::s2a($res);
$data['position'] = $res['position'];
... ...
... ... @@ -28,8 +28,8 @@ class ProjectCountryController extends BaseController
* @method :post
* @time :2023/4/28 17:53
*/
public function edit(ProjectCountryLogic $projectCountryLogic){
$projectCountryLogic->country_edit();
public function save(ProjectCountryLogic $projectCountryLogic){
$projectCountryLogic->country_save();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\ProofreadingLogic;
class ProofreadingController extends BaseController
{
const LANGUAGE_ID = 1;//默认语言英语
const TYPE_IMAGE = 2;//校队图片
/**
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/12 10:52
*/
public function lists(ProofreadingLogic $proofreadingLogic){
//默认显示语言为英语
if(!isset($this->map['language_id']) || empty($this->map['language_id'])){
$this->map['language_id'] = $this::LANGUAGE_ID;
}
$lists = $proofreadingLogic->proofreadingList($this->map,$this->page,$this->row);
if(!empty($lists['list']) && ($this->param['type'] == $this::TYPE_IMAGE)){
foreach ($lists['list'] as $k => $v){
$lists['list'][$k]['image_link'] = url('/b/image/' . $v['translate']);
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(新增/更新多语言)save
* @author :lyh
* @method :post
* @time :2023/6/12 10:52
*/
public function save(ProofreadingLogic $proofreadingLogic){
$proofreadingLogic->proofreadingSave();
$this->response('success');
}
/**
* @name :(当前项目选中的语言列表)languageList
* @author :lyh
* @method :post
* @time :2023/6/12 15:52
*/
public function languageList(ProofreadingLogic $proofreadingLogic){
$list = $proofreadingLogic->countryLanguageList($this->map,$this->order);
$this->response('success',Code::SUCCESS,$list);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Http\Logic\Bside\Statistics\StatisticsLogic;
use App\Models\Bside\Statistics\TrafficStatistics;
use Illuminate\Http\JsonResponse;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Throwable;
/**
* 流量统计
* Class StatisticsController
* @package App\Http\Controllers\Bside
*/
class StatisticsController extends BaseController
{
public $statisticsLogic;
public $trafficStatistics;
public function __construct()
{
$this->statisticsLogic = new StatisticsLogic();
$this->trafficStatistics = new TrafficStatistics();
}
/**
* 访问来源
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|Throwable
*/
public function source()
{
$type = $this->trafficStatistics::TYPE_SOURCE;
$response = $this->statisticsLogic->getStatisticsData($type);
return $this->success($response);
}
/**
* 地域分布
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|Throwable
*/
public function distribution()
{
$type = $this->trafficStatistics::TYPE_DISTRIBUTION;
$response = $this->statisticsLogic->getStatisticsData($type);
return $this->success($response);
}
/**
* 受访页面
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|Throwable
*/
public function page()
{
$type = $this->trafficStatistics::TYPE_PAGE;
$response = $this->statisticsLogic->getStatisticsData($type);
return $this->success($response);
}
/**
* 访问终端
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|Throwable
*/
public function terminal()
{
$type = $this->trafficStatistics::TYPE_TERMINAL;
$response = $this->statisticsLogic->getStatisticsData($type);
return $this->success($response);
}
/**
* 流量趋势
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|Throwable
*/
public function trend()
{
$type = $this->trafficStatistics::TYPE_TREND;
$response = $this->statisticsLogic->getStatisticsData($type);
$response['days'] = $this->statisticsLogic->getDaysTrend();
return $this->success($response);
}
}
... ...
... ... @@ -123,7 +123,8 @@ class TemplateController extends BaseController
$data = TemplateLogic::instance()->first($source,$source_id);
$res = [
'html' => $data['html']??'',
'name' => 'example'
'section_list_id' => $data['section_list_id']??'',
'name' => 'example',
];
return $this->response('',Code::SUCCESS,$res);
... ... @@ -139,10 +140,6 @@ class TemplateController extends BaseController
$data = $request->validated();
$data['data_source'] = $data['source'];
$data['data_source_id'] = $data['source_id'];
unset($data['source']);
unset($data['source_id']);
TemplateLogic::instance()->save($data);
return $this->response('保存成功');
// 不需要数据id
if(in_array($data['data_source'],['index'])){
... ... @@ -198,8 +195,7 @@ class TemplateController extends BaseController
*/
public function chunk(){
$lists = TemplateChunkLogic::instance()->getList([['status','=',1]],['sort'=>'asc'],['*'],false)->toArray();
$lists = TemplateChunkLogic::instance()->getList([['status','=',1]],['sort'=>'asc'],['*'],false);
foreach ($lists as &$list){
unset($list['created_at']);
unset($list['updated_at']);
... ...
... ... @@ -6,34 +6,82 @@ use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\User\DeptUserLogic;
use App\Models\User\ViewDeptUser;
use Illuminate\Support\Facades\DB;
class DeptUserController extends BaseController
{
/**
* @name :name
* @return void
* @author :liyuhang
* @method
*/
public function lists(ViewDeptUser $viewDeptUser){
$this->map['project_id'] = $this->user['project_id'];
$lists = $viewDeptUser->lists($this->map,$this->page,$this->row,'user_id');
public function lists(){
$query = DB::table('gl_project_user')
->leftJoin('gl_project_dept_user', 'gl_project_user.id', '=', 'gl_project_dept_user.user_id')
->leftJoin('gl_project_dept', 'gl_project_dept_user.dept_id', '=', 'gl_project_dept.id')
->join('gl_project_role', 'gl_project_user.role_id', '=', 'gl_project_role.id')
->orderBy('gl_project_dept_user.id','desc');
$query = $this->searchParam($query);
$lists = $query->paginate($this->row, $this->selectParam(), 'page', $this->page);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(查询参数设置)selectParam
* @author :lyh
* @method :post
* @time :2023/6/14 15:00
*/
public function selectParam(){
$select = [
'gl_project_dept_user.dept_id AS dept_id',
'gl_project_user.name AS name',
'gl_project_user.project_id AS project_id',
'gl_project_user.mobile AS mobile',
'gl_project_user.email AS email',
'gl_project_user.status AS status',
'gl_project_user.role_id AS role_id',
'gl_project_user.operator_id AS operator_id',
'gl_project_dept_user.is_admin AS is_admin',
'gl_project_dept.title AS title',
'gl_project_dept.pid AS pid',
'gl_project_dept.remark AS remark',
'gl_project_user.id AS user_id',
'gl_project_dept_user.id AS id',
'gl_project_role.name AS role_name'
];
return $select;
}
/**
* @name :(搜索参数处理)searchParam
* @author :lyh
* @method :post
* @time :2023/6/14 14:58
*/
public function searchParam(&$query){
//搜索条件处理
if(isset($this->map['name'])){
$query = $query->where('gl_project_user.name',$this->map['name'][0],'%'.$this->map['name'][1].'%');
}
if(isset($this->map['dept_id'])){
$query = $query->where('gl_project_dept_user.dept_id',$this->map['dept_id']);
}
$query = $query->where('gl_project_user.project_id',$this->user['project_id']);
return $query;
}
/**
* @param ViewDeptUser $viewDeptUser
* @name :(详情)info
* @author :lyh
* @method :post
* @time :2023/5/18 9:32
*/
public function info(ViewDeptUser $viewDeptUser){
public function info(DeptUserLogic $deptUserLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'id不能为空'
]);
$info = $viewDeptUser->read($this->param);
$info = $deptUserLogic->dept_user_info();
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -14,7 +14,6 @@ class ProjectRoleController extends BaseController
{
/**
* @name :用户角色列表()
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -30,7 +29,6 @@ class ProjectRoleController extends BaseController
/**
* @name :根据角色获取会员列表
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -41,7 +39,6 @@ class ProjectRoleController extends BaseController
}
/**
* @name :详情
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -56,7 +53,6 @@ class ProjectRoleController extends BaseController
}
/**
* @name :添加/编辑角色时获取菜单列表
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -66,7 +62,6 @@ class ProjectRoleController extends BaseController
}
/**
* @name :添加角色
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -78,7 +73,6 @@ class ProjectRoleController extends BaseController
/**
* @name :编辑角色
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -94,7 +88,6 @@ class ProjectRoleController extends BaseController
/**
* @name :修改用户状态
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -110,7 +103,6 @@ class ProjectRoleController extends BaseController
/**
* @name :删除角色
* @return void
* @author :liyuhang
* @method
*/
... ...
... ... @@ -17,7 +17,6 @@ class UserController extends BaseController
{
/**
* @name :name
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -41,7 +40,6 @@ class UserController extends BaseController
/**
* @name :添加管理员
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -53,7 +51,6 @@ class UserController extends BaseController
/**
* @name : 编辑管理员
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -69,7 +66,6 @@ class UserController extends BaseController
/**
* @name :修改当前用户状态
* @return void
* @author :liyuhang
* @method
*/
... ... @@ -85,7 +81,6 @@ class UserController extends BaseController
/**
* @name :详情
* @return json
* @author :liyuhang
* @method
*/
... ... @@ -100,7 +95,6 @@ class UserController extends BaseController
}
/**
* @name :删除管理员
* @return json
* @author :liyuhang
* @method
*/
... ...
... ... @@ -108,8 +108,13 @@ class FileController
echo $content;
exit;
}
/**
* 图片上传
* @remark :上传文件
* @name :upload
* @author :lyh
* @method :post
* @time :2023/6/17 16:32
*/
public function upload() {
$this->request->validate([
... ... @@ -129,11 +134,14 @@ class FileController
return $this->single($files);
}
}
/**
* @name :上传
* @return void
* @author :liyuhang
* @method
* @param $files
* @remark :单文件上传
* @name :single
* @author :lyh
* @method :post
* @time :2023/6/17 16:32
*/
public function single($files){
$hash = hash_file('md5', $files->getPathname());
... ... @@ -162,10 +170,14 @@ class FileController
}
return $this->response('资源',Code::SUCCESS,['file'=>$hash]);
}
/**
* 多文件上传
* @param type $files file对象集合
* @return type
* @param $files
* @remark :多文件上传
* @name :multi
* @author :lyh
* @method :post
* @time :2023/6/17 16:32
*/
private function multi($files) {
if (!is_array($files)) {
... ... @@ -199,11 +211,18 @@ class FileController
$fileModel->insert($save_data);
return $this->response('资源',Code::SUCCESS,['file'=>$data]);
}
/**
* @name 统一返回参数
* @return JsonResponse
* @author :liyuhang
* @method
* @param $msg
* @param string $code
* @param $data
* @param $result_code
* @param $type
* @remark :统一返回接口
* @name :response
* @author :lyh
* @method :post
* @time :2023/6/17 16:33
*/
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
... ... @@ -220,10 +239,11 @@ class FileController
/**
* @param $data
* @name :返回参数处理
* @return array|string
* @author :liyuhang
* @method
* @remark :参数处理
* @name :_extents
* @author :lyh
* @method :post
* @time :2023/6/17 16:32
*/
protected function _extents($data) {
... ... @@ -240,13 +260,7 @@ class FileController
}
switch ((string) $k) {
case 'file':
$data['file_link'] = url('/b/file_hash/' . $v .'/'.rand(100,999));
break;
case 'files':
$v = explode(',',$v);
foreach ($v as $k1=>$v1){
$data['files_link'][$k1] = url('/b/file_hash/' . $v1 . '/'.rand(100,999));
}
$data['file_link'] = url('/b/file_hash/'.$v);
break;
}
}
... ...
... ... @@ -91,7 +91,10 @@ class ImageController
}
/**
* 图片上传
* @name :(图片上传)upload
* @author :lyh
* @method :post
* @time :2023/6/17 16:28
*/
public function upload() {
$this->request->validate([
... ... @@ -112,10 +115,12 @@ class ImageController
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
* @param $files
* @remark :单图片上传
* @name :single
* @author :lyh
* @method :post
* @time :2023/6/17 16:30
*/
public function single($files){
$hash = hash_file('md5', $files->getPathname());
... ... @@ -144,12 +149,16 @@ class ImageController
}
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
}
/**
* 生成缩略图缓存
* @param type $info
* @param type $w
* @param type $h
* @return string
* @param $info
* @param $w
* @param $h
* @remark :生成缩略图
* @name :cacheImage
* @author :lyh
* @method :post
* @time :2023/6/17 16:31
*/
private function cacheImage($info, $w, $h) {
$path = $info['path'];
... ... @@ -159,9 +168,12 @@ class ImageController
}
/**
* 多图片上传
* @param type $files file对象集合
* @return type
* @param $files
* @remark :多图片上传
* @name :multi
* @author :lyh
* @method :post
* @time :2023/6/17 16:31
*/
private function multi($files) {
... ...
... ... @@ -5,7 +5,7 @@ namespace App\Http\Logic\Aside;
use App\Enums\Common\Common;
use App\Http\Logic\Logic;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Cache;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
... ... @@ -18,12 +18,9 @@ class BaseLogic extends Logic
protected $side = Common::A;
protected $user = [];
public function __construct()
{
$this->requestAll = request()->all();
$this->user = Session::get('manage');
}
... ...
... ... @@ -25,8 +25,6 @@ class ServerInformationLogic extends BaseLogic
{
parent::__construct();
$this->model = new ServerInformation();
$this->param = $this->requestAll;
}
... ... @@ -41,23 +39,22 @@ class ServerInformationLogic extends BaseLogic
{
$request = $this->param ?? [];
$service = new ServerInformation();
$this->extracted( $request, $service );
if ( $this->checkIp( $service->ip ) ) {
return $this->fail( '服务器信息添加失败,ip已存在' );
$this->extracted($request, $service, $service->FieldsArray());
if ($this->checkIp($request['ip'])) {
return $this->fail('服务器信息添加失败,ip已存在');
}
DB::beginTransaction();
if ( $service->save() ) {
$original = $service->getOriginal();
$original['type'] = $request['type'];
if ($service->save()) {
$original = $service->getOriginal();
$original['type'] = $request['type'];
$original['belong_to'] = $request['belong_to'];
// 添加日志
$this->server_action_log( ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id );
$this->server_action_log(ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id);
DB::commit();
return $this->success();
}
DB::rollBack();
return $this->fail( '服务器信息添加失败' );
return $this->fail('服务器信息添加失败');
}
... ... @@ -69,53 +66,53 @@ class ServerInformationLogic extends BaseLogic
*/
public function update()
{
$service = $this->getService();
$fields_array = $service->FieldsArray();
$request = $this->param ?? [];
$original = $service->getOriginal();
$original['type'] = $service->ServiceStr( $original['type'] );
$original['belong_to'] = $service->BelongToStr( $original['belong_to'] );
$this->extracted( $request, $service, $original );
$service = $this->getService();
$fields_array = $service->FieldsArray();
$request = $this->param ?? [];
$original = $service->getOriginal();
$original['type'] = $service->ServiceStr($original['type']);
$original['belong_to'] = $service->BelongToStr($original['belong_to']);
$this->extracted($request, $service, $original);
// 检查ip是否存在
if ( $service->ip != $request['ip'] ) {
if ( $this->checkIp( $request['ip'] ) ) {
$this->fail( '服务器信息修改失败,ip已存在', Code::USER_ERROR );
if ($service->ip != $request['ip']) {
if ($this->checkIp($request['ip'])) {
$this->fail('服务器信息修改失败,ip已存在', Code::USER_ERROR);
}
}
DB::beginTransaction();
if ( $service->save() ) {
if ($service->save()) {
$revised = $service->getAttributes();
$diff = array_diff_assoc( $original, $revised );
unset( $diff['created_at'] );
unset( $diff['updated_at'] );
unset( $diff['deleted'] );
$diff = array_diff_assoc($original, $revised);
unset($diff['created_at']);
unset($diff['updated_at']);
unset($diff['deleted']);
$remarks = '';
if ( $diff ) {
if ($diff) {
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:';
foreach ( $diff as $key => $value ) {
foreach ($diff as $key => $value) {
$remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
}
} else {
$remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改';
}
// 添加日志
$this->server_action_log( ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks );
$this->server_action_log(ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks);
DB::commit();
return $this->success();
}
DB::rollBack();
return $this->fail( '服务器信息修改失败' );
return $this->fail('服务器信息修改失败');
}
public function getService( int $deleted = ServerInformation::DELETED_NORMAL )
public function getService(int $deleted = ServerInformation::DELETED_NORMAL)
{
$id = $this->param['id'] ?? 0;
if ( !$id ) {
return $this->fail( 'ID不能为空' );
if (!$id) {
return $this->fail('ID不能为空');
}
$data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id );
if ( !$data ) {
return $this->fail( '数据不存在!' );
$data = ServerInformation::query()->where('deleted', $deleted)->find($id);
if (!$data) {
return $this->fail('数据不存在!');
}
return $data;
}
... ... @@ -125,10 +122,10 @@ class ServerInformationLogic extends BaseLogic
* @param $ip
* @return bool
*/
public function checkIp( $ip )
public function checkIp($ip)
{
$usIp = ServerInformation::query()->where( 'ip', $ip )->first();
if ( $usIp ) {
$usIp = ServerInformation::query()->where('ip', $ip)->first();
if ($usIp) {
return true;
} else {
return false;
... ... @@ -142,15 +139,15 @@ class ServerInformationLogic extends BaseLogic
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function serverInfo( int $deleted = ServerInformation::DELETED_NORMAL )
public function serverInfo(int $deleted = ServerInformation::DELETED_NORMAL)
{
$id = $this->param['id'] ?? 0;
if ( !$id ) {
return $this->fail( 'ID不能为空' );
if (!$id) {
return $this->fail('ID不能为空');
}
$data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id, [ 'type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at' ] );
if ( !$data ) {
return $this->fail( '数据不存在!' );
$data = ServerInformation::query()->where('deleted', $deleted)->find($id, ['type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at']);
if (!$data) {
return $this->fail('数据不存在!');
}
return $data;
}
... ... @@ -161,25 +158,25 @@ class ServerInformationLogic extends BaseLogic
* @param array $original 原始数据
* @param array $revised 修改后数据
*/
public function server_action_log( int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '' )
public function server_action_log(int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '')
{
$log = new ServerInformationLog();
$this->log( $log, $action, $original, $revised, $remarks );
$this->log($log, $action, $original, $revised, $remarks);
}
/**
* 提取数据
* @param array $request
* @param $service
* @param $service
* @param array $original
* @return void
*/
public function extracted( array $request, $service, array $original = [] )
public function extracted(array $request, $service, array $original)
{
$service->type = trim( $request['type'] ) ?? $original['type']; // 服务器类型
$service->ip = trim( $request['ip'] ) ?? $original['ip']; // 服务器ip
$service->title = trim( $request['title'] ) ?? $original['title']; // 服务器标题
$service->belong_to = trim( $request['belong_to'] ) ?? $original['belong_to']; // 服务器归属
$service->sshpass = trim( $request['sshpass'] ) ?? $original['sshpass']; // ssh密码
$service->ports = trim( $request['ports'] ) ?? $original['ports']; // ssh端口
$request = array_intersect_key($request, $original);
foreach ($request as $key => $value) {
$service->$key = trim($value) ?? $original[$key];
}
}
/**
... ... @@ -188,27 +185,27 @@ class ServerInformationLogic extends BaseLogic
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function get_batch_update( $action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL )
public function get_batch_update($action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL)
{
$ids = $this->getIds();
$data = ServerInformation::query()->whereIn( 'id', $ids )->where( 'deleted', $deleted )->get();
$restore_ids = $data->pluck( 'id' )->toArray();
$actionArr = ServerInformationLog::actionArr();
$actionStr = $actionArr[$action];
if ( empty( $restore_ids ) ) {
$this->fail( $actionStr . '服务器信息不存在!', Code::USER_ERROR );
$ids = $this->getIds();
$data = ServerInformation::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
$restore_ids = $data->pluck('id')->toArray();
$actionArr = ServerInformationLog::actionArr();
$actionStr = $actionArr[$action];
if (empty($restore_ids)) {
$this->fail($actionStr . '服务器信息不存在!', Code::USER_ERROR);
}
$original = $data->toArray();
DB::beginTransaction();
try {
$update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL;
ServerInformation::query()->whereIn( 'id', $restore_ids )->update( [ 'deleted' => $update ] );
$this->server_action_log( $action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode( ', ', $restore_ids ) );
ServerInformation::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);
$this->server_action_log($action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode(', ', $restore_ids));
DB::commit();
return $this->success();
} catch ( \Exception $e ) {
} catch (\Exception $e) {
DB::rollBack();
return $this->fail( '服务器信息' . $actionStr . '失败', Code::USER_ERROR );
return $this->fail('服务器信息' . $actionStr . '失败', Code::USER_ERROR);
}
}
... ... @@ -221,16 +218,16 @@ class ServerInformationLogic extends BaseLogic
public function getIds()
{
$id = $this->param['id'] ?? 0;
if ( !$id ) {
return $this->fail( '参数错误' );
if (!$id) {
return $this->fail('参数错误');
}
$ids = [];
if ( !is_array( $id ) ) {
$ids = explode( ',', $id );
if (!is_array($id)) {
$ids = explode(',', $id);
}
$ids = array_filter( $ids, 'intval' );
if ( empty( $ids ) ) {
return $this->fail( '参数错误' );
$ids = array_filter($ids, 'intval');
if (empty($ids)) {
return $this->fail('参数错误');
}
return $ids;
}
... ...
... ... @@ -10,7 +10,8 @@ use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Devops\ServerInformationLogic;
use App\Models\Aside\Domain\DomainInfo;
use App\Models\Aside\Domain\DomainInfoLog;
use App\Models\Devops\ServerInformation;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
... ... @@ -27,8 +28,6 @@ class DomainInfoLogic extends BaseLogic
{
parent::__construct();
$this->model = new ServerInformation();
$this->param = $this->requestAll;
}
... ... @@ -46,12 +45,12 @@ class DomainInfoLogic extends BaseLogic
return $this->fail('域名已存在!');
}
$domain = new DomainInfo();
$this->extracted($request, $domain);
$this->extracted($request, $domain, $domain->FieldsArray());
DB::beginTransaction();
if ($domain->save()) {
$original = $domain->getOriginal();
$original = $domain->getOriginal();
$original['belong_to'] = $request['belong_to'];
$original['status'] = $request['status'];
$original['status'] = $request['status'];
// 添加日志
$this->domain_action_log(DomainInfoLog::ACTION_ADD, $original, $original, '添加域名信息成功 - ID : ' . $domain->id);
DB::commit();
... ... @@ -70,23 +69,25 @@ class DomainInfoLogic extends BaseLogic
*/
public function update()
{
$domain = $this->getDomain();
$original = $domain->getOriginal();
$domain = $this->getDomain();
$original = $domain->getOriginal();
$original['belong_to'] = $domain->BelongToStr($original['belong_to']);
$original['status'] = $domain->StatusToStr($original['status']);
$request = $this->param;
$original['status'] = $domain->StatusToStr($original['status']);
$request = $this->param;
$this->extracted($request, $domain, $original);
// 检查ip是否存在
if ($domain->domain != $request['domain']) {
if ($this->checkDomain($request['domain'])) {
$this->fail('域名信息修改失败,域名已存在', Code::USER_ERROR);
if (array_key_exists('domain', $request)) {
if ($domain->domain != $request['domain']) {
if ($this->checkDomain($request['domain'])) {
$this->fail('域名信息修改失败,域名已存在', Code::USER_ERROR);
}
}
}
DB::beginTransaction();
if ($domain->save()) {
$fields_array = $domain->FieldsArray();
$revised = $domain->getAttributes();
$diff = array_diff_assoc($original, $revised);
$revised = $domain->getAttributes();
$diff = array_diff_assoc($original, $revised);
unset($diff['created_at']);
unset($diff['updated_at']);
unset($diff['deleted']);
... ... @@ -179,21 +180,13 @@ class DomainInfoLogic extends BaseLogic
* @param $domain
* @param array $original
* @return void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
public function extracted( array $request, $domain, array $original = [])
public function extracted(array $request, $domain, array $original)
{
$domain->domain = trim($request['domain']) ?? $original['domain'];
if (!$this->validateDomain($domain->domain)) {
$this->fail('域名格式错误');
$request = array_intersect_key($request, $original);
foreach ($request as $key => $value) {
$domain->$key = trim($value) ?? $original[$key];
}
$domain->belong_to = trim($request['belong_to']) ?? $original['belong_to']; // 域名归属 1 - 公司 2 - 客户
$domain->status = trim($request['status']) ?? $original['status']; // 域名状态 0 - 正常 1 - 关闭
$domain->domain_start_time = trim($request['domain_start_time']) ?? $original['domain_start_time']; // 域名开始时间
$domain->domain_end_time = trim($request['domain_end_time']) ?? $original['domain_end_time'];
$domain->certificate_start_time = trim($request['certificate_start_time']) ?? $original['certificate_start_time']; // 证书开始时间
$domain->certificate_end_time = trim($request['certificate_end_time']) ?? $original['certificate_end_time']; // 证书结束时间
}
/**
... ... @@ -204,11 +197,11 @@ class DomainInfoLogic extends BaseLogic
*/
public function get_batch_update($action = DomainInfoLog::ACTION_DELETE, $deleted = DomainInfo::DELETED_NORMAL)
{
$ids = (new ServerInformationLogic())->getIds();
$data = DomainInfo::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
$ids = (new ServerInformationLogic())->getIds();
$data = DomainInfo::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
$restore_ids = $data->pluck('id')->toArray();
$actionArr = DomainInfoLog::actionArr();
$actionStr = $actionArr[$action];
$actionArr = DomainInfoLog::actionArr();
$actionStr = $actionArr[$action];
if (empty($restore_ids)) {
$this->fail($actionStr . '域名信息不存在!', Code::USER_ERROR);
}
... ... @@ -232,18 +225,18 @@ class DomainInfoLogic extends BaseLogic
*/
public function getDomainCertificateTime($domain)
{
$domain = trim($domain);
$data = [];
$domain = trim($domain);
$data = [];
$context = stream_context_create(['ssl' => ['capture_peer_cert' => true]]); // Notice: only 7.0.7+ supports this
$stream = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
$stream = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($stream) {
$params = stream_context_get_params($stream);
$params = stream_context_get_params($stream);
$peerCertificate = openssl_x509_parse($params['options']['ssl']['peer_certificate']);
if ($peerCertificate) {
$validFrom = date_create_from_format('U', $peerCertificate['validFrom_time_t']); // 有效期开始时间
$validTo = date_create_from_format('U', $peerCertificate['validTo_time_t']); // 有效期结束时间
$validFrom = date_create_from_format('U', $peerCertificate['validFrom_time_t']); // 有效期开始时间
$validTo = date_create_from_format('U', $peerCertificate['validTo_time_t']); // 有效期结束时间
$data['validFrom'] = $validFrom->format('Y-m-d H:i:s');
$data['validTo'] = $validTo->format('Y-m-d H:i:s');
$data['validTo'] = $validTo->format('Y-m-d H:i:s');
}
}
return $data;
... ... @@ -256,60 +249,38 @@ class DomainInfoLogic extends BaseLogic
public function getAllDomain()
{
return DomainInfo::query()->where('status', 1)
->where('deleted', DomainInfo::DELETED_NORMAL)
->orderBy('updated_at', 'desc')
->get();
->where('deleted', DomainInfo::DELETED_NORMAL)
->orderBy('updated_at', 'desc')
->get();
}
/**
* 域名到期时间
* @param $domain
* @return array
* @throws GuzzleException
*/
public function getDomainTime($domain)
{
$conJson = file_get_contents("http://openai.waimaoq.com/v1/whois_api?domain={$domain}");
$conArr = json_decode($conJson, true);
$data = [];
if ($conArr['code'] == 200) {
$con = $conArr['text'];
$data['domain'] = $domain;
$url = "http://openai.waimaoq.com/v1/whois_api?domain={$domain}";
$client = new Client(['verify' => false]);
$http = $client->get($url);
$data = [];
if ($http->getStatusCode() != 200) {
return $data;
}
$content = $http->getBody()->getContents();
$json = json_decode($content, true);
if ($json['code'] == 200) {
$con = $json['text'];
$data['domain'] = $domain;
$data['validFrom'] = $con['creation_date'];
$data['validTo'] = $con['expiration_date'];
$data['validTo'] = $con['expiration_date'];
}
return $data;
}
/**
* 验证给定的值是否是有效的域名。
*
* @param mixed $value
* @return bool
*/
public function validateDomain($value)
{
// 从域中删除任何空间或路径。
$domain = preg_replace('/\s|\/.*$/', '', $value);
// 验证域是否至少包含一个句点。
if (strpos($domain, '.') === false) {
return false;
}
// 验证域是否以句点开始或结束。
if (strpos($domain, '.') === 0 || strrpos($domain, '.') === strlen($domain) - 1) {
return false;
}
// 验证域是否不包含无效字符。
if (!preg_match('/^[a-zA-Z0-9\-\.]+$/', $domain)) {
return false;
}
// 验证域是否具有有效的顶级域。
$tld = substr($domain, strrpos($domain, '.') + 1);
if (!in_array($tld, ['com', 'net', 'org'])) { // 如有必要,添加更多TLD。
return false;
}
return true;
}
/**
* 根据域名更新证书到期时间
* @param $id
* @param $updata
... ...
... ... @@ -2,10 +2,11 @@
namespace App\Http\Logic\Aside;
use App\Enums\Common\Common;
use App\Models\Manage\Manage;
use App\Models\Manage\LoginLog;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;
/**
... ... @@ -26,8 +27,7 @@ class LoginLogic extends BaseLogic
public function login()
{
$manage = $this->model->where('mobile', $this->requestAll['mobile'])->first();
$manage = $this->model->select('id', 'name', 'password', 'token', 'status', 'gid', 'dept_id')->where('mobile', $this->requestAll['mobile'])->first();
if (!$manage){
$this->fail('登录用户名不存在');
}
... ... @@ -37,21 +37,33 @@ class LoginLogic extends BaseLogic
if (!Hash::check($this->requestAll['password'], $manage->password)) {
$this->fail('登录密码不正确');
}
Session::put('manage', $manage->toArray());
if(!empty($manage['token'])){
//清除上一次用户缓存
Cache::pull(Common::MANAGE_TOKEN . $manage['token']);
}
//生成新token
$token = md5(uniqid().$manage['id']);
//存储缓存
$manage['token'] = $token;
Cache::add(Common::MANAGE_TOKEN . $token,$manage);
//更新用户信息
$manage->token = $token;
$res = $manage->save();
if(!$res){
$this->fail('系统错误,请联系管理员');
}
LoginLog::addLog($manage->id);
return $this->success();
return $this->success($manage->makeVisible('token')->toArray());
}
public function logout(){
Session::forget('manage');
return redirect(route('admin.login'));
Cache::pull(request()->header('token'));
return $this->success();
}
public static function manage($field = ''){
$manage = Session::get('manage');
$manage = Manage::find(1)->toArray();
$manage = Cache::get(Common::MANAGE_TOKEN . request()->header('token'));
$manage = Manage::find($manage['id'] ?? 0);
if($field){
return $manage[$field] ?? '';
}
... ...