MyController.php 47 KB

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