MyController.php 53 KB

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