Userhelp.php
4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* 2015-11-21
*/
namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use app\home\model\Message;
use think\Cookie;
use think\Page;
use think\Request;
use think\Session;
use think\Verify;
use think\db;
use think\Cache;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
class Userhelp extends MobileBase
{
public $user_id = 0;
public $user = array();
/*
* 初始化操作
*/
public function _initialize()
{
parent::_initialize();
$sid = I('stoid');
if (session('?user')) {
$user = session('user');
unset($_SESSION['user']);
$user0 = M('users')->where("user_id", $user['user_id'])->where("store_id", $sid)->find();
session('user', $user0); //覆盖session 中的 user
$this->user = $user0;
$this->user_id = $user0['user_id'];
$this->assign('user', $user0); //存储用户信息
} else {
$usrid = Cookie::get('user_id');
if ($usrid) {
$user0 = M('users')->where("user_id", $usrid)->where("store_id", $sid)->find();
session('user', $user0); //覆盖session 中的 user
$this->user = $user0;
$this->user_id = $user0['user_id'];
$this->assign('user', $user0); //存储用户信息
}
}
}
/**-- 助力分享跳转到手店商城--**/
public function index()
{
$stoid = getMobileStoId();
$fid=I("fid");
$act=M("marketing_help_form")->where("id",$fid)->find();
if($act){
//--判断是不是需要关注--
if(strpos($act['help_condition'],'1')!==false){
$gz=M("wx_openlist")->where("wxopenid",$this->user['openid'])->find();
if($gz && !$gz['issubscribe']){
$this->assign("need_gz",1);
}
}
//--判断是不是需要注册--
if(strpos($act['help_condition'],'2')!==false){
if(!$this->user['erpvipid']){
$this->assign("need_zc",1);
}
}
}else{
$this->error("未找到助力活动","/index.php/mobile/index/index/stoid/".$stoid);
}
return $this->fetch('', $stoid);
}
public function create_ewm()
{
$stoid = getMobileStoId();
$weixin_config = M('wx_user')->where('store_id=' . getMobileStoId())->field("appid,appsecret")->find(); //获取微信配置
if (empty($weixin_config)) {
return json(['code' => -1]);
}
$access_token = m_get_access_token($weixin_config);
mlog('关注开始2:', 'create_ewm/' . $stoid);
$url = "";
$return = M('wx_ewmlist')->where(array('store_id' => $stoid, 'scene_id' => ''))->find();
if (empty($return)) {
if ($access_token) {
//获取数据的地址(微信提供)
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token;
//发送给微信服务器的数据
$jsonstr = '{"expire_seconds": 1800, "action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": ""}}}';
$return = httpRequest($url, 'POST', $jsonstr);
mlog('关注二维码返回:' . $return, 'mobileindex/' . $stoid);
$return = json_decode($return, 1);
if (!empty($return['ticket'])) {
$v['ticket'] = $return['ticket'];
$v['store_id'] = $stoid;
$v['scene_id'] = '';
$v['date'] = time();
$v['loadurl'] = $return['url'];
M('wx_ewmlist')->add($v);
$url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $v['ticket'];
mlog('关注二维码生成成功', 'mobileindex/' . $stoid);
} else {
mlog('关注二维码生成失败', 'mobileindex/' . $stoid);
}
} else {
mlog('关注access_token失败', 'mobileindex/' . $stoid);
}
} else {
$url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $return['ticket'];
}
return json(['code' => 1, 'url' => $url]);
}
}