MyController.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\AccountLog;
  4. use App\Models\BaseDictionaryOptionModel;
  5. use App\Models\BaseSettingsModel;
  6. use App\Models\CommentInfoModel;
  7. use App\Models\DreamInfoModel;
  8. use App\Models\InteractionInfo;
  9. use App\Models\SearchInfoModel;
  10. use App\Models\Suggest;
  11. use App\Models\SystemInfoModel;
  12. use App\Models\UserBank;
  13. use App\Models\UserCareDream;
  14. use App\Models\UserCareUser;
  15. use App\Models\UserCashOut;
  16. use App\Models\UserInfoModel;
  17. use Illuminate\Http\Request;
  18. use App\Services\Base\ErrorCode;
  19. use App\Helper\JpushHelper;
  20. class MyController extends Controller
  21. {
  22. use JpushHelper;
  23. /**
  24. * @api {get} /api/my/show 个人首页
  25. * @apiDescription 个人首页
  26. * @apiGroup My
  27. * @apiPermission Passport
  28. * @apiSuccessExample {json} Success-Response:
  29. * HTTP/1.1 200 O* "status": true,
  30. {
  31. "status": true,
  32. "status_code": 0,
  33. "message": "",
  34. "data": {
  35. "id": 1,
  36. "phone": "13880642880",
  37. "nickname": "name1",
  38. "avatar": "/upload/user/20170629/e77068cc14c82086fb6b16e5bb7c3dd1.jpg",
  39. "birthday": "2000-06-21",
  40. "sign": 0,
  41. "money": 0,
  42. "coin": 308,
  43. "sex": 1,
  44. "signture": "我的个性签名1",
  45. "height": 170,
  46. "work": "网红",
  47. "emotion": 1,
  48. "address": "",
  49. "city": "上海",
  50. "detail_address": "",
  51. "status": 1,
  52. "wechat": "",
  53. "weibo": "",
  54. "remember_token": "",
  55. "created_at": "2017-06-25 10:27:08",
  56. "updated_at": "2017-08-19 13:24:29",
  57. "deleted_at": null,
  58. "care_number": 0, 关注
  59. "fans_number": 0, 粉丝
  60. "dreams_number": 9, 梦想
  61. "collection_number": 0, 收藏
  62. "interaction_number": 0, 发帖
  63. "huitie": 1, 回复
  64. }
  65. }
  66. * @apiErrorExample {json} Error-Response:
  67. * HTTP/1.1 400 Bad Request
  68. *{
  69. * "status": true,
  70. * "status_code": 0,
  71. * "message": "",
  72. * "data": {
  73. * "user": null
  74. * }
  75. *}
  76. */
  77. public function show()
  78. {
  79. $user = $this->getUser();
  80. /*
  81. * 我的关注人数,我的粉丝,收藏
  82. * 点赞?徽章?
  83. * */
  84. $care_num = $user->UserCareUser;
  85. $user->care_number = count($care_num);
  86. $fens = UserCareUser::where('other_user_id',$user->id)->get();
  87. $user->fans_number = count($fens);
  88. $dreams = $user->dreams;
  89. $user->dreams_number = count($dreams);
  90. $collection = $user->collection;
  91. $user->collection_number = count($collection);
  92. $interaction_infos = $user->allInteraction;
  93. $user->interaction_number = count($interaction_infos);
  94. $huitie = CommentInfoModel::where('user_id',$user->id)->orWhere('to_user_id',$user->id)->get()->groupBy('interaction_id');
  95. $user->huitie = count($huitie);
  96. return $this->api($user);
  97. }
  98. /**
  99. * @api {get} /api/my/edit 修改个人信息
  100. * @apiDescription 修改个人信息
  101. * @apiGroup My
  102. * @apiPermission Passport
  103. * @apiVersion 0.1.0
  104. * @apiSuccessExample {json} Success-Response:
  105. * HTTP/1.1 200 OK
  106. *{
  107. * "status": true,
  108. * "status_code": 0,
  109. * "message": "",
  110. "data": {
  111. "emotion": [
  112. {
  113. "value": "1",
  114. "name": "未婚"
  115. },
  116. {
  117. "value": "2",
  118. "name": "已婚"
  119. },
  120. {
  121. "value": "3",
  122. "name": "离异"
  123. }
  124. ],
  125. "sex": [
  126. {
  127. "value": "0",
  128. "name": "男"
  129. },
  130. {
  131. "value": "1",
  132. "name": "女"
  133. }
  134. ]
  135. }
  136. * }
  137. * @apiErrorExample {json} Error-Response:
  138. * HTTP/1.1 400 Bad Request
  139. * {
  140. * "status": false,
  141. * "status_code": 1500,
  142. * "message": "会员不存在",
  143. * "data": null
  144. * }
  145. */
  146. public function edit()
  147. {
  148. $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  149. where('dictionary_code','sex')->get();
  150. $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  151. where('dictionary_code','emotion')->get();
  152. return $this->api(compact('emotion','sex'));
  153. }
  154. /**
  155. * @api {post} /api/my/update 保存个人信息
  156. * @apiDescription 保存个人信息
  157. * @apiParam {string} pic 头像
  158. * @apiParam {int} sex 性别
  159. * @apiParam {string} signture 个性签名
  160. * @apiParam {int} emotion 情感状态
  161. * @apiParam {string} work 职业
  162. * @apiParam {int} height 身高
  163. * @apiGroup My
  164. * @apiPermission Passport
  165. * @apiVersion 0.1.0
  166. * @apiSuccessExample {json} Success-Response:
  167. * HTTP/1.1 200 OK
  168. *{
  169. * "status": true,
  170. * "status_code": 0,
  171. * "message": "",
  172. * "data": ""
  173. *}
  174. * @apiErrorExample {json} Error-Response:
  175. * HTTP/1.1 400 Bad Request
  176. *{
  177. * "status": false,
  178. * "status_code": 600,
  179. * "message": "保存用户数据失败",
  180. * "data": null
  181. * }
  182. */
  183. public function update(Request $request)
  184. {
  185. $user = $this->getUser();
  186. $data = $request->except('_token');
  187. $ok = $user->update($data);
  188. if ($ok == true) {
  189. return $this->api('');
  190. }else{
  191. return $this->error(ErrorCode::SAVE_USER_FAILED);
  192. }
  193. }
  194. /**
  195. * @api {post} /api/my/recharge 充值
  196. * @apiDescription 充值
  197. * @apiGroup My
  198. * @apiParam {int} coin 充值金额
  199. * @apiPermission Passport
  200. * @apiVersion 0.1.0
  201. * @apiSuccessExample {json} Success-Response:
  202. * HTTP/1.1 200 OK
  203. * @apiErrorExample {json} Error-Response:
  204. * HTTP/1.1 400 Bad Request
  205. */
  206. public function recharge(Request $request)
  207. {
  208. $validator = \Validator::make($request->all(),
  209. [
  210. 'coin' => 'required|integer',
  211. ],
  212. [
  213. 'coin.required' => '请填写金额',
  214. 'coin.integer' => '请输入整数',
  215. ]
  216. );
  217. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  218. $user = $this->getUser();
  219. $user->coin += $request->coin;
  220. $user->save();
  221. return $this->api('');
  222. }
  223. /**
  224. * @api {get} /api/my/reply 回复我的
  225. * @apiDescription 回复我的
  226. * @apiGroup My
  227. * @apiPermission Passport
  228. * @apiVersion 0.1.0
  229. * @apiSuccessExample {json} Success-Response:
  230. * HTTP/1.1 200 OK
  231. *{
  232. * "status": true,
  233. * "status_code": 0,
  234. * "message": "",
  235. * "data": [
  236. * {
  237. * ....
  238. * }
  239. * ]
  240. * @apiErrorExample {json} Error-Response:
  241. * HTTP/1.1 400 Bad Request
  242. */
  243. public function reply()
  244. {
  245. $user = $this->getUser();
  246. $data = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get(); //user_id
  247. foreach ($data as $item){ //访问接口 标记已读
  248. $item->update(['is_read'=>0]);
  249. $info = InteractionInfo::find($item->interaction_id);
  250. $dream_id =empty($info) ? 0 : $info->dream_id;
  251. $item->dream_id = $dream_id;
  252. }
  253. return $this->api($data);
  254. }
  255. /**
  256. * @api {get} /api/my/letter 私信
  257. * @apiDescription 私信
  258. * @apiGroup My
  259. * @apiPermission Passport
  260. * @apiVersion 0.1.0
  261. * @apiSuccessExample {json} Success-Response:
  262. * HTTP/1.1 200 OK
  263. *{
  264. * "status": true,
  265. * "status_code": 0,
  266. * "message": "",
  267. * "data": [
  268. * {
  269. * ....
  270. * }
  271. * ]
  272. * @apiErrorExample {json} Error-Response:
  273. * HTTP/1.1 400 Bad Request
  274. */
  275. public function letter()
  276. {
  277. $user = $this->getUser();
  278. $data = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  279. foreach ($data as $item){ //访问接口 标记已读
  280. $item->update(['is_read'=>1]);
  281. }
  282. return $this->api($data);
  283. } /**
  284. * @api {get} /api/my/system_info 系统消息
  285. * @apiDescription 系统消息
  286. * @apiGroup My
  287. * @apiPermission Passport
  288. * @apiVersion 0.1.0
  289. * @apiSuccessExample {json} Success-Response:
  290. * HTTP/1.1 200 OK
  291. *{
  292. * "status": true,
  293. * "status_code": 0,
  294. * "message": "",
  295. * "data": [
  296. * {
  297. * ....
  298. * }
  299. * ]
  300. * @apiErrorExample {json} Error-Response:
  301. * HTTP/1.1 400 Bad Request
  302. */
  303. public function systemInfo()
  304. {
  305. $user = $this->getUser();
  306. $data = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
  307. foreach ($data as $item){ //访问接口 标记已读
  308. $item->update(['is_read'=>1]);
  309. }
  310. return $this->api($data);
  311. }
  312. /**
  313. * @api {get} /api/my/info 消息中心
  314. * @apiDescription 消息中心
  315. * @apiGroup My
  316. * @apiPermission Passport
  317. * @apiVersion 0.1.0
  318. * @apiSuccessExample {json} Success-Response:
  319. * HTTP/1.1 200 OK
  320. *{
  321. * "status": true,
  322. * "status_code": 0,
  323. * "message": "",
  324. * "data": {
  325. * "systemInfo": {
  326. * "number": 3,
  327. * "is_read": 3
  328. * },
  329. * "letter": {
  330. * "number": 0,
  331. * "is_read": 0
  332. * },
  333. * "reply": {
  334. * "number": 3,
  335. * "is_read": 3
  336. * }
  337. * }
  338. *}
  339. * @apiErrorExample {json} Error-Response:
  340. * HTTP/1.1 400 Bad Request
  341. */
  342. public function info()
  343. {
  344. $user = $this->getUser();
  345. $systemInfo1 = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
  346. $systemInfo2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  347. ->whereNull('to_user_id')->orderBy('id','desc')->get();
  348. $letter1 = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  349. $letter2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  350. ->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  351. $comments1 = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get();
  352. $comments2 = CommentInfoModel::where('to_user_id',$user->id)->where('is_read','1')->orderBy('id','desc')->get();
  353. $arr = [];
  354. $arr['systemInfo']['number'] = count($systemInfo1) ;
  355. $arr['systemInfo']['is_read'] = count($systemInfo2) ;
  356. $arr['letter']['number'] = count($letter1) ;
  357. $arr['letter']['is_read'] = count($letter2) ;
  358. $arr['reply']['number'] = count($comments1) ;
  359. $arr['reply']['is_read'] = count($comments2) ;
  360. return $this->api($arr);
  361. }
  362. /**
  363. * @api {get} /api/my/read 设为已读
  364. * @apiDescription 设为已读
  365. * @apiGroup My
  366. * @apiPermission Passport
  367. * @apiVersion 0.1.0
  368. * @apiSuccessExample {json} Success-Response:
  369. * HTTP/1.1 200 OK
  370. *{
  371. * "status": true,
  372. * "status_code": 0,
  373. * "message": "",
  374. * "data": ""
  375. *}
  376. * @apiErrorExample {json} Error-Response:
  377. * HTTP/1.1 400 Bad Request
  378. * {
  379. * "status": false,
  380. * "status_code": 700,
  381. * "message": "操作失败",
  382. * "data": null
  383. *}
  384. */
  385. public function read()
  386. {
  387. $user = $this->getUser();
  388. $id = $user->id;
  389. $system_infos = SystemInfoModel::where(function ($query) use($id){
  390. $query->where('user_id',$id)->where('is_read','0');
  391. })->orWhere(function ($query) use($id){
  392. $query->where('to_user_id',$id)->where('is_read','0');
  393. })->orderBy('id','desc')->get();
  394. $comments = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
  395. foreach ($system_infos as $system_info){
  396. $system_info->update(['is_read'=>1]);
  397. }
  398. foreach ($comments as $comment){
  399. $comment->update(['is_read'=>1]);
  400. }
  401. if (count($system_infos) > 0 || count($comments) > 0) {
  402. return $this->api('');
  403. }else{
  404. return $this->error(ErrorCode::OPERATION_FAILED);
  405. }
  406. }
  407. /**
  408. * @api {get} /api/my/pay/article 支付说明
  409. * @apiDescription 支付说明
  410. * @apiGroup My
  411. * @apiPermission Passport
  412. * @apiVersion 0.1.0
  413. * @apiSuccessExample {json} Success-Response:
  414. * HTTP/1.1 200 OK
  415. *{
  416. * "status": true,
  417. * "status_code": 0,
  418. * "message": "",
  419. *"data": {
  420. * "key": "23453423453", 标题
  421. * "value": "<p><span style=\"color: rgb(255, 0, 0);\">42352345234534是大法官地方<
  422. * img src=\"/ueditor/php/upload/image/20170815/1502779635.jpg\" title=\"1502779635.jpg\" alt=\"a1.jpg\"/>234534</span><
  423. * br/></p>", 内容
  424. *}
  425. * ]
  426. *}
  427. * @apiErrorExample {json} Error-Response:
  428. * HTTP/1.1 400 Bad Request
  429. */
  430. public function payArticle()
  431. {
  432. $data = BaseSettingsModel::where('category','pay_article')->first();
  433. return $this->api($data);
  434. }
  435. /**
  436. * @api {post} /api/my/cash 提现
  437. * @apiDescription 提现
  438. * @apiGroup My
  439. * @apiParam {int} data[bank_id] 银行卡号id
  440. * @apiParam {int} data[cash] 提现金额
  441. * @apiPermission Passport
  442. * @apiVersion 0.1.0
  443. * @apiSuccessExample {json} Success-Response:
  444. * HTTP/1.1 200 OK
  445. *{
  446. * "status": false,
  447. * "status_code": 1413,
  448. * "message": "系统审核中",
  449. * "data": null
  450. *}
  451. * @apiErrorExample {json} Error-Response:
  452. *{
  453. * "status": false,
  454. * "status_code": 700,
  455. * "message": "操作失败",
  456. * "data": null
  457. *}
  458. */
  459. public function cash(Request $request)
  460. {
  461. $data = $request->data;
  462. $user = $this->getUser();
  463. $validator = \Validator::make($request->all(),
  464. [
  465. 'data.bank_id' => 'required|integer',
  466. 'data.cash' => 'required',
  467. ],
  468. [
  469. 'data.bank_id.required' => '请选择提现账号',
  470. 'data.bank_id.integer' => '提现账号不存在',
  471. 'data.cash.required' => '请输入金额',
  472. ]
  473. );
  474. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  475. // $info = [] ;
  476. // $info['from_type'] = '余额';
  477. // $info['from_id'] = $user->id;
  478. // $info['from_name'] = $user->name;
  479. // $info['op'] = '提现';
  480. // $info['from_amount'] = $data['coin'];
  481. // $info['to_type'] = '现金';
  482. // $info['to_id'] = $user->id;
  483. // $info['to_name'] = $data['account']; //账号
  484. // $info['note'] = $data['type'].$data['name'];
  485. // $ok = AccountLog::create($info);
  486. $data['user_id'] = $user->id;
  487. $data['status'] = 1;
  488. $ok = UserCashOut::create($data);
  489. $message = '你提现的¥'.$data["cash"].'已经到账啦,去实现梦想吧!喵~ ';
  490. $info = [
  491. 'user_id' => $user->id,
  492. 'message' => $message,
  493. ];
  494. SystemInfoModel::create($info);
  495. // 长连接
  496. $this->jPush($message,'',$user->id);
  497. if ($ok) {
  498. return $this->api(ErrorCode::verify);
  499. }else{
  500. return $this->error(ErrorCode::OPERATION_FAILED);
  501. }
  502. }
  503. // 联系客服
  504. /**
  505. * @api {post} /api/my/suggest 联系客服
  506. * @apiDescription 联系客服
  507. * @apiGroup My
  508. * @apiParam {string} data[content] 内容
  509. * @apiParam {string} data[email] 邮箱
  510. * @apiPermission Passport
  511. * @apiVersion 0.1.0
  512. * @apiSuccessExample {json} Success-Response:
  513. * HTTP/1.1 200 OK
  514. *{
  515. * "status": true,
  516. * "status_code": 0,
  517. * "message": "",
  518. * "data": ""
  519. *}
  520. * @apiErrorExample {json} Error-Response:
  521. *{
  522. * "status": false,
  523. * "status_code": 700,
  524. * "message": "操作失败",
  525. * "data": null
  526. *}
  527. */
  528. public function suggest(Request $request)
  529. {
  530. $data = $request->data;
  531. $user = $this->getUser();
  532. $validator = \Validator::make($request->all(),
  533. [
  534. 'data.content' => 'required',
  535. 'data.email' => 'required|email',
  536. ],
  537. [
  538. 'data.content.required' => '请输入你遇到的问题',
  539. 'data.email.required' => '请输入正确的邮箱地址',
  540. 'data.email.email' => '请输入正确的邮箱地址',
  541. ]
  542. );
  543. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  544. $data['user_id'] = $user->id;
  545. $ok =Suggest::create($data);
  546. if ($ok) {
  547. return $this->api('');
  548. }else{
  549. return $this->error(ErrorCode::OPERATION_FAILED);
  550. }
  551. }
  552. // 回复我的
  553. // public function replyMy()
  554. // {
  555. //
  556. // $user = $this->getUser();
  557. //// 梦想
  558. // $dreams = $user->UserDream;
  559. //
  560. // $data = $user->allInteraction;
  561. // foreach ($data as $item) {
  562. // $item->get_money = $item->dream->get_money;
  563. // $item->money = $item->dream->money;
  564. // }
  565. // dd($data) ;
  566. // if (count($dreams) == 0)
  567. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  568. // $comments_infos = [];
  569. // foreach ($dreams as $dream){
  570. // $comments_info = $dream->DreamInfo;
  571. // if (count($comments_info) > 0) {
  572. // foreach ($comments_info as $k => $value) {
  573. // $value->dream_name = $dream->dream;
  574. // $value->dream_about = $dream->about;
  575. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  576. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  577. // $value->reviewer = $value->CommentUser->nickname;
  578. // $value->reviewer_pic = $value->CommentUser->pic;
  579. // }
  580. // $comments_infos[] = $comments_info;
  581. // }
  582. // }
  583. //
  584. // return $this->api(compact('comments_infos'));
  585. // }
  586. /**
  587. * @api {get} /api/my/dream 我的梦想
  588. * @apiDescription 我的梦想
  589. * @apiGroup My
  590. * @apiPermission Passport
  591. * @apiVersion 0.1.0
  592. * @apiSuccessExample {json} Success-Response:
  593. * HTTP/1.1 200 OK
  594. {
  595. "status": true,
  596. "status_code": 0,
  597. "message": "",
  598. "data": {
  599. "current_page": 1,
  600. "data": [
  601. {
  602. "id": 32,
  603. "user_id": 1,
  604. "name": "name",
  605. "about": "13880642880",
  606. "coin": 100,
  607. "end_time": "0000-00-00 00:00:00",
  608. "get_coin": 2017,
  609. "mark": 100,
  610. "status": 127,
  611. "video": "0",
  612. "score": 0,
  613. "sign": "158730",
  614. "code": "http://www.miao.com/qrcodes/WECHATPAY_201708191324294255.png",
  615. "parameter": 0,
  616. "created_at": "2017-08-19 05:22:12",
  617. "updated_at": "2017-08-19 05:24:30",
  618. "img": {
  619. "title": "",
  620. "pic": "http://q8.9026.com/upload/dream/20170629/79c11614cc8a9d37f747e3974d055331.jpg"
  621. }
  622. },
  623. ],
  624. "from": 1,
  625. "last_page": 4,
  626. "next_page_url": "http://www.miao.com/api/my/dream?page=2",
  627. "path": "http://www.miao.com/api/my/dream",
  628. "per_page": 10,
  629. "prev_page_url": null,
  630. "to": 10,
  631. "total": 36
  632. }
  633. }
  634. * @apiErrorExample {json} Error-Response:
  635. * HTTP/1.1 400 Bad Request
  636. */
  637. public function dream()
  638. {
  639. $user = $this->getUser();
  640. $dreams = DreamInfoModel::where('user_id',$user->id)->orderBy('created_at','desc')->with('img')->paginate();
  641. return $this->api($dreams);
  642. }
  643. /**
  644. * @api {get} /api/my/collection 我的收藏
  645. * @apiDescription 我的收藏
  646. * @apiGroup My
  647. * @apiPermission Passport
  648. * @apiParam {string} [keyword] 关键字可选
  649. * @apiVersion 0.1.0
  650. * @apiSuccessExample {json} Success-Response:
  651. * HTTP/1.1 200 OK
  652. *{
  653. * "status": true,
  654. * "status_code": 0,
  655. * "message": "",
  656. * "data": {
  657. * "data": [
  658. * { 梦想详情
  659. * "id": 12,
  660. * "user_id": 2,
  661. * "name": "用户2梦想标题166",
  662. * "about": "用户2梦想介绍666",
  663. * "coin": 2500,
  664. * "time": 21,
  665. * "get_coin": 0,
  666. * "status": 0,
  667. * "video": null,
  668. * "sign": "",
  669. * },
  670. * "img": {
  671. * "title": "",
  672. * "pic": "https://f12f.jpg" 梦想封面图片
  673. * }
  674. * ],
  675. * "users": {
  676. * "2": "https://xxx.jpeg" ID号和头像
  677. * }
  678. * }
  679. *}
  680. * keyword存在
  681. *{
  682. * "status": true,
  683. * "status_code": 0,
  684. * "message": "",
  685. * "data": [
  686. * {
  687. * "id": 2,
  688. * "user_id": 1,
  689. * "dream_id": 12,
  690. * "dream_user_id": 2,
  691. * "interaction_number": 0,
  692. * "created_at": "2017-06-25 13:11:45",
  693. * "updated_at": "2017-06-25 13:11:45",
  694. * "dreams": [ 梦想
  695. * {
  696. * "id": 12,
  697. * "user_id": 2,
  698. * "name": "用户2梦想标题166",
  699. * "about": "用户2梦想介绍666",
  700. * "coin": 2500,
  701. * "end_time": 72000,
  702. * "get_coin": 792,
  703. * "mark": 5484,
  704. * "status": 0,
  705. * "video": "e",
  706. * "score": 158730,
  707. * "sign": "梦想达人",
  708. * "created_at": "2017-06-25 13:10:56",
  709. * "updated_at": "2017-06-28 16:53:39"
  710. * "img": { 图片
  711. * "title": "",
  712. * "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
  713. * },
  714. * "user": {
  715. *
  716. * }
  717. * }
  718. * ]
  719. * }
  720. * ]
  721. *}
  722. * @apiErrorExample {json} Error-Response:
  723. * HTTP/1.1 400 Bad Request
  724. */
  725. public function collection(Request $request)
  726. {
  727. $user = $this->getUser();
  728. if ($request->keyword) {
  729. $keyword ='%'.$request->keyword.'%';
  730. $data = UserCareDream::where('user_id',$user->id)->
  731. whereHas('dreams',function ($query) use($keyword){
  732. $query->where('end_time','>=',time())->where('name','like',$keyword);
  733. })->with('dreams')->get();
  734. foreach ($data as $item) {
  735. foreach ($item->dreams as $dream) {
  736. $dream->img;
  737. }
  738. }
  739. $this->insertSearchTable($user->id,$request->keyword);
  740. return $this->api($data);
  741. }else{
  742. $dreams = $user->collection;
  743. // $users = [];
  744. foreach ($dreams as $item) {
  745. /* if ($item->pivot->interaction_number > 0) {
  746. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  747. $avatar = $user_info ? $user_info->avatar : '';
  748. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  749. $users[$item->pivot->dream_user_id] = $avatar;
  750. }
  751. }*/
  752. $item->img;
  753. $item->user;
  754. }
  755. return $this->api(compact('dreams'));
  756. }
  757. }
  758. /**
  759. * @api {get} /api/my/miao 关于喵喵
  760. * @apiDescription 关于喵喵
  761. * @apiGroup My
  762. * @apiPermission Passport
  763. * @apiVersion 0.1.0
  764. * @apiSuccessExample {json} Success-Response:
  765. * HTTP/1.1 200 OK
  766. *{
  767. * "status": true,
  768. * "status_code": 0,
  769. * "message": "",
  770. * "data": {
  771. * "key": "2511789", 电话
  772. * "value": "关于喵喵介绍" 关于喵喵
  773. * }
  774. *}
  775. * @apiErrorExample {json} Error-Response:
  776. * HTTP/1.1 400 Bad Request
  777. */
  778. public function aboutMiao()
  779. {
  780. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  781. return $this->api($data);
  782. }
  783. /**
  784. * @api {get} /api/my/care 我关注的用户
  785. * @apiDescription 我关注的用户
  786. * @apiGroup My
  787. * @apiPermission Passport
  788. * @apiVersion 0.1.0
  789. * @apiSuccessExample {json} Success-Response:
  790. * HTTP/1.1 200 OK
  791. *{
  792. * "status": true,
  793. * "status_code": 0,
  794. * "message": "",
  795. * "data":[] or
  796. * "data": [
  797. * {
  798. * "id": 2,
  799. * "phone": "13880642881",
  800. * "nickname": "name2",
  801. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  802. * "birthday": "2000-06-21",
  803. * "sign": 0,
  804. * "money": 0,
  805. * "coin": 800,
  806. * "sex": 1,
  807. * "signture": "我的个性签名2",
  808. * "height": 200,
  809. * "work": "兼职",
  810. * "emotion": 2,
  811. * "address": "370105",
  812. * "city": "成都",
  813. * "detail_address": "",
  814. * "status": 1,
  815. * "wechat": "",
  816. * "weibo": "",
  817. * "remember_token": "",
  818. * "created_at": "2017-06-25 10:42:06",
  819. * "updated_at": "2017-06-30 09:15:04",
  820. * "deleted_at": null,
  821. * }
  822. * ]
  823. *}
  824. * @apiErrorExample {json} Error-Response:
  825. * HTTP/1.1 400 Bad Request
  826. */
  827. public function care()
  828. {
  829. $user = $this->getUser();
  830. $users =$user->UserCareUser;
  831. return $this->api($users);
  832. }
  833. public function insertSearchTable($id,$keyword)
  834. {
  835. $info = SearchInfoModel::where('user_id',$id)->
  836. where('search',trim($keyword))->first();
  837. if (count($info) == 0) {
  838. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  839. }else{
  840. $info->times += 1;
  841. $info->save();
  842. }
  843. }
  844. //我的银行账户
  845. /**
  846. * @api {get} /api/my/bank/list 我的银行账户
  847. * @apiDescription 我的银行账户
  848. * @apiGroup My
  849. * @apiPermission Passport
  850. * @apiVersion 0.1.0
  851. * @apiSuccessExample {json} Success-Response:
  852. * HTTP/1.1 200 OK
  853. *{
  854. * "status": true,
  855. * "status_code": 0,
  856. * "message": "",
  857. * "data":[] or
  858. * "data": [
  859. * {
  860. * "id": 1,
  861. * "user_id": 1,
  862. * "bank_name": "1",
  863. * "bank_number": "1", /账号
  864. * "bank_phone": "1",
  865. * "bank_user": "" 用户名/
  866. * "type": 微信, 微信(支付宝)二维码
  867. * "url": wwww.ddf, 二维码地址
  868. * "is_img": 1,
  869. * }
  870. *]
  871. * @apiErrorExample {json} Error-Response:
  872. * HTTP/1.1 400 Bad Request
  873. */
  874. public function bankList()
  875. {
  876. $user = $this->getUser();
  877. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  878. return $this->api($data);
  879. }
  880. /**
  881. * @api {get} /api/my/bank/account 账户余额
  882. * @apiDescription 账户余额
  883. * @apiGroup My
  884. * @apiPermission Passport
  885. * @apiVersion 0.1.0
  886. * @apiSuccessExample {json} Success-Response:
  887. * HTTP/1.1 200 OK
  888. *{
  889. * "status": true,
  890. * "status_code": 0,
  891. * "message": "",
  892. * "data":[] or
  893. * "data": {
  894. * "coin": 508, 余额
  895. * }
  896. *]
  897. * @apiErrorExample {json} Error-Response:
  898. * HTTP/1.1 400 Bad Request
  899. */
  900. public function account()
  901. {
  902. $user = $this->getUser();
  903. return $this->api($user);
  904. }
  905. // 添加银行卡
  906. /**
  907. * @api {post} /api/my/bank/create 添加银行卡
  908. * @apiDescription 添加银行卡
  909. * @apiGroup My
  910. * @apiParam {string} data[bank_name] 银行名称
  911. * @apiParam {string} data[bank_number] 银行卡号
  912. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  913. * @apiParam {string} data[bank_user] 银行卡用户姓名
  914. * @apiPermission Passport
  915. * @apiVersion 0.1.0
  916. * @apiSuccessExample {json} Success-Response:
  917. * HTTP/1.1 200 OK
  918. *{
  919. * "status": true,
  920. * "status_code": 0,
  921. * "message": "",
  922. * "data": ""
  923. *}
  924. * @apiErrorExample {json} Error-Response:
  925. *{
  926. * "status": false,
  927. * "status_code": 700,
  928. * "message": "操作失败",
  929. * "data": null
  930. *}
  931. */
  932. public function bankCreate(Request $request)
  933. {
  934. $data = $request->data;
  935. $user = $this->getUser();
  936. $validator = \Validator::make($request->all(),
  937. [
  938. 'data.bank_name' => 'required',
  939. 'data.bank_number' => 'required',
  940. 'data.bank_phone' => 'required',
  941. 'data.bank_user' => 'required',
  942. ],
  943. [
  944. 'data.bank_name.required' => '请选择账号类型',
  945. 'data.bank_number.required' => '请输入账号',
  946. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  947. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  948. ]
  949. );
  950. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  951. $data['user_id'] = $user->id;
  952. $ok =UserBank::create($data);
  953. if ($ok) {
  954. return $this->api('');
  955. }else{
  956. return $this->error(ErrorCode::OPERATION_FAILED);
  957. }
  958. } /**
  959. * @api {post} /api/my/bank/qrcode 添加二维码
  960. * @apiDescription 添加二维码
  961. * @apiGroup My
  962. * @apiParam {string} data[type] 类型
  963. * @apiParam {string} data[qrcode] 二维码图片
  964. * @apiPermission Passport
  965. * @apiVersion 0.1.0
  966. * @apiSuccessExample {json} Success-Response:
  967. * HTTP/1.1 200 OK
  968. *{
  969. * "status": true,
  970. * "status_code": 0,
  971. * "message": "",
  972. * "data": ""
  973. *}
  974. * @apiErrorExample {json} Error-Response:
  975. *{
  976. * "status": false,
  977. * "status_code": 700,
  978. * "message": "操作失败",
  979. * "data": null
  980. *}
  981. */
  982. public function bankImgCreate(Request $request)
  983. {
  984. $data = $request->data;
  985. $user = $this->getUser();
  986. $validator = \Validator::make($request->all(),
  987. [
  988. 'data.type' => 'required',
  989. 'data.qrcode' => 'required',
  990. ],
  991. [
  992. 'data.type.required' => '请选择账号类型',
  993. 'data.qrcode.required' => '请上传二维码图片',
  994. ]
  995. );
  996. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  997. $data['user_id'] = $user->id;
  998. /* $data['bank_user'] = '';
  999. $data['bank_phone'] = '';
  1000. $data['bank_number'] = '';
  1001. $data['bank_name'] = '';*/
  1002. $info = UserBank::whereNotNull('qrcode')->where('user_id',$user->id)
  1003. ->where('type',$data['type'])->first(); //定义为二维码
  1004. if (empty($info)) {
  1005. $ok =UserBank::create($data);
  1006. }else{
  1007. $ok = $info->update($data);
  1008. }
  1009. if ($ok) {
  1010. return $this->api('');
  1011. }else{
  1012. return $this->error(ErrorCode::OPERATION_FAILED);
  1013. }
  1014. }
  1015. /**
  1016. * @api {get} /api/my/bank/delete 删除银行卡
  1017. * @apiDescription 删除银行卡
  1018. * @apiGroup My
  1019. * @apiParam {int} id 银行卡id
  1020. * @apiPermission Passport
  1021. * @apiVersion 0.1.0
  1022. * @apiSuccessExample {json} Success-Response:
  1023. * HTTP/1.1 200 OK
  1024. *{
  1025. * "status": true,
  1026. * "status_code": 0,
  1027. * "message": "",
  1028. * "data": ""
  1029. *}
  1030. * @apiErrorExample {json} Error-Response:
  1031. *{
  1032. * "status": false,
  1033. * "status_code": 700,
  1034. * "message": "操作失败",
  1035. * "data": null
  1036. *}
  1037. */
  1038. public function bankDelete(Request $request)
  1039. {
  1040. $id = $request->id;
  1041. $validator = \Validator::make($request->all(),
  1042. [
  1043. 'id' => 'required',
  1044. ],
  1045. [
  1046. 'id.required' => '银行账号不存在',
  1047. ]
  1048. );
  1049. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1050. $ok =UserBank::destroy($id);
  1051. if ($ok) {
  1052. return $this->api('');
  1053. }else{
  1054. return $this->error(ErrorCode::OPERATION_FAILED);
  1055. }
  1056. }
  1057. }