Member.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\MemberHouseModel;
  4. use app\api\model\YzmModel;
  5. use app\common\controller\Api;
  6. use aliyun\api_demo\SmsDemo;
  7. use app\api\model\CodeModel;
  8. use app\api\model\MemberModel;
  9. use app\api\model\AppDataModel;
  10. use app\api\controller\Common;
  11. /**
  12. * 会员相关接口
  13. * @ApiWeigh (100)
  14. */
  15. class Member extends Api
  16. {
  17. protected $noNeedLogin = ['yzm','sendCode','register','create_qrcode','login','edit_password','out'];//,'my_keys','my_detail'
  18. protected $noNeedRight = ['*'];
  19. /**
  20. * 生成随机数字验证码图片
  21. * @ApiRoute (/api/member/yzm)
  22. * @ApiReturn ({
  23. "code": 1,
  24. "msg": "success",
  25. "time": "1603691703",
  26. "data": {
  27. "url": "/upload/verification_code_img/member_id_160369170339328.png", //验证码地址
  28. "rand": "160369170339328" //标识码,点击发送验证码也要传过来
  29. }
  30. })
  31. */
  32. function yzm($width = 80,$height = 40)
  33. {
  34. $str = '0123456789abcdefghizklmnopqrstuvwxyz'; // 也可取出类似的0il
  35. $code = substr(str_shuffle($str),0,'4');
  36. $rand=rand(10000,99999);
  37. $member_id=time().$rand;
  38. //判断文件夹是否存在,不存在则创建
  39. $dir = ROOT_PATH . 'public' . DS .'uploads/verification_code_img';
  40. if(!is_dir($dir)){
  41. mkdir($dir, 0777, true);
  42. }
  43. //验证码图片保存路径,文件名称
  44. $file_name = ROOT_PATH . 'public' . DS .'uploads/verification_code_img/'.$member_id.'.png';
  45. //域名返回
  46. $domain_name = config('site.cdnurl').'/uploads/verification_code_img/'.$member_id.'.png';
  47. $img = imagecreatetruecolor($width, $height);
  48. $black = imagecolorallocate($img, 0x00, 0x00, 0x00);
  49. $green = imagecolorallocate($img, 0x00, 0xFF, 0x00);
  50. $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
  51. imagefill($img,0,0,$white);
  52. imagestring($img, 5, 22, 12, $code, $black);
  53. //加入噪点干扰
  54. for($i=0;$i<100;$i++) {
  55. imagesetpixel($img, rand(0, $width) , rand(0, $width) , $black); //imagesetpixel — 画一个单一像素,语法: bool imagesetpixel ( resource $image , int $x , int $y , int $color )
  56. imagesetpixel($img, rand(0, $width) , rand(0, $width) , $green);
  57. }
  58. //输出验证码
  59. // header("content-type: image/png");
  60. imagepng($img,$file_name); //保存图片
  61. imagedestroy($img); //图像处理完成后,使用 imagedestroy() 指令销毁图像资源以释放内存,虽然该函数不是必须的,但使用它是一个好习惯。
  62. $log = ['code' => $code,
  63. 'rand' => $member_id,
  64. 'scene' => '图形验证码',
  65. 'time' => datetime(time())
  66. ];
  67. $addLog = YzmModel::create($log);
  68. $this->result('success', ['url'=>$domain_name,'rand'=>$member_id], 1);
  69. }
  70. /**
  71. * 发送短信验证码
  72. *
  73. * @ApiMethod (POST)
  74. * @ApiRoute (/api/member/sendCode)
  75. * @ApiParams (name="mobile", type="varchar", required=true, description="用户手机号")
  76. * @ApiParams (name="rand", type="string", required=true, description="标识码")
  77. * @ApiParams (name="code", type="string", required=true, description="输入的图形验证码")
  78. * @ApiParams (name="scene", type="string", required=true, description=" 1 注册发送验证码,2 找回密码验证码")
  79. * @ApiReturn ({
  80. 'code':'1', //0是失败,弹出msg提示
  81. 'msg':'验证码已发送'
  82. })
  83. */
  84. public function sendCode()
  85. {
  86. $mobile = $this->request->post('mobile');
  87. $rand= $this->request->post('rand');
  88. $code= $this->request->post('code');
  89. $scene= $this->request->post('scene');
  90. if (empty($code)){
  91. $this->result('请输入图形验证码');
  92. }
  93. if (!$mobile || !$rand || !$code) {
  94. $this->result('参数错误');
  95. }
  96. if (empty($scene)){
  97. $scene=1;
  98. }
  99. // $ip=get_ip();
  100. $check_code = CodeModel::where('mobile', $mobile)->where('scene',$scene)
  101. ->order('id desc')
  102. ->find();
  103. $sendTime = strtotime($check_code['time']);
  104. if (time() - $sendTime < 300) {
  105. $this->result('5分钟之后才可以发送');
  106. }
  107. $get_yzm=YzmModel::where('rand',$rand)->where('status','0')->order('id','desc')->find();
  108. if (empty($get_yzm)){
  109. $this->result('图形验证码错误!');
  110. }
  111. $sendTime = strtotime($get_yzm['time']);
  112. if (time() - $sendTime > 300) {//分钟过期
  113. $this->result('图形验证码已过期');
  114. }
  115. if ($code !=$get_yzm['code']){
  116. $this->result('图形验证码错误');
  117. }else{
  118. YzmModel::where('id',$get_yzm['id'])->update(['status'=>'1']);
  119. }
  120. $code = rand(1000, 9999);
  121. $Sms = new SmsDemo();
  122. $send = $Sms->sendSms($mobile, $code);
  123. if ($send->Message == 'OK') {
  124. $log = ['code' => $code,
  125. 'mobile' => $mobile,
  126. 'scene' =>$scene,
  127. 'time' => datetime(time())
  128. ];
  129. $addLog = CodeModel::create($log);
  130. if ($addLog) {
  131. $this->result('验证码已发送', [], 1);
  132. } else {
  133. $this->result('验证码发送失败');
  134. }
  135. } else {
  136. $this->result('验证码发送失败');
  137. }
  138. // $log = ['code' => '1234',
  139. // 'mobile' => $mobile,
  140. // 'scene' =>$scene,
  141. // 'time' => datetime(time())
  142. // ];
  143. // $addLog = CodeModel::create($log);
  144. // if ($addLog) {
  145. // $this->result('验证码已发送', [], 1);
  146. // } else {
  147. // $this->result('验证码发送失败');
  148. // }
  149. }
  150. /**
  151. * 用户注册
  152. *
  153. * @ApiTitle (用户注册)
  154. * @ApiSummary (用户注册)
  155. * @ApiMethod (POST)
  156. * @ApiRoute (/api/member/register)
  157. * @ApiParams (name="mobile", type="varchar", required=true, description="用户手机号")
  158. * @ApiParams (name="check_code", type="int", required=true, description="短信验证码")
  159. * @ApiParams (name="password", type="int", required=true, description="密码")
  160. */
  161. public function register()
  162. {
  163. $mobile = $this->request->post('mobile');
  164. $checkCode = $this->request->post('check_code');
  165. $password = $this->request->post('password');
  166. if (!$mobile || !$checkCode || !$password) {
  167. $this->result('参数错误');
  168. }
  169. // 验证验证码
  170. $check_code = CodeModel::where('mobile', $mobile)->where('scene','1')
  171. ->order('id desc')
  172. ->limit(0, 1)
  173. ->select();
  174. if (empty($check_code)) {
  175. $this->result('验证码错误');
  176. }
  177. if ($check_code[0]['code'] != $checkCode) {
  178. $this->result('验证码错误');
  179. }
  180. $sendTime = strtotime($check_code[0]['time']);
  181. if (time() - $sendTime > 300) {//5分钟过期时间
  182. $this->result('验证码已过期');
  183. }
  184. $get_is_user=MemberModel::where('mobile', $mobile)->field('id')->find();
  185. if (!empty($get_is_user)){
  186. $this->result('手机号已经注册,请直接登录或者找回密码');
  187. }else{
  188. $where = ['id' => 1];
  189. $defaultField = ['default_nickname', 'default_avatar'];
  190. $default = AppDataModel::where($where)->field($defaultField)->find();//-----------
  191. $info = [
  192. 'avatar' => $default['default_avatar'],
  193. 'nickname' => substr_replace($mobile,'****',3,4),//$default['default_nickname'],
  194. 'name' => substr_replace($mobile,'****',3,4),
  195. 'mobile' => $mobile,
  196. 'rands' =>createSalt(),
  197. 'password'=>md5(trim($password)),
  198. 'create_time' => datetime(time()),
  199. ];
  200. $createId = MemberModel::insertGetId($info);
  201. if ($createId) {
  202. $this->result('恭喜你成功注册新天物业', ['user_id' => intval($createId)], 1);
  203. // MemberModel::where('mobile', $mobile)->setInc('login_num', 1);
  204. // 生成token
  205. // $salt = createSalt();
  206. // $token = md5($createId.$salt);
  207. // // 更新token和随机码salt
  208. // $updateToken = MemberModel::where('mobile', $mobile)
  209. // ->update(['salt' => $salt, 'token' => $token]);
  210. // if ($updateToken) {
  211. // if (!empty($top_id)){
  212. // MemberModel::where('id', $top_id)->setInc('down_people');
  213. // }
  214. //
  215. // // $this->result('恭喜你成功注册新天物业', ['user_id' => intval($createId), 'token' => $token,'rands'=>$info['rands']], 1);
  216. // } else {
  217. // $this->result('登录失败', null, 0);
  218. // }
  219. } else {
  220. $this->result('注册失败', null, 0);
  221. }
  222. }
  223. }
  224. /**
  225. * 用户登录
  226. *
  227. * @ApiTitle (用户登录)
  228. * @ApiSummary (用户登录)
  229. * @ApiMethod (POST)
  230. * @ApiRoute (/api/member/login)
  231. * @ApiParams (name="mobile", type="varchar", required=true, description="用户手机号")
  232. * @ApiParams (name="password", type="int", required=true, description="密码")
  233. */
  234. public function login()
  235. {
  236. $mobile = $this->request->post('mobile');
  237. $password = $this->request->post('password');
  238. if (!$mobile || !$password) {
  239. $this->result('参数错误');
  240. }
  241. $user = MemberModel::where('mobile', $mobile)->where('password',md5(trim($password)))->field('id,rands')->find();
  242. if (!$user){
  243. $this->result('账号或密码错误,请重新登录');
  244. }else{
  245. $get_hu=MemberHouseModel::where('mid',$user['id'])->where('is_delete','0')->field('id')->find();
  246. if (empty($get_hu)){
  247. $user['hu_id']=0;
  248. }else{
  249. $user['hu_id']=$get_hu['id'];
  250. }
  251. MemberModel::where('id', $user['id'])->setInc('login_num', 1);
  252. // 生成token
  253. $salt = createSalt();
  254. $token = md5($user['id'].$salt);
  255. // 更新token和随机码salt
  256. $updateToken = MemberModel::where('mobile', $mobile)
  257. ->update(['salt' => $salt, 'token' => $token]);
  258. if ($updateToken) {
  259. $this->result('登录成功',['user_id' => $user['id'], 'token' => $token,'rands'=>$user['rands'],'hu_id'=>$user['hu_id']], 1);
  260. } else {
  261. $this->result('登录失败', null, 0);
  262. }
  263. }
  264. }
  265. /**
  266. * 找回密码
  267. *
  268. * @ApiTitle (找回密码)
  269. * @ApiSummary (找回密码)
  270. * @ApiMethod (POST)
  271. * @ApiRoute (/api/member/edit_password)
  272. * @ApiParams (name="mobile", type="varchar", required=true, description="用户手机号")
  273. * @ApiParams (name="check_code", type="int", required=true, description="短信验证码")
  274. * @ApiParams (name="password", type="int", required=true, description="密码")
  275. */
  276. public function edit_password()
  277. {
  278. $mobile = $this->request->post('mobile');
  279. $checkCode = $this->request->post('check_code');
  280. $password = $this->request->post('password');
  281. if (!$mobile || !$checkCode || !$password) {
  282. $this->result('参数错误');
  283. }
  284. // 验证验证码
  285. $check_code = CodeModel::where('mobile', $mobile)->where('scene','2')
  286. ->order('id desc')
  287. ->limit(0, 1)
  288. ->select();
  289. if (empty($check_code)) {
  290. $this->result('验证码错误');
  291. }
  292. if ($check_code[0]['code'] != $checkCode) {
  293. $this->result('验证码错误');
  294. }
  295. $sendTime = strtotime($check_code[0]['time']);
  296. if (time() - $sendTime > 300) {//5分钟过期时间
  297. $this->result('验证码已过期');
  298. }
  299. $user = MemberModel::where('mobile', $mobile)->field('id,rands')->find();
  300. if (empty($user)){
  301. $this->result('您的手机号还未注册用户,请注册');
  302. }
  303. MemberModel::where('id', $user['id'])->setInc('login_num', 1);
  304. // 生成token
  305. $salt = createSalt();
  306. $token = md5($user['id'].$salt);
  307. // 更新token和随机码salt
  308. $updateToken = MemberModel::where('mobile', $mobile)
  309. ->update(['salt' => $salt, 'token' => $token,'password'=>md5(trim($password))]);
  310. if ($updateToken) {
  311. $this->result('密码修改成功',['user_id' => $user['id'], 'token' => $token,'rands'=>$user['rands']], 1);
  312. } else {
  313. $this->result('登录失败', null, 0);
  314. }
  315. }
  316. /**
  317. * 我的信息
  318. *
  319. * @ApiTitle (我的信息)
  320. * @ApiSummary (我的信息)
  321. * @ApiMethod (POST)
  322. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  323. * @ApiRoute (/api/member/my_detail)
  324. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  325. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  326. * @ApiParams (name="house_id", type="int", required=true, description="房产id")
  327. * @ApiReturn ({
  328. "code": 1,
  329. "msg": "success",
  330. "time": "1604474877",
  331. "data": {
  332. "id": 1,//用户id
  333. "top_id": 0,
  334. "top_top_id": 0,
  335. "rands": "igqwpg",
  336. "avatar": "http://baoxiang.com//assets/img/qrcode.png",//用户头像
  337. "nickname": "默认昵称 ",//昵称
  338. "name": "",
  339. "price": null,
  340. "profile": "",
  341. "mobile": "13512144196",
  342. "wx_code": "",
  343. "sex": 0,
  344. "openid": "",
  345. "now_money": "0.00",//当前余额
  346. "down_people": 0,//下级人数
  347. "create_time": "2020-11-02 09:43:10",
  348. "login_num": 9,
  349. "status": 1,
  350. "salt": "pjxwqm",
  351. "token": "70780f043d7ffaf239c73095d5a2f808"
  352. }
  353. })
  354. */
  355. public function my_detail(){
  356. $userId = $this->request->post('user_id');
  357. $house_id = $this->request->post('house_id');
  358. if (empty($userId)){
  359. $this->result('登录信息丢失');
  360. }
  361. //
  362. $my=MemberModel::where(['id'=>$userId])->find();
  363. if (!empty($house_id)){
  364. $where['id']=$house_id;
  365. }
  366. $where['mid']=$userId;
  367. $where['is_delete']='0';
  368. $list=MemberHouseModel::where($where)
  369. ->with(['property','village','dong','danyuan','hu'])
  370. ->find();
  371. $my['house']='';
  372. if (!empty($list)){
  373. $my['house']=$list['village']['name'].$list['dong']['name'].$list['danyuan']['name'].$list['hu']['name'];
  374. }
  375. $this->result('success', $my, 1);
  376. }
  377. /**
  378. * 修改信息-昵称+头像
  379. *
  380. * @ApiTitle (修改信息-昵称+头像)
  381. * @ApiSummary (修改信息-昵称+头像)
  382. * @ApiMethod (POST)
  383. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  384. * @ApiRoute (/api/member/my_edit)
  385. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  386. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  387. * @ApiParams (name="nickname", type="string", required=true, description="昵称")
  388. * @ApiParams (name="avatar", type="string", required=true, description="头像地址")
  389. * @ApiParams (name="sex", type="string", required=true, description="未知,男,女")
  390. * @ApiReturn ()
  391. */
  392. public function my_edit(){
  393. $userId = $this->request->post('user_id');
  394. $nickname= $this->request->post('nickname');
  395. $avatar = $this->request->post('avatar');
  396. $sex = $this->request->post('sex');
  397. if (empty($userId)){
  398. $this->result('登录信息丢失');
  399. }
  400. $update=[];
  401. if (!empty($nickname)){
  402. $update['name']=$update['nickname']=preg_replace('/[\xf0-\xf7].{3}/', '', trim($nickname));
  403. }
  404. if (!empty($avatar)){
  405. $update['avatar']=$avatar;
  406. }
  407. if (!empty($sex)){
  408. $update['sex']=$sex;
  409. }else{
  410. $update['sex']='未知';
  411. }
  412. if (!empty($update)){
  413. MemberModel::where(['id'=>$userId])->update($update);
  414. $this->result('信息修改成功', [], 1);
  415. }else{
  416. $this->result('没修改任何信息');
  417. }
  418. }
  419. /**
  420. * 微信登录
  421. *
  422. * @ApiTitle (微信登录)
  423. * @ApiSummary (微信登录)
  424. * @ApiMethod (POST)
  425. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  426. * @ApiRoute (/api/member/wx_login)
  427. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  428. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  429. * @ApiParams (name="code", type="int", required=true, description="微信code")
  430. * @ApiReturn ()
  431. */
  432. public function wx_login()
  433. {
  434. $userId = $this->request->post('user_id');
  435. if (empty($userId)){
  436. $this->result('登录信息丢失');
  437. }
  438. $code = $this->request->post('code');
  439. if (!isset($code)) {
  440. return $this->result('未接收到code', []);
  441. }
  442. $appid = 'wxdbf57a855b519ecf';
  443. $appsecret = '87dc4671be6b63697a0048767924e94d';
  444. $access_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code';
  445. $tokens =$this->http_curl($access_token_url);
  446. if (isset($tokens['openid'])) {
  447. $member=MemberModel::where('id',$userId)->update(['openid'=>$tokens['openid']]);
  448. return $this->result('success', '', 200);
  449. } else {
  450. return $this->result($tokens);
  451. }
  452. }
  453. /**
  454. * 我的房屋列表
  455. *
  456. * @ApiTitle (我的房屋列表)
  457. * @ApiSummary (我的房屋列表)
  458. * @ApiMethod (POST)
  459. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  460. * @ApiRoute (/api/member/my_house_list)
  461. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  462. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  463. * @ApiParams (name="type", type="int", required=false, description="all 只有我的房屋列表才传值")
  464. * @ApiReturn ()
  465. */
  466. public function my_house_list(){
  467. $userId = $this->request->post('user_id');
  468. if (empty($userId)){
  469. $this->result('登录信息丢失');
  470. }
  471. $type = $this->request->post('type');
  472. if (empty($type)){
  473. $where['status']='1';
  474. }
  475. $where['is_delete']='0';
  476. $list=MemberHouseModel::where(['mid'=>$userId])
  477. ->where($where)
  478. ->with(['property','village','dong','danyuan','hu'])
  479. ->field('id,mid,property_id,village_id,dong_id,danyuan_id,hu_id,status')
  480. ->select();
  481. foreach ($list as $k=>$v){
  482. $list[$k]['house']=$v['property']['name']." ".$v['village']['name']." ".$v['danyuan']['name']." ".$v['hu']['name'];
  483. }
  484. $this->result('房屋列表', $list, 1);
  485. }
  486. /**
  487. * 绑定住房信息
  488. *
  489. * @ApiTitle (绑定住房信息)
  490. * @ApiSummary (绑定住房信息)
  491. * @ApiMethod (POST)
  492. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  493. * @ApiRoute (/api/member/my_house_add)
  494. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  495. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  496. * @ApiParams (name="property_id", type="int", required=true, description="物业id")
  497. * @ApiParams (name="village_id", type="int", required=true, description="小区id")
  498. * @ApiParams (name="dong_id", type="int", required=true, description="楼宇id")
  499. * @ApiParams (name="danyuan_id", type="int", required=true, description="单元id")
  500. * @ApiParams (name="hu_id", type="int", required=true, description="户id")
  501. * @ApiParams (name="name", type="int", required=true, description="姓名")
  502. * @ApiParams (name="phone", type="int", required=true, description="电话")
  503. * @ApiReturn ()
  504. */
  505. public function my_house_add(){
  506. $userId = $this->request->post('user_id');
  507. if (empty($userId)){
  508. $this->result('登录信息丢失');
  509. }
  510. $property_id = $this->request->post('property_id');
  511. $village_id = $this->request->post('village_id');
  512. $dong_id = $this->request->post('dong_id');
  513. $danyuan_id = $this->request->post('danyuan_id');
  514. $hu_id= $this->request->post('hu_id');
  515. $name= $this->request->post('name');
  516. $phone= $this->request->post('phone');
  517. $update=[
  518. 'property_id'=>$property_id,
  519. 'village_id'=>$village_id,
  520. 'dong_id'=>$dong_id,
  521. 'danyuan_id'=>$danyuan_id,
  522. 'hu_id'=>$hu_id,
  523. 'name'=>$name,
  524. 'phone'=>$phone,
  525. 'status'=>'0',
  526. 'mid'=>$userId,
  527. 'createtime'=>time(),
  528. 'updatetime'=>time()
  529. ];
  530. MemberHouseModel::insert($update);
  531. $this->result('住房绑定成功', '', 1);
  532. }
  533. /**
  534. * 解绑住房信息
  535. *
  536. * @ApiTitle (解绑住房信息)
  537. * @ApiSummary (解绑住房信息)
  538. * @ApiMethod (POST)
  539. * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  540. * @ApiRoute (/api/member/my_house_del)
  541. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  542. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  543. * @ApiParams (name="house_id", type="int", required=true, description="住房绑定列表id")
  544. * @ApiReturn ()
  545. */
  546. public function my_house_del(){
  547. $userId = $this->request->post('user_id');
  548. if (empty($userId)){
  549. $this->result('登录信息丢失');
  550. }
  551. $house_id = $this->request->post('house_id');
  552. MemberHouseModel::where(['mid'=>$userId,'id'=>$house_id])->update(['is_delete'=>'1']);
  553. $this->result('住房解绑成功', '', 1);
  554. }
  555. /**
  556. * 退出登录
  557. *
  558. * @ApiTitle (退出登录)
  559. * @ApiSummary (退出登录)
  560. * @ApiMethod (POST)
  561. * @ApiRoute (/api/member/out)
  562. * @ApiParams (name="user_id", type="int", required=true, description="用户id")
  563. * @ApiParams (name="token", type="int", required=true, description="请求的Token")
  564. */
  565. public function out()
  566. {
  567. $userId = $this->request->post('user_id');
  568. if (empty($userId)){
  569. $this->result('成功退出','', 1);
  570. }
  571. $updateToken = MemberModel::where('id', $userId)
  572. ->update(['salt' => '0', 'token' => '0']);
  573. $this->result('成功退出','', 1);
  574. }
  575. function http_curl($url, $type = 'get', $res = 'json', $arr = '')
  576. {
  577. //1.初始化curl
  578. $ch = curl_init();
  579. //2.设置curl的参数
  580. curl_setopt($ch, CURLOPT_URL, $url);
  581. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
  582. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
  583. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  584. // curl_setopt($ch, CURLOPT_HTTPHEADER, array(' Accept-Ranges:bytes Cache-control:max-age=604800 Connection:keep-alive Content-Length:28026 Content-Type:image/jpg Date:Wed, 16 Oct 2013 06:37:10 GMT Expires:Wed, 23 Oct 2013 14:37:10 +0800 Server:nginx/1.4.1'));
  585. //3.采集
  586. $output = curl_exec($ch);
  587. //4.关闭
  588. curl_close($ch);
  589. if ($res == 'json') {
  590. return json_decode($output, true);
  591. }
  592. return $output;
  593. }
  594. }