예제 #1
0
 def post(self):
     year = request.args.get('year')
     month = request.args.get('month')
     data = getPrizeNum(int(year), int(month))
     data_json = json.loads(data)
     # print(data_json)
     return data_json
예제 #2
0
    def get(self):
        year = int(request.args.get('year'))
        month = int(request.args.get('month'))
        receipt_prizenum = getPrizeNum(year, month)
        # print(receipt_prizenum[1])
        receipt_prizenum_json = json.loads(receipt_prizenum)
        # print(receipt_prizenum_json['msg'])

        return receipt_prizenum_json
예제 #3
0
    def post(self):
        year = request.args.get('year')
        month = request.args.get('month')
        code = request.args.get('code')

        YM = str(year) + str(month)

        receipt_prizenum = getPrizeNum(int(year), int(month))
        receipt_prizenum_json = json.loads(receipt_prizenum)
        if(receipt_prizenum_json['msg'] != '無此期別資料'):
            win, money = show_prize(str(code), receipt_prizenum_json)
        else:
            win = -1
            money = 0

        if(checkData('Mtranditional_code', code) == -1):
            addsql = 'Mtranditional_code(period, bar_code, win, money)'
            addsqlparams = "VALUES ('%s', '%s', '%s', '%s');" % (YM, code, win, money)
            setData(addsql, addsqlparams)
            print('insert data into database')
        else:
            print('bar_code exist!')

        return code
예제 #4
0
    def post(self):
        
        file = request.files['image']
        if file.filename == '':
            print('no image')
            return {
                'msg' : 'no data'
            }
        else:
            filename = 'image.jpg'
            file.save(filename)
            data = decode_qrcode(filename)

            if os.path.exists(filename):
                os.remove(filename)
                print('remove img already')
            
            if(data == -1):
                print('decode fail')
                return {
                    'msg' : 'no data'
                }, 200
            
            # insert into database
            # print(data['invDate'])
            # print(data['invPeriod'])
            year = int(data['invPeriod'][0:3])
            month = int(data['invPeriod'][3:])

            receipt_prizenum = getPrizeNum(year, month)
            receipt_prizenum_json = json.loads(receipt_prizenum)
            
            if(receipt_prizenum_json['msg'] != '無此期別資料'):
                win, money = show_prize(str(data['invNum'][2:]), receipt_prizenum_json)
            else:
                win = -1
                money = 0

            # if it is already in database
            # print(data['invNum'][2:])
            # print(len(data['details']))
            if(checkData('bar_code', data['invNum'][2:]) == -1):
            
                addsql = 'bar_code(date, period, prefix_barcode, bar_code, win, money)'
                addsqlparams = "VALUES ('%s', '%s', '%s', '%s', '%s', '%s');" % (data['invDate'], data['invPeriod'], data['invNum'][0:2], data['invNum'][2:] , win, money)
                setData(addsql, addsqlparams)

                id = getDataBar(data['invNum'][2:])
                # print(id[0][0])
            
                for it in data['details']:
                    addsql = 'receipt_group(group_name, item, price, number, barID)'
                    addsqlparams = "VALUES ('%s', '%s', '%s', '%s', '%s');" % ('食物', it['description'], it['unitPrice'], it['quantity'], id[0][0])
                    # addsqlparams = 'VALUES ("食物", "8888888888", "1", 2000)'
                    setData(addsql, addsqlparams)

                print('insert data into database')
                
            else:
                print('bar_code exist!')

            # print(data)
            return data