MyController.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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\SupportDreamModel;
  12. use App\Models\SystemInfoModel;
  13. use App\Models\UserBank;
  14. use App\Models\UserCareDream;
  15. use App\Models\UserCareUser;
  16. use App\Models\UserCashOut;
  17. use App\Models\UserInfoModel;
  18. use Illuminate\Http\Request;
  19. use App\Services\Base\ErrorCode;
  20. use App\Helper\JpushHelper;
  21. class MyController extends Controller
  22. {
  23. use JpushHelper;
  24. /**
  25. * @api {get} /api/my/show 个人首页
  26. * @apiDescription 个人首页
  27. * @apiGroup My
  28. * @apiPermission Passport
  29. * @apiSuccessExample {json} Success-Response:
  30. * HTTP/1.1 200 O* "status": true,
  31. {
  32. "status": true,
  33. "status_code": 0,
  34. "message": "",
  35. "data": {
  36. "id": 1,
  37. "phone": "13880642880",
  38. "nickname": "name1",
  39. "avatar": "/upload/user/20170629/e77068cc14c82086fb6b16e5bb7c3dd1.jpg",
  40. "birthday": "2000-06-21",
  41. "sign": 0,
  42. "money": 0,
  43. "coin": 308,
  44. "sex": 1,
  45. "signture": "我的个性签名1",
  46. "height": 170,
  47. "work": "网红",
  48. "emotion": 1,
  49. "address": "",
  50. "city": "上海",
  51. "detail_address": "",
  52. "status": 1,
  53. "wechat": "",
  54. "weibo": "",
  55. "remember_token": "",
  56. "created_at": "2017-06-25 10:27:08",
  57. "updated_at": "2017-08-19 13:24:29",
  58. "deleted_at": null,
  59. "care_number": 0, 关注
  60. "fans_number": 0, 粉丝
  61. "dreams_number": 9, 梦想
  62. "collection_number": 0, 收藏
  63. "interaction_number": 0, 发帖
  64. "huitie": 1, 回复
  65. }
  66. }
  67. * @apiErrorExample {json} Error-Response:
  68. * HTTP/1.1 400 Bad Request
  69. *{
  70. * "status": true,
  71. * "status_code": 0,
  72. * "message": "",
  73. * "data": {
  74. * "user": null
  75. * }
  76. *}
  77. */
  78. public function show()
  79. {
  80. $user = $this->getUser();
  81. /*
  82. * 我的关注人数,我的粉丝,收藏
  83. * 点赞?徽章?
  84. * */
  85. $care_num = $user->UserCareUser;
  86. $user->care_number = count($care_num);
  87. $fens = UserCareUser::where('other_user_id',$user->id)->get();
  88. $user->fans_number = count($fens);
  89. $dreams = $user->dreams;
  90. $user->dreams_number = count($dreams);
  91. $collection = $user->collection;
  92. $user->collection_number = count($collection);
  93. $interaction_infos = $user->allInteraction;
  94. $user->interaction_number = count($interaction_infos);
  95. $huitie = CommentInfoModel::where('user_id',$user->id)->orWhere('to_user_id',$user->id)->get()->groupBy('interaction_id');
  96. $user->huitie = count($huitie);
  97. return $this->api($user);
  98. }
  99. /**
  100. * @api {get} /api/my/edit 修改个人信息
  101. * @apiDescription 修改个人信息
  102. * @apiGroup My
  103. * @apiPermission Passport
  104. * @apiVersion 0.1.0
  105. * @apiSuccessExample {json} Success-Response:
  106. * HTTP/1.1 200 OK
  107. *{
  108. * "status": true,
  109. * "status_code": 0,
  110. * "message": "",
  111. "data": {
  112. "emotion": [
  113. {
  114. "value": "1",
  115. "name": "未婚"
  116. },
  117. {
  118. "value": "2",
  119. "name": "已婚"
  120. },
  121. {
  122. "value": "3",
  123. "name": "离异"
  124. }
  125. ],
  126. "sex": [
  127. {
  128. "value": "0",
  129. "name": "男"
  130. },
  131. {
  132. "value": "1",
  133. "name": "女"
  134. }
  135. ]
  136. }
  137. * }
  138. * @apiErrorExample {json} Error-Response:
  139. * HTTP/1.1 400 Bad Request
  140. * {
  141. * "status": false,
  142. * "status_code": 1500,
  143. * "message": "会员不存在",
  144. * "data": null
  145. * }
  146. */
  147. public function edit()
  148. {
  149. $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  150. where('dictionary_code','sex')->get();
  151. $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
  152. where('dictionary_code','emotion')->get();
  153. return $this->api(compact('emotion','sex'));
  154. }
  155. /**
  156. * @api {post} /api/my/update 保存个人信息
  157. * @apiDescription 保存个人信息
  158. * @apiParam {string} pic 头像
  159. * @apiParam {int} sex 性别
  160. * @apiParam {string} signture 个性签名
  161. * @apiParam {int} emotion 情感状态
  162. * @apiParam {string} work 职业
  163. * @apiParam {int} height 身高
  164. * @apiGroup My
  165. * @apiPermission Passport
  166. * @apiVersion 0.1.0
  167. * @apiSuccessExample {json} Success-Response:
  168. * HTTP/1.1 200 OK
  169. *{
  170. * "status": true,
  171. * "status_code": 0,
  172. * "message": "",
  173. * "data": ""
  174. *}
  175. * @apiErrorExample {json} Error-Response:
  176. * HTTP/1.1 400 Bad Request
  177. *{
  178. * "status": false,
  179. * "status_code": 600,
  180. * "message": "保存用户数据失败",
  181. * "data": null
  182. * }
  183. */
  184. public function update(Request $request)
  185. {
  186. $user = $this->getUser();
  187. $data = $request->except('_token');
  188. $ok = $user->update($data);
  189. if ($ok == true) {
  190. return $this->api('');
  191. }else{
  192. return $this->error(ErrorCode::SAVE_USER_FAILED);
  193. }
  194. }
  195. /**
  196. * @api {post} /api/my/recharge 充值
  197. * @apiDescription 充值
  198. * @apiGroup My
  199. * @apiParam {int} coin 充值金额
  200. * @apiPermission Passport
  201. * @apiVersion 0.1.0
  202. * @apiSuccessExample {json} Success-Response:
  203. * HTTP/1.1 200 OK
  204. * @apiErrorExample {json} Error-Response:
  205. * HTTP/1.1 400 Bad Request
  206. */
  207. public function recharge(Request $request)
  208. {
  209. $validator = \Validator::make($request->all(),
  210. [
  211. 'coin' => 'required|integer',
  212. ],
  213. [
  214. 'coin.required' => '请填写金额',
  215. 'coin.integer' => '请输入整数',
  216. ]
  217. );
  218. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  219. $user = $this->getUser();
  220. $user->coin += $request->coin;
  221. $user->save();
  222. return $this->api('');
  223. }
  224. /**
  225. * @api {get} /api/my/dream_info 梦想消息
  226. * @apiDescription 梦想消息
  227. * @apiGroup My
  228. * @apiPermission Passport
  229. * @apiVersion 0.1.0
  230. * @apiSuccessExample {json} Success-Response:
  231. * HTTP/1.1 200 OK
  232. *{
  233. * "status": true,
  234. * "status_code": 0,
  235. * "message": "",
  236. * "data": [
  237. * {
  238. * ....
  239. * }
  240. * ]
  241. * @apiErrorExample {json} Error-Response:
  242. * HTTP/1.1 400 Bad Request
  243. */
  244. public function dreamInfo()
  245. {
  246. // 梦想消息分为 1支持 2收藏 3互动 4提现 5梦想暂停 6结束
  247. $user = $this->getUser();
  248. $data1 = SystemInfoModel::where('to_user_id',$user->id)->where('type_id',1)->where('attr_id',1)->orderBy('id','desc')->get()->toArray();
  249. $new_data1 = [] ;
  250. if (count($data1) > 0) {
  251. if (count($data1) >= 5) {
  252. $data1[0]['message'] = "已经有".count($data1)."个人支持了你的梦想!";
  253. $new_data1[] = $data1[0];
  254. }else{
  255. $new_data1 = $data1;
  256. }
  257. }
  258. $data2 = SystemInfoModel::where('to_user_id',$user->id)->where('type_id',1)->where('attr_id',2)->orderBy('id','desc')->get()->toArray();
  259. $new_data2 = [] ;
  260. if (count($data2) > 0) {
  261. if (count($data2) >= 5) {
  262. $data2[0]['message'] = "已经有".count($data2)."个人收藏了你的梦想!";
  263. $new_data2[] = $data2[0];
  264. }else{
  265. $new_data2 = $data2;
  266. }
  267. }
  268. $data3 = SystemInfoModel::where('to_user_id',$user->id)->where('type_id',1)->where('attr_id',3)->orderBy('id','desc')->get()->toArray();
  269. $new_data3 = [] ;
  270. if (count($data3) > 0) {
  271. if (count($data3) >= 5) {
  272. $data3[0]['message'] = "你的互动已经有".count($data3)."个留言啦!快点击看看!";
  273. $new_data3[] = $data3[0];
  274. }else{
  275. $new_data3 = $data3;
  276. }
  277. }
  278. $data456 = SystemInfoModel::where('to_user_id',$user->id)->where('type_id',1)
  279. ->where(function ($query) {
  280. $query->where('attr_id',4)->orWhere('attr_id',5)->orWhere('attr_id',6);
  281. })->orderBy('id','desc')->get()->toArray();
  282. $data = array_merge($new_data1,$new_data2,$new_data3,$data456);
  283. SystemInfoModel::where('to_user_id',$user->id)->where('type_id',1)->update(['is_read' => 1]);
  284. return $this->api($data);
  285. // foreach ($data as $item){ //访问接口 标记已读
  286. // $item->update(['is_read'=>0]);
  287. // $info = InteractionInfo::find($item->interaction_id);
  288. // $dream_id =empty($info) ? 0 : $info->dream_id;
  289. // $item->dreamid = $dream_id;
  290. // }
  291. }
  292. /**
  293. * @api {get} /api/my/sup_info 支持消息
  294. * @apiDescription 支持消息
  295. * @apiGroup My
  296. * @apiPermission Passport
  297. * @apiVersion 0.1.0
  298. * @apiSuccessExample {json} Success-Response:
  299. * HTTP/1.1 200 OK
  300. *{
  301. * "status": true,
  302. * "status_code": 0,
  303. * "message": "",
  304. * "data": [
  305. * {
  306. * ....
  307. * }
  308. * ]
  309. * @apiErrorExample {json} Error-Response:
  310. * HTTP/1.1 400 Bad Request
  311. */
  312. public function supInfo()
  313. {
  314. // 支持消息有 7私信 8@ 9梦想倒计时 10排名 梦想结束
  315. $user = $this->getUser();
  316. $data8 = SystemInfoModel::where('to_user_id',$user->id)->where('type_id',2)->where('attr_id',8)->orderBy('id','desc')->get()->toArray();
  317. // 计算interaction_id出现的次数
  318. // dd(array_column($data8,"interaction_id"));
  319. $count = array_count_values(array_filter(array_column($data8,"interaction_id")));
  320. $new_data8 = [] ;
  321. if (!empty($count)) {
  322. foreach ($count as $interaction_id => $value) {
  323. $interaction = InteractionInfo::find($interaction_id);
  324. $dream_id = empty($interaction) ? '0':$interaction->dream_id;
  325. if ($value>=5) {
  326. $message =empty($interaction) ? '': $interaction->title."互动上已经提起了你".($value)."次!你还不去瞧一瞧?你也太大牌啦!";
  327. }else{
  328. $message =empty($interaction) ? '': $interaction->title."提起了你哦~点击看看!";
  329. }
  330. if (!empty($message)) {
  331. $new_data8[] = [
  332. 'dream_id'=>$dream_id,
  333. 'interaction_id'=>$interaction_id,
  334. 'message'=>$message,
  335. "attr_id" => 8,
  336. "is_reply" => 0,
  337. "is_max" => 0,
  338. "is_ok" => 0,
  339. "is_end" => 0,
  340. "is_url" => 0,
  341. "type_id" => 2,
  342. ];
  343. }
  344. }
  345. }
  346. $data9 = SystemInfoModel::with('user')->where('to_user_id',$user->id)->where('type_id',2)->where('attr_id','!=',8)->orderBy('id','desc')->get()->toArray();
  347. $data = array_merge($new_data8,$data9);
  348. SystemInfoModel::where('to_user_id',$user->id)->where('type_id',2)->update(['is_read' => 1]);
  349. return $this->api($data);
  350. }
  351. /**
  352. * @api {get} /api/my/system_info 通知消息
  353. * @apiDescription 通知消息
  354. * @apiGroup My
  355. * @apiPermission Passport
  356. * @apiVersion 0.1.0
  357. * @apiSuccessExample {json} Success-Response:
  358. * HTTP/1.1 200 OK
  359. *{
  360. * "status": true,
  361. * "status_code": 0,
  362. * "message": "",
  363. * "data": [
  364. * {
  365. * ....
  366. * }
  367. * ]
  368. * @apiErrorExample {json} Error-Response:
  369. * HTTP/1.1 400 Bad Request
  370. */
  371. public function systemInfo()
  372. {
  373. $user = $this->getUser();
  374. $data = SystemInfoModel::where('to_user_id',$user->id)->where('type_id',0)->orderBy('id','desc')->get()->toArray();
  375. SystemInfoModel::where('to_user_id',$user->id)->where('type_id',0)->update(['is_read' => 1]);
  376. return $this->api($data);
  377. }
  378. /**
  379. * @api {get} /api/my/info 消息中心
  380. * @apiDescription 消息中心
  381. * @apiGroup My
  382. * @apiPermission Passport
  383. * @apiVersion 0.1.0
  384. * @apiSuccessExample {json} Success-Response:
  385. * HTTP/1.1 200 OK
  386. *{
  387. * "status": true,
  388. * "status_code": 0,
  389. * "message": "",
  390. * "data": {
  391. * "dream_info": {
  392. * "number": 3,
  393. * },
  394. * "sup_info": {
  395. * "number": 0,
  396. * },
  397. * "system_info": {
  398. * "number": 3,
  399. * }
  400. * }
  401. *}
  402. * @apiErrorExample {json} Error-Response:
  403. * HTTP/1.1 400 Bad Request
  404. */
  405. public function info()
  406. {
  407. $user = $this->getUser();
  408. /* $systemInfo1 = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
  409. $systemInfo2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  410. ->whereNull('to_user_id')->orderBy('id','desc')->get();
  411. $letter1 = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  412. $letter2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
  413. ->whereNotNull('to_user_id')->orderBy('id','desc')->get();
  414. $comments1 = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get();
  415. $comments2 = CommentInfoModel::where('to_user_id',$user->id)->where('is_read','1')->orderBy('id','desc')->get();
  416. $arr = [];
  417. $arr['systemInfo']['number'] = count($systemInfo1) ;
  418. $arr['systemInfo']['is_read'] = count($systemInfo2) ;
  419. $arr['letter']['number'] = count($letter1) ;
  420. $arr['letter']['is_read'] = count($letter2) ;
  421. $arr['reply']['number'] = count($comments1) ;
  422. $arr['reply']['is_read'] = count($comments2) ;*/
  423. // 梦想消息 支持消息 通知消息
  424. $user_id = $user->id;
  425. $dream_info = SystemInfoModel::where('to_user_id',$user_id)->where('type_id',1)->where('is_read',0)->orderBy('id','desc')->get();
  426. $sup_info = SystemInfoModel::where('to_user_id',$user_id)->where('type_id',2)->where('is_read',0)->orderBy('id','desc')->get();
  427. $system_info = SystemInfoModel::where('to_user_id',$user_id)->where('type_id',0)->where('is_read',0)->orderBy('id','desc')->get();
  428. $arr['dream_info']['number'] = count($dream_info) ;
  429. $arr['sup_info']['number'] = count($sup_info) ;
  430. $arr['system_info']['number'] = count($system_info) ;
  431. return $this->api($arr);
  432. }
  433. /**
  434. * @api {get} /api/my/read 设为已读
  435. * @apiDescription 设为已读
  436. * @apiGroup My
  437. * @apiPermission Passport
  438. * @apiVersion 0.1.0
  439. * @apiSuccessExample {json} Success-Response:
  440. * HTTP/1.1 200 OK
  441. *{
  442. * "status": true,
  443. * "status_code": 0,
  444. * "message": "",
  445. * "data": ""
  446. *}
  447. * @apiErrorExample {json} Error-Response:
  448. * HTTP/1.1 400 Bad Request
  449. * {
  450. * "status": false,
  451. * "status_code": 700,
  452. * "message": "操作失败",
  453. * "data": null
  454. *}
  455. */
  456. public function read()
  457. {
  458. $user = $this->getUser();
  459. $id = $user->id;
  460. $system_infos = SystemInfoModel::where(function ($query) use($id){
  461. $query->where('user_id',$id)->where('is_read','0');
  462. })->orWhere(function ($query) use($id){
  463. $query->where('to_user_id',$id)->where('is_read','0');
  464. })->orderBy('id','desc')->get();
  465. $comments = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
  466. foreach ($system_infos as $system_info){
  467. $system_info->update(['is_read'=>1]);
  468. }
  469. foreach ($comments as $comment){
  470. $comment->update(['is_read'=>1]);
  471. }
  472. if (count($system_infos) > 0 || count($comments) > 0) {
  473. return $this->api('');
  474. }else{
  475. return $this->error(ErrorCode::OPERATION_FAILED);
  476. }
  477. }
  478. /**
  479. * @api {get} /api/my/pay/article 支付说明
  480. * @apiDescription 支付说明
  481. * @apiGroup My
  482. * @apiPermission Passport
  483. * @apiVersion 0.1.0
  484. * @apiSuccessExample {json} Success-Response:
  485. * HTTP/1.1 200 OK
  486. *{
  487. * "status": true,
  488. * "status_code": 0,
  489. * "message": "",
  490. *"data": {
  491. * "key": "23453423453", 标题
  492. * "value": "<p><span style=\"color: rgb(255, 0, 0);\">42352345234534是大法官地方<
  493. * img src=\"/ueditor/php/upload/image/20170815/1502779635.jpg\" title=\"1502779635.jpg\" alt=\"a1.jpg\"/>234534</span><
  494. * br/></p>", 内容
  495. *}
  496. * ]
  497. *}
  498. * @apiErrorExample {json} Error-Response:
  499. * HTTP/1.1 400 Bad Request
  500. */
  501. public function payArticle()
  502. {
  503. $data = BaseSettingsModel::where('category','pay_article')->first();
  504. return $this->api($data);
  505. }
  506. /**
  507. * @api {post} /api/my/cash 提现
  508. * @apiDescription 提现
  509. * @apiGroup My
  510. * @apiParam {int} data[bank_id] 银行卡号id
  511. * @apiParam {int} data[cash] 提现金额
  512. * @apiPermission Passport
  513. * @apiVersion 0.1.0
  514. * @apiSuccessExample {json} Success-Response:
  515. * HTTP/1.1 200 OK
  516. *{
  517. * "status": false,
  518. * "status_code": 1413,
  519. * "message": "系统审核中",
  520. * "data": null
  521. *}
  522. * @apiErrorExample {json} Error-Response:
  523. *{
  524. * "status": false,
  525. * "status_code": 700,
  526. * "message": "操作失败",
  527. * "data": null
  528. *}
  529. */
  530. public function cash(Request $request)
  531. {
  532. $data = $request->data;
  533. $user = $this->getUser();
  534. $validator = \Validator::make($request->all(),
  535. [
  536. 'data.bank_id' => 'required|integer',
  537. 'data.cash' => 'required',
  538. ],
  539. [
  540. 'data.bank_id.required' => '请选择提现账号',
  541. 'data.bank_id.integer' => '提现账号不存在',
  542. 'data.cash.required' => '请输入金额',
  543. ]
  544. );
  545. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  546. // $info = [] ;
  547. // $info['from_type'] = '余额';
  548. // $info['from_id'] = $user->id;
  549. // $info['from_name'] = $user->name;
  550. // $info['op'] = '提现';
  551. // $info['from_amount'] = $data['coin'];
  552. // $info['to_type'] = '现金';
  553. // $info['to_id'] = $user->id;
  554. // $info['to_name'] = $data['account']; //账号
  555. // $info['note'] = $data['type'].$data['name'];
  556. // $ok = AccountLog::create($info);
  557. $data['user_id'] = $user->id;
  558. $data['status'] = 1;
  559. $ok = UserCashOut::create($data);
  560. $message = '你提现的¥'.$data["cash"].'已经到账啦,去实现梦想吧!喵~ ';
  561. $info = [
  562. 'user_id' => $user->id,
  563. 'message' => $message,
  564. 'attr_id' => 4,
  565. 'type_id' => 1,
  566. ];
  567. SystemInfoModel::create($info);
  568. // 长连接
  569. $this->jPush($message,'',$user->id);
  570. if ($ok) {
  571. return $this->api(ErrorCode::verify);
  572. }else{
  573. return $this->error(ErrorCode::OPERATION_FAILED);
  574. }
  575. }
  576. // 联系客服
  577. /**
  578. * @api {post} /api/my/suggest 联系客服
  579. * @apiDescription 联系客服
  580. * @apiGroup My
  581. * @apiParam {string} data[content] 内容
  582. * @apiParam {string} data[email] 邮箱
  583. * @apiPermission Passport
  584. * @apiVersion 0.1.0
  585. * @apiSuccessExample {json} Success-Response:
  586. * HTTP/1.1 200 OK
  587. *{
  588. * "status": true,
  589. * "status_code": 0,
  590. * "message": "",
  591. * "data": ""
  592. *}
  593. * @apiErrorExample {json} Error-Response:
  594. *{
  595. * "status": false,
  596. * "status_code": 700,
  597. * "message": "操作失败",
  598. * "data": null
  599. *}
  600. */
  601. public function suggest(Request $request)
  602. {
  603. $data = $request->data;
  604. $user = $this->getUser();
  605. $validator = \Validator::make($request->all(),
  606. [
  607. 'data.content' => 'required',
  608. 'data.email' => 'required|email',
  609. ],
  610. [
  611. 'data.content.required' => '请输入你遇到的问题',
  612. 'data.email.required' => '请输入正确的邮箱地址',
  613. 'data.email.email' => '请输入正确的邮箱地址',
  614. ]
  615. );
  616. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  617. $data['user_id'] = $user->id;
  618. $ok =Suggest::create($data);
  619. if ($ok) {
  620. return $this->api('');
  621. }else{
  622. return $this->error(ErrorCode::OPERATION_FAILED);
  623. }
  624. }
  625. // 回复我的
  626. // public function replyMy()
  627. // {
  628. //
  629. // $user = $this->getUser();
  630. //// 梦想
  631. // $dreams = $user->UserDream;
  632. //
  633. // $data = $user->allInteraction;
  634. // foreach ($data as $item) {
  635. // $item->get_money = $item->dream->get_money;
  636. // $item->money = $item->dream->money;
  637. // }
  638. // dd($data) ;
  639. // if (count($dreams) == 0)
  640. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  641. // $comments_infos = [];
  642. // foreach ($dreams as $dream){
  643. // $comments_info = $dream->DreamInfo;
  644. // if (count($comments_info) > 0) {
  645. // foreach ($comments_info as $k => $value) {
  646. // $value->dream_name = $dream->dream;
  647. // $value->dream_about = $dream->about;
  648. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  649. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  650. // $value->reviewer = $value->CommentUser->nickname;
  651. // $value->reviewer_pic = $value->CommentUser->pic;
  652. // }
  653. // $comments_infos[] = $comments_info;
  654. // }
  655. // }
  656. //
  657. // return $this->api(compact('comments_infos'));
  658. // }
  659. /**
  660. * @api {get} /api/my/dream 我的梦想
  661. * @apiDescription 我的梦想
  662. * @apiGroup My
  663. * @apiPermission Passport
  664. * @apiVersion 0.1.0
  665. * @apiSuccessExample {json} Success-Response:
  666. * HTTP/1.1 200 OK
  667. {
  668. "status": true,
  669. "status_code": 0,
  670. "message": "",
  671. "data": {
  672. "current_page": 1,
  673. "data": [
  674. {
  675. "id": 32,
  676. "user_id": 1,
  677. "name": "name",
  678. "about": "13880642880",
  679. "coin": 100,
  680. "end_time": "0000-00-00 00:00:00",
  681. "get_coin": 2017,
  682. "mark": 100,
  683. "status": 127,
  684. "video": "0",
  685. "score": 0,
  686. "sign": "158730",
  687. "code": "http://www.miao.com/qrcodes/WECHATPAY_201708191324294255.png",
  688. "parameter": 0,
  689. "created_at": "2017-08-19 05:22:12",
  690. "updated_at": "2017-08-19 05:24:30",
  691. "img": {
  692. "title": "",
  693. "pic": "http://q8.9026.com/upload/dream/20170629/79c11614cc8a9d37f747e3974d055331.jpg"
  694. }
  695. },
  696. ],
  697. "from": 1,
  698. "last_page": 4,
  699. "next_page_url": "http://www.miao.com/api/my/dream?page=2",
  700. "path": "http://www.miao.com/api/my/dream",
  701. "per_page": 10,
  702. "prev_page_url": null,
  703. "to": 10,
  704. "total": 36
  705. }
  706. }
  707. * @apiErrorExample {json} Error-Response:
  708. * HTTP/1.1 400 Bad Request
  709. */
  710. public function dream()
  711. {
  712. $user = $this->getUser();
  713. $dreams = DreamInfoModel::where('user_id',$user->id)->orderBy('created_at','desc')->with('img')->paginate();
  714. return $this->api($dreams);
  715. }
  716. /**
  717. * @api {get} /api/my/collection 我的收藏
  718. * @apiDescription 我的收藏
  719. * @apiGroup My
  720. * @apiPermission Passport
  721. * @apiParam {string} [keyword] 关键字可选
  722. * @apiVersion 0.1.0
  723. * @apiSuccessExample {json} Success-Response:
  724. * HTTP/1.1 200 OK
  725. *{
  726. * "status": true,
  727. * "status_code": 0,
  728. * "message": "",
  729. * "data": {
  730. * "data": [
  731. * { 梦想详情
  732. * "id": 12,
  733. * "user_id": 2,
  734. * "name": "用户2梦想标题166",
  735. * "about": "用户2梦想介绍666",
  736. * "coin": 2500,
  737. * "time": 21,
  738. * "get_coin": 0,
  739. * "status": 0,
  740. * "video": null,
  741. * "sign": "",
  742. * },
  743. * "img": {
  744. * "title": "",
  745. * "pic": "https://f12f.jpg" 梦想封面图片
  746. * }
  747. * ],
  748. * "users": {
  749. * "2": "https://xxx.jpeg" ID号和头像
  750. * }
  751. * }
  752. *}
  753. * keyword存在
  754. *{
  755. * "status": true,
  756. * "status_code": 0,
  757. * "message": "",
  758. * "data": [
  759. * {
  760. * "id": 2,
  761. * "user_id": 1,
  762. * "dream_id": 12,
  763. * "dream_user_id": 2,
  764. * "interaction_number": 0,
  765. * "created_at": "2017-06-25 13:11:45",
  766. * "updated_at": "2017-06-25 13:11:45",
  767. * "dreams": [ 梦想
  768. * {
  769. * "id": 12,
  770. * "user_id": 2,
  771. * "name": "用户2梦想标题166",
  772. * "about": "用户2梦想介绍666",
  773. * "coin": 2500,
  774. * "end_time": 72000,
  775. * "get_coin": 792,
  776. * "mark": 5484,
  777. * "status": 0,
  778. * "video": "e",
  779. * "score": 158730,
  780. * "sign": "梦想达人",
  781. * "created_at": "2017-06-25 13:10:56",
  782. * "updated_at": "2017-06-28 16:53:39"
  783. * "img": { 图片
  784. * "title": "",
  785. * "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
  786. * },
  787. * "user": {
  788. *
  789. * }
  790. * }
  791. * ]
  792. * }
  793. * ]
  794. *}
  795. * @apiErrorExample {json} Error-Response:
  796. * HTTP/1.1 400 Bad Request
  797. */
  798. public function collection(Request $request)
  799. {
  800. $user = $this->getUser();
  801. if ($request->keyword) {
  802. $keyword ='%'.$request->keyword.'%';
  803. $data = UserCareDream::where('user_id',$user->id)->
  804. whereHas('dreams',function ($query) use($keyword){
  805. $query->where('end_time','>=',time())->where('name','like',$keyword);
  806. })->with('dreams')->get();
  807. foreach ($data as $item) {
  808. foreach ($item->dreams as $dream) {
  809. $dream->img;
  810. }
  811. }
  812. $this->insertSearchTable($user->id,$request->keyword);
  813. return $this->api($data);
  814. }else{
  815. $dreams = $user->collection;
  816. // $users = [];
  817. foreach ($dreams as $item) {
  818. /* if ($item->pivot->interaction_number > 0) {
  819. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  820. $avatar = $user_info ? $user_info->avatar : '';
  821. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  822. $users[$item->pivot->dream_user_id] = $avatar;
  823. }
  824. }*/
  825. $item->img;
  826. $item->user;
  827. }
  828. return $this->api(compact('dreams'));
  829. }
  830. }
  831. /**
  832. * @api {get} /api/my/miao 关于喵喵
  833. * @apiDescription 关于喵喵
  834. * @apiGroup My
  835. * @apiPermission Passport
  836. * @apiVersion 0.1.0
  837. * @apiSuccessExample {json} Success-Response:
  838. * HTTP/1.1 200 OK
  839. *{
  840. * "status": true,
  841. * "status_code": 0,
  842. * "message": "",
  843. * "data": {
  844. * "key": "2511789", 电话
  845. * "value": "关于喵喵介绍" 关于喵喵
  846. * }
  847. *}
  848. * @apiErrorExample {json} Error-Response:
  849. * HTTP/1.1 400 Bad Request
  850. */
  851. public function aboutMiao()
  852. {
  853. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  854. return $this->api($data);
  855. }
  856. /**
  857. * @api {get} /api/my/care 我关注的用户
  858. * @apiDescription 我关注的用户
  859. * @apiGroup My
  860. * @apiPermission Passport
  861. * @apiVersion 0.1.0
  862. * @apiSuccessExample {json} Success-Response:
  863. * HTTP/1.1 200 OK
  864. *{
  865. * "status": true,
  866. * "status_code": 0,
  867. * "message": "",
  868. * "data":[] or
  869. * "data": [
  870. * {
  871. * "id": 2,
  872. * "phone": "13880642881",
  873. * "nickname": "name2",
  874. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  875. * "birthday": "2000-06-21",
  876. * "sign": 0,
  877. * "money": 0,
  878. * "coin": 800,
  879. * "sex": 1,
  880. * "signture": "我的个性签名2",
  881. * "height": 200,
  882. * "work": "兼职",
  883. * "emotion": 2,
  884. * "address": "370105",
  885. * "city": "成都",
  886. * "detail_address": "",
  887. * "status": 1,
  888. * "wechat": "",
  889. * "weibo": "",
  890. * "remember_token": "",
  891. * "created_at": "2017-06-25 10:42:06",
  892. * "updated_at": "2017-06-30 09:15:04",
  893. * "deleted_at": null,
  894. * }
  895. * ]
  896. *}
  897. * @apiErrorExample {json} Error-Response:
  898. * HTTP/1.1 400 Bad Request
  899. */
  900. public function care()
  901. {
  902. $user = $this->getUser();
  903. $users =$user->UserCareUser;
  904. return $this->api($users);
  905. }
  906. /**
  907. * @api {get} /api/my/careme 关注我的用户
  908. * @apiDescription 关注我的用户
  909. * @apiGroup My
  910. * @apiPermission Passport
  911. * @apiVersion 0.1.0
  912. * @apiSuccessExample {json} Success-Response:
  913. * HTTP/1.1 200 OK
  914. *{
  915. * "status": true,
  916. * "status_code": 0,
  917. * "message": "",
  918. * "data":[] or
  919. * "data": [
  920. * {
  921. * "id": 2,
  922. * "phone": "13880642881",
  923. * "nickname": "name2",
  924. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  925. * "birthday": "2000-06-21",
  926. * "sign": 0,
  927. * "money": 0,
  928. * "coin": 800,
  929. * "sex": 1,
  930. * "signture": "我的个性签名2",
  931. * "height": 200,
  932. * "work": "兼职",
  933. * "emotion": 2,
  934. * "address": "370105",
  935. * "city": "成都",
  936. * "detail_address": "",
  937. * "status": 1,
  938. * "wechat": "",
  939. * "weibo": "",
  940. * "remember_token": "",
  941. * "created_at": "2017-06-25 10:42:06",
  942. * "updated_at": "2017-06-30 09:15:04",
  943. * "deleted_at": null,
  944. * }
  945. * ]
  946. *}
  947. * @apiErrorExample {json} Error-Response:
  948. * HTTP/1.1 400 Bad Request
  949. */
  950. public function careMe()
  951. {
  952. $user = $this->getUser();
  953. $users =$user->UserCareMe;
  954. return $this->api($users);
  955. }
  956. public function insertSearchTable($id,$keyword)
  957. {
  958. $info = SearchInfoModel::where('user_id',$id)->
  959. where('search',trim($keyword))->first();
  960. if (count($info) == 0) {
  961. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  962. }else{
  963. $info->times += 1;
  964. $info->save();
  965. }
  966. }
  967. //我的银行账户
  968. /**
  969. * @api {get} /api/my/bank/list 我的银行账户
  970. * @apiDescription 我的银行账户
  971. * @apiGroup My
  972. * @apiPermission Passport
  973. * @apiVersion 0.1.0
  974. * @apiSuccessExample {json} Success-Response:
  975. * HTTP/1.1 200 OK
  976. *{
  977. * "status": true,
  978. * "status_code": 0,
  979. * "message": "",
  980. * "data":[] or
  981. * "data": [
  982. * {
  983. * "id": 1,
  984. * "user_id": 1,
  985. * "bank_name": "1",
  986. * "bank_number": "1", /账号
  987. * "bank_phone": "1",
  988. * "bank_user": "" 用户名/
  989. * "type": 微信, 微信(支付宝)二维码
  990. * "url": wwww.ddf, 二维码地址
  991. * "is_img": 1,
  992. * }
  993. *]
  994. * @apiErrorExample {json} Error-Response:
  995. * HTTP/1.1 400 Bad Request
  996. */
  997. public function bankList()
  998. {
  999. $user = $this->getUser();
  1000. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  1001. return $this->api($data);
  1002. }
  1003. /**
  1004. * @api {get} /api/my/bank/account 账户余额
  1005. * @apiDescription 账户余额
  1006. * @apiGroup My
  1007. * @apiPermission Passport
  1008. * @apiVersion 0.1.0
  1009. * @apiSuccessExample {json} Success-Response:
  1010. * HTTP/1.1 200 OK
  1011. *{
  1012. * "status": true,
  1013. * "status_code": 0,
  1014. * "message": "",
  1015. * "data":[] or
  1016. * "data": {
  1017. * "coin": 508, 余额
  1018. * }
  1019. *]
  1020. * @apiErrorExample {json} Error-Response:
  1021. * HTTP/1.1 400 Bad Request
  1022. */
  1023. public function account()
  1024. {
  1025. $user = $this->getUser();
  1026. return $this->api($user);
  1027. }
  1028. // 添加银行卡
  1029. /**
  1030. * @api {post} /api/my/bank/create 添加银行卡
  1031. * @apiDescription 添加银行卡
  1032. * @apiGroup My
  1033. * @apiParam {string} data[bank_name] 银行名称
  1034. * @apiParam {string} data[bank_number] 银行卡号
  1035. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  1036. * @apiParam {string} data[bank_user] 银行卡用户姓名
  1037. * @apiPermission Passport
  1038. * @apiVersion 0.1.0
  1039. * @apiSuccessExample {json} Success-Response:
  1040. * HTTP/1.1 200 OK
  1041. *{
  1042. * "status": true,
  1043. * "status_code": 0,
  1044. * "message": "",
  1045. * "data": ""
  1046. *}
  1047. * @apiErrorExample {json} Error-Response:
  1048. *{
  1049. * "status": false,
  1050. * "status_code": 700,
  1051. * "message": "操作失败",
  1052. * "data": null
  1053. *}
  1054. */
  1055. public function bankCreate(Request $request)
  1056. {
  1057. $data = $request->data;
  1058. $user = $this->getUser();
  1059. $validator = \Validator::make($request->all(),
  1060. [
  1061. 'data.bank_name' => 'required',
  1062. 'data.bank_number' => 'required',
  1063. 'data.bank_phone' => 'required',
  1064. 'data.bank_user' => 'required',
  1065. ],
  1066. [
  1067. 'data.bank_name.required' => '请选择账号类型',
  1068. 'data.bank_number.required' => '请输入账号',
  1069. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  1070. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  1071. ]
  1072. );
  1073. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1074. $data['user_id'] = $user->id;
  1075. $ok =UserBank::create($data);
  1076. if ($ok) {
  1077. return $this->api('');
  1078. }else{
  1079. return $this->error(ErrorCode::OPERATION_FAILED);
  1080. }
  1081. } /**
  1082. * @api {post} /api/my/bank/qrcode 添加二维码
  1083. * @apiDescription 添加二维码
  1084. * @apiGroup My
  1085. * @apiParam {string} data[type] 类型
  1086. * @apiParam {string} data[qrcode] 二维码图片
  1087. * @apiPermission Passport
  1088. * @apiVersion 0.1.0
  1089. * @apiSuccessExample {json} Success-Response:
  1090. * HTTP/1.1 200 OK
  1091. *{
  1092. * "status": true,
  1093. * "status_code": 0,
  1094. * "message": "",
  1095. * "data": ""
  1096. *}
  1097. * @apiErrorExample {json} Error-Response:
  1098. *{
  1099. * "status": false,
  1100. * "status_code": 700,
  1101. * "message": "操作失败",
  1102. * "data": null
  1103. *}
  1104. */
  1105. public function bankImgCreate(Request $request)
  1106. {
  1107. $data = $request->data;
  1108. $user = $this->getUser();
  1109. $validator = \Validator::make($request->all(),
  1110. [
  1111. 'data.type' => 'required',
  1112. 'data.qrcode' => 'required',
  1113. ],
  1114. [
  1115. 'data.type.required' => '请选择账号类型',
  1116. 'data.qrcode.required' => '请上传二维码图片',
  1117. ]
  1118. );
  1119. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1120. $data['user_id'] = $user->id;
  1121. /* $data['bank_user'] = '';
  1122. $data['bank_phone'] = '';
  1123. $data['bank_number'] = '';
  1124. $data['bank_name'] = '';*/
  1125. $info = UserBank::whereNotNull('qrcode')->where('user_id',$user->id)
  1126. ->where('type',$data['type'])->first(); //定义为二维码
  1127. if (empty($info)) {
  1128. $ok =UserBank::create($data);
  1129. }else{
  1130. $ok = $info->update($data);
  1131. }
  1132. if ($ok) {
  1133. return $this->api('');
  1134. }else{
  1135. return $this->error(ErrorCode::OPERATION_FAILED);
  1136. }
  1137. }
  1138. /**
  1139. * @api {get} /api/my/bank/delete 删除银行卡
  1140. * @apiDescription 删除银行卡
  1141. * @apiGroup My
  1142. * @apiParam {int} id 银行卡id
  1143. * @apiPermission Passport
  1144. * @apiVersion 0.1.0
  1145. * @apiSuccessExample {json} Success-Response:
  1146. * HTTP/1.1 200 OK
  1147. *{
  1148. * "status": true,
  1149. * "status_code": 0,
  1150. * "message": "",
  1151. * "data": ""
  1152. *}
  1153. * @apiErrorExample {json} Error-Response:
  1154. *{
  1155. * "status": false,
  1156. * "status_code": 700,
  1157. * "message": "操作失败",
  1158. * "data": null
  1159. *}
  1160. */
  1161. public function bankDelete(Request $request)
  1162. {
  1163. $id = $request->id;
  1164. $validator = \Validator::make($request->all(),
  1165. [
  1166. 'id' => 'required',
  1167. ],
  1168. [
  1169. 'id.required' => '银行账号不存在',
  1170. ]
  1171. );
  1172. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1173. $ok =UserBank::destroy($id);
  1174. if ($ok) {
  1175. return $this->api('');
  1176. }else{
  1177. return $this->error(ErrorCode::OPERATION_FAILED);
  1178. }
  1179. }
  1180. // 发私信
  1181. /**
  1182. * @api {post} /api/my/letter/store 发送私信
  1183. * @apiDescription 发送私信
  1184. * @apiGroup My
  1185. * @apiParam {string} content 私信内容
  1186. * @apiParam {array} [image] 图片
  1187. * @apiParam {string} [video] 视频
  1188. * @apiParam {int} to_user_id 私信对象
  1189. * @apiPermission Passport
  1190. * @apiVersion 0.1.0
  1191. * @apiSuccessExample {json} Success-Response:
  1192. * HTTP/1.1 200 OK
  1193. *{
  1194. * "status": true,
  1195. * "status_code": 0,
  1196. * "message": "",
  1197. * "data": ""
  1198. *}
  1199. * @apiErrorExample {json} Error-Response:
  1200. *{
  1201. * "status": false,
  1202. * "status_code": 700,
  1203. * "message": "操作失败",
  1204. * "data": null
  1205. *}
  1206. */
  1207. public function letterStore(Request $request)
  1208. {
  1209. $validator = \Validator::make($request->all(),
  1210. [
  1211. 'content' => 'required',
  1212. 'to_user_id' => 'required',
  1213. ],
  1214. [
  1215. 'content.required' => '私信内容不存在',
  1216. 'to_user_id.required' => '私信对象不存在',
  1217. ]
  1218. );
  1219. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1220. $user = $this->getUser();
  1221. $user_id = $user->id;
  1222. $info = $request->input('content');
  1223. $video = $request->input('video');
  1224. $img = $request->input('image');
  1225. if (is_array($img)&&!empty($img)) {
  1226. $image = $img[0];
  1227. }else{
  1228. $image = '';
  1229. }
  1230. $to_user_id = $request->input('to_user_id');
  1231. // 链接到最近的一个梦想
  1232. $dream = DreamInfoModel::where('user_id',$user_id)->orderBy('id','desc')->first();
  1233. $dream_id = empty($dream) ? 0 : $dream->id;
  1234. $arr = [
  1235. 'user_id'=>$user_id,
  1236. 'info'=>$info,
  1237. 'message'=>$user->nickname.'给你发了个私信哦~点击看看!',
  1238. 'to_user_id'=>$to_user_id,
  1239. 'dream_id'=>$dream_id,
  1240. 'video'=>$video,
  1241. 'image'=>$image,
  1242. 'type_id'=>2,
  1243. 'is_url'=>1,
  1244. 'attr_id'=>7,
  1245. ];
  1246. $ok =SystemInfoModel::create($arr);
  1247. if ($ok) {
  1248. $this->jPush($user->nickname.'给你发了个私信哦~点击看看!','',$to_user_id);
  1249. return $this->api('');
  1250. }else{
  1251. return $this->error(ErrorCode::OPERATION_FAILED);
  1252. }
  1253. }
  1254. /**
  1255. * @api {get} /api/my/letter/show 查看私信
  1256. * @apiDescription 查看私信
  1257. * @apiGroup My
  1258. * @apiParam {int} id 私信主键id
  1259. * @apiPermission Passport
  1260. * @apiVersion 0.1.0
  1261. * @apiSuccessExample {json} Success-Response:
  1262. * HTTP/1.1 200 OK
  1263. *{
  1264. * "status": true,
  1265. * "status_code": 0,
  1266. * "message": "",
  1267. * "data": ""
  1268. *}
  1269. * @apiErrorExample {json} Error-Response:
  1270. *{
  1271. * "status": false,
  1272. * "status_code": 700,
  1273. * "message": "操作失败",
  1274. * "data": null
  1275. *}
  1276. */
  1277. public function letterShow(Request $request)
  1278. {
  1279. $validator = \Validator::make($request->all(),
  1280. [
  1281. 'id' => 'required',
  1282. ],
  1283. [
  1284. 'id.required' => '私信id不存在',
  1285. ]
  1286. );
  1287. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1288. $user = $this->getUser();
  1289. $user_id = $user->id;
  1290. $id = $request->input('id');
  1291. $data = SystemInfoModel::find($id);
  1292. return $this->api($data);
  1293. }
  1294. // 梦想结束时梦想者是否同意见面
  1295. /**
  1296. * @api {get} /api/my/sure_meet 梦想者是否同意见面
  1297. * @apiDescription 梦想结束时梦想者是否同意见面
  1298. * @apiGroup My
  1299. * @apiParam {int} dream_id 梦想id
  1300. * @apiParam {int} value 0取消1确定
  1301. * @apiPermission Passport
  1302. * @apiVersion 0.1.0
  1303. * @apiSuccessExample {json} Success-Response:
  1304. * HTTP/1.1 200 OK
  1305. *{
  1306. * "status": true,
  1307. * "status_code": 0,
  1308. * "message": "",
  1309. * "data": ""
  1310. *}
  1311. * @apiErrorExample {json} Error-Response:
  1312. *{
  1313. * "status": false,
  1314. * "status_code": 700,
  1315. * "message": "操作失败",
  1316. * "data": null
  1317. *}
  1318. */
  1319. public function isOk(Request $request)
  1320. {
  1321. $validator = \Validator::make($request->all(),
  1322. [
  1323. 'value' => 'required',
  1324. 'dream_id' => 'required',
  1325. ],
  1326. [
  1327. 'value.required' => '参数错误',
  1328. 'dream_id.required' => '梦想不存在',
  1329. ]
  1330. );
  1331. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1332. $dream_id = $request->input('dream_id');
  1333. $value = $request->input('value');
  1334. $dream = DreamInfoModel::find($dream_id);
  1335. if (empty($dream)) return $this->error(ErrorCode::DREAM_NOT_EXIST);
  1336. $support_dream = SupportDreamModel::where('dream_id',$dream_id)->get();
  1337. $top = [] ;
  1338. foreach ($support_dream as $item) {
  1339. if (!array_key_exists($item->user_id,$top)) {
  1340. $top[$item->user_id] = $item->score;
  1341. }else{
  1342. $top[$item->user_id] += $item->score;
  1343. }
  1344. }
  1345. arsort($top);
  1346. $new_arr = array_values($top);
  1347. if (!empty($top)) {
  1348. $top_user = array_search($new_arr[0],$top);
  1349. }else{
  1350. $top_user = 0;
  1351. }
  1352. if ($value==1) {
  1353. // 同意见面
  1354. $dream->is_ok = 1;
  1355. $dream->save();
  1356. $message = "你支持的梦想者已经同意见面啦";
  1357. }else{
  1358. $message = "你支持的梦想者拒绝了本次见面,你支持的梦想资金将会退还给您";
  1359. // 退款逻辑
  1360. }
  1361. if (empty($top)) {
  1362. // 给最大支持者发送消息
  1363. $arr = [
  1364. 'user_id'=>0,
  1365. 'message'=>$message,
  1366. 'to_user_id'=>$top_user,
  1367. 'dream_id'=>$dream_id,
  1368. 'is_end'=>1,
  1369. 'type_id'=>1,
  1370. 'is_max'=>1,
  1371. ];
  1372. SystemInfoModel::firstOrCreate($arr);
  1373. }
  1374. return $this->api('');
  1375. }
  1376. // 梦想结束时梦主是否同意见面
  1377. /**
  1378. * @api {get} /api/my/sure_meet2 梦主是否同意见面
  1379. * @apiDescription 梦想结束时梦主是否同意见面
  1380. * @apiGroup My
  1381. * @apiParam {int} to_user_id 梦想者id(数据中的user_id)
  1382. * @apiParam {int} value 0取消1确定
  1383. * @apiPermission Passport
  1384. * @apiVersion 0.1.0
  1385. * @apiSuccessExample {json} Success-Response:
  1386. * HTTP/1.1 200 OK
  1387. *{
  1388. * "status": true,
  1389. * "status_code": 0,
  1390. * "message": "",
  1391. * "data": ""
  1392. *}
  1393. * @apiErrorExample {json} Error-Response:
  1394. *{
  1395. * "status": false,
  1396. * "status_code": 700,
  1397. * "message": "操作失败",
  1398. * "data": null
  1399. *}
  1400. */
  1401. public function isOk2(Request $request)
  1402. {
  1403. $user = $this->getUser();
  1404. $validator = \Validator::make($request->all(),
  1405. [
  1406. 'value' => 'required',
  1407. 'to_user_id' => 'required',
  1408. ],
  1409. [
  1410. 'value.required' => '参数错误',
  1411. 'to_user_id.required' => '梦想者不存在',
  1412. ]
  1413. );
  1414. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1415. $value = $request->input('value');
  1416. $to_user_id = $request->input('to_user_id');
  1417. $to_user_info = UserInfoModel::find($to_user_id);
  1418. if ($value==1) {
  1419. $message = '您的梦主同意见面了,赶快准备一下吧';
  1420. // 同意见面会收到一条提示信息
  1421. if (!empty($to_user_info)) {
  1422. $arr = [
  1423. 'user_id'=>0,
  1424. 'message'=>$to_user_info->nickname.'会第一时间联系你!见面时需要你扫一扫他提供的二维码哦',
  1425. 'to_user_id'=>$user->id,
  1426. 'is_end'=>1,
  1427. 'type_id'=>1,
  1428. ];
  1429. SystemInfoModel::firstOrCreate($arr);
  1430. }
  1431. }else{
  1432. $message = '您的梦主拒绝了你们的见面,喵~';
  1433. }
  1434. $arr = [
  1435. 'user_id'=>0,
  1436. 'message'=>$message,
  1437. 'to_user_id'=>$to_user_id,
  1438. 'is_end'=>1,
  1439. 'type_id'=>1,
  1440. ];
  1441. SystemInfoModel::firstOrCreate($arr);
  1442. }
  1443. }