Esempio n. 1
0
 def post(self):
     notify = PaymentNotify()
     notify.content = self.request.body
     notify.notify_time = int(time.time())
     notify.notify_type = 2
     notify.payment = 2
     notify.function_type = 1
     notify.save()
     notify_data = Notify_pub()
     notify_data.saveData(self.request.body)
     ps = notify_data.getData()
     if notify_data.checkSign():
         if ps['return_code'] == 'SUCCESS' and ps[
                 'result_code'] == 'SUCCESS':
             create_msg(
                 simplejson.dumps({
                     'payment': 2,
                     'order_id': ps['out_trade_no']
                 }), 'recharge')
             if MoneyRecord.select().where(
                     MoneyRecord.in_num ==
                     ps['transaction_id']).count() > 0:
                 logging.error(u'微信重复回调:order_id:%s in_num:%s' %
                               (ps['out_trade_no'], ps['transaction_id']))
             else:
                 recharge(ps['out_trade_no'], ps['transaction_id'],
                          float(ps['total_fee']) / 100, u'微信')
             notify_data.setReturnParameter('return_code', 'SUCCESS')
         else:
             logging.info(u'微信通知支付失败')
     else:
         logging.info(u'微信通知验证失败')
     self.write(notify_data.returnXml())
Esempio n. 2
0
 def post(self):
     notify = PaymentNotify()
     notify.content = self.request.body
     notify.notify_time = int(time.time())
     notify.notify_type = 2
     notify.payment = 1
     notify.function_type = 1
     notify.save()
     msg = "fail"
     params = {}
     ks = self.request.arguments.keys()
     for k in ks:
         params[k] = self.get_argument(k)
     ps = notify_verify(params)
     if ps:
         if ps['trade_status'].upper().strip() == 'TRADE_FINISHED' or ps[
                 'trade_status'].upper().strip() == 'TRADE_SUCCESS':
             order, is_insurance_order = change_order_status(
                 ps['out_trade_no'], ps['trade_no'])
             create_msg(
                 simplejson.dumps({
                     'payment': 1,
                     'order_id': ps['out_trade_no']
                 }), 'pay_success')
             if is_insurance_order and order:
                 send_new_insurance_order_msg(
                     order.delivery_tel, order.store.name,
                     order.store.area_code, order.ordernum,
                     order.current_order_price.insurance.name,
                     order.payment, order.current_order_price.gift_policy,
                     order.sms_content,
                     order.current_order_price.total_price)
             msg = "success"
     self.write(msg)
Esempio n. 3
0
def new_user_balance(user):
    pass
    try:
        b_new = Balance()
        b_new.user = user.id
        b_new.balance = 5
        b_new.created = int(time.time())
        b_new.stype = 0
        b_new.log = u'新用户注册即送5元账户余额'
        b_new.save()
        msg = u'恭喜您,注册成功!并获得系统赠送5元现金余额,请登录车装甲个人中心查收。'
        sms = {
            'mobile': user.username,
            'body': msg,
            'signtype': '1',
            'isyzm': '1'
        }
        create_msg(simplejson.dumps(sms), 'sms')
    except Exception, ex:
        msg = u'新用户注册送5元账户余额失败,用户名' + user.username + u' 错误信息:' + ex.message
        email = {
            u'receiver':
            ['*****@*****.**', '*****@*****.**'],
            u'subject': u'新用户注册即送5元账户余额失败',
            u'body': msg
        }
        create_msg(simplejson.dumps(email), 'email')
Esempio n. 4
0
 def post(self):
     result = {'return_code': 'FAIL'}
     try:
         ps = Trade(isCZ=True).smart_str_decode(self.request.body)
         if Trade(isCZ=True).union_validate(ps):
             if ps['respMsg'] == 'Success!':
                 create_msg(
                     simplejson.dumps({
                         'payment': 3,
                         'order_id': ps['orderId']
                     }), 'recharge')
                 if MoneyRecord.select().where(
                         MoneyRecord.in_num == ps['queryId']).count() > 0:
                     logging.error(u'银联重复回调:order_id:%s in_num:%s' %
                                   (ps['orderId'], ps['queryId']))
                 else:
                     recharge(ps['orderId'], ps['queryId'],
                              float(ps['settleAmt']) / 100, u'银联')
                 result['return_code'] = 'SUCCESS'
             else:
                 result['return_msg'] = 'upay get FAIL notify'
         else:
             logging.info('upay invalid')
     except Exception, e:
         logging.info('Error: upay error %s' % e)
Esempio n. 5
0
 def post(self):
     notify = PaymentNotify()
     notify.content = self.request.body
     notify.notify_time = int(time.time())
     notify.notify_type = 2
     notify.payment = 1
     notify.function_type = 1
     notify.save()
     msg = "fail"
     params = {}
     ks = self.request.arguments.keys()
     for k in ks:
         params[k] = self.get_argument(k)
     logging.error('----parms=%s---' % params)
     ps = notify_verify(params)
     logging.error('----ps=%s---' % ps)
     if ps:
         if ps['trade_status'].upper().strip() == 'TRADE_FINISHED' or ps[
                 'trade_status'].upper().strip() == 'TRADE_SUCCESS':
             if MoneyRecord.select().where(
                     MoneyRecord.in_num == ps['trade_no']).count() > 0:
                 logging.error(u'支付宝重复回调:order_id:%s in_num:%s' %
                               (ps['out_trade_no'], ps['trade_no']))
             else:
                 create_msg(
                     simplejson.dumps({
                         'payment': 1,
                         'order_id': ps['out_trade_no']
                     }), 'recharge')
                 recharge(ps['out_trade_no'], ps['trade_no'],
                          ps['total_fee'], u'支付宝')
             msg = "success"
     self.write(msg)
Esempio n. 6
0
 def post(self):
     result = {'return_code': 'FAIL'}
     try:
         ps = Trade().smart_str_decode(self.request.body)
         if Trade().union_validate(ps):
             if ps['respMsg'] == 'Success!':
                 order, is_insurance_order = change_order_status(
                     ps['orderId'], ps['queryId'])
                 create_msg(
                     simplejson.dumps({
                         'payment': 3,
                         'order_id': ps['orderId']
                     }), 'pay_success')
                 if is_insurance_order and order:
                     send_new_insurance_order_msg(
                         order.delivery_tel, order.store.name,
                         order.store.area_code, order.ordernum,
                         order.current_order_price.insurance.name,
                         order.payment,
                         order.current_order_price.gift_policy,
                         order.sms_content,
                         order.current_order_price.total_price)
                 result['return_code'] = 'SUCCESS'
             else:
                 result['return_msg'] = 'upay get FAIL notify'
         else:
             logging.info('upay invalid')
     except Exception, e:
         logging.info('Error: upay error %s' % e.message)
Esempio n. 7
0
 def post(self):
     notify = PaymentNotify()
     notify.content = self.request.body
     notify.notify_time = int(time.time())
     notify.notify_type = 2
     notify.payment = 2
     notify.function_type = 1
     notify.save()
     notify_data = Notify_pub()
     notify_data.saveData(self.request.body)
     ps = notify_data.getData()
     if notify_data.checkSign():
         if ps['return_code'] == 'SUCCESS' and ps[
                 'result_code'] == 'SUCCESS':
             order, is_insurance_order = change_order_status(
                 ps['out_trade_no'], ps['transaction_id'])
             create_msg(
                 simplejson.dumps({
                     'payment': 2,
                     'order_id': ps['out_trade_no']
                 }), 'pay_success')
             if is_insurance_order and order:
                 send_new_insurance_order_msg(
                     order.delivery_tel, order.store.name,
                     order.store.area_code, order.ordernum,
                     order.current_order_price.insurance.name,
                     order.payment, order.current_order_price.gift_policy,
                     order.sms_content,
                     order.current_order_price.total_price)
             notify_data.setReturnParameter('return_code', 'SUCCESS')
         else:
             logging.info(u'微信通知支付失败')
     else:
         logging.info(u'微信通知验证失败')
     self.write(notify_data.returnXml())
Esempio n. 8
0
def create_coupon_real(user, total_id, createby, type):
    try:
        seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
        sa = []
        for i in range(16):
            sa.append(random.choice(seed))
            salt = ''.join(sa)
        code = uuid.uuid3(uuid.NAMESPACE_DNS, salt + str(int(time.time())))
        cp = CouponReal()
        cp.user = user.id
        cp.code = code
        cp.coupon_real_total = total_id
        cp.status = 1
        cp.starttime = int(time.time())
        cp.endtime = int(
            time.mktime(
                time.strptime(
                    time.strftime("%Y-%m-%d 0:0:0",
                                  time.localtime(time.time() + 86400 * 30)),
                    "%Y-%m-%d 0:0:0")))
        cp.createby = createby
        cp.createtime = int(time.time())
        cp.save()
        cp.coupon_real_total.quantity += 1
        cp.coupon_real_total.save()

        gift = Gift()
        gift.user = user.id
        gift.product = cp.coupon_real_total.product
        gift.product_standard = cp.coupon_real_total.product_standard
        gift.quantity = 1
        gift.created = int(time.time())
        gift.created_by = AdminUser.get(AdminUser.username == createby).id
        gift.status = 0
        gift.type = type  # 对应orderItem表中的item_type
        gift.end_time = cp.endtime
        gift.save()
        cp.status = 1
        cp.save()
        cp.coupon_real_total.used += 1
        cp.coupon_real_total.save()

        msg = u'为用户' + user.username + u'增加实物优惠券成功!'
        return msg
    except Exception, ex:
        msg = u'创建实物优惠券失败,错误信息:' + ex.message
        email = {
            u'receiver':
            ['*****@*****.**', '*****@*****.**'],
            u'subject': u'创建实物优惠券失败',
            u'body': msg
        }
        create_msg(simplejson.dumps(email), 'email')
        return msg
Esempio n. 9
0
    def post(self):
        alipay = Alipay(**self.settings)

        params = {}
        ks = self.request.arguments.keys()

        for k in ks:
            params[k] = self.get_argument(k)

        if alipay.notify_verify(params):
            batch_no = self.get_argument("batch_no", None)  # 退款批次号
            try:
                pay_backs = PayBack.select().where(
                    PayBack.batch_no == batch_no)
                if pay_backs.count() > 0:
                    pay_back = pay_backs[0]
                    if pay_back.status == 0:  # 等待退款
                        pay_back.status = 1
                        pay_back.pay_response = simplejson.dumps(params)
                        pay_back.save()
                        try:
                            admins = AdminUser.select().where(AdminUser.roles %
                                                              '%Y%')
                            receivers = [
                                n.email for n in admins if len(n.email) > 0
                            ]
                            email = {
                                u'receiver':
                                receivers,
                                u'subject':
                                u'用户退款成功',
                                u'body':
                                u"退款订单编号为:" + pay_back.order.ordernum +
                                u";<br>退款金额:" + str(pay_back.price) + u";"
                            }
                            create_msg(simplejson.dumps(email), 'email')
                        except Exception, e:
                            print e

            except Exception, ex:
                logging.error(ex)
            self.write("success")
Esempio n. 10
0
def user_top_up_balance(balance):
    max_price = int(setting.Balance_Max_Price)  #最大返利金额
    end_date = time.mktime(time.strptime(setting.Balance_End_Date,
                                         "%Y-%m-%d"))  #活动结束时间
    date = int(time.time())
    if date < end_date:
        try:
            b = Balance.select(
                db.fn.SUM(Balance.balance).alias('total_price')).where(
                    (Balance.user == balance.user) & (Balance.stype == 0)
                    & (Balance.log == '充值返现活动赠送')).dicts()
            need_price = 0
            if b[0]["total_price"]:
                if b[0]["total_price"] < max_price:
                    need_price = max_price - b[0]["total_price"]
                    if (balance.balance / 2 < need_price):
                        need_price = balance.balance / 2
                else:
                    return
            else:
                need_price = balance.balance / 2
                if need_price > max_price:
                    need_price = max_price
            b_new = Balance()
            b_new.user = balance.user
            b_new.balance = need_price
            b_new.created = int(time.time())
            b_new.stype = 0
            b_new.log = u'充值返现活动赠送'
            b_new.save()
            msg = u'恭喜您,充值成功!并获得充值返现金额 ' + str(need_price) + u' 元,请登录车装甲查收。'
            sms = {
                'mobile': balance.user.username,
                'body': msg,
                'signtype': '1',
                'isyzm': '1'
            }
            create_msg(simplejson.dumps(sms), 'sms')
        except Exception, ex:
            logging.error(ex)
            pass
Esempio n. 11
0
def old_new_user_coupon(promote, user):
    if promote:
        result = 0
        msg = ''
        try:
            oldUser = User.get(User.username == promote)
            cps = CouponTotal.select().where((CouponTotal.name == '满30减3元') & (
                CouponTotal.status == 0)).limit(1)
            if cps.count() < 1:
                msg = u'请检查“满30减3元优惠券”是否被禁用或者不存在,老用户' + oldUser.username + u"未获得返卷,请手动补充优惠券后手动补发。"
                admins = AdminUser.select()
                receivers = [n.email for n in admins if len(n.email) > 0]
                email = {
                    u'receiver': receivers,
                    u'subject': u'老推新用户注册返卷失败',
                    u'body': msg
                }
                create_msg(simplejson.dumps(email), 'email')
            else:
                log = u'系统自动赠送'
                create_coupon(oldUser, cps[0].id, log)
                msg = u'恭喜您,您推荐的好友' + user.mobile + u'已经注册成功,您获得3元优惠券一张,请在有效期内使用。'
                sms = {
                    'mobile': oldUser.username,
                    'body': msg,
                    'signtype': '1',
                    'isyzm': '1'
                }
                create_msg(simplejson.dumps(sms), 'sms')
                result = 1
            up = User_Promote()
            up.old_user = oldUser.id
            up.new_user = user.id
            up.signuped = int(time.time())
            if result == 1:
                up.signup_gift = 1
                up.signup_gift_content = msg
            up.save()
        except Exception, e:
            logging.error("推荐人不存在" + e)
Esempio n. 12
0
def old_new_user_balance(order):
    try:
        rate = float(setting.Old_New_User_Rate)  #首单返利利率
        max_price = float(setting.Old_New_Max_Price)  #首单返利最大金额
        oc = Order.select().where((Order.user == order.user)
                                  & (Order.status == 4)
                                  & (Order.ordered <= order.ordered))
        if oc.count() == 1:
            fl_price = oc[0].currentprice - oc[
                0].shippingprice  #商品金额 = 订单实际支付金额 - 订单运费
            if (fl_price >= 0):
                return_balance = round((fl_price * rate), 2)
                if return_balance > max_price:
                    return_balance = max_price
                up = User_Promote.get(User_Promote.new_user == order.user)
                if up:
                    balance = Balance()
                    balance.user = up.old_user
                    balance.balance = return_balance
                    balance.created = int(time.time())
                    balance.stype = 0
                    balance.log = u'老推新首单返利。'
                    balance.save()
                    msg = u'恭喜您,您推荐的好友'+order.user.username+u'首次订单已经完成,您获得'+str(return_balance)+\
                          u'元余额返利,请登录车装甲查收。'
                    sms = {
                        'mobile': up.old_user.username,
                        'body': msg,
                        'signtype': '1',
                        'isyzm': '1'
                    }
                    create_msg(simplejson.dumps(sms), 'sms')

                    up.first_order_gift = 1
                    up.first_order_time = int(time.time())
                    up.first_order_content = msg
                    up.save()
    except:
        pass
Esempio n. 13
0
def create_coupon(user, total_id, log):
    try:
        seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
        sa = []
        for i in range(16):
            sa.append(random.choice(seed))
            salt = ''.join(sa)
        code = uuid.uuid3(uuid.NAMESPACE_DNS, salt + str(int(time.time())))
        cp = Coupon()
        cp.user = user.id
        cp.code = code
        cp.coupontotal = total_id
        cp.status = 1
        cp.starttime = int(time.time())
        cp.endtime = int(
            time.mktime(
                time.strptime(
                    time.strftime("%Y-%m-%d 0:0:0",
                                  time.localtime(time.time() + 86400 * 30)),
                    "%Y-%m-%d 0:0:0")))
        cp.log = log
        cp.save()
        cp.coupontotal.quantity += 1
        cp.coupontotal.save()
        msg = u'为用户' + user.username + u'增加优惠券成功!'
        return msg
    except Exception, ex:
        msg = u'创建优惠券失败,错误信息:' + ex.message
        email = {
            u'receiver':
            ['*****@*****.**', '*****@*****.**'],
            u'subject': u'创建优惠券失败',
            u'body': msg
        }
        create_msg(simplejson.dumps(email), 'email')
        return msg
Esempio n. 14
0
    def post(self):
        store_id = self.get_body_argument('store_id',None)
        card_id = self.get_body_argument('card_id',None)

        store_id = int(store_id) if store_id else 0
        card_id = int(card_id) if card_id else 0
        if not (store_id and card_id):
            self.render('weixin/result.html',msg='参数有无,无法使用该优惠券')
        try:
            card = CarServiceCard.get(id=card_id)
            if card.status in [-1,2]:
                self.render('weixin/result.html', msg='无效的保养券')
            store = Store.get(id=store_id)
            card.service_store = store.id
            card.status = 2
            card.save()
            sms = {'apptype': 1, 'body': '您收到微信用户:%s的%s,请其提供响应的服务!'%(card.user.mobile,card.type), 'jpushtype': 'alias', 'alias': store.mobile,
                   'images': '', 'extras': {'link': 'czj://car_service_cards'}}
            create_msg(simplejson.dumps(sms), 'jpush')
            self.self.render('weixin/result.html', msg='使用成功,请联系店铺工作人员核对,并享受对应保养服务')
        except CarServiceCard.DoesNotExist:
            self.render('weixin/result.html',msg='保养券不存在')
        except Store.DoesNotExist:
            self.render('weixin/result.html',msg='店铺不存在')
Esempio n. 15
0
def send_new_insurance_order_msg(mobile, storeName, area_code, ordernum, iName,
                                 payment, LubeOrScore, summary, price):
    mobiles = setting.financeMobiles
    if payment == 1:
        paymentV = u'支付宝'
    elif payment == 2:
        paymentV = u'微信支付'
    elif payment == 3:
        paymentV = u'银联支付'
    elif payment == 4:
        paymentV = u'余额支付'
    else:
        paymentV = u'其它方式支付'

    if LubeOrScore == 1:
        gift = u'返油'
    elif LubeOrScore == 2:
        gift = u'返现'
    elif LubeOrScore == 3:
        gift = u'返积分'
    else:
        gift = u'其它'

    addrs = Area().get_detailed_address(area_code)
    # to 客户
    sms = {
        'mobile': mobile,
        'body': [storeName, addrs, ordernum, iName, paymentV, gift, summary],
        'signtype': '1',
        'isyzm': 'paySuccess'
    }
    create_msg(simplejson.dumps(sms), 'sms')
    # to 财务
    summary = u'订单总额 %s, 客户 %s' % (price, mobile)
    sms = {
        'mobile': mobiles,
        'body': [storeName, addrs, ordernum, iName, paymentV, gift, summary],
        'signtype': '1',
        'isyzm': 'paySuccess'
    }
    create_msg(simplejson.dumps(sms), 'sms')
    if area_code.startswith('0004'):
        sms = {
            'mobile': setting.ShanXiIphone,
            'body':
            [storeName, addrs, ordernum, iName, paymentV, gift, summary],
            'signtype': '1',
            'isyzm': 'paySuccess'
        }
        create_msg(simplejson.dumps(sms), 'sms')
Esempio n. 16
0
def new_year_send_logic(order):
    user = order.user
    beginvalue = time.mktime(time.strptime('2015-01-31', "%Y-%m-%d"))
    endvalue = time.mktime(time.strptime('2015-02-15', "%Y-%m-%d"))
    now = int(time.time())
    # logger.error(str(now))
    needsend = True
    if now < endvalue and order.status < 5 and order.payment < 9 and \
            ((order.status > -1 and order.payment == 0) or (order.status > 0 and order.payment > 0)):
        #当前为2月15日之前,并且订单状态有效
        if user.signuped > beginvalue:  #新注册用户,1月31日当天或以后注册的
            q = Order.select().where(
                (Order.user == user) & (Order.id != order.id)
                & (Order.status < 5) & (Order.payment < 9)
                & (((Order.status > -1) & (Order.payment == 0)) | (
                    (Order.status > 0) & (Order.payment > 0))))
            ct = q.count()
            if ct == 0:  #新用户第一次购买
                needsend = False
                tencount = int(order.currentprice / 40.0)
                fivecount = tencount * 2
                if fivecount > 0:
                    cps = Coupon.select(Coupon).join(CouponTotal).where(
                        (CouponTotal.name == '满50减5元') & (Coupon.status == 0)
                        & (Coupon.user >> None)).limit(fivecount)
                    if cps.count() < fivecount:
                        admins = AdminUser.select()
                        receivers = [
                            n.email for n in admins if len(n.email) > 0
                        ]
                        email = {
                            u'receiver': receivers,
                            u'subject': u'5元优惠劵库存不够了',
                            u'body': u'用户:' + str(user.id) + u'领取优惠劵失败,库存不足。'
                        }
                        try:
                            create_msg(simplejson.dumps(email), 'email')
                        except:
                            pass
                    else:
                        for cp in cps:
                            cp.user = user
                            cp.status = 1
                            cp.save()

                            cp.coupontotal.quantity += 1
                            cp.coupontotal.save()

                if tencount > 0:
                    cps = Coupon.select(Coupon).join(CouponTotal).where(
                        (CouponTotal.name == '满100减10元') & (Coupon.status == 0)
                        & (Coupon.user >> None)).limit(tencount)
                    if cps.count() < tencount:
                        admins = AdminUser.select()
                        receivers = [
                            n.email for n in admins if len(n.email) > 0
                        ]
                        email = {
                            u'receiver': receivers,
                            u'subject': u'10元优惠劵库存不够了',
                            u'body': u'用户:' + str(user.id) + u'领取优惠劵失败,库存不足。'
                        }
                        try:
                            create_msg(simplejson.dumps(email), 'email')
                        except:
                            pass
                    else:
                        for cp in cps:
                            cp.user = user
                            cp.status = 1
                            cp.save()

                            cp.coupontotal.quantity += 1
                            cp.coupontotal.save()
                if fivecount > 0:
                    try:
                        content = '小易终于等到您啦~请收下见面礼吧!' + str(
                            tencount * 10 +
                            fivecount * 5) + '元代金券已经放入账户,下单时即可使用。更多优惠请到车装甲'
                        sms = {
                            'mobile': user.mobile,
                            'body': content,
                            'signtype': '1',
                            'isyzm': '1'
                        }
                        create_msg(simplejson.dumps(sms), 'sms')
                    except:
                        pass

        if needsend:  #老用户下单(含新用户第二次下单),满50送5,满80送5X2;1月31日以前注册的用户
            cpcount = 0
            if order.currentprice >= 80:
                cpcount = 2
            elif order.currentprice >= 50:
                cpcount = 1

            if cpcount > 0:
                cps = Coupon.select(Coupon).join(CouponTotal).where(
                    (CouponTotal.name == '满50减5元') & (Coupon.status == 0)
                    & (Coupon.user >> None)).limit(cpcount)
                if cps.count() < cpcount:
                    admins = AdminUser.select()
                    receivers = [n.email for n in admins if len(n.email) > 0]
                    email = {
                        u'receiver': receivers,
                        u'subject': u'5元优惠劵赠送异常',
                        u'body': u'用户:' + str(user.id) + u'领取优惠劵失败,库存不足。'
                    }
                    try:
                        create_msg(simplejson.dumps(email), 'email')
                    except:
                        pass
                else:
                    for cp in cps:
                        cp.user = user
                        cp.status = 1
                        cp.save()

                        cp.coupontotal.quantity += 1
                        cp.coupontotal.save()
                    try:
                        content = '作为车装甲最最重视的用户,非常感谢您对车装甲的支持。送您' + str(
                            cpcount * 5) + '元优惠券,请笑纳。'
                        sms = {
                            'mobile': user.mobile,
                            'body': content,
                            'signtype': '1',
                            'isyzm': '1'
                        }
                        create_msg(simplejson.dumps(sms), 'sms')
                    except:
                        pass
Esempio n. 17
0
    def post(self):
        alipay = Alipay(**self.settings)

        params = {}
        ks = self.request.arguments.keys()

        for k in ks:
            params[k] = self.get_argument(k)

        if alipay.notify_verify(params):
            tn = self.get_argument("out_trade_no", None)  #订单编号
            trade_no = self.get_argument("trade_no", None)  #支付宝交易号
            trade_status = self.get_argument("trade_status", None)  #交易状态
            logging.info("notify:%s - %s - %s" % (tn, trade_no, trade_status))

            buyer_email = self.get_argument("buyer_email", None)  #买家支付宝帐号
            notify_time = self.get_argument("notify_time", None)  #通知时间
            subject = self.get_argument("subject", None)  #商品名称
            payment_type = self.get_argument("payment_type", None)  #支付类型
            gmt_create = self.get_argument("gmt_create", None)  #交易创建时间
            gmt_payment = self.get_argument("gmt_payment", None)  #交易付款时间
            gmt_close = self.get_argument("gmt_close", None)  #交易关闭时间
            refund_status = self.get_argument("refund_status", None)  #退款状态
            gmt_refund = self.get_argument("gmt_refund", None)  #退款时间
            seller_email = self.get_argument("seller_email", None)  #卖家支付宝账号
            seller_id = self.get_argument("seller_id", None)  #卖家支付宝账户号
            buyer_id = self.get_argument("buyer_id", None)  #买家支付宝账户号
            price = self.get_argument("price", None)  #商品单价
            total_fee = self.get_argument("total_fee", None)  #Number
            quantity = self.get_argument("quantity", None)  #购买数量
            body = self.get_argument("body", None)  #商品描述
            is_total_fee_adjust = self.get_argument("is_total_fee_adjust",
                                                    None)  #是否调整总价
            use_coupon = self.get_argument("use_coupon", None)  #是否使用红包买家
            error_code = self.get_argument("error_code", None)  #错误代码
            bank_seq_no = self.get_argument("bank_seq_no", None)  #网银流水
            out_channel_inst = self.get_argument("out_channel_inst",
                                                 None)  #实际支付渠道

            pay_response = {
                'out_trade_no': tn,
                'trade_no': trade_no,
                'trade_status': trade_status,
                'buyer_email': buyer_email,
                'notify_time': notify_time,
                'subject': subject,
                'payment_type': payment_type,
                'gmt_create': gmt_create,
                'gmt_payment': gmt_payment,
                'gmt_close': gmt_close,
                'refund_status': refund_status,
                'gmt_refund': gmt_refund,
                'seller_email': seller_email,
                'seller_id': seller_id,
                'buyer_id': buyer_id,
                'price': price,
                'total_fee': total_fee,
                'quantity': quantity,
                'body': body,
                'is_total_fee_adjust': is_total_fee_adjust,
                'use_coupon': use_coupon,
                'error_code': error_code,
                'bank_seq_no': bank_seq_no,
                'out_channel_inst': out_channel_inst
            }

            try:
                order = None
                tn = tn.split(',')
                for n in tn:
                    orders = Order.select().where(Order.ordernum == n)
                    if orders.count() > 0:
                        order = orders[0]
                    if order and order.status == 0:
                        order.status = 1
                        order.pay_account = buyer_email
                        order.trade_no = trade_no
                        order.pay_response = simplejson.dumps(pay_response)
                        order.save()

                        order_Item = ''
                        cartProducts = OrderItem.select().where(
                            OrderItem.order == order)
                        for cartproduct in cartProducts:
                            order_Item += u'名称:' + cartproduct.product.name + u' X ' + str(
                                cartproduct.quantity) + u'份;'
                            if cartproduct.item_type == 5:
                                pr = Product_Reserve.get(
                                    Product_Reserve.product ==
                                    cartproduct.product)
                                old_quantity = pr.quantity
                                pr.quantity += cartproduct.quantity
                                pr.save()
                                if (old_quantity < pr.quantity_stage1) & (
                                        pr.quantity >= pr.quantity_stage1):
                                    return_reserve_balance(
                                        cartproduct.product.id)
                                elif (old_quantity < pr.quantity_stage2) & (
                                        pr.quantity >= pr.quantity_stage2):
                                    return_reserve_balance(
                                        cartproduct.product.id)
                        for n in cartProducts:
                            if n.product.categoryfront.type == '2':
                                sn = 1
                                for s in range(n.quantity):
                                    sn = sn + s
                                    seed = "1234567890"
                                    sa = []
                                    for i in range(12):
                                        sa.append(random.choice(seed))
                                        salt = ''.join(sa)
                                    OrderItemService.create(order_item=n.id,
                                                            sn=sn,
                                                            service_code=salt,
                                                            service_used=0,
                                                            store=order.store,
                                                            user=order.user)
                        try:
                            admins = AdminUser.select().where(AdminUser.roles %
                                                              '%Y%')
                            receivers = [
                                n.email for n in admins if len(n.email) > 0
                            ]
                            email = {
                                u'receiver':
                                receivers,
                                u'subject':
                                u'用户下单成功',
                                u'body':
                                u"支付方式:在线支付;<br/>订单编号为:" + n + u";<br>订单金额:" +
                                str(order.currentprice) + u";<br>订单详情:" +
                                order_Item
                            }
                            create_msg(simplejson.dumps(email), 'email')
                        except Exception, e:
                            print e

            except Exception, ex:
                logging.error(ex)

            if trade_status == 'WAIT_SELLER_SEND_GOODS':
                alipay.send_goods_confirm_by_platform(trade_no)

            self.write("success")
Esempio n. 18
0
    def get(self):
        userid = self.get_argument('userid', None)

        if userid:
            user = User.get(id=userid)
            if user:
                activities = UserActivity.select().where(
                    UserActivity.user == user)
                if activities.count() == 0:
                    beginvalue = time.mktime(
                        time.strptime('2015-01-12', "%Y-%m-%d"))
                    endvalue = time.mktime(
                        time.strptime('2015-01-31', "%Y-%m-%d"))
                    q = Order.select(Order.currentprice).where(
                        (Order.user == self.current_user)
                        & (Order.ordered >= beginvalue) & (Order.status < 5)
                        & (Order.ordered < endvalue) & (Order.payment < 9)
                        & (((Order.status > -1) & (Order.payment == 0)) | (
                            (Order.status > 0) &
                            (Order.payment > 0)))).dicts()

                    price = sum([n['currentprice'] for n in q])
                    cpcount = int(price / 50.0)
                    if cpcount > 0:
                        cps = Coupon.select(Coupon).join(CouponTotal).where(
                            (CouponTotal.name == '满50减5元')
                            & (Coupon.status == 0)).limit(cpcount)
                        if cps.count() < cpcount:
                            msg = '领取优惠券失败,管理员会立即处理,请谅解,给您带来的不便'
                            admins = AdminUser.select()
                            receivers = [
                                n.email for n in admins if len(n.email) > 0
                            ]
                            email = {
                                u'receiver': receivers,
                                u'subject': u'5元优惠券库存不够了',
                                u'body':
                                u'用户:' + str(userid) + u'领取优惠券失败,库存不足。'
                            }
                            try:
                                create_msg(simplejson.dumps(email), 'email')
                            except:
                                pass
                        else:
                            for cp in cps:
                                cp.user = user
                                cp.status = 1
                                cp.save()

                                cp.coupontotal.quantity += 1
                                cp.coupontotal.save()
                            UserActivity.create(user=user,
                                                catchtime=int(time.time()),
                                                status=1)
                            msg = '成功领取' + str(
                                cpcount
                            ) + '张优惠券。您可以在 [个人中心]-[我的优惠券] 中查看详情,感谢您的关注'
                            try:

                                content = '作为车装甲最最重视的用户,非常感谢您对车装甲的支持。送您' + str(
                                    cpcount * 5) + '元优惠券,请笑纳。'
                                sms = {
                                    'mobile': user.mobile,
                                    'body': content,
                                    'signtype': '1',
                                    'isyzm': '1'
                                }
                                create_msg(simplejson.dumps(sms), 'sms')
                            except:
                                pass
                    else:
                        msg = '您累计消费不足50元,无法领取优惠券,感谢您的关注'
                else:
                    msg = '您已经领取过优惠券,感谢您的关注'
            else:
                msg = '请先登录车装甲,之后才能领取,感谢您的关注'
        else:
            msg = '请先登录车装甲,之后才能领取,感谢您的关注'
        self.write(msg)
Esempio n. 19
0
    def get(self):
        alipay = Alipay(**self.settings)

        params = {}
        ks = self.request.arguments.keys()

        for k in ks:
            params[k] = self.get_argument(k)
        msg = ""
        if alipay.notify_verify(params):
            tn = self.get_argument("out_trade_no", None)
            trade_no = self.get_argument("trade_no", None)
            trade_status = self.get_argument("trade_status", None)
            logging.info("return:%s - %s - %s" % (tn, trade_no, trade_status))

            try:
                order = None
                tn1 = tn.split(',')
                for n in tn1:
                    orders = Order.select().where(Order.ordernum == n)
                    if orders.count() > 0:
                        order = orders[0]
                    if order and order.status == 0:
                        order.status = 1
                        order.save()

                        order_Item = ''
                        cartProducts = OrderItem.select().where(
                            OrderItem.order == order)
                        for cartproduct in cartProducts:
                            order_Item += u'名称:' + cartproduct.product.name + u' X ' + str(
                                cartproduct.quantity) + u'份;'
                            if cartproduct.item_type == 5:
                                pr = Product_Reserve.get(
                                    Product_Reserve.product ==
                                    cartproduct.product)
                                old_quantity = pr.quantity
                                pr.quantity += cartproduct.quantity
                                pr.save()
                                if (old_quantity < pr.quantity_stage1) & (
                                        pr.quantity >= pr.quantity_stage1):
                                    return_reserve_balance(
                                        cartproduct.product.id)
                                elif (old_quantity < pr.quantity_stage2) & (
                                        pr.quantity >= pr.quantity_stage2):
                                    return_reserve_balance(
                                        cartproduct.product.id)
                        for n in cartProducts:
                            if n.product.categoryfront.type == '2':
                                sn = 1
                                for s in range(n.quantity):
                                    sn = sn + s
                                    seed = "1234567890"
                                    sa = []
                                    for i in range(12):
                                        sa.append(random.choice(seed))
                                        salt = ''.join(sa)
                                    OrderItemService.create(order_item=n.id,
                                                            sn=sn,
                                                            service_code=salt,
                                                            service_used=0,
                                                            store=order.store,
                                                            user=order.user)
                        try:
                            admins = AdminUser.select().where(AdminUser.roles %
                                                              '%Y%')
                            receivers = [
                                n.email for n in admins if len(n.email) > 0
                            ]
                            email = {
                                u'receiver':
                                receivers,
                                u'subject':
                                u'用户下单成功',
                                u'body':
                                u"支付方式:在线支付;<br/>订单编号为:" + n + u";<br>订单金额:" +
                                str(order.currentprice) + u";<br>订单详情:" +
                                order_Item
                            }
                            create_msg(simplejson.dumps(email), 'email')
                        except Exception, e:
                            print e

                alipay.send_goods_confirm_by_platform(trade_no)
                msg = "success"
                self.redirect("/cart/pay?result=" + msg + "&tn=" + tn +
                              "&price=" + str(order.currentprice) + "&ptype=1")
            except Exception, ex:
                logging.error(ex)
Esempio n. 20
0
#!/usr/bin/env python
# coding=utf8

import datetime
import urllib2
import simplejson
import logging
import time
from sys import path

path.append(r'../')
from lib.mqhelper import create_msg

if __name__ == '__main__':
    res = ''
    try:
        res = urllib2.urlopen("http://www.eofan.com/admin/check_activity_order_timeout").read()

    except Exception, e:
        email = {u'receiver': ['*****@*****.**','*****@*****.**'],
                 u'subject':u'系统删除秒杀超时订单错误',u'body': u"错误信息:" + e.message + res}
        create_msg(simplejson.dumps(email), 'email')
Esempio n. 21
0
    def get_checked_msg(self):
        now = time.time()

        need_send_msgs = JPushRecord.select().where(
            (JPushRecord.start_time <= now) & (now <= JPushRecord.end_time)
            & (JPushRecord.check == 1) & (JPushRecord.send == 0))

        for msg in need_send_msgs:
            mobile = []
            jpush_type = None

            if msg.type == 1:  # 新注册用户jpush 计划
                jpush_type = 'alias'
                mobile = self.new_store(
                    msg.istest) + ['18710483413', '13389182031']
            elif msg.type == 2:  # 经常出单用户(返油)jpush计划
                jpush_type = 'alias'
                mobile = self.often_create_io_store(
                    'lube', msg.istest) + ['18710483413', '13389182031']
            elif msg.type == 3:  # 经常出单用户(返现)jpush计划
                jpush_type = 'alias'
                mobile = self.often_create_io_store(
                    'cash', msg.istest) + ['18710483413', '13389182031']
            elif msg.type == 4:
                pass
            elif msg.type == 5:
                pass
            elif msg.type == 6:
                pass
            elif msg.type == 7:
                pass
            elif msg.type == 10001:  # 所有用户
                jpush_type = 'tags'
                mobile = [item for item in msg.jpush_user.split(',') if item]
            elif msg.type == 10002:  # 按区域发送
                jpush_type = 'tags'
                mobile = [item for item in msg.jpush_user.split(',') if item
                          ] + ['18710483413', '13389182031']
            elif msg.type == 10003:  # 指定用户
                jpush_type = 'alias'
                mobile = [item for item in msg.jpush_user.split(',') if item]

            print mobile, msg.intro.link_type
            if msg.intro.link_type == 0:
                link = ''
                if msg.intro.jpush_active:
                    link = 'http://admin.520czj.com/user/showarticle/%d' % msg.intro.jpush_active.id

                j = 0
                jpush_msg = JPushMsg.get(id=msg.intro.id)
                print j * 1000 < len(mobile)
                while j * 1000 < len(mobile):
                    sms = {
                        'apptype': 1,
                        'body': jpush_msg.content,
                        'jpushtype': jpush_type,
                        'extras': {
                            'link': link
                        },
                        jpush_type: mobile[j * 1000:(j + 1) * 1000],
                        'images': jpush_msg.img_url
                    }
                    print sms
                    create_msg(simplejson.dumps(sms), 'jpush')
                    j += 1
                msg.send = 1
                msg.save()
            else:  # 动态url
                pass