Kirin 3 years ago
parent
commit
cfac645abb
3 changed files with 134 additions and 0 deletions
  1. 115 0
      app/common.php
  2. 18 0
      app/controller/admin/system/merchant/Merchant.php
  3. 1 0
      route/admin.php

+ 115 - 0
app/common.php

@@ -882,3 +882,118 @@ if (!function_exists('attr_format')) {
         return [$data, $res];
     }
 }
+
+if (!function_exists('not_empty_check')) {
+    /**
+     * 非空验证
+     * @param $param
+     * @return bool
+     */
+    function not_empty_check($param)
+    {
+        if (is_array($param)) {
+            return !(count($param) <= 0);
+        } else {
+            if ($param == '') {
+                return false;
+            }
+            if ($param == null) {
+                return false;
+            }
+            return true;
+        }
+    }
+}
+
+if (!function_exists('mobile_check')) {
+    /**
+     * 电话验证
+     * @param $param
+     * @return bool
+     */
+    function mobile_check($param)
+    {
+        if (!preg_match("/^1[3456789]\d{9}$/", $param)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+}
+
+if (!function_exists('do_request')) {
+    /**
+     * CURL 请求接口
+     * @param string $url 请求地址
+     * @param array $data 请求参数
+     * @param array $header 请求头
+     * @param bool $post true:post请求 false:get请求
+     * @param bool $json post请求时 请求数据打包方式是否为json
+     * @param int $format 数据打包为json格式时打包的格式值 来自json_encode
+     * @param bool $form post请求时 请求数据是否为表单 同时为false时为http提交 优先级高于json
+     * @return bool|false|string
+     */
+    function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
+    {
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+        if ($post) {
+            curl_setopt($curl, CURLOPT_POST, 1);
+            if (!$json && !$form) {
+                curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
+            } else if ($json && !$form) {
+                curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
+            } else {
+                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+            }
+        }
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        if ($header) {
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
+            curl_setopt($curl, CURLOPT_HEADER, 0);
+        }
+        $result = curl_exec($curl);
+        if (curl_errno($curl)) {
+            return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
+        }
+        curl_close($curl);
+        return $result;
+    }
+}
+
+if (!function_exists('get_distance')) {
+    function get_distance($lat1, $lng1, $lat2, $lng2)
+    {
+        $EARTH_RADIUS = 6378137;
+
+        $radLat1 = rad($lat1);
+        $radLat2 = rad($lat2);
+        $a = $radLat1 - $radLat2;
+        $b = rad($lng1) - rad($lng2);
+        $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
+        $s = $s * $EARTH_RADIUS;
+        $s = round($s * 10000) / 10000;
+        return $s;
+    }
+}
+if (!function_exists('rad')) {
+    function rad($d)
+    {
+        return $d * M_PI / 180.0;
+    }
+}
+if (!function_exists('file_debug')) {
+    /**
+     * @param $file
+     * @param $title
+     * @param $data
+     * @param int $step
+     * @return void
+     */
+    function file_debug($file, $title, $data, $step = 0)
+    {
+        file_put_contents($file, "【" . date('Y-m-d H:i:s') . "】{$title}:" . ($step > 0 ? ('(step' . $step . ')') : '') . json_encode($data) . PHP_EOL, FILE_APPEND);
+    }
+}

+ 18 - 0
app/controller/admin/system/merchant/Merchant.php

@@ -145,6 +145,24 @@ class Merchant extends BaseController
         return app('json')->success('编辑成功');
     }
 
+    /**
+     * @param int $id
+     * @return mixed
+     * @throws DbException
+     * @author xaboy
+     * @day 2020-05-06
+     */
+    public function updateLocal($id)
+    {
+        $data = $this->request->params([['longitude', ''], ['latitude', '']]);
+        if (!$this->repository->exists($id))
+            return app('json')->fail('数据不存在');
+        if ($data['longitude'] == '' || !$data['latitude'] == '')
+            return app('json')->fail('请选择经纬度');
+        $this->repository->update($id, $data);
+        return app('json')->success('编辑成功');
+    }
+
     /**
      * @param int $id
      * @return mixed

+ 1 - 0
route/admin.php

@@ -209,6 +209,7 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
             Route::post('create', '.Merchant/create')->name('systemMerchantCreate');
             Route::get('update/form/:id', '.Merchant/updateForm')->name('systemMerchantUpdateForm');
             Route::post('update/:id', '.Merchant/update')->name('systemMerchantUpdate');
+            Route::post('update_local/:id', '.Merchant/updateLocal')->name('systemMerchantUpdateLocal');//商户修改定位
             Route::post('status/:id', '.Merchant/switchStatus')->name('systemMerchantStatus');
             Route::post('close/:id', '.Merchant/switchClose')->name('systemMerchantClose');
             Route::delete('delete/:id', '.Merchant/delete')->name('systemMerchantDelete');