AutoEmailContentController.php 2.0 KB
<?php
/**
 * @remark :
 * @name   :AutoEmailContentController.php
 * @author :lyh
 * @method :post
 * @time   :2024/12/30 14:09
 */

namespace App\Http\Controllers\Bside\Subscribe;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Project\AutoEmail;
use App\Models\Subscribe\Smtp;

/**
 * @remark :项目设置自动回复邮件内容
 * @name   :AutoEmailContentController
 * @author :lyh
 * @method :post
 * @time   :2024/12/30 14:09
 */
class AutoEmailContentController extends BaseController
{
    /**
     * @remark :获取
     * @name   :getInfo
     * @author :lyh
     * @method :post
     * @time   :2024/12/30 14:10
     */
    public function getContent(){
        $autoEmailModel = new AutoEmail();
        $lists = $autoEmailModel->list(['project_id'=>$this->user['project_id']]);
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :保存详情
     * @name   :saveContent
     * @author :lyh
     * @method :post
     * @time   :2024/12/30 14:11
     */
    public function saveContent(){
        $this->request->validate([
            'content' => ['required'],
        ], [
            'content.required' => '内容不能为空',
        ]);
        $smtpModel = new Smtp();
        $smtpInfo = $smtpModel->read(['project_id' => $this->user['project_id']]);
        if($smtpInfo === false){
            $this->fail('请先设置SMTP',Code::USER_ERROR);
        }
        $autoEmailModel = new AutoEmail();
        $info = $autoEmailModel->read(['project_id'=>$this->user['project_id']]);
        if($info === false){
            //执行新增
            $data = ['project_id'=>$this->user['project_id'],['title'=>$this->param['title'],'content'=>$this->param['content']];
            $id = $autoEmailModel->addReturnId($data);
        }else{
            $id = $info['id'];
            $autoEmailModel->edit(['title'=>$this->param['title'],'content'=>$this->param['content']],['project_id'=>$this->user['project_id']]);
        }
        $this->response('success',Code::SUCCESS,['id'=>$id]);
    }


}