MyController.php 48 KB

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