MobileMember.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. * ============================================================================
  5. * DSMall多用户商城
  6. * ============================================================================
  7. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  8. * 网站地址: http://www.csdeshang.com
  9. * ----------------------------------------------------------------------------
  10. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  11. * 不允许对程序代码以任何形式任何目的的再发布。
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class MobileMember extends MobileHome {
  16. public function initialize() {
  17. parent::initialize();
  18. $key = request()->header('X-DS-KEY');
  19. if(!$key){
  20. $key=input('param.key');//微信支付需要
  21. }
  22. if (!empty($key)) {
  23. $mbusertoken_model = model('mbusertoken');
  24. $mb_user_token_info = $mbusertoken_model->getMbusertokenInfoByToken($key);
  25. if (empty($mb_user_token_info)) {
  26. ds_json_encode(11001, lang('please_login'));
  27. }
  28. $member_model = model('member');
  29. $this->member_info = $member_model->getMemberInfoByID($mb_user_token_info['member_id']);
  30. if (empty($this->member_info)) {
  31. ds_json_encode(11001, lang('please_login'));
  32. } else {
  33. if (!$this->member_info['member_state']) {
  34. ds_json_encode(11001, lang('please_login'));
  35. }
  36. $this->member_info['member_clienttype'] = $mb_user_token_info['member_clienttype'];
  37. $this->member_info['member_openid'] = $mb_user_token_info['member_openid'];
  38. $this->member_info['member_token'] = $mb_user_token_info['member_token'];
  39. $level_name = $member_model->getOneMemberGrade($mb_user_token_info['member_id']);
  40. $this->member_info['level_name'] = $level_name['level_name'];
  41. //读取卖家信息
  42. $seller_info = model('seller')->getSellerInfo(array('member_id' => $this->member_info['member_id']));
  43. $this->member_info['store_id'] = $seller_info['store_id'];
  44. //考虑到模型中session
  45. if (session('member_id') != $this->member_info['member_id']) {
  46. //避免重复查询数据库
  47. $member_model->createSession(array_merge($this->member_info, $level_name), true);
  48. }
  49. }
  50. }else{
  51. ds_json_encode(11001, lang('please_login'));
  52. }
  53. }
  54. public function getOpenId() {
  55. return $this->member_info['member_openid'];
  56. }
  57. public function setOpenId($openId) {
  58. $this->member_info['member_openid'] = $openId;
  59. model('mbusertoken')->editMemberOpenId($this->member_info['member_token'], $openId);
  60. }
  61. }
  62. ?>