WebSettingFromLogic.php 2.4 KB
<?php

namespace App\Http\Logic\Bside\Setting;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\WebSetting\WebSettingForm;
use App\Models\WebSetting\WebSettingFormBack;

class WebSettingFromLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();

        $this->model = new WebSettingForm();
        $this->param = $this->requestAll;
    }

    /**
     * @name   :(获取表单设置详情)setting_from_info
     * @author :lyh
     * @method :post
     * @time   :2023/5/4 13:43
     */
    public function setting_from_info(){
        $info = $this->model->list(['project_id'=>$this->user['project_id']],'created_at');
        if($info === false){
            $this->fail('当前数据不存在,或者已被删除');
        }
        return $this->success($info);
    }

    /**
     * @name   :(表单设置)setting_from_save
     * @param  :(is_required是否必填,name名称)
     * @author :lyh
     * @method :post
     * @time   :2023/5/4 10:39
     */
    public function setting_from_save(){
        try {
            //删除以前的数据
            $this->model->del(['project_id'=>$this->user['project_id']]);
            foreach ($this->param['data'] as $k => $v){
                $v['created_at'] = date('Y-m-d H:i:s');
                $v['updated_at'] = date('Y-m-d H:i:s');
                $v['project_id'] = $this->user['project_id'];
                $this->param['data'][$k] = $v;
            }
            //新增
            $this->model->insert($this->param['data']);
        }catch (\Exception $e){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * 保存询盘请求返回信息
     * @param $message
     * @param $url
     * @return WebSettingFormBack|mixed
     */
    public function fromBackMsgSet($message, $url, $other = false)
    {
        $project_id = $this->user['project_id'];
        $info = WebSettingFormBack::saveBack($project_id, $message, $url,$other);
        return $info;
    }

    /**
     * 获取询盘请求返回信息
     * @return mixed
     */
    public function fromBackMsgGet()
    {
        $project_id = $this->user['project_id'];
        $info = WebSettingFormBack::getBack($project_id);
        $result = [
            'message' => $info->message ?? '',
            'url' => $info->url ?? '',
            'other' => $info->other ?? ''
        ];
        return $result;
    }
}