MyController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\BaseDictionaryOptionModel;
  4. use App\Models\BaseSettingsModel;
  5. use App\Models\DreamImages;
  6. use App\Models\DreamInfoModel;
  7. use App\Models\ReplyCommentsInfo;
  8. use App\Models\SystemInfoModel;
  9. use App\Models\UserCareDream;
  10. use App\Models\UserInfoModel;
  11. use Illuminate\Http\Request;
  12. use App\Services\Base\ErrorCode;
  13. class MyController extends Controller
  14. {
  15. /**
  16. * @api {get} /api/my/show 个人首页
  17. * @apiDescription 个人首页
  18. * @apiGroup My
  19. * @apiPermission Passport
  20. * @apiSuccessExample {json} Success-Response:
  21. * HTTP/1.1 200 O* "status": true,
  22. *{
  23. * "status": true,
  24. * "status_code": 0,
  25. * "message": "",
  26. * "data": {
  27. * "id": 1,
  28. * "phone": "13880642880",
  29. * "nickname": "name1",
  30. * "avatar": "https://tims%2Fitem%225_kzrcM.thumb.224_0.jpeg",
  31. * "birthday": "2000-06-21",
  32. * "sign": 0,
  33. * "money": 0,
  34. * "coin": 1300,
  35. * "sex": 1,
  36. * "signture": "",
  37. * "height": 170,
  38. * "work": "",
  39. * "emotion": 1,
  40. * "address": "",
  41. * "city": "",
  42. * "detail_address": "",
  43. * "status": 1,
  44. * "wechat": "",
  45. * "weibo": "",
  46. * "remember_token": "",
  47. * "created_at": "2017-06-25 10:27:08",
  48. * "updated_at": "2017-06-25 15:20:11",
  49. * "deleted_at": null,
  50. * "care_dreams_number": 2,
  51. * "fans_number": 0,
  52. * "collection_number": 0,
  53. * "interaction_number": 0,
  54. * }
  55. *}
  56. * @apiErrorExample {json} Error-Response:
  57. * HTTP/1.1 400 Bad Request
  58. *{
  59. * "status": true,
  60. * "status_code": 0,
  61. * "message": "",
  62. * "data": {
  63. * "user": null
  64. * }
  65. *}
  66. */
  67. public function show()
  68. {
  69. $user = $this->getUser();
  70. /*
  71. * 我的关注人数,我的粉丝,收藏
  72. * 点赞?徽章?
  73. * */
  74. $care_num = $user->careDreams;
  75. $user->care_dreams_number = count($care_num);
  76. $fens = UserCareDream::where('dream_user_id',$user->id)->get();
  77. $user->fans_number = count($fens);
  78. $collection = $user->myCollection;
  79. $user->collection_number = count($collection);
  80. $interaction_infos = $user->allInteraction;
  81. $user->interaction_number = count($interaction_infos);
  82. return $this->api($user);
  83. }
  84. /**
  85. * @api {get} /api/my/edit 修改个人信息
  86. * @apiDescription 修改个人信息
  87. * @apiGroup My
  88. * @apiPermission Passport
  89. * @apiVersion 0.1.0
  90. * @apiSuccessExample {json} Success-Response:
  91. * HTTP/1.1 200 OK
  92. *{
  93. * "status": true,
  94. * "status_code": 0,
  95. * "message": "",
  96. "data": {
  97. "emotion": [
  98. {
  99. "value": "1",
  100. "name": "未婚"
  101. },
  102. {
  103. "value": "2",
  104. "name": "已婚"
  105. },
  106. {
  107. "value": "3",
  108. "name": "离异"
  109. }
  110. ],
  111. "sex": [
  112. {
  113. "value": "0",
  114. "name": "男"
  115. },
  116. {
  117. "value": "1",
  118. "name": "女"
  119. }
  120. ]
  121. }
  122. * }
  123. * @apiErrorExample {json} Error-Response:
  124. * HTTP/1.1 400 Bad Request
  125. * {
  126. * "status": false,
  127. * "status_code": 1500,
  128. * "message": "会员不存在",
  129. * "data": null
  130. * }
  131. */
  132. public function edit()
  133. {
  134. $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  135. where('dictionary_code','sex')->get();
  136. $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  137. where('dictionary_code','emotion')->get();
  138. return $this->api(compact('emotion','sex'));
  139. }
  140. /**
  141. * @api {post} /api/my/update 保存个人信息
  142. * @apiDescription 保存个人信息
  143. * @apiParam {string} pic 头像
  144. * @apiParam {int} sex 性别
  145. * @apiParam {string} signture 个性签名
  146. * @apiParam {int} emotion 情感状态
  147. * @apiParam {string} work 职业
  148. * @apiParam {int} height 身高
  149. * @apiGroup My
  150. * @apiPermission Passport
  151. * @apiVersion 0.1.0
  152. * @apiSuccessExample {json} Success-Response:
  153. * HTTP/1.1 200 OK
  154. *{
  155. * "status": true,
  156. * "status_code": 0,
  157. * "message": "",
  158. * "data": ""
  159. *}
  160. * @apiErrorExample {json} Error-Response:
  161. * HTTP/1.1 400 Bad Request
  162. *{
  163. * "status": false,
  164. * "status_code": 600,
  165. * "message": "保存用户数据失败",
  166. * "data": null
  167. * }
  168. */
  169. public function update(Request $request)
  170. {
  171. $user = $this->getUser();
  172. $data = $request->except('_token');
  173. $ok = $user->update($data);
  174. if ($ok == true) {
  175. return $this->api('');
  176. }else{
  177. return $this->error(ErrorCode::SAVE_USER_FAILED);
  178. }
  179. }
  180. /**
  181. * @api {post} /api/my/recharge 充值(recharge)
  182. * @apiDescription 充值(recharge)
  183. * @apiGroup My
  184. * @apiParam {int} coin 充值金额
  185. * @apiPermission Passport
  186. * @apiVersion 0.1.0
  187. * @apiSuccessExample {json} Success-Response:
  188. * HTTP/1.1 200 OK
  189. * @apiErrorExample {json} Error-Response:
  190. * HTTP/1.1 400 Bad Request
  191. */
  192. public function recharge(Request $request)
  193. {
  194. $validator = \Validator::make($request->all(),
  195. [
  196. 'coin' => 'required|integer',
  197. ],
  198. [
  199. 'coin.required' => '请填写金额',
  200. 'coin.integer' => '请输入整数',
  201. ]
  202. );
  203. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  204. $user = $this->getUser();
  205. $user->coin += $request->coin;
  206. $user->save();
  207. return $this->api('');
  208. }
  209. /**
  210. * @api {get} /api/my/system_info 系统消息(systemInfo)
  211. * @apiDescription 系统消息(systemInfo)
  212. * @apiGroup My
  213. * @apiPermission Passport
  214. * @apiVersion 0.1.0
  215. * @apiSuccessExample {json} Success-Response:
  216. * HTTP/1.1 200 OK
  217. *{
  218. * "status": true,
  219. * "status_code": 0,
  220. * "message": "",
  221. * "data": {
  222. * "data": [
  223. * ...
  224. * ]
  225. *}
  226. * @apiErrorExample {json} Error-Response:
  227. * HTTP/1.1 400 Bad Request
  228. */
  229. public function systemInfo()
  230. {
  231. $user = $this->getUser();
  232. $data = SystemInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
  233. return $this->api(compact('data'));
  234. }
  235. // 回复我的
  236. // public function replyMy()
  237. // {
  238. //
  239. // $user = $this->getUser();
  240. //// 梦想
  241. // $dreams = $user->UserDream;
  242. //
  243. // $data = $user->allInteraction;
  244. // foreach ($data as $item) {
  245. // $item->get_money = $item->dream->get_money;
  246. // $item->money = $item->dream->money;
  247. // }
  248. // dd($data) ;
  249. // if (count($dreams) == 0)
  250. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  251. // $comments_infos = [];
  252. // foreach ($dreams as $dream){
  253. // $comments_info = $dream->DreamInfo;
  254. // if (count($comments_info) > 0) {
  255. // foreach ($comments_info as $k => $value) {
  256. // $value->dream_name = $dream->dream;
  257. // $value->dream_about = $dream->about;
  258. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  259. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  260. // $value->reviewer = $value->CommentUser->nickname;
  261. // $value->reviewer_pic = $value->CommentUser->pic;
  262. // }
  263. // $comments_infos[] = $comments_info;
  264. // }
  265. // }
  266. //
  267. // return $this->api(compact('comments_infos'));
  268. // }
  269. /**
  270. * @api {get} /api/my/dream 我的梦想(dream)
  271. * @apiDescription 我的梦想(recharge)
  272. * @apiGroup My
  273. * @apiPermission Passport
  274. * @apiVersion 0.1.0
  275. * @apiSuccessExample {json} Success-Response:
  276. * HTTP/1.1 200 OK
  277. *{
  278. * "status": true,
  279. * "status_code": 0,
  280. * "message": "",
  281. * "data": [
  282. * {
  283. * "id": 5,
  284. * "user_id": 1,
  285. * "name": "梦想标题1",
  286. * "about": "梦想介绍",
  287. * "coin": 2500,
  288. * "time": 21,
  289. * "get_coin": 0,
  290. * "status": 0,
  291. * "video": null,
  292. * "sign": "",
  293. * "created_at": "2017-06-25 12:45:22",
  294. * "updated_at": "2017-06-25 12:45:22",
  295. * "pic": "https://timgsa.baidu.com/timg?image7b14f12f.jpg",
  296. * },
  297. * ]
  298. *}
  299. * @apiErrorExample {json} Error-Response:
  300. * HTTP/1.1 400 Bad Request
  301. */
  302. public function dream()
  303. {
  304. $user = $this->getUser();
  305. $dreams = $user->dreams;
  306. if (count($dreams) == 0)
  307. return $this->error(ErrorCode::DREAM_NOT_EXIST);
  308. foreach ($dreams as $dream){
  309. $dream->pic = count($dream->img) > 0 ? $dream->img->pic : '';
  310. }
  311. return $this->api($dreams);
  312. }
  313. /**
  314. * @api {get} /api/my/collection 我的收藏(collection)
  315. * @apiDescription 我的收藏(recharge)
  316. * @apiGroup My
  317. * @apiPermission Passport
  318. * @apiVersion 0.1.0
  319. * @apiSuccessExample {json} Success-Response:
  320. * HTTP/1.1 200 OK
  321. *{
  322. * "status": true,
  323. * "status_code": 0,
  324. * "message": "",
  325. * "data": {
  326. * "data": [
  327. * { 梦想详情
  328. * "id": 12,
  329. * "user_id": 2,
  330. * "name": "用户2梦想标题166",
  331. * "about": "用户2梦想介绍666",
  332. * "coin": 2500,
  333. * "time": 21,
  334. * "get_coin": 0,
  335. * "status": 0,
  336. * "video": null,
  337. * "sign": "",
  338. * },
  339. * "img": {
  340. * "title": "",
  341. * "pic": "https://f12f.jpg" 梦想封面图片
  342. * }
  343. * ],
  344. * "users": {
  345. * "2": "https://xxx.jpeg" ID号和头像
  346. * }
  347. * }
  348. *}
  349. * @apiErrorExample {json} Error-Response:
  350. * HTTP/1.1 400 Bad Request
  351. */
  352. public function collection()
  353. {
  354. $user = $this->getUser();
  355. $data = $user->collection;
  356. $users = [];
  357. foreach ($data as $item) {
  358. if ($item->pivot->interaction_number > 0) {
  359. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  360. $avatar = $user_info ? $user_info->avatar : '';
  361. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  362. $users[$item->pivot->dream_user_id] = $avatar;
  363. }
  364. }
  365. $item->img;
  366. }
  367. return $this->api(compact('data','users'));
  368. }
  369. /**
  370. * @api {get} /api/my/setting 设置(setting)
  371. * @apiDescription 设置(setting)
  372. * @apiGroup My
  373. * @apiPermission Passport
  374. * @apiVersion 0.1.0
  375. * @apiSuccessExample {json} Success-Response:
  376. * HTTP/1.1 200 OK
  377. *{
  378. * "status": true,
  379. * "status_code": 0,
  380. * "message": "",
  381. * "data": {
  382. * "key": "2511789", 电话
  383. * "value": "关于喵喵介绍" 关于喵喵
  384. * }
  385. *}
  386. * @apiErrorExample {json} Error-Response:
  387. * HTTP/1.1 400 Bad Request
  388. */
  389. public function setting()
  390. {
  391. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  392. return $this->api($data);
  393. }
  394. }