MyController.php 52 KB

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