MyController.php 49 KB

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