Пример #1
0
    def process(self):
        order_id = self.parameters.get('order_id')
        order = OrderService.get_order(order_id)
        if order.orderStatus == '2':
            if order.thunderserviceStatus != '1':
                if OrderService.make_fulfill(order_id):
                    return{
                             "code":200,
                             "message": "order fulfilled success"
                         },200
                else:
                    return{
                              "code":4011,
                              "message": returncode['4011']
                          },200

        elif order:
            return{
                      "code":4016,
                      "message": returncode['4016']
                  },200
        else:
            return{
                "code":4013,
                "message": returncode['4013']
            },200
Пример #2
0
    def process(self):
        pageNum = request.args.get('pageNum', 1, type=int)
        pageSize = request.args.get('pageSize', 10, type=int)
        logging.info("GetOrdersView. pageNum:{},pageSize:{}".format(pageNum, pageSize))

        totals = OrderService.get_order_amount()
        totalPages = (totals + pageSize - 1) // pageSize
        orders = OrderService.get_orders(pageNum, pageSize)
        ordersview = list()
        for order in orders:
            ordersview.append({
                'order_id': order.id,
                "user_id": order.user_id,
                "thunderservice_id" : order.thunderservice_id,
                "placeOrderTime" : order.placeOrderTime,
                "coupon": order.coupon,
                "paymentMethod": order.paymentMethod,
                "paymentTime": order.paymentTime,
                "paymentSN": order.paymentSN,
                "emailNotification": order.emailNotification,
                "amount":order.amount,
                "orderStatus":order.orderStatus,
                "thunderserviceStatus":order.thunderserviceStatus
            })
        return {
            "code": 200,
            "message": "get orders success",
            "results": {
                "totals": totals,
                "totalPages": totalPages,
                "list": ordersview
            }
        }
Пример #3
0
def get_all_pending_orders():
    try:
        order_service = OrderService()
        orders = order_service.get_all_pending_orders()
        return render_template('order_list.html', orders=orders)
    except Exception as error:
        from run import app
        app.logger.error(error)
        raise ValidationError("Error al cargar las ordenes")
Пример #4
0
def cancel_order():
    try:
        data = request.get_json()
        order_id = data['order']
        order_service = OrderService()
        order_service.cancel_order(order_id)
        return 'OK', 200
    except Exception as error:
        from run import app
        app.logger.error(error)
        return "Error al cargar la orden", 500
Пример #5
0
    def process(self):
        trackinginput = self.parameters.get('body')
        TrackingService.tracking(trackinginput)

        logging.info(
            f"支付网关收到支付宝的notify,需要执行thunderservice的发货动作: {trackinginput}")

        FinishOrderViewbody = self.parameters.get('body')
        order_id = str(FinishOrderViewbody.get('out_trade_no'))
        paymentSN = str(FinishOrderViewbody.get('trade_no'))
        paymentTime = str(FinishOrderViewbody.get('timestamp'))
        sign = str(FinishOrderViewbody.get('sign'))

        if self.check_sign(order_id, paymentSN, paymentTime, sign):

            order = OrderService.get_expressorder(order_id)
            if order:
                if order.thunderserviceStatus == "1":
                    logging.info(
                        f"已经开通了服务,可能是重复调用,不操作:thunder service already fulfilled"
                    )
                    return {
                        "code": 200,
                        "message": "thunder service already fulfilled"
                    }, 200

                try:
                    OrderService.mark_paid_order(order.id)
                    OrderService.make_fulfill(order.id)

                    #发送mqtt通知给app
                    message = {
                        "cmd_id": str(int(time.time() * 1000)),
                        "action": "payment_completed",
                        "timestamp": int(time.time()),
                        "expired_on": int(time.time()) + 300
                    }
                    send_single_message(user_id=order.user_id,
                                        message=json.dumps(message))

                    logging.info(f"开通服务成功:thunder service all set")
                    return {
                        "code": 200,
                        "message": "thunder service all set"
                    }, 200
                except:
                    logging.error(f"开通服务失败:5006")
                    return {"code": 5006, "message": returncode['5006']}, 200
            else:
                logging.error(f"开通服务失败:4013")
                return {"code": 4013, "message": returncode['4013']}, 200
        else:
            logging.error(f"开通服务失败:4027")
            return {"code": 4027, "message": returncode['4027']}, 200
Пример #6
0
 def process(self):
     order_id = self.parameters.get('order_id')
     order_data = OrderService.get_order(order_id)
     if order_data:
         OrderService.delete_order(order_id)
         db.session.commit()
         return{
             "code":200,
             "message":"delete success"
         }
     else:
         return{
             "code":4013,
             "message": returncode['4013']
         } ,200
Пример #7
0
def get_order(order_id):
    try:
        order_service = OrderService()
        order = order_service.get_order_by_id(order_id)
        dtos = map(map_to_purchase_dto, order.purchases)
        dto_list = list(dtos)
        response = []
        for dto in dto_list:
            response.append(dto.__dict__)
        return render_template('order_detail.html',
                               order=order,
                               purchases=response)
    except Exception as error:
        from run import app
        app.logger.error(error)
        raise ValidationError("Error al cargar la orden")
Пример #8
0
    def process(self):
        orderID = request.args.get('orderID',type=str)

        #按传入的很长的orderID,取出实际的order记录,得到description和amount
        order = OrderService.get_expressorder(orderID)
        productdetail= order.description
        amount=order.amount
        thunderservice_id = order.thunderservice_id

        #根据orderID中记录的thunderservice_id,取到thunderservice信息
        thunderservice = GetThunderservice.get_thunderservice(thunderservice_id)
        subject = thunderservice.membershipEN

        #根据orderID中记录的user_id,取到用户email
        user = UserService.get_user(order.user_id)
        if user:
            useremail= user.email
        else:
            useremail = 'ERROR'

        resp = make_response(render_template('expressorder.html',
                                             productdetail=productdetail,
                                             amount=amount,
                                             subject = subject,
                                             orderid=orderID,
                                             productID = thunderservice_id,
                                             useremail=useremail,
                                             OrderTime = int(time.time())), 200)
        return resp
Пример #9
0
    def process(self):
        order_id = self.parameters.get('order_id')
        logging.info("GetOrderView. order_id:{}".format(order_id))
        order = OrderService.get_order(order_id)
        if (order):
            order_info = {
                'order_id': order.id,
                "user_id": order.user_id,
                "thunderservice_id" : order.thunderservice_id,
                "placeOrderTime" : order.placeOrderTime,
                "coupon": order.coupon,
                "paymentMethod": order.paymentMethod,
                "paymentTime": order.paymentTime,
                "paymentSN": order.paymentSN,
                "emailNotification": order.emailNotification,
                "amount":order.amount,
                "orderStatus":order.orderStatus,
                "thunderserviceStatus":order.thunderserviceStatus
            }

            return {
                "code": 200,
                "message": "get order success",
                "results": order_info
            }
        return {
            "code": 4013,
            "message": returncode['4013']
        },200
Пример #10
0
 def process(self):
     order_id = self.parameters.get('order_id')
     print (self.parameters)
     order_data = OrderService.get_order(order_id)
     if order_data:
         OrderService.mark_paid_order(order_id)
         db.session.commit()
         return{
             "code":200,
             "message":"Mark this order as paid success"
         },200
     else:
         return{
             "code":4013,
             "message": returncode['4013']
         },200
Пример #11
0
 def get_summary(thisDayStart, thisDayEnd, thisMonthStart, thisMonthEnd):
     newUserToday = UserService.get_newuser_amount(thisDayStart, thisDayEnd)
     totalUser = UserService.get_user_amount()
     membershipDAU = KService.get_user_DAU('102', thisDayStart, thisDayEnd)
     VipDAU = KService.get_user_DAU('103', thisDayStart, thisDayEnd)
     incomeDay = OrderService.get_paidOrder_sum(thisDayStart, thisDayEnd)
     incomeMonth = OrderService.get_paidOrder_sum(thisMonthStart,
                                                  thisMonthEnd)
     data = {
         "newUserToday": newUserToday,
         "totalUser": totalUser,
         "membershipDAU": membershipDAU,
         "VipDAU": VipDAU,
         "incomeDay": incomeDay,
         "incomeMonth": incomeMonth
     }
     return data
Пример #12
0
 def process(self):
     order_id = self.parameters.get('order_id')
     order_data = OrderService.get_order(order_id)
     if order_data:
         if order_data.thunderserviceStatus == "1":
             return{
                       "code":4015,
                       "message": returncode['4015']
                   } ,200
         else:
             OrderService.cancel_order(order_id)
             return{
                 "code":200,
                 "message":"Cancel this order success"
         }
     else:
         return{
             "code":4013,
             "message": returncode['4013']
         } ,200
Пример #13
0
 def process(self):
     data = self.parameters.get('body')
     order_id = data.get('order_id')
     order = OrderService.get_expressorder(order_id)
     if order:
         if order.orderStatus == '2':
             if order.thunderserviceStatus == '1':
                 return{"code":2000,"message":  returncode['2000']},200
             else:
                 return{"code":2001,"message":  returncode['2001']},200
         else:
             return{"code":2002,"message":  returncode['2002']},200
     else:
         return{"code":4013,"message":  returncode['4013']},200
Пример #14
0
    def process(self):
        from application.services.user_service import UserService
        data = self.parameters.get('body')
        print("AddOrderView:")
        print(data)
        user_info = UserService.get_user(data['user_id'])
        if user_info:
            OrderService.add_order(data['user_id'], data['thunderservice_id'],\
                                   time.time()*1000,data['coupon'],data['amount'],data['emailNotification'])
            db.session.commit()

            # 增加记录到K线图
            KService_action = '201'
            KService.add_record(action=KService_action,parameter1=data['amount'],parameter2='New',timestamp=int(time.time()))

            return {
                "code":200,
                "message":"Add order success"
            }
        else:
            return {
                "code": 4011,
                "message": returncode['4011']
            },200
Пример #15
0
    def process(self):
        from application.services.user_service import UserService
        data = self.parameters.get('body')

        logging.info(f"addExpressorder(POST /app/expressorder):{data}")

        user_info = UserService.get_user(data.get('user_id'))
        if user_info:

            thunderserviceFufeiList = GetThunderservice.get_fufei_thunderservice()
            thunderserviceList = []
            if len(thunderserviceFufeiList):
                for item in thunderserviceFufeiList:
                    temp = {
                        "thunderserviceID":item.id,
                        "price":item.price,
                        "currency":"USD",
                        "duration":item.duration
                    }
                    thunderserviceList.append(temp)

            #生成order_id
            thunderServiceID = data.get('thunderserviceID') if data.get('thunderserviceID') else '3'
            if str(thunderServiceID) not in thunder_service_for_expressorderID['FUFEI']:
                logging.error(f"ERROR: addExpressorder: 5005")
                return {
                           "code": 5005,
                           "message": returncode['5005']
                       },200

            # order_id = 'EX'+time.strftime("%Y%m%d%H%M%S",time.localtime())+'U'+user_info.email[:1]+'P'+str(thunderServiceID)

            ts = time.time()
            ts_ms = int(ts*1000-int(ts)*1000)
            order_id = 'EX'+time.strftime("%Y%m%d%H%M%S",time.localtime(ts))+'S'+str(ts_ms)+'U'+user_info.email[:1]+'P'+str(thunderServiceID)

            #取出定价,根据coupon,调整amount
            thunderservice_selected = GetThunderservice.get_thunderservice(thunderServiceID)
            amount = thunderservice_selected.price if thunderservice_selected else 0
            coupon = data.get('coupon')
            # TODO coupon
            amount = amount

            #expressorder不需要发送订单邮件
            emailNotification = False

            #取到thunderservice中对应的desc
            description = thunderservice_selected.description if thunderservice_selected else None

            #添加订单记录
            OrderService.add_order(order_id,data['user_id'], thunderServiceID, \
                                   time.time()*1000,coupon,amount,emailNotification,description)
            db.session.commit()

            # 增加记录到K线图
            KService_action = '201'
            KService.add_record(action=KService_action,parameter1=amount,parameter2='New',timestamp=int(time.time()))

            resp = {
                "code":200,
                "thunderserviceList":thunderserviceList,
                "selectedThunderServiceID":thunderServiceID,
                "orderID":order_id,
                "qrsource":"/app/expressorder_view?orderID="+order_id
            }

            logging.info(f"addExpressorder, response:{resp}")
            return resp,200
        else:
            logging.error(f"ERROR: addExpressorder: 4011")
            return {
                       "code": 4011,
                       "message": returncode['4011']
                   },200
Пример #16
0
    def process(self):
        # TODO 用于多语言及切换货币
        Country = "cn"

        data = request.args
        logging.info(f"appPopupHtmlQRcode(GET: /app/app_popup/qrcode):{data}")

        # 检查入参及取到用户信息
        try:
            token = data['token']
            thunderServiceID = data['thunderserviceID']
            data = jwt.decode(token, config.settings.SECRET_KEY)
            user_info = UserService.get_user(data['user_id'])
        except:
            # invalid token or no thunderServiceID input
            return "Token expired or no thunderServiceID find, please try again", 200

        # 生成order_id
        if str(thunderServiceID) not in thunder_service_ID['FUFEI']:
            logging.error(f"ERROR: addExpressorder: 5005")
            return {
                       "code": 5005,
                       "message": returncode['5005']
                   },200

        ts = time.time()
        ts_ms = int(ts*1000-int(ts)*1000)
        order_id = 'EX'+time.strftime("%Y%m%d%H%M%S",time.localtime(ts))+'S'+str(ts_ms)+'U'+user_info.email[:1]+'P'+str(thunderServiceID)

        # 取出定价,根据coupon,调整amount
        thunderservice_selected = GetThunderservice.get_thunderservice(thunderServiceID)
        amount = thunderservice_selected.price_cn if Country == 'cn' else thunderservice_selected.price
        coupon = data.get('coupon')
        # TODO coupon
        amount = amount

        # 取到thunderservice中对应的desc
        description = thunderservice_selected.description if thunderservice_selected else None

        # expressorder不需要发送订单邮件
        emailNotification = False

        # 添加订单记录
        OrderService.add_order(order_id,user_info.id, thunderServiceID,time.time()*1000,coupon,amount,emailNotification,description)
        db.session.commit()

        # 增加记录到K线图
        KService_action = '201'
        KService.add_record(action=KService_action,parameter1=amount,parameter2='New',timestamp=int(time.time()))

        # 取到要拼接的跳转域名
        website_proxy = SettingService.get_setting_by_name('api_gateway_0')
        if website_proxy:
            url = website_proxy.value
            if url[-1:] != '/':
                url += '/'
            url = url+"app/passwordreset?key="+password_reset
        else:
            raise Exception('5007')

        url = 'lasdjfljdslkasjflkasjflkjdslkfjlksdjafkljdasfkljkljdfkljsdklfjalfkjdlskfj'

        # 生成qrcode
        qr = qrcode.QRCode(
            version=4,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=5,
            border=1
        )
        qr.add_data(url)
        qr.make(fit=True)
        qrimage = qr.make_image()

        byte_io=BytesIO()
        qrimage.save(byte_io, 'png')
        byte_io.seek(0)

        # 方法1:返回base64以后的字符串
        # return {"qr":base64.b64encode(byte_io.getvalue()).decode()}

        # 方法2:或者返回图片字节,可以在浏览器直接加载显示
        res = make_response(byte_io.getvalue()) # 设置响应体
        res.status = '200' # 设置http返回状态码
        res.headers['Content-Type'] = "image/png" # 设置响应头,必要步骤
        # return res

        # 方法3:结合2试试看
        # return u"data:image/png;base64," + base64.b64encode(byte_io.getvalue()).decode('ascii')

        logging.info(f"appPopupHtmlQRcode, response:{res}")
        return res