123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907 |
- <?php
- /**
- * Created by PhpStorm.
- * User: 思维定制
- * Date: 2019/4/11
- * Time: 17:41
- */
- namespace App\Http\Controllers\Api\V1;
- use App\Models\AlbumAgentModel;
- use App\Models\AlbumCatModel;
- use App\Models\AlbumProductModel;
- use App\Models\AlbumUserModel;
- use App\Models\AlbumWatchRecord;
- use App\Models\CustomerCatRecordModel;
- 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();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required'
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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]])->first(['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
- * @apiParam {int} [pageNum] 分页
- * @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();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'agent_id' => 'required',
- 'pageNum' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- 'agent_id.required' => '缺少经销商参数',
- 'pageNum.required' => '缺少页码参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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) && $i < ($data['pageNum'] * 20)) {
- $user = AlbumUserModel::where('open_id', $value->open_id)->first(['avatar', 'username', 'address']);
- $userComment = CustomerDetailsModel::where('open_id', $value->open_id)->first(['comment']);
- if (empty($user->phone)) {
- $phone = '暂无';
- } else {
- $phone = $user->phone;
- }
- if (!$userComment) {
- $customer[] = [
- 'name' => '暂无',
- 'avatar' => $user->avatar,
- 'username' => $user->username,
- 'phone' => $phone
- ];
- } else {
- $customer[] = [
- 'name' => $userComment->comment,
- 'avatar' => $user->avatar,
- 'username' => $user->username,
- 'phone' => $phone
- ];
- }
- }
- $i++;
- }
- return $this->api(compact('agent', 'customer'), 0, 'success');
- }
- /**
- * @api {post} /api/album_boss/agent_statistical 经销商数据(agent_statistical)
- * @apiDescription 经销商数据(agent_statistical)
- * @apiGroup Boss
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [agent_id] 经销商id
- * @apiParam {int} [start] 开始时间
- * @apiParam {int} [end] 结束时间
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "favoriteCount":11,
- * "downloadCount":11,
- * "shareCount":11,
- * "newCustomerCount":11,
- * "totalCustomerCount":11,
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function agentStatistical(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- 'agent_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- 'agent_id.required' => '缺少经销商参数',
- ]);
- if ($userAuth->is_boss != 1) {
- return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
- }
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $data = $request->input();
- $end = $request->input('end');
- $start = $request->input('start');
- if (!$end) {
- $end = time();
- }
- if (!$start) {
- $start = 0;
- }
- $end = date('Y-m-d H:i:s', $end);
- $start = date('Y-m-d H:i:s', $start);
- $favoriteCount = AlbumWatchRecord::where([
- ['agent_id', $data['agent_id']],
- ['store_id', $data['store_id']],
- ['action', 1],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $downloadCount = AlbumWatchRecord::where([
- ['agent_id', $data['agent_id']],
- ['store_id', $data['store_id']],
- ['action', 9],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $shareCount = AlbumWatchRecord::where([
- ['agent_id', $data['agent_id']],
- ['store_id', $data['store_id']],
- ['action', 8],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $newCustomerCount = AlbumWatchRecord::where([
- ['agent_id', $data['agent_id']],
- ['store_id', $data['store_id']],
- ['is_new', 1],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $totalCustomer = AlbumWatchRecord::where([
- ['agent_id', $data['agent_id']],
- ['store_id', $data['store_id']],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->groupBy('open_id')->get();
- $totalCustomerCount = count($totalCustomer);
- return $this->api(compact('shareCount', 'totalCustomerCount', 'newCustomerCount', 'downloadCount', 'favoriteCount'));
- }
- /**
- * @api {post} /api/album_boss/agent_overview_active 经销商总览活跃客户(agent_overview_active)
- * @apiDescription 经销商总览活跃客户(agent_overview_active)
- * @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": {
- * "activeCustomers": [
- * {
- * "day" : 03/25,
- * "num" : 111
- * }
- * ],
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumOverviewActive(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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');
- $activeCustomers = array();
- for ($d = 0; $d < 15; $d++) {
- $StartO = mktime(0, 0, 0, date('m'), date('d'), date('y')) - 86400 * $d;
- $EndO = $StartO + 86400;
- $End = date('Y-m-d H:i:s', $EndO);
- $Start = date('Y-m-d H:i:s', $StartO);
- $customerNum = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['updated_at','>=',$Start],
- ['updated_at','<=',$End]
- ])->orderByDesc('id')->groupBy('open_id')->count();
- $activeCustomers[] = [
- 'day' => date('m', $StartO) . '-' . date('d', $EndO),
- 'num' => $customerNum
- ];
- }
- return $this->api($activeCustomers);
- }
- /**
- * @api {post} /api/album_boss/agent_overview_left 经销商总览左侧(agent_overview_left)
- * @apiDescription 经销商总览左侧(agent_overview_left)
- * @apiGroup Boss
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [start] 开始时间
- * @apiParam {int} [end] 结束时间
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "customerFollow":11,
- * "downloadCount":11,
- * "shareCount":11,
- * "newCustomerCount":11,
- * "totalCustomerCount":11,
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumOverviewLeft(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
- }
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $end = $request->input('end');
- $start = $request->input('start');
- $store_id = $request->input('store_id');
- if (!$end) {
- $end = time();
- }
- if (!$start) {
- $start = 0;
- }
- $end = date('Y-m-d H:i:s', $end);
- $start = date('Y-m-d H:i:s', $start);
- $customerFollow = CustomerDetailsModel::where([
- ['store_id', $store_id],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->count();
- $downloadCount = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['action', 9],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $shareCount = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['action', 8],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $newCustomerCount = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['is_new', 1],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->count();
- $totalCustomer = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->orderByDesc('id')->groupBy('open_id')->get()->toArray();
- $totalCustomerCount = count($totalCustomer);
- return $this->api(compact('totalCustomerCount', 'newCustomerCount', 'shareCount', 'downloadCount', 'customerFollow'));
- }
- /**
- * @api {post} /api/album_boss/agent_overview_funnel 经销商总览漏斗(agent_overview_funnel)
- * @apiDescription 经销商总览漏斗(agent_overview_funnel)
- * @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": {
- * "customerFollow":11,
- * "shareCount":11,
- * "totalCustomerCount":11,
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumOverviewFunnel(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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');
- $customerFollow = CustomerDetailsModel::where('store_id', $store_id)->count();
- $shareCount = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['action', 8],
- ])->orderByDesc('id')->count();
- $totalCustomer = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ])->orderByDesc('id')->groupBy('open_id')->get()->toArray();
- $totalCustomerCount = count($totalCustomer);
- return $this->api(compact('totalCustomerCount', 'shareCount', 'customerFollow'));
- }
- /**
- * @api {post} /api/album_boss/agent_overview_call 经销商总览咨询(agent_overview_call)
- * @apiDescription 经销商总览咨询(agent_overview_call)
- * @apiGroup Boss
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [day] 天数
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "callCustomers": [
- * {
- * "day" : 03/25,
- * "num" : 111
- * }
- * ]
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumOverviewCall(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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');
- $day = $request->input('day');
- $callCustomers = array();
- for ($d = 0; $d < $day; $d++) {
- $StartO = mktime(0, 0, 0, date('m'), date('d'), date('y')) - 86400 * $d;
- $EndO = $StartO + 86400;
- $End = date('Y-m-d H:i:s', $EndO);
- $Start = date('Y-m-d H:i:s', $StartO);
- $callCustomer = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['action', 7],
- ['updated_at','>=',$Start],
- ['updated_at','<=',$End]
- ])->orderByDesc('id')->count();
- $callCustomers[] = [
- 'day' => date('m', $StartO) . '-' . date('d', $EndO),
- 'num' => $callCustomer
- ];
- }
- return $this->api($callCustomers);
- }
- /**
- * @api {post} /api/album_boss/agent_overview_favorite 经销商总览兴趣占比(agent_overview_favorite)
- * @apiDescription 经销商总览兴趣占比(agent_overview_favorite)
- * @apiGroup Boss
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [parent_id] 商户id
- * @apiParam {int} [start] 开始时间
- * @apiParam {int} [end] 结束时间
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "arrFavorite": [
- * {
- * '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 albumOverviewFavorite(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
- }
- if ($validator->fails()) {
- return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
- }
- $end = $request->input('end');
- $start = $request->input('start');
- $store_id = $request->input('store_id');
- if (!$end) {
- $end = time();
- }
- if (!$start) {
- $start = 0;
- }
- $end = date('Y-m-d H:i:s', $end);
- $start = date('Y-m-d H:i:s', $start);
- $parent_id = $request->input('parent_id');
- $cat = AlbumCatModel::where([['store_id',$store_id],['parent_id', $parent_id]])->get(['name','id'])->toArray();
- $total = 0;
- foreach ($cat as $key => $val) {
- $count = CustomerCatRecordModel::where([
- ['store_id',$store_id],
- ['cat_id',$val['id']],
- ['updated_at','>=',$start],
- ['updated_at','<=',$end]
- ])->count();
- $total += $count;
- $cat[$key]['num'] = $count;
- }
- foreach ($cat as $key => $val) {
- if ($val['num'] == 0 || $total == 0) {
- $cat[$key]['point'] = 0;
- } else {
- $cat[$key]['point'] = ($val['num'] / $total * 100) . '%';
- }
- }
- return $this->api($cat);
- }
- /**
- * @api {post} /api/album_boss/agent_overview_new 经销商总览新增客户(agent_overview_new)
- * @apiDescription 经销商总览新增客户(agent_overview_new)
- * @apiGroup Boss
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} [store_id] 商户id
- * @apiParam {int} [day] 天数
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "newCustomers": [
- * {
- * "day" : 03/25,
- * "num" : 111
- * }
- * ]
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function albumOverviewNew(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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');
- $day = $request->input('day');
- $newCustomers = array();
- for ($d = 0; $d < $day; $d++) {
- $StartO = mktime(0, 0, 0, date('m'), date('d'), date('y')) - 86400 * $d;
- $EndO = $StartO + 86400;
- $End = date('Y-m-d H:i:s', $EndO);
- $Start = date('Y-m-d H:i:s', $StartO);
- $newCustomer = AlbumWatchRecord::where([
- ['store_id', $store_id],
- ['is_new', 1],
- ['updated_at','>=',$Start],
- ['updated_at','<=',$End]
- ])->orderByDesc('id')->count();
- $newCustomers[] = [
- 'day' => date('m', $StartO) . '-' . date('d', $EndO),
- 'num' => $newCustomer
- ];
- }
- return $this->api($newCustomers);
- }
- /**
- * @api {post} /api/album_boss/agent_analysis 经销商分析(agent_analysis)
- * @apiDescription 经销商分析(agent_analysis)
- * @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": [
- * {
- * "realname" : 释迦摩尼,
- * "pointCount" : 111
- * "callCount" : 111
- * "favoriteCount" : 111
- * "get_count" : 111
- * "share_times" : 111
- * "newCount" : 111
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function agentAnalysis(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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');
- $agent = AlbumAgentModel::where('store_id', $store_id)->orderByDesc('newCount')->paginate(12);
- foreach ($agent as $value) {
- $user = AlbumUserModel::where([['id', $value->user_id], ['store_id', $store_id]])->first(['avatar']);
- $value->avatar = $user->avatar;
- }
- return $this->api($agent);
- }
- /**
- * @api {get} /api/album_boss/boss_interactive 经销商互动排名(boss_interactive)
- * @apiDescription 经销商互动排名(boss_interactive)
- * @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": [
- * {
- * "realname" : 释迦摩尼,
- * "interactive" : 111
- * "avatar" : 111
- * }
- * ]
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function BossInteractive(Request $request)
- {
- $userAuth = Auth('api')->user();
- $validator = Validator::make($request->all(), [
- 'store_id' => 'required',
- ], [
- 'store_id.required' => '缺少商户参数',
- ]);
- if ($userAuth->is_boss != 1) {
- 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');
- $agent = AlbumAgentModel::where('store_id', $store_id)->orderByDesc('interactive')->paginate(20);
- foreach ($agent as $value) {
- $user = AlbumUserModel::where([['id', $value->user_id], ['store_id', $store_id]])->first(['avatar']);
- $value->avatar = $user->avatar;
- }
- return $this->api($agent);
- }
- }
|