def verify(): l_orderNo = [] column_name = [ 'orderNo', 'deliverFee', 'actualFee', 'couponPrice', 'fromStore', 'orderStatus' ] condition = {'isVerify': '0', 'isDetaildown': '1'} # kwargs = {'isVerify': '2', 'isDetaildown': '1'} ms = MySql() result = ms.get(t="tb_order_spider", cn=column_name, c=condition) if result: for i in result: total = 0 orderNo = i[0] deliverFee = i[1] actualFee = i[2] couponPrice = i[3] fromStore = i[4] column_name = ['unitPrice', 'sellNum', 'unitBenefits'] condition = {'orderNo': orderNo} result2 = ms.get(t="tb_order_detail_spider", cn=column_name, c=condition) for j in result2: unitPrice = j[0] sellNum = j[1] unitBenefits = j[2] total = total + unitPrice * sellNum - unitBenefits a = round(total, 3) + deliverFee - actualFee - couponPrice if abs(a) > 0.0001 and i[5] != '交易关闭': list_tmp = [] list_tmp.append(str(round(total, 2))) list_tmp.append(str(deliverFee)) list_tmp.append(str(actualFee)) list_tmp.append(str(couponPrice)) list_tmp.append(str(a)) list_tmp.append(store_trans(fromStore)) list_tmp.append(orderNo) l_orderNo.append("|".join(list_tmp)) ms.update(t="tb_order_spider", set={ 'isVerify': 2, 'isDetaildown': 0 }, c={'orderNo': orderNo}) else: ms.update(t="tb_order_spider", set={'isVerify': 1}, c={'orderNo': orderNo}) # print('没有异常数据,验证完成!') pass if l_orderNo: s = "\n".join(l_orderNo) # print(s) mail("数据异常报告", s, ["*****@*****.**"])
async def parse_order_detail_item(continue_code, i, main_orders, sub_orders, tb_order_item, ms): for j in range(len(sub_orders)): tb_order_detail_item = TBOrderDetailItem() tb_order_detail_item.orderNo = main_orders[i]["id"] tb_order_detail_item.itemNo = j try: tb_order_detail_item.goodsCode = sub_orders[j]['itemInfo'][ 'extra'][0]['value'] except KeyError: tb_order_detail_item.goodsCode = 'error' tb_order_detail_item.tbName = format_tb_name( sub_orders[j]['itemInfo']['title']) tb_order_detail_item.unitPrice = sub_orders[j]['priceInfo'][ 'realTotal'] tb_order_detail_item.sellNum = sub_orders[j]['quantity'] tb_order_detail_item.orderStatus = tb_order_item.orderStatus tb_order_detail_item.url = "https:" + sub_orders[j]['itemInfo'][ 'itemUrl'] try: attribute_list = sub_orders[j]['itemInfo']['skuText'] except KeyError: pass else: tb_order_detail_item.goodsAttribute = format_attribute( attribute_list) try: operations = sub_orders[j]['operations'] except KeyError: pass else: for x in range(len(operations)): t = operations[x]['style'] if t in ['t12', 't16'] and operations[x]['text'] != "退运保险": tb_order_detail_item.refundStatus = operations[x][ 'text'] tb_order_detail_item.isRefund = "1" elif t == 't0' and operations[x]['text'] == '已取消': continue_code = 1 delete_item = { 'orderNo': tb_order_detail_item.orderNo, 'itemNo': tb_order_detail_item.itemNo, 'goodsCode': tb_order_detail_item.goodsCode } ms = MySql() is_exist = ms.get(t="tb_order_detail_spider", l=1, c=delete_item) if is_exist: ms.delete(t="tb_order_detail_spider", c=delete_item) sql = "UPDATE tb_order_detail_spider SET itemNo=itemNo-1 " \ "WHERE orderNo='{}' " \ "AND itemNo>'{}'".format(tb_order_detail_item.orderNo, tb_order_detail_item.itemNo) ms.update(sql=sql) pass if continue_code: continue tb_order_detail_item.save(ms)