dyjh 6 年之前
父節點
當前提交
487ad93f74

+ 81 - 1
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd xqd xqd xqd
@@ -20,6 +20,7 @@ use App\Models\AlbumProductStyleModel;
 use App\Models\AlbumUserModel;
 use App\Models\AlbumWatchRecord;
 use App\Models\AlbumXyxUserModel;
+use App\Models\CustomerCatRecordModel;
 use App\User;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
@@ -431,6 +432,12 @@ class AlbumController extends Controller
             $add_record['store_id'] = $store_id;
             $add_record['detail'] = json_encode($select_info);
             AlbumWatchRecord::create($add_record);
+            $cat_record['agent_id'] = $userAuth->up_agent_id;
+            $cat_record['open_id'] = $userAuth->wechat_open_id;
+            $cat_record['store_id'] = $store_id;
+            $cat_record['style_id'] = $style;
+            $cat_record['cat_id'] = $cat_id;
+            CustomerCatRecordModel::create($cat_record);
             $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
             $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
             try{
@@ -846,6 +853,7 @@ class AlbumController extends Controller
      *          {
      *              "1": [
      *                  'name':'asdawd',
+     *                  'point':'asdawd',
      *                  'num':'1',
      *              ],
      *          }
@@ -880,6 +888,7 @@ class AlbumController extends Controller
         $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
         $res = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['action',3]])->get();
         $arr = array();
+        $total = 0;
         foreach($res as $key=>$val){
             $goods_data = json_decode($val->detail,true);
             $goods_id = $goods_data['goods_id'];
@@ -890,11 +899,82 @@ class AlbumController extends Controller
                 $arr[$goods->id]['num']=1;
                 $arr[$goods->id]['name']=$goods->name;
             }
-
+            $total++;
+        }
+        foreach($arr as $key=>$val){
+            $arr[$key]['point'] = ($val['num']/$total*100).'%';
         }
         return $this->api(compact('arr'));
     }
 
+
+    /**
+     * @api {post} /api/album/get_data_cat 获取分类访问数据(get_data_cat)
+     * @apiDescription 获取分类访问数据(get_data_cat)
+     * @apiGroup Album
+     * @apiPermission 需要登录
+     * @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": [
+     *          {
+     *              "1": [
+     *                  'name':'asdawd',
+     *                  'point':'asdawd',
+     *                  'num':'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 albumGetDataCat(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
+        $validator = Validator::make($request->all(), [
+            'store_id' => 'required',
+            'style_id' => 'required'
+        ],[
+            'store_id.required'=>'缺少商户参数',
+            'style_id.required'=>'缺少风格参数',
+        ]);
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $store_id = $request->input('store_id');
+        $style_id = $request->input('style_id');
+        if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
+
+        $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+        $cat = AlbumCatModel::where('store_id',$store_id)->get(['name','id'])->toArray();
+        $total = 0;
+        foreach ($cat as $key=>$val){
+            $count = CustomerCatRecordModel::where([['agent_id',$user_agent->id],['store_id',$store_id],['style_id',$style_id],['cat_id',$val['id']]])->count();
+            $total += $count;
+            $cat[$key]['num'] = $count;
+        }
+        foreach($cat as $key=>$val){
+            $cat[$key]['point'] = ($val['num']/$total*100).'%';
+        }
+        return $this->api(compact('cat'));
+    }
+
+
     /**
      * @api {post} /api/album/get-cart-of-watch 客户浏览情况概览(get-cart-of-watch)
      * @apiDescription 客户浏览情况概览(get-cart-of-watch)

+ 36 - 0
app/Models/CustomerCatRecordModel.php

xqd
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2019/1/19
+ * Time: 16:30
+ */
+
+namespace App\Models;
+
+
+class CustomerCatRecordModel extends BaseModel
+{
+    protected $table = 'customer_cat_record';
+
+    /**
+    主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'agent_id',
+        'store_id',
+        'open_id',
+        'cat_id',
+        'style_id',
+    ];
+}

+ 37 - 0
app/Models/CustomerDetailsModel.php

xqd
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2019/1/19
+ * Time: 15:44
+ */
+
+namespace App\Models;
+
+
+class CustomerDetailsModel extends BaseModel
+{
+    protected $table = 'customer_details';
+
+    /**
+    主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'agent_id',
+        'store_id',
+        'open_id',
+        'tips',
+        'comment',
+        'purpose_level',
+    ];
+}

+ 37 - 0
database/migrations/2019_01_19_152156_create_table_customer_details.php

xqd
@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableCustomerDetails extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('customer_details', function (Blueprint $table) {
+            $table->increments('id');
+            $table->unsignedInteger('agent_id')->comment('经销商id');
+            $table->unsignedInteger('store_id')->comment('store_id');
+            $table->unsignedInteger('open_id')->comment('open_id');
+            $table->string('tips',255)->nullable()->default(null)->comment('标签');
+            $table->unsignedInteger('purpose_level')->default(1)->comment('意向等级 1 25% 2 50% 3 75% 4 100%');
+            $table->string('comment',255)->nullable()->default(null)->comment('备注');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('customer_details');
+    }
+}

+ 36 - 0
database/migrations/2019_01_19_161909_create_table_customer_cat_record.php

xqd
@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableCustomerCatRecord extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('customer_cat_record', function (Blueprint $table) {
+            $table->increments('id');
+            $table->unsignedInteger('store_id')->comment('store_id');
+            $table->unsignedInteger('open_id')->comment('open_id');
+            $table->unsignedInteger('agent_id')->comment('agent_id');
+            $table->unsignedInteger('cat_id')->comment('cat_id');
+            $table->unsignedInteger('style_id')->comment('style_id');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('customer_cat_record');
+    }
+}

+ 48 - 1
public/apidoc/api_data.js

xqd xqd
@@ -852,6 +852,53 @@ define({ "api": [
     "groupTitle": "Album",
     "name": "PostApiAlbumGetWatchRecored"
   },
+  {
+    "type": "post",
+    "url": "/api/album/get_data_cat",
+    "title": "获取分类访问数据(get_data_cat)",
+    "description": "<p>获取分类访问数据(get_data_cat)</p>",
+    "group": "Album",
+    "permission": [
+      {
+        "name": "需要登录"
+      }
+    ],
+    "version": "0.1.0",
+    "parameter": {
+      "fields": {
+        "Parameter": [
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "store_id",
+            "description": "<p>商户id 模拟值为0</p>"
+          }
+        ]
+      }
+    },
+    "success": {
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"\",\n    \"data\": [\n         {\n             \"1\": [\n                 'name':'asdawd',\n                 'point':'asdawd',\n                 'num':'1',\n             ],\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_data_cat"
+  },
   {
     "type": "post",
     "url": "/api/album/get_data_goods",
@@ -881,7 +928,7 @@ define({ "api": [
       "examples": [
         {
           "title": "Success-Response:",
-          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"\",\n    \"data\": [\n         {\n             \"1\": [\n                 'name':'asdawd',\n                 'num':'1',\n             ],\n         }\n     ]\n}",
+          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"\",\n    \"data\": [\n         {\n             \"1\": [\n                 'name':'asdawd',\n                 'point':'asdawd',\n                 'num':'1',\n             ],\n         }\n     ]\n}",
           "type": "json"
         }
       ]

+ 48 - 1
public/apidoc/api_data.json

xqd xqd
@@ -852,6 +852,53 @@
     "groupTitle": "Album",
     "name": "PostApiAlbumGetWatchRecored"
   },
+  {
+    "type": "post",
+    "url": "/api/album/get_data_cat",
+    "title": "获取分类访问数据(get_data_cat)",
+    "description": "<p>获取分类访问数据(get_data_cat)</p>",
+    "group": "Album",
+    "permission": [
+      {
+        "name": "需要登录"
+      }
+    ],
+    "version": "0.1.0",
+    "parameter": {
+      "fields": {
+        "Parameter": [
+          {
+            "group": "Parameter",
+            "type": "int",
+            "optional": true,
+            "field": "store_id",
+            "description": "<p>商户id 模拟值为0</p>"
+          }
+        ]
+      }
+    },
+    "success": {
+      "examples": [
+        {
+          "title": "Success-Response:",
+          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"\",\n    \"data\": [\n         {\n             \"1\": [\n                 'name':'asdawd',\n                 'point':'asdawd',\n                 'num':'1',\n             ],\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_data_cat"
+  },
   {
     "type": "post",
     "url": "/api/album/get_data_goods",
@@ -881,7 +928,7 @@
       "examples": [
         {
           "title": "Success-Response:",
-          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"\",\n    \"data\": [\n         {\n             \"1\": [\n                 'name':'asdawd',\n                 'num':'1',\n             ],\n         }\n     ]\n}",
+          "content": "HTTP/1.1 200 OK\n{\n    \"status\": true,\n    \"status_code\": 0,\n    \"message\": \"\",\n    \"data\": [\n         {\n             \"1\": [\n                 'name':'asdawd',\n                 'point':'asdawd',\n                 'num':'1',\n             ],\n         }\n     ]\n}",
           "type": "json"
         }
       ]

+ 1 - 1
public/apidoc/api_project.js

xqd
@@ -9,7 +9,7 @@ define({
   "apidoc": "0.3.0",
   "generator": {
     "name": "apidoc",
-    "time": "2018-12-25T08:29:03.910Z",
+    "time": "2019-01-19T09:06:36.046Z",
     "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": "2018-12-25T08:29:03.910Z",
+    "time": "2019-01-19T09:06:36.046Z",
     "url": "http://apidocjs.com",
     "version": "0.17.6"
   }

+ 5 - 0
routes/api.php

xqd
@@ -298,6 +298,11 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'uses' => 'AlbumController@albumGetDataGoods',
     ]);
 
+    $api->post('album/get_data_cat', [
+        'as' => 'album.get_data_cat',
+        'uses' => 'AlbumController@albumGetDataCat',
+    ]);
+
     $api->get('album/favorite_list', [
         'as' => 'album.favorite_list',
         'uses' => 'AlbumController@albumFavoriteList',