dyjh 6 yıl önce
ebeveyn
işleme
e70f7ff581

+ 165 - 1
app/Http/Controllers/Api/V1/AlbumBossController.php

xqd
@@ -8,10 +8,174 @@
 
 namespace App\Http\Controllers\Api\V1;
 
-
+use App\Models\AlbumAgentModel;
+use App\Models\AlbumUserModel;
+use App\Models\AlbumWatchRecord;
+use App\Models\CustomerDetailsModel;
+use Illuminate\Http\Request;
+use Validator, Response,Auth;
 use App\Services\Base\ErrorCode;
 
 class AlbumBossController extends Controller
 {
+    /**
+     * @api {get} /api/album_boss/get_top 经销商排行榜(get_top)
+     * @apiDescription 经销商排行榜(get_top)
+     * @apiGroup Boss
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [store_id]  商户id
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "agent": [
+     *              {
+     *                  "id": 3,
+     *                  "avatar": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
+     *                  "name": "张三",
+     *                  "get_count": "客户数量",
+     *              }
+     *          ],
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function getTop(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        if (!$userAuth) {
+            return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
+        }
+        $validator = Validator::make($request->all(), [
+            'store_id' => 'required'
+        ], [
+            'store_id.required' => '缺少商户参数',
+        ]);
+
+        if ($userAuth->role != 4) {
+            return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
+        }
+
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $store_id = $request->input('store_id');
+        $agentData = AlbumAgentModel::where('store_id', $store_id)->orderByDesc('get_count')->paginate(20);
+        foreach ($agentData as $value) {
+            $user = AlbumUserModel::where([['id', $value->user_id], ['store_id', $store_id]])->get(['avatar']);
+            $value->avatar = $user->avatar;
+        }
+
+        return $this->api($agentData, 0, 'success');
+    }
+
+    /**
+     * @api {post} /api/album_boss/agent_customer 经销商客户(agent_customer)
+     * @apiDescription 经销商客户(agent_customer)
+     * @apiGroup Boss
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [store_id]  商户id
+     * @apiParam {int}    [agent_id]  经销商id
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "agent": [
+     *              {
+     *                  "id": 3,
+     *                  "avatar": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
+     *                  "name": "张三",
+     *                  "address": "四川省",
+     *                  "phone": "8208208820",
+     *                  "lon": "100.123123",
+     *                  "lat": "123.123123",
+     *              }
+     *          ],
+     *         "customer": [
+     *              {
+     *                  "id": 3,
+     *                  "avatar": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
+     *                  "name": "张三",
+     *                  "address": "四川省甘肃市"
+     *               }
+     *          ]
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function agentCustomer(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        if (!$userAuth) {
+            return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
+        }
+        $validator = Validator::make($request->all(), [
+            'store_id' => 'required',
+            'agent_id' => 'required',
+            'pageNum' => 'required',
+        ], [
+            'store_id.required' => '缺少商户参数',
+            'agent_id.required' => '缺少经销商参数',
+            'pageNum.required' => '缺少页码参数',
+        ]);
+
+        if ($userAuth->role != 4) {
+            return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
+        }
+
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+
+        $data = $request->input();
+        $agent = AlbumAgentModel::where([['store_id', $data['store_id']], ['id', $data['agent_id']]])->first();
+        $userCount = AlbumWatchRecord::where([
+            ['agent_id', $agent->id], ['store_id',$data['store_id']]
+        ])->groupBy('open_id')->get();
+        $i = 0;
+        foreach ($userCount as $value) {
+            if ($i >= (($data['pageNum'] + 1) * 20)) {
+                break;
+            }
+            if ($i >= ($data['pageNum'] * 20) && $i < (($data['pageNum'] + 1) * 20)) {
+                $user = AlbumUserModel::where('open_id', $value->open_id)->first(['avatar', 'username', 'address']);
+                $userComment = CustomerDetailsModel::where('open_id', $value->open_id)->first(['comment']);
+                $customer[] = [
+                    'name' => $userComment->comment,
+                    'avatar' => $user->avatar,
+                    'username' => $user->username,
+                    'address' => $user->address
+                ];
+                $i++;
+            }
+        }
 
+        return $this->api(compact('agent', 'customer'), 0, 'success');
+    }
 }

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

+ 3 - 0
app/Models/AlbumUserModel.php

xqd
@@ -40,6 +40,9 @@ class AlbumUserModel extends Authenticatable
     protected $fillable = [
         'username',
         'wechat_open_id',
+        'address',
+        'lng',
+        'lat',
         'g_open_id',
         'open_id',
         'wechat_union_id',

+ 2 - 0
app/Services/Base/ErrorCode.php

xqd xqd
@@ -14,6 +14,7 @@ namespace App\Services\Base;
 
 final class ErrorCode {
     //错误常量定义
+    const NOT_BOSS = 606;
     const ATTACHMENT_DELETE_FAILED = 605;
     const ATTACHMENT_MOVE_FAILED = 604;
     const ATTACHMENT_RECORD_DELETE_FAILED = 606;
@@ -76,6 +77,7 @@ final class ErrorCode {
 
     //错误常量枚举
     private static $_msg = [
+        self::NOT_BOSS => '该用户没有Boss权限',
         self::ORDER_NOT_EXIST => '订单没有找到',
         self::APPID_NOT_EXIST => 'appid不存在',
         self::ADDRESS_NOT_EXIST => '地址不存在',

+ 35 - 0
database/migrations/2019_04_14_105335_add_address_info_to_album_user.php

xqd
@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddAddressInfoToAlbumUser extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('album_user', function (Blueprint $table) {
+            //
+            $table->string('address', 255)->nullable()->default(null)->comment('地址');
+            $table->string('lng', 100)->nullable()->default(null);
+            $table->string('lat', 100)->nullable()->default(null);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('album_user', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 7 - 1
routes/api.php

xqd
@@ -493,6 +493,12 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'furniture.newgoods_addbooking',
         'uses' => 'FurnitureController@newgoods_addbooking',
     ]);
-
+/*
+ *  AlbumBoss
+ */
+    $api->get('album_boss/get_top', [
+        'as' => 'album_boss.get_top',
+        'uses' => 'AlbumBossController@getTop',
+    ]);
 
 });