Пример #1
0
 def test15(self):
     query = SellDao()
     queryCustomer = CustomerDao()
     queryGoods = GoodsDao()
     companyId = "5"
     customerId = "201353eb-4f3b-3992-bdae-347841dc304d"
     result = queryCustomer.query_byId(customerId)
     if len(result) == 1:
         customerName = result[0][1]
     else:
         customerName = ""
     sumprice = 22.5
     date = "2019-7-12"
     id = str(uuid.uuid3(uuid.NAMESPACE_OID, date))
     goodsId = "e7f00942-5aad-3df5-90d1-c850b0839ff2"
     number = 5
     goodsResult = queryGoods.query_byId(goodsId)
     if len(goodsResult) == 1:
         goodsName = goodsResult[0][1]
     else:
         goodsName = ""
     row = query.add(id, customerId, goodsId, companyId, number, sumprice,
                     date, customerName, goodsName)
     if row == 1:
         return json.dumps(return_success("Yes!"))
     else:
         return json.dumps(return_unsuccess('Error: Add failed'))
Пример #2
0
def update_goods_info():
    _json = request.json
    goods_dao = GoodsDao()
    res = goods_dao.query_byId(_json.get('id'))
    if len(res) is not 1:
        return json.dumps(return_unsuccess("未找到该商品"), ensure_ascii=False)
    try:
        goods_dao.update_info(_json.get('id'), _json.get('name'),
                              _json.get('sellprice'), _json.get('type'),
                              _json.get('unitInfo'), _json.get('barcode'))
        return json.dumps(return_success("更新商品信息成功"), ensure_ascii=False)
    except Exception as e:
        print(e)
        return json.dumps(return_unsuccess("添加商品失败"), ensure_ascii=False)
Пример #3
0
def addSell():
    conn = MyHelper()
    queryCustomer = CustomerDao()
    queryGoods = GoodsDao()
    _json = request.json
    params = []
    sqls = []
    companyId = _json.get('companyId')
    customerId = _json.get('customerId')
    result = queryCustomer.query_byId(customerId)
    if len(result) == 1:
        customerName = result[0][1]
    else:
        customerName = ""
    date = _json.get('date')
    goodsList = _json.get('goodsList')
    id = str(uuid.uuid3(uuid.NAMESPACE_OID, str(time.time())))
    # print(goodsList)
    for puchase in goodsList:
        sumprice = puchase['sumprice']
        goodsId = puchase['goodsId']
        number = puchase['number']
        goodsResult = queryGoods.query_byId(goodsId)
        if len(goodsResult) == 1:
            goodsName = goodsResult[0][1]
            goodsUnit = goodsResult[0][5]
        else:
            goodsName = ""
        params.append([
            id, customerId, goodsId, companyId, number, sumprice, date,
            customerName, goodsName, goodsUnit
        ])
        sqls.append(
            "insert into Sell (id,customerId, goodsId, companyId, number, sumprice,date,customerName,goodsName,unitInfo) "
            "values (%s, %s, %s, %s, %s,%s, %s, %s, %s, %s)")

    rows = conn.executeUpdateTransaction(sqls=sqls, params=params)
    if rows:
        return json.dumps(return_success(id))
    else:
        return json.dumps(return_unsuccess('Error: Add failed'))
Пример #4
0
def queryPurchase():
    query = PurchaseDao()
    querySupplierName = SupplierDao()
    queryGoodsPhoto = GoodsDao()
    _json = request.json
    companyId = _json.get('companyId')
    results = []
    if _json.get('id') == None:
        if _json.get('date') == None:
            idResult = query.queryAllId(companyId)
        else:
            if _json.get('start') != None:
                start = _json.get('start')
                end = _json.get('end')
            else:
                date = _json.get('date')
                start = datetime.datetime.strptime(date, '%Y-%m-%d')
                delta = datetime.timedelta(days=1)
                n_days = start + delta
                end = n_days.strftime('%Y-%m-%d %H:%M:%S')
            idResult = query.query_byDate(companyId, start, end)
        size = len(idResult)
        if size == 0:
            return json.dumps(return_unsuccess('Error: No data'))
        else:
            for j in range(0, len(idResult)):
                result = []
                id = idResult[j][0]
                goodsList = []
                goodsResult = query.query_byId(id)
                for i in range(0, len(goodsResult)):
                    status = goodsResult[i][8]
                    supplierId = goodsResult[i][3]
                    PhothResult = queryGoodsPhoto.query_byId(goodsResult[i][1])
                    goodsPhoto = PhothResult[0][7]
                    NameResult = querySupplierName.query_byId(supplierId)
                    supplierName = NameResult[0][1]
                    date = goodsResult[i][7]
                    goods = []
                    goods.append(goodsResult[i][6])
                    goods.append(goodsResult[i][1])
                    goods.append(goodsPhoto)
                    goods.append(goodsResult[i][2])
                    goods.append(goodsResult[i][5])
                    goodsList.append(goods)
                result.append(id)
                result.append(status)
                result.append(supplierId)
                result.append(date)
                result.append(supplierName)
                result.append(goodsList)
                results.append(result)
    else:
        id = _json.get('id')
        result = []
        goodsList = []
        goodsResult = query.query_byId(id)
        if len(goodsResult) >= 0:
            for i in range(0, len(goodsResult)):
                status = goodsResult[i][8]
                supplierId = goodsResult[i][3]
                PhothResult = queryGoodsPhoto.query_byId(goodsResult[i][1])
                goodsPhoto = PhothResult[0][7]
                NameResult = querySupplierName.query_byId(supplierId)
                supplierName = NameResult[0][1]
                date = goodsResult[i][7]
                goods = []
                goods.append(goodsResult[i][6])
                goods.append(goodsResult[i][1])
                goods.append(goodsPhoto)
                goods.append(goodsResult[i][2])
                goods.append(goodsResult[i][5])
                goodsList.append(goods)
            result.append(id)
            result.append(status)
            result.append(supplierId)
            result.append(date)
            result.append(supplierName)
            result.append(goodsList)
            results.append(result)
    size = len(results)
    if size == 0:
        return json.dumps(return_unsuccess('Error: No data'))
    else:
        return json.dumps(return_success(PurchaseDao.to_dict(results)), ensure_ascii=False, cls=DecimalEncoder)