dyjh 6 роки тому
батько
коміт
88e0e9604e

+ 101 - 5
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd xqd
@@ -654,6 +654,11 @@ class AlbumController extends Controller
      * @apiPermission none
      * @apiVersion 0.1.0
      * @apiParam {int}    [store_id]  商户id 模拟值为0
+     * @apiParam {int}    [type]  查询方式 1 按用户 2 按时间 3 按类型
+     * @apiParam {int}    [user_id]  用户id
+     * @apiParam {int}    [action]  行为类型 1 收藏  2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
+     * @apiParam {int}    [start_time]  查询开始时间
+     * @apiParam {int}    [end_time]  查询结束时间
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
      * {
@@ -692,18 +697,36 @@ class AlbumController extends Controller
         if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
         $validator = Validator::make($request->all(), [
             'store_id' => 'required',
+            'type'=>'required'
         ],[
             'store_id.required'=>'缺少商户参数',
+            'type.required'=>'缺少类型参数',
         ]);
         if ($validator->fails()) {
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
         }
+        $type = $request->input('type');
         $store_id = $request->input('store_id');
         if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
         $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
-        $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]])->get();
-        $count_user = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]])->groupBy('open_id')->get();
-        $count = count($count_user);
+        $query = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]]);
+        switch ($type){
+            case '1':
+                if(!$request->input('user_id')) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
+                $query = $query->andWhere(['user_id',$request->input('user_id')]);
+                break;
+            case '2':
+                if(!$request->input('start_time')||!$request->input('end_time')) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
+                $start_time = date('Y-m-d H:i:s',$request->input('start_time'));
+                $end_time = date('Y-m-d H:i:s',$request->input('end_time'));
+                $query = $query->andWhere([['created_at','>=',$start_time],['created_at','<=',$end_time]]);
+                break;
+            case '3':
+                if(!$request->input('action')) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!');
+                $query = $query->andWhere(['action',$request->input('action')]);
+                break;
+        }
+        $res = $query->get();
         $action = '';
         foreach($res as $key=>$val){
             if($val->action==4){
@@ -738,16 +761,89 @@ class AlbumController extends Controller
                 $action = '查看了您的电话'.$phone.',并且点击了拨号';
             }
             $user = AlbumUserModel::where([['wechat_open_id',$val->open_id],['store_id',$val->store_id]])->select(['username','avatar','phone'])->first();
-            $data_res['type'.$val->action][] = [
+            $data_res[] = [
                 'time'=>$val->created_at,
                 'action'=>$action,
                 'user'=>$user
             ];
         }
-        $data_res['count'] = $count;
         return $this->api(compact('data_res'));
     }
 
+    /**
+     * @api {post} /api/album/get-cart-of-watch 客户浏览情况概览(get-cart-of-watch)
+     * @apiDescription 客户浏览情况概览(get-cart-of-watch)
+     * @apiGroup Album
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [store_id]  商户id 模拟值为0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": [
+     *         "user": {
+     *              "username":"王小贱",
+     *              "avatar":"awdawdawdawdawdawd",头像
+     *               "phone":"1123123123123"
+     *              }
+     *         "count":6,
+     *         "action":[
+     *              "type1":1,
+     *              "type2":1,
+     *              "type3":1,
+     *              "type4":1,
+     *              "type5":1,
+     *              "type6":1,
+     *              "type7":1,
+     *          ]
+     *      ]
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function albumGetCartOfWatch(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
+        $validator = Validator::make($request->all(), [
+            'store_id' => 'required',
+        ],[
+            'store_id.required'=>'缺少商户参数',
+        ]);
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $store_id = $request->input('store_id');
+        if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
+        $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+        $count_user = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id]])->groupBy('open_id')->get();
+
+        $users = Array();
+        if($count_user){
+            foreach($count_user as $key=>$val){
+                $user = AlbumUserModel::where([['wechat_open_id',$val->open_id],['store_id',$val->store_id]])->select(['username','avatar','phone'])->first();
+                $users[] = $user;
+            }
+        }
+        $count = count($users);
+        $action = Array();
+        for($i=1;$i<=7;$i++){
+            $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['action',$i]])->get();
+            $action['type'.$i] = count($res);
+        }
+        return $this->api(compact('count','users','action'));
+    }
     /**
      * @api {get} /api/album/checklogin 登陆应用(checklogin)
      * @apiDescription 登陆应用(checklogin)

+ 1 - 1
app/Http/Controllers/Api/V1/Controller.php

xqd
@@ -22,7 +22,7 @@ class Controller extends BaseController
         $this->middleware('auth:api', [
             'except' => [
                 'upload', 'getCode', 'reset', 'login', 'get', 'register', 'alipayNotify', 'wechatpayNotify', 'get', 'area', 'get_province', 'get_city', 'get_county', 'albumStyle', 'test', 'index', 'companyInfo', 'shop2', 'cardIndex', 'cardUserInfo', 'cardUserProgress', 'cardUserHonor', 'cardUserProject', 'CardUserTrend', 'projectDetail', 'trendDetail', 'albumSetting', 'albumXyxLogin', 'albumCat', 'albumchecklogin', 'albumGoods', 'albumGoodsDetail', 'albumSetPrice', 'albumXcxLogin', 'albumContentList', 'albumSearchGoods','albumContentDetail','albumFavoriteList','albumAddFavorite','albumFavoriteDel','getAttr','getOrder','getProgress','getReviewCount', 'furnitureNewsDetail','furnitureSetting','furnitureXcxLogin','furnitureGoodsList','serviceLogin','getFurnitureAds','getPhoneNumber','getQrcode','orderCount','searchList','printOrder','saveFormId','furnitureNewsList','getMoreComments','addToLike','albumSavePhone',
-                'albumGetWatchRecord','albumSetWatch'
+                'albumGetWatchRecord','albumSetWatch','albumGetCartOfWatch'
             ]
         ]);
 

+ 5 - 0
routes/api.php

xqd
@@ -250,6 +250,11 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'uses' => 'AlbumController@albumGetWatchRecord',
     ]);
 
+    $api->post('album/get-cart-of-watch', [
+        'as' => 'album.GetCartOfWatch',
+        'uses' => 'AlbumController@albumGetCartOfWatch',
+    ]);
+
     $api->post('album/set-watch', [
         'as' => 'album.SetWatch',
         'uses' => 'AlbumController@albumSetWatch',