public function vip_home() { $vipinfo = $this->getViplist(); $uid = session('user_auth.uid'); $this->assign('nickname', $vipinfo[0]); $this->assign('Title', '我的积分'); $this->assign('score', Credits::getUserCredits($uid)); $this->assign('name', $vipinfo[1]); $this->assign('progress', $vipinfo[3]); self::setHeader(true); $this->display(); }
public function gethongbao() { $this->is_login(); $userinfo = session('P'); //读取微信红包领取配置 $wxpay_config = $this->ag_hongbao_config(); //是否限制红包兑换 if (empty($wxpay_config['hb_dh_auth'])) { $this->error('亲,暂时无法领取红包~'); } $wxpay_user_score = $wxpay_config['hb_leiji'][$userinfo['cate_group']]; //用户组是否可以领红包 if (empty($wxpay_user_score)) { $this->error('亲,您所在的用户组暂时无法领取红包~'); } //兑换比例因子 $id = I('get.id'); $time = time(); $map['start_time'] = array('lt', $time); $map['end_time'] = array('gt', $time); $map['credits'] = array('gt', 1); $map['status'] = 1; $map['id'] = $id; $info = M('wxpay_hongbao')->where($map)->find(); //判断今日红包兑换面值是否超过 $nowdate = strtotime(date('Y-m-d')); $oldmap['create_time'] = array('egt', $nowdate); $oldmap['userid'] = $userinfo['id']; $all_value = M('wxpay_userhongbao')->where($oldmap)->field('hb_value')->sum('hb_value'); $now_value = $info['value'] + $all_value; if ($wxpay_user_score < $now_value) { $this->error('亲,改天再来吧,您今天兑换面值已经超过咯~'); } $socre = Credits::getUserCredits($userinfo['id']); $socre = empty($socre) ? 0 : $socre; //兑换积分 if (!empty($info) && $info['credits'] <= $socre) { $nowscore = $socre - $info['credits']; $data['userid'] = $userinfo['id']; $data['hongbaoid'] = $info['id']; //获取红包详情 $data['hb_star'] = $info['start_time']; $data['hb_end'] = $info['end_time']; $data['hb_title'] = $info['title']; $data['hb_pic'] = $info['img']; $data['hb_value'] = $info['value']; $data['type'] = '1'; $data['create_time'] = time(); $data['status'] = 1; //TODO 统一积分接口 api('Wxuser/update_info_id', array('id' => $userinfo['id'], 'data' => array('score' => $nowscore))); M('wxpay_userhongbao')->add($data); $this->success('恭喜您,兑换红包成功', U('hongbaoprofile', array('status' => 1))); } else { $this->error('该红包已经过期咯~'); } }