Kirin 2 months ago
parent
commit
67eef6fe76

+ 16 - 2
app/Request.php

@@ -14,6 +14,8 @@ class Request extends \think\Request
     private $adminInfo = null;
     private $user = null;
     private $tokenData = null;
+    private $longitude = 0;
+    private $latitude = 0;
 
     /**
      * 不过滤变量名
@@ -40,6 +42,12 @@ class Request extends \think\Request
         $this->tokenData = $data;
     }
 
+    public function setLocation($latitude, $longitude)
+    {
+        $this->latitude = $latitude;
+        $this->longitude = $longitude;
+    }
+
 
     /**
      * 获取请求的数据
@@ -114,9 +122,9 @@ class Request extends \think\Request
      * @param bool $filter
      * @return array
      */
-    public function getMore(array $params, bool $suffix = false, callable $deal = null, int $update_id = 0, bool $filter = true): array
+    public function getMore(array $params, bool $suffix = false, callable $deal = null, bool $filter = true): array
     {
-        return $this->more($params, $suffix, $deal, $update_id, $filter);
+        return $this->more($params, $suffix, $deal, $filter);
     }
 
     /**
@@ -257,4 +265,10 @@ class Request extends \think\Request
     }
 
 
+    public function location()
+    {
+        return [$this->latitude, $this->longitude];
+    }
+
+
 }

+ 56 - 0
app/common/ApiBaseController.php

@@ -10,6 +10,8 @@ namespace app\common;
 
 
 use app\Request;
+use Joypack\Tencent\Map\Bundle\Location;
+use Joypack\Tencent\Map\Bundle\LocationOption;
 use qiniu\basic\BaseController;
 
 abstract class ApiBaseController extends BaseController
@@ -45,4 +47,58 @@ abstract class ApiBaseController extends BaseController
         $this->uid = $this->request->uid();
         $this->userInfo = $this->request->user();
     }
+
+    /**
+     * @return array
+     */
+    public function getAddress(): array
+    {
+        list($latitude, $longitude) = $this->request->location();
+        $address = $this->geoLbscoder($latitude, $longitude);
+        if ($address) {
+            return [
+                'address' => $address['address_component'],
+                'formatted_addresses' => $address['formatted_addresses'],
+                'info' => $address['ad_info'],
+            ];
+        }
+        return [];
+    }
+
+    /**
+     * 经纬度反向解析地址
+     * @param string $latitude
+     * @param string $longitude
+     * @return mixed|null
+     */
+    private function geoLbscoder(string $latitude, string $longitude)
+    {
+        if (!$latitude || !$longitude) {
+            return null;
+        }
+        $mapKey = sys_config('tengxun_map_key');
+        $mapKSecret = sys_config('tengxun_map_secret', '');
+        if (!$mapKSecret) $mapKSecret = null;
+        if (!$mapKey) {
+            return null;
+        }
+        try {
+            $locationOption = new LocationOption($mapKey, $mapKSecret);
+            $locationOption->setLocation($latitude, $longitude);
+            $location = new Location($locationOption);
+            $res = $location->request();
+            if ($res->error) {
+                return null;
+            }
+            if ($res->status) {
+                return null;
+            }
+            if (!$res->result) {
+                return null;
+            }
+            return $res->result;
+        } catch (\Throwable $e) {
+            return null;
+        }
+    }
 }

+ 1 - 2
app/controller/admin/system/SystemMenus.php

@@ -37,13 +37,12 @@ class SystemMenus extends AdminBaseController
             ['pid', 0],
             ['sort', 0],
             ['auth_type', 1],
+            ['type', 1],
             ['is_show', 1],
             ['is_show_path', 0],
             ['extend', []],
         ];
         $this->saveDeal = $this->updateDeal = function (&$data) {
-            $data['type'] = 1;
-            if (!$data['menu_name']) throw new ValidateException('请输入菜单名称');
             if (!$data['menu_name']) throw new ValidateException('请输入菜单名称');
             if ($data['auth_type'] == 1) {
                 if (!$data['menu_path']) throw new ValidateException('请填写菜单路径');

+ 6 - 23
app/controller/admin/system/config/SystemConfig.php

@@ -48,15 +48,12 @@ class SystemConfig extends AdminBaseController
             ['input_type', ''],
             ['config_tab_id', []],
             ['parameter', ''],
-            ['upload_type', 1],
-            ['required', ''],
-            ['width', 0],
-            ['high', 0],
             ['value', ''],
             ['info', ''],
             ['desc', ''],
             ['sort', 0],
             ['status', 0],
+            ['configuration', []],
             ['is_store', 0],
         ];
     }
@@ -100,20 +97,6 @@ class SystemConfig extends AdminBaseController
         if ($data['sort'] < 0) {
             $data['sort'] = 0;
         }
-        if ($data['type'] == 'text') {
-            if (!$data['width']) return $this->error('请输入文本框的宽度');
-            if ($data['width'] <= 0) return $this->error('请输入正确的文本框的宽度');
-        }
-        if ($data['type'] == 'textarea') {
-            if (!$data['width']) return $this->error('请输入多行文本框的宽度');
-            if (!$data['high']) return $this->error('请输入多行文本框的高度');
-            if ($data['width'] < 0) return $this->error('请输入正确的多行文本框的宽度');
-            if ($data['high'] < 0) return $this->error('请输入正确的多行文本框的宽度');
-        }
-        if ($data['type'] == 'radio' || $data['type'] == 'checkbox') {
-            if (!$data['parameter']) return $this->error('请输入配置参数');
-            $this->service->valiDateRadioAndCheckbox($data);
-        }
         $data['value'] = json_encode($data['value']);
         $config = $this->service->getOne(['menu_name' => $data['menu_name']]);
         if ($config) {
@@ -137,13 +120,14 @@ class SystemConfig extends AdminBaseController
     public function update($id)
     {
         $type = request()->post('type');
-        if ($type == 'text' || $type == 'textarea' || $type == 'radio' || ($type == 'upload' && (request()->post('upload_type') == 1 || request()->post('upload_type') == 3))) {
+        $configuration = request()->post('configuration/a');
+        if ($type == 'Input' || $type == 'RadioGroup' || $type == 'Select' || $type == 'Datepicker' || ($type == 'Upload' && (($configuration['upload_type'] ?? 1) == 1 || ($configuration['upload_type'] ?? 1) == 3))) {
             $value = request()->post('value');
         } else {
             $value = request()->post('value/a');
         }
         if (!$value) $value = request()->post(request()->post('menu_name'));
-        $data = $this->request->postMore([['is_store', 0], 'status', 'info', 'desc', 'sort', 'config_tab_id', 'required', 'parameter', ['value', $value], 'upload_type', 'input_type']);
+        $data = $this->request->postMore(array_merge($this->createParams, [['value', $value]]));
         $data['config_tab_id'] = end($data['config_tab_id']);
         if (!$this->service->get($id)) {
             return $this->error('编辑的记录不存在!');
@@ -212,8 +196,8 @@ class SystemConfig extends AdminBaseController
             if (is_array($v)) {
                 $res = $this->service->getUploadTypeList($k);
                 foreach ($res as $kk => $vv) {
-                    if ($kk == 'upload') {
-                        if ($vv == 1 || $vv == 3) {
+                    if ($kk == 'Upload') {
+                        if (($vv['upload_type'] ?? 1) == 1 || ($vv['upload_type'] ?? 1) == 3) {
                             $post[$k] = $v[0];
                         }
                     }
@@ -249,7 +233,6 @@ class SystemConfig extends AdminBaseController
             $config_one = $this->service->getOne(['menu_name' => $k]);
             if ($config_one) {
                 $config_one['value'] = $v;
-                $this->service->valiDateValue($config_one);
                 $this->service->update($k, ['value' => json_encode($v)], 'menu_name');
             }
         }

+ 2 - 2
app/controller/admin/system/config/SystemConfigTab.php

@@ -46,7 +46,7 @@ class SystemConfigTab extends AdminBaseController
         $this->createParams = [
             'status',
             ['title', ''],
-            ['en_title', ''],
+            ['eng_title', ''],
             ['icon', ''],
             ['sort', 0],
             ['info', ''],
@@ -88,7 +88,7 @@ class SystemConfigTab extends AdminBaseController
     {
         /** @var SystemConfigServices $services */
         $services = app()->make(SystemConfigServices::class);
-        if ($services->be(['tab_id' => $id])) {
+        if ($services->be(['config_tab_id' => $id])) {
             return $this->error('存在下级配置,无法删除!');
         }
         if (!$this->service->delete($id))

+ 46 - 0
app/http/middleware/api/LocationMiddleware.php

@@ -0,0 +1,46 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+namespace app\http\middleware\api;
+
+
+use app\Request;
+use Closure;
+use qiniu\interfaces\MiddlewareInterface;
+
+/**
+ * Class AuthTokenMiddleware
+ * @package app\api\middleware
+ */
+class LocationMiddleware implements MiddlewareInterface
+{
+    private $default = '39.904213,116.407385';
+
+    /**
+     * @param Request $request
+     * @param Closure $next
+     * @return mixed|object
+     */
+    public function handle(Request $request, Closure $next)
+    {
+        $location = $request->header('QN-Location', '');
+        if ($location) {
+            $location = explode(',', $location);
+        }
+        if (!$location || !count($location) == 2) {
+            $location = explode(',', $this->default);
+        }
+        $latitude = $location[0];
+        $longitude = $location[1];
+        $request->setLocation($latitude, $longitude);
+        return $next($request);
+    }
+}

+ 12 - 140
app/services/system/config/SystemConfigServices.php

@@ -31,13 +31,6 @@ use think\exception\ValidateException;
 class SystemConfigServices extends BaseServices implements ServeConfigInterface
 {
 
-
-    /**
-     * 表单数据切割符号
-     * @var string
-     */
-    protected $cuttingStr = '=>';
-
     /**
      * SystemConfigServices constructor.
      * @param SystemConfig $model
@@ -108,10 +101,7 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
         $count = $this->getCount($where);
         foreach ($list as &$item) {
             $item['value'] = $item['value'] ? json_decode($item['value'], true) ?: '' : '';
-            if ($item['type'] == 'radio' || $item['type'] == 'checkbox') {
-                $item['value'] = $this->getRadioOrCheckboxValueInfo($item['menu_name'], $item['value']);
-            }
-            if ($item['type'] == 'upload' && !empty($item['value'])) {
+            if ($item['type'] == 'Upload' && !empty($item['value'])) {
                 $item['value'] = set_file_url($item['value']);
                 $tidy_srr = [];
                 foreach ($item['value'] as $key => $value) {
@@ -124,40 +114,6 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
         return compact('count', 'list');
     }
 
-    /**
-     * 获取单选按钮或者多选按钮的显示值
-     * @param string $menu_name
-     * @param $value
-     * @return string
-     * @throws DataNotFoundException
-     * @throws DbException
-     * @throws ModelNotFoundException
-     */
-    public function getRadioOrCheckboxValueInfo(string $menu_name, $value): string
-    {
-        $option = [];
-        $config_one = $this->getOne(['menu_name' => $menu_name]);
-        if (!$config_one) {
-            return '';
-        }
-        $parameter = explode("\n", $config_one['parameter']);
-        foreach ($parameter as $k => $v) {
-            if (isset($v) && strlen($v) > 0) {
-                $data = explode($this->cuttingStr, $v);
-                $option[$data[0]] = $data[1];
-            }
-        }
-        $str = '';
-        if (is_array($value)) {
-            foreach ($value as $v) {
-                $str .= $option[$v] . ',';
-            }
-        } else {
-            $str .= !empty($value) ? $option[$value] ?? '' : $option[0] ?? '';
-        }
-        return $str;
-    }
-
     /**
      * 获取系统配置信息
      * @param int $tabId
@@ -166,11 +122,16 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
     public function getReadList(int $tabId)
     {
         $info = $this->getConfigTabAllList($tabId);
-        foreach ($info as $k => $v) {
-            if (!is_null(json_decode($v['value'])))
-                $info[$k]['value'] = json_decode($v['value'], true);
-            if ($v['type'] == 'upload' && !empty($v['value'])) {
-                if ($v['upload_type'] == 1 || $v['upload_type'] == 3) $info[$k]['value'] = explode(',', $v['value']);
+        foreach ($info as &$v) {
+            $v['value'] = $v['value'] ? json_decode($v['value'], true) ?: '' : '';
+            if ($v['type'] == 'Upload' && !empty($v['value'])) {
+                $v['value'] = set_file_url($v['value']);
+                $tidy_srr = [];
+                foreach ($v['value'] as $key => $value) {
+                    $tidy_srr[$key]['filepath'] = $value;
+                    $tidy_srr[$key]['filename'] = basename($value);
+                }
+                $v['value'] = $tidy_srr;
             }
         }
         return $info;
@@ -197,83 +158,7 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
      */
     public function getUploadTypeList(string $configName)
     {
-        return $this->search(['menu_name' => $configName])->column('upload_type', 'type');
-    }
-
-    /**
-     * radio 和 checkbox规则的判断
-     * @param $data
-     * @return bool
-     */
-    public function valiDateRadioAndCheckbox($data)
-    {
-        $option = [];
-        $option_new = [];
-        $data['parameter'] = str_replace("\r\n", "\n", $data['parameter']);//防止不兼容
-        $parameter = explode("\n", $data['parameter']);
-        if (count($parameter) < 2) {
-            throw new AdminException('请输入正确格式的配置参数');
-        }
-        foreach ($parameter as $k => $v) {
-            if (isset($v) && !empty($v)) {
-                $option[$k] = explode('=>', $v);
-            }
-        }
-        if (count($option) < 2) {
-            throw new AdminException('请输入正确格式的配置参数');
-        }
-        $bool = 1;
-        foreach ($option as $k => $v) {
-            $option_new[$k] = $option[$k][0];
-            foreach ($v as $kk => $vv) {
-                $vv_num = strlen($vv);
-                if (!$vv_num) {
-                    $bool = 0;
-                }
-            }
-        }
-        if (!$bool) {
-            throw new AdminException('请输入正确格式的配置参数');
-        }
-        $num1 = count($option_new);//提取该数组的数目
-        $arr2 = array_unique($option_new);//合并相同的元素
-        $num2 = count($arr2);//提取合并后数组个数
-        if ($num1 > $num2) {
-            throw new AdminException('请输入正确格式的配置参数');
-        }
-        return true;
-    }
-
-    /**
-     * 验证参数
-     * @param $data
-     * @return bool
-     */
-    public function valiDateValue($data)
-    {
-        if (!$data || !isset($data['required']) || !$data['required']) {
-            return true;
-        }
-        $valids = explode(',', $data['required']);
-        foreach ($valids as $valid) {
-            $valid = explode(':', $valid);
-            if (isset($valid[0]) && isset($valid[1])) {
-                $k = strtolower(trim($valid[0]));
-                $v = strtolower(trim($valid[1]));
-                switch ($k) {
-                    case 'required':
-                        if ($v == 'true' && $data['value'] === '') {
-                            throw new ValidateException(($data['info'] ?? '') . '请输入默认值');
-                        }
-                        break;
-                    case 'url':
-                        if ($v == 'true' && !check_link($data['value'])) {
-                            throw new ValidateException(($data['info'] ?? '') . '请输入正确url');
-                        }
-                        break;
-                }
-            }
-        }
+        return $this->search(['menu_name' => $configName])->column('configuration', 'type');
     }
 
 
@@ -333,19 +218,6 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
     }
 
 
-    public function getOptions(string $parameter)
-    {
-        $parameter = explode("\n", $parameter);
-        $options = [];
-        foreach ($parameter as $v) {
-            if (strstr($v, $this->cuttingStr) !== false) {
-                $pdata = explode($this->cuttingStr, $v);
-                $options[] = ['label' => $pdata[1], 'value' => (int)$pdata[0]];
-            }
-        }
-        return $options;
-    }
-
     /**
      * 获取配置
      * @param string $key