RenewLogic.php 3.2 KB
<?php
/**
 * @remark :
 * @name   :RenewLogic.php
 * @author :lyh
 * @method :post
 * @time   :2023/8/11 17:29
 */

namespace App\Http\Logic\Aside\Project;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\Project\ProjectRenew;
use Illuminate\Support\Facades\DB;

class RenewLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->param = $this->requestAll;
        $this->model = new ProjectRenew();
    }

    /**
     * @remark :续费单记录列表
     * @name   :renewLog
     * @author :lyh
     * @method :post
     * @time   :2023/8/11 17:30
     */
    public function renewListsLog($map,$page,$row,$order,$field = ['*']){
        $lists = $this->model->lists($map,$page,$row,$order,$field);
        if(!empty($lists['list'])){
            $projectModel = new Project();
            foreach ($lists['list'] as $k => $v){
                $v['plan'] = Project::planMap()[$v['plan']];
                $v['project_name'] = $projectModel->getProjectName($v['project_id']);
                $lists['list'][$k] = $v;
            }
        }
        return $this->success($lists);
    }

    /**
     * @remark :根据主键获取续费单详情
     * @name   :renewRead
     * @author :lyh
     * @method :post
     * @time   :2023/8/14 9:12
     */
    public function renewRead(){
        $info = $this->model->read(['id'=>$this->param['id']]);
        if($info === false){
            $this->fail('当前数据不存在或者被删除');
        }
        return $this->success($info);
    }

    /**
     * @remark :关联续费单
     * @name   :editProjectRenew
     * @author :lyh
     * @method :post
     * @time   :2023/9/19 10:21
     */
    public function editProjectRenew(){
        //获取续费单详情
        $info = $this->model->read(['id'=>$this->param['renew_id']]);
        if($info === false){
            $this->fail('当前续费单不存在');
        }
        if($info['project_id'] != 0){
            $this->fail('当前续费单已关联项目,请重新选择');
        }
        DB::beginTransaction();
        try {
            $this->model->edit(['project_id'=>$this->param['id'],'operator_id'=>$this->manager['id']],['id'=>$this->param['renew_id']]);
            $project = new Project();
            $project->edit(['extend_type'=>0],['id'=>$this->param['id']]);
            $deployBuild = new DeployBuild();
            $deployBuild->edit(
                ['service_duration'=>DB::raw('service_duration + ' . $info['service_duration']),
                    'plan'=>$info['plan']], ['project_id'=>$this->param['id']]);
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :编辑续费单状态
     * @name   :editStatus
     * @author :lyh
     * @method :post
     * @time   :2023/9/19 15:50
     */
    public function editStatus(){
        $rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }
}