ServiceLogic.php 2.4 KB
<?php

namespace App\Http\Logic\Aside\Service;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\Service;
use Illuminate\Support\Facades\DB;

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

    /**
     * @remark :企业服务列表
     * @name   :serviceLists
     * @author :lyh
     * @method :post
     * @time   :2023/6/25 14:32
     */
    public function serviceLists($map,$page,$row,$order = 'id',$filed = ['*']){
        $lists = $this->model->lists($map,$page,$row,$order,$filed);
        return $this->success($lists);
    }

    /**
     * @remark :获取详情
     * @name   :serviceRead
     * @author :lyh
     * @method :post
     * @time   :2023/6/25 13:44
     */
    public function serviceRead(){
        $info = $this->model->read(['id'=>$this->param['id'],'status'=>0]);
        return $this->success($info);
    }

    /**
     * @remark :新增或编辑
     * @name   :serviceSave
     * @author :lyh
     * @method :post
     * @time   :2023/6/25 13:45
     */
    public function serviceSave(){
        $info = $this->model->read(['id'=>$this->param['id']]);
        if($info === false){
            $rs = $this->model->add($this->param);
        }else{
            $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        }
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :指定状态始终为一条数据
     * @name   :serviceStatus
     * @author :lyh
     * @method :post
     * @time   :2023/6/25 14:09
     */
    public function serviceStatus(){
        DB::beginTransaction();
        try {
            $this->model->edit(['status'=>1],['id'=>['!=',$this->param['id']]]);
            $this->model->edit(['status'=>0],['id'=>$this->param['id']]);
            DB::commit();
        }catch (\Exception $e){
            DB::rollBack();
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :删除企业服务信息
     * @name   :serviceDel
     * @author :lyh
     * @method :post
     * @time   :2023/6/25 14:22
     */
    public function serviceDel(){
        $rs = $this->model->del(['id'=>['in',$this->param['id']]]);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }
}