作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

<?php
namespace App\Console\Commands;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\File\DataFile;
use Dompdf\Dompdf;
use Dompdf\Options;
use Illuminate\Console\Command;
class ProjectFilePDF extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_file_pdf';
/**
* The console command description.
*
* @var string
*/
protected $description = '网站项目数据,生成PDF文件';
protected $AiccWechat;
protected $DataFile;
protected $time;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
$this->AiccWechat = new ProjectAssociation();
$this->DataFile = new DataFile();
$this->time = date("Y-m-d");
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$data = $this->get_data();
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
$this->dataPush($items);
if ($totalPage > 1) {
for ($page = 2; $page <= $totalPage; $page++) {
$da = $this->get_data();
$this->dataPush($da['items']);
}
}
$this->info('生成pdf完成');
return 0;
}
/**
* 数据生成并保存
* @param array $items
* @return void
*/
public function dataPush(array $items)
{
foreach ($items as $item) {
$project_id = $item->project_id;
$application_id = $item->wx_id;
$wx_user_id = $item->wx_user_id;
// todo 根据项目查询数据
$project_data = [];
$html = $this->html($project_data);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $application_id);
$file_path = $this->savePDF($html, $filename);
$this->DataFile->saveData(compact('project_id', 'application_id', 'file_path') + ['time' => $this->time]);
}
}
public function get_data($page = 1, $perPage = 20)
{
$data = $this->AiccWechat->allData($page, $perPage);
# 总条数
$total = $data['total'];
if (empty($total)) {
$this->error('暂无绑定AICC微信数据');
return 0;
}
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
# 当前页
$currentPage = $data['currentPage'];
return compact('total', 'items', 'totalPage', 'currentPage');
}
public function savePDF($html, $filename)
{
// todo 生成中文有问题
# 实例化并使用dompdf类
$options = new Options();
$options->setDefaultFont('arial');
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
#(可选)设置纸张大小和方向
$dompdf->setPaper('A4', 'landscape');
# 将HTML渲染为PDF
$dompdf->render();
// 获取PDF内容
$pdfContent = $dompdf->output();
// 指定保存路径和文件名
$savePath = public_path('PDF/' . $filename . '.pdf');
// 将PDF内容保存到文件
file_put_contents($savePath, $pdfContent);
// 输出保存成功消息
return $savePath;
}
/**
* 根据数据生成 Html
* @param $item
* @return string
*/
protected function html($item)
{
$html = '<html>';
$html .= '<body style="font-family:arial">';
$html .= '<h1>Hello, World!</h1>';
$html .= '<p>中文内容</p>';
$html .= '</body>';
$html .= '</html>';
return $html;
}
}
... ...
... ... @@ -59,11 +59,11 @@ class UpdateRoute extends Command
echo date('Y-m-d H:i:s') . ' start: 项目id为' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->setProductRoute($v['id']);
$this->setProductKeywordRoute($v['id']);
$this->setBlogRoute($v['id']);
$this->setNewsRoute($v['id']);
$this->setBlogCateRoute($v['id']);
$this->setNewsCateRoute($v['id']);
// $this->setProductKeywordRoute($v['id']);
// $this->setBlogRoute($v['id']);
// $this->setNewsRoute($v['id']);
// $this->setBlogCateRoute($v['id']);
// $this->setNewsCateRoute($v['id']);
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . ' end: 项目id为' . $v['id'] . PHP_EOL;
... ...
<?php
namespace App\Console\Commands;
use App\Models\File\DataFile;
use Illuminate\Console\Command;
class WebsiteData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'website_data';
/**
* The console command description.
*
* @var string
*/
protected $description = '向AICC推送数据';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$DataFile = new DataFile();
$data = $DataFile->allData();
# 详细数据
$items = $data['items'];
# 总分页
$totalPage = $data['totalPage'];
$this->post_data($items);
if ($totalPage > 1) {
for ($page = 2; $page <= $totalPage; $page++) {
$da = $DataFile->allData($page);
$this->post_data($da['items']);
}
}
$this->info('项目文件数据推送完成!');
return 0;
}
public function post_data($data)
{
return http_post("http://aicc-local.com/api/save_file_data", json_encode(compact('data')));
}
}
... ...
... ... @@ -38,6 +38,8 @@ class Kernel extends ConsoleKernel
$schedule->command('last_inquiry')->dailyAt('04:00')->withoutOverlapping(1);// 最近一次询盘信息
$schedule->command('update_progress')->everyThirtyMinutes()->withoutOverlapping(1);//监控更新
$schedule->command('update_seo_tdk_crontab')->dailyAt('00:00')->withoutOverlapping(1); //更新上线项目TDK
$schedule->command('website_data')->everyMinute()->withoutOverlapping(1); // 向AICC推送数据
$schedule->command('project_file_pdf')->everyMinute()->withoutOverlapping(1); // 网站项目数据,生成PDF文件
}
/**
... ...
... ... @@ -300,4 +300,24 @@ class LoginController extends BaseController
return $data;
}
public function ceshi(){
$url = 'https://demo.globalso.site/';
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];
$context = stream_context_create($contextOptions);
$sourceCode = file_get_contents($url, false, $context);
$pattern = '/<style\b[^>]*>(.*?)<\/style>/s'; // 定义匹配`<style>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $sourceCode); // 删除`<style>`标签及其内容
$pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签
$pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式
$matches = array();
preg_match_all($pattern, $strippedContent, $matches);
$textContentArray = $matches[1];
var_dump($textContentArray);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\ProjectAssociation;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Aside\ProjectAssociation\ProjectAssociationLogic;
use Illuminate\Http\Request;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ProjectAssociationController extends BaseController
{
private $ProjectAssociationLogic;
public function __construct(Request $request)
{
$this->ProjectAssociationLogic = new ProjectAssociationLogic();
parent::__construct($request);
}
/**
* V6与AICC数据关联
* @return void
* @throws BsideGlobalException
*/
public function saveWeChatData()
{
$project_id = (int)request()->post('project_id', 0);
if (empty($project_id)) {
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
}
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
$wx_user_id = (int)request()->post('user_id', 0);
if (empty($wx_user_id) && $status) {
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
}
$wx_id = (int)request()->post('wx_id', 0);
if (empty($wx_id) && $status) {
$this->fail('请选择要绑定的AICC项目!', Code::USER_PARAMS_ERROE);
}
$wx_nickname = request()->post('nickname', '');
$wx_user_name = request()->post('user_name', '');
$wx_image = request()->post('image', '');
$data = compact('project_id', 'wx_id', 'wx_nickname', 'wx_user_id', 'wx_user_name', 'wx_image');
$this->ProjectAssociationLogic->saveWeChatData($data);
$this->response('success');
}
}
... ...
... ... @@ -51,4 +51,17 @@ class ProofreadingController extends BaseController
$list = $proofreadingLogic->countryLanguageList($this->map,$this->order);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取Url内容
* @name :getUrlRead
* @author :lyh
* @method :post
* @time :2023/11/22 10:02
*/
public function getUrlRead($url){
$sourceCode = file_get_contents($url);
$strippedContent = strip_tags($sourceCode); // 删除所有HTML标签
var_dump($strippedContent);
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Template;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\BTemplateModuleLogic;
use App\Models\Template\BModuleProject;
/**
* @remark :左侧模块管理
... ... @@ -25,7 +26,12 @@ class BTemplateModuleController extends BaseController
if(!isset($this->map['test_model'])){
$this->map['test_model'] = 0;
}
$data = [];
$list = $BTemplateModuleLogic->ModuleList($this->map,$this->order);
// $data['list'] = $list;
// $moduleProjectModel = new BModuleProject();
// $module_list = $moduleProjectModel->list(['project_id'=>$this->user['project_id']]);
// $data['module_list'] = $module_list;
$this->response('success',Code::SUCCESS,$list);
}
... ...
<?php
namespace App\Http\Logic\Aside\ProjectAssociation;
use App\Enums\Common\Code;
use App\Http\Logic\Logic;
use App\Models\ProjectAssociation\ProjectAssociation;
use Illuminate\Support\Facades\DB;
class ProjectAssociationLogic extends Logic
{
public function saveWeChatData($data)
{
$wx = new ProjectAssociation();
DB::beginTransaction();
try {
$status = $wx->saveData($data);
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
$e->getMessage();
errorLog('V6与AICC关联失败', $wx, $e);
$this->fail('请检查操作是否正确!', Code::SERVER_MYSQL_ERROR);
}
return $status;
}
}
... ...
... ... @@ -44,6 +44,7 @@ class NavLogic extends BaseLogic
$this->param['group_id'] = BNavGroup::DEFAULT_FOOTER_ID;
}
}
unset($this->param['able_import']);
$this->param['image'] = str_replace_url(isset($this->param['image']) ? $this->param['image'] : '');
$this->param['remark_image'] = str_replace_url(isset($this->param['remark_image']) ? $this->param['remark_image'] : '');
if(isset($this->param['id']) && !empty($this->param['id'])){
... ...
... ... @@ -366,7 +366,8 @@ class ProductLogic extends BaseLogic
$info = $this->model->read(['id'=>$this->param['id']]);
$param = $this->setProductParams($info);
$save_id = $this->model->insertGetId($param);
$route = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
$route = preg_replace('/-product.*/', '', $param['route']);
$route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$save_id]);
//同步可视化装修数据
$this->copyTemplate($this->param['id'],$info['project_id'],$save_id);
... ...
<?php
namespace App\Models\File;
use App\Models\Base;
class DataFile extends Base
{
protected $table = 'gl_data_file';
public function saveData(array $data): bool
{
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->where('created_at', 'like', $data['time'] . '%')->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
$isRes->file_path = $data['file_path'];
$isRes->application_id = $data['application_id'];
return $isRes->save();
}
/**
* @param int $page
* @param int $perPage
* @return array
*/
public function allData(int $page = 1, int $perPage = 15)
{
$lists = self::query()->paginate($perPage, ['*'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
$total = $lists->total();
$currentPage = $lists->currentPage();
return compact('total', 'items', 'totalPage', 'currentPage');
}
}
... ...
<?php
namespace App\Models\ProjectAssociation;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class ProjectAssociation extends Model
{
protected $table = 'gl_project_association';
/**
* 保存|修改数据
* @param array $data
* @return bool
*/
public function saveData(array $data): bool
{
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
$isRes->wx_id = $data['wx_id'];
$isRes->wx_nickname = $data['wx_nickname'];
$isRes->wx_user_id = $data['wx_user_id'];
$isRes->wx_user_name = $data['wx_user_name'];
$isRes->wx_image = $data['wx_image'];
return $isRes->save();
}
/**
* 检查项目是否存在
* @param $project_id
* @return Builder|Model|object|null
*/
public function check($project_id)
{
return self::query()->where('project_id', $project_id)->first();
}
/**
* @param int $page
* @param int $perPage
* @return array
*/
public function allData(int $page = 1, int $perPage = 15)
{
$status = 1; # 1 - 正常, 0 - 禁用
$lists = self::query()->where('status', $status)
->whereNotNull('project_id')
->whereNotNull('wx_user_id')
->paginate($perPage, ['project_id', 'wx_id', 'wx_user_id'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
$total = $lists->total();
$currentPage = $lists->currentPage();
return compact('total', 'items', 'totalPage', 'currentPage');
}
}
... ...
... ... @@ -151,11 +151,11 @@ class RouteMap extends Base
* @time :2023/11/21 18:48
*/
public static function setProductRoute($route,$i = 0){
$route = $route.'-product';
$routes = $route.'-product';
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$route]);
$routeInfo = $routeMapModel->read(['route'=>$routes]);
if($routeInfo === false){
return $route;
return $routes;
}else{
$i = $i + 1;
$route = $route.'-'.$i;
... ... @@ -171,11 +171,11 @@ class RouteMap extends Base
* @time :2023/11/21 18:48
*/
public static function setKeywordRoute($route,$i = 0){
$route = $route.'-tag';
$routes = $route.'-tag';
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$route]);
$routeInfo = $routeMapModel->read(['route'=>$routes]);
if($routeInfo === false){
return $route;
return $routes;
}else{
$i = $i + 1;
$route = $route.'-'.$i;
... ...
... ... @@ -8,6 +8,7 @@
"bensampo/laravel-enum": "^4.2",
"beyondcode/laravel-websockets": "^1.14",
"doctrine/dbal": "^3.6",
"dompdf/dompdf": "^2.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"hashids/hashids": "^4.1",
... ...
... ... @@ -13,6 +13,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/editPassword', [Aside\Com\IndexController::class, 'editPassword'])->name('admin.editPassword.white');
Route::get('/logout', [Aside\LoginController::class, 'logout'])->name('admin.logout.white');
Route::any('/getAccessAddress', [Aside\LoginController::class, 'getAccessAddress'])->name('admin.getAccessAddress');//获取B端地址
Route::post('/aicc/wechat', [\App\Http\Controllers\Bside\ProjectAssociation\ProjectAssociationController::class, 'saveWeChatData'])->name('admin.aicc.wechat');
//会员相关
Route::prefix('user')->group(function () {
//会员管理
... ...