import datetime from ladder.dao.include import * from ladder.lib.Logger import Logger logger = Logger("task").getlog() def addUser(data): settle_dt = datetime.datetime.now().strftime('%Y%m%d') data.update(settle_dt=settle_dt) user = User() user_dao = UserDao() count = user_dao.countUserDB(settle_dt) user_id = "%s%04d" % (settle_dt, int(count) + 1) data.update(user_id=user_id) user.setUser(data) user_dao.insertUser2DB(user) return user_id def openAccount(user_id): balance_dao = BalanceDao() balance = Balance() data = {} data.update(user_id=user_id) balance.setBalanceDict(data) balance_dao.insertBalance2DB(balance)
import json from random import Random from ladder.dao.SQLOper import SQLOper from ladder.lib.RetMsg import * from ladder.lib.Logger import Logger logger = Logger("server").getlog() class ServerDao: def __init__(self): self.table_name = "tbl_server" self.select_all_which = "server_id,ip,port,password,server_status" def countUserDB(self, server_id): logger.info("enter") sql = "select count(*) from %s where server_id = '%s' " % ( self.table_name, server_id) sqlOper = SQLOper() count = sqlOper.executeSql(sql) return count[0][0] def insertServer2DB(self, server): logger.info("enter") server_id = server.data["server_id"] if self.countUserDB(server_id) == 0: sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, server.pattern,
import json import datetime from ladder.dao.SQLOper import SQLOper from ladder.lib.Logger import Logger from ladder.lib.RetMsg import * logger = Logger("trans").getlog() class TransDao: """ operation the tbl_trans table """ def __init__(self): self.table_name = "tbl_trans" self.select_all_which = "user_id,buss_no,trans_cd,trans_at,trans_day,settle_dt,curr_day,curr_balance" # 插入新交易,同步修改余额表 def insertTrans(self, trans): logger.info("enter") user_id = trans.data["user_id"] trans_cd = trans.data["trans_cd"] sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, trans.pattern, trans.value_str) if (sqlRes): logger.info("insert user_id={},trans_cd={} SUCCESS".format( user_id, trans_cd)) return SUCCESS.setRet( msg="insert user_id={},trans_cd={} SUCCESS".format(
import json from ladder.dao.SQLOper import SQLOper from ladder.lib.RetMsg import * from ladder.lib.Logger import Logger logger = Logger("balance").getlog() class BalanceDao: def __init__(self): self.table_name = "tbl_balance" self.select_all_which = "user_id,current_day,total_day,total_balance,over_day,server_id" self.pattren = "" # zidong xiugai def autoUpdateBalance(self): # TODO pass # zidong xiugai status 余额加上超期时间为0的用户 # return 修改用户号 def autoUpdateStatus(self): # TODO pass def countUserDB(self, user_id): return 0 #TODO dangban
from ladder.lib.Logger import Logger from ladder.dao.include import * logger = Logger("charge module").getlog() class Charge: """ charge interface """ def __init__(self, data): self.data = {} self.data.update(data) self.req_list = [ "user_id", "trans_cd", "buss_no", "settle_dt", "trans_at", "trans_day" ] self.rsp_list = [ "trans_cd", "buss_no", "settle_dt", "resp_no", "resp_msg", "user_id", "current_day", "total_balance" ] self.rsp_data = {} self.trans = Trans() self.trans_dao = TransDao() self.balance = Balance() self.balance_dao = BalanceDao() self.user_dao = UserDao() def checkParam(self): for key in self.req_list: if self.data.__contains__(key) is False:
from ladder.lib.Logger import Logger from ladder.dao.include import * logger = Logger("register").getlog() class Register: def __init__(self, data): self.data = {} self.data.update(data) self.user_list = [ "user_id", "nike_name", "qq_no", "qq_name", "wechat_no", "wechat_name", "phone_no", "user_status", "password", "settle_dt" ] self.req_list = ["trans_cd", "buss_no", "settle_dt"] self.rsp_list = [] self.rsp_data = {} self.user_id = "" self.user = User() self.user_dao = UserDao() self.balance_dao = BalanceDao() self.balance = Balance() self.request_dao = RequestDao() def checkParam(self): if (self.data.get("qq_no", "") + self.data.get("wechat_no", "")).__len__() == 0: msg = "qq号 与 微信号 都不存在" logger.error(msg) return FAILURE.setMsg(msg)
import datetime import json from ladder.dao.SQLOper import SQLOper from ladder.lib.CheckData import CheckData from ladder.lib.Logger import Logger from ladder.lib.RetMsg import * logger = Logger().getlog() class UserDao: def __init__(self): self.table_name = "tbl_user" self.pattern = "" self.unique_check = False self.check = CheckData() def countUserDB(self, settleDt): #TODO # sql = "select count(*) from %s where settle_dt= '%s' " % (self.table_name, settleDt) # sqlOper = SQLOper() # count = sqlOper.executeSql(sql) # return count[0][0] return 1 def insertUser2DB(self, user): logger.info("enter") # print("AAA"+user.data.get("wechat_no","")+user.data.get("qq_no","")) if (user.data.get("wechat_no", "") + user.data.get("qq_no", "")).strip().__len__() == 0: # print("qq号, 微信号 不同时为空")
import pymysql from ladder.lib.Logger import Logger logger = Logger("sqlOper").getlog() class SQLOper: def __init__(self): self.host = "127.0.0.1" # self.host="182.150.27.208" self.user = "******" self.port = 3306 self.password = "******" self.dbname = "vpndb" self.db = "" def getDB(self): self.db = pymysql.connect(host=self.host, user=self.user, password=self.password, db=self.dbname, port=self.port) def closeDB(self): self.db.close() def executeDoubleSql(self, sql1, sql2): logger.info("enter ") self.getDB() cur = self.db.cursor()
from ladder.lib.Logger import Logger from ladder.lib.RetMsg import * from ladder.dao.SQLOper import SQLOper logger = Logger('request').getlog() class RequestDao: def __init__(self): self.table_name = "tbl_request" self.select_all_which = "req_no,req_cd,settle_dt,req_param,res_msg" self.pattern = "" self.value_str = "" def insertRequset(self, request): sqlOper = SQLOper() sqlRes = sqlOper.executeInsertSql(self.table_name, request.pattern, request.value_str) if (sqlRes): logger.info("insert{:^25}SUCCESS".format(request.data['req_no'])) ret = SUCCESS else: logger.error(" insert FAIL {}={} ".format("req_no", request.data['req_no'])) ret = FAILURE.setRet(msg=" insert FAIL {}={} ".format( "req_no", request.data['req_no'])) def getInsertRequsetSql(self, request):