zory 3 주 전
부모
커밋
30c96d0f94
5개의 변경된 파일236개의 추가작업 그리고 12개의 파일을 삭제
  1. 31 0
      app/controller/common/Common.php
  2. 150 0
      app/extra/basic/Base.php
  3. 0 12
      config/translation.php
  4. 3 0
      resource/translations/en/messages.php
  5. 52 0
      resource/translations/zh_CN/messages.php

+ 31 - 0
app/controller/common/Common.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace app\controller\common;
+
+use app\extra\basic\Base;
+use LinFly\Annotation\Route\Controller;
+use LinFly\Annotation\Route\Middleware;
+use LinFly\Annotation\Route\Route;
+use support\Response;
+
+/**
+ *
+ */
+#[Controller(prefix: "/api/service")]
+class Common extends Base
+{
+
+    /**
+     *
+     */
+    #[Route(path: "data",methods: "get")]
+    public function getServiceData(): Response
+    {
+        try {
+            return successTrans("success",[]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 150 - 0
app/extra/basic/Base.php

@@ -0,0 +1,150 @@
+<?php
+
+namespace app\extra\basic;
+
+use Overtrue\EasySms\Strategies\OrderStrategy;
+use think\Validate;
+
+class Base
+{
+
+    protected array $mobileWhite = ["18665619195","18665619196","18665619198","18665619199"];
+
+    protected function getParent(array $data)
+    {
+        if ($data['parent_id'] > 0) {
+            return $data['parent_id'];
+        }
+        return $data['user_id'];
+    }
+
+    public function getShopId()
+    {
+        return request()->header("shop",0);
+    }
+
+    public function getAccountId(array $data)
+    {
+        return $data['account_id'];
+    }
+
+    protected function getSmsChannel(): array
+    {
+        return [
+            [
+                "name"  => "阿里云",
+                "type"  => "aliyun",
+                "url"   => "https://dysms.console.aliyun.com/dysms.htm"
+            ],
+            [
+                "name"  => "腾讯云",
+                "type"  => "qcloud",
+                "url"   => "https://console.cloud.tencent.com/smsv2"
+            ],
+            [
+                "name"  => "七牛云",
+                "type"  => "qiniu",
+                "url"   => "https://portal.qiniu.com/sms/dashboard"
+            ]
+        ];
+    }
+
+    /**
+     * 短信配置
+     * @return array
+     */
+    protected function getSmsConfig(): array
+    {
+        $sms = sysconf('sms.');
+        return [
+            'enable' => true,
+            'timeout' => 5.0,
+            "default"   => [
+                "strategy"  => OrderStrategy::class,
+                "gateways"  => [$sms['sms_type']]
+            ],
+            "gateways"  => [
+                'errorlog' => [
+                    'file' => runtime_path().'/tmp/easy-sms.log',
+                ],
+                'aliyun' => [
+                    'access_key_id' => $sms['AccessKeyId'],
+                    'access_key_secret' => $sms['AccessKeySecret'],
+                    'sign_name' => trim($sms['sign']),
+                ],
+            ]
+        ];
+    }
+
+    /**
+     *  快捷输入并验证( 支持 规则 # 别名 )
+     * @param array $rules 验证规则( 验证信息数组 )
+     * @param array|string $input 输入方式 ( post. 或 get. )
+     * @param callable|null $callable 异常处理操作
+     */
+    protected function _valid(array $rules, array|string $input = '', ?callable $callable = null)
+    {
+        if (is_string($input)) {
+            $type = trim($input, '.') ?: 'get';
+            $input = request()->$type();
+        }
+        [$data, $rule, $info] = [[], [], []];
+        foreach ($rules as $name => $message) if (is_numeric($name)) {
+            [$name, $alias] = explode('#', $message . '#');
+            $data[$name] = $input[($alias ?: $name)] ?? null;
+        } elseif (!str_contains($name, '.')) {
+            $data[$name] = $message;
+        } elseif (preg_match('|^(.*?)\.(.*?)#(.*?)#?$|', $name . '#', $matches)) {
+            [, $_key, $_rule, $alias] = $matches;
+            if (in_array($_rule, ['value', 'default'])) {
+                if ($_rule === 'value') $data[$_key] = $message;
+                elseif ($_rule === 'default') $data[$_key] = $input[($alias ?: $_key)] ?? $message;
+            } else {
+                $info[explode(':', $name)[0]] = $message;
+                $data[$_key] = $data[$_key] ?? ($input[($alias ?: $_key)] ?? null);
+                $rule[$_key] = isset($rule[$_key]) ? ($rule[$_key] . '|' . $_rule) : $_rule;
+            }
+        }
+        $validate = new Validate();
+        if ($validate->rule($rule)->message($info)->check($data)) {
+            return $data;
+        } elseif (is_callable($callable)) {
+            return call_user_func($callable, $validate->getError(), $data);
+        } else {
+            return $validate->getError();
+        }
+    }
+
+
+    /**
+     * 菜单信息格式化
+     * @param array $menus
+     * @param int $type
+     * @return array
+     */
+    protected function filterMenu(array $menus,int $type,int $mch = 0): array
+    {
+        foreach ($menus as &$menu) {
+            $menu['meta'] = [
+                "title"     => $menu['title'],
+                "icon"      => $menu['icon']??'',
+                "type"      => $menu['type'],
+                "desc"      => $menu['descs'],
+            ];
+            if (!empty($menu['children'])) {
+                $menu['children'] = $this->filterMenu($menu['children'],$type,$mch);
+            }
+            if ($mch > 0) {
+                $menu['component'] = ($mch==1?'merchant/':'store/').$menu['name'];
+            } else {
+                $menu['component'] = $menu['name'];
+            }
+            $menu['isMenu'] = $menu['status'];
+            if($type == 1) unset($menu['title'],$menu['icon'],$menu['type'],$menu['pid'],$menu['id']);
+        }
+        return $menus;
+    }
+
+
+
+}

+ 0 - 12
config/translation.php

@@ -1,16 +1,4 @@
 <?php
-/**
- * This file is part of webman.
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the MIT-LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @author    walkor<walkor@workerman.net>
- * @copyright walkor<walkor@workerman.net>
- * @link      http://www.workerman.net/
- * @license   http://www.opensource.org/licenses/mit-license.php MIT License
- */
 
 /**
  * Multilingual configuration

+ 3 - 0
resource/translations/en/messages.php

@@ -0,0 +1,3 @@
+<?php
+
+return [];

+ 52 - 0
resource/translations/zh_CN/messages.php

@@ -0,0 +1,52 @@
+<?php
+
+
+return [
+    40001 => '请输入登录账号',
+    40002 => '请输入登录密码',
+    40003 => '登录账号不存在',
+    40004 => '您已被禁止登录,请联系管理员',
+    40005 => '此账号已被封禁,无法操作',
+    40006 => '账号或密码错误',
+    40007 => '登录成功',
+    400017 => '注册成功,正在跳转登录',
+    40008 => '登录已过期,请重新登录',
+    40009 => '登录状态有误,请重新登录',
+    40010 => '上传失败',
+    40011 => '权限已到期,请联系管理员',
+    40012 => '该来客账户ID已添加,请勿重复操作',
+    40013 => '该AppId已添加,请勿重复操作',
+    40014 => '该POI已添加,请勿重复操作',
+    40015 => '门店数据不存在',
+    40035 => '不合法的参数',
+    40038 => '不合法的请求格式',
+
+    "error"     => '操作失败',
+    "success"   => "操作成功",
+    "empty"     => "数据不存在",
+
+    20010 => "参数格式错误",
+    20011 => "当前设定账号已存在,请更换",
+    20012 => "该手机号码已注册,请更换",
+    20014 => "用户账号已存在,请更换",
+    20015 => "当前门店入库错误,请联系管理员",
+    20016 => "注册成功,请联系对应负责人开通权限",
+    20017 => "该账号尚未绑定权限,请联系对应负责人",
+    20018 => "注册账号失败,请联系对应负责人",
+
+    300010 => "请勿重复获取",
+    300011 => "获取验证码失败,请联系管理员",
+    300012 => "验证码已成功发送至%mobile%,请注意查收",
+    300013 => "请先验证手机号码",
+
+    500001 => "门店开通成功,请使用手机号码%mobile%进行登录",
+    500002 => "请输入用户手机号码",
+    500003 => "请输入密码",
+    500004 => "请输入验证码",
+    500005 => "场景值错误",
+    500006 => "请选择所属门店",
+    500007 => "请输入名称",
+    500008 => "请输入登录账号",
+
+    600001 => "当前账号无权限,请使用主账号操作"
+];