def post(self): coupon_sn = self.get_argument('coupon_sn', '') if not coupon_sn: self.write({'error': '券号为空'}) return coupon = self.db.get( 'select i.*, c.* from item i, item_coupon c where i.id=c.item_id and c.sn=%s', coupon_sn) if not coupon: self.write({'error': '电子券不存在'}) return if not datetime.now() < coupon.expire_at: self.write({'error': '过期电子券不能重发'}) return if not coupon.mobile: self.write({'error': '手机号码为空,发送失败'}) return if not coupon.sms_sent_count < 10: self.write({'error': '发送次数超过10次限制'}) return if not can_send_by_operator(self.db, coupon): self.write({'error': '电子券当前状态不能执行重发操作'}) return CouponSMSMessage(self.db, self.redis, coupon=coupon).remark('运营后台重发短信').operator( self.current_user.name).send()
def get(self, id): # 券信息 coupon = self.db.get( 'select i.*, c.*, c.id as cid, d.name as distributor_shop_name, d.distributor_name from ' 'item i, item_coupon c, distributor_shop d ' 'where c.id=%s and i.id=c.item_id and d.id = i.distr_shop_id', long(id)) # 券验证操作信息 verify_coupon = self.db.query( 'select * from journal where iid= %s and type=2 order by id desc', coupon.cid) # 重发短信要求:为消费的或者已消费的导入券, 并且未过期的,并且有手机号(去除导出券)的, 并且没超过发送次数限制10次的 resend = can_send_by_operator(self.db, coupon) and datetime.now( ) < coupon.expire_at and coupon.mobile and coupon.sms_sent_count < 10 self.render('coupon/detail.html', coupon=coupon, verify_coupon=verify_coupon, resend=resend)