MobileMember.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. * ============================================================================
  5. *
  6. * ============================================================================
  7. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  8. * 网站地址: https://www.valimart.net/
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 控制器
  13. */
  14. class MobileMember extends MobileHome {
  15. public function initialize() {
  16. parent::initialize();
  17. $key = request()->header('X-DS-KEY');
  18. if(!$key){
  19. $key=input('param.key');//微信支付需要
  20. }
  21. if (!empty($key)) {
  22. $mbusertoken_model = model('mbusertoken');
  23. $mb_user_token_info = $mbusertoken_model->getMbusertokenInfoByToken($key);
  24. if (empty($mb_user_token_info)) {
  25. ds_json_encode(11001, lang('please_login'));
  26. }
  27. $member_model = model('member');
  28. $this->member_info = $member_model->getMemberInfoByID($mb_user_token_info['member_id']);
  29. if (empty($this->member_info)) {
  30. ds_json_encode(11001, lang('please_login'));
  31. } else {
  32. if (!$this->member_info['member_state']) {
  33. ds_json_encode(11001, lang('please_login'));
  34. }
  35. $this->member_info['member_clienttype'] = $mb_user_token_info['member_clienttype'];
  36. $this->member_info['member_openid'] = $mb_user_token_info['member_openid'];
  37. $this->member_info['member_token'] = $mb_user_token_info['member_token'];
  38. $level_name = $member_model->getOneMemberGrade($mb_user_token_info['member_id']);
  39. $this->member_info['level_name'] = $level_name['level_name'];
  40. //读取卖家信息
  41. $seller_info = model('seller')->getSellerInfo(array('member_id' => $this->member_info['member_id']));
  42. $this->member_info['store_id'] = $seller_info['store_id'];
  43. //考虑到模型中session
  44. if (session('member_id') != $this->member_info['member_id']) {
  45. //避免重复查询数据库
  46. $member_model->createSession(array_merge($this->member_info, $level_name), true);
  47. }
  48. }
  49. }else{
  50. ds_json_encode(11001, lang('please_login'));
  51. }
  52. }
  53. public function getOpenId() {
  54. return $this->member_info['member_openid'];
  55. }
  56. public function setOpenId($openId) {
  57. $this->member_info['member_openid'] = $openId;
  58. model('mbusertoken')->editMemberOpenId($this->member_info['member_token'], $openId);
  59. }
  60. }
  61. ?>