MyController.php 48 KB

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