123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import pymysql;
- from DBUtils.PooledDB import PooledDB;
- import logApi
- logger = logApi.logger
- import os
- from ini_op import Config;
- import json
- import time
- import requests
- import sys
- import traceback
- base_dir = os.path.dirname(os.path.abspath(__file__))
- config = Config(base_dir+"/config.ini");
- tokenApiUrl = config.get("baseconf", "tokenApiUrl");
- pwd = config.get("baseconf", "pwd");
- db = config.get("baseconf", "db");
- pool = PooledDB(pymysql,10,host='localhost',user='root',passwd='wdshy1gxf',db=db,port=3306,charset="utf8");
- # pool = PooledDB(pymysql,10,host='localhost',user='root',passwd='$661883$',db=db,port=3306,charset="utf8");
- class UserController():
- def getConn(self):
- self.conn = pool.connection();
- self.cursor = self.conn.cursor();
- # 获取当前所有商户
- def getUser(self):
- try:
- res=[];
- self.conn=pool.connection();
- self.cursor = self.conn.cursor();
- sql = "select * from sys_user where `role_id` = 4";
- count = self.cursor.execute(sql);
- for i in range(count):
- user_info={};
- user_info['user_name']=self.cursor.fetchone()[2];
- res.append(user_info);
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- self.cursor.close();
- self.conn.close();
- return res;
- #现在需要getModelByUserAndNum以及getFieldByUserAndModel
- # def getModelByNum(self,product_num):
- # try:
- # res=[];
- # self.conn=pool.connection();
- # self.cursor = self.conn.cursor();
- #
- # sql = "select * from user_model where `product_num` = '"+product_num+"' and model_state ='已上线'" ;
- # count = self.cursor.execute(sql);
- # for i in range(count):
- # data=self.cursor.fetchone();
- #
- # except:
- # logger.error(traceback.print_exc())
- # logger.error(traceback.format_exc())
- # self.cursor.close();
- # self.conn.close();
- def getModelByUserAndNum(self,user_list,product_num):
- product_num = product_num;
- try:
- res=[];
- self.conn=pool.connection();
- self.cursor = self.conn.cursor();
- for k in range(len(user_list)-1):
- # sql = "select * from user_model where `user_name` = '"+user_list[k]['user_name']+"' and model_state='审核通过'" ;
- sql = "select * from user_model where `user_name` = '" + user_list[k][
- 'user_name'] +"' and product_num='" + product_num + "' and model_state='已上线'"
- count = self.cursor.execute(sql);
- model_list=[]
- for i in range(count):
- data=self.cursor.fetchone()
- model_info={}
- model_info["model_name"]=data[2]
- model_info["product_num"]=data[3]
- model_info["model_type"]=data[7]
- model_info["other_data"]=data[8]
- model_list.append(model_info)
- # user_list[k]['model_name']=data[2];
- # # product_str=data[3];
- # # product_list=product_str.split(";");
- # user_list[k]['product_num']=data[3];
- user_list[k]["model_list"]=model_list;
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- self.cursor.close();
- self.conn.close();
- # return res;
- def getFieldByUserAndModel(self,user_list,model_name):
- try:
- res=[];
- self.conn=pool.connection();
- self.cursor = self.conn.cursor();
- for k in range(len(user_list)-1):
- sql = "select * from user_field where `user_name` = '"+user_list[k]['user_name']+ "' and model_name='" +model_name+ "' and field_state ='审核通过'" ;
- count = self.cursor.execute(sql);
- for i in range(count):
- data=self.cursor.fetchone();
- user_list[k]['field_data']=data[5];
- except:
- logger.error(traceback.print_exc())
- logger.error(traceback.format_exc())
- self.cursor.close();
- self.conn.close();
- userController=UserController();
- userController.getConn();
- user_list=userController.getUser();
- # print(user_list);
- #
- # userController.getModelByUserAndNum(user_list,);
- # # print(user_list);
- #
- # userController.getFieldByUser(user_list);
- # print(user_list);
- # print(res);
- # for i in res:
- # print(userController.getModelByUser(i));
- # for i in res:
- # print(userController.getFieldByUser(i));
|