def add_step_by(self, stepnum, **kwargs): self.check_upgrade() if not hasattr(self, '_steps'): self._steps = json.loads(self.step_detail) self._steps['step_' + str(stepnum)] = kwargs self.step_detail = json.dumps(self._steps, cls=DjangoJSONEncoder) self.update_time = msec_time()
def _smscaptcha_verify(phone, captcha): cap = Smscaptcha.objects.filter(phone=phone) if (not cap) or (cap[0].captcha != captcha) or \ (msec_time() > cap[0].create_time + Const['sms.valid.time'] * Const['const.msperminute']): return False else: return True
def smscaptcha_request(r, phone): # 校验验证码 if r.c_type == Const['model.device.pc']: rand_code = r.REQUEST['rand_code'] # rand_code_arr = ['X3NC', '4MPQ', '8FAE', 'YG9H', 'MYAV', '2B7Q', '83EJ', 'HE4S', 'GAWQ', 'RWTU'] # if not rand_code_arr[int(rand_pic)] == rand_code: # return JsonResponse(code=Const['code.system_error'], msg='请输入正确验证码') if not r.session['randcode'] == rand_code.lower(): return JsonResponse(code=Const['code.system_error'], msg='请输入正确验证码') capt = str(randint(100000, 999999)) nowtime = msec_time() if phone in [13586280698]: return JsonResponse(code=Const['code.request_error']) try: s = Smscaptcha.objects.get(phone=phone) s.create_time = nowtime s.captcha = capt s.save() except ObjectDoesNotExist: s = Smscaptcha.objects.create(phone=phone, captcha=capt, create_time=nowtime) result = SMSService.sendTemplateSMS(phone, [capt, Const['sms.valid.time']], 133993) if (result['statusCode'] == '000000'): return JsonResponse(code=Const['code.success']) else: logger.error(result) return JsonResponse(code=Const['code.system_error'], msg='发送短信验证码失败')
def add_general_progress(self, source, content, **progress_detail): if source not in Appeal.avaliable_sources: return False progress_detail['create_time'] = msec_time() progress_detail['source'] = source progress_detail['content'] = content self._add_progress(**progress_detail) return True
def notice_modify(r, nid): notice = Notice.objects.get(pk=nid) conditions = make_conditions(r, content='content', url='url', pic_path='pic_path', important='important') if 'important' in conditions: conditions['important'] = bool(int(conditions['important'])) conditions['update_time'] = msec_time() obj_modify(notice, conditions) notice.save() return JsonResponse(code=Const['code.success'])
def user_award(r, uid): user = User.objects.get(pk=uid) now = msec_time() last = user.last_award_time if (not last) or (get_date_by_stamp(now) != get_date_by_stamp(last)): award = random.uniform(Const['min.award'], Const['max.award']) user.money_operate(Const['model.record.commission'], award, '签到奖励', Const['model.record.category.signup']) user.last_award_time = now user.save() return JsonResponse(code=Const['code.success'], data={'award': award}) else: return JsonResponse(code=Const['code.award.already.receive'])
def user_qninfo(self): global qiniu, qiniu_token, qiniu_expires now = msec_time() if now > qiniu_expires: logger.debug('qiniu token reflush') qiniu_token = qiniu.upload_token(Const['qiniu.workspace'], None, Const['qiniu.maxage']) qiniu_expires = now + 1000 * (Const['qiniu.maxage'] - Const['qiniu.safe']) return JsonResponse(code=Const['code.success'], data={ 'token': qiniu_token, 'expires': qiniu_expires, 'domain': Const['qiniu.domain'], })
def bankcard_withdraw(r, bid): params = r.REQUEST bankcard = Bankcard.objects.get(pk=bid) user = bankcard.user if params['password'] != user.password: return JsonResponse(code=Const['code.password_error']) timestamp = msec_time() - 24 * Const['ms.per.hour'] logger.info(timestamp) if Withdraw.objects.filter(bankcard_id=bid).filter( Q(verify_time__gte=timestamp) | Q(verify_time=None)).count() > 0: return JsonResponse(code=Const['code.request_error'], msg=u'距离上次提现成功小于24小时') amount = Decimal(params['amount']) if amount <= 0: return if 'type' in params and params['type'] == '0': ret = user.money_operatesafe( Const['model.record.pricipal'], -amount, '本金提现', Const['model.record.category.principalwithdraw']) rew = reward(amount, type=0) if ret < 0: return JsonResponse(code=Const['code.amount.exceed'], msg=u"余额不足") Withdraw.objects.create(bankcard=bankcard, amount=amount, reward=rew, type=Const['model.withdraw.type.principal']) else: ret = user.money_operatesafe( Const['model.record.commission'], -amount, '佣金提现', Const['model.record.category.commissionwithdraw']) rew = reward(amount, type=1) if ret < 0: return JsonResponse(code=Const['code.amount.exceed']) Withdraw.objects.create(bankcard=bankcard, amount=amount, reward=rew, type=Const['model.withdraw.type.commission']) # user.money_operate(Const['model.record.commission'], # -amount, # '佣金提现', # Const['model.record.category.commissionwithdraw']) return JsonResponse(code=Const['code.success'])
def smscaptcha_request(request, phone): capt = str(randint(100000, 999999)) nowtime = msec_time() try: r = Smscaptcha.objects.get(phone=phone) r.create_time = nowtime r.captcha = capt r.save() except ObjectDoesNotExist: r = Smscaptcha.objects.create(phone=phone, captcha=capt, create_time=nowtime) result = SMSService.sendTemplateSMS(phone, [capt, Const['sms.valid.time']], 89306) if (result['statusCode'] == '000000'): return JsonResponse(code=Const['code.success']) else: logger.error(result) return JsonResponse(code=Const['code.system_error'])
def order_manage(): logger.info('order_manage start') nowtime = msec_time() #自动返款 orders = Order.objects.filter( status=Const['model.order.status.step3'], receive_time__lte=nowtime - 12 * Const['ms.per.hour'], #这里应该是12小时的,测试环境下的 task__return_type=Const['model.task.return_type.platform']).exclude( frozen=True) #logger.debug(orders.query) counter = 0 for o in orders: if _order_returndeliver(o): with transaction.atomic(): counter = counter + 1 o.save() # 避免刷手提交资金和商家的商品资金不同的情况 order_auto_returndeliver(o) # 原来的情况 # o.tb.user.money_operate(Const['model.record.pricipal'], # o.buyer_principal,'订单本金归还,订单编号:%d'%o.id, # Const['model.record.category.principalreturn']) logger.info('自动还款数:%d' % counter) # 自动取消订单 counter = 0 orders = Order.objects.filter( status=Const['model.order.status.received'], task__prepublish=False, receive_time__lte=nowtime - 2 * Const['ms.per.hour'], ).exclude(frozen=True) for o in orders: order = Order.objects.get(pk=o.id) if order.status == Const['model.order.status.received']: with transaction.atomic(): counter = counter + 1 order.tb.user.money_operate( Const['model.record.commission'], Decimal(-1) if order.is_buy_order() else Decimal(-0.3), '取消订单惩罚,订单:%d' % order.id) if order.is_buy_order(): StoreRecentBuyer.objects.filter( tb_id=order.tb_id, store_id=order.task.store_id, type=Const['model.ordergtype.comment']).delete() order.tb.today_receive_orders = order.tb.today_receive_orders - 1 order.tb.save() else: StoreRecentBuyer.objects.filter( tb_id=order.tb_id, store_id=order.task.store_id, type=order.order_type).delete() order.status = Const['model.order.status.init'] order.tb = None order.receive_time = None order.step_detail = '{}' order.save() logger.info('自动取消订单数:%d' % counter) #自动确认订单 counter = 0 orders = Order.objects.filter( status=Const['model.order.status.comment'], update_time__lte=nowtime - 2 * Const['ms.per.hour']).exclude(frozen=True) for o in orders: if _order_affirm(o.id): counter = counter + 1 logger.info('自动确认订单数:%d' % counter) logger.info('order_manage end')
def is_new(self): nowms = msec_time() if (nowms - self.create_time) < Const['notice.new.timedelta']: return True else: return False