12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Models\AccountLog;
- use App\Models\BaseDictionaryOptionModel;
- use App\Models\BaseSettingsModel;
- use App\Models\CommentInfoModel;
- use App\Models\DreamInfoModel;
- use App\Models\InteractionInfo;
- use App\Models\SearchInfoModel;
- use App\Models\Suggest;
- use App\Models\SystemInfoModel;
- use App\Models\UserBank;
- use App\Models\UserCareDream;
- use App\Models\UserCareUser;
- use App\Models\UserCashOut;
- use App\Models\UserInfoModel;
- use Illuminate\Http\Request;
- use App\Services\Base\ErrorCode;
- use App\Helper\JpushHelper;
- class MyController extends Controller
- {
- use JpushHelper;
- /**
- * @api {get} /api/my/show 个人首页
- * @apiDescription 个人首页
- * @apiGroup My
- * @apiPermission Passport
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 O* "status": true,
- {
- "status": true,
- "status_code": 0,
- "message": "",
- "data": {
- "id": 1,
- "phone": "13880642880",
- "nickname": "name1",
- "avatar": "/upload/user/20170629/e77068cc14c82086fb6b16e5bb7c3dd1.jpg",
- "birthday": "2000-06-21",
- "sign": 0,
- "money": 0,
- "coin": 308,
- "sex": 1,
- "signture": "我的个性签名1",
- "height": 170,
- "work": "网红",
- "emotion": 1,
- "address": "",
- "city": "上海",
- "detail_address": "",
- "status": 1,
- "wechat": "",
- "weibo": "",
- "remember_token": "",
- "created_at": "2017-06-25 10:27:08",
- "updated_at": "2017-08-19 13:24:29",
- "deleted_at": null,
- "care_number": 0, 关注
- "fans_number": 0, 粉丝
- "dreams_number": 9, 梦想
- "collection_number": 0, 收藏
- "interaction_number": 0, 发帖
- "huitie": 1, 回复
- }
- }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "user": null
- * }
- *}
- */
- public function show()
- {
- $user = $this->getUser();
- /*
- * 我的关注人数,我的粉丝,收藏
- * 点赞?徽章?
- * */
- $care_num = $user->UserCareUser;
- $user->care_number = count($care_num);
- $fens = UserCareUser::where('other_user_id',$user->id)->get();
- $user->fans_number = count($fens);
- $dreams = $user->dreams;
- $user->dreams_number = count($dreams);
- $collection = $user->collection;
- $user->collection_number = count($collection);
- $interaction_infos = $user->allInteraction;
- $user->interaction_number = count($interaction_infos);
- $huitie = CommentInfoModel::where('user_id',$user->id)->orWhere('to_user_id',$user->id)->get()->groupBy('interaction_id');
- $user->huitie = count($huitie);
- return $this->api($user);
- }
- /**
- * @api {get} /api/my/edit 修改个人信息
- * @apiDescription 修改个人信息
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- "data": {
- "emotion": [
- {
- "value": "1",
- "name": "未婚"
- },
- {
- "value": "2",
- "name": "已婚"
- },
- {
- "value": "3",
- "name": "离异"
- }
- ],
- "sex": [
- {
- "value": "0",
- "name": "男"
- },
- {
- "value": "1",
- "name": "女"
- }
- ]
- }
- * }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "status": false,
- * "status_code": 1500,
- * "message": "会员不存在",
- * "data": null
- * }
- */
- public function edit()
- {
- $sex = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
- where('dictionary_code','sex')->get();
- $emotion = BaseDictionaryOptionModel::where('dictionary_table_code','user_info')->
- where('dictionary_code','emotion')->get();
- return $this->api(compact('emotion','sex'));
- }
- /**
- * @api {post} /api/my/update 保存个人信息
- * @apiDescription 保存个人信息
- * @apiParam {string} pic 头像
- * @apiParam {int} sex 性别
- * @apiParam {string} signture 个性签名
- * @apiParam {int} emotion 情感状态
- * @apiParam {string} work 职业
- * @apiParam {int} height 身高
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": ""
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- *{
- * "status": false,
- * "status_code": 600,
- * "message": "保存用户数据失败",
- * "data": null
- * }
- */
- public function update(Request $request)
- {
- $user = $this->getUser();
- $data = $request->except('_token');
- $ok = $user->update($data);
- if ($ok == true) {
- return $this->api('');
- }else{
- return $this->error(ErrorCode::SAVE_USER_FAILED);
- }
- }
- /**
- * @api {post} /api/my/recharge 充值
- * @apiDescription 充值
- * @apiGroup My
- * @apiParam {int} coin 充值金额
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function recharge(Request $request)
- {
- $validator = \Validator::make($request->all(),
- [
- 'coin' => 'required|integer',
- ],
- [
- 'coin.required' => '请填写金额',
- 'coin.integer' => '请输入整数',
- ]
- );
- if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
- $user = $this->getUser();
- $user->coin += $request->coin;
- $user->save();
- return $this->api('');
- }
- /**
- * @api {get} /api/my/reply 回复我的
- * @apiDescription 回复我的
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * ....
- * }
- * ]
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function reply()
- {
- $user = $this->getUser();
- $data = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get(); //user_id
- foreach ($data as $item){ //访问接口 标记已读
- $item->update(['is_read'=>0]);
- $info = InteractionInfo::find($item->interaction_id);
- $dream_id =empty($info) ? 0 : $info->dream_id;
- $item->dream_id = $dream_id;
- }
- return $this->api($data);
- }
- /**
- * @api {get} /api/my/letter 私信
- * @apiDescription 私信
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * ....
- * }
- * ]
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function letter()
- {
- $user = $this->getUser();
- $data = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
- foreach ($data as $item){ //访问接口 标记已读
- $item->update(['is_read'=>1]);
- }
- return $this->api($data);
- } /**
- * @api {get} /api/my/system_info 系统消息
- * @apiDescription 系统消息
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * ....
- * }
- * ]
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function systemInfo()
- {
- $user = $this->getUser();
- $data = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
- foreach ($data as $item){ //访问接口 标记已读
- $item->update(['is_read'=>1]);
- }
- return $this->api($data);
- }
- /**
- * @api {get} /api/my/info 消息中心
- * @apiDescription 消息中心
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "systemInfo": {
- * "number": 3,
- * "is_read": 3
- * },
- * "letter": {
- * "number": 0,
- * "is_read": 0
- * },
- * "reply": {
- * "number": 3,
- * "is_read": 3
- * }
- * }
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function info()
- {
- $user = $this->getUser();
- $systemInfo1 = SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
- $systemInfo2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
- ->whereNull('to_user_id')->orderBy('id','desc')->get();
- $letter1 = SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
- $letter2 = SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
- ->whereNotNull('to_user_id')->orderBy('id','desc')->get();
- $comments1 = CommentInfoModel::where('to_user_id',$user->id)->orderBy('id','desc')->get();
- $comments2 = CommentInfoModel::where('to_user_id',$user->id)->where('is_read','1')->orderBy('id','desc')->get();
- $arr = [];
- $arr['systemInfo']['number'] = count($systemInfo1) ;
- $arr['systemInfo']['is_read'] = count($systemInfo2) ;
- $arr['letter']['number'] = count($letter1) ;
- $arr['letter']['is_read'] = count($letter2) ;
- $arr['reply']['number'] = count($comments1) ;
- $arr['reply']['is_read'] = count($comments2) ;
- return $this->api($arr);
- }
- /**
- * @api {get} /api/my/read 设为已读
- * @apiDescription 设为已读
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": ""
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- * {
- * "status": false,
- * "status_code": 700,
- * "message": "操作失败",
- * "data": null
- *}
- */
- public function read()
- {
- $user = $this->getUser();
- $id = $user->id;
- $system_infos = SystemInfoModel::where(function ($query) use($id){
- $query->where('user_id',$id)->where('is_read','0');
- })->orWhere(function ($query) use($id){
- $query->where('to_user_id',$id)->where('is_read','0');
- })->orderBy('id','desc')->get();
- $comments = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
- foreach ($system_infos as $system_info){
- $system_info->update(['is_read'=>1]);
- }
- foreach ($comments as $comment){
- $comment->update(['is_read'=>1]);
- }
- if (count($system_infos) > 0 || count($comments) > 0) {
- return $this->api('');
- }else{
- return $this->error(ErrorCode::OPERATION_FAILED);
- }
- }
- /**
- * @api {get} /api/my/pay/article 支付说明
- * @apiDescription 支付说明
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- *"data": {
- * "key": "23453423453", 标题
- * "value": "<p><span style=\"color: rgb(255, 0, 0);\">42352345234534是大法官地方<
- * img src=\"/ueditor/php/upload/image/20170815/1502779635.jpg\" title=\"1502779635.jpg\" alt=\"a1.jpg\"/>234534</span><
- * br/></p>", 内容
- *}
- * ]
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function payArticle()
- {
- $data = BaseSettingsModel::where('category','pay_article')->first();
- return $this->api($data);
- }
- /**
- * @api {post} /api/my/cash 提现
- * @apiDescription 提现
- * @apiGroup My
- * @apiParam {int} data[bank_id] 银行卡号id
- * @apiParam {int} data[cash] 提现金额
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": false,
- * "status_code": 1413,
- * "message": "系统审核中",
- * "data": null
- *}
- * @apiErrorExample {json} Error-Response:
- *{
- * "status": false,
- * "status_code": 700,
- * "message": "操作失败",
- * "data": null
- *}
- */
- public function cash(Request $request)
- {
- $data = $request->data;
- $user = $this->getUser();
- $validator = \Validator::make($request->all(),
- [
- 'data.bank_id' => 'required|integer',
- 'data.cash' => 'required',
- ],
- [
- 'data.bank_id.required' => '请选择提现账号',
- 'data.bank_id.integer' => '提现账号不存在',
- 'data.cash.required' => '请输入金额',
- ]
- );
- if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
- // $info = [] ;
- // $info['from_type'] = '余额';
- // $info['from_id'] = $user->id;
- // $info['from_name'] = $user->name;
- // $info['op'] = '提现';
- // $info['from_amount'] = $data['coin'];
- // $info['to_type'] = '现金';
- // $info['to_id'] = $user->id;
- // $info['to_name'] = $data['account']; //账号
- // $info['note'] = $data['type'].$data['name'];
- // $ok = AccountLog::create($info);
- $data['user_id'] = $user->id;
- $data['status'] = 1;
- $ok = UserCashOut::create($data);
- $message = '你提现的¥'.$data["cash"].'已经到账啦,去实现梦想吧!喵~ ';
- $info = [
- 'user_id' => $user->id,
- 'message' => $message,
- ];
- SystemInfoModel::create($info);
- // 长连接
- $this->jPush($message,'',$user->id);
- if ($ok) {
- return $this->api(ErrorCode::verify);
- }else{
- return $this->error(ErrorCode::OPERATION_FAILED);
- }
- }
- // 联系客服
- /**
- * @api {post} /api/my/suggest 联系客服
- * @apiDescription 联系客服
- * @apiGroup My
- * @apiParam {string} data[content] 内容
- * @apiParam {string} data[email] 邮箱
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": ""
- *}
- * @apiErrorExample {json} Error-Response:
- *{
- * "status": false,
- * "status_code": 700,
- * "message": "操作失败",
- * "data": null
- *}
- */
- public function suggest(Request $request)
- {
- $data = $request->data;
- $user = $this->getUser();
- $validator = \Validator::make($request->all(),
- [
- 'data.content' => 'required',
- 'data.email' => 'required|email',
- ],
- [
- 'data.content.required' => '请输入你遇到的问题',
- 'data.email.required' => '请输入正确的邮箱地址',
- 'data.email.email' => '请输入正确的邮箱地址',
- ]
- );
- if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
- $data['user_id'] = $user->id;
- $ok =Suggest::create($data);
- if ($ok) {
- return $this->api('');
- }else{
- return $this->error(ErrorCode::OPERATION_FAILED);
- }
- }
- // 回复我的
- // public function replyMy()
- // {
- //
- // $user = $this->getUser();
- //// 梦想
- // $dreams = $user->UserDream;
- //
- // $data = $user->allInteraction;
- // foreach ($data as $item) {
- // $item->get_money = $item->dream->get_money;
- // $item->money = $item->dream->money;
- // }
- // dd($data) ;
- // if (count($dreams) == 0)
- // return $this->error(ErrorCode::DREAM_NOT_EXIST);
- // $comments_infos = [];
- // foreach ($dreams as $dream){
- // $comments_info = $dream->DreamInfo;
- // if (count($comments_info) > 0) {
- // foreach ($comments_info as $k => $value) {
- // $value->dream_name = $dream->dream;
- // $value->dream_about = $dream->about;
- // $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
- // $value->progress = $dream->money == 0 ? 0 : floor($dream->get_money/$dream->money);
- // $value->reviewer = $value->CommentUser->nickname;
- // $value->reviewer_pic = $value->CommentUser->pic;
- // }
- // $comments_infos[] = $comments_info;
- // }
- // }
- //
- // return $this->api(compact('comments_infos'));
- // }
- /**
- * @api {get} /api/my/dream 我的梦想
- * @apiDescription 我的梦想
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- {
- "status": true,
- "status_code": 0,
- "message": "",
- "data": {
- "current_page": 1,
- "data": [
- {
- "id": 32,
- "user_id": 1,
- "name": "name",
- "about": "13880642880",
- "coin": 100,
- "end_time": "0000-00-00 00:00:00",
- "get_coin": 2017,
- "mark": 100,
- "status": 127,
- "video": "0",
- "score": 0,
- "sign": "158730",
- "code": "http://www.miao.com/qrcodes/WECHATPAY_201708191324294255.png",
- "parameter": 0,
- "created_at": "2017-08-19 05:22:12",
- "updated_at": "2017-08-19 05:24:30",
- "img": {
- "title": "",
- "pic": "http://q8.9026.com/upload/dream/20170629/79c11614cc8a9d37f747e3974d055331.jpg"
- }
- },
- ],
- "from": 1,
- "last_page": 4,
- "next_page_url": "http://www.miao.com/api/my/dream?page=2",
- "path": "http://www.miao.com/api/my/dream",
- "per_page": 10,
- "prev_page_url": null,
- "to": 10,
- "total": 36
- }
- }
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function dream()
- {
- $user = $this->getUser();
- $dreams = DreamInfoModel::where('user_id',$user->id)->orderBy('created_at','desc')->with('img')->paginate();
- return $this->api($dreams);
- }
- /**
- * @api {get} /api/my/collection 我的收藏
- * @apiDescription 我的收藏
- * @apiGroup My
- * @apiPermission Passport
- * @apiParam {string} [keyword] 关键字可选
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "data": [
- * { 梦想详情
- * "id": 12,
- * "user_id": 2,
- * "name": "用户2梦想标题166",
- * "about": "用户2梦想介绍666",
- * "coin": 2500,
- * "time": 21,
- * "get_coin": 0,
- * "status": 0,
- * "video": null,
- * "sign": "",
- * },
- * "img": {
- * "title": "",
- * "pic": "https://f12f.jpg" 梦想封面图片
- * }
- * ],
- * "users": {
- * "2": "https://xxx.jpeg" ID号和头像
- * }
- * }
- *}
- * keyword存在
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": [
- * {
- * "id": 2,
- * "user_id": 1,
- * "dream_id": 12,
- * "dream_user_id": 2,
- * "interaction_number": 0,
- * "created_at": "2017-06-25 13:11:45",
- * "updated_at": "2017-06-25 13:11:45",
- * "dreams": [ 梦想
- * {
- * "id": 12,
- * "user_id": 2,
- * "name": "用户2梦想标题166",
- * "about": "用户2梦想介绍666",
- * "coin": 2500,
- * "end_time": 72000,
- * "get_coin": 792,
- * "mark": 5484,
- * "status": 0,
- * "video": "e",
- * "score": 158730,
- * "sign": "梦想达人",
- * "created_at": "2017-06-25 13:10:56",
- * "updated_at": "2017-06-28 16:53:39"
- * "img": { 图片
- * "title": "",
- * "pic": "https://timgsa.baidu.com/timg9&di2f.jpg"
- * },
- * "user": {
- *
- * }
- * }
- * ]
- * }
- * ]
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function collection(Request $request)
- {
- $user = $this->getUser();
- if ($request->keyword) {
- $keyword ='%'.$request->keyword.'%';
- $data = UserCareDream::where('user_id',$user->id)->
- whereHas('dreams',function ($query) use($keyword){
- $query->where('end_time','>=',time())->where('name','like',$keyword);
- })->with('dreams')->get();
- foreach ($data as $item) {
- foreach ($item->dreams as $dream) {
- $dream->img;
- }
- }
- $this->insertSearchTable($user->id,$request->keyword);
- return $this->api($data);
- }else{
- $dreams = $user->collection;
- // $users = [];
- foreach ($dreams as $item) {
- /* if ($item->pivot->interaction_number > 0) {
- $user_info = UserInfoModel::find($item->pivot->dream_user_id);
- $avatar = $user_info ? $user_info->avatar : '';
- if (!array_key_exists($item->pivot->dream_user_id,$users)) {
- $users[$item->pivot->dream_user_id] = $avatar;
- }
- }*/
- $item->img;
- $item->user;
- }
- return $this->api(compact('dreams'));
- }
- }
- /**
- * @api {get} /api/my/miao 关于喵喵
- * @apiDescription 关于喵喵
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": {
- * "key": "2511789", 电话
- * "value": "关于喵喵介绍" 关于喵喵
- * }
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function aboutMiao()
- {
- $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
- return $this->api($data);
- }
- /**
- * @api {get} /api/my/care 我关注的用户
- * @apiDescription 我关注的用户
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[] or
- * "data": [
- * {
- * "id": 2,
- * "phone": "13880642881",
- * "nickname": "name2",
- * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
- * "birthday": "2000-06-21",
- * "sign": 0,
- * "money": 0,
- * "coin": 800,
- * "sex": 1,
- * "signture": "我的个性签名2",
- * "height": 200,
- * "work": "兼职",
- * "emotion": 2,
- * "address": "370105",
- * "city": "成都",
- * "detail_address": "",
- * "status": 1,
- * "wechat": "",
- * "weibo": "",
- * "remember_token": "",
- * "created_at": "2017-06-25 10:42:06",
- * "updated_at": "2017-06-30 09:15:04",
- * "deleted_at": null,
- * }
- * ]
- *}
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function care()
- {
- $user = $this->getUser();
- $users =$user->UserCareUser;
- return $this->api($users);
- }
- public function insertSearchTable($id,$keyword)
- {
- $info = SearchInfoModel::where('user_id',$id)->
- where('search',trim($keyword))->first();
- if (count($info) == 0) {
- SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
- }else{
- $info->times += 1;
- $info->save();
- }
- }
- //我的银行账户
- /**
- * @api {get} /api/my/bank/list 我的银行账户
- * @apiDescription 我的银行账户
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[] or
- * "data": [
- * {
- * "id": 1,
- * "user_id": 1,
- * "bank_name": "1",
- * "bank_number": "1", /账号
- * "bank_phone": "1",
- * "bank_user": "" 用户名/
- * "type": 微信, 微信(支付宝)二维码
- * "url": wwww.ddf, 二维码地址
- * "is_img": 1,
- * }
- *]
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function bankList()
- {
- $user = $this->getUser();
- $data = UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
- return $this->api($data);
- }
- /**
- * @api {get} /api/my/bank/account 账户余额
- * @apiDescription 账户余额
- * @apiGroup My
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data":[] or
- * "data": {
- * "coin": 508, 余额
- * }
- *]
- * @apiErrorExample {json} Error-Response:
- * HTTP/1.1 400 Bad Request
- */
- public function account()
- {
- $user = $this->getUser();
- return $this->api($user);
- }
- // 添加银行卡
- /**
- * @api {post} /api/my/bank/create 添加银行卡
- * @apiDescription 添加银行卡
- * @apiGroup My
- * @apiParam {string} data[bank_name] 银行名称
- * @apiParam {string} data[bank_number] 银行卡号
- * @apiParam {int} data[bank_phone] 银行卡绑定手机号
- * @apiParam {string} data[bank_user] 银行卡用户姓名
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": ""
- *}
- * @apiErrorExample {json} Error-Response:
- *{
- * "status": false,
- * "status_code": 700,
- * "message": "操作失败",
- * "data": null
- *}
- */
- public function bankCreate(Request $request)
- {
- $data = $request->data;
- $user = $this->getUser();
- $validator = \Validator::make($request->all(),
- [
- 'data.bank_name' => 'required',
- 'data.bank_number' => 'required',
- 'data.bank_phone' => 'required',
- 'data.bank_user' => 'required',
- ],
- [
- 'data.bank_name.required' => '请选择账号类型',
- 'data.bank_number.required' => '请输入账号',
- 'data.bank_phone.required' => '请输入账号绑定手机号码',
- 'data.bank_user.required' => '请输入账号绑定用户姓名',
- ]
- );
- if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
- $data['user_id'] = $user->id;
- $ok =UserBank::create($data);
- if ($ok) {
- return $this->api('');
- }else{
- return $this->error(ErrorCode::OPERATION_FAILED);
- }
- } /**
- * @api {post} /api/my/bank/qrcode 添加二维码
- * @apiDescription 添加二维码
- * @apiGroup My
- * @apiParam {string} data[type] 类型
- * @apiParam {string} data[qrcode] 二维码图片
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": ""
- *}
- * @apiErrorExample {json} Error-Response:
- *{
- * "status": false,
- * "status_code": 700,
- * "message": "操作失败",
- * "data": null
- *}
- */
- public function bankImgCreate(Request $request)
- {
- $data = $request->data;
- $user = $this->getUser();
- $validator = \Validator::make($request->all(),
- [
- 'data.type' => 'required',
- 'data.qrcode' => 'required',
- ],
- [
- 'data.type.required' => '请选择账号类型',
- 'data.qrcode.required' => '请上传二维码图片',
- ]
- );
- if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
- $data['user_id'] = $user->id;
- /* $data['bank_user'] = '';
- $data['bank_phone'] = '';
- $data['bank_number'] = '';
- $data['bank_name'] = '';*/
- $info = UserBank::whereNotNull('qrcode')->where('user_id',$user->id)
- ->where('type',$data['type'])->first(); //定义为二维码
- if (empty($info)) {
- $ok =UserBank::create($data);
- }else{
- $ok = $info->update($data);
- }
- if ($ok) {
- return $this->api('');
- }else{
- return $this->error(ErrorCode::OPERATION_FAILED);
- }
- }
- /**
- * @api {get} /api/my/bank/delete 删除银行卡
- * @apiDescription 删除银行卡
- * @apiGroup My
- * @apiParam {int} id 银行卡id
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- *{
- * "status": true,
- * "status_code": 0,
- * "message": "",
- * "data": ""
- *}
- * @apiErrorExample {json} Error-Response:
- *{
- * "status": false,
- * "status_code": 700,
- * "message": "操作失败",
- * "data": null
- *}
- */
- public function bankDelete(Request $request)
- {
- $id = $request->id;
- $validator = \Validator::make($request->all(),
- [
- 'id' => 'required',
- ],
- [
- 'id.required' => '银行账号不存在',
- ]
- );
- if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
- $ok =UserBank::destroy($id);
- if ($ok) {
- return $this->api('');
- }else{
- return $this->error(ErrorCode::OPERATION_FAILED);
- }
- }
- }
|