MyController.php 51 KB

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