MyController.php 48 KB

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