MyController.php 32 KB

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