dyjh 6 年之前
父節點
當前提交
188321bcb5

+ 121 - 12
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -24,6 +24,7 @@ use App\Models\AlbumXyxUserModel;
 use App\Models\CustomerCatRecordModel;
 use App\Models\CustomerDetailsModel;
 use App\User;
+use EasyWeChat\Kernel\Messages\Text;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
@@ -225,7 +226,7 @@ class AlbumController extends Controller
                     $user_agent->save();
                     $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
                     try{
-                        $this->sendLogsMessage($datas['store_id'],$agent->open_id,4,$userAuth->username);
+                        $this->sendLogsMessage($datas['store_id'],$agent->open_id,4,$userAuth->username,$agent->g_open_id);
                     }catch (\Exception $e){
 
                     }
@@ -364,7 +365,7 @@ class AlbumController extends Controller
             $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
             $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
             try{
-                $this->sendLogsMessage($store_id,$agent->open_id,2,$userAuth->username);
+                $this->sendLogsMessage($store_id,$agent->open_id,2,$userAuth->username,$agent->g_open_id);
             }catch (\Exception $e){
 
             }
@@ -498,7 +499,7 @@ class AlbumController extends Controller
             $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
             $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
             try{
-                $this->sendLogsMessage($store_id,$agent->open_id,3,$userAuth->username);
+                $this->sendLogsMessage($store_id,$agent->open_id,3,$userAuth->username,$agent->g_open_id);
             }catch (\Exception $e){
 
             }
@@ -1316,7 +1317,7 @@ class AlbumController extends Controller
             $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
             $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
             try{
-                $this->sendLogsMessage($data['store_id'],$agent->open_id,1,$userAuth->username);
+                $this->sendLogsMessage($data['store_id'],$agent->open_id,1,$userAuth->username,$agent->g_open_id);
             }catch (\Exception $e){
 
             }
@@ -1661,7 +1662,7 @@ class AlbumController extends Controller
             $add_record['agent_id'] = $userAuth->up_agent_id;
             $add_record['open_id'] = $userAuth->open_id;
             $add_record['action'] = $data['type'];
-            $add_record['store_id'] = 1;
+            $add_record['store_id'] = $data['store_id'];
             $add_record['detail'] = json_encode($select_info);
            // dd($add_record);
             $res = AlbumWatchRecord::create($add_record);
@@ -1669,7 +1670,7 @@ class AlbumController extends Controller
             $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
             if($res){
                 try{
-                    $this->sendLogsMessage($data['store_id'],$agent->open_id,$data['type'],$userAuth->username);
+                    $this->sendLogsMessage($data['store_id'],$agent->open_id,$data['type'],$userAuth->username,$agent->g_open_id);
                 }catch (\Exception $e){
 
                 }
@@ -1686,7 +1687,7 @@ class AlbumController extends Controller
      * @param $action 1 收藏  2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
      * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
      */
-    private function sendLogsMessage($storeid,$open_id,$action,$name)
+    private function sendLogsMessage($storeid,$open_id,$action,$name,$g_open_id)
     {
         $user = AlbumUserModel::where('open_id',$open_id)->first();
         $formId = AlbumFormId::where([['open_id',$open_id]])->first();
@@ -1715,6 +1716,15 @@ class AlbumController extends Controller
                     $content = '有用户点击了您的号码';
                     break;
             }
+            $weChatApp = AlbumManufacturerModel::where('store_id', $storeid)->first();
+            $config = [
+                'app_id' => $weChatApp->G_app_id,
+                'secret' => $weChatApp->G_app_secret,
+                'response_type' => 'array',
+            ];
+            $app = Factory::officialAccount($config);
+            $text = new Text($content);
+            $app->customer_service->message($text)->to($g_open_id)->send();
             $this->wechat_app = AlbumManufacturerModel::where('store_id',$storeid)->first();
             $config = [
                 'app_id' => $this->wechat_app->app_id,
@@ -2333,6 +2343,7 @@ class AlbumController extends Controller
      * @apiPermission AUTH
      * @apiVersion 0.1.0
      * @apiParam {int}    [store_id]  商户id
+     * @apiParam {int}    [goods_id]  商品id
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
      * {
@@ -2354,6 +2365,8 @@ class AlbumController extends Controller
      */
     public function albumStatistical(Request $request)
     {
+        $userAuth = Auth('api')->user();
+        if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
         $validator = Validator::make($request->all(), [
             'store_id' => 'required',
             'agent_id' => 'required'
@@ -2365,14 +2378,14 @@ class AlbumController extends Controller
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
         }
         $store_id = $request->input('store_id');
-        $agent_id = $request->input('agent_id');
-        if($agent_id!=0){
-            $user_agent = AlbumAgentModel::where([['id',$agent_id],['status',1]])->first();
+        $goods_id = $request->input('goods_id');
+
+        if($userAuth->up_agent_id !=0){
+            $user_agent = AlbumAgentModel::where([['id',$userAuth->up_agent_id],['status',1]])->first();
             $user_agent->share_times++;
             $user_agent->save();
         }
-        $userAuth = Auth('api')->user();
-        if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
+
         $time = mktime(0,0,0,date('m'),date('d'),date('y'));
         $check = AlbumStatisticalModel::where([['time',$time],['store_id',$store_id]])->first();
         if($check){
@@ -2385,6 +2398,102 @@ class AlbumController extends Controller
             $add['favorite_times'] = 0;
             AlbumStatisticalModel::create($add);
         }
+        if($userAuth->up_agent_id!=0 && !empty($goods_id)){
+            $add_record['agent_id'] = $userAuth->up_agent_id;
+            $add_record['open_id'] = $userAuth->open_id;
+            $add_record['action'] = 8;
+            $add_record['store_id'] = $store_id;
+            $add_record['detail'] = $goods_id;
+            $res = AlbumWatchRecord::create($add_record);
+        }
         return $this->api([],0,'success');
     }
+
+
+    /**
+     * @api {post} /api/album/get_statistical 获取分享记录(get-statistical)
+     * @apiDescription 获取分享记录(get-statistical)
+     * @apiGroup Album
+     * @apiPermission AUTH
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [store_id]  商户id
+     * @apiParam {int}    [type]  1 尺寸统计 2拨打电话 3 分享
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "success",
+     *     "data":[
+     *          {
+     *             'content':xxxxx,
+     *             'time':xxx-xx-xx,
+     *          },
+     *      ]
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function albumGetStatistical(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        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());
+        }
+        $data = $request->input();
+        if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
+        $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+        if ($data['type'] == 1) {    //尺寸统计
+            $record = AlbumWatchRecord::where([['agent_id',$user_agent->id],['detail','lick','%\u5c3a\u5bf8\u56fe%'],['action',5],['store_id',$data['store_id']]])->get();
+            foreach ($record as $key=>$val){
+                $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$data['store_id']]])->first();
+                $detail = json_decode($val->detail,true);
+                $goods = AlbumProductModel::where([['store_id',$data['store_id'].['id',$detail['goods_id']]]])->first();
+                if (!$goods) {
+                    continue;
+                }
+                $res[] = [
+                    'content' => $user->username . '点击' . $goods->name . $detail['detail'],
+                    'time' => date('Y-m-d H:i',strtotime($val->created_at))
+                ];
+            }
+        } elseif ($data['type'] == 2) {   //拨打电话
+            $record = AlbumWatchRecord::where([['agent_id',$user_agent->id],['action',7],['store_id',$data['store_id']]])->get();
+            foreach ($record as $key=>$val){
+                $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$data['store_id']]])->first();
+                $res[] = [
+                    'content' => $user->username . '拨打了经销商电话',
+                    'time' => date('Y-m-d H:i',strtotime($val->created_at))
+                ];
+            }
+        } else {
+            $record = AlbumWatchRecord::where([['agent_id',$user_agent->id],['action',8],['store_id',$data['store_id']]])->get();
+            foreach ($record as $key=>$val){
+                $goods = AlbumProductModel::where([['store_id',$data['store_id'].['id',$val->detail]]])->first();
+                $style = AlbumProductStyleModel::where([['store_id',$data['store_id'].['id',$goods->style]]])->first();
+                $cat = AlbumCatModel::where([['store_id',$data['store_id'].['id',$goods->cat_id]]])->first();
+                $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$data['store_id']]])->first();
+                $res[] = [
+                    'content' => "$user->username 分享了 $style->name $cat->name $goods->name ",
+                    'time' => date('Y-m-d H:i',strtotime($val->created_at))
+                ];
+            }
+        }
+    }
 }

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

xqd
@@ -21,7 +21,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',
+                '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','albumGetStatistical',
                 'albumGetWatchRecord','albumSetWatch','albumGetCartOfWatch','albumSaveFormId','albumAddAgent','albumGetBanner','albumGetDataGoods','newgoods_list','newgoods_index','albumGetAgentAdress','albumSetCustomer','albumGetCustomer','albumGetDataCat','albumCustomerGoods','albumCustomerGoodsDetail','albumGetDataCatSingle','albumGetCountOfFavorite','albumGetUserInfo','albumStatistical','posterInfo','createPoster','posterDel'
             ]
         ]);

+ 61 - 0
public/apidoc/api_data.js

xqd xqd
@@ -1243,6 +1243,60 @@ define({ "api": [
     "groupTitle": "Album",
     "name": "PostApiAlbumGet_data_goods"
   },
+  {
+    "type": "post",
+    "url": "/api/album/get_statistical",
+    "title": "获取分享记录(get-statistical)",
+    "description": "<p>获取分享记录(get-statistical)</p>",
+    "group": "Album",
+    "permission": [
+      {
+        "name": "AUTH"
+      }
+    ],
+    "version": "0.1.0",
+    "parameter": {
+      "fields": {
+        "Parameter": [
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "store_id",
+            "description": "<p>商户id</p>"
+          },
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "type",
+            "description": "<p>1 尺寸统计 2拨打电话 3 分享</p>"
+          }
+        ]
+      }
+    },
+    "success": {
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"success\",\n    \"data\":[\n         {\n            'content':xxxxx,\n            'time':xxx-xx-xx,\n         },\n     ]\n}",
+          "type": "json"
+        }
+      ]
+    },
+    "error": {
+      "examples": [
+        {
+          "title": "Error-Response:",
+          "content": "HTTP/1.1 400 Bad Request\n{\n    \"state\": false,\n    \"code\": 1000,\n    \"message\": \"传入参数不正确\",\n    \"data\": null or []\n}\n可能出现的错误代码:\n   1000    CLIENT_WRONG_PARAMS             传入参数不正确",
+          "type": "json"
+        }
+      ]
+    },
+    "filename": "app/Http/Controllers/Api/V1/AlbumController.php",
+    "groupTitle": "Album",
+    "name": "PostApiAlbumGet_statistical"
+  },
   {
     "type": "post",
     "url": "/api/album/set-customer",
@@ -1461,6 +1515,13 @@ define({ "api": [
             "optional": true,
             "field": "store_id",
             "description": "<p>商户id</p>"
+          },
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "goods_id",
+            "description": "<p>商品id</p>"
           }
         ]
       }

+ 61 - 0
public/apidoc/api_data.json

xqd xqd
@@ -1243,6 +1243,60 @@
     "groupTitle": "Album",
     "name": "PostApiAlbumGet_data_goods"
   },
+  {
+    "type": "post",
+    "url": "/api/album/get_statistical",
+    "title": "获取分享记录(get-statistical)",
+    "description": "<p>获取分享记录(get-statistical)</p>",
+    "group": "Album",
+    "permission": [
+      {
+        "name": "AUTH"
+      }
+    ],
+    "version": "0.1.0",
+    "parameter": {
+      "fields": {
+        "Parameter": [
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "store_id",
+            "description": "<p>商户id</p>"
+          },
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "type",
+            "description": "<p>1 尺寸统计 2拨打电话 3 分享</p>"
+          }
+        ]
+      }
+    },
+    "success": {
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"success\",\n    \"data\":[\n         {\n            'content':xxxxx,\n            'time':xxx-xx-xx,\n         },\n     ]\n}",
+          "type": "json"
+        }
+      ]
+    },
+    "error": {
+      "examples": [
+        {
+          "title": "Error-Response:",
+          "content": "HTTP/1.1 400 Bad Request\n{\n    \"state\": false,\n    \"code\": 1000,\n    \"message\": \"传入参数不正确\",\n    \"data\": null or []\n}\n可能出现的错误代码:\n   1000    CLIENT_WRONG_PARAMS             传入参数不正确",
+          "type": "json"
+        }
+      ]
+    },
+    "filename": "app/Http/Controllers/Api/V1/AlbumController.php",
+    "groupTitle": "Album",
+    "name": "PostApiAlbumGet_statistical"
+  },
   {
     "type": "post",
     "url": "/api/album/set-customer",
@@ -1461,6 +1515,13 @@
             "optional": true,
             "field": "store_id",
             "description": "<p>商户id</p>"
+          },
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "goods_id",
+            "description": "<p>商品id</p>"
           }
         ]
       }

+ 1 - 1
public/apidoc/api_project.js

xqd
@@ -9,7 +9,7 @@ define({
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2019-03-05T12:04:15.465Z",
+    "time": "2019-03-06T09:03:42.404Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }

+ 1 - 1
public/apidoc/api_project.json

xqd
@@ -9,7 +9,7 @@
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2019-03-05T12:04:15.465Z",
+    "time": "2019-03-06T09:03:42.404Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }

+ 4 - 0
routes/api.php

xqd
@@ -324,6 +324,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'album.statistical',
         'uses' => 'AlbumController@albumStatistical',
     ]);
+    $api->post('album/get_statistical', [
+        'as' => 'album.get_statistical',
+        'uses' => 'AlbumController@albumGetStatistical',
+    ]);
 
     $api->post('album/get_data_cat', [
         'as' => 'album.get_data_cat',