MyController.php 48 KB

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