123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Models\CardBannerModel;
- use App\Models\CardSettingModel;
- use App\Models\CardUserHonorModel;
- use App\Models\CardUserInfoModel;
- use App\Models\CardUserProgressModel;
- use App\Models\CardUserProjectModel;
- use App\Models\CardUserTrendModel;
- use Illuminate\Http\Request;
- use Validator;
- use App\Services\Base\ErrorCode;
- class CardController extends Controller
- {
- /**
- * @api {get} /api/card/index 名片主页(index)
- * @apiDescription 公司详情(index)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "banner": []//轮播图
- * "project": []//经营项目
- * "trend": []//个人动态
- * "info": []//个人详情
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function cardIndex(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- //小程序設置
- $setting = CardSettingModel::where('appid', $user_id)->first();
- if(!$setting){
- $setting = [
- 'banner_height' => 180,
- 'banner_hide' => 0,
- 'base_color' => '#0074cd',
- 'project_type' => 2,
- 'trend_type' => 0,
- 'show_style' => 0,
- 'copyright' => '',
- 'aboutme_icon'=>'../../images/aboutme.png',
- 'develo_icon'=>'../../images/develop.png',
- 'we_icon'=>'../../images/we.png',
- 'honer_icon'=>'../../images/honer.png',
- ];
- }
- $project_num = isset($setting->project_type) && $setting->project_type == 1 ? 4 : 3;
- $trend_num = isset($setting->trend_type) && $setting->trend_type == 1 ? 4 : 3;
- //幻灯片
- $banner = CardBannerModel::where('appid', $user_id)->where('status', '显示')->orderBy('sort', 'DESC')->get();
- //经营项目
- $project = CardUserProjectModel::where('appid', $user_id)->orderBy('sort', 'DESC')->paginate($project_num);
- foreach ($project as $pitem){
- $pitem->detail = strip_tags($pitem->detail);
- }
- //个人动态
- $trend = CardUserTrendModel::where('appid', $user_id)->orderBy('sort', 'DESC')->paginate($trend_num);
- foreach ($trend as $titem){
- $titem->pic = strip_tags($titem->pic);
- }
- //个人名片详情
- $info = CardUserInfoModel::where('appid', $user_id)->first();
- return $this->api(compact('banner', 'project', 'trend', 'info', 'setting'));
- }
- /**
- * @api {get} /api/card/info 个人详情(info)
- * @apiDescription 个人详情(info)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "info": []//个人详情
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function cardUserInfo(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- //个人名片详情
- $info = CardUserInfoModel::where('appid', $user_id)->first();
- return $this->api(compact('info'));
- }
- /**
- * @api {get} /api/card/progress 个人经历(progress)
- * @apiDescription 个人经历(progress)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "progress": []//个人经历
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function cardUserProgress(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $progress = CardUserProgressModel::where('appid', $user_id)->get();
- return $this->api(compact('progress'));
- }
- /**
- * @api {get} /api/card/honor 个人荣誉(honor)
- * @apiDescription 个人荣誉(honor)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "honor": []//个人荣誉
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function cardUserHonor(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $honor = CardUserHonorModel::where('appid', $user_id)->get();
- return $this->api(compact('honor'));
- }
- /**
- * @api {get} /api/card/project 经营项目(project)
- * @apiDescription 经营项目(project)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "project": []//经营项目
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function cardUserProject(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $project = CardUserProjectModel::where('appid', $user_id)->orderBy('sort', 'DESC')->get();
- return $this->api(compact('project'));
- }
- /**
- * @api {get} /api/card/projectDetail 经营项目详情(projectDetail)
- * @apiDescription 经营项目详情(projectDetail)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiParam {int} pro_id 项目ID
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "project": []//经营项目
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function projectDetail(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- 'pro_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- 'pro_id.required' => '所选项目未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $pro_id = $request->pro_id;
- $project = CardUserProjectModel::where('appid', $user_id)->where('id', $pro_id)->first();
- if (!$project) return $this->error(1000, '所经营项目不存在');
- return $this->api(compact('project'));
- }
- /**
- * @api {get} /api/card/trend 所有动态(trend)
- * @apiDescription 所有动态(trend)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "trend": []//所有动态
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function CardUserTrend(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $trend = CardUserTrendModel::where('appid', $user_id)->orderBy('sort', 'DESC')->get();
- foreach ($trend as $k => $item) {
- if ($item->pic) {
- $trend[$k]->pic = explode(',', $item->pic);
- } else {
- $trend[$k]->pic = [];
- }
- }
- return $this->api(compact('trend'));
- }
- /**
- * @api {get} /api/card/trendDetail 个人动态详情(trendDetail)
- * @apiDescription 个人动态详情(trendDetail)
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiParam {int} trend_id 动态ID
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "state": true,
- * "code": 0,
- * "message": "",
- * "data": {
- * "trend": []//经营项目
- * }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "state": false,
- * "code": 1000,
- * "message": "传入参数不正确",
- * "data": null or []
- * }
- * 可能出现的错误代码:
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
- */
- public function trendDetail(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- 'trend_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- 'trend_id.required' => '动态ID未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $trend_id = $request->trend_id;
- $trend = CardUserTrendModel::where('appid', $user_id)->where('id', $trend_id)->first();
- if (!$trend) return $this->error(1000, '动态不存在');
- return $this->api(compact('trend'));
- }
- /**
- * @api {get} /api/card/setting 基础设置
- * @apiDescription 基础设置
- * @apiGroup Card
- * @apiPermission none
- * @apiVersion 0.1.0
- * @apiParam {int} user_id user_id
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function cardSetting(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'user_id' => 'required',
- ], [
- 'user_id.required' => '用户信息未知',
- ]);
- if ($validator->fails()) {
- return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
- }
- $user_id = $request->user_id;
- $setting = CardSettingModel::where('appid', $user_id)->fitst();
- return $this->api(compact('setting'));
- }
- }
|