MyController.php 54 KB

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