作者 赵彬吉
<?php
/**
* @remark :
* @name :EditPage.php
* @author :lyh
* @method :post
* @time :2023/11/13 10:06
*/
namespace App\Console\Commands;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class EditPage extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'edit_page';
/**
* The console command description.
*
* @var string
*/
protected $description = '修复单页面路由数据';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
//获取所有项目
$projectModel = new Project();
$list = $projectModel->list(['type'=>['in',[1,2,3,4]]]);
try {
foreach ($list as $v){
echo date('Y-m-d H:i:s') . ' start: '. $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
BCustomTemplate::where('url', 'like', '%-tag%')
->update(['url' => DB::raw("REPLACE(url, '-tag', '')")]);
RouteMap::where('route', 'like', '%-tag%')->where('source','page')
->update(['route' => DB::raw("REPLACE(route, '-tag', '')")]);
DB::disconnect('custom_mysql');
}
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: down' . PHP_EOL;
return true;
}
}
... ...
... ... @@ -225,13 +225,10 @@ class SyncProject extends Command
if($is_update == 1){
//4.0或5.0更新到6.0
//初始化数据库
$this->initializationMysql($id);
//初始账号
$this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']);
//新增数据抓取任务
$task_list = [];
foreach ($param['api_type'] as $v_type){
... ... @@ -245,7 +242,6 @@ class SyncProject extends Command
UpdateLog::createLog($id,$task,$param['get_data_url']);
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -278,9 +274,11 @@ class SyncProject extends Command
* @time :2023/8/30 15:53
*/
public function saveProject($param){
// if(isset($param['channel']) && !empty($param['channel'])){
if(isset($param['channel']) && !empty($param['channel'])){
$param['channel'] = Arr::a2s($param['channel']);
// }
}else{
$param['channel'] = Arr::a2s(["user_id"=>"", "zone_id"=>"", "channel_id"=>""]);
}
$projectModel = new Project();
$info = $projectModel->read(['from_order_id'=>$param['from_order_id'],'delete_status'=>0]);
if($info !== false){
... ... @@ -319,12 +317,11 @@ class SyncProject extends Command
protected function savePayment($param,$id){
$param['project_id'] = $id;
$paymentModel= new Payment();
// if(isset($param['contract']) && !empty($param['contract'])){
$param['contract'] = Arr::a2s($param['contract']);
// }
// if(isset($param['bill']) && !empty($param['bill'])){
$param['bill'] = Arr::a2s($param['bill']);
// }
$param['contract'] = Arr::a2s($param['contract']);
$param['bill'] = Arr::a2s($param['bill']);
if(!isset($param['renewal_record'])){
$param['renewal_record'] = [["amount"=> null, "remark"=> null, "expire_at"=> null]];
}
$info = $paymentModel->read(['project_id'=>$id]);
if($info !== false){
$paymentModel->edit($param,['id'=>$info['id']]);
... ...
... ... @@ -10,6 +10,7 @@
namespace App\Console\Commands;
use App\Models\Mail\Mail;
use App\Models\Project\Project;
use App\Models\User\User;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
... ... @@ -40,16 +41,20 @@ class UpdateProgress extends Command
*/
public function handle()
{
$project_id = Redis::rpop('updateProgress');
echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
//获取所有项目
$projectModel = new Project();
$list = $projectModel->list(['type'=>['in',[1,2,3,4]]]);
try {
ProjectServer::useProject($project_id);
$this->getUpdateProgress($project_id);
DB::disconnect('custom_mysql');
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->getUpdateProgress($v['id']);
DB::disconnect('custom_mysql');
}
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
echo date('Y-m-d H:i:s') . ' error: ->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL;
}
/**
... ... @@ -62,6 +67,7 @@ class UpdateProgress extends Command
public function getUpdateProgress($project_id){
$info = DB::connection('custom_mysql')->table('gl_update_progress')->whereRaw('total_num > current_num')->first();
if(!empty($info)){
//超时时间
$time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 60);
if($time > date("Y-m-d H:i:s")){
DB::connection('custom_mysql')->table('gl_update_progress')->where('id',$info['id'])->update(['current_num'=>$info['total_num']]);
... ... @@ -74,10 +80,9 @@ class UpdateProgress extends Command
$data["content"] = "部分页面更新超时,请重新更新,或联系管理员";
$mail = new Mail();
$mail->add($data);
}else{
Redis::lpush('updateProgress', $project_id);
}
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
return true;
}
}
... ...
... ... @@ -196,13 +196,9 @@ class DomainInfoController extends BaseController
$this->request->validate([
'id'=>'required',
'type' => 'required',
'other_domain'=>'required',
'extend_config'=>'required'
],[
'id.required' => 'id不能为空',
'type.required' => '类型不能为空',
'other_domain.required' => '其他域名不能为空',
'extend_config.required' => '301配置不能为空',
]);
$domainInfoLogic->sslSave();
$this->response('success');
... ...
... ... @@ -90,6 +90,8 @@ class ProjectController extends BaseController
$query = $this->searchContent($query);
//搜索升级项目
$query = $this->searchUpgrade($query);
//搜索战队
$query = $this->searchChannel($query);
return $query;
}
... ... @@ -189,6 +191,23 @@ class ProjectController extends BaseController
}
/**
* @remark :搜索战队
* @name :searchChannel
* @author :lyh
* @method :post
* @time :2023/11/9 10:16
*/
public function searchChannel(&$query){
if(isset($this->map['zone_id']) && !empty($this->map['zone_id'])){
$query->where('gl_project.channel','like','%"zone_id": "'.$this->map['channel_id'].'"%');
}
if(isset($this->map['channel_id']) && !empty($this->map['channel_id'])){
$query->where('gl_project.channel','like','%"channel_id": "'.$this->map['channel_id'].'"%');
}
return $query;
}
/**
* @remark :搜索技术组
* @name :searchDept
* @author :lyh
... ...
... ... @@ -141,7 +141,6 @@ class CNoticeController extends BaseController
];
$updateProgressModel = new UpdateProgress();
$updateProgressModel->insert($data);
Redis::lpush('updateProgress', $this->user['project_id']);
return true;
}
... ...
... ... @@ -56,9 +56,6 @@ class BaseController extends Controller
if(is_array($v)){
$this->map[$k] = $v;
}else{
if(empty($v) && ($v == null)){
unset($this->param[$k]);
}
$this->getMap($k,$v);
}
}
... ...
... ... @@ -138,6 +138,11 @@ class LoginController extends BaseController
* @time :2023/6/28 16:13
*/
public function stringTranslation(){
$this->request->validate([
'str'=>'required',
],[
'str.required' => '翻译字符串不能为空',
]);
$str = Translate::tran($this->param['str'], 'en');
$this->response('success',Code::SUCCESS,strtolower($str));
}
... ...
<?php
/**
* @remark :
* @name :ExtendController.php
* @author :lyh
* @method :post
* @time :2023/11/9 14:22
*/
namespace App\Http\Controllers\Bside\Product;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\ExtendLogic;
use App\Models\Product\Extend;
/**
* @remark :添加扩展字段
* @name :ExtendController
* @author :lyh
* @method :post
* @time :2023/11/9 14:22
*/
class ExtendController extends BaseController
{
/**
* @remark :获取所有扩展字段
* @name :lists
* @author :lyh
* @method :post
* @time :2023/11/9 14:23
*/
public function lists(Extend $extend){
$lists = $extend->list($this->map);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2023/11/9 14:26
*/
public function save(ExtendLogic $extendLogic){
$this->request->validate([
'title'=>'required',
'type'=>'required',
],[
'title.required' => '字段名称不能为空',
'type.required' => '字段类型不能为空',
]);
$info = $extendLogic->extendSave();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :删除扩展字段
* @name :del
* @author :lyh
* @method :post
* @time :2023/11/9 16:00
*/
public function del(ExtendLogic $extendLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => '主键不能为空',
]);
$extendLogic->extendDel();
$this->response('success');
}
}
... ...
... ... @@ -11,6 +11,7 @@ use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
... ... @@ -268,6 +269,17 @@ class ProductController extends BaseController
$templateInfo = $templateSettingModel->read(['project_id'=>$this->user['project_id']]);
$v['is_renovation'] = $this->getProductIsRenovation($templateInfo,$v['id']);
$v['url'] = $this->user['domain'].$v['route'];
//获取当前数据扩展字段及值
$extendInfoModel = new ExtendInfo();
$v['extend'] = $extendInfoModel->list(['product_id'=>$v['id']],'created_at');
foreach ($v['extend'] as $k1=>$v1){
if($v1['type'] == 3){
$v1['values'] = getImageUrl($v1['values']);
}elseif ($v1['type'] == 4){
$v1['values'] = getFileUrl($v1['values']);
}
$v['extend'][$k1] = $v1;
}
return $v;
}
... ...
<?php
/**
* @remark :
* @name :ExtendLogic.php
* @author :lyh
* @method :post
* @time :2023/11/9 14:24
*/
namespace App\Http\Logic\Bside\Product;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
class ExtendLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Extend();
}
/**
* @remark :保存数据
* @name :extendSave
* @author :lyh
* @method :post
* @time :2023/11/9 14:29
*/
public function extendSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$info = $this->model->read(['title'=>$this->param['title']]);
if($info !== false){
$this->fail('当前扩展名称已存在');
}
$key = trim(strtolower(preg_replace('/[\W]+/', '-', trim(Translate::tran($this->param['title'], 'en')))), '-');
$this->param['key'] = $this->getKey($key);
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success($this->param);
}
/**
* @remark :获取唯一key
* @name :getKey
* @author :lyh
* @method :post
* @time :2023/11/9 15:55
*/
public function getKey($key){
$info = $this->model->read(['key'=>$key]);
if($info !== false){
$key .= '-'.rand(1, 100);
return $this->getKey($key);
}
return $key;
}
/**
* @remark :删除自定义字段
* @name :extendDel
* @author :lyh
* @method :post
* @time :2023/11/9 16:07
*/
public function extendDel(){
$info = $this->model->read(['id'=>$this->param['id']]);
//查看当前扩展字段是否设置了值
$extendInfoModel = new ExtendInfo();
$extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
if($extendInfo !== false){
$this->fail('当前扩展字段已有产品在使用,不允许删除');
}
$this->model->del(['id'=>$this->param['id']]);
return $this->success();
}
}
... ...
... ... @@ -53,13 +53,10 @@ class KeywordLogic extends BaseLogic
try {
$this->param = $this->handleSaveParam($this->param);
if(isset($this->param['id']) && !empty($this->param['id'])){
$info = $this->model->read(['id'=>$this->param['id']],['id','route']);
$route = $info['route'];
$this->model->edit($this->param,['id'=>$info['id']]);
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['title'] = $this->param['title'].'-tag';
$this->param['updated_at'] = $this->param['created_at'];
$id = $this->model->insertGetId($this->param);
//路由映射
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
... ... @@ -37,6 +38,12 @@ class ProductLogic extends BaseLogic
* @time :2023/8/21 18:35
*/
public function productSave(){
//扩展字段
$extend = [];
if(!empty($this->param['extend'])){
$extend = $this->param['extend'];
unset($this->param['extend']);
}
$this->param = $this->handleSaveParam($this->param);
//单独处理分类
$category_ids = [];
... ... @@ -52,26 +59,67 @@ class ProductLogic extends BaseLogic
$this->param['route'] = $this->editProductRoute($this->param['route']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['updated_at'] = $this->param['created_at'];
$this->param['route'] = $this->param['route'].'-'.RouteMap::SOURCE_PRODUCT;
$this->param = $this->addHandleParam($this->param);
$id = $this->model->addReturnId($this->param);
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
}
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
$this->model->edit(['route'=> $this->param['route']],['id'=>$id]);
//产品分类关联
CategoryRelated::saveRelated($id, $category_ids);
//保存扩展字段
$this->saveExtendInfo($id,$extend);
DB::connection('custom_mysql')->commit();
}catch (\Exception $e){
DB::connection('custom_mysql')->rollBack();
$this->fail('系统错误请联系管理员');
}
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]);
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$this->param['route']]);
return $this->success();
}
/**
* @remark :新增时处理字段
* @name :addHandleParam
* @author :lyh
* @method :post
* @time :2023/11/9 14:48
*/
public function addHandleParam($param){
$param['project_id'] = $this->user['project_id'];
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = $param['created_at'];
return $param;
}
/**
* @remark :保存扩展字段
* @name :saveExtend
* @author :lyh
* @method :post
* @time :2023/11/9 15:02
*/
public function saveExtendInfo($id,$extend){
//先删除以前的数据
$extendInfoModel = new ExtendInfo();
$extendInfoModel->del(['project_id'=>$id]);
if(!empty($extend)){
foreach ($extend as $v){
unset($v['title']);
if(!empty($v['values'])){
if($v['type'] == 3 || $v['type'] || 4){
$v['values'] = str_replace_url($v['values']);
}
$v['project_id'] = $this->user['project_id'];
$v['product_id'] = $id;
$extendInfoModel->add($v);
}
}
}
return $this->success();
}
/**
* @remark :编辑列表数据
* @name :editList
... ... @@ -135,15 +183,15 @@ class ProductLogic extends BaseLogic
$v['url'] = str_replace_url($v['url']);
$param['gallery'][$k] = $v;
}
$param['thumb'] = Arr::a2s($param['gallery'][0] ?? '');
$param['gallery'] = Arr::a2s($param['gallery'] ?? '');
$param['thumb'] = Arr::a2s($param['gallery'][0] ?? []);
$param['gallery'] = Arr::a2s($param['gallery'] ?? []);
}
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
$param['attrs'] = Arr::a2s($param['attrs'] ?? []);
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
}
$param['describe'] = Arr::a2s($param['describe'] ?? '');
$param['describe'] = Arr::a2s($param['describe'] ?? []);
$param['describe_id'] = Arr::arrToSet($param['describe_id'] ?? '');
$param['seo_mate'] = Arr::a2s($param['seo_mate'] ?? '');
$param['related_product_id'] = Arr::arrToSet($param['related_product_id'] ?? '');
... ... @@ -151,7 +199,7 @@ class ProductLogic extends BaseLogic
foreach ($param['icon'] as $k1 => $v1){
$param['icon'][$k1] = str_replace_url($v1);
}
$param['icon'] = Arr::a2s($param['icon'] ?? '');
$param['icon'] = Arr::a2s($param['icon'] ?? []);
}
$param['created_uid'] = $this->user['id'];
return $param;
... ...
... ... @@ -166,6 +166,7 @@ class UserLoginLogic
$info['is_customized'] = $project['is_customized'];
$info['is_upload_manage'] = $project['is_upload_manage'];
$info['upload_config'] = $project['upload_config'];
$info['image_max'] = $project['image_max'];
$info['configuration'] = $project['deploy_build']['configuration'];
//保存项目缓存
Cache::put('user-'.$info['project_id'],$project,$minutes = null);
... ...
<?php
/**
* @remark :
* @name :Extend.php
* @author :lyh
* @method :post
* @time :2023/11/9 14:18
*/
namespace App\Models\Product;
use App\Models\Base;
class Extend extends Base
{
//设置关联表名
protected $table = 'gl_product_extend';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
<?php
/**
* @remark :
* @name :ExtendInfo.php
* @author :lyh
* @method :post
* @time :2023/11/9 14:19
*/
namespace App\Models\Product;
use App\Models\Base;
class ExtendInfo extends Base
{
//设置关联表名
protected $table = 'gl_product_extend_info';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -117,6 +117,10 @@ class RouteMap extends Base
$route_map->path = self::SOURCE_BLOG;
}elseif ($source == self::SOURCE_BLOG_CATE){
$route_map->path = self::PATH_BLOG_CATE;
}elseif ($source == self::SOURCE_PRODUCT_KEYWORD){
$route = $route.'-tag';
}elseif ($source == self::SOURCE_PRODUCT){
$route = $route.'-product';
}
$route_map->source_id = $source_id;
$route_map->project_id = $project_id;
... ...
... ... @@ -232,6 +232,9 @@ Route::middleware(['bloginauth'])->group(function () {
Route::get('describe/info', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'info'])->name('product_describe_info');
Route::post('describe/save', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'save'])->name('product_describe_save');
Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete');
//扩展字段
Route::any('extend', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'lists'])->name('product_extend');
Route::any('extend/save', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'save'])->name('product_extend_save');
});
... ...