ServiceLogic.php 3.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);
        foreach ($lists as $k => $v){
            if(!empty($v['images'])){
                $arr = explode(',',$v['images']);
                foreach ($arr as $k1 => $v1){
                    $v['images_link'][$k1] = url('a/image/'.$v1);
                }
            }
            if(!empty($v['android'])){
                $v['android_link'] = url('a/image/'.$v['android']);
            }
            if(!empty($v['ios'])){
                $v['ios_link'] = url('a/image/'.$v['android']);
            }
            $lists[$k] = $v;
        }
        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]);
        if(!empty($info['images'])){
            $arr = explode(',',$info['images']);
            foreach ($arr as $k => $v){
                $info['images_link'][$k] = url('a/image/'.$v);
            }
        }
        if(!empty($info['android'])){
            $info['android_link'] = url('a/image/'.$v['android']);
        }
        if(!empty($info['ios'])){
            $info['ios_link'] = url('a/image/'.$v['android']);
        }
        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();
    }
}