public function _initialize() { if (SERVER_ENVIRONMENT == 'LOCAL_HOST') { session('openid', 'oZcK7wtW4NB-hr5I1_XKKfoC6zV8'); //测试openid } if (ACTION_NAME != 'notifyurl') { //支付通知--过滤掉 if (!session('openid')) { $this->_session_openid(); } } $weobj = wechatInstance(); $signature = $weobj->getJsSign(currentUrl(), time(), md5(rand(1, 9999)), C('WECHAT_APPID')); $signature['jsApiList'] = ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone']; $this->assign('signature', str_replace("\\/", "/", json_encode($signature))); $sharetitle = getSysConfig('share-title'); $sharedesc = getSysConfig('share-desc'); $shareimgUrl = getSysConfig('share-imgUrl'); $sharelink = getSysConfig('share-link'); $this->assign('sharetitle', $sharetitle); $this->assign('sharedesc', $sharedesc); $this->assign('shareimgUrl', $shareimgUrl); $this->assign('inviteurl', domainurl() . UC($sharelink, array('invate' => getOpenid()))); }
public function releaseShareCouponAct() { if (IS_POST) { $openid = getOpenid(); \Wechat\Logic\CouponLogic::publicShareCoupon($openid); return true; } return false; }
public function makeOrder($postData) { S('orderticketname_' . getOpenid(), $postData['ticketname2'], 3600); S('orderareaname_' . getOpenid(), $postData['areaname'], 3600); unset($postData['ticketname2']); unset($postData['areaname']); $array['sn'] = time() . rand(100000, 999999); $array['open_id'] = session('openid'); $array['total_cost'] = $postData['price']; $array['add_time'] = time(); $array['status'] = 0; $array['third_party_pay'] = $postData['price']; $order_id = $this->add($array); if ($order_id) { $data = D('TicketOrderDetail')->makeDetail($postData, $order_id); return $order_id; } else { return false; } }
public function receiveAct() { $activity_id = I('get.id'); $nowtime = time(); $couponlist = D('activity_coupon')->where("activity_id={$activity_id} and stime<{$nowtime} and etime>{$nowtime}")->select(); foreach ($couponlist as $coupon) { $isexist = D('user_activitycoupon')->where(array('open_id' => getOpenid(), 'activitycoupon_id' => $coupon['id']))->find(); if ($isexist) { continue; } $info['open_id'] = getOpenid(); $info['activitycoupon_id'] = $coupon['id']; $info['ctime'] = $nowtime; $info['status'] = 0; D('user_activitycoupon')->add($info); //小提示 \Wechat\Logic\CouponLogic::ticketTip(getOpenid()); } //设置提示 \Wechat\Logic\PushLogic::pushTextMsg(getOpenid(), getSysConfig('coupon-text')); redirect(UC('/Wechat/Coupon/index'), 0, '页面跳转中...'); }
public function reciveCouponAct() { $openid = getOpenid(); $invate = I('get.invate'); $userinfo = \Wechat\Logic\UserLogic::getUserinfo($openid); $this->assign('userinfo', $userinfo); //先领分享优惠券,然后判断是否已经领取了新人优惠券 \Wechat\Logic\CouponLogic::receviceShareCoupon($openid, $invate); $receviCount = \Wechat\Logic\CouponLogic::countCoupon($openid, NewerCouponID); if ($receviCount > 0) { redirect('/Wechat/Coupon/index', 0, '页面跳转中...'); return; } //再领新人优惠券 if (IS_POST) { $phone = I('post.phone'); if (preg_match("/1[3458]{1}\\d{9}\$/", $phone)) { if ($openid == $invate) { $this->assign("msg", "本人不可领取"); } else { \Wechat\Logic\UserLogic::updateByOpenid($openid, array('phone' => $phone, 'inviter' => $invate)); //赠送优惠券 \Wechat\Logic\CouponLogic::giveCoupon($openid, NewerCouponID); //给本人 \Wechat\Logic\CouponLogic::giveCoupon($invate, InviteCouponID1); //给推荐者 $username = D('User')->where(array('open_id' => $openid))->getField('nickname'); $invatename = D('User')->where(array('open_id' => $invate))->getField('nickname'); \Wechat\Logic\PushLogic::pushTextMsg($invate, "非常感谢您的分享,您的好友@" . $username . "成功领取了一张魔乐城优惠劵。"); \Wechat\Logic\PushLogic::pushTextMsg($openid, getSysConfig('coupon-text')); redirect('/Wechat/Coupon/index', 0, '页面跳转中...'); return; } } else { $this->assign("msg", "手机号码填写不正确"); } } $this->display(); }
public function testAllCouponAct() { echo getOpenid(); $dd = \Wechat\Logic\CouponLogic::getAllCoupon(getOpenid()); print_r($dd); }
public function index() { $wechat_url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]; $this->load->helper('mobile'); if (is_weixin()) { if (!$this->customer->isLogged()) { if ($this->config->get('weixin_login_status')) { if ($this->config->get('wxpay_status')) { if (isset($this->session->data['weixin_login_openid']) && isset($this->session->data['weixin_login_unionid'])) { if (isset($this->session->data['weixin_logout_status'])) { if ($this->session->data['weixin_logout_status'] == 0) { if ($this->customer->login_weixin($this->session->data['weixin_login_unionid'])) { unset($this->session->data['guest']); // Default Shipping Address $this->load->model('account/address'); if ($this->config->get('config_tax_customer') == 'payment') { $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); } if ($this->config->get('config_tax_customer') == 'shipping') { $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); } } else { } } } else { if ($this->customer->login_weixin($this->session->data['weixin_login_unionid'])) { unset($this->session->data['guest']); // Default Shipping Address $this->load->model('account/address'); if ($this->config->get('config_tax_customer') == 'payment') { $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); } if ($this->config->get('config_tax_customer') == 'shipping') { $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); } $this->response->redirect($wechat_url); } else { } } } elseif (isset($this->request->get['code'])) { $appid = $this->config->get('wxpay_appid'); $appsecret = $this->config->get('wxpay_appsecret'); $openid_result = getOpenid($appid, $appsecret, $this->request->get['code']); $unionid_result = getWeiXinUserInfo($appid, $appsecret, $openid_result['openid']); if ($openid_result && $unionid_result) { $this->session->data['weixin_login_openid'] = $openid_result['openid']; $this->session->data['weixin_openid'] = $openid_result['openid']; $this->session->data['weixin_login_unionid'] = $unionid_result['unionid']; } else { $this->session->data['weixin_login_openid'] = ''; $this->session->data['weixin_openid'] = ''; $this->session->data['weixin_login_unionid'] = ''; } header('Location: ' . $wechat_url); } else { $appid = $this->config->get('wxpay_appid'); header('Location: https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $appid . '&redirect_uri=' . $wechat_url . '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'); } } } else { //if weixin login disabled if ($this->config->get('wxpay_status')) { if (isset($this->session->data['weixin_login_openid'])) { } elseif (isset($this->request->get['code'])) { $appid = $this->config->get('wxpay_appid'); $appsecret = $this->config->get('wxpay_appsecret'); $openid_result = getOpenid($appid, $appsecret, $this->request->get['code']); $this->session->data['weixin_login_openid'] = ''; $this->session->data['weixin_openid'] = $openid_result['openid']; $this->session->data['weixin_login_unionid'] = ''; } else { $appid = $this->config->get('wxpay_appid'); header('Location: https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $appid . '&redirect_uri=' . $wechat_url . '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'); } } } } } }
public function orderlistAct() { $list = \Wechat\Logic\OrderLogic::getUserOrderList(getOpenid()); $this->assign('list', $list); $this->display(); }
/** * 确认订单 */ public function sureOrderAct() { $openid = session('openid'); $order_id = I('order_id'); if (!$order_id) { $this->error('参数错误!'); } $orderInfo = D('TicketOrder')->getOrderInfo($order_id); if ($orderInfo['coupon_pay'] == 0) { $ticket_type = D('TicketOrderDetail')->where(array('order_id' => $order_id))->getField('ticket_type'); if ($ticket_type != 3 && $ticket_type != 11) { $couponInfo = \Wechat\Logic\CouponLogic::getAllCoupon($openid); $this->assign('couponInfo', $couponInfo); } if ($couponInfo && $orderInfo['third_party_pay'] > $couponInfo[0]['price']) { $orderInfo['third_party_pay'] = $orderInfo['third_party_pay'] - $couponInfo[0]['price']; } elseif ($couponInfo && $orderInfo['third_party_pay'] <= $couponInfo[0]['price']) { $orderInfo['third_party_pay'] = 0; } } $this->assign('orderticketname', S('orderticketname_' . getOpenid())); $this->assign('orderareaname', S('orderareaname_' . getOpenid())); $this->assign('orderInfo', $orderInfo); $this->display(); }