MyController.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  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. $message = '你提现的申请已经提交,我们会第一时间审核哦';
  573. $info = [
  574. 'user_id' => $user->id,
  575. 'message' => $message,
  576. 'attr_id' => 4,
  577. 'type_id' => 1,
  578. ];
  579. SystemInfoModel::create($info);
  580. // 长连接
  581. $this->jPush($message,'',$user->id);
  582. if ($ok) {
  583. return $this->api(ErrorCode::verify);
  584. }else{
  585. return $this->error(ErrorCode::OPERATION_FAILED);
  586. }
  587. }
  588. // 联系客服
  589. /**
  590. * @api {post} /api/my/suggest 联系客服
  591. * @apiDescription 联系客服
  592. * @apiGroup My
  593. * @apiParam {string} data[content] 内容
  594. * @apiParam {string} data[email] 邮箱
  595. * @apiPermission Passport
  596. * @apiVersion 0.1.0
  597. * @apiSuccessExample {json} Success-Response:
  598. * HTTP/1.1 200 OK
  599. *{
  600. * "status": true,
  601. * "status_code": 0,
  602. * "message": "",
  603. * "data": ""
  604. *}
  605. * @apiErrorExample {json} Error-Response:
  606. *{
  607. * "status": false,
  608. * "status_code": 700,
  609. * "message": "操作失败",
  610. * "data": null
  611. *}
  612. */
  613. public function suggest(Request $request)
  614. {
  615. $data = $request->data;
  616. $user = $this->getUser();
  617. $validator = \Validator::make($request->all(),
  618. [
  619. 'data.content' => 'required',
  620. 'data.email' => 'required|email',
  621. ],
  622. [
  623. 'data.content.required' => '请输入你遇到的问题',
  624. 'data.email.required' => '请输入正确的邮箱地址',
  625. 'data.email.email' => '请输入正确的邮箱地址',
  626. ]
  627. );
  628. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  629. $data['user_id'] = $user->id;
  630. $ok =Suggest::create($data);
  631. if ($ok) {
  632. return $this->api('');
  633. }else{
  634. return $this->error(ErrorCode::OPERATION_FAILED);
  635. }
  636. }
  637. // 回复我的
  638. // public function replyMy()
  639. // {
  640. //
  641. // $user = $this->getUser();
  642. //// 梦想
  643. // $dreams = $user->UserDream;
  644. //
  645. // $data = $user->allInteraction;
  646. // foreach ($data as $item) {
  647. // $item->get_money = $item->dream->get_money;
  648. // $item->money = $item->dream->money;
  649. // }
  650. // dd($data) ;
  651. // if (count($dreams) == 0)
  652. // return $this->error(ErrorCode::DREAM_NOT_EXIST);
  653. // $comments_infos = [];
  654. // foreach ($dreams as $dream){
  655. // $comments_info = $dream->DreamInfo;
  656. // if (count($comments_info) > 0) {
  657. // foreach ($comments_info as $k => $value) {
  658. // $value->dream_name = $dream->dream;
  659. // $value->dream_about = $dream->about;
  660. // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
  661. // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
  662. // $value->reviewer = $value->CommentUser->nickname;
  663. // $value->reviewer_pic = $value->CommentUser->pic;
  664. // }
  665. // $comments_infos[] = $comments_info;
  666. // }
  667. // }
  668. //
  669. // return $this->api(compact('comments_infos'));
  670. // }
  671. /**
  672. * @api {get} /api/my/dream 我的梦想
  673. * @apiDescription 我的梦想
  674. * @apiGroup My
  675. * @apiPermission Passport
  676. * @apiVersion 0.1.0
  677. * @apiSuccessExample {json} Success-Response:
  678. * HTTP/1.1 200 OK
  679. {
  680. "status": true,
  681. "status_code": 0,
  682. "message": "",
  683. "data": {
  684. "current_page": 1,
  685. "data": [
  686. {
  687. "id": 32,
  688. "user_id": 1,
  689. "name": "name",
  690. "about": "13880642880",
  691. "coin": 100,
  692. "end_time": "0000-00-00 00:00:00",
  693. "get_coin": 2017,
  694. "mark": 100,
  695. "status": 127,
  696. "video": "0",
  697. "score": 0,
  698. "type_name": 已完成,
  699. "sign": "158730",
  700. "code": "http://www.miao.com/qrcodes/WECHATPAY_201708191324294255.png",
  701. "parameter": 0,
  702. "created_at": "2017-08-19 05:22:12",
  703. "updated_at": "2017-08-19 05:24:30",
  704. "img": {
  705. "title": "",
  706. "pic": "http://q8.9026.com/upload/dream/20170629/79c11614cc8a9d37f747e3974d055331.jpg"
  707. }
  708. },
  709. ],
  710. "from": 1,
  711. "last_page": 4,
  712. "next_page_url": "http://www.miao.com/api/my/dream?page=2",
  713. "path": "http://www.miao.com/api/my/dream",
  714. "per_page": 10,
  715. "prev_page_url": null,
  716. "to": 10,
  717. "total": 36
  718. }
  719. }
  720. * @apiErrorExample {json} Error-Response:
  721. * HTTP/1.1 400 Bad Request
  722. */
  723. public function dream()
  724. {
  725. $user = $this->getUser();
  726. $dreams = DreamInfoModel::where('user_id',$user->id)->orderBy('created_at','desc')->with('img')->paginate();
  727. foreach ($dreams as $dream) {
  728. if (strtotime($dream->end_time) > time()) {
  729. $dream->type_name = '进行中';
  730. }else{
  731. if ($dream->get_coin >=$dream->coin) {
  732. $dream->type_name = '已完成';
  733. }else{
  734. $dream->type_name = '未完成';
  735. }
  736. }
  737. }
  738. return $this->api($dreams);
  739. }
  740. /**
  741. * @api {get} /api/my/collection 我的收藏
  742. * @apiDescription 我的收藏
  743. * @apiGroup My
  744. * @apiPermission Passport
  745. * @apiParam {string} [keyword] 关键字可选
  746. * @apiVersion 0.1.0
  747. * @apiSuccessExample {json} Success-Response:
  748. * HTTP/1.1 200 OK
  749. *{
  750. * "status": true,
  751. * "status_code": 0,
  752. * "message": "",
  753. * "data": {
  754. * "data": [
  755. * { 梦想详情
  756. * "id": 12,
  757. * "user_id": 2,
  758. * "name": "用户2梦想标题166",
  759. * "about": "用户2梦想介绍666",
  760. * "coin": 2500,
  761. * "time": 21,
  762. * "get_coin": 0,
  763. * "status": 0,
  764. * "video": null,
  765. * "sign": "",
  766. * },
  767. * "img": {
  768. * "title": "",
  769. * "pic": "https://f12f.jpg" 梦想封面图片
  770. * }
  771. * ],
  772. * "users": {
  773. * "2": "https://xxx.jpeg" ID号和头像
  774. * }
  775. * }
  776. *}
  777. * keyword存在
  778. *{
  779. * "status": true,
  780. * "status_code": 0,
  781. * "message": "",
  782. * "data": [
  783. * {
  784. * "id": 2,
  785. * "user_id": 1,
  786. * "dream_id": 12,
  787. * "dream_user_id": 2,
  788. * "interaction_number": 0,
  789. * "created_at": "2017-06-25 13:11:45",
  790. * "updated_at": "2017-06-25 13:11:45",
  791. * "dreams": [ 梦想
  792. * {
  793. * "id": 12,
  794. * "user_id": 2,
  795. * "name": "用户2梦想标题166",
  796. * "about": "用户2梦想介绍666",
  797. * "coin": 2500,
  798. * "end_time": 72000,
  799. * "get_coin": 792,
  800. * "mark": 5484,
  801. * "status": 0,
  802. * "video": "e",
  803. * "score": 158730,
  804. * "sign": "梦想达人",
  805. * "created_at": "2017-06-25 13:10:56",
  806. * "updated_at": "2017-06-28 16:53:39"
  807. * "img": { 图片
  808. * "title": "",
  809. * "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
  810. * },
  811. * "user": {
  812. *
  813. * }
  814. * }
  815. * ]
  816. * }
  817. * ]
  818. *}
  819. * @apiErrorExample {json} Error-Response:
  820. * HTTP/1.1 400 Bad Request
  821. */
  822. public function collection(Request $request)
  823. {
  824. $user = $this->getUser();
  825. if ($request->keyword) {
  826. $keyword ='%'.$request->keyword.'%';
  827. $data = UserCareDream::where('user_id',$user->id)->
  828. whereHas('dreams',function ($query) use($keyword){
  829. $query->where('end_time','>=',time())->where('name','like',$keyword);
  830. })->with('dreams')->get();
  831. foreach ($data as $item) {
  832. foreach ($item->dreams as $dream) {
  833. $dream->img;
  834. }
  835. }
  836. $this->insertSearchTable($user->id,$request->keyword);
  837. return $this->api($data);
  838. }else{
  839. $dreams = $user->collection;
  840. // $users = [];
  841. foreach ($dreams as $item) {
  842. /* if ($item->pivot->interaction_number > 0) {
  843. $user_info = UserInfoModel::find($item->pivot->dream_user_id);
  844. $avatar = $user_info ? $user_info->avatar : '';
  845. if (!array_key_exists($item->pivot->dream_user_id,$users)) {
  846. $users[$item->pivot->dream_user_id] = $avatar;
  847. }
  848. }*/
  849. $item->img;
  850. $item->user;
  851. if (strtotime($item->end_time) > time()) {
  852. $item->type_name = '进行中';
  853. }else{
  854. if ($item->get_coin >=$item->coin) {
  855. $item->type_name = '已完成';
  856. }else{
  857. $item->type_name = '未完成';
  858. }
  859. }
  860. }
  861. return $this->api(compact('dreams'));
  862. }
  863. }
  864. /**
  865. * @api {get} /api/my/miao 关于喵喵
  866. * @apiDescription 关于喵喵
  867. * @apiGroup My
  868. * @apiPermission Passport
  869. * @apiVersion 0.1.0
  870. * @apiSuccessExample {json} Success-Response:
  871. * HTTP/1.1 200 OK
  872. *{
  873. * "status": true,
  874. * "status_code": 0,
  875. * "message": "",
  876. * "data": {
  877. * "key": "2511789", 电话
  878. * "value": "关于喵喵介绍" 关于喵喵
  879. * }
  880. *}
  881. * @apiErrorExample {json} Error-Response:
  882. * HTTP/1.1 400 Bad Request
  883. */
  884. public function aboutMiao()
  885. {
  886. $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
  887. return $this->api($data);
  888. }
  889. /**
  890. * @api {get} /api/my/care 我关注的用户
  891. * @apiDescription 我关注的用户
  892. * @apiGroup My
  893. * @apiPermission Passport
  894. * @apiVersion 0.1.0
  895. * @apiSuccessExample {json} Success-Response:
  896. * HTTP/1.1 200 OK
  897. *{
  898. * "status": true,
  899. * "status_code": 0,
  900. * "message": "",
  901. * "data":[] or
  902. * "data": [
  903. * {
  904. * "id": 2,
  905. * "phone": "13880642881",
  906. * "nickname": "name2",
  907. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  908. * "birthday": "2000-06-21",
  909. * "sign": 0,
  910. * "money": 0,
  911. * "coin": 800,
  912. * "sex": 1,
  913. * "signture": "我的个性签名2",
  914. * "height": 200,
  915. * "work": "兼职",
  916. * "emotion": 2,
  917. * "address": "370105",
  918. * "city": "成都",
  919. * "detail_address": "",
  920. * "status": 1,
  921. * "wechat": "",
  922. * "weibo": "",
  923. * "remember_token": "",
  924. * "created_at": "2017-06-25 10:42:06",
  925. * "updated_at": "2017-06-30 09:15:04",
  926. * "deleted_at": null,
  927. * }
  928. * ]
  929. *}
  930. * @apiErrorExample {json} Error-Response:
  931. * HTTP/1.1 400 Bad Request
  932. */
  933. public function care()
  934. {
  935. $user = $this->getUser();
  936. $users =$user->UserCareUser;
  937. return $this->api($users);
  938. }
  939. /**
  940. * @api {get} /api/my/careme 关注我的用户
  941. * @apiDescription 关注我的用户
  942. * @apiGroup My
  943. * @apiPermission Passport
  944. * @apiVersion 0.1.0
  945. * @apiSuccessExample {json} Success-Response:
  946. * HTTP/1.1 200 OK
  947. *{
  948. * "status": true,
  949. * "status_code": 0,
  950. * "message": "",
  951. * "data":[] or
  952. * "data": [
  953. * {
  954. * "id": 2,
  955. * "phone": "13880642881",
  956. * "nickname": "name2",
  957. * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
  958. * "birthday": "2000-06-21",
  959. * "sign": 0,
  960. * "money": 0,
  961. * "coin": 800,
  962. * "sex": 1,
  963. * "signture": "我的个性签名2",
  964. * "height": 200,
  965. * "work": "兼职",
  966. * "emotion": 2,
  967. * "address": "370105",
  968. * "city": "成都",
  969. * "detail_address": "",
  970. * "status": 1,
  971. * "wechat": "",
  972. * "weibo": "",
  973. * "remember_token": "",
  974. * "created_at": "2017-06-25 10:42:06",
  975. * "updated_at": "2017-06-30 09:15:04",
  976. * "deleted_at": null,
  977. * }
  978. * ]
  979. *}
  980. * @apiErrorExample {json} Error-Response:
  981. * HTTP/1.1 400 Bad Request
  982. */
  983. public function careMe()
  984. {
  985. $user = $this->getUser();
  986. $users =$user->UserCareMe;
  987. return $this->api($users);
  988. }
  989. public function insertSearchTable($id,$keyword)
  990. {
  991. $info = SearchInfoModel::where('user_id',$id)->
  992. where('search',trim($keyword))->first();
  993. if (count($info) == 0) {
  994. SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
  995. }else{
  996. $info->times += 1;
  997. $info->save();
  998. }
  999. }
  1000. //我的银行账户
  1001. /**
  1002. * @api {get} /api/my/bank/list 我的银行账户
  1003. * @apiDescription 我的银行账户
  1004. * @apiGroup My
  1005. * @apiPermission Passport
  1006. * @apiVersion 0.1.0
  1007. * @apiSuccessExample {json} Success-Response:
  1008. * HTTP/1.1 200 OK
  1009. *{
  1010. * "status": true,
  1011. * "status_code": 0,
  1012. * "message": "",
  1013. * "data":[] or
  1014. * "data": [
  1015. * {
  1016. * "id": 1,
  1017. * "user_id": 1,
  1018. * "bank_name": "1",
  1019. * "bank_number": "1", /账号
  1020. * "bank_phone": "1",
  1021. * "bank_user": "" 用户名/
  1022. * "type": 微信, 微信(支付宝)二维码
  1023. * "url": wwww.ddf, 二维码地址
  1024. * "is_img": 1,
  1025. * }
  1026. *]
  1027. * @apiErrorExample {json} Error-Response:
  1028. * HTTP/1.1 400 Bad Request
  1029. */
  1030. public function bankList()
  1031. {
  1032. $user = $this->getUser();
  1033. $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
  1034. return $this->api($data);
  1035. }
  1036. /**
  1037. * @api {get} /api/my/bank/account 账户余额
  1038. * @apiDescription 账户余额
  1039. * @apiGroup My
  1040. * @apiPermission Passport
  1041. * @apiVersion 0.1.0
  1042. * @apiSuccessExample {json} Success-Response:
  1043. * HTTP/1.1 200 OK
  1044. *{
  1045. * "status": true,
  1046. * "status_code": 0,
  1047. * "message": "",
  1048. * "data":[] or
  1049. * "data": {
  1050. * "coin": 508, 余额
  1051. * }
  1052. *]
  1053. * @apiErrorExample {json} Error-Response:
  1054. * HTTP/1.1 400 Bad Request
  1055. */
  1056. public function account()
  1057. {
  1058. $user = $this->getUser();
  1059. return $this->api($user);
  1060. }
  1061. // 添加银行卡
  1062. /**
  1063. * @api {post} /api/my/bank/create 添加银行卡
  1064. * @apiDescription 添加银行卡
  1065. * @apiGroup My
  1066. * @apiParam {string} data[bank_name] 银行名称
  1067. * @apiParam {string} data[bank_number] 银行卡号
  1068. * @apiParam {int} data[bank_phone] 银行卡绑定手机号
  1069. * @apiParam {string} data[bank_user] 银行卡用户姓名
  1070. * @apiPermission Passport
  1071. * @apiVersion 0.1.0
  1072. * @apiSuccessExample {json} Success-Response:
  1073. * HTTP/1.1 200 OK
  1074. *{
  1075. * "status": true,
  1076. * "status_code": 0,
  1077. * "message": "",
  1078. * "data": ""
  1079. *}
  1080. * @apiErrorExample {json} Error-Response:
  1081. *{
  1082. * "status": false,
  1083. * "status_code": 700,
  1084. * "message": "操作失败",
  1085. * "data": null
  1086. *}
  1087. */
  1088. public function bankCreate(Request $request)
  1089. {
  1090. $data = $request->data;
  1091. $user = $this->getUser();
  1092. if (empty($user)) return $this->error(ErrorCode::MERCHANT_NOT_EXIST);
  1093. $validator = \Validator::make($request->all(),
  1094. [
  1095. 'data.bank_name' => 'required',
  1096. 'data.bank_number' => 'required',
  1097. 'data.bank_phone' => 'required',
  1098. 'data.bank_user' => 'required',
  1099. ],
  1100. [
  1101. 'data.bank_name.required' => '请选择账号类型',
  1102. 'data.bank_number.required' => '请输入账号',
  1103. 'data.bank_phone.required' => '请输入账号绑定手机号码',
  1104. 'data.bank_user.required' => '请输入账号绑定用户姓名',
  1105. ]
  1106. );
  1107. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1108. $data['user_id'] = $user->id;
  1109. $ok =UserBank::create($data);
  1110. if ($ok) {
  1111. return $this->api('');
  1112. }else{
  1113. return $this->error(ErrorCode::OPERATION_FAILED);
  1114. }
  1115. } /**
  1116. * @api {post} /api/my/bank/qrcode 添加二维码
  1117. * @apiDescription 添加二维码
  1118. * @apiGroup My
  1119. * @apiParam {string} data[type] 类型
  1120. * @apiParam {string} data[qrcode] 二维码图片
  1121. * @apiPermission Passport
  1122. * @apiVersion 0.1.0
  1123. * @apiSuccessExample {json} Success-Response:
  1124. * HTTP/1.1 200 OK
  1125. *{
  1126. * "status": true,
  1127. * "status_code": 0,
  1128. * "message": "",
  1129. * "data": ""
  1130. *}
  1131. * @apiErrorExample {json} Error-Response:
  1132. *{
  1133. * "status": false,
  1134. * "status_code": 700,
  1135. * "message": "操作失败",
  1136. * "data": null
  1137. *}
  1138. */
  1139. public function bankImgCreate(Request $request)
  1140. {
  1141. $data = $request->data;
  1142. $user = $this->getUser();
  1143. if (empty($user)) return $this->error(ErrorCode::MERCHANT_NOT_EXIST);
  1144. $validator = \Validator::make($request->all(),
  1145. [
  1146. 'data.type' => 'required',
  1147. 'data.qrcode' => 'required',
  1148. ],
  1149. [
  1150. 'data.type.required' => '请选择账号类型',
  1151. 'data.qrcode.required' => '请上传二维码图片',
  1152. ]
  1153. );
  1154. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1155. $data['user_id'] = $user->id;
  1156. /* $data['bank_user'] = '';
  1157. $data['bank_phone'] = '';
  1158. $data['bank_number'] = '';
  1159. $data['bank_name'] = '';*/
  1160. $info = UserBank::whereNotNull('qrcode')->where('user_id',$user->id)
  1161. ->where('type',$data['type'])->first(); //定义为二维码
  1162. if (empty($info)) {
  1163. $ok =UserBank::create($data);
  1164. }else{
  1165. $ok = $info->update($data);
  1166. }
  1167. if ($ok) {
  1168. return $this->api('');
  1169. }else{
  1170. return $this->error(ErrorCode::OPERATION_FAILED);
  1171. }
  1172. }
  1173. /**
  1174. * @api {get} /api/my/bank/delete 删除银行卡
  1175. * @apiDescription 删除银行卡
  1176. * @apiGroup My
  1177. * @apiParam {int} id 银行卡id
  1178. * @apiPermission Passport
  1179. * @apiVersion 0.1.0
  1180. * @apiSuccessExample {json} Success-Response:
  1181. * HTTP/1.1 200 OK
  1182. *{
  1183. * "status": true,
  1184. * "status_code": 0,
  1185. * "message": "",
  1186. * "data": ""
  1187. *}
  1188. * @apiErrorExample {json} Error-Response:
  1189. *{
  1190. * "status": false,
  1191. * "status_code": 700,
  1192. * "message": "操作失败",
  1193. * "data": null
  1194. *}
  1195. */
  1196. public function bankDelete(Request $request)
  1197. {
  1198. $id = $request->id;
  1199. $validator = \Validator::make($request->all(),
  1200. [
  1201. 'id' => 'required',
  1202. ],
  1203. [
  1204. 'id.required' => '银行账号不存在',
  1205. ]
  1206. );
  1207. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1208. $ok =UserBank::destroy($id);
  1209. if ($ok) {
  1210. return $this->api('');
  1211. }else{
  1212. return $this->error(ErrorCode::OPERATION_FAILED);
  1213. }
  1214. }
  1215. // 发私信
  1216. /**
  1217. * @api {post} /api/my/letter/store 发送私信
  1218. * @apiDescription 发送私信
  1219. * @apiGroup My
  1220. * @apiParam {string} content 私信内容
  1221. * @apiParam {array} [image] 图片
  1222. * @apiParam {string} [video] 视频
  1223. * @apiParam {int} to_user_id 私信对象
  1224. * @apiPermission Passport
  1225. * @apiVersion 0.1.0
  1226. * @apiSuccessExample {json} Success-Response:
  1227. * HTTP/1.1 200 OK
  1228. *{
  1229. * "status": true,
  1230. * "status_code": 0,
  1231. * "message": "",
  1232. * "data": ""
  1233. *}
  1234. * @apiErrorExample {json} Error-Response:
  1235. *{
  1236. * "status": false,
  1237. * "status_code": 700,
  1238. * "message": "操作失败",
  1239. * "data": null
  1240. *}
  1241. */
  1242. public function letterStore(Request $request)
  1243. {
  1244. $validator = \Validator::make($request->all(),
  1245. [
  1246. 'content' => 'required',
  1247. 'to_user_id' => 'required',
  1248. ],
  1249. [
  1250. 'content.required' => '私信内容不存在',
  1251. 'to_user_id.required' => '私信对象不存在',
  1252. ]
  1253. );
  1254. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1255. $user = $this->getUser();
  1256. if (empty($user)) return $this->error(ErrorCode::MERCHANT_NOT_EXIST);
  1257. $user_id = $user->id;
  1258. $info = $request->input('content');
  1259. $video = $request->input('video');
  1260. $img = $request->input('image');
  1261. if (is_array($img)&&!empty($img)) {
  1262. $image = $img[0];
  1263. }else{
  1264. $image = '';
  1265. }
  1266. $to_user_id = $request->input('to_user_id');
  1267. // 链接到最近的一个梦想
  1268. $dream = DreamInfoModel::where('user_id',$user_id)->orderBy('id','desc')->first();
  1269. $dream_id = empty($dream) ? 0 : $dream->id;
  1270. $arr = [
  1271. 'user_id'=>$user_id,
  1272. 'info'=>$info,
  1273. 'message'=>$user->nickname.'给你发了个私信哦~点击看看!',
  1274. 'to_user_id'=>$to_user_id,
  1275. 'dream_id'=>$dream_id,
  1276. 'video'=>$video,
  1277. 'image'=>$image,
  1278. 'type_id'=>2,
  1279. 'is_url'=>1,
  1280. 'attr_id'=>7,
  1281. ];
  1282. $ok =SystemInfoModel::create($arr);
  1283. if ($ok) {
  1284. if (!empty($to_user_id)) {
  1285. $this->jPush($user->nickname.'给你发了个私信哦~点击看看!','',$to_user_id);
  1286. }
  1287. return $this->api('');
  1288. }else{
  1289. return $this->error(ErrorCode::OPERATION_FAILED);
  1290. }
  1291. }
  1292. /**
  1293. * @api {get} /api/my/letter/show 查看私信
  1294. * @apiDescription 查看私信
  1295. * @apiGroup My
  1296. * @apiParam {int} id 私信主键id
  1297. * @apiPermission Passport
  1298. * @apiVersion 0.1.0
  1299. * @apiSuccessExample {json} Success-Response:
  1300. * HTTP/1.1 200 OK
  1301. *{
  1302. * "status": true,
  1303. * "status_code": 0,
  1304. * "message": "",
  1305. * "data": ""
  1306. *}
  1307. * @apiErrorExample {json} Error-Response:
  1308. *{
  1309. * "status": false,
  1310. * "status_code": 700,
  1311. * "message": "操作失败",
  1312. * "data": null
  1313. *}
  1314. */
  1315. public function letterShow(Request $request)
  1316. {
  1317. $validator = \Validator::make($request->all(),
  1318. [
  1319. 'id' => 'required',
  1320. ],
  1321. [
  1322. 'id.required' => '私信id不存在',
  1323. ]
  1324. );
  1325. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1326. $user = $this->getUser();
  1327. $user_id = $user->id;
  1328. $id = $request->input('id');
  1329. $data = SystemInfoModel::find($id);
  1330. return $this->api($data);
  1331. }
  1332. // 梦想结束时梦想者是否同意见面
  1333. /**
  1334. * @api {get} /api/my/sure_meet 梦想者是否同意见面
  1335. * @apiDescription 梦想结束时梦想者是否同意见面
  1336. * @apiGroup My
  1337. * @apiParam {int} dream_id 梦想id
  1338. * @apiParam {int} value 0取消1确定
  1339. * @apiPermission Passport
  1340. * @apiVersion 0.1.0
  1341. * @apiSuccessExample {json} Success-Response:
  1342. * HTTP/1.1 200 OK
  1343. *{
  1344. * "status": true,
  1345. * "status_code": 0,
  1346. * "message": "",
  1347. * "data": 0 0表示并没有人支持你
  1348. *}
  1349. * @apiErrorExample {json} Error-Response:
  1350. *{
  1351. * "status": false,
  1352. * "status_code": 700,
  1353. * "message": "操作失败",
  1354. * "data": null
  1355. *}
  1356. */
  1357. public function isOk(Request $request)
  1358. {
  1359. $validator = \Validator::make($request->all(),
  1360. [
  1361. 'value' => 'required',
  1362. 'dream_id' => 'required',
  1363. ],
  1364. [
  1365. 'value.required' => '参数错误',
  1366. 'dream_id.required' => '梦想不存在',
  1367. ]
  1368. );
  1369. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1370. $dream_id = $request->input('dream_id');
  1371. $value = $request->input('value');
  1372. $dream = DreamInfoModel::find($dream_id);
  1373. if (empty($dream)) return $this->error(ErrorCode::DREAM_NOT_EXIST);
  1374. $support_dream = SupportDreamModel::where('dream_id',$dream_id)->get();
  1375. $top = [] ;
  1376. foreach ($support_dream as $item) {
  1377. if (!array_key_exists($item->user_id,$top)) {
  1378. $top[$item->user_id] = $item->score;
  1379. }else{
  1380. $top[$item->user_id] += $item->score;
  1381. }
  1382. }
  1383. arsort($top);
  1384. $new_arr = array_values($top);
  1385. if (!empty($top)) {
  1386. $top_user = array_search($new_arr[0],$top);
  1387. }else{
  1388. $top_user = 0;
  1389. }
  1390. if ($value==1) {
  1391. // 同意见面
  1392. $dream->is_ok = 1;
  1393. $dream->save();
  1394. $message = "你支持的梦想者已经同意见面啦";
  1395. }else{
  1396. $message = "你支持的梦想者拒绝了本次见面,你支持的梦想资金将会退还给您";
  1397. // 退款逻辑
  1398. }
  1399. Log::info('is_max:'.$top_user);
  1400. if (!empty($top_user)) {
  1401. // 给最大支持者发送消息
  1402. $arr = [
  1403. 'user_id'=>0,
  1404. 'message'=>$message,
  1405. 'to_user_id'=>$top_user,
  1406. 'dream_id'=>$dream_id,
  1407. 'attr_id'=>6,
  1408. 'is_end'=>0,
  1409. 'type_id'=>2,
  1410. 'is_max'=>1,
  1411. ];
  1412. SystemInfoModel::firstOrCreate($arr);
  1413. }
  1414. return $this->api($top_user);
  1415. }
  1416. // 梦想结束时梦主是否同意见面
  1417. /**
  1418. * @api {get} /api/my/sure_meet2 梦主是否同意见面
  1419. * @apiDescription 梦想结束时梦主是否同意见面
  1420. * @apiGroup My
  1421. * @apiParam {int} to_user_id 梦想者id(数据中的user_id)
  1422. * @apiParam {int} value 0取消1确定
  1423. * @apiPermission Passport
  1424. * @apiVersion 0.1.0
  1425. * @apiSuccessExample {json} Success-Response:
  1426. * HTTP/1.1 200 OK
  1427. *{
  1428. * "status": true,
  1429. * "status_code": 0,
  1430. * "message": "",
  1431. * "data": ""
  1432. *}
  1433. * @apiErrorExample {json} Error-Response:
  1434. *{
  1435. * "status": false,
  1436. * "status_code": 700,
  1437. * "message": "操作失败",
  1438. * "data": null
  1439. *}
  1440. */
  1441. public function isOk2(Request $request)
  1442. {
  1443. $user = $this->getUser();
  1444. $validator = \Validator::make($request->all(),
  1445. [
  1446. 'value' => 'required',
  1447. 'to_user_id' => 'required',
  1448. ],
  1449. [
  1450. 'value.required' => '参数错误',
  1451. 'to_user_id.required' => '梦想者不存在',
  1452. ]
  1453. );
  1454. if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  1455. $value = $request->input('value');
  1456. $to_user_id = $request->input('to_user_id');
  1457. $to_user_info = UserInfoModel::find($to_user_id);
  1458. if ($value==1) {
  1459. $message = '您的梦主同意见面了,赶快准备一下吧';
  1460. // 同意见面会收到一条提示信息
  1461. if (!empty($to_user_info)) {
  1462. $arr = [
  1463. 'user_id'=>0,
  1464. 'message'=>$to_user_info->nickname.'会第一时间联系你!见面时需要你扫一扫他提供的二维码哦',
  1465. // 'info'=>$to_user_info->nickname.'会第一时间联系你!见面时需要你扫一扫他提供的二维码哦',
  1466. 'to_user_id'=>$user->id,
  1467. 'is_end'=>1,
  1468. 'attr_id'=>6,
  1469. 'type_id'=>2,
  1470. ];
  1471. SystemInfoModel::firstOrCreate($arr);
  1472. }
  1473. }else{
  1474. $message = '您的梦主拒绝了你们的见面,喵~';
  1475. }
  1476. $arr = [
  1477. 'user_id'=>0,
  1478. 'message'=>$message,
  1479. 'to_user_id'=>$to_user_id,
  1480. 'is_end'=>1,
  1481. 'attr_id'=>5,
  1482. 'type_id'=>1,
  1483. ];
  1484. SystemInfoModel::firstOrCreate($arr);
  1485. return $this->api('');
  1486. }
  1487. /**
  1488. * @api {get} /api/my/account_log 支付列表
  1489. * @apiDescription 支付列表
  1490. * @apiGroup My
  1491. * @apiPermission Passport
  1492. * @apiVersion 0.1.0
  1493. * @apiSuccessExample {json} Success-Response:
  1494. * HTTP/1.1 200 OK
  1495. {
  1496. "status": true,
  1497. "status_code": 0,
  1498. "message": "",
  1499. "data": [
  1500. {
  1501. "id": 1,
  1502. "from_type": "1",
  1503. "from_id": 1,
  1504. "from_name": "1",
  1505. "op": "",
  1506. "from_amount": 2,
  1507. "to_type": "2",
  1508. "to_id": 1,
  1509. "to_name": null,
  1510. "to_amount": 2,
  1511. "channel": "1",
  1512. "avatar": null,
  1513. "transaction_id": null,
  1514. "note": null,
  1515. "created_at": null,
  1516. "updated_at": null,
  1517. "deleted_at": null
  1518. }
  1519. ]
  1520. }
  1521. * @apiErrorExample {json} Error-Response:
  1522. *{
  1523. * "status": false,
  1524. * "status_code": 700,
  1525. * "message": "操作失败",
  1526. * "data": null
  1527. *}
  1528. */
  1529. public function accountLog()
  1530. {
  1531. $user = $this->getUser();
  1532. $data = AccountLog::where('to_id',$user->id)->orWhere('from_id',$user->id)->orderBy('id','desc')->get();
  1533. return $this->api($data);
  1534. }
  1535. }