CardController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\CardBannerModel;
  4. use App\Models\CardSettingModel;
  5. use App\Models\CardUserHonorModel;
  6. use App\Models\CardUserInfoModel;
  7. use App\Models\CardUserProgressModel;
  8. use App\Models\CardUserProjectModel;
  9. use App\Models\CardUserTrendModel;
  10. use Illuminate\Http\Request;
  11. use Validator;
  12. use App\Services\Base\ErrorCode;
  13. class CardController extends Controller
  14. {
  15. /**
  16. * @api {get} /api/card/index 名片主页(index)
  17. * @apiDescription 公司详情(index)
  18. * @apiGroup Card
  19. * @apiPermission none
  20. * @apiVersion 0.1.0
  21. * @apiParam {int} user_id user_id
  22. * @apiSuccessExample {json} Success-Response:
  23. * HTTP/1.1 200 OK
  24. * {
  25. * "state": true,
  26. * "code": 0,
  27. * "message": "",
  28. * "data": {
  29. * "banner": []//轮播图
  30. * "project": []//经营项目
  31. * "trend": []//个人动态
  32. * "info": []//个人详情
  33. * }
  34. * }
  35. * @apiErrorExample {json} Error-Response:
  36. * HTTP/1.1 400 Bad Request
  37. * {
  38. * "state": false,
  39. * "code": 1000,
  40. * "message": "传入参数不正确",
  41. * "data": null or []
  42. * }
  43. * 可能出现的错误代码:
  44. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  45. */
  46. public function cardIndex(Request $request)
  47. {
  48. $validator = Validator::make($request->all(), [
  49. 'user_id' => 'required',
  50. ], [
  51. 'user_id.required' => '用户信息未知',
  52. ]);
  53. if ($validator->fails()) {
  54. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  55. }
  56. $user_id = $request->user_id;
  57. //小程序設置
  58. $setting = CardSettingModel::where('appid', $user_id)->first();
  59. if(!$setting){
  60. $setting = [
  61. 'banner_height' => 180,
  62. 'banner_hide' => 0,
  63. 'base_color' => '#0074cd',
  64. 'project_type' => 2,
  65. 'trend_type' => 0,
  66. 'show_style' => 0,
  67. 'copyright' => '',
  68. 'aboutme_icon'=>'../../images/aboutme.png',
  69. 'develo_icon'=>'../../images/develop.png',
  70. 'we_icon'=>'../../images/we.png',
  71. 'honer_icon'=>'../../images/honer.png',
  72. ];
  73. }
  74. $project_num = isset($setting->project_type) && $setting->project_type == 1 ? 4 : 3;
  75. $trend_num = isset($setting->trend_type) && $setting->trend_type == 1 ? 4 : 3;
  76. //幻灯片
  77. $banner = CardBannerModel::where('appid', $user_id)->where('status', '显示')->orderBy('sort', 'DESC')->get();
  78. //经营项目
  79. $project = CardUserProjectModel::where('appid', $user_id)->orderBy('sort', 'DESC')->paginate($project_num);
  80. foreach ($project as $pitem){
  81. $pitem->detail = strip_tags($pitem->detail);
  82. }
  83. //个人动态
  84. $trend = CardUserTrendModel::where('appid', $user_id)->orderBy('sort', 'DESC')->paginate($trend_num);
  85. foreach ($trend as $titem){
  86. $titem->pic = strip_tags($titem->pic);
  87. }
  88. //个人名片详情
  89. $info = CardUserInfoModel::where('appid', $user_id)->first();
  90. return $this->api(compact('banner', 'project', 'trend', 'info', 'setting'));
  91. }
  92. /**
  93. * @api {get} /api/card/info 个人详情(info)
  94. * @apiDescription 个人详情(info)
  95. * @apiGroup Card
  96. * @apiPermission none
  97. * @apiVersion 0.1.0
  98. * @apiParam {int} user_id user_id
  99. * @apiSuccessExample {json} Success-Response:
  100. * HTTP/1.1 200 OK
  101. * {
  102. * "state": true,
  103. * "code": 0,
  104. * "message": "",
  105. * "data": {
  106. * "info": []//个人详情
  107. * }
  108. * }
  109. * @apiErrorExample {json} Error-Response:
  110. * HTTP/1.1 400 Bad Request
  111. * {
  112. * "state": false,
  113. * "code": 1000,
  114. * "message": "传入参数不正确",
  115. * "data": null or []
  116. * }
  117. * 可能出现的错误代码:
  118. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  119. */
  120. public function cardUserInfo(Request $request)
  121. {
  122. $validator = Validator::make($request->all(), [
  123. 'user_id' => 'required',
  124. ], [
  125. 'user_id.required' => '用户信息未知',
  126. ]);
  127. if ($validator->fails()) {
  128. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  129. }
  130. $user_id = $request->user_id;
  131. //个人名片详情
  132. $info = CardUserInfoModel::where('appid', $user_id)->first();
  133. return $this->api(compact('info'));
  134. }
  135. /**
  136. * @api {get} /api/card/progress 个人经历(progress)
  137. * @apiDescription 个人经历(progress)
  138. * @apiGroup Card
  139. * @apiPermission none
  140. * @apiVersion 0.1.0
  141. * @apiParam {int} user_id user_id
  142. * @apiSuccessExample {json} Success-Response:
  143. * HTTP/1.1 200 OK
  144. * {
  145. * "state": true,
  146. * "code": 0,
  147. * "message": "",
  148. * "data": {
  149. * "progress": []//个人经历
  150. * }
  151. * }
  152. * @apiErrorExample {json} Error-Response:
  153. * HTTP/1.1 400 Bad Request
  154. * {
  155. * "state": false,
  156. * "code": 1000,
  157. * "message": "传入参数不正确",
  158. * "data": null or []
  159. * }
  160. * 可能出现的错误代码:
  161. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  162. */
  163. public function cardUserProgress(Request $request)
  164. {
  165. $validator = Validator::make($request->all(), [
  166. 'user_id' => 'required',
  167. ], [
  168. 'user_id.required' => '用户信息未知',
  169. ]);
  170. if ($validator->fails()) {
  171. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  172. }
  173. $user_id = $request->user_id;
  174. $progress = CardUserProgressModel::where('appid', $user_id)->get();
  175. return $this->api(compact('progress'));
  176. }
  177. /**
  178. * @api {get} /api/card/honor 个人荣誉(honor)
  179. * @apiDescription 个人荣誉(honor)
  180. * @apiGroup Card
  181. * @apiPermission none
  182. * @apiVersion 0.1.0
  183. * @apiParam {int} user_id user_id
  184. * @apiSuccessExample {json} Success-Response:
  185. * HTTP/1.1 200 OK
  186. * {
  187. * "state": true,
  188. * "code": 0,
  189. * "message": "",
  190. * "data": {
  191. * "honor": []//个人荣誉
  192. * }
  193. * }
  194. * @apiErrorExample {json} Error-Response:
  195. * HTTP/1.1 400 Bad Request
  196. * {
  197. * "state": false,
  198. * "code": 1000,
  199. * "message": "传入参数不正确",
  200. * "data": null or []
  201. * }
  202. * 可能出现的错误代码:
  203. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  204. */
  205. public function cardUserHonor(Request $request)
  206. {
  207. $validator = Validator::make($request->all(), [
  208. 'user_id' => 'required',
  209. ], [
  210. 'user_id.required' => '用户信息未知',
  211. ]);
  212. if ($validator->fails()) {
  213. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  214. }
  215. $user_id = $request->user_id;
  216. $honor = CardUserHonorModel::where('appid', $user_id)->get();
  217. return $this->api(compact('honor'));
  218. }
  219. /**
  220. * @api {get} /api/card/project 经营项目(project)
  221. * @apiDescription 经营项目(project)
  222. * @apiGroup Card
  223. * @apiPermission none
  224. * @apiVersion 0.1.0
  225. * @apiParam {int} user_id user_id
  226. * @apiSuccessExample {json} Success-Response:
  227. * HTTP/1.1 200 OK
  228. * {
  229. * "state": true,
  230. * "code": 0,
  231. * "message": "",
  232. * "data": {
  233. * "project": []//经营项目
  234. * }
  235. * }
  236. * @apiErrorExample {json} Error-Response:
  237. * HTTP/1.1 400 Bad Request
  238. * {
  239. * "state": false,
  240. * "code": 1000,
  241. * "message": "传入参数不正确",
  242. * "data": null or []
  243. * }
  244. * 可能出现的错误代码:
  245. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  246. */
  247. public function cardUserProject(Request $request)
  248. {
  249. $validator = Validator::make($request->all(), [
  250. 'user_id' => 'required',
  251. ], [
  252. 'user_id.required' => '用户信息未知',
  253. ]);
  254. if ($validator->fails()) {
  255. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  256. }
  257. $user_id = $request->user_id;
  258. $project = CardUserProjectModel::where('appid', $user_id)->orderBy('sort', 'DESC')->get();
  259. return $this->api(compact('project'));
  260. }
  261. /**
  262. * @api {get} /api/card/projectDetail 经营项目详情(projectDetail)
  263. * @apiDescription 经营项目详情(projectDetail)
  264. * @apiGroup Card
  265. * @apiPermission none
  266. * @apiVersion 0.1.0
  267. * @apiParam {int} user_id user_id
  268. * @apiParam {int} pro_id 项目ID
  269. * @apiSuccessExample {json} Success-Response:
  270. * HTTP/1.1 200 OK
  271. * {
  272. * "state": true,
  273. * "code": 0,
  274. * "message": "",
  275. * "data": {
  276. * "project": []//经营项目
  277. * }
  278. * }
  279. * @apiErrorExample {json} Error-Response:
  280. * HTTP/1.1 400 Bad Request
  281. * {
  282. * "state": false,
  283. * "code": 1000,
  284. * "message": "传入参数不正确",
  285. * "data": null or []
  286. * }
  287. * 可能出现的错误代码:
  288. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  289. */
  290. public function projectDetail(Request $request)
  291. {
  292. $validator = Validator::make($request->all(), [
  293. 'user_id' => 'required',
  294. 'pro_id' => 'required',
  295. ], [
  296. 'user_id.required' => '用户信息未知',
  297. 'pro_id.required' => '所选项目未知',
  298. ]);
  299. if ($validator->fails()) {
  300. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  301. }
  302. $user_id = $request->user_id;
  303. $pro_id = $request->pro_id;
  304. $project = CardUserProjectModel::where('appid', $user_id)->where('id', $pro_id)->first();
  305. if (!$project) return $this->error(1000, '所经营项目不存在');
  306. return $this->api(compact('project'));
  307. }
  308. /**
  309. * @api {get} /api/card/trend 所有动态(trend)
  310. * @apiDescription 所有动态(trend)
  311. * @apiGroup Card
  312. * @apiPermission none
  313. * @apiVersion 0.1.0
  314. * @apiParam {int} user_id user_id
  315. * @apiSuccessExample {json} Success-Response:
  316. * HTTP/1.1 200 OK
  317. * {
  318. * "state": true,
  319. * "code": 0,
  320. * "message": "",
  321. * "data": {
  322. * "trend": []//所有动态
  323. * }
  324. * }
  325. * @apiErrorExample {json} Error-Response:
  326. * HTTP/1.1 400 Bad Request
  327. * {
  328. * "state": false,
  329. * "code": 1000,
  330. * "message": "传入参数不正确",
  331. * "data": null or []
  332. * }
  333. * 可能出现的错误代码:
  334. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  335. */
  336. public function CardUserTrend(Request $request)
  337. {
  338. $validator = Validator::make($request->all(), [
  339. 'user_id' => 'required',
  340. ], [
  341. 'user_id.required' => '用户信息未知',
  342. ]);
  343. if ($validator->fails()) {
  344. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  345. }
  346. $user_id = $request->user_id;
  347. $trend = CardUserTrendModel::where('appid', $user_id)->orderBy('sort', 'DESC')->get();
  348. foreach ($trend as $k => $item) {
  349. if ($item->pic) {
  350. $trend[$k]->pic = explode(',', $item->pic);
  351. } else {
  352. $trend[$k]->pic = [];
  353. }
  354. }
  355. return $this->api(compact('trend'));
  356. }
  357. /**
  358. * @api {get} /api/card/trendDetail 个人动态详情(trendDetail)
  359. * @apiDescription 个人动态详情(trendDetail)
  360. * @apiGroup Card
  361. * @apiPermission none
  362. * @apiVersion 0.1.0
  363. * @apiParam {int} user_id user_id
  364. * @apiParam {int} trend_id 动态ID
  365. * @apiSuccessExample {json} Success-Response:
  366. * HTTP/1.1 200 OK
  367. * {
  368. * "state": true,
  369. * "code": 0,
  370. * "message": "",
  371. * "data": {
  372. * "trend": []//经营项目
  373. * }
  374. * }
  375. * @apiErrorExample {json} Error-Response:
  376. * HTTP/1.1 400 Bad Request
  377. * {
  378. * "state": false,
  379. * "code": 1000,
  380. * "message": "传入参数不正确",
  381. * "data": null or []
  382. * }
  383. * 可能出现的错误代码:
  384. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  385. */
  386. public function trendDetail(Request $request)
  387. {
  388. $validator = Validator::make($request->all(), [
  389. 'user_id' => 'required',
  390. 'trend_id' => 'required',
  391. ], [
  392. 'user_id.required' => '用户信息未知',
  393. 'trend_id.required' => '动态ID未知',
  394. ]);
  395. if ($validator->fails()) {
  396. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  397. }
  398. $user_id = $request->user_id;
  399. $trend_id = $request->trend_id;
  400. $trend = CardUserTrendModel::where('appid', $user_id)->where('id', $trend_id)->first();
  401. if (!$trend) return $this->error(1000, '动态不存在');
  402. return $this->api(compact('trend'));
  403. }
  404. /**
  405. * @api {get} /api/card/setting 基础设置
  406. * @apiDescription 基础设置
  407. * @apiGroup Card
  408. * @apiPermission none
  409. * @apiVersion 0.1.0
  410. * @apiParam {int} user_id user_id
  411. * @apiSuccessExample {json} Success-Response:
  412. * HTTP/1.1 200 OK
  413. * @apiErrorExample {json} Error-Response:
  414. * HTTP/1.1 400 Bad Request
  415. */
  416. public function cardSetting(Request $request)
  417. {
  418. $validator = Validator::make($request->all(), [
  419. 'user_id' => 'required',
  420. ], [
  421. 'user_id.required' => '用户信息未知',
  422. ]);
  423. if ($validator->fails()) {
  424. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  425. }
  426. $user_id = $request->user_id;
  427. $setting = CardSettingModel::where('appid', $user_id)->fitst();
  428. return $this->api(compact('setting'));
  429. }
  430. }