MobileMember.php 2.5 KB

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