<?php


/**
 * Class PjlWxc
 */
class PjlWxc extends PjlBase
{

    /**
     * @param int $id
     * @param array $data
     * @param array $repData
     * @return bool
     */
    public function update(int $id,array $data,array $repData) : bool
    {
        if($id <= 0){
            return false;
        }
        if(empty($data)){
            return false;
        }
        $this->PjlDb->Begin();
        $res = $this->PjlDb->Update("pl_repair",$data,sprintf("shopr_id=%d",$id));
        if($res == false){
            $this->PjlDb->Rollback(true);
            return false;
        }
        if(!empty($repData)){
            $res = $this->PjlDb->Query(sprintf("delete from %s where resl_shopr_id=%d",  LibFc::Escape("pl_repair_serve_link"), $id));
            if($res == false){
                $this->PjlDb->Rollback(true);
                return false;
            }
            $res = $this->PjlDb->Insert("pl_repair_serve_link",$repData);
            if($res == false){
                $this->PjlDb->Rollback(true);
                return false;
            }
        }
        $this->PjlDb->End();
        return true;
    }

    /**
     * @param int $repsId 服务项目ID
     * @return bool 成功返回true,失败返回false
     */
    public function deleteServe(int $repsId) : bool
    {
        if($repsId <= 0){
            return false;
        }
        $this->PjlDb->Begin();
        $this->PjlDb->Query(sprintf("delete from pl_repair_serve where reps_id=%d",$repsId));
        $this->PjlDb->Query(sprintf("delete from pl_repair_serve_link where resl_reps_id=%d",$repsId));
        $this->PjlDb->End();
        return true;
    }
}

