rabin 13 годин тому
батько
коміт
e8e7750e7d

+ 2 - 2
api/Task.php → app/Api/Task.php

@@ -8,7 +8,7 @@ class Task
         # 删除1个月前的数据
         list($start, $end) = Date::month(1);
         $where['cdate'] = ['<=', $end];
-        Dever::db('code', 'sms')->delete($where);
-        Dever::db('notify', 'sms')->delete($where);
+        Dever::db('sms/code')->delete($where);
+        Dever::db('smg/notify')->delete($where);
     }
 }

+ 2 - 2
lib/Manage.php → app/Lib/Manage.php

@@ -5,7 +5,7 @@ class Manage
     # 发送消息
     public function showRecord($id, $type = 'code')
     {
-        $info = Dever::db('code', 'msg')->find($id);
+        $info = Dever::db('msg/code')->find($id);
         if (is_object($info['record'])) {
             $info['record'] = (array)$info['record'];
         }
@@ -21,7 +21,7 @@ class Manage
     public function getTemplateName($id, $name = '')
     {
         if ($id) {
-            $info = Dever::db('template', 'msg')->find($id);
+            $info = Dever::db('msg/template')->find($id);
             return $info['name'];
         }
         return $name;

+ 1 - 1
lib/Method/Email.php → app/Lib/Method/Email.php

@@ -17,7 +17,7 @@ class Email
         if ($project != 'api') {
             $msg = $project;
         }
-        $this->config = Dever::db('account_email', $msg)->find(['account_id' => $config_id]);
+        $this->config = Dever::db($msg . '/account_email')->find(['account_id' => $config_id]);
         if (!$this->config) {
             Dever::error('邮件配置不存在');
         }

+ 3 - 2
lib/Method/Sms.php → app/Lib/Method/Sms.php

@@ -1,5 +1,6 @@
 <?php namespace Msg\Lib\Method;
 use Dever;
+use Api\Lib\Account;
 class Sms
 {
     private $config;
@@ -14,7 +15,7 @@ class Sms
         if ($project != 'api') {
             $msg = $project;
         }
-        $this->config = Dever::db('account_sms', $msg)->find(['account_id' => $config_id, 'template_id' => $template_id]);
+        $this->config = Dever::db($msg . '/account_sms')->find(['account_id' => $config_id, 'template_id' => $template_id]);
         if (!$this->config) {
             Dever::error('短信配置不存在');
         }
@@ -33,7 +34,7 @@ class Sms
         $send['TemplateCode'] = $this->config['code'];
         $send['TemplateParam'] = $param;
         $send['log'] = true;
-        $result = Dever::load('account', 'api')->run($api, 'send_sms', $send, 1, 'run', $this->config['project']);
+        $result = Dever::load(Account::class)->run($api, 'send_sms', $send, 1, 'run', $this->config['project']);
         return Dever::json_encode($result);
     }
 }

+ 3 - 2
lib/Method/Wechat_applet.php → app/Lib/Method/WechatApplet.php

@@ -1,5 +1,6 @@
 <?php namespace Msg\Lib\Method;
 use Dever;
+use Api\Lib\Account;
 class Wechat_applet
 {
     private $config;
@@ -14,7 +15,7 @@ class Wechat_applet
         if ($project != 'api') {
             $msg = $project;
         }
-        $this->config = Dever::db('account_wechat', $msg)->find(['account_id' => $config_id, 'template_id' => $template_id]);
+        $this->config = Dever::db($msg . '/account_wechat')->find(['account_id' => $config_id, 'template_id' => $template_id]);
         if (!$this->config) {
             Dever::error('小程序配置不存在');
         }
@@ -38,7 +39,7 @@ class Wechat_applet
         $send['page'] = $param['page'] ?? '';
         $send['data'] = $data;
         $send['log'] = true;
-        $result = Dever::load('account', 'api')->run($api, 'applet_send', $send, 1, 'run', $this->config['project']);
+        $result = Dever::load(Account::class)->run($api, 'applet_send', $send, 1, 'run', $this->config['project']);
         return Dever::json_encode($result);
     }
 }

+ 2 - 2
lib/Method/Wechat_service.php → app/Lib/Method/WechatService.php

@@ -14,7 +14,7 @@ class Wechat_service
         if ($project != 'api') {
             $msg = $project;
         }
-        $this->config = Dever::db('account_wechat', $msg)->find(['account_id' => $config_id, 'template_id' => $template_id]);
+        $this->config = Dever::db($msg . '/account_wechat')->find(['account_id' => $config_id, 'template_id' => $template_id]);
         if (!$this->config) {
             Dever::error('公众号配置不存在');
         }
@@ -38,7 +38,7 @@ class Wechat_service
         $send['url'] = $param['url'] ?? '';
         $send['data'] = $data;
         $send['log'] = true;
-        $result = Dever::load('account', 'api')->run($api, 'service_send', $send, 1, 'run', $this->config['project']);
+        $result = Dever::load(Account::class)->run($api, 'service_send', $send, 1, 'run', $this->config['project']);
         return Dever::json_encode($result);
     }
 }

+ 51 - 0
app/Lib/Template.php

@@ -0,0 +1,51 @@
+<?php namespace Msg\Lib;
+use Dever;
+use Msg\Lib\Type\Notify;
+use Msg\Lib\Type\Code;
+class Template
+{
+    # 获取通知方式
+    public function method()
+    {
+        $value = [
+            'Letter' => '站内信',
+            'Sms' => '短信',
+            'WechatService' => '微信公众号模板消息',
+            'WechatApplet' => '微信小程序订阅消息',
+            //'App' => 'APP推送',
+            //'Email' => '邮箱',
+        ];
+        return $value;
+    } 
+
+    # 发送消息
+    public function send($template, $account = [], $param = [], $project = 'api')
+    {
+        $template = Dever::db('msg/template')->find(['key' => $template, 'status' => 1]);
+        if (!$template) {
+            Dever::error('消息模板不存在');
+        }
+        if ($template['type'] == 1) {
+            $method = Notify::class;
+        } elseif ($template['type'] == 2) {
+            $method = Code::class;
+        }
+        $template['method'] = explode(',', $template['method']);
+        return Dever::load($method)->send($template, $account, $param, $project);
+    }
+
+    # 验证码检查
+    public function check($template, $account, $code, $update = 1)
+    {
+        $template = Dever::db('msg/template')->find(['key' => $template, 'status' => 1]);
+        if (!$template) {
+            Dever::error('消息模板不存在');
+        }
+        if ($template['type'] == 2) {
+            $state = Dever::load(Code::class)->check($template['id'], $account, $code, $update);
+            if (!$state) {
+                Dever::error('验证码错误');
+            }
+        }
+    }
+}

+ 10 - 9
lib/Type/Code.php → app/Lib/Type/Code.php

@@ -1,5 +1,6 @@
 <?php namespace Msg\Lib\Type;
 use Dever;
+use Api\Lib\Account;
 class Code
 {
     private $config;
@@ -9,7 +10,7 @@ class Code
         $data['template_id'] = $template['id'];
         $data['day'] = date('Ymd', DEVER_TIME);
         if (empty($param['code'])) {
-            $this->config = Dever::db('template_code', 'msg')->find(['template_id' => $template['id']]);
+            $this->config = Dever::db('msg/template_code')->find(['template_id' => $template['id']]);
             if (!$this->config) {
                 Dever::error('验证码未配置');
             }
@@ -20,19 +21,19 @@ class Code
         }
         $test = 1;
         foreach ($template['method'] as $k => $v) {
-            $config = Dever::db('account', 'msg')->find(['method' => $v]);
+            $config = Dever::db('msg/account')->find(['method' => $v]);
             if ($config) {
-                $handle = Dever::load('method/' . $config['method'], 'msg');
+                $handle = Dever::load('\\Msg\\Lib\\Method\\' . $config['method']);
                 $data['account'] = $handle->init($template['id'], $config['id'], $account, $project);
                 $this->valid($data);
                 if ($config['test'] == 2) {
                     $test = 2;
-                    $api = Dever::load('account', 'api')->get($config['api_account_id'], $project);
+                    $api = Dever::load(Account::class)->get($config['api_account_id'], $project);
                     $data['record'] = $handle->send($api, $template['content'], $param);
                 }
                 $data['code'] = $param['code'];
                 $data['status'] = 1;
-                Dever::db('code', 'msg')->insert($data);
+                Dever::db('msg/code')->insert($data);
                 # 这里以后加入计费机制
             }
         }
@@ -46,10 +47,10 @@ class Code
     # 检测并使用验证码
     public function check($template_id, $account, $code, $update = 1)
     {
-        $info = Dever::db('code', 'msg')->find(['template_id' => $template_id, 'account' => $account], ['order' => 'cdate desc']);
+        $info = Dever::db('msg/code')->find(['template_id' => $template_id, 'account' => $account], ['order' => 'cdate desc']);
         if ($info && $info['status'] == 1 && $code == $info['code']) {
             if ($update == 1) {
-                Dever::db('code', 'msg')->update($info['id'], ['status' => 2]);
+                Dever::db('msg/code')->update($info['id'], ['status' => 2]);
             }
             return true;
         }
@@ -65,11 +66,11 @@ class Code
 
     protected function valid($where)
     {
-        $info = Dever::db('code', 'msg')->find($where);
+        $info = Dever::db('msg/code')->find($where);
         if ($info) {
             if (DEVER_TIME - $this->config['cdate'] < $this->config['interval']) {
                 Dever::error('请不要在'.$this->config['interval'].'秒之内申请多次验证码,请您稍后再试');
-            } elseif (Dever::db('code', 'msg')->count($where) >= $this->config['total']) {
+            } elseif (Dever::db('msg/code')->count($where) >= $this->config['total']) {
                 Dever::error('很抱歉,您已经申请获取验证码超过' . $this->config['total'] . '次,今天您已经无法获取验证码了,请您明天再来');
             }
         }

+ 5 - 4
lib/Type/Notify.php → app/Lib/Type/Notify.php

@@ -1,5 +1,6 @@
 <?php namespace Msg\Lib\Type;
 use Dever;
+use Api\Lib\Account;
 class Notify
 {
     # 发送通知
@@ -9,16 +10,16 @@ class Notify
             $template['content'] = \Dever\Helper\Str::val($template['content'], $param);
         }
         foreach ($template['method'] as $k => $v) {
-            $config = Dever::db('account', 'msg')->find(['method' => $v]);
+            $config = Dever::db('msg/account')->find(['method' => $v]);
             if ($config) {
-                $handle = Dever::load('method/' . $config['method'], 'msg');
+                $handle = Dever::load('\\Msg\\Lib\\Method\\' . $config['method']);
                 $data['account'] = $handle->init($template['id'], $config['id'], $account, $project);
                 if ($config['test'] == 2) {
-                    $api = Dever::load('account', 'api')->get($config['api_account_id'], $project);
+                    $api = Dever::load(Account::class)->get($config['api_account_id'], $project);
                     $data['record'] = $handle->send($api, $template['content'], $param);
                 }
                 $data['content'] = $template['content'];
-                Dever::db('notify', 'msg')->insert($data);
+                Dever::db('msg/notify')->insert($data);
             }
         }
         return '通知发送成功';

+ 1 - 1
index.php

@@ -1,5 +1,5 @@
 <?php
-define('DEVER_APP_NAME', 'msg');
+define('DEVER_APP_NAME', 'Msg');
 define('DEVER_APP_LANG', '消息管理');
 define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
 include(DEVER_APP_PATH . '../../boot.php');

+ 0 - 50
lib/Template.php

@@ -1,50 +0,0 @@
-<?php namespace Msg\Lib;
-use Dever;
-class Template
-{
-    # 获取通知方式
-    public function method()
-    {
-        $value = [
-            ['id' => 'letter', 'name' => '站内信'],
-            ['id' => 'sms', 'name' => '短信'],
-            ['id' => 'wechat_service', 'name' => '微信公众号模板消息'],
-            ['id' => 'wechat_applet', 'name' => '微信小程序订阅消息'],
-            //['id' => 'app', 'name' => 'APP推送'],
-
-            //['id' => 'email', 'name' => '邮箱'],
-        ];
-        return $value;
-    } 
-
-    # 发送消息
-    public function send($template, $account = [], $param = [], $project = 'api')
-    {
-        $template = Dever::db('template', 'msg')->find(['key' => $template, 'status' => 1]);
-        if (!$template) {
-            Dever::error('消息模板不存在');
-        }
-        if ($template['type'] == 1) {
-            $method = 'notify';
-        } elseif ($template['type'] == 2) {
-            $method = 'code';
-        }
-        $template['method'] = explode(',', $template['method']);
-        return Dever::load('type/' . $method, 'msg')->send($template, $account, $param, $project);
-    }
-
-    # 验证码检查
-    public function check($template, $account, $code, $update = 1)
-    {
-        $template = Dever::db('template', 'msg')->find(['key' => $template, 'status' => 1]);
-        if (!$template) {
-            Dever::error('消息模板不存在');
-        }
-        if ($template['type'] == 2) {
-            $state = Dever::load('type/code', 'msg')->check($template['id'], $account, $code, $update);
-            if (!$state) {
-                Dever::error('验证码错误');
-            }
-        }
-    }
-}

+ 10 - 10
manage/account.php

@@ -20,8 +20,8 @@ $config = [
         ],
         'data_button' => [
             '设置' => ['fastedit', 'name,method,api_account_id,msg/account_email'],
-            '短信模板' => ['fastedit', 'msg/account_sms,tip', '', 'method=sms'],
-            '微信模板' => ['fastedit', 'msg/account_wechat,tip', '', 'method=wechat_service,wechat_applet'],
+            '短信模板' => ['fastedit', 'msg/account_sms,tip', '', 'method=Sms'],
+            '微信模板' => ['fastedit', 'msg/account_wechat,tip', '', 'method=WechatService,WechatApplet'],
         ],
         'search' => [
             'name',
@@ -44,10 +44,10 @@ $config = [
         ],
         'control' => [
             'msg/account_email' => [
-                'method' => ['email'],
+                'method' => ['Email'],
             ],
             'api_account_id' => [
-                'method' => ['sms', 'wechat_service', 'wechat_applet', 'app'],
+                'method' => ['Sms', 'WechatService', 'WechatApplet', 'App'],
             ],
         ],
     ],
@@ -56,8 +56,8 @@ $config = [
 $id = Dever::input('id');
 if ($id > 0) {
     $default = [];
-    $info = Dever::db('account', 'msg')->find($id);
-    $template = Dever::db('template', 'msg')->select(['method' => ['like', $info['method']]]);
+    $info = Dever::db('msg/account')->find($id);
+    $template = Dever::db('msg/template')->select(['method' => ['like', $info['method']]]);
     if ($template) {
         foreach ($template as $v) {
             $default[] = [
@@ -65,13 +65,13 @@ if ($id > 0) {
                 'template_name' => $v['name'],
             ];
         }
-        if ($info['method'] == 'sms') {
+        if ($info['method'] == 'Sms') {
             $config['update']['field']['msg/account_sms'] = [
                 'name' => '短信模板',
                 'where'  => ['account_id' => 'id'],
                 'default' => $default,
             ];
-        } elseif (strstr($info['method'], 'wechat')) {
+        } elseif (strstr($info['method'], 'Wechat')) {
             $config['update']['field']['msg/account_wechat'] = [
                 'name' => '微信模板',
                 'where'  => ['account_id' => 'id'],
@@ -79,13 +79,13 @@ if ($id > 0) {
             ];
         }
     } else {
-        if ($info['method'] == 'sms') {
+        if ($info['method'] == 'Sms') {
             $config['update']['field']['tip'] = [
                 'name' => '短信模板',
                 'type' => 'show',
                 'default' => '暂无短信模板,请在消息模板中选择',
             ];
-        } elseif (strstr($info['method'], 'wechat')) {
+        } elseif (strstr($info['method'], 'Wechat')) {
             $config['update']['field']['tip'] = [
                 'name' => '微信模板',
                 'type' => 'show',

+ 1 - 1
manage/account_sms.php

@@ -8,7 +8,7 @@ return [
             'template_name' => [
                 'type' => 'show',
                 'name' => '消息模板',
-                'default'  => 'Dever::call("msg/manage.getTemplateName", [{template_id}, "{template_name}"])',
+                'default'  => 'Dever::call("Msg/Lib/Manage.getTemplateName", [{template_id}, "{template_name}"])',
             ],
             'code' => [
                 'tip' => '填写短信模板编码,阿里云短信需要模板编码',

+ 1 - 1
manage/account_wechat.php

@@ -8,7 +8,7 @@ return [
             'template_name' => [
                 'type' => 'show',
                 'name' => '消息模板',
-                'default'  => 'Dever::call("msg/manage.getTemplateName", [{template_id}, "{template_name}"])',
+                'default'  => 'Dever::call("Msg/Lib/Manage.getTemplateName", [{template_id}, "{template_name}"])',
             ],
             'code' => [
                 'tip' => '填写微信模板ID',

+ 1 - 1
manage/code.php

@@ -11,7 +11,7 @@ return [
                 'type' => 'popover',
                 'title' => '查看',
                 'location' => 'left',
-                'show' => 'Dever::load("msg/manage")->showRecord("{id}")',
+                'show' => 'Dever::load("Msg/Lib/Manage")->showRecord("{id}")',
             ],
             'status',
             'cdate',

+ 2 - 2
table/account.php

@@ -11,8 +11,8 @@ return [
         'method'      => [
             'type'      => 'varchar(100)',
             'name'      => '账户功能',
-            'default'   => 'sms',
-            'value'    => 'Dever::call("msg/template.method")',
+            'default'   => 'Sms',
+            'value'    => 'Dever::call("Msg/Lib/Template.method")',
         ],
 
         'api_account_id'      => [

+ 1 - 1
table/code.php

@@ -1,7 +1,7 @@
 <?php
 return [
     'name' => '验证码',
-    'partition' => 'Dever::call("manage/util.system")',
+    'partition' => 'Dever::call("Manage/Lib/Util.system")',
     'order' => 'cdate desc',
     'struct' => [
         'template_id'        => [

+ 1 - 1
table/notify.php

@@ -1,7 +1,7 @@
 <?php
 return [
     'name' => '通知记录',
-    'partition' => 'Dever::call("manage/util.system")',
+    'partition' => 'Dever::call("Manage/Lib/Util.system")',
     'struct' => [
         'template_id'        => [
             'type'      => 'int(11)',

+ 1 - 1
table/template.php

@@ -32,7 +32,7 @@ return [
             'type'      => 'varchar(100)',
             'name'      => '通知方式',
             'default'   => '',
-            'value'    => 'Dever::call("msg/template.method")',
+            'value'    => 'Dever::call("Msg/Lib/Template.method")',
         ],
 
         'content'      => [