WebSettingReceivingLogic.php 2.5 KB
<?php

namespace App\Http\Logic\Bside\Setting;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\WebSetting\WebSettingReceiving;
use App\Services\SyncService;
use Illuminate\Support\Facades\DB;

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

    /**
     * @name   :(列表数据)setting_receiving_lists
     * @author :lyh
     * @method :post
     * @time   :2023/5/8 16:17
     */
    public function setting_receiving_lists(){
        $lists = $this->model->list(['project_id'=>$this->user['project_id']],'created_at');
        return $this->success($lists);
    }

    /**
     * @name   :(设置收信账号)setting_receiving_save
     * @author :lyh
     * @method :post
     * @time   :2023/5/8 16:26
     */
    public function setting_receiving_save(){
        $data = [];
        if(!isset($this->param['data']) || empty($this->param['data'])){
            $this->fail('参数错误,请联系管理员');
        }
        foreach ($this->param['data'] as  $v){
            if($v['type'] == 1){
                // 使用正则表达式匹配中国大陆手机号
                $pattern = '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/';
                if (!preg_match($pattern, $v['values'])) {
                    $this->fail('当前数据不符合规则:'.$v['values']);
                }
            }
            if($v['type'] == 2){
                // 使用正则表达式匹配中国大陆手机号
                $pattern = '/^1[3456789]\d{9}$/';
                if (!preg_match($pattern, $v['values'])) {
                    $this->fail('当前数据不符合规则:'.$v['values']);
                }
            }
            $v['project_id'] = $this->user['project_id'];
            $v['created_at'] = date('Y-m-d H:i:s');
            $v['updated_at'] = date('Y-m-d H:i:s');
            $data[] = $v;
        }
        DB::connection('custom_mysql')->beginTransaction();
        try {
            $this->model->del(['project_id'=>$this->user['project_id']]);
            if(!empty($data)){
                $this->model->insert($data);
            }
            DB::connection('custom_mysql')->commit();
        }catch (\Exception $e){
            DB::connection('custom_mysql')->rollBack();
            $this->fail('编辑失败,请联系管理员');
        }
        (new SyncService())->projectAcceptAddress($this->user['project_id']);
        return $this->success();
    }
}