MyController.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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/dreamInfo 梦想消息
  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 dreamInfo()
  244. {
  245. // 梦想消息分为 支持 收藏 互动 提现 梦想暂停 结束
  246. $user = $this->getUser();
  247. $data = SystemInfoModel::where('user_id',$user->id)->where('type_id',1)->orderBy('id','desc')->get();
  248. foreach ($data as $item){ //访问接口 标记已读
  249. $item->update(['is_read'=>0]);
  250. $info = InteractionInfo::find($item->interaction_id);
  251. $dream_id =empty($info) ? 0 : $info->dream_id;
  252. $item->dreamid = $dream_id;
  253. }
  254. return $this->api($data);
  255. }
  256. /**
  257. * @api {get} /api/my/sup_info 支持消息
  258. * @apiDescription 支持消息
  259. * @apiGroup My
  260. * @apiPermission Passport
  261. * @apiVersion 0.1.0
  262. * @apiSuccessExample {json} Success-Response:
  263. * HTTP/1.1 200 OK
  264. *{
  265. * "status": true,
  266. * "status_code": 0,
  267. * "message": "",
  268. * "data": [
  269. * {
  270. * ....
  271. * }
  272. * ]
  273. * @apiErrorExample {json} Error-Response:
  274. * HTTP/1.1 400 Bad Request
  275. */
  276. public function supInfo()
  277. {
  278. $user = $this->getUser();
  279. $data = SystemInfoModel::with('touser')->where('user_id',$user->id)->where('type_id',2)->orderBy('id','desc')->get();
  280. foreach ($data as $item){ //访问接口 标记已读
  281. $item->update(['is_read'=>1]);
  282. }
  283. return $this->api($data);
  284. }
  285. /**
  286. * @api {get} /api/my/system_info 通知消息
  287. * @apiDescription 通知消息
  288. * @apiGroup My
  289. * @apiPermission Passport
  290. * @apiVersion 0.1.0
  291. * @apiSuccessExample {json} Success-Response:
  292. * HTTP/1.1 200 OK
  293. *{
  294. * "status": true,
  295. * "status_code": 0,
  296. * "message": "",
  297. * "data": [
  298. * {
  299. * ....
  300. * }
  301. * ]
  302. * @apiErrorExample {json} Error-Response:
  303. * HTTP/1.1 400 Bad Request
  304. */
  305. public function systemInfo()
  306. {
  307. $user = $this->getUser();
  308. $data = SystemInfoModel::where('user_id',$user->id)->where('type_id',0)->orderBy('id','desc')->get();
  309. foreach ($data as $item){ //访问接口 标记已读
  310. $item->update(['is_read'=>1]);
  311. }
  312. return $this->api($data);
  313. }
  314. /**
  315. * @api {get} /api/my/info 消息中心
  316. * @apiDescription 消息中心
  317. * @apiGroup My
  318. * @apiPermission Passport
  319. * @apiVersion 0.1.0
  320. * @apiSuccessExample {json} Success-Response:
  321. * HTTP/1.1 200 OK
  322. *{
  323. * "status": true,
  324. * "status_code": 0,
  325. * "message": "",
  326. * "data": {
  327. * "dream_info": {
  328. * "number": 3,
  329. * },
  330. * "sup_info": {
  331. * "number": 0,
  332. * },
  333. * "system_info": {
  334. * "number": 3,
  335. * }
  336. * }
  337. *}
  338. * @apiErrorExample {json} Error-Response:
  339. * HTTP/1.1 400 Bad Request
  340. */
  341. public function info()
  342. {
  343. $user = $this->getUser();
  344. /* $systemInfo1 = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
  345. $systemInfo2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  346. ->whereNull('to_user_id')->orderBy('id','desc')->get();
  347. $letter1 = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  348. $letter2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  349. ->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  350. $comments1 = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get();
  351. $comments2 = CommentInfoModel::where('to_user_id',$user->id)->where('is_read','1')->orderBy('id','desc')->get();
  352. $arr = [];
  353. $arr['systemInfo']['number'] = count($systemInfo1) ;
  354. $arr['systemInfo']['is_read'] = count($systemInfo2) ;
  355. $arr['letter']['number'] = count($letter1) ;
  356. $arr['letter']['is_read'] = count($letter2) ;
  357. $arr['reply']['number'] = count($comments1) ;
  358. $arr['reply']['is_read'] = count($comments2) ;*/
  359. // 梦想消息 支持消息 通知消息
  360. $user_id = $user->id;
  361. $dream_info = SystemInfoModel::where('to_user_id',$user_id)->where('type_id',1)->where('is_read',0)->orderBy('id','desc')->get();
  362. $sup_info = SystemInfoModel::where('to_user_id',$user_id)->where('type_id',2)->where('is_read',0)->orderBy('id','desc')->get();
  363. $system_info = SystemInfoModel::where('to_user_id',$user_id)->where('type_id',0)->where('is_read',0)->orderBy('id','desc')->get();
  364. $arr['dream_info']['number'] = count($dream_info) ;
  365. $arr['sup_info']['number'] = count($sup_info) ;
  366. $arr['system_info']['number'] = count($system_info) ;
  367. return $this->api($arr);
  368. }
  369. /**
  370. * @api {get} /api/my/read 设为已读
  371. * @apiDescription 设为已读
  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. *}
  383. * @apiErrorExample {json} Error-Response:
  384. * HTTP/1.1 400 Bad Request
  385. * {
  386. * "status": false,
  387. * "status_code": 700,
  388. * "message": "操作失败",
  389. * "data": null
  390. *}
  391. */
  392. public function read()
  393. {
  394. $user = $this->getUser();
  395. $id = $user->id;
  396. $system_infos = SystemInfoModel::where(function ($query) use($id){
  397. $query->where('user_id',$id)->where('is_read','0');
  398. })->orWhere(function ($query) use($id){
  399. $query->where('to_user_id',$id)->where('is_read','0');
  400. })->orderBy('id','desc')->get();
  401. $comments = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
  402. foreach ($system_infos as $system_info){
  403. $system_info->update(['is_read'=>1]);
  404. }
  405. foreach ($comments as $comment){
  406. $comment->update(['is_read'=>1]);
  407. }
  408. if (count($system_infos) > 0 || count($comments) > 0) {
  409. return $this->api('');
  410. }else{
  411. return $this->error(ErrorCode::OPERATION_FAILED);
  412. }
  413. }
  414. /**
  415. * @api {get} /api/my/pay/article 支付说明
  416. * @apiDescription 支付说明
  417. * @apiGroup My
  418. * @apiPermission Passport
  419. * @apiVersion 0.1.0
  420. * @apiSuccessExample {json} Success-Response:
  421. * HTTP/1.1 200 OK
  422. *{
  423. * "status": true,
  424. * "status_code": 0,
  425. * "message": "",
  426. *"data": {
  427. * "key": "23453423453", 标题
  428. * "value": "<p><span style=\"color: rgb(255, 0, 0);\">42352345234534是大法官地方<
  429. * img src=\"/ueditor/php/upload/image/20170815/1502779635.jpg\" title=\"1502779635.jpg\" alt=\"a1.jpg\"/>234534</span><
  430. * br/></p>", 内容
  431. *}
  432. * ]
  433. *}
  434. * @apiErrorExample {json} Error-Response:
  435. * HTTP/1.1 400 Bad Request
  436. */
  437. public function payArticle()
  438. {
  439. $data = BaseSettingsModel::where('category','pay_article')->first();
  440. return $this->api($data);
  441. }
  442. /**
  443. * @api {post} /api/my/cash 提现
  444. * @apiDescription 提现
  445. * @apiGroup My
  446. * @apiParam {int} data[bank_id] 银行卡号id
  447. * @apiParam {int} data[cash] 提现金额
  448. * @apiPermission Passport
  449. * @apiVersion 0.1.0
  450. * @apiSuccessExample {json} Success-Response:
  451. * HTTP/1.1 200 OK
  452. *{
  453. * "status": false,
  454. * "status_code": 1413,
  455. * "message": "系统审核中",
  456. * "data": null
  457. *}
  458. * @apiErrorExample {json} Error-Response:
  459. *{
  460. * "status": false,
  461. * "status_code": 700,
  462. * "message": "操作失败",
  463. * "data": null
  464. *}
  465. */
  466. public function cash(Request $request)
  467. {
  468. $data = $request->data;
  469. $user = $this->getUser();
  470. $validator = \Validator::make($request->all(),
  471. [
  472. 'data.bank_id' => 'required|integer',
  473. 'data.cash' => 'required',
  474. ],
  475. [
  476. 'data.bank_id.required' => '请选择提现账号',
  477. 'data.bank_id.integer' => '提现账号不存在',
  478. 'data.cash.required' => '请输入金额',
  479. ]
  480. );
  481. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  482. // $info = [] ;
  483. // $info['from_type'] = '余额';
  484. // $info['from_id'] = $user->id;
  485. // $info['from_name'] = $user->name;
  486. // $info['op'] = '提现';
  487. // $info['from_amount'] = $data['coin'];
  488. // $info['to_type'] = '现金';
  489. // $info['to_id'] = $user->id;
  490. // $info['to_name'] = $data['account']; //账号
  491. // $info['note'] = $data['type'].$data['name'];
  492. // $ok = AccountLog::create($info);
  493. $data['user_id'] = $user->id;
  494. $data['status'] = 1;
  495. $ok = UserCashOut::create($data);
  496. $message = '你提现的¥'.$data["cash"].'已经到账啦,去实现梦想吧!喵~ ';
  497. $info = [
  498. 'user_id' => $user->id,
  499. 'message' => $message,
  500. 'attr_id' => 4,
  501. 'type_id' => 1,
  502. ];
  503. SystemInfoModel::create($info);
  504. // 长连接
  505. $this->jPush($message,'',$user->id);
  506. if ($ok) {
  507. return $this->api(ErrorCode::verify);
  508. }else{
  509. return $this->error(ErrorCode::OPERATION_FAILED);
  510. }
  511. }
  512. // 联系客服
  513. /**
  514. * @api {post} /api/my/suggest 联系客服
  515. * @apiDescription 联系客服
  516. * @apiGroup My
  517. * @apiParam {string} data[content] 内容
  518. * @apiParam {string} data[email] 邮箱
  519. * @apiPermission Passport
  520. * @apiVersion 0.1.0
  521. * @apiSuccessExample {json} Success-Response:
  522. * HTTP/1.1 200 OK
  523. *{
  524. * "status": true,
  525. * "status_code": 0,
  526. * "message": "",
  527. * "data": ""
  528. *}
  529. * @apiErrorExample {json} Error-Response:
  530. *{
  531. * "status": false,
  532. * "status_code": 700,
  533. * "message": "操作失败",
  534. * "data": null
  535. *}
  536. */
  537. public function suggest(Request $request)
  538. {
  539. $data = $request->data;
  540. $user = $this->getUser();
  541. $validator = \Validator::make($request->all(),
  542. [
  543. 'data.content' => 'required',
  544. 'data.email' => 'required|email',
  545. ],
  546. [
  547. 'data.content.required' => '请输入你遇到的问题',
  548. 'data.email.required' => '请输入正确的邮箱地址',
  549. 'data.email.email' => '请输入正确的邮箱地址',
  550. ]
  551. );
  552. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  553. $data['user_id'] = $user->id;
  554. $ok =Suggest::create($data);
  555. if ($ok) {
  556. return $this->api('');
  557. }else{
  558. return $this->error(ErrorCode::OPERATION_FAILED);
  559. }
  560. }
  561. // 回复我的
  562. // public function replyMy()
  563. // {
  564. //
  565. // $user = $this->getUser();
  566. //// 梦想
  567. // $dreams = $user->UserDream;
  568. //
  569. // $data = $user->allInteraction;
  570. // foreach ($data as $item) {
  571. // $item->get_money = $item->dream->get_money;
  572. // $item->money = $item->dream->money;
  573. // }
  574. // dd($data) ;
  575. // if (count($dreams) == 0)
  576. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  577. // $comments_infos = [];
  578. // foreach ($dreams as $dream){
  579. // $comments_info = $dream->DreamInfo;
  580. // if (count($comments_info) > 0) {
  581. // foreach ($comments_info as $k => $value) {
  582. // $value->dream_name = $dream->dream;
  583. // $value->dream_about = $dream->about;
  584. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  585. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  586. // $value->reviewer = $value->CommentUser->nickname;
  587. // $value->reviewer_pic = $value->CommentUser->pic;
  588. // }
  589. // $comments_infos[] = $comments_info;
  590. // }
  591. // }
  592. //
  593. // return $this->api(compact('comments_infos'));
  594. // }
  595. /**
  596. * @api {get} /api/my/dream 我的梦想
  597. * @apiDescription 我的梦想
  598. * @apiGroup My
  599. * @apiPermission Passport
  600. * @apiVersion 0.1.0
  601. * @apiSuccessExample {json} Success-Response:
  602. * HTTP/1.1 200 OK
  603. {
  604. "status": true,
  605. "status_code": 0,
  606. "message": "",
  607. "data": {
  608. "current_page": 1,
  609. "data": [
  610. {
  611. "id": 32,
  612. "user_id": 1,
  613. "name": "name",
  614. "about": "13880642880",
  615. "coin": 100,
  616. "end_time": "0000-00-00 00:00:00",
  617. "get_coin": 2017,
  618. "mark": 100,
  619. "status": 127,
  620. "video": "0",
  621. "score": 0,
  622. "sign": "158730",
  623. "code": "http://www.miao.com/qrcodes/WECHATPAY_201708191324294255.png",
  624. "parameter": 0,
  625. "created_at": "2017-08-19 05:22:12",
  626. "updated_at": "2017-08-19 05:24:30",
  627. "img": {
  628. "title": "",
  629. "pic": "http://q8.9026.com/upload/dream/20170629/79c11614cc8a9d37f747e3974d055331.jpg"
  630. }
  631. },
  632. ],
  633. "from": 1,
  634. "last_page": 4,
  635. "next_page_url": "http://www.miao.com/api/my/dream?page=2",
  636. "path": "http://www.miao.com/api/my/dream",
  637. "per_page": 10,
  638. "prev_page_url": null,
  639. "to": 10,
  640. "total": 36
  641. }
  642. }
  643. * @apiErrorExample {json} Error-Response:
  644. * HTTP/1.1 400 Bad Request
  645. */
  646. public function dream()
  647. {
  648. $user = $this->getUser();
  649. $dreams = DreamInfoModel::where('user_id',$user->id)->orderBy('created_at','desc')->with('img')->paginate();
  650. return $this->api($dreams);
  651. }
  652. /**
  653. * @api {get} /api/my/collection 我的收藏
  654. * @apiDescription 我的收藏
  655. * @apiGroup My
  656. * @apiPermission Passport
  657. * @apiParam {string} [keyword] 关键字可选
  658. * @apiVersion 0.1.0
  659. * @apiSuccessExample {json} Success-Response:
  660. * HTTP/1.1 200 OK
  661. *{
  662. * "status": true,
  663. * "status_code": 0,
  664. * "message": "",
  665. * "data": {
  666. * "data": [
  667. * { 梦想详情
  668. * "id": 12,
  669. * "user_id": 2,
  670. * "name": "用户2梦想标题166",
  671. * "about": "用户2梦想介绍666",
  672. * "coin": 2500,
  673. * "time": 21,
  674. * "get_coin": 0,
  675. * "status": 0,
  676. * "video": null,
  677. * "sign": "",
  678. * },
  679. * "img": {
  680. * "title": "",
  681. * "pic": "https://f12f.jpg" 梦想封面图片
  682. * }
  683. * ],
  684. * "users": {
  685. * "2": "https://xxx.jpeg" ID号和头像
  686. * }
  687. * }
  688. *}
  689. * keyword存在
  690. *{
  691. * "status": true,
  692. * "status_code": 0,
  693. * "message": "",
  694. * "data": [
  695. * {
  696. * "id": 2,
  697. * "user_id": 1,
  698. * "dream_id": 12,
  699. * "dream_user_id": 2,
  700. * "interaction_number": 0,
  701. * "created_at": "2017-06-25 13:11:45",
  702. * "updated_at": "2017-06-25 13:11:45",
  703. * "dreams": [ 梦想
  704. * {
  705. * "id": 12,
  706. * "user_id": 2,
  707. * "name": "用户2梦想标题166",
  708. * "about": "用户2梦想介绍666",
  709. * "coin": 2500,
  710. * "end_time": 72000,
  711. * "get_coin": 792,
  712. * "mark": 5484,
  713. * "status": 0,
  714. * "video": "e",
  715. * "score": 158730,
  716. * "sign": "梦想达人",
  717. * "created_at": "2017-06-25 13:10:56",
  718. * "updated_at": "2017-06-28 16:53:39"
  719. * "img": { 图片
  720. * "title": "",
  721. * "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
  722. * },
  723. * "user": {
  724. *
  725. * }
  726. * }
  727. * ]
  728. * }
  729. * ]
  730. *}
  731. * @apiErrorExample {json} Error-Response:
  732. * HTTP/1.1 400 Bad Request
  733. */
  734. public function collection(Request $request)
  735. {
  736. $user = $this->getUser();
  737. if ($request->keyword) {
  738. $keyword ='%'.$request->keyword.'%';
  739. $data = UserCareDream::where('user_id',$user->id)->
  740. whereHas('dreams',function ($query) use($keyword){
  741. $query->where('end_time','>=',time())->where('name','like',$keyword);
  742. })->with('dreams')->get();
  743. foreach ($data as $item) {
  744. foreach ($item->dreams as $dream) {
  745. $dream->img;
  746. }
  747. }
  748. $this->insertSearchTable($user->id,$request->keyword);
  749. return $this->api($data);
  750. }else{
  751. $dreams = $user->collection;
  752. // $users = [];
  753. foreach ($dreams as $item) {
  754. /* if ($item->pivot->interaction_number > 0) {
  755. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  756. $avatar = $user_info ? $user_info->avatar : '';
  757. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  758. $users[$item->pivot->dream_user_id] = $avatar;
  759. }
  760. }*/
  761. $item->img;
  762. $item->user;
  763. }
  764. return $this->api(compact('dreams'));
  765. }
  766. }
  767. /**
  768. * @api {get} /api/my/miao 关于喵喵
  769. * @apiDescription 关于喵喵
  770. * @apiGroup My
  771. * @apiPermission Passport
  772. * @apiVersion 0.1.0
  773. * @apiSuccessExample {json} Success-Response:
  774. * HTTP/1.1 200 OK
  775. *{
  776. * "status": true,
  777. * "status_code": 0,
  778. * "message": "",
  779. * "data": {
  780. * "key": "2511789", 电话
  781. * "value": "关于喵喵介绍" 关于喵喵
  782. * }
  783. *}
  784. * @apiErrorExample {json} Error-Response:
  785. * HTTP/1.1 400 Bad Request
  786. */
  787. public function aboutMiao()
  788. {
  789. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  790. return $this->api($data);
  791. }
  792. /**
  793. * @api {get} /api/my/care 我关注的用户
  794. * @apiDescription 我关注的用户
  795. * @apiGroup My
  796. * @apiPermission Passport
  797. * @apiVersion 0.1.0
  798. * @apiSuccessExample {json} Success-Response:
  799. * HTTP/1.1 200 OK
  800. *{
  801. * "status": true,
  802. * "status_code": 0,
  803. * "message": "",
  804. * "data":[] or
  805. * "data": [
  806. * {
  807. * "id": 2,
  808. * "phone": "13880642881",
  809. * "nickname": "name2",
  810. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  811. * "birthday": "2000-06-21",
  812. * "sign": 0,
  813. * "money": 0,
  814. * "coin": 800,
  815. * "sex": 1,
  816. * "signture": "我的个性签名2",
  817. * "height": 200,
  818. * "work": "兼职",
  819. * "emotion": 2,
  820. * "address": "370105",
  821. * "city": "成都",
  822. * "detail_address": "",
  823. * "status": 1,
  824. * "wechat": "",
  825. * "weibo": "",
  826. * "remember_token": "",
  827. * "created_at": "2017-06-25 10:42:06",
  828. * "updated_at": "2017-06-30 09:15:04",
  829. * "deleted_at": null,
  830. * }
  831. * ]
  832. *}
  833. * @apiErrorExample {json} Error-Response:
  834. * HTTP/1.1 400 Bad Request
  835. */
  836. public function care()
  837. {
  838. $user = $this->getUser();
  839. $users =$user->UserCareUser;
  840. return $this->api($users);
  841. }
  842. /**
  843. * @api {get} /api/my/careme 关注我的用户
  844. * @apiDescription 关注我的用户
  845. * @apiGroup My
  846. * @apiPermission Passport
  847. * @apiVersion 0.1.0
  848. * @apiSuccessExample {json} Success-Response:
  849. * HTTP/1.1 200 OK
  850. *{
  851. * "status": true,
  852. * "status_code": 0,
  853. * "message": "",
  854. * "data":[] or
  855. * "data": [
  856. * {
  857. * "id": 2,
  858. * "phone": "13880642881",
  859. * "nickname": "name2",
  860. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  861. * "birthday": "2000-06-21",
  862. * "sign": 0,
  863. * "money": 0,
  864. * "coin": 800,
  865. * "sex": 1,
  866. * "signture": "我的个性签名2",
  867. * "height": 200,
  868. * "work": "兼职",
  869. * "emotion": 2,
  870. * "address": "370105",
  871. * "city": "成都",
  872. * "detail_address": "",
  873. * "status": 1,
  874. * "wechat": "",
  875. * "weibo": "",
  876. * "remember_token": "",
  877. * "created_at": "2017-06-25 10:42:06",
  878. * "updated_at": "2017-06-30 09:15:04",
  879. * "deleted_at": null,
  880. * }
  881. * ]
  882. *}
  883. * @apiErrorExample {json} Error-Response:
  884. * HTTP/1.1 400 Bad Request
  885. */
  886. public function careMe()
  887. {
  888. $user = $this->getUser();
  889. $users =$user->UserCareMe;
  890. return $this->api($users);
  891. }
  892. public function insertSearchTable($id,$keyword)
  893. {
  894. $info = SearchInfoModel::where('user_id',$id)->
  895. where('search',trim($keyword))->first();
  896. if (count($info) == 0) {
  897. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  898. }else{
  899. $info->times += 1;
  900. $info->save();
  901. }
  902. }
  903. //我的银行账户
  904. /**
  905. * @api {get} /api/my/bank/list 我的银行账户
  906. * @apiDescription 我的银行账户
  907. * @apiGroup My
  908. * @apiPermission Passport
  909. * @apiVersion 0.1.0
  910. * @apiSuccessExample {json} Success-Response:
  911. * HTTP/1.1 200 OK
  912. *{
  913. * "status": true,
  914. * "status_code": 0,
  915. * "message": "",
  916. * "data":[] or
  917. * "data": [
  918. * {
  919. * "id": 1,
  920. * "user_id": 1,
  921. * "bank_name": "1",
  922. * "bank_number": "1", /账号
  923. * "bank_phone": "1",
  924. * "bank_user": "" 用户名/
  925. * "type": 微信, 微信(支付宝)二维码
  926. * "url": wwww.ddf, 二维码地址
  927. * "is_img": 1,
  928. * }
  929. *]
  930. * @apiErrorExample {json} Error-Response:
  931. * HTTP/1.1 400 Bad Request
  932. */
  933. public function bankList()
  934. {
  935. $user = $this->getUser();
  936. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  937. return $this->api($data);
  938. }
  939. /**
  940. * @api {get} /api/my/bank/account 账户余额
  941. * @apiDescription 账户余额
  942. * @apiGroup My
  943. * @apiPermission Passport
  944. * @apiVersion 0.1.0
  945. * @apiSuccessExample {json} Success-Response:
  946. * HTTP/1.1 200 OK
  947. *{
  948. * "status": true,
  949. * "status_code": 0,
  950. * "message": "",
  951. * "data":[] or
  952. * "data": {
  953. * "coin": 508, 余额
  954. * }
  955. *]
  956. * @apiErrorExample {json} Error-Response:
  957. * HTTP/1.1 400 Bad Request
  958. */
  959. public function account()
  960. {
  961. $user = $this->getUser();
  962. return $this->api($user);
  963. }
  964. // 添加银行卡
  965. /**
  966. * @api {post} /api/my/bank/create 添加银行卡
  967. * @apiDescription 添加银行卡
  968. * @apiGroup My
  969. * @apiParam {string} data[bank_name] 银行名称
  970. * @apiParam {string} data[bank_number] 银行卡号
  971. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  972. * @apiParam {string} data[bank_user] 银行卡用户姓名
  973. * @apiPermission Passport
  974. * @apiVersion 0.1.0
  975. * @apiSuccessExample {json} Success-Response:
  976. * HTTP/1.1 200 OK
  977. *{
  978. * "status": true,
  979. * "status_code": 0,
  980. * "message": "",
  981. * "data": ""
  982. *}
  983. * @apiErrorExample {json} Error-Response:
  984. *{
  985. * "status": false,
  986. * "status_code": 700,
  987. * "message": "操作失败",
  988. * "data": null
  989. *}
  990. */
  991. public function bankCreate(Request $request)
  992. {
  993. $data = $request->data;
  994. $user = $this->getUser();
  995. $validator = \Validator::make($request->all(),
  996. [
  997. 'data.bank_name' => 'required',
  998. 'data.bank_number' => 'required',
  999. 'data.bank_phone' => 'required',
  1000. 'data.bank_user' => 'required',
  1001. ],
  1002. [
  1003. 'data.bank_name.required' => '请选择账号类型',
  1004. 'data.bank_number.required' => '请输入账号',
  1005. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  1006. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  1007. ]
  1008. );
  1009. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1010. $data['user_id'] = $user->id;
  1011. $ok =UserBank::create($data);
  1012. if ($ok) {
  1013. return $this->api('');
  1014. }else{
  1015. return $this->error(ErrorCode::OPERATION_FAILED);
  1016. }
  1017. } /**
  1018. * @api {post} /api/my/bank/qrcode 添加二维码
  1019. * @apiDescription 添加二维码
  1020. * @apiGroup My
  1021. * @apiParam {string} data[type] 类型
  1022. * @apiParam {string} data[qrcode] 二维码图片
  1023. * @apiPermission Passport
  1024. * @apiVersion 0.1.0
  1025. * @apiSuccessExample {json} Success-Response:
  1026. * HTTP/1.1 200 OK
  1027. *{
  1028. * "status": true,
  1029. * "status_code": 0,
  1030. * "message": "",
  1031. * "data": ""
  1032. *}
  1033. * @apiErrorExample {json} Error-Response:
  1034. *{
  1035. * "status": false,
  1036. * "status_code": 700,
  1037. * "message": "操作失败",
  1038. * "data": null
  1039. *}
  1040. */
  1041. public function bankImgCreate(Request $request)
  1042. {
  1043. $data = $request->data;
  1044. $user = $this->getUser();
  1045. $validator = \Validator::make($request->all(),
  1046. [
  1047. 'data.type' => 'required',
  1048. 'data.qrcode' => 'required',
  1049. ],
  1050. [
  1051. 'data.type.required' => '请选择账号类型',
  1052. 'data.qrcode.required' => '请上传二维码图片',
  1053. ]
  1054. );
  1055. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1056. $data['user_id'] = $user->id;
  1057. /* $data['bank_user'] = '';
  1058. $data['bank_phone'] = '';
  1059. $data['bank_number'] = '';
  1060. $data['bank_name'] = '';*/
  1061. $info = UserBank::whereNotNull('qrcode')->where('user_id',$user->id)
  1062. ->where('type',$data['type'])->first(); //定义为二维码
  1063. if (empty($info)) {
  1064. $ok =UserBank::create($data);
  1065. }else{
  1066. $ok = $info->update($data);
  1067. }
  1068. if ($ok) {
  1069. return $this->api('');
  1070. }else{
  1071. return $this->error(ErrorCode::OPERATION_FAILED);
  1072. }
  1073. }
  1074. /**
  1075. * @api {get} /api/my/bank/delete 删除银行卡
  1076. * @apiDescription 删除银行卡
  1077. * @apiGroup My
  1078. * @apiParam {int} id 银行卡id
  1079. * @apiPermission Passport
  1080. * @apiVersion 0.1.0
  1081. * @apiSuccessExample {json} Success-Response:
  1082. * HTTP/1.1 200 OK
  1083. *{
  1084. * "status": true,
  1085. * "status_code": 0,
  1086. * "message": "",
  1087. * "data": ""
  1088. *}
  1089. * @apiErrorExample {json} Error-Response:
  1090. *{
  1091. * "status": false,
  1092. * "status_code": 700,
  1093. * "message": "操作失败",
  1094. * "data": null
  1095. *}
  1096. */
  1097. public function bankDelete(Request $request)
  1098. {
  1099. $id = $request->id;
  1100. $validator = \Validator::make($request->all(),
  1101. [
  1102. 'id' => 'required',
  1103. ],
  1104. [
  1105. 'id.required' => '银行账号不存在',
  1106. ]
  1107. );
  1108. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1109. $ok =UserBank::destroy($id);
  1110. if ($ok) {
  1111. return $this->api('');
  1112. }else{
  1113. return $this->error(ErrorCode::OPERATION_FAILED);
  1114. }
  1115. }
  1116. // 发私信
  1117. /**
  1118. * @api {post} /api/my/letter/store 发送私信
  1119. * @apiDescription 发送私信
  1120. * @apiGroup My
  1121. * @apiParam {string} content 私信内容
  1122. * @apiParam {int} to_user_id 私信对象
  1123. * @apiPermission Passport
  1124. * @apiVersion 0.1.0
  1125. * @apiSuccessExample {json} Success-Response:
  1126. * HTTP/1.1 200 OK
  1127. *{
  1128. * "status": true,
  1129. * "status_code": 0,
  1130. * "message": "",
  1131. * "data": ""
  1132. *}
  1133. * @apiErrorExample {json} Error-Response:
  1134. *{
  1135. * "status": false,
  1136. * "status_code": 700,
  1137. * "message": "操作失败",
  1138. * "data": null
  1139. *}
  1140. */
  1141. public function letterStore(Request $request)
  1142. {
  1143. $validator = \Validator::make($request->all(),
  1144. [
  1145. 'content' => 'required',
  1146. 'to_user_id' => 'required',
  1147. ],
  1148. [
  1149. 'content.required' => '私信内容不存在',
  1150. 'to_user_id.required' => '私信对象不存在',
  1151. ]
  1152. );
  1153. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1154. $user = $this->getUser();
  1155. $user_id = $user->id;
  1156. $info = $request->input('content');
  1157. $to_user_id = $request->input('to_user_id');
  1158. // 链接到最近的一个梦想
  1159. $dream = DreamInfoModel::where('user_id',$user_id)->orderBy('id','desc')->first();
  1160. $dream_id = empty($dream) ? 0 : $dream->id;
  1161. $arr = [
  1162. 'user_id'=>$to_user_id,
  1163. 'info'=>$info,
  1164. 'message'=>$user->nickname.'给你发了个私信哦~点击看看!',
  1165. 'to_user_id'=>$user_id,
  1166. 'dream_id'=>$dream_id,
  1167. 'type_id'=>2,
  1168. 'is_url'=>1,
  1169. ];
  1170. $ok =SystemInfoModel::create($arr);
  1171. if ($ok) {
  1172. $this->jPush($user->nickname.'给你发了个私信哦~点击看看!','',$to_user_id);
  1173. return $this->api('');
  1174. }else{
  1175. return $this->error(ErrorCode::OPERATION_FAILED);
  1176. }
  1177. } /**
  1178. * @api {get} /api/my/letter/show 查看私信
  1179. * @apiDescription 查看私信
  1180. * @apiGroup My
  1181. * @apiParam {int} id 私信主键id
  1182. * @apiPermission Passport
  1183. * @apiVersion 0.1.0
  1184. * @apiSuccessExample {json} Success-Response:
  1185. * HTTP/1.1 200 OK
  1186. *{
  1187. * "status": true,
  1188. * "status_code": 0,
  1189. * "message": "",
  1190. * "data": ""
  1191. *}
  1192. * @apiErrorExample {json} Error-Response:
  1193. *{
  1194. * "status": false,
  1195. * "status_code": 700,
  1196. * "message": "操作失败",
  1197. * "data": null
  1198. *}
  1199. */
  1200. public function letterShow(Request $request)
  1201. {
  1202. $validator = \Validator::make($request->all(),
  1203. [
  1204. 'id' => 'required',
  1205. ],
  1206. [
  1207. 'id.required' => '私信id不存在',
  1208. ]
  1209. );
  1210. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1211. $user = $this->getUser();
  1212. $user_id = $user->id;
  1213. $id = $request->input('id');
  1214. $data = SystemInfoModel::find($id);
  1215. return $this->api($data);
  1216. }
  1217. }