MyController.php 51 KB

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