Пример #1
0
def _add_award_to_member(user_profile, award_type, award_content, member,
                         integral_type):
    if award_type:
        if award_type == AWARD_COUPON:
            consume_coupon(user_profile.user.id, award_content, member.id)
        elif award_type == AWARD_INTEGRAL:
            try:
                increase_member_integral(member, award_content, integral_type)
            except:
                notify_msg = u"新推广扫码-微信会员二维码扫描增加积分失败1 cause:\n{}".format(
                    unicode_full_stack())
                watchdog_fatal(notify_msg)
Пример #2
0
def get_consume_coupon(owner_id, app_name, app_id, rule_id, member_id):
	'''

	@param owner_id:
	@param app_name:
	@param app_id:
	@param rule_id:
	@param member_id:
	@param has_coupon_count: 表示在抽奖活动里某个会员获得优惠券的数量
	@return:
	'''
	coupon = None
	curr_coupon_count = 0
	rules = CouponRule.objects.filter(id=rule_id, owner_id=owner_id)
	if rules.count() <= 0:
		coupon_message = u'该优惠券使用期已过,不能领取!'
		return coupon, coupon_message, curr_coupon_count
	rule = rules.first()
	if rule and rule.end_date <= datetime.today():
		coupon_message = u'该优惠券使用期已过,不能领取!'
	else:
		curr_coupon_count = rule.remained_count
		coupon, coupon_message = consume_coupon(owner_id, rule_id, member_id)
		# with transaction.atomic():
		# 	coupon = promotion_models.Coupon.objects.select_for_update().filter(coupon_rule_id=rule_id, member_id=0, status=promotion_models.COUPON_STATUS_UNGOT).first()
		# 	if coupon:
		# 		coupon.status = promotion_models.COUPON_STATUS_UNUSED
		# 		coupon.member_id = member_id
		# 		coupon.provided_time = datetime.today()
		# 		coupon.coupon_record_id = 0
		# 		coupon.save()
        #
		# 		if has_coupon_count:
		# 			rules.update(remained_count=F('remained_count') - 1, get_count=F('get_count') + 1)
		# 		else:
		# 			rules.update(remained_count=F('remained_count') - 1, get_person_count=F('get_person_count') + 1,
		# 						 get_count=F('get_count') + 1)

	data = {
		'user_id': owner_id,
		'app_name': app_name,
		'app_id': app_id,
		'member_id': member_id,
		'coupon_id': coupon.id if coupon else 0,
		'coupon_msg': coupon_message,
		'created_at': datetime.today()
	}
	consume_coupon_log = mongo_models.ConsumeCouponLog(**data)
	consume_coupon_log.save()
	return coupon, coupon_message, curr_coupon_count
Пример #3
0
def update_activity_sign_status(request, sign_code):
	activity_user_code = ActivityUserCode.objects.filter(sign_code=sign_code)
	activity_user_code.update(sign_status=1)
	if activity_user_code:
		activity = activity_user_code[0].activity
		member_id = int(request.GET.get('member_id', -1))
		member = member_module_api.get_member_by_id(member_id)
		if member:
			#给予奖励
			#无奖励
			if activity.prize_type == -1:
				pass
			#优惠券
			elif activity.prize_type == 1:
				rule_id = activity.prize_source
				# coupons = create_coupons(activity.owner, rule_id, 1, member.id)
				consume_coupon(activity.owner.id, rule_id, member.id)
			#积分
			elif activity.prize_type == 3:
				prize_detail = activity.prize_source
				#增加积分
				member.consume_integral(-int(prize_detail), u'参加获得,获得积分')
	return HttpResponseRedirect(request.META['HTTP_REFERER'])
Пример #4
0
def join_research(request):
    member = request.member
    webapp_user = request.webapp_user
    research_id = request.POST['research_id']

    try:
        research = Research.objects.get(id=research_id)
    except:
        response = create_response(500)
        response.errMsg = u'该调研不存在'
        response.innerErrMsg = full_stack()
        return response.get_response()

    username = ''
    phone_number = ''
    if request.POST:
        try:
            items = ResearchItem.objects.filter(research=research)
            for item in items:
                input_name = '{}-{}'.format(item.id, item.type)
                if item.type == RESEARCHITEM_TYPE_IMAGE:
                    file = request.POST[input_name]
                    if file:
                        value = save_base64_img_file_local_for_webapp(
                            request, file)
                    else:
                        value = ''
                else:
                    value = request.POST.get(input_name, '')

                if item.title == u'姓名':
                    username = value
                if item.title == u'手机号':
                    phone_number = value

                ResearchItemValue.objects.create(
                    owner_id=request.webapp_owner_id,
                    item=item,
                    research=research,
                    webapp_user=webapp_user,
                    value=value)

            if member:
                try:
                    member.update_member_info(username, phone_number)
                except:
                    #不同步到会员
                    pass

                #给予奖励
                #无奖励
                if research.prize_type == -1:
                    pass
                #优惠券
                elif research.prize_type == 1:
                    rule_id = research.prize_source
                    # coupons = create_coupons(research.owner, rule_id, 1, member.id)
                    consume_coupon(research.owner.id, rule_id, member.id)
                #积分
                elif research.prize_type == 3:
                    prize_detail = research.prize_source
                    #增加积分
                    member.consume_integral(-int(prize_detail), u'参与调研,获得积分')

            response = create_response(200)
        except:
            response = create_response(500)
            response.errMsg = u'提交错误'
            response.innerErrMsg = full_stack()
            return response.get_response()
    else:
        response = create_response(500)
        response.errMsg = u'is not POST method'

    return response.get_response()
Пример #5
0
def __record_prize(webapp_user, lottery, member, prize, prize_position=0):
    prize_money = 0

    #减积分
    if lottery.expend_integral > 0:
        if webapp_user.integral_info['count'] > lottery.expend_integral:
            expend_integral = lottery.expend_integral
        else:
            expend_integral = webapp_user.integral_info['count']
        webapp_user.consume_integral(expend_integral, u'参与抽奖,花费积分')

    if not prize:
        LotteryRecord.objects.create(owner=lottery.owner,
                                     member=member,
                                     lottery=lottery,
                                     lottery_name=lottery.name,
                                     prize_type=0,
                                     prize_level=0,
                                     prize_name=u'谢谢参与',
                                     is_awarded=True,
                                     prize_number=time.time(),
                                     prize_detail='',
                                     prize_money=prize_money)

        return None

    relation = LotteryHasPrize.objects.get(lottery=lottery, prize=prize)

    #实物
    if relation.prize_type == 0:
        is_awarded = False
        prize_detail = relation.prize_source
    #优惠券
    elif relation.prize_type == 1:
        is_awarded = True
        rule_id = relation.prize_source
        # coupons = create_coupons(lottery.owner, rule_id, 1, member.id)
        # prize_detail = coupons.coupon_id
        # prize_money = coupons[0].money
        coupon, msg = consume_coupon(lottery.owner.id, rule_id, member.id)
        if coupon:
            prize_detail = coupon.coupon_id
            prize_money = coupon.money
        else:
            watchdog_notice(
                '微信抽奖失败,错误原因:%s,owner.id:%s:rule.id:%s,member.id:%s' %
                (msg, lottery.owner.id, rule_id, member.id),
                type="mall")
            LotteryRecord.objects.create(owner=lottery.owner,
                                         member=member,
                                         lottery=lottery,
                                         lottery_name=lottery.name,
                                         prize_type=0,
                                         prize_level=0,
                                         prize_name=u'谢谢参与',
                                         is_awarded=True,
                                         prize_number=time.time(),
                                         prize_detail='',
                                         prize_money=prize_money)
            return None
    #兑换码
    elif relation.prize_type == 2:
        is_awarded = True
        prize_detail = relation.prize_source
    #积分
    elif relation.prize_type == 3:
        is_awarded = True
        prize_detail = relation.prize_source
        #增加积分
        webapp_user.consume_integral(-int(prize_detail), u'参与抽奖,赢得积分')

    from hashlib import md5
    cur_time = str(time.time())
    prize_number = md5(cur_time).hexdigest()[10:-10]  #生成一个12位字符串

    LotteryRecord.objects.create(owner=lottery.owner,
                                 member=member,
                                 lottery=lottery,
                                 lottery_name=lottery.name,
                                 prize_type=relation.prize_type,
                                 prize_level=prize.level,
                                 prize_name=prize.name,
                                 is_awarded=is_awarded,
                                 prize_number=prize_number,
                                 prize_detail=prize_detail,
                                 prize_money=prize_money,
                                 prize_position=prize_position)

    #更改奖品个数
    Prize.decrease_count(prize, 1)

    return prize
Пример #6
0
def join_activity(request):
    weapp_user = request.webapp_user
    member = weapp_user.get_member_by_webapp_user_id(weapp_user.id)
    activity_id = request.POST['activity_id']

    try:
        activity = Activity.objects.get(id=activity_id)
    except:
        response = create_response(500)
        response.errMsg = u'该活动不存在'
        response.innerErrMsg = full_stack()
        return response.get_response()

    if not activity.is_non_member:
        if member is None:
            response = create_response(500)
            response.errMsg = u'您还不是会员'
            return response.get_response()

    username = ''
    phone_number = ''
    if request.POST:
        try:
            response = create_response(200)
            if activity.is_enable_offline_sign:
                sign_code = _create_activity_sign_code(request.webapp_user.id,
                                                       activity.id)
                ActivityUserCode.objects.create(
                    owner_id=request.webapp_owner_id,
                    activity=activity,
                    webapp_user_id=weapp_user.id,
                    sign_code=sign_code)
                response.data.sign_code = sign_code
            items = ActivityItem.objects.filter(activity=activity)
            for item in items:
                input_name = '{}-{}'.format(item.id, item.type)
                if item.type == ACTIVITYITEM_TYPE_IMAGE:
                    file = request.POST[input_name]
                    if file:
                        value = save_base64_img_file_local_for_webapp(
                            request, file)
                    else:
                        value = ''
                else:
                    value = request.POST.get(input_name, '')

                if item.title == u'姓名':
                    username = value
                if item.title == u'手机号':
                    phone_number = value

                ActivityItemValue.objects.create(
                    owner_id=request.webapp_owner_id,
                    webapp_user_id=weapp_user.id,
                    item=item,
                    activity=activity,
                    value=value)
            try:
                #是否开启线下签到
                is_enable_offline_sign = activity.is_enable_offline_sign
                if not is_enable_offline_sign and member:
                    member.update_member_info(username, phone_number)
                    #给予奖励
                    #无奖励
                    if activity.prize_type == -1:
                        pass
                    #优惠券
                    elif activity.prize_type == 1:
                        rule_id = activity.prize_source
                        # coupons = create_coupons(activity.owner, rule_id, 1, member.id)
                        consume_coupon(activity.owner.id, rule_id, member.id)
                    #积分
                    elif activity.prize_type == 3:
                        prize_detail = activity.prize_source
                        #增加积分
                        member.consume_integral(-int(prize_detail),
                                                u'参加活动,获得积分')
            except:
                ActivityItemValue.objects.filter(
                    owner_id=request.webapp_owner_id,
                    activity=activity,
                    webapp_user_id=weapp_user.id).delete()
                ActivityUserCode.objects.filter(
                    owner_id=request.webapp_owner_id,
                    activity=activity,
                    webapp_user_id=weapp_user.id,
                ).delete()
                raise IOError
        except:
            notify_msg = u"活动报名失败, cause:\n{}".format(unicode_full_stack())
            watchdog_fatal(notify_msg)
            response = create_response(500)
            response.errMsg = u'提交错误'
            response.innerErrMsg = full_stack()
            return response.get_response()
    else:
        response = create_response(500)
        response.errMsg = u'is not POST method'

    return response.get_response()
Пример #7
0
	def handle(self, context, is_from_simulator=False):
		message = context.message

		if message.is_optimization_message:
			print 'ChannelDistributionQrcodeHandler only handle is_optimization_message = true'
			return None

		username = message.fromUserName
		user_profile = context.user_profile
		member = context.member

		if not hasattr(context.message, 'event'):
			return None

		if not hasattr(context.message, 'ticket') or context.message.ticket is None:
			return None
		ticket = context.message.ticket

		if not hasattr(context.message, 'eventKey') or context.message.eventKey is None or ticket == '':
			return None

		if member and (hasattr(member, 'is_new') is False):
			member.is_new = False

		#优化处理
		if hasattr(context, 'is_member_qrcode') and (context.is_member_qrcode is True):
			return None

		# 一 将信息添加到ChannelDistributionQrcodeHasMember中
		# 二 将扫码的会员添加到新分组中
		channel_distribution_qrcode_has_member = ChannelDistributionQrcodeHasMember.objects.filter(member_id=member.id)
		if channel_distribution_qrcode_has_member:  # 如果这个会员已经绑定到别人的二维码下:
			return None
		else:
			qrcode = ChannelDistributionQrcodeSettings.objects.filter(ticket=ticket)  # 得到ticket绑定的二维码数据
			if qrcode:
				ChannelDistributionQrcodeHasMember.objects.create(
					channel_qrcode_id = qrcode[0].id,
					member_id = member.id,
				)
				qrcode.update(bing_member_count = F('bing_member_count') + 1)
				# 得到需要绑定的member分组
				group_id = qrcode[0].group_id
				# 添加到得到的分组
				MemberHasTag.add_tag_member_relation(member, [group_id])
				# 发放优惠券
				award_prize_info = json.loads(qrcode[0].award_prize_info)
				if award_prize_info['type'] == u"优惠券":
					coupon_id = award_prize_info['id']  # 优惠券id
					consume_coupon(qrcode[0].owner.id, coupon_id, member.id)
				elif award_prize_info['type'] == u"积分":
					# 发放积分
					award = award_prize_info['id']  # 扫码奖励积分
					increase_member_integral(member, award, u'推荐扫码奖励')

				# 扫码回复
				msg_type, detail = get_response_msg_info_restructure(qrcode[0], user_profile)
				if msg_type != None:
					# from_weixin_user = self._get_from_weixin_user(message)
					# token = self._get_token_for_weixin_user(user_profile, from_weixin_user, is_from_simulator)
					if msg_type == 'text' and detail:
						if is_from_simulator:
							return generator.get_text_response(username, message.toUserName,
								emotion.change_emotion_to_img(detail), username,
								user_profile)
						else:
							return generator.get_text_response(username, message.toUserName, detail, username,
															   user_profile)
					if msg_type == 'news' and get_material_news_info(detail):
						news = get_material_news_info(detail)
						return generator.get_news_response(username, message.toUserName, news, username)
				else:
					return None
			else:
				return None
		return None
Пример #8
0
def __record_prize(webapp_user, red_envelope, prize, member, prize_position=0):
    prize_money = 0
    webapp_user_id = -1
    if webapp_user:
        webapp_user_id = webapp_user.id
    if not prize:
        return RedEnvelopeRecord.objects.create(
            owner=red_envelope.owner,
            red_envelope=red_envelope,
            red_envelope_name=red_envelope.name,
            prize_type=-1,
            prize_level=0,
            prize_name=u'红包领光了,您来晚了!',
            prize_number=time.time(),
            prize_detail='',
            prize_money=prize_money,
            webapp_user_id=webapp_user_id)

    relation = RedEnvelopeHasPrize.objects.get(red_envelope=red_envelope,
                                               prize=prize)

    if member is None and relation.prize_type != 1:
        return RedEnvelopeRecord.objects.create(
            owner=red_envelope.owner,
            red_envelope=red_envelope,
            red_envelope_name=red_envelope.name,
            prize_type=-1,
            prize_level=0,
            prize_name=u'谢谢参与',
            prize_number=time.time(),
            prize_detail='',
            prize_money=prize_money,
            webapp_user_id=webapp_user_id)

    #实物
    if relation.prize_type == 0:
        is_awarded = False
        prize_detail = relation.prize_source
    #优惠券
    elif relation.prize_type == 1:
        is_awarded = True
        rule_id = relation.prize_source
        # coupons = create_coupons(red_envelope.owner, rule_id, 1, member.id)
        # prize_detail = coupons[0].coupon_id
        # prize_money = coupons[0].money
        coupon, msg = consume_coupon(red_envelope.owner.id, rule_id, member.id)
        if coupon:
            prize_detail = coupon.coupon_id
            prize_money = coupon.money
        else:
            watchdog_notice(
                '红包领取失败,错误原因:%s,owner.id:%s:rule.id:%s,member.id:%s' %
                (msg, red_envelope.owner.id, rule_id, member.id),
                type="mall")
            return RedEnvelopeRecord.objects.create(
                owner=red_envelope.owner,
                red_envelope=red_envelope,
                red_envelope_name=red_envelope.name,
                prize_type=-1,
                prize_level=0,
                prize_name=u'谢谢参与',
                prize_number=time.time(),
                prize_detail='',
                prize_money=prize_money,
                webapp_user_id=webapp_user_id)
    #兑换码
    elif relation.prize_type == 2:
        is_awarded = True
        prize_detail = relation.prize_source
    #积分
    elif relation.prize_type == 3:
        is_awarded = True
        prize_detail = relation.prize_source
        #增加积分
        webapp_user.consume_integral(-int(prize_detail), u'红包积分')

    from hashlib import md5
    cur_time = str(time.time())
    prize_number = md5(cur_time).hexdigest()[10:-10]  #生成一个12位字符串

    red_envelope_record = RedEnvelopeRecord.objects.create(
        owner=red_envelope.owner,
        webapp_user_id=webapp_user_id,
        red_envelope=red_envelope,
        red_envelope_name=red_envelope.name,
        prize_type=relation.prize_type,
        prize_level=prize.level,
        prize_name=prize.name,
        prize_number=prize_number,
        prize_detail=prize_detail,
        prize_money=prize_money,
        prize_position=prize_position,
        is_awarded=is_awarded)

    #更改奖品个数
    Prize.decrease_count(prize, 1)

    return red_envelope_record