Prechádzať zdrojové kódy

Merge branch 'master' of http://git.9026.com/roobe/miao

YanaDH 7 rokov pred
rodič
commit
b9267dcc87

+ 11 - 5
server/app/Http/Controllers/Api/V1/AuthController.php

xqd xqd xqd xqd
@@ -30,7 +30,7 @@ class AuthController extends Controller
      * @apiPermission none
      * @apiVersion 0.1.0
      * @apiParam {string}  phone    手机号码
-     * @apiParam {string}  [wechat]    微信openid
+     * @apiParam {string}  wechat   微信openid
      * @apiParam {String}  verify_code  手机验证码
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -70,10 +70,12 @@ class AuthController extends Controller
     public function login(Request $request) {
         $validator = Validator::make($request->all(),
             [
+//                'wechat'      => 'required',
                 'phone'         => 'required|regex:/^1[34578]\d{9}$/',
                 'verify_code'      => 'required',
             ],
             [
+//                'wechat.required'      => '请先绑定微信',
                 'phone.required'        => '请输入手机号码',
                 'phone.regex'           => '手机号码格式不正确',
                 'verify_code.required'      => '短信验证码必填',
@@ -82,7 +84,6 @@ class AuthController extends Controller
 
         if ($validator->fails())
             return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
-
         $phone = $request->phone;
         $wechat = $request->wechat;
         $key = $this->keySmsCode . $phone;
@@ -91,17 +92,22 @@ class AuthController extends Controller
         if ($request->verify_code != $code) return $this->error(ErrorCode::SERVICE_CODE_FAILED);
         $user = UserInfoModel::where('phone',$phone)->first();
         if (empty($user)) {
-            $user = UserInfoModel::create(['phone'=>$phone,'password'=>bcrypt(123456)]);
+            $user = UserInfoModel::create([
+                'phone'=>$phone,
+                'wechat'=>$wechat,
+                'password'=>bcrypt(123456)
+            ]);
             $user->status=1;
+            $user->save();
         }
         $status =empty($user) ? 0 : $user->status;
         if ($status == 0) return $this->error(ErrorCode::LOCK_USER);
         if (Auth::attempt(['phone'=>$phone,'password'=>$password])) {
             $user = Auth::user();
-            if (!empty($wechat)) {
+         /*   if (!empty($wechat)) {
                 $user->wechat =$wechat;
                 $user->save();
-            }
+            }*/
             \Log::info($user);
             $token = $user->createToken($user->phone)->accessToken;
             return $this->api(compact( 'user', 'code','token'));

+ 33 - 0
server/app/Http/Controllers/Api/V1/DreamController.php

xqd
@@ -729,4 +729,37 @@ class DreamController extends Controller
         }
     }
 
+    /**
+     * @api {get} /api/dream/share 分享
+     * @apiDescription 分享
+     * @apiParam {int}  id          梦想id
+     * @apiGroup Dream
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     */
+//    分享梦想
+    public function share(Request $request)
+    {
+        $validator = \Validator::make($request->all(),
+            [
+                'id'  => 'required',
+            ],
+            [
+                'id.required'  => '梦想id不存在',
+            ]
+        );
+        if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
+        $url = env('APP_URL').'/api/dream/show?id='.$request->id;
+        $dream = DreamInfoModel::with('img')->find($request->id);
+        $img = !empty($dream->img) ? $dream->img->pic : '';
+        $html =
+            "<div style='text-align: center'>
+                <a href='$url'>
+                    <h1>$dream->name</h1>
+                    <img src=\"$img\" style='width: 20px;height: 20px;' alt=''>
+                </a>
+            </div>";
+        return $html;
+    }
+
 }

+ 112 - 0
server/app/Http/Controllers/Api/V1/IndexController.php

xqd
@@ -313,4 +313,116 @@ class IndexController extends Controller
 
     }
 
+    /**
+     * @api {get}  /api/index/filter 筛选
+     * @apiDescription 筛选
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  [sex]   性别   //1男,2女,0:全部,
+     * @apiParam {string}  [age]   年龄段  0:全部,1:18-21,2:22-25,3:26-29,4:30-33,5:34-37,6:>37,
+     * @apiParam {string}  [area]   地区   例:成都
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *    "status": true,
+     *    "status_code": 0,
+     *    "message": "",
+     *    "data":[
+     *      {
+     *         "nickname": "ha",  昵称
+     *         "pic": "",    头像
+     *          ...
+     *      },
+     *   ]
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function filter(Request $request)
+    {
+        $sex = $request->sex;
+        $age = $request->age;
+        $area = $request->area;
+        $login_user = $this->getUser();
+        $id = $login_user->id;
+        $query = new DreamInfoModel();
+        if (($sex) == 1) {
+            $query = $query->whereHas('user', function ($select) use ($sex) {
+                $select->where('sex',0);
+            });
+        }
+        if (($sex) == 2) {
+            $query = $query->whereHas('user', function ($select) use ($sex) {
+                $select->where('sex',1);
+            });
+        }
+        if ($age == 1) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-21)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-18)));
+            });
+        }
+        if ($age == 2) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-25)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-22)));
+            });
+        }
+        if ($age == 3) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-29)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-26)));
+            });
+        }
+        if ($age == 4) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-33)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-30)));
+            });
+        }
+        if ($age == 5) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-37)))->where('birthday','<=',date('Y-m-d',strtotime(date('Y')-34)));
+            });
+        }
+        if ($age == 6) {
+            $query = $query->whereHas('user', function ($select) use ($age) {
+                $select->where('birthday','>=',date('Y-m-d',strtotime(date('Y')-38)));
+            });
+        }
+
+        if (!empty($area)) {
+            $query = $query->whereHas('user', function ($select) use ($area) {
+                $select->where('city','like','%'.$area.'%');
+            });
+        }
+        $arr1 =DreamInfoModel::limit(20)->select('id')->get()->toArray();
+        $id_arr1 = array_column($arr1,'id');
+        $arr2 =DreamInfoModel::orderBy('score','desc')->limit(120)->select('id')->get()->toArray();
+        $id_arr2 = array_column($arr2,'id');
+        $dtusers =UserCareUser::where('user_id',$id)->with('other_user')->
+        where('dream_number','>',0)->orderBy('created_at')->get()->toArray();
+        $hdusers = CommentInfoModel::where(function ($query) use ($id) {
+            $query->where('user_id',$id)->orWhere('to_user_id',$id);
+        })->where('is_read',0)->with('to_user')->orderBy('created_at')->get()->toArray();
+        $users = [] ;
+        foreach ($dtusers as $k => $v){
+            $users[] = $v['other_user'];
+        }
+        foreach ($hdusers as $k => $v){
+            $users[] = $v['to_user'];
+        }
+        $type = $request->type;
+        if ($type == 'trend') {
+            $dreams = $query->orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
+            $this->dreams($dreams);
+            return $this->api(compact('users','dreams'));
+        } elseif ($type == 'news') {
+            $dreams = $query->orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
+            $this->dreams($dreams);
+            return $this->api(compact('users','dreams'));
+        } else{
+            $banners = $this->getBanner();
+            $dreams = $query->orderBy('score','desc')->with('user')->limit(20)->paginate(20);
+            $this->dreams($dreams);
+            return $this->api(compact('banners','users','dreams'));
+        }
+    }
 }

+ 0 - 5
server/app/Http/Controllers/Api/V1/MyController.php

xqd
@@ -628,14 +628,9 @@ class MyController extends Controller
     {
         $user = $this->getUser();
         $dreams = $user->dreams;
-
-        if (count($dreams) == 0)
-            return $this->error(ErrorCode::DREAM_NOT_EXIST);
-
         foreach ($dreams as $dream){
             $dream->pic = count($dream->img) > 0 ? $dream->img->pic : '';
         }
-
         return $this->api($dreams);
     }
 

+ 1 - 0
server/app/Models/UserInfoModel.php

xqd
@@ -53,6 +53,7 @@ class UserInfoModel extends Authenticatable
                            'status',
                            'remember_token',
                            'birthday',
+                           'wechat',
                           ];
 
     protected $hidden = ['password'];

+ 8 - 0
server/routes/api.php

xqd xqd
@@ -97,6 +97,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'index.home',
         'uses' => 'IndexController@home',
     ]);
+    $api->get('index/filter', [
+        'as' => 'index.filter',
+        'uses' => 'IndexController@filter',
+    ]);
     $api->get('index/search', [
         'as' => 'index.search',
         'uses' => 'IndexController@search',
@@ -225,6 +229,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'dream.show',
         'uses' => 'DreamController@show',
     ]);
+    $api->get('dream/share', [
+        'as' => 'dream.share',
+        'uses' => 'DreamController@share',
+    ]);
     $api->get('dream/search', [
         'as' => 'dream.search',
         'uses' => 'DreamController@search',