|
@@ -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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|