def _get_service_attribute(self):
        attributes = service_handler.get_attribute_by_service(self.service_id)
        attr_had = {}
        for data in attributes:
            attr_had[data[0]] = data[1]

        return attr_had
示例#2
0
    def ApiService(self, keyWord, getData):
        try:
            if self.request.method == "GET":
                if keyWord == "one":
                    second_services = service_handler.get_all_first_level_service(
                    )
                    send_data = list()
                    for data in second_services:
                        send_data.append({
                            "oneMenuId": data[0],
                            "name": data[1]
                        })
                    return set_return_dicts(send_data)

                elif keyWord == "two":
                    first_service_id = getData.get("oneMenuId")
                    second_services = service_handler.get_second_service_by_father(
                        first_service_id)
                    send_data = list()
                    for data in second_services:
                        second_service_id = data[2]
                        second_service_name = data[3]
                        attribute_dict = {}
                        for attr in service_handler.get_attribute_by_service(
                                second_service_id):
                            attribute_dict[attr[1]] = '1'

                        send_data.append({
                            "twoMenuId": second_service_id,
                            "name": second_service_name,
                            "attribute": attribute_dict,
                        })
                    return set_return_dicts(send_data)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

        except ApiException as e:
            return set_return_dicts(forWorker=e.error_result['forWorker'],
                                    code=e.error_result['errorCode'],
                                    forUser=e.error_result['forUser'])
示例#3
0
    def _get_attribute_list(self):
        service_id = get_table_current_index_info(self.second_service_table, 2)
        attribute = service_handler.get_attribute_by_service(service_id)

        return attribute
示例#4
0
    def ApiService(self, keyword, para_data):
        try:
            if self.request.method == "GET":
                if keyword == "one":
                    second_services = service_handler.get_all_first_level_service()
                    send_data = list()
                    for data in second_services:
                        send_data.append({
                            "oneMenuId": data[0],
                            "name": data[1]
                        })
                    return set_return_dicts(send_data)

                elif keyword == "two":
                    first_service_id = para_data.get("oneMenuId")
                    second_services = service_handler.get_second_service_by_father(first_service_id)
                    send_data = list()
                    for data in second_services:
                        second_service_id = data[2]
                        second_service_name = data[3]
                        attribute_dict = {}
                        for attr in service_handler.get_attribute_by_service(second_service_id):
                            attribute_dict[attr[1]] = '1'

                        send_data.append({
                            "twoMenuId": second_service_id,
                            "name": second_service_name,
                            "attribute": attribute_dict,
                        })
                    return set_return_dicts(send_data)

                elif keyword == 'brand':
                    second_service_id = para_data.get['second_service_id']
                    brands = []
                    for brand in stock_handler.get_brand_by_second_service(second_service_id):
                        brands.append({'name': brand['brand_name'], 'id': brand['brand_id']})
                    send_data = {
                        'second_service_id': second_service_id,
                        'brands': brands
                    }
                    return set_return_dicts(send_data)

                elif keyword == 'model':
                    second_service_id = para_data.get['second_service_id']
                    brand_id = para_data.get['brand_id']
                    models = []
                    for model in stock_handler.get_model_by_second_service_and_brand(second_service_id, brand_id):
                        models.append(({'name': model['model_name'], 'id': model['model_id']}))
                    send_data = {
                        'second_service_id': second_service_id,
                        'models': models
                    }
                    return set_return_dicts(send_data)

                elif keyword == 'balance':
                    model_id = para_data.get['model_id']
                    stock = stock_handler.get_stock_by_model(model_id)
                    if stock:
                        balance = stock['balance']
                    else:
                        balance = 0
                    send_data = {
                        'model_id': model_id,
                        'balance': balance
                    }

                    return set_return_dicts(send_data)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

        except ApiException as e:
            return set_return_dicts(forWorker=e.error_result['forWorker'],
                                    code=e.error_result['errorCode'],
                                    forUser=e.error_result['forUser'])
示例#5
0
    def order(self, keyword, para_data):
        try:
            if self.request.method == 'POST':
                if keyword == "add":
                    today = datetime.now()

                    order_no = get_sale_order_no(today)

                    para_data["orderNo"] = order_no
                    para_data["createdTime"] = today
                    print(keyword)
                    try:
                        car_user = para_data.get("carUser")
                        user_id = para_data.get("userId")
                        worker_id = para_data.get("workerId")
                        pc_id = para_data.get("pcId")
                        car_phone = para_data.get("carPhone")
                        car_model = para_data.get("carModel")
                        car_id = para_data.get("carId")
                        pc_sign = para_data.get("pcSign")
                        worker_name = para_data.get("workerName")
                        order_check_id = get_uuid1()
                        save_data = {
                            'createdTime':
                            para_data.get("createdTime").strftime(
                                "%Y-%m-%d %H:%M:%S"),
                            'userId':
                            user_id,
                            'pcId':
                            pc_id,
                            'pcSign':
                            pc_sign,
                            'carId':
                            car_id,
                            'workerName':
                            worker_name,
                            'workerId':
                            worker_id,
                            'carUser':
                            car_user,
                            'carPhone':
                            car_phone,
                            'carModel':
                            car_model,
                            "orderNo":
                            order_no,
                            "orderCheckId":
                            order_check_id,
                            'code':
                            config.get_local_register_code(),
                        }

                        parameter = para_data.get("parameter", [])
                        if type(parameter) == str:
                            parameter = json.loads(parameter)

                        page = 0
                        for data in parameter:
                            page += 1
                            order_id = get_uuid1()

                            services = data.get('project')
                            services = services.split('-')
                            first_service_name = services[0]
                            second_service_name = services[1]

                            first_service_id = service_handler.get_service_id_by_name(
                                first_service_name)[0]
                            second_service_id = service_handler.get_service_id_by_name(
                                second_service_name, first_service_id)[0]

                            attributes = data.get('attribute')
                            logger.info(attributes)
                            try:
                                unit = attributes.get('单位', '')
                                unit_price = float(attributes.get('单价', ''))
                                number = int(attributes.get('数量', ''))
                                subtotal = float(attributes.get('小计', ''))
                                total = float(attributes.get('总价', ''))
                                note = attributes.get('备注', '')
                                model = attributes.get('型号', '')
                                brand = attributes.get('品牌', '')
                            except Exception as attribute_deal_error:
                                logger.error(attribute_deal_error)
                                unit = ''
                                unit_price = 0.0
                                number = 0
                                subtotal = 0.0
                                total = 0.0
                                note = ''
                                model = ''
                                brand = ''

                            temp = {
                                'project':
                                data.get('project'),
                                'id':
                                order_id,
                                'attribute':
                                json.dumps(attributes, ensure_ascii=False),
                                'serviceId':
                                second_service_id,
                                'unit':
                                unit,
                                'unit_price':
                                unit_price,
                                'number':
                                number,
                                'subtotal':
                                subtotal,
                                'total':
                                total,
                                'note':
                                note
                            }
                            db_transaction_util.begin()
                            logger.info('增加销售数据')
                            logger.info(temp.__str__())
                            logger.info(save_data.__str__())
                            sale_id = sale_handler.add_sale_info(
                                dict(temp, **save_data))

                            service_attributes = service_handler.get_attribute_by_service(
                                second_service_id)
                            all_required_attr = attribute_handler.get_all_required_attributes(
                            )
                            required_attr_list = []
                            for attr in all_required_attr:
                                required_attr_list.append(attr[1])

                            logger.info('增加销售扩展属性')
                            for srv_attr in service_attributes:
                                attr_name = srv_attr[1]
                                if attr_name not in required_attr_list:
                                    attr_id = attribute_handler.get_attr_by_name(
                                        attr_name)[0]
                                    sale_item_handler.add_sale_item(
                                        sale_id, attr_id,
                                        attributes.get(attr_name, ''))

                            # 库存信息更新
                            logger.info('更新库存信息')
                            stock_service.refresh_stock_info(
                                sale_id, brand, model, number, unit,
                                second_service_id)

                            # 回访设置
                            if data.get("callbackTime"):
                                logger.info('增加回访信息')
                                customer_handler.add_return_visit_data(
                                    data.get("callbackTime"), car_phone,
                                    car_id, car_user, today)
                            db_transaction_util.commit()
                    except Exception as add_error:
                        logger.error(add_error)
                        logger.error('traceback.format_exc():\n{}'.format(
                            traceback.format_exc()))
                        db_transaction_util.rollback()
                        raise ApiException(ErrorCode.ParameterMiss)

                    try:
                        p = "defaultPrinter"  # 打印机名称
                        html, page_height = self.preview_html(para_data, True)
                        logger.info('\n' + html)
                        Printer.printing(p, html, page_height)
                    except:
                        pass

                    return set_return_dicts({"orderNo": order_no})

                elif keyword == 'preview':
                    html = self.preview_html(para_data)
                    logger.info('\n' + html)
                    return set_return_dicts(html)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

            elif self.request.method == "GET":

                if not self.storeId:
                    raise ApiException(ErrorCode.PCError)

                if keyword == "detail":

                    check_order_id = para_data.get("checkOrderId")
                    if not check_order_id:
                        raise ApiException(ErrorCode.ParameterMiss)

                    if self.connect:
                        result_dict = SocketServer("orderdetail {} {}".format(
                            self.storeId, check_order_id))

                    else:
                        result = get_sale_info_by_one_key(
                            "orderCheckId", check_order_id)
                        result_list = list()

                        result_dict = {}
                        if result:
                            created_time = ''
                            car_id = ''
                            car_user = ''
                            car_phone = ''
                            car_model = ''
                            total_price = 0
                            order_no = ''
                            for data in result:
                                attribute = OrderedDict()
                                for attr in sale_item_handler.get_item_info_buy_sale_id(
                                        data['sale_id']):
                                    attribute[
                                        attr['name']] = attr['attribute_value']
                                logger.info('销售数据属性调整后的记录:' +
                                            attribute.__str__())
                                created_time = data['createdTime']
                                car_id = data['carId']
                                car_user = data['carUser']
                                car_phone = data['carPhone']
                                car_model = data['carModel']
                                price = data['unit_price']
                                pc_id = data['pcId']
                                order_no = data['orderNo']
                                if pc_id:
                                    total_price += price
                                    attribute['project'] = data['project']
                                    attribute['totalPrice'] = price
                                    attribute['orderNo'] = order_no
                                    result_list.append(attribute)

                            try:
                                pc_sign = config.get_store_name()
                            except:
                                pc_sign = ""
                            result_dict = {
                                "msg": result_list,
                                "totalPrice": total_price,
                                "createdTime": created_time,
                                "carId": car_id,
                                "carUser": car_user,
                                "carPhone": car_phone,
                                "carModel": car_model,
                                "orderNo": order_no,
                                "checkOrderId": check_order_id,
                                "pcSign": pc_sign,
                            }

                    if result_dict == 'restart':
                        raise ApiException(ErrorCode.ReStartPC)
                    return set_return_dicts(result_dict)
                else:
                    raise ApiException(ErrorCode.ErrorRequest)

        except ApiException as e:
            return set_return_dicts(forWorker=e.error_result['forWorker'],
                                    code=e.error_result['errorCode'],
                                    forUser=e.error_result['forUser'])
示例#6
0
    def ApiOrder(self, keyWord, getData):
        try:
            if self.request.method == 'POST':
                if keyWord == "add":
                    today = datetime.now()

                    orderNo = get_sale_order_no(today)

                    getData["orderNo"] = orderNo
                    getData["createdTime"] = today
                    print(keyWord)
                    try:
                        # if True:
                        carUser = getData.get("carUser")
                        userId = getData.get("userId")
                        workerId = getData.get("workerId")
                        pcId = getData.get("pcId")
                        carPhone = getData.get("carPhone")
                        carModel = getData.get("carModel")
                        carId = getData.get("carId")
                        pc_sign = getData.get("pcSign")
                        workerName = getData.get("workerName")
                        root = 'config.ini'
                        basicMsg = configparser.ConfigParser()
                        basicMsg.read(root)
                        orderCheckId = get_order_id()
                        saveData = {
                            'createdTime':
                            getData.get("createdTime").strftime(
                                "%Y-%m-%d %H:%M:%S"),
                            'userId':
                            userId,
                            'pcId':
                            pcId,
                            'pcSign':
                            pc_sign,
                            'carId':
                            carId,
                            'workerName':
                            workerName,
                            'workerId':
                            workerId,
                            'carUser':
                            carUser,
                            'carPhone':
                            carPhone,
                            'carModel':
                            carModel,
                            "orderNo":
                            orderNo,
                            "orderCheckId":
                            orderCheckId,
                            'code':
                            basicMsg.get("msg", "code"),
                        }

                        parameter = getData.get("parameter", [])
                        if type(parameter) == str:
                            parameter = json.loads(parameter)

                        page = 0
                        for data in parameter:
                            page += 1
                            order_id = get_order_id()

                            services = data.get('project')
                            services = services.split('-')
                            first_service_name = services[0]
                            second_service_name = services[1]

                            first_service_id = service_handler.get_service_id_by_name(
                                first_service_name)[0]
                            second_service_id = service_handler.get_service_id_by_name(
                                second_service_name, first_service_id)[0]

                            attributes = data.get('attribute')
                            print(attributes)
                            try:
                                unit = attributes.get('单位', '')
                                unit_price = float(attributes.pop('单价', ''))
                                number = int(attributes.get('数量', ''))
                                subtotal = float(attributes.get('小计', ''))
                                total = float(attributes.get('总价', ''))
                                note = attributes.get('备注', '')
                            except Exception as attribute_deal_error:
                                print(attribute_deal_error)
                                unit = ''
                                unit_price = 0.0
                                number = 0
                                subtotal = 0.0
                                total = 0.0
                                note = ''

                            temp = {
                                'project': data.get('project'),
                                'id': order_id,
                                'attribute': json.dumps(data.get('attribute')),
                                'serviceId': second_service_id,
                                'unit': unit,
                                'unit_price': unit_price,
                                'number': number,
                                'subtotal': subtotal,
                                'total': total,
                                'note': note
                            }

                            sale_id = sale_handler.add_sale_info(
                                dict(temp, **saveData))
                            service_attrs = service_handler.get_attribute_by_service(
                                second_service_id)
                            print(service_attrs)
                            all_required_attr = attribute_handler.get_all_required_attributes(
                            )
                            required_attr_list = []
                            for attr in all_required_attr:
                                required_attr_list.append(attr[1])

                            for srv_attr in service_attrs:
                                attr_name = srv_attr[1]
                                if attr_name not in required_attr_list:
                                    attr_id = attribute_handler.get_attr_by_name(
                                        attr_name)[0]
                                    sale_item_handler.add_sale_item(
                                        order_id, attr_id,
                                        attributes.get(attr_name, ''))

                            # 回访设置
                            if data.get("callbackTime"):
                                dbname = "CallBack"
                                key = "{},{},{},{},{},{}".format(
                                    "callbackTime", "phone", 'carId',
                                    "username", 'createdTime', 'state')
                                value = "\'{}\',\'{}\',\'{}\',\'{}\',\'{}\',\'{}\'".format(
                                    data.get("callbackTime"), carPhone, carId,
                                    carUser, today, '0')
                                self.dbhelp.InsertData(dbname, key, value)
                                customer_handler.add_return_visit_data(
                                    data.get("callbackTime"), carPhone, carId,
                                    carUser, today)
                    except Exception as add_error:
                        print(add_error)
                        raise ApiException(ErrorCode.ParameterMiss)

                    try:
                        # if True:
                        # 打印
                        p = "defaultPrinter"  # 打印机名称
                        html, pageHeight = self.preview_html(getData, True)
                        Printer.printing(p, html, pageHeight)
                    except:
                        # raise ApiException(ErrorCode.PrinterError)
                        pass

                    return set_return_dicts({"orderNo": orderNo})

                elif keyWord == 'preview':
                    print('preview')
                    html = self.preview_html(getData)
                    print(html)
                    return set_return_dicts(html)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

            elif self.request.method == "GET":

                if not self.storeId:
                    raise ApiException(ErrorCode.PCError)

                if keyWord == "detail":

                    checkOrderId = getData.get("checkOrderId")
                    if not checkOrderId:
                        raise ApiException(ErrorCode.ParameterMiss)

                    if self.connect:
                        result_dict = SocketServer("orderdetail {} {}".format(
                            self.storeId, checkOrderId))

                    else:
                        result = get_sale_info_by_one_key(
                            "orderCheckId", checkOrderId)
                        resultList = list()

                        result_dict = {}
                        if result:
                            createdTime = ''
                            carId = ''
                            carUser = ''
                            carPhone = ''
                            carModel = ''
                            totalPrice = 0
                            pcId = ''
                            orderNo = ''
                            for data in result:
                                attribute = OrderedDict(json.loads(data[8]))
                                createdTime = data[0]
                                carId = data[2]
                                carUser = data[3]
                                carPhone = data[4]
                                carModel = data[5]
                                price = data[16]
                                pcId = data[9]
                                orderNo = data[1]
                                if pcId:
                                    totalPrice += price
                                    attribute['project'] = data[7]
                                    attribute['totalPrice'] = price
                                    attribute['orderNo'] = orderNo
                                    resultList.append(attribute)

                            try:
                                pc_sign = config.get_store_name()
                            except:
                                pc_sign = ""
                            result_dict = {
                                "msg": resultList,
                                "totalPrice": totalPrice,
                                "createdTime": createdTime,
                                "carId": carId,
                                "carUser": carUser,
                                "carPhone": carPhone,
                                "carModel": carModel,
                                "orderNo": orderNo,
                                "checkOrderId": checkOrderId,
                                "pcSign": pc_sign,
                            }

                    if result_dict == 'restart':
                        raise ApiException(ErrorCode.ReStartPC)
                        # resultDict = {}
                    return set_return_dicts(result_dict)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

        except ApiException as e:
            return set_return_dicts(forWorker=e.error_result['forWorker'],
                                    code=e.error_result['errorCode'],
                                    forUser=e.error_result['forUser'])