def list_loan(): if 'username' in session: if session['type'] == 0: loanlist = run([call, cname, caddr, 'GetLoanList'])[0] else: loanlist = run( [call, cname, caddr, 'GetSupplierLoan', session['id']])[0] user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] llist = [] for loan in loanlist: l = run([call, cname, caddr, 'GetLoanInfo', loan]) print(l) u = [ l[0], l[1], datetime.datetime.fromtimestamp( l[2]).strftime("%Y-%m-%d %H:%M:%S") ] print(u) llist.append(u) return render_template("list_loan.html", user=user, llist=llist) else: return redirect(url_for('login'))
def make_list(pre_node, now_node, level): global node_list node_list.remove(now_node) supplier_name = run([call, cname, caddr, 'GetSupplierInfo', now_node])[0] supplier_stuck = len( run([call, cname, caddr, 'GetSupplierStuck', now_node])[0]) supplier_balance = run( [call, cname, caddr, 'GetSupplierBalance', now_node])[0] add_node([now_node, supplier_name, supplier_stuck, supplier_balance], level) links = run([call, cname, caddr, 'GetSupplierRelation', now_node]) links_prior = list(links[0]) links_next = list(links[1]) if pre_node in links_prior: links_prior.remove(pre_node) add_link([pre_node, now_node]) if pre_node in links_next: links_next.remove(pre_node) add_link([now_node, pre_node]) for node in links_prior: if node in node_list: make_list(now_node, node, level - 1) else: add_link([node, now_node]) for node in links_next: if node in node_list: make_list(now_node, node, level + 1) else: add_link([now_node, node])
def del_stuck(): if 'username' in session: if session['type'] == 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] if request.method == 'POST': if request.form['id'] == '': return render_template("del_stuck.html", user=user, error=2) if run([ send, cname, caddr, 'DeleteStuck', user['id'], request.form['id'], int(time.mktime(datetime.datetime.now().timetuple())) ])[0]: return render_template("del_stuck.html", user=user, error=-1, au=request.form['id']) else: return render_template("del_stuck.html", user=user, error=1) return render_template("del_stuck.html", user=user, error=0) else: return redirect(url_for('login'))
def produce_stuck(): if 'username' in session: if session['type'] == 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] if request.method == 'POST': if request.form['num'] == '': return render_template("produce_stuck.html", user=user, error=2) if request.form['name'] == '': return render_template("produce_stuck.html", user=user, error=3) stuck_id = run([ send, cname, caddr, 'CreateStuck', user['id'], request.form['num'], request.form['name'], int(time.mktime(datetime.datetime.now().timetuple())) ])[0] if stuck_id == '0x0000000000000000000000000000000000000000': return render_template("produce_stuck.html", user=user, error=1) else: return render_template("produce_stuck.html", user=user, error=-1, au=stuck_id) return render_template("produce_stuck.html", user=user, error=0) else: return redirect(url_for('login'))
def buy(sid, uid): if 'username' in session: if session['type'] == 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] user['loan'] = run([call, cname, caddr, 'GetSupplierLoan', user['id']])[0] llist = [] for ll in user['loan']: sp = run([call, cname, caddr, 'GetLoanSp', ll])[0] if sid in sp: llist.append(ll) if request.method == 'POST': if request.form['price'] == '': return render_template("buy.html", user=user, error=2, llist=llist) if request.form['sp'] == '0': deal_id = run([ send, cname, caddr, 'makeDeal', sid, user['id'], request.form['price'], uid, int(time.mktime(datetime.datetime.now().timetuple())) ])[0] else: deal_id = run([ send, cname, caddr, 'LoanDeal', sid, user['id'], request.form['price'], uid, int(time.mktime(datetime.datetime.now().timetuple())), request.form['sp'] ])[0] if deal_id == '0x0000000000000000000000000000000000000000': return render_template("buy.html", user=user, error=1, llist=llist) return render_template("buy.html", user=user, error=-1, llist=llist, au=deal_id) return render_template("buy.html", user=user, error=0, llist=llist)
def login(): if request.method == 'POST': if request.form['username'] == 'admin': session['id'] = caddr session['username'] = '******' session['type'] = 0 return redirect(url_for('index')) supplier_list = run([call, cname, caddr, 'GetSupplierList'])[0] for supplier_id in supplier_list: supplier = run( [call, cname, caddr, 'GetSupplierInfo', supplier_id]) if supplier[0] == request.form['username']: session['id'] = supplier_id session['username'] = supplier[0] session['type'] = supplier[1] return redirect(url_for('index')) return render_template("login.html", error=1) return render_template("login.html", error=0)
def add_loan(): if 'username' in session: if session['type'] != 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] supplier_list = run([call, cname, caddr, 'GetSupplierList'])[0] if request.method == 'POST': if request.form['money'] == '': return render_template("add_loan.html", user=user, error=2, sp_list=supplier_list) if request.form['sp'] == '': return render_template("add_loan.html", user=user, error=3, sp_list=supplier_list) loan_id = run([ send, cname, caddr, 'CreateLoan', request.form['money'], request.form['sp'], int(time.mktime(datetime.datetime.now().timetuple())) ])[0] if loan_id == '0x0000000000000000000000000000000000000000': return render_template("add_loan.html", user=user, error=1, sp_list=supplier_list) for sp in supplier_list: if sp in request.form: run([send, cname, caddr, 'AddLoanSupplier', loan_id, sp]) return render_template("add_loan.html", user=user, error=-1, sp_list=supplier_list, au=loan_id) return render_template("add_loan.html", user=user, error=0, sp_list=supplier_list) else: return redirect(url_for('login'))
def shop(): if 'username' in session: if session['type'] == 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] userlist = [] supplier_list = run( [call, cname, caddr, 'GetSupplierRelation', user['id']])[0] for supplier_id in supplier_list: if supplier_id != user['id']: supplier = run( [call, cname, caddr, 'GetSupplierInfo', supplier_id]) u = [supplier_id, supplier[0], supplier[1]] userlist.append(u) return render_template("shop.html", user=user, userlist=userlist) else: return redirect(url_for('login'))
def list_stuck(): if 'username' in session: if session['type'] == 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] user['stn'] = run([call, cname, caddr, 'GetSupplierStuck', user['id']])[0] stucklist = [] for stuck_id in user['stn']: stuck = run([call, cname, caddr, 'GetStuckInfo', stuck_id]) u = [stuck_id, stuck[0], stuck[1]] stucklist.append(u) return render_template("list_stuck.html", user=user, stucklist=stucklist) else: return redirect(url_for('login'))
def list_user(): if 'username' in session: if session['type'] != 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] userlist = [[caddr, '管理员', 0, '']] supplier_list = run([call, cname, caddr, 'GetSupplierList'])[0] for supplier_id in supplier_list: supplier = run( [call, cname, caddr, 'GetSupplierInfo', supplier_id]) balance = run( [call, cname, caddr, 'GetSupplierBalance', supplier_id]) u = [supplier_id, supplier[0], supplier[1], balance[0]] userlist.append(u) return render_template("list_user.html", user=user, userlist=userlist) else: return redirect(url_for('login'))
def index(): if 'username' in session: user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] if user['id'] != caddr: user['balance'] = run( [call, cname, caddr, 'GetSupplierBalance', user['id']])[0] user['stn'] = run( [call, cname, caddr, 'GetSupplierStuck', user['id']])[0] user['loan'] = run( [call, cname, caddr, 'GetSupplierLoan', user['id']])[0] supplier_list = run([call, cname, caddr, 'GetSupplierList'])[0] return render_template("index.html", user=user, sp_num=len(supplier_list)) else: import _thread drawSupplyChain.__init() _thread.start_new_thread(drawSupplyChain.program, ()) return render_template("index.html", user=user) else: return redirect(url_for('login'))
def make_list_ex(pr_id, s_id, level, mode): global u_list, place stuck_info_buff = run([call, cname, caddr, 'GetStuckInfo', s_id]) stuck_info = str(stuck_info_buff[0]) + stuck_info_buff[1] stuck_flew = run([call, cname, caddr, 'GetStuckFlew', s_id]) if not mode: level = level - len(stuck_flew[1]) + 1 buf = 0 for trs_time in stuck_flew[1]: u_list[0][0].append(stuck_info) u_list[0][4].append(s_id + str(buf)) if buf == 0: sp1 = run( [call, cname, caddr, 'GetSupplierInfo', stuck_flew[0][0]])[0] u_list[0][1].append('制造') u_list[0][2].append(sp1) elif buf < len(stuck_flew[0]): sp1 = run([ call, cname, caddr, 'GetSupplierInfo', stuck_flew[0][buf - 1] ])[0] sp2 = run( [call, cname, caddr, 'GetSupplierInfo', stuck_flew[0][buf]])[0] u_list[0][1].append('物流') u_list[0][2].append(sp1 + ' -> ' + sp2) add_link([s_id + str(buf - 1), s_id + str(buf)]) else: sp1 = run([ call, cname, caddr, 'GetSupplierInfo', stuck_flew[0][buf - 1] ])[0] u_list[0][1].append('使用') u_list[0][2].append(sp1) add_link([s_id + str(buf - 1), s_id + str(buf)]) u_list[0][3].append(timestamp_to_format(trs_time)) place.append(level + buf) buf += 1 make_info = run([call, cname, caddr, 'GetMakeInfo', s_id]) print(make_info) left = level - 1 right = level + buf for s_f in make_info[0]: if s_f != pr_id: newbf = make_list_ex(s_id, s_f, left, False) add_link([s_f + str(newbf - 1), s_id + '0']) if mode and make_info[1]: make_list_ex(s_id, make_info[1][0], right, True) print('=================' + make_info[1][0] + '=======================' + s_id + str(buf - 1)) add_link([s_id + str(buf - 1), make_info[1][0] + '0']) return buf
def transfer_stuck(): if 'username' in session: if session['type'] == 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] user['stn'] = run([call, cname, caddr, 'GetSupplierStuck', user['id']])[0] if request.method == 'POST': if request.form['num'] == '': return render_template("transfer_stuck.html", user=user, error=2) if request.form['name'] == '': return render_template("transfer_stuck.html", user=user, error=3) stuck_id = run([ send, cname, caddr, 'CreateStuck', user['id'], request.form['num'], request.form['name'], int(time.mktime(datetime.datetime.now().timetuple())) ])[0] if stuck_id == '0x0000000000000000000000000000000000000000': return render_template("transfer_stuck.html", user=user, error=1) else: for s in user['stn']: if s in request.form: run([ send, cname, caddr, 'AddMaterials', user['id'], s, stuck_id ]) run([ send, cname, caddr, 'DeleteStuck', user['id'], s, int( time.mktime( datetime.datetime.now().timetuple())) ]) return render_template("transfer_stuck.html", user=user, error=-1, au=stuck_id) return render_template("transfer_stuck.html", user=user, error=0) else: return redirect(url_for('login'))
def add_user(): if 'username' in session: if session['type'] != 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] supplier_list = list(run([call, cname, caddr, 'GetSupplierList'])[0]) if request.method == 'POST': if request.form['username'] == '': return render_template("add_user.html", user=user, error=2, slist=supplier_list) supplier_id = run([ send, cname, caddr, 'CreateSupplier', request.form['username'], request.form['type'] ])[0] if supplier_id in supplier_list: supplier_list.remove(supplier_id) if supplier_id == '0x0000000000000000000000000000000000000000': return render_template("add_user.html", user=user, error=1, slist=supplier_list) for sp in supplier_list: if sp != supplier_id: if 'prior' + sp in request.form: run([ send, cname, caddr, 'LinkSupplier', sp, supplier_id ]) elif 'next' + sp in request.form: run([ send, cname, caddr, 'LinkSupplier', supplier_id, sp ]) return render_template("add_user.html", user=user, error=-1, slist=supplier_list, au=request.form['username'], au_id=supplier_id) return render_template("add_user.html", user=user, error=0, slist=supplier_list) else: return redirect(url_for('login'))
def del_user(): if 'username' in session: if session['type'] != 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] if request.method == 'POST': if request.form['username'] == '': return render_template("del_user.html", user=user, error=2) if run([ send, cname, caddr, 'DeleteSupplier', request.form['username'] ])[0]: return render_template("del_user.html", user=user, error=-1, au=request.form['username']) else: return render_template("del_user.html", user=user, error=1) return render_template("del_user.html", user=user, error=0) else: return redirect(url_for('login'))
def edit_balance(): if 'username' in session: if session['type'] != 0: return redirect(url_for('index')) user = {} user['id'] = session['id'] user['username'] = session['username'] user['type'] = session['type'] if request.method == 'POST': if request.form['id'] == '': return render_template("edit_balance.html", user=user, error=2) if run([ send, cname, caddr, 'ChangeBalance', request.form['id'], request.form['delta'] ])[0]: return render_template("edit_balance.html", user=user, error=-1, au=request.form['id']) else: return render_template("edit_balance.html", user=user, error=1) return render_template("edit_balance.html", user=user, error=0) else: return redirect(url_for('login'))
def __init(): global u_list, place, node_list u_list = [[[], [], [], []], [[], []]] place = [] node_list = list(run([call, cname, caddr, 'GetSupplierList'])[0])