MyController.php 53 KB

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