https://blog.csdn.net/qq19124152/article/details/81012150
模版修改位置:
addons/ewei_shopv2/template/mobile/default/_share.html
代碼:
wx.onMenuShareTimeline({
{php echo tttaddshare(json_encode($_W['shopshare']))}, // 分享內容
success: function () {
// 用戶確認分享后執行的回調函數
var url = "{php echo mobileUrl('member/addshare', array('ctype'=>fenxiangok))}";
$.post(url, function(dat){
//alert(2);
});
},
cancel: function () {
// 用戶取消分享后執行的回調函數
}
});
添加一個函數用於去掉分享代碼的大括號,
位置:addons\ewei_shopv2\core\inc\functions.php
function tttaddshare($str)
{
$str=trim($str,'{');
$str=trim($str,'}');
return $str;
}
然后在 addons\ewei_shopv2\core\mobile\member\addshare.php 這個文件是新建的
$openid = $_W['openid'];
$uniacid = $_W['uniacid'];
$member = m('member')->getMember($openid);
if ($_GPC['ctype']=='fenxiangok') { //這個判斷沒亂用只是為了不讓人隨便訪問到而已。
if (empty($member)) {
exit();
}
$time=date('Y-m-d',time());
$logrow = pdo_fetch('select * from ' . tablename('ewei_shop_addshare_log') . ' where openid=:openid and uniacid=:uniacid limit 1', array(':openid' => $openid,':uniacid' => $_W['uniacid']));
//上面這個表是新建的,為了統計分享數量,並且限制每個人每天只能獲得一次分享得到積分的機會
if(strtotime($time)>$logrow['createtime']){
$log = array('uniacid' => $_W['uniacid'],'openid' => $openid, 'createtime' => strtotime($time));
pdo_insert('ewei_shop_addshare_log', $log);
m('member')->setCredit($openid, 'credit2', 1, array(0, '分享贈送積分+1'));
exit();
}
}
數據表:
DROP TABLE IF EXISTS `ims_ewei_shop_addshare_log`;
CREATE TABLE `ims_ewei_shop_addshare_log` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`uniacid` int(10) NOT NULL,
`createtime` int(11) DEFAULT NULL,
`openid` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
因為自己在項目中用到了這塊,所以特意記錄了下來,希望看到的人能夠幫助你。
如果有更多問題可以聯系的QQ。就是我用戶名,
---------------------
作者:qq19124152
來源:CSDN
原文:https://blog.csdn.net/qq19124152/article/details/81012150
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!