MyController.php 48 KB

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