def worker(self, keyword, get_data): try: if self.request.method == 'POST': if keyword == "code": code = get_data.get("code", "").strip() local_code = config.get_local_register_code() if code != "" and local_code == code: # 请求获取门店信息 data = store_pc_info.get_store_detail() if not self.connect or not data: store = config.get_local_store_info() data = { 'data': { "pcId": store.id(), "pcPhone": store.phone(), "pcAddress": store.address(), "pcSign": store.name(), }, 'code': 200 } if data.get('code') == 200: result = data.get("data") else: raise ApiException(ErrorCode.CodeError) else: raise ApiException(ErrorCode.CodeError) return set_return_dicts(result) elif keyword == "ip": return set_return_dicts(True) else: raise ApiException(ErrorCode.ErrorRequest) elif self.request.method == "GET": if keyword == "list": worker = user_handler.get_all_staff() worker_list = list() for data in worker: worker_list.append({ "workerId": data[0], "workerName": data[1] }) return set_return_dicts(worker_list) 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'])
def get(self, *args, **kwargs): try: # 异步 yield tornado.gen.Task(ioloop.IOLoop.instance().add_timeout, time.time()) if args != (): self.__keyWord = args[0] get_data = self.get_all_argument() if len(args) > 1: get_data['args'] = list(args) get_data['args'].remove(self.__keyWord) check_result = self.check_device() if not check_result: raise ApiException(ErrorCode.UserStateError) elif check_result == 2: raise ApiException(ErrorCode.UserStateWaitError) if self.__keyWord: result = yield self.func(self.__keyWord, get_data) else: result = yield self.func(get_data) transmission_result = json.dumps(result) self.write(transmission_result) self.finish() except ApiException as e: self.write(json.dumps(set_return_dicts(forWorker=e.error_result['forWorker'], code=e.error_result['errorCode'], forUser=e.error_result['forUser']))) logger.error(e) self.finish() except Exception as commException: logger.error(commException) self.write(json.dumps(set_return_dicts(forWorker='不合法的参数', code=ErrorCode.ParameterError, forUser='******'))) self.finish()
def post(self, *args, **kwargs): try: # 异步 yield tornado.gen.Task(ioloop.IOLoop.instance().add_timeout, time.time()) if args != (): self.__keyWord = args[0] # json传输 try: get_data = json.loads(self.request.body.decode()) except Exception as outer: print(outer) try: get_data = self.get_all_argument() except Exception as inner: print(inner) raise ApiException(ErrorCode.JsonError) check_result = self.check_device() if not check_result: raise ApiException(ErrorCode.UserStateError) elif check_result == 2: raise ApiException(ErrorCode.UserStateWaitError) if self.__keyWord: result = yield self.func(self.__keyWord, get_data) else: result = yield self.func(get_data) transmission_result = json.dumps(result) self.write(transmission_result.encode('utf-8')) self.finish() except ApiException as e: self.write(json.dumps(set_return_dicts(forWorker=e.error_result['forWorker'], code=e.error_result['errorCode'], forUser=e.error_result['forUser']))) self.finish()
def print_html(printer): try: if not myconnect: raise ApiException(ErrorCode.ErrorRequest) code = config.get_local_register_code() url = domain + "store/api/detail?code={}".format(code) req = requests.get(url=url) result_data = json.loads(req.text) except Exception as e: logger.error(e.__str__()) store = config.get_local_store_info() result_data = { 'data': { "pcId": store.id(), "pcPhone": store.phone(), "pcAddress": store.address(), "pcSign": store.name(), }, 'code': 200 } mustSet = ['数量', '单价', '小计', '总价', '单位', '备注'] if result_data.get("code") != 200: storeName = "" pcAddress = "" pcPhone = "" else: storeName = result_data.get("data").get("pcSign", "") pcAddress = result_data.get("data").get("pcAddress", "") pcPhone = result_data.get("data").get("pcPhone", "") result = get_sale_info_by_one_key("orderCheckId", selectOrderNo) font_size = config.get_print_font_size() # *{font-size:65px;} if result: header = """<html> <style> table{ background-color:#000000; } .linetd{ text-align: center; width: 820px; color: red; height: 30px; } .halftd{ width: 410px; } #content{ text-align: center; position: relative; top: 50%; transform: translateY(-50%); } td{ padding:2px; align:center; border:1px solid black; background-color:#ffffff } """ + "*{font-size:" + str(font_size) + "pt;}" + ".bigWord{font-size:" + str( font_size * 1.5) + "pt;}" + "</style><head></head>" # *{font-size:50px;} tdWidth = 19 body = """ <body style="text-align: center;"> <table width=100% CELLPADDING="0" CELLSPACING="1" border="0"> <tr> <td class="bigWord" align="center" colspan="100" width="100%"> {storeName} </td> </tr> <tr> <td colspan="50">车牌号:{carId}</td> <td colspan="50">销售日期:{createdTime}</td> </tr> <tr> <td colspan="50">客户电话:{carPhone}</td> <td colspan="50">销售单号:<span style="">{orderNo}</span></td> </tr> <tr> <td colspan="100" height="20px"> </td> </tr> """.format(storeName=storeName, carId=result[0][2], createdTime=result[0][0], carPhone=result[0][4], orderNo=result[0][1]) content = "" xuhao = 1 zongjia = 0 page = 0 pageHeight = 100 for order in result: page += 1 attribute = json.loads(order[8]) baseHeight = 180 # 手动排序 # mustSet = ['数量','单价','小计','总价','单位','备注'] # 去除mustset后的必然顺序为:"品牌","型号","工时费","更换里程" # 后面用字符串排序key来排序 tempKeyList2 = ["品牌", "型号", "工时费", "更换里程"] tempKeyList = list() for t in tempKeyList2: if attribute.get(t) and attribute.get(t) != '-': tempKeyList.append(t) for k, v in attribute.items(): if k not in mustSet + ["品牌", "型号", "工时费", "更换里程"] and v != "-" and v != "" and k != "检索ID": tempKeyList.append(k) tempKeyList.sort() noMustSet = OrderedDict() for k in tempKeyList: noMustSet[k] = attribute.get(k) # 总长度要减去备注和名称,因为名称长度另外设置,备注不打印 td = "" keyDict = dict() i = 0 j = 0 tdList = list() keyList = list() pageHeight += int(len(noMustSet.keys()) / 5 + 1) * 60 + baseHeight for k, v in noMustSet.items(): # if k not in mustSet and v != "-" and v != "" and k!="检索ID" : td += "<td colspan=\"{tdWidth}\" align=\"center\"><b>{key}</b></td>".format(tdWidth=tdWidth, key=k) keyList.append(k) if i >= 4: i = 0 tdList.append(td) td = "" keyDict[j] = keyList keyList = list() j += 1 else: i += 1 # 补齐 if keyList: if len(keyList) < 5: num = len(keyList) for i in range(5 - num): keyList.append("") td += "<td colspan=\"{tdWidth}\" align=\"center\"></td>".format(tdWidth=tdWidth) tdList.append(td) keyDict[j] = keyList # 序号合并列数 xuNum = len(tdList) * 2 + 2 # createdTime,orderNo,carId,carUser,carPhone,carModel,workerName,project,brand," \ # "model,huawen,number,unitPrice,xiaoji,gongshi,ghlc,remark,totalPrice,pcId,unit content += """ <tr> <td colspan="5" align="center"><b>序</b></td> <td colspan="{tdWidth}" align="center"><b>名称</b></td> <td colspan="{tdWidth}" align="center"><b>单位</b></td> <td colspan="{tdWidth}" align="center"><b>数量</b></td> <td colspan="{tdWidth}" align="center"><b>单价</b></td> <td colspan="{tdWidth}" align="center"><b>小计</b></td> </tr> <tr> <td rowspan="{xuNum}" colspan="5" align="center"><br/>{xuhao}</td> <td colspan="{tdWidth}" align="center">{project}</td> <td colspan="{tdWidth}" align="center">{unit}</td> <td colspan="{tdWidth}" align="center">{number}</td> <td colspan="{tdWidth}" align="center">{unitPrice}</td> <td colspan="{tdWidth}" align="center">{xiaoji}</td> </tr> """.format(xuNum=xuNum, xuhao=xuhao, unit=attribute.get("单位", ""), number=attribute.get("数量", ""), unitPrice=attribute.get("单价", ""), xiaoji=attribute.get('小计', ""), project=order[7], tdWidth=tdWidth) moreContent = "" ii = 0 for td in tdList: # 先放入表头 moreContent += "<tr>" + td + "</tr>" # 再放入内容 moreContent += """ <tr> <td colspan="{tdWidth}" align="center">{one}</td> <td colspan="{tdWidth}" align="center">{two}</td> <td colspan="{tdWidth}" align="center">{three}</td> <td colspan="{tdWidth}" align="center">{four}</td> <td colspan="{tdWidth}" align="center">{five}</td> </tr> """.format(tdWidth=tdWidth, one=attribute.get(keyDict[ii][0], ""), two=attribute.get(keyDict[ii][1], ""), three=attribute.get(keyDict[ii][2], ""), four=attribute.get(keyDict[ii][3], ""), five=attribute.get(keyDict[ii][4], "")) ii += 1 fenge = """ <tr> <td colspan="100" height="20px"> </td> </tr> """ zongjiaconetent = """ <tr> <td colspan="95">总价:{zongjia}</td> </tr> """.format(zongjia=attribute.get('总价', "")) content += moreContent + zongjiaconetent + fenge xuhao += 1 try: zongjia += float(attribute.get('总价', 0)) except: zongjia = 0 zongjia = str(zongjia) cn = cncurrency(zongjia) foot = """ <tr> <td style="height:35px" colspan="70">合计人名币(大写):{cn}</td> <td style="height:35px" colspan="30">小写:{zongjia}</td> </tr> <tr> <td colspan="30">{storeName}</td> <td colspan="35">地址:{pcAddress}</td> <td colspan="35">联系电话:{pcPhone}</td> </tr> </table> </body> </html> """.format(cn=cn, zongjia=zongjia, storeName=storeName, pcPhone=pcPhone, pcAddress=pcAddress) html = header + body + content + foot textDocument = QTextDocument() textDocument.setHtml(html) textDocument.setDocumentMargin(35) printer.setPageSize(QPrinter.Custom) # height = baseHeight+((page-1)*150) # printer.setPaperSize(QSizeF(printer.logicalDpiX()*(86/25.4),height),QPrinter.Point) # textDocument.setPageSize(QSizeF(printer.logicalDpiX()*(86/25.4),height)) printer.setPaperSize(QSizeF(581, pageHeight), QPrinter.Point) textDocument.setPageSize(QSizeF(581, pageHeight)) textOp = QTextOption() textOp.setWrapMode(QTextOption.WrapAnywhere) textOp.setAlignment(Qt.AlignCenter) textDocument.setDefaultTextOption(textOp) printer.setOutputFormat(QPrinter.NativeFormat) textDocument.print(printer)
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'])
def preview_html(self, get_data, get_height=False): if get_data.get("createdTime"): today = get_data.get("createdTime") else: today = datetime.now() if get_data.get("orderNo"): order_no = get_data.get("orderNo") else: order_no = sale_handler.get_sale_order_no(today) parameter = get_data.get("parameter", []) if type(parameter) == str: parameter = json.loads(parameter) car_id = get_data.pop("carId", "1") car_phone = get_data.pop("carPhone", "1") store_name = get_data.pop("pcSign", "1") try: if not self.connect: raise ApiException(ErrorCode.ErrorRequest) code = config.get_local_register_code() url = domain + "store/api/detail?code={}".format(code) req = requests.get(url=url) result_data = json.loads(req.text) except Exception as exception: logger.error(exception) store = config.get_local_store_info() result_data = { 'data': { "pcId": store.id(), "pcPhone": store.phone(), "pcAddress": store.address(), "pcSign": store.name(), }, 'code': 200 } if result_data.get("code") != 200: store_address = "" store_phone = "" else: store_address = result_data.get("data").get("pcAddress", "") store_phone = result_data.get("data").get("pcPhone", "") font_size = config.get_print_font_size() header = """<html> <head> <style> table{ background-color:#000000 } .linetd{ text-align: center; border:solid 1px #000; width: 820px; color: red; height: 30px; } .halftd{ border:solid 1px #000; width: 410px; } #content{ text-align: center; border:solid 1px #000; position: relative; top: 50%; transform: translateY(-50%); } td{ padding:2px; align:center; border:1px solid black; background-color:#ffffff } *{ font-size: """ + str( font_size) + "pt;}" + "\n .bigWord{font-size: " + str( font_size * 1.5) + "pt;\n }" + "\n </style>\n </head>" # 总长度要减去备注和名称,因为名称长度另外设置,备注不打印 td_width = 19 logger.info('begin body') body = """\n <body > <div style="width:100%;text-align:center"> <table width=100% CELLPADDING="0" CELLSPACING="1" border="0"> <tr> <td class="bigWord" align="center" colspan="100" width="100%"> {storeName} </td> </tr> <tr> <td colspan="50">车牌号:{carId}</td> <td colspan="50">销售日期:{createdTime}</td> </tr> <tr> <td colspan="50">客户电话:{carPhone}</td> <td colspan="50">销售单号:<span style="">{orderNo}</span></td> </tr> <tr> <td colspan="100" height="20px"> </td> </tr>""" \ .format(storeName=store_name, carId=car_id, createdTime=today.strftime("%Y-%m-%d %H:%M:%S"), carPhone=car_phone, orderNo=order_no) logger.info('begin make attribute') target_content = "" sequence = 1 total_price = 0 page_height = 100 td_indent = ''' ''' tr_indent = ''' ''' for order in parameter: attribute = order.get("attribute") base_height = 180 # 按照系统给定的打印顺序排序 need_print_attributes = attribute_handler.get_all_need_print_attr() # 拼接打印预览的表格头部和值 key_td_str = td_indent + '''<td colspan=''' + str( td_width) + '''" align="center">{key}</td>''' value_td_str = td_indent + '''<td colspan="''' + str( td_width) + '''" align="center">{value}</td>''' first_key_str = td_indent + '''<td colspan="5" align="center">序</td>''' first_value_str = td_indent + '''<td rowspan="{seq_row_span}" colspan="5" align="center">{seq}</td>''' value_td_list = [key_td_str.format(key=order.get("project"))] key_td_list = [value_td_str.format(value='名称')] for print_attr in need_print_attributes: key = print_attr['name'] value = attribute.get(key, '') # 是否必须显示,如果是,即便为空也要打印,否则不为空且值不为'-'才打印 is_required = print_attr['is_required'] if not is_required and (not value or value == '-' ) or print_attr['print_order'] == 1000: continue key_td_list.append(key_td_str.format(key=key)) value_td_list.append(value_td_str.format(value=value)) row_num = len(key_td_list) # 补齐最后一行空缺的单元格 for i in range(5 - row_num % 5): key_td_list.append(key_td_str.format(key='')) value_td_list.append(value_td_str.format(value='')) # 序号列合并行数 seq_row_span = int(row_num / 5 + 1) * 2 # 打印所需的高度 page_height += int(row_num / 5 + 1) * 60 + base_height # 拼凑消费项目打印所需HTML logger.info('拼凑消费项目打印所需HTML') first_value_str = first_value_str.format(seq_row_span=seq_row_span, seq=sequence) key_content = tr_indent + '''<tr style="font-weight:800">\n''' value_content = tr_indent + '''<tr style="font-weight:800">\n''' for index, td_str in enumerate(key_td_list): if not index: key_content += first_key_str + '\n' value_content += first_value_str + '\n' key_content += td_str + '\n' value_content += value_td_list[index] + '\n' if not (index + 1) % 5: target_content += key_content + tr_indent + '''</tr>\n''' target_content += value_content + tr_indent + '''</tr>\n''' key_content = tr_indent + '''<tr style="font-weight:800">\n''' value_content = tr_indent + '''<tr style="font-weight:800">\n''' separator = tr_indent + """<tr><td colspan="100" height="20px"> </td></tr>\n""" total_price_content = tr_indent + """<tr><td colspan="95">总价:{total_price}</td></tr>\n""" \ .format(total_price=attribute.get('总价', "")) target_content += total_price_content target_content += separator sequence += 1 total_price += float(attribute.get('总价', 0)) logger.info('end make attribute') total_price = str(total_price) cn = cncurrency(total_price) logger.info('拼凑消费项目总计消费HTML') foot = tr_indent + '''<tr> <td style="height:35px" colspan="70">合计人名币(大写):{cn}</td> <td style="height:35px" colspan="30">小写:{total_price}</td> </tr> <tr> <td colspan="30">{storeName}</td> <td colspan="35">地址:{pcAddress}</td> <td colspan="35">联系电话:{pcPhone}</td> </tr> </table> </div> </body> </html>''' \ .format(cn=cn, total_price=total_price, storeName=store_name, pcPhone=store_phone, pcAddress=store_address) html = header + body + target_content + foot logger.info('add str end') if get_height: return html, page_height else: return html
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'])
def user(self, keyword, get_data): try: if self.request.method == 'POST': if keyword == "add": try: username = get_data.pop("username") phone = get_data.pop("carPhone") car_model = get_data.pop("carModel") car_id = get_data.pop("carId") except Exception as e: print(e) raise ApiException(ErrorCode.ParameterMiss) customer = Customer() customer.username(username) customer.car_model(car_model) customer.phone(phone) customer.car_id(car_id) customer.create_time(time_utils.get_now()) temp_user = customer_handler.get_customer_by_key( "carId", car_id) if temp_user: try: customer_handler.update_customer_by_car_id( customer) except Exception as update_exception: print(update_exception) raise ApiException(ErrorCode.ParameterError) customer_id = temp_user[0][0] else: try: customer_id = customer_handler.add_customer( customer) except Exception as insert_exception: print(insert_exception) raise ApiException(ErrorCode.UserMore) return set_return_dicts({"userId": customer_id}) else: raise ApiException(ErrorCode.ErrorRequest) elif self.request.method == "GET": if not self.storeId: raise ApiException(ErrorCode.PCError) if keyword == "find": key = get_data.get("key", "") if key not in ["carPhone", "carId"]: raise ApiException(ErrorCode.ParameterError) value = get_data.get("value", "") if self.connect: temp = SocketServer("user {} {} {}".format( self.storeId, key, value)) if not temp: temp = self.find_customer(key, value) else: temp = self.find_customer(key, value) result = [] key_temp = [] if temp == 'restart': raise ApiException(ErrorCode.ReStartPC) else: for data in temp: key = data.get("phone") + data.get( "carId") + data.get("carModel") + data.get( "userName") if key in key_temp: pass else: result.append(data) key_temp.append(key) return set_return_dicts(result) elif keyword == 'order': car_id = get_data.get("carId", "") phone = get_data.get("carPhone", "") if not car_id: raise ApiException(ErrorCode.ParameterMiss) if self.connect: all_order_money = 0.0 result = SocketServer("userorder {} {} {}".format( self.storeId, car_id, phone)) if result: order_number = len(result) for data in result: all_order_money += data.get("totalPrice") else: result, order_number, all_order_money = self.get_order( car_id) else: result, order_number, all_order_money = self.get_order( car_id) if result == 'restart': raise ApiException(ErrorCode.ReStartPC) # result = [] else: print('sort') try: result.sort(key=lambda obj: obj.get('createdTime'), reverse=True) except Exception as sortE: print(sortE) try: for data in result: print(data) msg = data.get("msg") for msg_data in msg: temp = {} attribute = msg_data.get("attribute") for k, v in attribute.items(): if v != "" and v != "-": temp[k] = v msg_data['attribute'] = temp except Exception as forException: print(forException) send_msg = { 'orderMsg': result, 'orderNumber': order_number, 'allOrderMoney': all_order_money } print(send_msg) return set_return_dicts(send_msg) 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'])