MyController.php 52 KB

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