AlbumBossController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 思维定制
  5. * Date: 2019/4/11
  6. * Time: 17:41
  7. */
  8. namespace App\Http\Controllers\Api\V1;
  9. use App\Models\AlbumAgentModel;
  10. use App\Models\AlbumCatModel;
  11. use App\Models\AlbumProductModel;
  12. use App\Models\AlbumUserModel;
  13. use App\Models\AlbumWatchRecord;
  14. use App\Models\CustomerCatRecordModel;
  15. use App\Models\CustomerDetailsModel;
  16. use Illuminate\Http\Request;
  17. use Validator, Response,Auth;
  18. use App\Services\Base\ErrorCode;
  19. class AlbumBossController extends Controller
  20. {
  21. /**
  22. * @api {get} /api/album_boss/get_top 经销商排行榜(get_top)
  23. * @apiDescription 经销商排行榜(get_top)
  24. * @apiGroup Boss
  25. * @apiPermission none
  26. * @apiVersion 0.1.0
  27. * @apiParam {int} [store_id] 商户id
  28. * @apiSuccessExample {json} Success-Response:
  29. * HTTP/1.1 200 OK
  30. * {
  31. * "status": true,
  32. * "status_code": 0,
  33. * "message": "",
  34. * "data": {
  35. * "agent": [
  36. * {
  37. * "id": 3,
  38. * "avatar": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  39. * "name": "张三",
  40. * "get_count": "客户数量",
  41. * }
  42. * ],
  43. * }
  44. * }
  45. * @apiErrorExample {json} Error-Response:
  46. * HTTP/1.1 400 Bad Request
  47. * {
  48. * "state": false,
  49. * "code": 1000,
  50. * "message": "传入参数不正确",
  51. * "data": null or []
  52. * }
  53. * 可能出现的错误代码:
  54. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  55. */
  56. public function getTop(Request $request)
  57. {
  58. $userAuth = Auth('api')->user();
  59. $validator = Validator::make($request->all(), [
  60. 'store_id' => 'required'
  61. ], [
  62. 'store_id.required' => '缺少商户参数',
  63. ]);
  64. if ($userAuth->is_boss != 1) {
  65. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  66. }
  67. if ($validator->fails()) {
  68. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  69. }
  70. $store_id = $request->input('store_id');
  71. $agentData = AlbumAgentModel::where('store_id', $store_id)->orderByDesc('get_count')->paginate(20);
  72. foreach ($agentData as $value) {
  73. $user = AlbumUserModel::where([['id', $value->user_id], ['store_id', $store_id]])->first(['avatar']);
  74. $value->avatar = $user->avatar;
  75. }
  76. return $this->api($agentData, 0, 'success');
  77. }
  78. /**
  79. * @api {post} /api/album_boss/agent_customer 经销商客户(agent_customer)
  80. * @apiDescription 经销商客户(agent_customer)
  81. * @apiGroup Boss
  82. * @apiPermission none
  83. * @apiVersion 0.1.0
  84. * @apiParam {int} [store_id] 商户id
  85. * @apiParam {int} [agent_id] 经销商id
  86. * @apiParam {int} [pageNum] 分页
  87. * @apiSuccessExample {json} Success-Response:
  88. * HTTP/1.1 200 OK
  89. * {
  90. * "status": true,
  91. * "status_code": 0,
  92. * "message": "",
  93. * "data": {
  94. * "agent": [
  95. * {
  96. * "id": 3,
  97. * "avatar": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  98. * "name": "张三",
  99. * "address": "四川省",
  100. * "phone": "8208208820",
  101. * "lon": "100.123123",
  102. * "lat": "123.123123",
  103. * }
  104. * ],
  105. * "customer": [
  106. * {
  107. * "id": 3,
  108. * "avatar": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  109. * "name": "张三",
  110. * "address": "四川省甘肃市"
  111. * }
  112. * ]
  113. * }
  114. * }
  115. * @apiErrorExample {json} Error-Response:
  116. * HTTP/1.1 400 Bad Request
  117. * {
  118. * "state": false,
  119. * "code": 1000,
  120. * "message": "传入参数不正确",
  121. * "data": null or []
  122. * }
  123. * 可能出现的错误代码:
  124. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  125. */
  126. public function agentCustomer(Request $request)
  127. {
  128. $userAuth = Auth('api')->user();
  129. $validator = Validator::make($request->all(), [
  130. 'store_id' => 'required',
  131. 'agent_id' => 'required',
  132. 'pageNum' => 'required',
  133. ], [
  134. 'store_id.required' => '缺少商户参数',
  135. 'agent_id.required' => '缺少经销商参数',
  136. 'pageNum.required' => '缺少页码参数',
  137. ]);
  138. if ($userAuth->is_boss != 1) {
  139. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  140. }
  141. if ($validator->fails()) {
  142. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  143. }
  144. $data = $request->input();
  145. $agent = AlbumAgentModel::where([['store_id', $data['store_id']], ['id', $data['agent_id']]])->first();
  146. $userCount = AlbumWatchRecord::where([
  147. ['agent_id', $agent->id], ['store_id',$data['store_id']]
  148. ])->groupBy('open_id')->get();
  149. $i = 0;
  150. foreach ($userCount as $value) {
  151. if ($i >= (($data['pageNum'] - 1) * 20) && $i < ($data['pageNum'] * 20)) {
  152. $user = AlbumUserModel::where('open_id', $value->open_id)->first(['avatar', 'username', 'address']);
  153. $userComment = CustomerDetailsModel::where('open_id', $value->open_id)->first(['comment']);
  154. if (empty($user->phone)) {
  155. $phone = '暂无';
  156. } else {
  157. $phone = $user->phone;
  158. }
  159. if (!$userComment) {
  160. $customer[] = [
  161. 'name' => '暂无',
  162. 'avatar' => $user->avatar,
  163. 'username' => $user->username,
  164. 'phone' => $phone
  165. ];
  166. } else {
  167. $customer[] = [
  168. 'name' => $userComment->comment,
  169. 'avatar' => $user->avatar,
  170. 'username' => $user->username,
  171. 'phone' => $phone
  172. ];
  173. }
  174. }
  175. $i++;
  176. }
  177. return $this->api(compact('agent', 'customer'), 0, 'success');
  178. }
  179. /**
  180. * @api {post} /api/album_boss/agent_statistical 经销商数据(agent_statistical)
  181. * @apiDescription 经销商数据(agent_statistical)
  182. * @apiGroup Boss
  183. * @apiPermission none
  184. * @apiVersion 0.1.0
  185. * @apiParam {int} [store_id] 商户id
  186. * @apiParam {int} [agent_id] 经销商id
  187. * @apiParam {int} [start] 开始时间
  188. * @apiParam {int} [end] 结束时间
  189. * @apiSuccessExample {json} Success-Response:
  190. * HTTP/1.1 200 OK
  191. * {
  192. * "status": true,
  193. * "status_code": 0,
  194. * "message": "",
  195. * "data": {
  196. * "favoriteCount":11,
  197. * "downloadCount":11,
  198. * "shareCount":11,
  199. * "newCustomerCount":11,
  200. * "totalCustomerCount":11,
  201. * }
  202. * }
  203. * @apiErrorExample {json} Error-Response:
  204. * HTTP/1.1 400 Bad Request
  205. * {
  206. * "state": false,
  207. * "code": 1000,
  208. * "message": "传入参数不正确",
  209. * "data": null or []
  210. * }
  211. * 可能出现的错误代码:
  212. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  213. */
  214. public function agentStatistical(Request $request)
  215. {
  216. $userAuth = Auth('api')->user();
  217. $validator = Validator::make($request->all(), [
  218. 'store_id' => 'required',
  219. 'agent_id' => 'required',
  220. ], [
  221. 'store_id.required' => '缺少商户参数',
  222. 'agent_id.required' => '缺少经销商参数',
  223. ]);
  224. if ($userAuth->is_boss != 1) {
  225. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  226. }
  227. if ($validator->fails()) {
  228. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  229. }
  230. $data = $request->input();
  231. $end = $request->input('end');
  232. $start = $request->input('start');
  233. if (!$end) {
  234. $end = time();
  235. }
  236. if (!$start) {
  237. $start = 0;
  238. }
  239. $end = date('Y-m-d H:i:s', $end);
  240. $start = date('Y-m-d H:i:s', $start);
  241. $favoriteCount = AlbumWatchRecord::where([
  242. ['agent_id', $data['agent_id']],
  243. ['store_id', $data['store_id']],
  244. ['action', 1],
  245. ['updated_at','>=',$start],
  246. ['updated_at','<=',$end]
  247. ])->orderByDesc('id')->count();
  248. $downloadCount = AlbumWatchRecord::where([
  249. ['agent_id', $data['agent_id']],
  250. ['store_id', $data['store_id']],
  251. ['action', 9],
  252. ['updated_at','>=',$start],
  253. ['updated_at','<=',$end]
  254. ])->orderByDesc('id')->count();
  255. $shareCount = AlbumWatchRecord::where([
  256. ['agent_id', $data['agent_id']],
  257. ['store_id', $data['store_id']],
  258. ['action', 8],
  259. ['updated_at','>=',$start],
  260. ['updated_at','<=',$end]
  261. ])->orderByDesc('id')->count();
  262. $newCustomerCount = AlbumWatchRecord::where([
  263. ['agent_id', $data['agent_id']],
  264. ['store_id', $data['store_id']],
  265. ['is_new', 1],
  266. ['updated_at','>=',$start],
  267. ['updated_at','<=',$end]
  268. ])->orderByDesc('id')->count();
  269. $totalCustomer = AlbumWatchRecord::where([
  270. ['agent_id', $data['agent_id']],
  271. ['store_id', $data['store_id']],
  272. ['updated_at','>=',$start],
  273. ['updated_at','<=',$end]
  274. ])->orderByDesc('id')->groupBy('open_id')->get();
  275. $totalCustomerCount = count($totalCustomer);
  276. return $this->api(compact('shareCount', 'totalCustomerCount', 'newCustomerCount', 'downloadCount', 'favoriteCount'));
  277. }
  278. /**
  279. * @api {post} /api/album_boss/agent_overview_active 经销商总览活跃客户(agent_overview_active)
  280. * @apiDescription 经销商总览活跃客户(agent_overview_active)
  281. * @apiGroup Boss
  282. * @apiPermission none
  283. * @apiVersion 0.1.0
  284. * @apiParam {int} [store_id] 商户id
  285. * @apiSuccessExample {json} Success-Response:
  286. * HTTP/1.1 200 OK
  287. * {
  288. * "status": true,
  289. * "status_code": 0,
  290. * "message": "",
  291. * "data": {
  292. * "activeCustomers": [
  293. * {
  294. * "day" : 03/25,
  295. * "num" : 111
  296. * }
  297. * ],
  298. * }
  299. * }
  300. * @apiErrorExample {json} Error-Response:
  301. * HTTP/1.1 400 Bad Request
  302. * {
  303. * "state": false,
  304. * "code": 1000,
  305. * "message": "传入参数不正确",
  306. * "data": null or []
  307. * }
  308. * 可能出现的错误代码:
  309. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  310. */
  311. public function albumOverviewActive(Request $request)
  312. {
  313. $userAuth = Auth('api')->user();
  314. $validator = Validator::make($request->all(), [
  315. 'store_id' => 'required',
  316. ], [
  317. 'store_id.required' => '缺少商户参数',
  318. ]);
  319. if ($userAuth->is_boss != 1) {
  320. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  321. }
  322. if ($validator->fails()) {
  323. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  324. }
  325. $store_id = $request->input('store_id');
  326. $activeCustomers = array();
  327. for ($d = 0; $d < 15; $d++) {
  328. $StartO = mktime(0, 0, 0, date('m'), date('d'), date('y')) - 86400 * $d;
  329. $EndO = $StartO + 86400;
  330. $End = date('Y-m-d H:i:s', $EndO);
  331. $Start = date('Y-m-d H:i:s', $StartO);
  332. $customerNum = AlbumWatchRecord::where([
  333. ['store_id', $store_id],
  334. ['updated_at','>=',$Start],
  335. ['updated_at','<=',$End]
  336. ])->orderByDesc('id')->groupBy('open_id')->count();
  337. $activeCustomers[] = [
  338. 'day' => date('m', $StartO) . '-' . date('d', $EndO),
  339. 'num' => $customerNum
  340. ];
  341. }
  342. return $this->api($activeCustomers);
  343. }
  344. /**
  345. * @api {post} /api/album_boss/agent_overview_left 经销商总览左侧(agent_overview_left)
  346. * @apiDescription 经销商总览左侧(agent_overview_left)
  347. * @apiGroup Boss
  348. * @apiPermission none
  349. * @apiVersion 0.1.0
  350. * @apiParam {int} [store_id] 商户id
  351. * @apiParam {int} [start] 开始时间
  352. * @apiParam {int} [end] 结束时间
  353. * @apiSuccessExample {json} Success-Response:
  354. * HTTP/1.1 200 OK
  355. * {
  356. * "status": true,
  357. * "status_code": 0,
  358. * "message": "",
  359. * "data": {
  360. * "customerFollow":11,
  361. * "downloadCount":11,
  362. * "shareCount":11,
  363. * "newCustomerCount":11,
  364. * "totalCustomerCount":11,
  365. * }
  366. * }
  367. * @apiErrorExample {json} Error-Response:
  368. * HTTP/1.1 400 Bad Request
  369. * {
  370. * "state": false,
  371. * "code": 1000,
  372. * "message": "传入参数不正确",
  373. * "data": null or []
  374. * }
  375. * 可能出现的错误代码:
  376. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  377. */
  378. public function albumOverviewLeft(Request $request)
  379. {
  380. $userAuth = Auth('api')->user();
  381. $validator = Validator::make($request->all(), [
  382. 'store_id' => 'required',
  383. ], [
  384. 'store_id.required' => '缺少商户参数',
  385. ]);
  386. if ($userAuth->is_boss != 1) {
  387. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  388. }
  389. if ($validator->fails()) {
  390. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  391. }
  392. $end = $request->input('end');
  393. $start = $request->input('start');
  394. $store_id = $request->input('store_id');
  395. if (!$end) {
  396. $end = time();
  397. }
  398. if (!$start) {
  399. $start = 0;
  400. }
  401. $end = date('Y-m-d H:i:s', $end);
  402. $start = date('Y-m-d H:i:s', $start);
  403. $customerFollow = CustomerDetailsModel::where([
  404. ['store_id', $store_id],
  405. ['updated_at','>=',$start],
  406. ['updated_at','<=',$end]
  407. ])->count();
  408. $downloadCount = AlbumWatchRecord::where([
  409. ['store_id', $store_id],
  410. ['action', 9],
  411. ['updated_at','>=',$start],
  412. ['updated_at','<=',$end]
  413. ])->orderByDesc('id')->count();
  414. $shareCount = AlbumWatchRecord::where([
  415. ['store_id', $store_id],
  416. ['action', 8],
  417. ['updated_at','>=',$start],
  418. ['updated_at','<=',$end]
  419. ])->orderByDesc('id')->count();
  420. $newCustomerCount = AlbumWatchRecord::where([
  421. ['store_id', $store_id],
  422. ['is_new', 1],
  423. ['updated_at','>=',$start],
  424. ['updated_at','<=',$end]
  425. ])->orderByDesc('id')->count();
  426. $totalCustomer = AlbumWatchRecord::where([
  427. ['store_id', $store_id],
  428. ['updated_at','>=',$start],
  429. ['updated_at','<=',$end]
  430. ])->orderByDesc('id')->groupBy('open_id')->get()->toArray();
  431. $totalCustomerCount = count($totalCustomer);
  432. return $this->api(compact('totalCustomerCount', 'newCustomerCount', 'shareCount', 'downloadCount', 'customerFollow'));
  433. }
  434. /**
  435. * @api {post} /api/album_boss/agent_overview_funnel 经销商总览漏斗(agent_overview_funnel)
  436. * @apiDescription 经销商总览漏斗(agent_overview_funnel)
  437. * @apiGroup Boss
  438. * @apiPermission none
  439. * @apiVersion 0.1.0
  440. * @apiParam {int} [store_id] 商户id
  441. * @apiSuccessExample {json} Success-Response:
  442. * HTTP/1.1 200 OK
  443. * {
  444. * "status": true,
  445. * "status_code": 0,
  446. * "message": "",
  447. * "data": {
  448. * "customerFollow":11,
  449. * "shareCount":11,
  450. * "totalCustomerCount":11,
  451. * }
  452. * }
  453. * @apiErrorExample {json} Error-Response:
  454. * HTTP/1.1 400 Bad Request
  455. * {
  456. * "state": false,
  457. * "code": 1000,
  458. * "message": "传入参数不正确",
  459. * "data": null or []
  460. * }
  461. * 可能出现的错误代码:
  462. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  463. */
  464. public function albumOverviewFunnel(Request $request)
  465. {
  466. $userAuth = Auth('api')->user();
  467. $validator = Validator::make($request->all(), [
  468. 'store_id' => 'required',
  469. ], [
  470. 'store_id.required' => '缺少商户参数',
  471. ]);
  472. if ($userAuth->is_boss != 1) {
  473. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  474. }
  475. if ($validator->fails()) {
  476. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  477. }
  478. $store_id = $request->input('store_id');
  479. $customerFollow = CustomerDetailsModel::where('store_id', $store_id)->count();
  480. $shareCount = AlbumWatchRecord::where([
  481. ['store_id', $store_id],
  482. ['action', 8],
  483. ])->orderByDesc('id')->count();
  484. $totalCustomer = AlbumWatchRecord::where([
  485. ['store_id', $store_id],
  486. ])->orderByDesc('id')->groupBy('open_id')->get()->toArray();
  487. $totalCustomerCount = count($totalCustomer);
  488. return $this->api(compact('totalCustomerCount', 'shareCount', 'customerFollow'));
  489. }
  490. /**
  491. * @api {post} /api/album_boss/agent_overview_call 经销商总览咨询(agent_overview_call)
  492. * @apiDescription 经销商总览咨询(agent_overview_call)
  493. * @apiGroup Boss
  494. * @apiPermission none
  495. * @apiVersion 0.1.0
  496. * @apiParam {int} [store_id] 商户id
  497. * @apiParam {int} [day] 天数
  498. * @apiSuccessExample {json} Success-Response:
  499. * HTTP/1.1 200 OK
  500. * {
  501. * "status": true,
  502. * "status_code": 0,
  503. * "message": "",
  504. * "data": {
  505. * "callCustomers": [
  506. * {
  507. * "day" : 03/25,
  508. * "num" : 111
  509. * }
  510. * ]
  511. * }
  512. * }
  513. * @apiErrorExample {json} Error-Response:
  514. * HTTP/1.1 400 Bad Request
  515. * {
  516. * "state": false,
  517. * "code": 1000,
  518. * "message": "传入参数不正确",
  519. * "data": null or []
  520. * }
  521. * 可能出现的错误代码:
  522. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  523. */
  524. public function albumOverviewCall(Request $request)
  525. {
  526. $userAuth = Auth('api')->user();
  527. $validator = Validator::make($request->all(), [
  528. 'store_id' => 'required',
  529. ], [
  530. 'store_id.required' => '缺少商户参数',
  531. ]);
  532. if ($userAuth->is_boss != 1) {
  533. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  534. }
  535. if ($validator->fails()) {
  536. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  537. }
  538. $store_id = $request->input('store_id');
  539. $day = $request->input('day');
  540. $callCustomers = array();
  541. for ($d = 0; $d < $day; $d++) {
  542. $StartO = mktime(0, 0, 0, date('m'), date('d'), date('y')) - 86400 * $d;
  543. $EndO = $StartO + 86400;
  544. $End = date('Y-m-d H:i:s', $EndO);
  545. $Start = date('Y-m-d H:i:s', $StartO);
  546. $callCustomer = AlbumWatchRecord::where([
  547. ['store_id', $store_id],
  548. ['action', 7],
  549. ['updated_at','>=',$Start],
  550. ['updated_at','<=',$End]
  551. ])->orderByDesc('id')->count();
  552. $callCustomers[] = [
  553. 'day' => date('m', $StartO) . '-' . date('d', $EndO),
  554. 'num' => $callCustomer
  555. ];
  556. }
  557. return $this->api($callCustomers);
  558. }
  559. /**
  560. * @api {post} /api/album_boss/agent_overview_favorite 经销商总览兴趣占比(agent_overview_favorite)
  561. * @apiDescription 经销商总览兴趣占比(agent_overview_favorite)
  562. * @apiGroup Boss
  563. * @apiPermission none
  564. * @apiVersion 0.1.0
  565. * @apiParam {int} [store_id] 商户id
  566. * @apiParam {int} [parent_id] 商户id
  567. * @apiParam {int} [start] 开始时间
  568. * @apiParam {int} [end] 结束时间
  569. * @apiSuccessExample {json} Success-Response:
  570. * HTTP/1.1 200 OK
  571. * {
  572. * "status": true,
  573. * "status_code": 0,
  574. * "message": "",
  575. * "data": {
  576. * "arrFavorite": [
  577. * {
  578. * 'name':'asdawd',
  579. * 'point':'asdawd',
  580. * 'num':'1',
  581. * }
  582. * ]
  583. * }
  584. * }
  585. * @apiErrorExample {json} Error-Response:
  586. * HTTP/1.1 400 Bad Request
  587. * {
  588. * "state": false,
  589. * "code": 1000,
  590. * "message": "传入参数不正确",
  591. * "data": null or []
  592. * }
  593. * 可能出现的错误代码:
  594. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  595. */
  596. public function albumOverviewFavorite(Request $request)
  597. {
  598. $userAuth = Auth('api')->user();
  599. $validator = Validator::make($request->all(), [
  600. 'store_id' => 'required',
  601. ], [
  602. 'store_id.required' => '缺少商户参数',
  603. ]);
  604. if ($userAuth->is_boss != 1) {
  605. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  606. }
  607. if ($validator->fails()) {
  608. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  609. }
  610. $end = $request->input('end');
  611. $start = $request->input('start');
  612. $store_id = $request->input('store_id');
  613. if (!$end) {
  614. $end = time();
  615. }
  616. if (!$start) {
  617. $start = 0;
  618. }
  619. $end = date('Y-m-d H:i:s', $end);
  620. $start = date('Y-m-d H:i:s', $start);
  621. $parent_id = $request->input('parent_id');
  622. $cat = AlbumCatModel::where([['store_id',$store_id],['parent_id', $parent_id]])->get(['name','id'])->toArray();
  623. $total = 0;
  624. foreach ($cat as $key => $val) {
  625. $count = CustomerCatRecordModel::where([
  626. ['store_id',$store_id],
  627. ['cat_id',$val['id']],
  628. ['updated_at','>=',$start],
  629. ['updated_at','<=',$end]
  630. ])->count();
  631. $total += $count;
  632. $cat[$key]['num'] = $count;
  633. }
  634. foreach ($cat as $key => $val) {
  635. if ($val['num'] == 0 || $total == 0) {
  636. $cat[$key]['point'] = 0;
  637. } else {
  638. $cat[$key]['point'] = ($val['num'] / $total * 100) . '%';
  639. }
  640. }
  641. return $this->api($cat);
  642. }
  643. /**
  644. * @api {post} /api/album_boss/agent_overview_new 经销商总览新增客户(agent_overview_new)
  645. * @apiDescription 经销商总览新增客户(agent_overview_new)
  646. * @apiGroup Boss
  647. * @apiPermission none
  648. * @apiVersion 0.1.0
  649. * @apiParam {int} [store_id] 商户id
  650. * @apiParam {int} [day] 天数
  651. * @apiSuccessExample {json} Success-Response:
  652. * HTTP/1.1 200 OK
  653. * {
  654. * "status": true,
  655. * "status_code": 0,
  656. * "message": "",
  657. * "data": {
  658. * "newCustomers": [
  659. * {
  660. * "day" : 03/25,
  661. * "num" : 111
  662. * }
  663. * ]
  664. * }
  665. * }
  666. * @apiErrorExample {json} Error-Response:
  667. * HTTP/1.1 400 Bad Request
  668. * {
  669. * "state": false,
  670. * "code": 1000,
  671. * "message": "传入参数不正确",
  672. * "data": null or []
  673. * }
  674. * 可能出现的错误代码:
  675. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  676. */
  677. public function albumOverviewNew(Request $request)
  678. {
  679. $userAuth = Auth('api')->user();
  680. $validator = Validator::make($request->all(), [
  681. 'store_id' => 'required',
  682. ], [
  683. 'store_id.required' => '缺少商户参数',
  684. ]);
  685. if ($userAuth->is_boss != 1) {
  686. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  687. }
  688. if ($validator->fails()) {
  689. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  690. }
  691. $store_id = $request->input('store_id');
  692. $day = $request->input('day');
  693. $newCustomers = array();
  694. for ($d = 0; $d < $day; $d++) {
  695. $StartO = mktime(0, 0, 0, date('m'), date('d'), date('y')) - 86400 * $d;
  696. $EndO = $StartO + 86400;
  697. $End = date('Y-m-d H:i:s', $EndO);
  698. $Start = date('Y-m-d H:i:s', $StartO);
  699. $newCustomer = AlbumWatchRecord::where([
  700. ['store_id', $store_id],
  701. ['is_new', 1],
  702. ['updated_at','>=',$Start],
  703. ['updated_at','<=',$End]
  704. ])->orderByDesc('id')->count();
  705. $newCustomers[] = [
  706. 'day' => date('m', $StartO) . '-' . date('d', $EndO),
  707. 'num' => $newCustomer
  708. ];
  709. }
  710. return $this->api($newCustomers);
  711. }
  712. /**
  713. * @api {post} /api/album_boss/agent_analysis 经销商分析(agent_analysis)
  714. * @apiDescription 经销商分析(agent_analysis)
  715. * @apiGroup Boss
  716. * @apiPermission none
  717. * @apiVersion 0.1.0
  718. * @apiParam {int} [store_id] 商户id
  719. * @apiSuccessExample {json} Success-Response:
  720. * HTTP/1.1 200 OK
  721. * {
  722. * "status": true,
  723. * "status_code": 0,
  724. * "message": "",
  725. * "data": [
  726. * {
  727. * "realname" : 释迦摩尼,
  728. * "pointCount" : 111
  729. * "callCount" : 111
  730. * "favoriteCount" : 111
  731. * "get_count" : 111
  732. * "share_times" : 111
  733. * "newCount" : 111
  734. * }
  735. * ]
  736. * }
  737. * @apiErrorExample {json} Error-Response:
  738. * HTTP/1.1 400 Bad Request
  739. * {
  740. * "state": false,
  741. * "code": 1000,
  742. * "message": "传入参数不正确",
  743. * "data": null or []
  744. * }
  745. * 可能出现的错误代码:
  746. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  747. */
  748. public function agentAnalysis(Request $request)
  749. {
  750. $userAuth = Auth('api')->user();
  751. $validator = Validator::make($request->all(), [
  752. 'store_id' => 'required',
  753. ], [
  754. 'store_id.required' => '缺少商户参数',
  755. ]);
  756. if ($userAuth->is_boss != 1) {
  757. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  758. }
  759. if ($validator->fails()) {
  760. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  761. }
  762. $store_id = $request->input('store_id');
  763. $agent = AlbumAgentModel::where('store_id', $store_id)->orderByDesc('newCount')->paginate(12);
  764. foreach ($agent as $value) {
  765. $user = AlbumUserModel::where([['id', $value->user_id], ['store_id', $store_id]])->first(['avatar']);
  766. $value->avatar = $user->avatar;
  767. }
  768. return $this->api($agent);
  769. }
  770. /**
  771. * @api {get} /api/album_boss/boss_interactive 经销商互动排名(boss_interactive)
  772. * @apiDescription 经销商互动排名(boss_interactive)
  773. * @apiGroup Boss
  774. * @apiPermission none
  775. * @apiVersion 0.1.0
  776. * @apiParam {int} [store_id] 商户id
  777. * @apiSuccessExample {json} Success-Response:
  778. * HTTP/1.1 200 OK
  779. * {
  780. * "status": true,
  781. * "status_code": 0,
  782. * "message": "",
  783. * "data": [
  784. * {
  785. * "realname" : 释迦摩尼,
  786. * "interactive" : 111
  787. * "avatar" : 111
  788. * }
  789. * ]
  790. * }
  791. * @apiErrorExample {json} Error-Response:
  792. * HTTP/1.1 400 Bad Request
  793. * {
  794. * "state": false,
  795. * "code": 1000,
  796. * "message": "传入参数不正确",
  797. * "data": null or []
  798. * }
  799. * 可能出现的错误代码:
  800. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  801. */
  802. public function BossInteractive(Request $request)
  803. {
  804. $userAuth = Auth('api')->user();
  805. $validator = Validator::make($request->all(), [
  806. 'store_id' => 'required',
  807. ], [
  808. 'store_id.required' => '缺少商户参数',
  809. ]);
  810. if ($userAuth->is_boss != 1) {
  811. return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
  812. }
  813. if ($validator->fails()) {
  814. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  815. }
  816. $store_id = $request->input('store_id');
  817. $agent = AlbumAgentModel::where('store_id', $store_id)->orderByDesc('interactive')->paginate(20);
  818. foreach ($agent as $value) {
  819. $user = AlbumUserModel::where([['id', $value->user_id], ['store_id', $store_id]])->first(['avatar']);
  820. $value->avatar = $user->avatar;
  821. }
  822. return $this->api($agent);
  823. }
  824. }