作者 赵彬吉

project

... ... @@ -39,7 +39,7 @@ class ProjectController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'manager_uids', 'remark']));
return $this->success($data);
}
public function save(ProjectRequest $request, ProjectLogic $logic)
... ... @@ -47,16 +47,4 @@ class ProjectController extends BaseController
$data = $logic->save($this->param);
return $this->success($data);
}
public function delete(Request $request, ProjectLogic $logic)
{
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
}
... ...
... ... @@ -7,7 +7,7 @@ namespace App\Http\Logic\Aside\Devops;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\Devops\DevopsTask;
use App\Models\Project;
use App\Models\Project\Project;
use App\Models\Devops\ServerConfig;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
... ...
<?php
namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\DeployBuild;
class DeployBuildLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new DeployBuild();
}
}
... ...
<?php
namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\DeployOptimize;
class DeployOptimizeLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new DeployOptimize();
}
}
... ...
<?php
namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\Payment;
class PaymentLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Payment();
}
}
... ...
... ... @@ -3,9 +3,20 @@
namespace App\Http\Logic\Aside\Project;
use App\Helper\Arr;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use Illuminate\Support\Facades\DB;
/**
* Class ProjectLogic
* @package App\Http\Logic\Aside\Project
* @author zbj
* @date 2023/4/26
*/
class ProjectLogic extends BaseLogic
{
public function __construct()
... ... @@ -15,4 +26,85 @@ class ProjectLogic extends BaseLogic
$this->model = new Project();
}
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
parent::setWith(['payment', 'deploy_build', 'deploy_optimize']);
return parent::getList($map, $sort, $columns, $limit);
}
public function getInfo($id)
{
parent::setWith(['payment', 'deploy_build', 'deploy_optimize']); //删除缓存要添加带with的cache_key
return parent::getInfo($id);
}
public function save($param){
DB::beginTransaction();
try {
parent::save($param);
$this->savePayment($param);
$this->saveDeployBuild($param);
$this->saveDeployOptimize($param);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('保存失败');
}
return $this->success();
}
/**
* 保存付款续费
* @author zbj
* @date 2023/4/26
*/
protected function savePayment($param){
if(empty($param['payment'])){
return true;
}
$data = $param['payment'];
$data['project_id'] = $param['id'];
$data['id'] = Payment::where('project_id', $param['id'])->value('id');
Arr::forget($data, ['amount']);
return (new PaymentLogic)->save($data);
}
/**
* 保存建站部署
* @author zbj
* @date 2023/4/26
*/
protected function saveDeployBuild($param){
if(empty($param['deploy_build'])){
return true;
}
$data = $param['deploy_build'];
$data['project_id'] = $param['id'];
$data['id'] = DeployBuild::where('project_id', $param['id'])->value('id');
Arr::forget($data, ['test_domain', 'plan']);
return (new DeployBuildLogic)->save($data);
}
/**
* 保存优化部署
* @author zbj
* @date 2023/4/26
*/
protected function saveDeployOptimize($param){
if(empty($param['deploy_optimize'])){
return true;
}
$data = $param['deploy_optimize'];
$data['project_id'] = $param['id'];
$data['id'] = DeployOptimize::where('project_id', $param['id'])->value('id');
return (new DeployOptimizeLogic)->save($data);
}
public function clearCache($id)
{
parent::clearCache($id);
parent::setWith(['payment', 'deploy_build', 'deploy_optimize']);
parent::clearCache($id);
}
}
... ...
... ... @@ -21,6 +21,8 @@ class Logic
protected $is_cache = true; //是否缓存数据
protected $with = []; //预加载多个关联
/**
* @notes: 请简要描述方法功能
* @param array $data
... ... @@ -69,9 +71,9 @@ class Logic
// 数据分页设置
if ($limit) {
$result = $query->select($columns)->paginate($limit);
$result = $query->with($this->with)->select($columns)->paginate($limit);
}else{
$result = $query->select($columns)->get();
$result = $query->with($this->with)->select($columns)->get();
}
if($this->side == Common::A){
return $result;
... ... @@ -107,13 +109,13 @@ class Logic
if($this->is_cache){
$info = Cache::get($this->getInfoCacheKey($id));
if (!$info) {
$info = $this->model->find($id);
$info = $this->model->with($this->with)->find($id);
if($info){
Cache::put($this->getInfoCacheKey($id), $info);
}
}
}else{
$info = $this->model->find($id);
$info = $this->model->with($this->with)->find($id);
}
return $info;
}
... ... @@ -132,6 +134,8 @@ class Logic
if(!$this->model){
$this->fail('数据不存在或者已经删除');
}
}else{
Arr::forget($param, ['id']);
}
$columns = Schema::getColumnListing($this->model->getTable());
foreach ($param as $name => $value){
... ... @@ -145,7 +149,7 @@ class Logic
if($res){
//清缓存
if($this->is_cache && !empty($param['id'])){
Cache::forget($this->getInfoCacheKey($param['id']));
$this->clearCache($param['id']);
}
return $this->success(['id' => $this->model->id]); //返回保存的数据id
}else{
... ... @@ -175,7 +179,7 @@ class Logic
}
$model->delete();
if($this->is_cache){
Cache::forget($this->getInfoCacheKey($id));
$this->clearCache($id);
}
}
... ... @@ -189,7 +193,33 @@ class Logic
* @date 2023/4/13
*/
public function getInfoCacheKey($id){
return $this->model->getTable() . '_info_' . $id;
$key = $this->model->getTable() . '_info_' . $id;
if($this->with){
$key .= '_' . implode('_', $this->with);
}
return $key;
}
/**
* @param $id
* @return string
* @author zbj
* @date 2023/4/13
*/
public function clearCache($id){
Cache::forget($this->getInfoCacheKey($id));
}
/**
* 设置关联查询表
* @param $with
* @return $this
* @author zbj
* @date 2023/4/26
*/
public function setWith($with){
$this->with = $with;
return $this;
}
/**
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Http\Requests\Aside\Project;
use App\Rules\Mobile;
use Illuminate\Foundation\Http\FormRequest;
/**
... ... @@ -30,17 +31,29 @@ class ProjectRequest extends FormRequest
public function rules()
{
return [
'title'=>'required|max:50',
'remark'=>'max:200',
// 'id' => 'required',
// 'title' => 'max:100',
// 'company' => 'max:100',
// 'lead_name' => 'max:20',
// 'mobile' => [new Mobile()],
// 'qq' => 'max:20',
// 'cooperate_date' => 'date_format:Y-m-d',
// 'province' => 'max:20',
// 'city' => 'max:20',
];
}
public function messages()
{
return [
'title.required' => '请输入部门名称',
'title.max' => '部门名称不能超过50个字符',
'remark.max' => '备注不能超过200个字符',
'id.required' => 'ID不能为空',
'title.max' => '项目名称不能超过100个字符',
'company.max' => '公司名不能超过100个字符',
'lead_name.max' => '联系人不能超过20个字符',
'qq.max' => 'QQ号不能超过20个字符',
'cooperate_date.date_format' => '合作时间格式不正确',
'province.max' => '省份不能超过20个字符',
'city.max' => '城市不能超过20个字符',
];
}
... ...
<?php
namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
class DeployBuild extends Base
{
//设置关联表名
protected $table = 'gl_project_deploy_build';
public function setPlanAttribute($value){
$this->attributes['plan'] = Arr::arrToSet($value);
}
public function getPlanAttribute($value){
return Arr::setToArr($value);
}
}
... ...
<?php
namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
class DeployOptimize extends Base
{
//设置关联表名
protected $table = 'gl_project_deploy_optimize';
public function setMinorLanguagesAttribute($value){
$this->attributes['minor_languages'] = Arr::a2s($value);
}
public function getMinorLanguagesAttribute($value){
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
class Payment extends Base
{
//设置关联表名
protected $table = 'gl_project_payment';
public function setRenewalRecordAttribute($value){
$this->attributes['renewal_record'] = Arr::a2s($value);
}
public function getRenewalRecordAttribute($value){
return Arr::s2a($value);
}
}
... ...
<?php
namespace App\Models;
namespace App\Models\Project;
use App\Helper\Arr;
use App\Models\Base;
use App\Models\Devops\ServerConfig;
class Project extends Base
... ... @@ -29,6 +31,25 @@ class Project extends Base
}
/**
* 项目分类
* @return string[]
* @author zbj
* @date 2023/4/26
*/
public static function typeMap()
{
return [
1 => '建站进程中',
2 => '已完成–推广进程中',
3 => '已完成-建站用户',
4 => '续费记录单',
5 => '推广续网站',
6 => '未续费项目',
7 => '特殊推广项目'
];
}
/**
* 项目部署服务器信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
... ... @@ -65,4 +86,62 @@ class Project extends Base
{
return self::DATABASE_NAME_FIX . $this->id;
}
/**
* 付款续费信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @author zbj
* @date 2023/4/26
*/
public function payment()
{
return self::hasOne(Payment::class, 'project_id', 'id');
}
/**
* 建站部署信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @author zbj
* @date 2023/4/26
*/
public function deploy_build()
{
return self::hasOne(DeployBuild::class, 'project_id', 'id');
}
/**
* 建站部署信息
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @author zbj
* @date 2023/4/26
*/
public function deploy_optimize()
{
return self::hasOne(DeployOptimize::class, 'project_id', 'id');
}
public function setLevelAttribute($value){
$this->attributes['level'] = Arr::arrToSet($value);
}
public function getLevelAttribute($value){
return Arr::setToArr($value);
}
public function setChannelAttribute($value){
$this->attributes['channel'] = Arr::a2s($value);
}
public function getChannelAttribute($value){
return Arr::s2a($value);
}
public function setNoticeAttribute($value){
$this->attributes['notice'] = Arr::a2s($value);
}
public function getNoticeAttribute($value){
return Arr::s2a($value);
}
}
... ...