AlbumBossController.php 31 KB

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