chenhao 4 years ago
parent
commit
a534121b59
2 changed files with 26 additions and 5 deletions
  1. 22 1
      application/index/controller/User.php
  2. 4 4
      config/database.php

+ 22 - 1
application/index/controller/User.php

@@ -160,8 +160,29 @@ class User extends Api
         $res = Db::name('user_weixiu_baobei')->where('status',$type)->where('uid',$user['id'])->order('create_time')->select();
 
         $datas = array_merge($data,$res);
+        # 按距离降序排序
+        $a = self::arraySort($datas, 'create_time', SORT_DESC);
+//        print_r($a);die;
+//       # 按money升序排序
+//        $b = arraySort($data, 'money', SORT_ASC);
+//        print_r($b);
+        return $this->success('',$a);
+    }
 
-        return $this->success('',$datas);
+    /**
+     * 二维数组根据某个字段排序
+     * @param array $array 要排序的数组
+     * @param string $keys   要排序的键字段
+     * @param string $sort  排序类型  SORT_ASC     SORT_DESC
+     * @return array 排序后的数组
+     */
+    function arraySort($array, $keys, $sort = SORT_DESC) {
+        $keysValue = [];
+        foreach ($array as $k => $v) {
+            $keysValue[$k] = $v[$keys];
+        }
+        array_multisort($keysValue, $sort, $array);
+        return $array;
     }
 
     /**

+ 4 - 4
config/database.php

@@ -19,13 +19,13 @@ return [
     // 数据库类型
     'type'        => 'mysql',
     // 服务器地址
-    'hostname'    => '127.0.0.1',
+    'hostname'    => '47.111.246.47',
     // 数据库名
-    'database'    => 'deshu',
+    'database'    => 'degao',
     // 用户名
-    'username'    => 'root',
+    'username'    => 'degao',
     // 密码
-    'password'    => 'root',
+    'password'    => 'mWhMPt3tHSp6hHhG',
     // 编码
     'charset'     => 'utf8mb4',
     // 端口