MyController.php 51 KB

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