作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -25,7 +25,7 @@ class CountDate extends Command @@ -25,7 +25,7 @@ class CountDate extends Command
25 * 25 *
26 * @var string 26 * @var string
27 */ 27 */
28 - protected $signature = 'count_data'; 28 + protected $signature = 'count_data {date}';
29 29
30 /** 30 /**
31 * The console command description. 31 * The console command description.
@@ -42,6 +42,7 @@ class CountDate extends Command @@ -42,6 +42,7 @@ class CountDate extends Command
42 */ 42 */
43 public function handle() 43 public function handle()
44 { 44 {
  45 + $date = $this->argument('date');
45 $list = DB::table('gl_project')->where('gl_project.extend_type','=',0) 46 $list = DB::table('gl_project')->where('gl_project.extend_type','=',0)
46 ->whereIn('gl_project.type',[1,2,3,4,6]) 47 ->whereIn('gl_project.type',[1,2,3,4,6])
47 ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id') 48 ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
@@ -51,7 +52,7 @@ class CountDate extends Command @@ -51,7 +52,7 @@ class CountDate extends Command
51 if(!empty($list)){ 52 if(!empty($list)){
52 $list = $list->toArray(); 53 $list = $list->toArray();
53 // $yesterday = Carbon::yesterday()->toDateString(); 54 // $yesterday = Carbon::yesterday()->toDateString();
54 - $yesterday = '2024-08-31 00:00:00'; 55 + $yesterday = $date;
55 $domainInfo = new DomainInfo(); 56 $domainInfo = new DomainInfo();
56 foreach ($list as $v){ 57 foreach ($list as $v){
57 $v = (array)$v; 58 $v = (array)$v;
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :CountProject.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/1/8 9:03
  8 + */
  9 +
  10 +namespace App\Console\Commands\MonthlyCount;
  11 +
  12 +use App\Helper\FormGlobalsoApi;
  13 +use App\Models\Com\UpdateOldInfo;
  14 +use App\Models\Domain\DomainInfo;
  15 +use App\Models\Inquiry\InquiryFormData;
  16 +use App\Models\Project\Project;
  17 +use App\Services\ProjectServer;
  18 +use Illuminate\Console\Command;
  19 +use Illuminate\Support\Facades\DB;
  20 +use App\Models\HomeCount\MonthCount AS MonthCountModel;
  21 +
  22 +class MonthCountDate extends Command
  23 +{
  24 + /**
  25 + * The name and signature of the console command.
  26 + *
  27 + * @var string
  28 + */
  29 + protected $signature = 'month_counts_date {date}';
  30 +
  31 + /**
  32 + * The console command description.
  33 + *
  34 + * @var string
  35 + */
  36 + protected $description = '每天生成月统计记录';
  37 +
  38 + public function handle(){
  39 + $list = DB::table('gl_project')->where('gl_project.extend_type','=',0)
  40 + ->whereIn('gl_project.type',[1,2,3,4,6])
  41 + ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
  42 + ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
  43 + ->select($this->selectParam())->get()->toArray();
  44 + foreach ($list as $v) {
  45 + $v = (array)$v;
  46 + if($v['type'] == Project::TYPE_ZERO){
  47 + continue;
  48 + }
  49 + if($v['is_upgrade'] == 1){
  50 + $oldModel = new UpdateOldInfo();
  51 + $info = $oldModel->read(['project_id' => $v['id']]);
  52 + if ($info !== false) {
  53 + $url = $info['old_domain_online'];
  54 + }else{
  55 + continue;
  56 + }
  57 + }else{
  58 + $domainInfo = new DomainInfo();
  59 + if(!empty($v['domain'])){
  60 + $info = $domainInfo->read(['id'=>$v['domain']]);
  61 + if($info !== false){
  62 + $url = $info['domain'];
  63 + }
  64 + }else{
  65 + $url = $v['test_domain'];
  66 + }
  67 + }
  68 + ProjectServer::useProject($v['id']);
  69 + echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
  70 + $this->count($v['id'], $url);
  71 + DB::disconnect('custom_mysql');
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * @name :(查询参数设置)selectParam
  77 + * @author :lyh
  78 + * @method :post
  79 + * @time :2023/6/14 15:00
  80 + */
  81 + public function selectParam(){
  82 + $select = [
  83 + 'gl_project.id AS id',
  84 + 'gl_project.type AS type',
  85 + 'gl_project.extend_type AS extend_type',
  86 + 'gl_project_deploy_build.test_domain AS test_domain',
  87 + 'gl_project.is_upgrade AS is_upgrade',
  88 + 'gl_project_deploy_optimize.domain AS domain',
  89 + 'gl_project_deploy_build.project_id AS project_id',
  90 + 'gl_project.cooperate_date AS cooperate_date',
  91 + 'gl_project_deploy_build.service_duration AS service_duration',
  92 + ];
  93 + return $select;
  94 + }
  95 + /**
  96 + * @remark :日统计记录
  97 + * @name :count
  98 + * @author :lyh
  99 + * @method :post
  100 + * @time :2024/1/8 9:05
  101 + */
  102 + public function count($project_id,$url){
  103 + $arr = [];
  104 + $date = $this->argument('date');
  105 + $v = ['month'=>$date];
  106 + $monthCountModel = new MonthCountModel();
  107 + $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
  108 + // 获取当月开始时间
  109 + $start = date('Y-m-01', strtotime($v['month']));
  110 + // 获取当月结束时间
  111 + $end = date('Y-m-t', strtotime($v['month']));
  112 + $arr['project_id'] = $project_id;
  113 + $res = (new FormGlobalsoApi())->getMonthInquiry($url,$v['month']);
  114 + $arr['total'] = $arr['month_total'] = 0;
  115 + if(isset($res['data']['count'])){
  116 + echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
  117 + $arr['month_total'] = $res['data']['count'] + InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
  118 + }
  119 + //获取上一个的count
  120 + $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));
  121 + $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
  122 + if($previousInfo === false){
  123 + $arr['total'] = $arr['month_total'];
  124 + }else{
  125 + $arr['total'] = $arr['month_total'] + ($previousInfo['total'] ?? 0);
  126 + }
  127 + $country = [];
  128 + if(isset($res['data']['data'])){
  129 + $country = $res['data']['data'];
  130 + }
  131 + $countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']);
  132 + foreach ($countryData as $v1){
  133 + if(isset($country[$v1['country']])){
  134 + $country[$v1['country']] += $v1['count'];
  135 + }else{
  136 + $country[$v1['country']] = $v1['count'];
  137 + }
  138 + }
  139 + $arr['country'] = json_encode($country);
  140 + $arr['month'] = $v['month'];
  141 + $arr = $this->pv_ip($arr,$start,$end,$project_id);
  142 + $arr = $this->sourceCount($arr,$start,$end);
  143 + if($info === false){
  144 + $selectedDate = $start;
  145 + $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
  146 + $arr['created_at'] = $firstDayOfNextMonth;
  147 + $arr['updated_at'] = $firstDayOfNextMonth;
  148 + $monthCountModel->insert($arr);
  149 + }else{
  150 + $monthCountModel->edit($arr,['id'=>$info['id']]);
  151 + }
  152 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  153 + }
  154 +
  155 + /**
  156 + * @remark :本月询盘总量
  157 + * @name :month_total
  158 + * @author :lyh
  159 + * @method :post
  160 + * @time :2024/1/8 11:02
  161 + */
  162 + public function pv_ip(&$arr,$start,$end,$project_id){
  163 + $pv_ip = DB::table('gl_count')
  164 + ->where(['project_id'=>$project_id])
  165 + ->where('date','>=',$start.' 00:00:00')
  166 + ->where('date','<=',$end.' 23:59:59')
  167 + ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'),DB::raw('SUM(inquiry_num) as inquiry_num'))
  168 + ->first();
  169 + $arr['pv'] = $pv_ip->pv_num;
  170 + $arr['ip'] = $pv_ip->ip_num;
  171 + if($arr['ip'] != 0){
  172 + $arr['rate'] = round((($arr['month_total'] ?? 0) / $arr['ip']) * 10,2);
  173 + }
  174 + return $arr;
  175 + }
  176 + /**
  177 + * @remark :来源访问前8
  178 + * @name :sourceCount
  179 + * @author :lyh
  180 + * @method :post
  181 + * @time :2023/6/30 16:14
  182 + */
  183 + public function sourceCount(&$arr,$startTime,$endTime){
  184 + //访问来源前10
  185 + $source = DB::connection('custom_mysql')->table('gl_customer_visit')
  186 + ->select('referrer_url', DB::raw('COUNT(*) as count'))
  187 + ->groupBy('referrer_url')
  188 + ->whereBetween('updated_date', [$startTime,$endTime])
  189 + ->orderByDesc('count')->limit(10)->get()->toArray();
  190 + $arr['source'] = json_encode($source);
  191 + //访问国家前15
  192 + $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
  193 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  194 + ->groupBy('country')
  195 + ->whereBetween('updated_date', [$startTime,$endTime])
  196 + ->orderBy('ip','desc')->limit(15)->get()->toArray();
  197 + $arr['source_country'] = json_encode($source_country);
  198 + //受访界面前15
  199 + $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
  200 + ->select('url',DB::raw('COUNT(*) as num'))
  201 + ->orderBy('num','desc')
  202 + ->whereBetween('updated_date', [$startTime,$endTime])
  203 + ->groupBy('url')
  204 + ->limit(15)->get()->toArray();
  205 + $arr['referrer_url'] = json_encode($referrer_url);
  206 + //访问端口
  207 + $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
  208 + ->select('device_port',DB::raw('COUNT(*) as num'))
  209 + ->orderBy('num','desc')
  210 + ->whereBetween('updated_date', [$startTime,$endTime])
  211 + ->groupBy('device_port')
  212 + ->limit(15)->get()->toArray();
  213 + $arr['referrer_port'] = json_encode($referrer_port);
  214 + return $arr;
  215 + }
  216 +
  217 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Task;
  4 +
  5 +
  6 +use App\Mail\TextMail;
  7 +use App\Models\Subscribe\GroupSendTask;
  8 +use App\Models\Subscribe\GroupSendTaskLog;
  9 +use App\Models\Subscribe\Smtp;
  10 +use Illuminate\Console\Command;
  11 +use Illuminate\Support\Facades\Config;
  12 +use Illuminate\Support\Facades\Mail;
  13 +
  14 +/**
  15 + *
  16 + * Class TaskDistribution
  17 + * @package App\Console\Commands
  18 + * @author zbj
  19 + * @date 2023/11/28
  20 + */
  21 +class EmailGroupSend extends Command
  22 +{
  23 +
  24 + protected $signature = 'email_group_send_task';
  25 + protected $description = '邮件群发任务';
  26 +
  27 + public function handle()
  28 + {
  29 + while (true) {
  30 + $tasks = GroupSendTask::where('status', GroupSendTask::STATUS_PENDING)->where('send_time', '<=', time())->get();
  31 + if (!$tasks->count()) {
  32 + sleep(10);
  33 + }
  34 + foreach ($tasks as $task) {
  35 + $this->toQueue($task);
  36 + }
  37 + }
  38 + }
  39 +
  40 + public function toQueue(GroupSendTask $task)
  41 + {
  42 + $this->output('开始执行任务:' . $task->id);
  43 + $smtp_config = Smtp::where('project_id', $task->project_id)->first();
  44 + if (!$smtp_config) {
  45 + $task->status = GroupSendTask::STATUS_ERROR;
  46 + $task->remark = '未配置SMTP';
  47 + $task->save();
  48 +
  49 + $this->output('任务:' . $task->id . '失败,未配置SMTP');
  50 + return false;
  51 + }
  52 + Config::set('mail.mailers.smtp.host', $smtp_config['host']);
  53 + Config::set('mail.mailers.smtp.username', $smtp_config['email']);
  54 + Config::set('mail.mailers.smtp.password', $smtp_config['password']);
  55 + Config::set('mail.from.address', $smtp_config['email']);
  56 + Config::set('mail.from.name', $smtp_config['from_name']);
  57 + foreach ($task->emails as $email) {
  58 + try {
  59 + Mail::to([$email])->send(new TextMail(['subject' => $task->subject, 'text' => $task->text]));
  60 + GroupSendTaskLog::addLog($task->id, $task->project_id, $smtp_config['email'], $email);
  61 + } catch (\Exception $e) {
  62 + GroupSendTaskLog::addLog($task->id, $task->project_id, $smtp_config['email'], $email, 2, $e->getMessage());
  63 + $this->output('任务:' . $task->id . ' 邮箱' . $email . '发送失败,' . $e->getMessage());
  64 + }
  65 + }
  66 + $task->status = GroupSendTask::STATUS_SUCCESS;
  67 + $task->save();
  68 + }
  69 +
  70 + /**
  71 + * 输出处理日志
  72 + */
  73 + public function output($message): bool
  74 + {
  75 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  76 + return true;
  77 + }
  78 +}
@@ -15,6 +15,7 @@ use App\Models\RouteMap\RouteMap; @@ -15,6 +15,7 @@ use App\Models\RouteMap\RouteMap;
15 use App\Models\User\ProjectMenu as ProjectMenuModel; 15 use App\Models\User\ProjectMenu as ProjectMenuModel;
16 use App\Models\User\ProjectRole as ProjectRoleModel; 16 use App\Models\User\ProjectRole as ProjectRoleModel;
17 use App\Models\User\User; 17 use App\Models\User\User;
  18 +use Illuminate\Database\Eloquent\Model;
18 use Illuminate\Support\Facades\Cache; 19 use Illuminate\Support\Facades\Cache;
19 20
20 /*** 21 /***
@@ -109,6 +110,10 @@ class ComController extends BaseController @@ -109,6 +110,10 @@ class ComController extends BaseController
109 if($projectCode != 1){ 110 if($projectCode != 1){
110 $info['role_menu'] = trim(str_replace(',50,',',',','.$info['role_menu'].','),','); 111 $info['role_menu'] = trim(str_replace(',50,',',',','.$info['role_menu'].','),',');
111 } 112 }
  113 + $is_subscribe = $this->getIsSubscribe();
  114 + if(!$is_subscribe){
  115 + $info['role_menu'] = trim(str_replace(',52,',',',','.$info['role_menu'].','),',');
  116 + }
112 $this->map = [ 117 $this->map = [
113 'status'=>0, 118 'status'=>0,
114 'is_role'=>0, 119 'is_role'=>0,
@@ -217,6 +222,11 @@ class ComController extends BaseController @@ -217,6 +222,11 @@ class ComController extends BaseController
217 return 0; 222 return 0;
218 } 223 }
219 224
  225 +
  226 + public function getIsSubscribe(){
  227 + return $this->project['is_subscribe'];
  228 + }
  229 +
220 /** 230 /**
221 * @name :登录用户编辑资料/修改密码 231 * @name :登录用户编辑资料/修改密码
222 * @author :liyuhang 232 * @author :liyuhang
@@ -26,6 +26,7 @@ class BaseController extends Controller @@ -26,6 +26,7 @@ class BaseController extends Controller
26 protected $map = [];//处理后的参数 26 protected $map = [];//处理后的参数
27 protected $uid = 0; 27 protected $uid = 0;
28 protected $user = [];//当前登录用户详情 28 protected $user = [];//当前登录用户详情
  29 + protected $project = [];//当前登录项目详情
29 /** 30 /**
30 * ceshi获取所有参数 31 * ceshi获取所有参数
31 */ 32 */
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Subscribe;
  4 +
  5 +
  6 +use App\Enums\Common\Code;
  7 +use App\Helper\Arr;
  8 +use App\Http\Controllers\Bside\BaseController;
  9 +use App\Http\Logic\Bside\Inquiry\InquiryLogic;
  10 +use App\Models\Inquiry\InquiryForm;
  11 +use App\Models\Subscribe\Email;
  12 +use App\Models\Subscribe\GroupSendTask;
  13 +use App\Models\Subscribe\Smtp;
  14 +use App\Rules\Ids;
  15 +use App\Services\BatchExportService;
  16 +use Illuminate\Http\Request;
  17 +use Illuminate\Support\Facades\Storage;
  18 +use Illuminate\Support\Str;
  19 +
  20 +/**
  21 + * 订阅邮件管理
  22 + * Class EmailController
  23 + * @package App\Http\Controllers\Bside\Subscribe
  24 + * @author zbj
  25 + * @date 2024/8/29
  26 + */
  27 +class EmailController extends BaseController
  28 +{
  29 +
  30 + public function list(Email $emailModel)
  31 + {
  32 + $lists = $emailModel->lists($this->map, $this->page, $this->row);
  33 + $this->response('success', Code::SUCCESS, $lists);
  34 + }
  35 +
  36 + public function delete(Email $emailModel)
  37 + {
  38 + $this->request->validate([
  39 + 'id' => 'required',
  40 + ], [
  41 + 'id.required' => 'id不为空',
  42 + ]);
  43 + $emailModel->del(['id' => $this->param['id']]);
  44 + $this->response('success');
  45 + }
  46 +
  47 +
  48 + public function export(Email $emailModel)
  49 + {
  50 + $data = $emailModel->list([], 'id', ['*'], 'desc', 1000);
  51 + //生成文件,发送到客户端
  52 + $map = [
  53 + 'email' => '邮箱',
  54 + 'created_at' => '订阅时间',
  55 + ];
  56 + $table = new BatchExportService("订阅邮箱导出");
  57 + $file = $table->head($map)->data($data)->save();
  58 + if (!$file) {
  59 + throw new \Exception('文件生成失败,请重试');
  60 + }
  61 + $fileurl = Storage::disk('runtime')->url($file);
  62 + $this->response('success', Code::SUCCESS, ['url' => $fileurl]);
  63 + }
  64 +
  65 +
  66 + public function set_smtp(Smtp $smtp)
  67 + {
  68 + $this->request->validate([
  69 + 'project_id' => ['required'],
  70 + 'email' => ['required', 'email', 'max:200'],
  71 + 'password' => ['required', 'max:200'],
  72 + 'host' => ['required', 'max:200', 'regex:/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/'],
  73 + 'from_name' => ['required', 'max:200'],
  74 + ], [
  75 + 'project_id.required' => '参数异常',
  76 + 'email.required' => '邮箱必须',
  77 + 'email.email' => '邮箱格式错误',
  78 + 'password.required' => '授权码/密码必须',
  79 + 'host.required' => 'smtp地址必须',
  80 + 'host.regex' => 'smtp格式错误',
  81 + 'from_name.required' => '发信人昵称必须',
  82 + ]);
  83 + $info = $smtp->read(['project_id' => $this->param['project_id']]);
  84 + if (!$info) {
  85 + $smtp->add($this->param);
  86 + } else {
  87 + $smtp->edit($this->param, ['project_id' => $this->param['project_id']]);
  88 + }
  89 + $this->response('success');
  90 + }
  91 +
  92 + public function group_send(GroupSendTask $groupSendTask)
  93 + {
  94 + $this->request->validate([
  95 + 'project_id' => ['required'],
  96 + 'emails' => ['required'],
  97 + 'subject' => ['required'],
  98 + 'text' => ['required'],
  99 + ], [
  100 + 'project_id.required' => '参数异常',
  101 + 'emails.required' => '发送对象必须',
  102 + 'subject.required' => '邮件主题必须',
  103 + 'host.required' => 'smtp地址必须',
  104 + ]);
  105 + if($this->param['send_time'] && !strtotime($this->param['send_time'])){
  106 + $this->fail('发送时间格式错误',Code::USER_ERROR);
  107 + }
  108 +
  109 + $smtp = new Smtp();
  110 + $info = $smtp->read(['project_id' => $this->param['project_id']]);
  111 + if(!$info){
  112 + $this->fail('请先设置SMTP',Code::USER_ERROR);
  113 + }
  114 +
  115 + $this->param['emails'] = Arr::a2s($this->param['emails']);
  116 + $this->param['send_time'] = empty($this->param['send_time']) ? 0 : strtotime($this->param['send_time']);
  117 + $this->param['user_id'] = $this->user['id'];
  118 + $groupSendTask->add($this->param);
  119 + $this->response('success');
  120 + }
  121 +}
@@ -191,6 +191,7 @@ class UserLoginLogic @@ -191,6 +191,7 @@ class UserLoginLogic
191 } 191 }
192 $info['is_visualization_authority'] = $project['deploy_build']['is_visualization_authority']; 192 $info['is_visualization_authority'] = $project['deploy_build']['is_visualization_authority'];
193 $info['is_inquiry_country'] = $project['is_inquiry_country']; 193 $info['is_inquiry_country'] = $project['is_inquiry_country'];
  194 + $info['is_subscribe'] = $project['is_subscribe'];
194 //是否开通AMP 195 //是否开通AMP
195 $is_amp = 0; 196 $is_amp = 0;
196 if(!empty($project['deploy_optimize']['domain'])){ 197 if(!empty($project['deploy_optimize']['domain'])){
@@ -299,6 +300,7 @@ class UserLoginLogic @@ -299,6 +300,7 @@ class UserLoginLogic
299 } 300 }
300 $info['is_visualization_authority'] = $project['deploy_build']['is_visualization_authority']; 301 $info['is_visualization_authority'] = $project['deploy_build']['is_visualization_authority'];
301 $info['is_inquiry_country'] = $project['is_inquiry_country']; 302 $info['is_inquiry_country'] = $project['is_inquiry_country'];
  303 + $info['is_subscribe'] = $project['is_subscribe'];
302 //是否开通AMP 304 //是否开通AMP
303 $is_amp = 0; 305 $is_amp = 0;
304 if(!empty($project['deploy_optimize']['domain'])){ 306 if(!empty($project['deploy_optimize']['domain'])){
  1 +<?php
  2 +
  3 +namespace App\Mail;
  4 +
  5 +use Illuminate\Bus\Queueable;
  6 +use Illuminate\Contracts\Queue\ShouldQueue;
  7 +use Illuminate\Mail\Mailable;
  8 +use Illuminate\Queue\SerializesModels;
  9 +
  10 +class TextMail extends Mailable
  11 +{
  12 + use Queueable, SerializesModels;
  13 +
  14 + protected string $text;
  15 +
  16 + /**
  17 + * Create a new message instance.
  18 + *
  19 + * @return void
  20 + */
  21 + public function __construct($data)
  22 + {
  23 + $this->subject = $data['subject'];
  24 + $this->text = $data['text'];
  25 + }
  26 +
  27 + /**
  28 + * Build the message.
  29 + *
  30 + * @return $this
  31 + */
  32 + public function build()
  33 + {
  34 + return $this->subject($this->subject)->view('mail.text', ['text' => $this->text]);
  35 + }
  36 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Subscribe;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +/**
  8 + * Class Email
  9 + * @package App\Models\Subscribe
  10 + * @author zbj
  11 + * @date 2024/8/27
  12 + */
  13 +class Email extends Base
  14 +{
  15 + use SoftDeletes;
  16 +
  17 + //设置关联表名
  18 + /**
  19 + * @var mixed
  20 + */
  21 + protected $connection = "custom_mysql";
  22 + protected $table = 'gl_subscribe_email';
  23 +
  24 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Subscribe;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\Base;
  7 +use Illuminate\Database\Eloquent\SoftDeletes;
  8 +/**
  9 + * Class GroupSendTask
  10 + * @package App\Models\Subscribe
  11 + * @author zbj
  12 + * @date 2024/8/27
  13 + */
  14 +class GroupSendTask extends Base
  15 +{
  16 + use SoftDeletes;
  17 +
  18 + const STATUS_PENDING = 0;
  19 + const STATUS_QUEUE = 1;
  20 + const STATUS_SUCCESS = 2;
  21 + const STATUS_ERROR = 9;
  22 +
  23 +
  24 + //设置关联表名
  25 + /**
  26 + * @var mixed
  27 + */
  28 + protected $table = 'gl_email_group_send_task';
  29 +
  30 +// public function setEmailsAttribute($value){
  31 +// $this->attributes['emails'] = Arr::a2s($value);
  32 +// }
  33 +
  34 + public function getEmailsAttribute($value){
  35 + return Arr::s2a($value);
  36 + }
  37 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Subscribe;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +/**
  8 + * Class GroupSendTaskLog
  9 + * @package App\Models\Subscribe
  10 + * @author zbj
  11 + * @date 2024/8/27
  12 + */
  13 +class GroupSendTaskLog extends Base
  14 +{
  15 + use SoftDeletes;
  16 +
  17 + //设置关联表名
  18 + /**
  19 + * @var mixed
  20 + */
  21 + protected $table = 'gl_email_group_send_task_log';
  22 +
  23 +
  24 + //`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  25 + // `task_id` int(11) unsigned NOT NULL DEFAULT '0',
  26 + // `project_id` int(11) unsigned NOT NULL DEFAULT '0',
  27 + // `from` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  28 + // `to` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  29 + // `status` tinyint(1) unsigned NOT NULL DEFAULT '0',
  30 + // `manage_id` int(11) unsigned NOT NULL DEFAULT '0',
  31 + // `created_at` datetime NOT NULL,
  32 + // `updated_at` datetime NOT NULL,
  33 + // `deleted_at` datetime DEFAULT NULL,
  34 + // `remark` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  35 +
  36 + public static function addLog($task_id, $project_id, $from, $to, $status = 1, $remark = '')
  37 + {
  38 + $model = new self();
  39 + $model->task_id = $task_id;
  40 + $model->project_id = $project_id;
  41 + $model->from = $from;
  42 + $model->to = $to;
  43 + $model->status = $status;
  44 + $model->remark = $remark;
  45 + $model->save();
  46 + }
  47 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Subscribe;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +/**
  8 + * Class Smtp
  9 + * @package App\Models\Subscribe
  10 + * @author zbj
  11 + * @date 2024/8/27
  12 + */
  13 +class Smtp extends Base
  14 +{
  15 + use SoftDeletes;
  16 +
  17 + //设置关联表名
  18 + /**
  19 + * @var mixed
  20 + */
  21 + protected $table = 'gl_email_smtp';
  22 +
  23 +}
@@ -8,8 +8,10 @@ use App\Models\Inquiry\InquiryForm; @@ -8,8 +8,10 @@ use App\Models\Inquiry\InquiryForm;
8 use App\Models\Inquiry\InquiryFormData; 8 use App\Models\Inquiry\InquiryFormData;
9 use App\Models\Project\InquiryFilterConfig; 9 use App\Models\Project\InquiryFilterConfig;
10 use App\Models\Project\Project; 10 use App\Models\Project\Project;
  11 +use App\Models\Subscribe\Email;
11 use App\Models\SyncSubmitTask\SyncSubmitTask; 12 use App\Models\SyncSubmitTask\SyncSubmitTask;
12 use App\Models\Visit\Visit; 13 use App\Models\Visit\Visit;
  14 +use App\Utils\LogUtils;
13 use Illuminate\Support\Facades\Http; 15 use Illuminate\Support\Facades\Http;
14 use Illuminate\Support\Facades\URL; 16 use Illuminate\Support\Facades\URL;
15 use Illuminate\Support\Str; 17 use Illuminate\Support\Str;
@@ -52,6 +54,20 @@ class SyncSubmitTaskService @@ -52,6 +54,20 @@ class SyncSubmitTaskService
52 } 54 }
53 55
54 $action = $task['type']; 56 $action = $task['type'];
  57 +
  58 + //是否是订阅邮箱
  59 + if($action == 'inquiry' && !empty($project['is_subscribe'])){
  60 + //是否只有email字段
  61 + $filed = '';
  62 + foreach ($data['data']['data'] as $k => $v){
  63 + if(Str::startsWith(strtolower($k),'globalso-')){
  64 + continue;
  65 + }
  66 + $filed .= $k;
  67 + }
  68 + $filed == 'email' && $action = 'subscribe';
  69 + }
  70 +
55 $handler = new self(); 71 $handler = new self();
56 return $handler->$action($data, $date); 72 return $handler->$action($data, $date);
57 } 73 }
@@ -75,7 +91,25 @@ class SyncSubmitTaskService @@ -75,7 +91,25 @@ class SyncSubmitTaskService
75 return $referer; 91 return $referer;
76 } 92 }
77 93
78 - 94 + /**
  95 + *
  96 + * 订阅邮箱
  97 + * @param $data
  98 + * @param $date
  99 + * @throws InquiryFilterException
  100 + * @author zbj
  101 + * @date 2024/8/27
  102 + */
  103 + public function subscribe($data, $date){
  104 + $email = $data['data']['data']['email'];
  105 + if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  106 + $model = new Email();
  107 + $model->email = $email;
  108 + $model->save();
  109 + }else{
  110 + throw new InquiryFilterException( '邮箱格式异常:' . $email);
  111 + }
  112 + }
79 113
80 /** 114 /**
81 * 询盘 115 * 询盘
@@ -87,7 +121,6 @@ class SyncSubmitTaskService @@ -87,7 +121,6 @@ class SyncSubmitTaskService
87 */ 121 */
88 public function inquiry($data, $date) 122 public function inquiry($data, $date)
89 { 123 {
90 -  
91 $this->inquiryFilter($data['project_id'], $data); 124 $this->inquiryFilter($data['project_id'], $data);
92 125
93 //数组key转为小写 126 //数组key转为小写
@@ -608,6 +608,15 @@ Route::middleware(['bloginauth'])->group(function () { @@ -608,6 +608,15 @@ Route::middleware(['bloginauth'])->group(function () {
608 Route::any('/getInfo', [\App\Http\Controllers\Bside\BCom\OperationHeartbeatController::class, 'getInfo'])->name('operation_heartbeat_getInfo'); 608 Route::any('/getInfo', [\App\Http\Controllers\Bside\BCom\OperationHeartbeatController::class, 'getInfo'])->name('operation_heartbeat_getInfo');
609 609
610 }); 610 });
  611 +
  612 + //订阅邮件管理
  613 + Route::prefix('subscribe')->group(function () {
  614 + Route::any('/', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'list'])->name('subscribe_email_list');
  615 + Route::any('/del', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'delete'])->name('subscribe_email_del');
  616 + Route::any('/export', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'export'])->name('subscribe_email_export');
  617 + Route::any('/set_smtp', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'set_smtp'])->name('subscribe_email_set_smtp');
  618 + Route::any('/group_send', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'group_send'])->name('subscribe_email_group_send');
  619 + });
611 }); 620 });
612 //无需登录验证的路由组 621 //无需登录验证的路由组
613 Route::group([], function () { 622 Route::group([], function () {