├── README.md ├── conf ├── hjs_cms_db.sql ├── nginx │ └── hjs_cms.conf └── supervisor │ └── hjs_cms.conf ├── doc └── hjs_WEB_API.md ├── install ├── README.md ├── deploy_hjs_cms.sh ├── install_hjs_cms.sh ├── nginx │ └── hjs_cms.conf ├── persion.conf ├── publish_hjs_cms.py ├── secret.py ├── supervisor │ └── hjs_cms.conf ├── template_deal.py └── tools │ └── ssh.exp └── src ├── base ├── bs_base_cfg.py ├── bs_database_pid.py ├── bs_email.py ├── bs_log.py ├── bs_process.py ├── bs_syshead.py ├── bs_time.py └── bs_util.py ├── bean ├── hjs_custom.py ├── hjs_index.py ├── hjs_order.py ├── hjs_ps_order.py └── hjs_user.py ├── dao ├── hjs_custom_dao.py ├── hjs_order_dao.py ├── hjs_ps_order_dao.py └── hjs_user_dao.py ├── hjs_cfg.py └── web ├── sessions └── debbfa68ae475a5b8f82f961b149a19ef8526f5e ├── static ├── css │ ├── base.css │ ├── component.css │ ├── hack.css │ ├── haiersoft.css │ ├── login.css │ ├── print.css │ └── reset.css ├── images │ ├── aiwrap.png │ ├── common │ │ ├── clear.gif │ │ ├── ico01.png │ │ ├── ico02.png │ │ ├── ico03.png │ │ ├── ico04.gif │ │ ├── ico05.png │ │ ├── ico06.png │ │ ├── ico07.png │ │ ├── ico_arrow01.gif │ │ ├── ico_uer.gif │ │ ├── left.gif │ │ ├── logo.png │ │ ├── logo2.png │ │ ├── right.gif │ │ └── 懒人图库.txt │ └── web_login_bg.jpg └── js │ ├── classie.js │ ├── custom.js │ ├── index.js │ ├── jquery-1.10.1.min.js │ ├── modernizr.custom.js │ ├── order.js │ ├── order_today.js │ ├── others.js │ ├── popwin.js │ ├── select.js │ ├── side.js │ └── user.js ├── templates ├── custom_add.html ├── custom_edit.html ├── custom_list.html ├── custom_search.html ├── index.html ├── login.html ├── order_add.html ├── order_all.html ├── order_cancel.html ├── order_edit.html ├── order_search.html ├── order_today.html ├── user_add.html ├── user_edit.html └── user_list.html ├── url.py ├── viewset ├── __init__.py ├── view_base.py ├── view_custom.py ├── view_index.py ├── view_login.py ├── view_order.py ├── view_user.py └── web_util.py └── web_main.py /README.md: -------------------------------------------------------------------------------- 1 | ##基于python开发的简易订单系统 2 | 3 | 4 | 这是受朋友之托帮忙开发的一个简易的订单系统。基本也没什么有创新可谈的,主要是它基于Python开发的高效特色框架。得益于实习期间跟随导师学了不要东西,该框架也是从他那学来的,在此十分感谢,算是领我这个菜鸟上道了^_^!整个开发差不多花了一周时间,从数据库,后台到前端,算是坑了一把,不过毕竟还是要经历才有收获。 5 | 6 | ### 1. 框架简述 7 | 8 | 该系统前端采用了RestAPI的设计,使用jQuery异步调取后端WEB接口的形式获取json的数据并渲染展示。 9 | 后端框架采用了base(基础类库层)、bean(后台逻辑层)、dao(数据持久层)、web(view展示层)的四层结构,代码结构清晰,高度模块化设计,使得开发起来高效、实用、可靠,并且便于扩展和维护。 10 | 11 | 12 | 下面是该系统的源码结构: 13 | ``` 14 | hjs_cms 15 | ├── bin/ 16 | ├── conf/ 17 | ├── src 18 | │   ├── base/ 19 | │   ├── bean/ 20 | │   ├── dao/ 21 | │   ├── hjs_cfg.py 22 | │   └── web 23 | │   ├── sessions/ 24 | │   ├── static 25 | │   │   ├── css/ 26 | │   │   ├── images/ 27 | │   │   └── js/ 28 | │   ├── templates/ 29 | │   ├── url.py 30 | │   ├── viewset/ 31 | │   └── web_main.py 32 | └── test/ 33 | ``` 34 | 35 | ### 2. 框架亮点 36 | 37 | * 高度模块化、结构化设计 38 | * 双返回值设计结构确保安全、可靠 39 | * 采用fabric自动化部署 40 | * 采用nose单元测试框架 41 | * 实现了标准规范的log模块 42 | * web.py 设计RestAPI 43 | * 采用JQuery 调用WEB API渲染展示 44 | * 采用nginx + gunicorn + web.py + supervisor 部署运行 45 | 46 | ### 3. 自动化部署 47 | 48 | 进入hjs_cms/install目录下,修改好远程服务器的业务配置环境(persion.conf)和远程服务器的ssh配置(secret.py),并行: 49 | ``` 50 | python publish_hjs_cms.py deploy $srv_ip 51 | ``` 52 | 53 | 注意: 54 | 1. 执行publish_hjs_cms.py之前需要将/tools/ssh.exp 添加到本地环变量中 55 | 2. 在publish_hjs_cms.py脚本最后有重启supervisor的命令,这需要root权限才可以重启! 56 | 3. 日志目录配置在根目录下logs下,重新部署后可能需要创建此目录 57 | 58 | 59 | -------------------------------------------------------------------------------- /conf/hjs_cms_db.sql: -------------------------------------------------------------------------------- 1 | -- Adminer 4.2.1 MySQL dump 2 | 3 | SET NAMES utf8; 4 | SET time_zone = '+00:00'; 5 | SET foreign_key_checks = 0; 6 | SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; 7 | 8 | DROP TABLE IF EXISTS `tb_custom`; 9 | CREATE TABLE `tb_custom` ( 10 | `cid` int(10) NOT NULL AUTO_INCREMENT, 11 | `name` varchar(50) NOT NULL, 12 | `address` varchar(100) NOT NULL, 13 | `phone` varchar(50) DEFAULT NULL, 14 | `ctype` enum('N','O') NOT NULL DEFAULT 'N', 15 | `class` varchar(10) DEFAULT 'A', 16 | `status` enum('normal','cancel','delete') NOT NULL DEFAULT 'normal', 17 | `remark` text, 18 | `insert_tm` datetime DEFAULT NULL, 19 | PRIMARY KEY (`cid`) 20 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 21 | 22 | 23 | DROP TABLE IF EXISTS `tb_order`; 24 | CREATE TABLE `tb_order` ( 25 | `oid` int(10) NOT NULL AUTO_INCREMENT, 26 | `cid` int(10) NOT NULL, 27 | `name` varchar(50) NOT NULL, 28 | `otype` varchar(10) NOT NULL DEFAULT 'A', 29 | `order_tm` datetime NOT NULL, 30 | `start_tm` date NOT NULL, 31 | `end_tm` date NOT NULL, 32 | `amount` float NOT NULL, 33 | `cash` float NOT NULL, 34 | `status` enum('normal','stop') NOT NULL DEFAULT 'normal', 35 | `remark` text NOT NULL, 36 | `insert_tm` datetime NOT NULL, 37 | PRIMARY KEY (`oid`), 38 | KEY `cid` (`cid`), 39 | CONSTRAINT `tb_order_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `tb_custom` (`cid`) 40 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 41 | 42 | 43 | DROP TABLE IF EXISTS `tb_ps_order`; 44 | CREATE TABLE `tb_ps_order` ( 45 | `pid` int(11) NOT NULL AUTO_INCREMENT, 46 | `oid` int(10) NOT NULL, 47 | `cid` int(10) NOT NULL, 48 | `name` varchar(50) NOT NULL, 49 | `pause_tm` date NOT NULL, 50 | `remark` text NOT NULL, 51 | `insert_tm` datetime NOT NULL, 52 | PRIMARY KEY (`pid`), 53 | KEY `oid` (`oid`), 54 | KEY `cid` (`cid`), 55 | CONSTRAINT `tb_ps_order_ibfk_1` FOREIGN KEY (`oid`) REFERENCES `tb_order` (`oid`), 56 | CONSTRAINT `tb_ps_order_ibfk_2` FOREIGN KEY (`cid`) REFERENCES `tb_custom` (`cid`) 57 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 58 | 59 | 60 | DROP TABLE IF EXISTS `tb_user`; 61 | CREATE TABLE `tb_user` ( 62 | `uid` int(10) NOT NULL AUTO_INCREMENT, 63 | `nickname` varchar(50) NOT NULL, 64 | `username` varchar(50) NOT NULL, 65 | `password` varchar(50) NOT NULL, 66 | `phone` varchar(50) DEFAULT NULL, 67 | `email` varchar(50) DEFAULT NULL, 68 | `privilege` int(1) NOT NULL DEFAULT '1', 69 | `lastlogin` datetime DEFAULT NULL, 70 | PRIMARY KEY (`uid`) 71 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 72 | 73 | 74 | -- 2017-01-02 09:56:02 75 | -------------------------------------------------------------------------------- /conf/nginx/hjs_cms.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name hjs.s0nnet.com; 4 | 5 | location / { 6 | root /home/project/hjs_cms/src/web/; 7 | proxy_pass http://127.0.0.1:8080; 8 | proxy_set_header X-Real-IP $remote_addr; 9 | proxy_set_header Host $host; 10 | # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 11 | proxy_set_header X-Forwarded-For $remote_addr; 12 | } 13 | 14 | location /static { 15 | root /home/project/hjs_cms/src/web/; 16 | } 17 | 18 | location /templates { 19 | root /home/project/hjs_cms/src/web/templates/; 20 | } 21 | 22 | error_page 500 502 503 504 /50x.html; 23 | location = /50x.html { 24 | root /usr/share/nginx/html; 25 | } 26 | 27 | charset utf-8; 28 | access_log /var/log/nginx/hjs.s0nnet.com.access.log; 29 | error_log /var/log/nginx/hjs.s0nnet.com.error.log; 30 | } 31 | -------------------------------------------------------------------------------- /conf/supervisor/hjs_cms.conf: -------------------------------------------------------------------------------- 1 | [program:hjs_cms] 2 | command=gunicorn web_main:application --chdir /home/project/hjs_cms/src/web/ -b localhost:5000 -n hjs_cms -w 10 --timeout 120 --access-logfile /home/project/hjs_cms/logs/hjs_cms_web_access.log --error-logfile /home/project/hjs_cms/logs/hjs_cms_web_error.log 3 | autorestart=true 4 | autostart=false 5 | stderr_logfile= /home/project/hjs_cms/logs/hjs_cms_web_stdout.log 6 | stdout_logfile= /home/project/hjs_cms/logs/hjs_cms_web_stderr.log 7 | numprocs=1 8 | numprocs_start=0 9 | user=s0nnet 10 | -------------------------------------------------------------------------------- /install/README.md: -------------------------------------------------------------------------------- 1 | #### 自动化部署脚本 2 | 3 | 4 | ##### 1. 脚本说明: 5 | 6 | * nginx/ nginx配置 7 | * supervisor/ supervisor配置 8 | * tools/ ssh.exp执ssh的脚本 9 | * persion.conf 远程服务器的业务配置环境 10 | * publish_hjs_cms.py 自动化部署脚本主执行脚本 11 | * secret.py 远程服务器的ssh配置信息 12 | * template_deal.py 对配置(persion.conf)的解析 13 | 14 | 15 | 16 | ##### 2. 自动化部署 17 | ``` 18 | python publish_hjs_cms.py deploy $srv_ip 19 | ``` 20 | 21 | 注意: 22 | 1. 执行publish_hjs_cms.py之前需要将/tools/ssh.exp 添加到本地环变量中 23 | 2. 在publish_hjs_cms.py脚本最后有重启supervisor的命令,这需要root权限才可以重启! 24 | 3. 日志目录配置在根目录下logs下,重新部署后可能需要创建此目录 25 | 26 | -------------------------------------------------------------------------------- /install/deploy_hjs_cms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | 5 | #global value 6 | CUR_VERSION="1.0" 7 | LOG_FILE=deploy_hjs_cms.log 8 | NGINXi_PATH=/usr/local/nginx/sbin/nginx 9 | MYSQL_PATH=/usr/local/mysql 10 | 11 | 12 | 13 | # 运行状态日志 14 | log_to_file() 15 | { 16 | echo "$1" 17 | echo "$1" >> ${LOG_FILE} 18 | } 19 | 20 | # 运行状态结果日志 21 | log_result() 22 | { 23 | if [ $2 -ne 0 ];then 24 | log_to_file "[-] $1 faild!" 25 | else 26 | log_to_file "[+] $1 successed!" 27 | fi 28 | } 29 | 30 | # 文件备份 31 | backup_file() 32 | { 33 | cp -f $1 $1.bak 34 | } 35 | 36 | 37 | # 安装系统基本依赖库 38 | install_basic_suite() 39 | { 40 | cur_module="install_basic_suite" 41 | log_to_file "[*] ${cur_module}" 42 | suite=( 43 | "gcc --version" 44 | "g++ --version" 45 | "pip --veriosn" 46 | "virtualenv --version" 47 | "wget --version" 48 | ) 49 | length=${#suite[@]} 50 | 51 | yum install -y gcc gcc-c++ 52 | yum install -y pip 53 | yum install -y mysql-devel 54 | yum install -y pyhton-pip 55 | yum install -y python-virtualenv 56 | yum install -y wget 57 | 58 | for((i=0; i<$length; i++)) 59 | do 60 | ${suite[$i]} > /dev/null 61 | check_result ${cur_module} \ 62 | "[-] install failed: ${suite[$i]}" \ 63 | "[+] installed: ${suite[$i]}" 64 | done 65 | 66 | log_result ${cur_module} 0 67 | } 68 | 69 | # 安装Nginx 70 | install_nginx() 71 | { 72 | cur_module="install nginx" 73 | log_to_file "[*] ${cur_module}" 74 | 75 | ${NGINX_PATH} -v > /dev/null 76 | if [ $? -ne 0 ];then 77 | log_to_file "[!] no nginx installed! installing ..." 78 | yum install -y nginx 79 | else 80 | log_to_file "[!] nginx has realdy installed!" 81 | fi 82 | 83 | ${NGINX_PATH} > /dev/null 84 | if [ $? -ne 0];then 85 | nginx 86 | fi 87 | 88 | log_result ${cur_module} 0 89 | } 90 | 91 | # 安装MySQL 92 | install_mysql() 93 | { 94 | cur_module="install mysql" 95 | log_to_file "[*] ${cur_module}" 96 | 97 | mysql --version > /dev/null 98 | if [ $? -ne 0 ];then 99 | log_to_file "[!] no mysql intsalled! installing ..." 100 | yum install -y mysql-server mysql mysql-devel 101 | fi 102 | 103 | systemctl enable mysqld 104 | systemctl start mysqld.service 105 | if [ $? -ne 0 ];then 106 | log_to_file "[!] start mysqld service failed!" 107 | fi 108 | 109 | log_result ${cur_module} 0 110 | } 111 | 112 | # 安装python_web环境 113 | install_web_suite() 114 | { 115 | cur_module="install_web_suite" 116 | log_to_file "[*] ${cur_module}" 117 | 118 | suite=( 119 | "supervisord -v" 120 | ) 121 | length=${#suite[@]} 122 | yum install -y supervisor 123 | pip install web.py 124 | 125 | for((i=0; i<$length; i++)) 126 | do 127 | ${suite[$i]} > /dev/null 128 | check_result ${cur_module} \ 129 | "[-] install faild: ${suite[$i]}" \ 130 | "[+] installed: ${suite[$i]}" 131 | done 132 | 133 | log_result ${cur_module} 0 134 | } 135 | 136 | # 配置iptables 137 | setup_iptables() 138 | { 139 | cur_module="setup_iptables" 140 | log_to_file "[*] ${cur_module}" 141 | 142 | #install iptables 143 | yum install iptables-services 144 | check_result ${cur_module} \ 145 | "[-] install iptabes failed" \ 146 | "[+] installed iptables!" 147 | 148 | log_to_file "[*] start iptables" 149 | systemctl enable iptables; 150 | systemctl enable ip6tables; 151 | systemctl start iptables; 152 | systemctl start ip6tables; 153 | iptables -L 154 | iptables -F 155 | iptables -X 156 | 157 | log_to_file "[*] backup /etc/sysctl.conf" 158 | backup_file /etc/sysctl.conf 159 | } 160 | 161 | # 添加系统账户 162 | add_web_user() 163 | { 164 | cur_module="add_user" 165 | log_to_file "[*] ${cur_module}" 166 | 167 | # add mysql user 168 | userdel mysql 169 | groupadd mysql 170 | useradd -r -g mysql mysql 171 | check_result ${cur_module} \ 172 | "[-] useradd mysql failed" \ 173 | "[+] useradd mysql successed" 174 | 175 | #add web user 176 | userdel hjs_cms 177 | groupadd hjs_cms 178 | useradd -g hjs_cms hjs_cms -p hjs@!cms 179 | check_result ${cur_module} \ 180 | "[-] useradd hjs_cms failed" \ 181 | "[+] useradd hjs_cms successed" 182 | 183 | log_result ${cur_module} 0 184 | } 185 | 186 | # 配置web环境 187 | config_web_suite() 188 | { 189 | cur_module="config_web_suite" 190 | log_to_file "[*] ${cur_module}" 191 | 192 | 193 | 194 | } 195 | 196 | 197 | install_hjs_cms() 198 | { 199 | install_basic_suite 200 | install_nginx 201 | install_mysql 202 | install_web_suite 203 | setup_iptables 204 | add_web_user 205 | config_web_suite 206 | start_services 207 | } 208 | 209 | case "$1" in 210 | deploy) 211 | deploy_hjs_cms 212 | ;; 213 | install) 214 | install_hjs_cms 215 | ;; 216 | service) 217 | restart_service 218 | ;; 219 | *) 220 | echo "args error: $1" 221 | exit -1 222 | ;; 223 | esac 224 | -------------------------------------------------------------------------------- /install/install_hjs_cms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | 5 | #global value 6 | CUR_VERSION="1.0" 7 | LOG_FILE=deploy_hjs_cms.log 8 | NGINXi_PATH=/usr/local/nginx/sbin/nginx 9 | MYSQL_PATH=/usr/local/mysql 10 | 11 | 12 | 13 | # 运行状态日志 14 | log_to_file() 15 | { 16 | echo "$1" 17 | echo "$1" >> ${LOG_FILE} 18 | } 19 | 20 | # 运行状态结果日志 21 | log_result() 22 | { 23 | if [ $2 -ne 0 ];then 24 | log_to_file "[-] $1 faild!" 25 | else 26 | log_to_file "[+] $1 successed!" 27 | fi 28 | } 29 | 30 | # 文件备份 31 | backup_file() 32 | { 33 | cp -f $1 $1.bak 34 | } 35 | 36 | 37 | # 安装系统基本依赖库 38 | install_basic_suite() 39 | { 40 | cur_module="install_basic_suite" 41 | log_to_file "[*] ${cur_module}" 42 | suite=( 43 | "gcc --version" 44 | "g++ --version" 45 | "pip --veriosn" 46 | "virtualenv --version" 47 | "wget --version" 48 | ) 49 | length=${#suite[@]} 50 | 51 | yum install -y gcc gcc-c++ 52 | yum install -y pip 53 | yum install -y mysql-devel 54 | yum install -y pyhton-pip 55 | yum install -y python-virtualenv 56 | yum install -y wget 57 | 58 | for((i=0; i<$length; i++)) 59 | do 60 | ${suite[$i]} > /dev/null 61 | check_result ${cur_module} \ 62 | "[-] install failed: ${suite[$i]}" \ 63 | "[+] installed: ${suite[$i]}" 64 | done 65 | 66 | log_result ${cur_module} 0 67 | } 68 | 69 | # 安装Nginx 70 | install_nginx() 71 | { 72 | cur_module="install nginx" 73 | log_to_file "[*] ${cur_module}" 74 | 75 | ${NGINX_PATH} -v > /dev/null 76 | if [ $? -ne 0 ];then 77 | log_to_file "[!] no nginx installed! installing ..." 78 | yum install -y nginx 79 | else 80 | log_to_file "[!] nginx has realdy installed!" 81 | fi 82 | 83 | ${NGINX_PATH} > /dev/null 84 | if [ $? -ne 0];then 85 | nginx 86 | fi 87 | 88 | log_result ${cur_module} 0 89 | } 90 | 91 | # 安装MySQL 92 | install_mysql() 93 | { 94 | cur_module="install mysql" 95 | log_to_file "[*] ${cur_module}" 96 | 97 | mysql --version > /dev/null 98 | if [ $? -ne 0 ];then 99 | log_to_file "[!] no mysql intsalled! installing ..." 100 | yum install -y mysql-server mysql mysql-devel 101 | fi 102 | 103 | systemctl enable mysqld 104 | systemctl start mysqld.service 105 | if [ $? -ne 0 ];then 106 | log_to_file "[!] start mysqld service failed!" 107 | fi 108 | 109 | log_result ${cur_module} 0 110 | } 111 | 112 | # 安装python_web环境 113 | install_web_suite() 114 | { 115 | cur_module="install_web_suite" 116 | log_to_file "[*] ${cur_module}" 117 | 118 | suite=( 119 | "supervisord -v" 120 | ) 121 | length=${#suite[@]} 122 | yum install -y supervisor 123 | pip install web.py 124 | 125 | for((i=0; i<$length; i++)) 126 | do 127 | ${suite[$i]} > /dev/null 128 | check_result ${cur_module} \ 129 | "[-] install faild: ${suite[$i]}" \ 130 | "[+] installed: ${suite[$i]}" 131 | done 132 | 133 | log_result ${cur_module} 0 134 | } 135 | 136 | # 配置iptables 137 | setup_iptables() 138 | { 139 | cur_module="setup_iptables" 140 | log_to_file "[*] ${cur_module}" 141 | 142 | #install iptables 143 | yum install iptables-services 144 | check_result ${cur_module} \ 145 | "[-] install iptabes failed" \ 146 | "[+] installed iptables!" 147 | 148 | log_to_file "[*] start iptables" 149 | systemctl enable iptables; 150 | systemctl enable ip6tables; 151 | systemctl start iptables; 152 | systemctl start ip6tables; 153 | iptables -L 154 | iptables -F 155 | iptables -X 156 | 157 | log_to_file "[*] backup /etc/sysctl.conf" 158 | backup_file /etc/sysctl.conf 159 | } 160 | 161 | # 添加系统账户 162 | add_web_user() 163 | { 164 | cur_module="add_user" 165 | log_to_file "[*] ${cur_module}" 166 | 167 | # add mysql user 168 | userdel mysql 169 | groupadd mysql 170 | useradd -r -g mysql mysql 171 | check_result ${cur_module} \ 172 | "[-] useradd mysql failed" \ 173 | "[+] useradd mysql successed" 174 | 175 | #add web user 176 | userdel hjs_cms 177 | groupadd hjs_cms 178 | useradd -g hjs_cms hjs_cms -p hjs@!cms 179 | check_result ${cur_module} \ 180 | "[-] useradd hjs_cms failed" \ 181 | "[+] useradd hjs_cms successed" 182 | 183 | log_result ${cur_module} 0 184 | } 185 | 186 | # 配置web环境 187 | config_web_suite() 188 | { 189 | cur_module="config_web_suite" 190 | log_to_file "[*] ${cur_module}" 191 | 192 | #deploy source code 193 | thisPath=`pwd` 194 | backup_file /home/project/hjs_cms/src 195 | cp $thisPath/../src /home/project/hjs_cms -R 196 | 197 | chown -R s0nnet:s0nnet /home/project/hjs_cms 198 | 199 | log_result ${cur_module} 0 200 | } 201 | 202 | # 启动web服务 203 | start_services() 204 | { 205 | cur_module="start_services" 206 | log_to_file "[*] ${cur_module}" 207 | 208 | service_list=( 209 | "mysql" 210 | "nginx" 211 | "supervisor" 212 | ) 213 | length=${#service_list[@]} 214 | 215 | for ((i=0; i<$length; i++)) 216 | do 217 | service=$(service_list[$i]) 218 | service $service start 219 | done 220 | 221 | log_result ${cur_module} 0 222 | } 223 | 224 | # 重启web服务 225 | restart_services() 226 | { 227 | cur_module="restart_services" 228 | log_to_file "[*] ${cur_module}" 229 | 230 | service_list=( 231 | "mysql" 232 | "nginx" 233 | "supervisor" 234 | ) 235 | length=${#service_list[@]} 236 | 237 | for ((i=0; i<$length; i++)) 238 | do 239 | service=${service_list[$i]} 240 | service $service stop 241 | service $service start 242 | done 243 | 244 | log_result ${cur_module} 0 245 | } 246 | 247 | install_hjs_cms() 248 | { 249 | install_basic_suite 250 | install_nginx 251 | install_mysql 252 | install_web_suite 253 | setup_iptables 254 | add_web_user 255 | config_web_suite 256 | start_services 257 | } 258 | 259 | case "$1" in 260 | deploy) 261 | deploy_hjs_cms 262 | ;; 263 | install) 264 | install_hjs_cms 265 | ;; 266 | service) 267 | restart_service 268 | ;; 269 | *) 270 | echo "args error: $1" 271 | exit -1 272 | ;; 273 | esac 274 | -------------------------------------------------------------------------------- /install/nginx/hjs_cms.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name hjs.s0nnet.com; 4 | 5 | location / { 6 | root /home/project/hjs_cms/src/web/; 7 | proxy_pass http://127.0.0.1:8080; 8 | proxy_set_header X-Real-IP $remote_addr; 9 | proxy_set_header Host $host; 10 | # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 11 | proxy_set_header X-Forwarded-For $remote_addr; 12 | } 13 | 14 | location /static { 15 | root /home/project/hjs_cms/src/web/; 16 | } 17 | 18 | location /templates { 19 | root /home/project/hjs_cms/src/web/templates/; 20 | } 21 | 22 | error_page 500 502 503 504 /50x.html; 23 | location = /50x.html { 24 | root /usr/share/nginx/html; 25 | } 26 | 27 | charset utf-8; 28 | access_log /var/log/nginx/hjs.s0nnet.com.access.log; 29 | error_log /var/log/nginx/hjs.s0nnet.com.error.log; 30 | } 31 | -------------------------------------------------------------------------------- /install/persion.conf: -------------------------------------------------------------------------------- 1 | 222.24.xx.xx CUR_ENV = EnvEnum.T_ONLINE 2 | 222.24.xx.xx BaseConf.SQL_HOST = "222.24.xx.xx" 3 | 222.24.xx.xx BaseConf.SQL_USER = "hjs_cms_username" 4 | 222.24.xx.xx BaseConf.SQL_PASSWD = "hjs_cms_passwd" 5 | 222.24.xx.xx BaseConf.SQL_DB = "hjs_cms_db" 6 | 7 | -------------------------------------------------------------------------------- /install/publish_hjs_cms.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2015-12-21 5 | # desc: publish main 6 | 7 | 8 | import sys 9 | import os 10 | import datetime 11 | from template_deal import * 12 | from secret import * 13 | 14 | 15 | class PublishHjsCmsWeb: 16 | 17 | def __init__(self): 18 | self.app_name = "hjs_cms" 19 | self.conf_file = "hjs_cfg.py" 20 | self.localPath = "/tmp/publish_dir" 21 | 22 | self.code_rep = "git clone git@github.com:Lingerhk/hjs_cms.git" 23 | self.code_update = "git pull origin master" 24 | 25 | self.remote_path = "/home/project" 26 | self.remote_owner = "s0nnet" 27 | self.remote_enum = "online" 28 | 29 | 30 | def _cmd_exec(self, cmd): 31 | iRet = os.system(cmd) 32 | print cmd 33 | if iRet < 0: 34 | os.write(sys.stderr.fileno(), "cmd: %s ERR\n" %(cmd)) 35 | return False, "cmd: %s ERR\n" %(cmd) 36 | return True, "" 37 | 38 | def _ssh_cp(self, ip, fpath, dstpath): 39 | cmd = "ssh.exp %s scp %s %s@%s:%s" %(self.passwd, fpath, self.user, ip, dstpath) 40 | return self._cmd_exec(cmd) 41 | 42 | def _ssh_cmd(self, ip, cmd): 43 | cmd = "ssh.exp %s ssh %s@%s \"%s\"" %(self.passwd, self.user, ip, cmd) 44 | return self._cmd_exec(cmd) 45 | 46 | def _up_source(self): 47 | appPath = "%s_source/%s" %(self.localPath, self.app_name) 48 | if not os.path.exists(appPath): 49 | bRet,sRet = self._cmd_exec("%s %s" %(self.code_rep, appPath)) 50 | if not bRet: return bRet, sRet 51 | else: 52 | bRet,sRet = self._cmd_exec("cd %s; %s; cd -" %(appPath, self.code_update)) 53 | if not bRet: return bRet, sRet 54 | 55 | return True, "" 56 | 57 | 58 | def _get_source_code(self): 59 | bRet, sRet = self._up_source() 60 | if not bRet: return bRet, sRet 61 | 62 | appPath = "%s_source/%s" %(self.localPath, self.app_name) 63 | dstPath = "%s/%s" %(self.localPath, self.app_name) 64 | if os.path.exists(dstPath): os.system("rm -rf %s" %(dstPath)) 65 | cmd = "cp %s %s -r" %(appPath, dstPath) 66 | os.system(cmd) 67 | 68 | cmd = "find %s -name .svn | xargs rm -rf" %(dstPath) 69 | os.system(cmd) 70 | cmd = "find %s -name .git | xargs rm -rf" %(dstPath) 71 | os.system(cmd) 72 | cmd = "find %s -name .idea | xargs rm -rf" %(dstPath) 73 | os.system(cmd) 74 | 75 | return True, "" 76 | 77 | 78 | def _build_dst(self): 79 | dstPath = "%s/%s" %(self.localPath, self.app_name) 80 | tarCmd = "cd %s;tar -zcvf %s.tar.gz %s" %(self.localPath, dstPath, self.app_name) 81 | os.system(tarCmd) 82 | return True, None 83 | 84 | 85 | def _replace_conf(self, ip): 86 | persionConf = "persion.conf" 87 | dstConfPath = "%s/%s/src/%s" %(self.localPath, self.app_name, self.conf_file) 88 | confTemplate = "%s/%s/src/%s.template" %(self.localPath, self.app_name, self.conf_file) 89 | os.rename(dstConfPath, confTemplate) 90 | bRet = conf_produce(persionConf, confTemplate, dstConfPath, ip) 91 | os.unlink(confTemplate) 92 | if not bRet: return False, "ERR" 93 | return True, "" 94 | 95 | 96 | def _package(self, ip): 97 | if not os.path.exists(self.localPath): 98 | bRet, sRet = self._cmd_exec("mkdir -p %s" %(self.localPath)) 99 | if not bRet: return bRet, sRet 100 | if not os.path.exists(self.localPath): 101 | return False, "ERR" 102 | 103 | #get source 104 | bRet, sRet = self._get_source_code() 105 | if not bRet: return bRet, sRet 106 | 107 | # replace conf 108 | bRet, sRet = self._replace_conf(ip) 109 | if not bRet: return bRet, sRet 110 | 111 | # build dst 112 | bRet, sRet = self._build_dst() 113 | if not bRet: return bRet, sRet 114 | 115 | return True, "" 116 | 117 | 118 | def _load_conf(self, ip): 119 | confJson = get_srv_conf(self.remote_enum, ip) 120 | if not confJson: 121 | os.write(sys.stderr.fileno(), "ip: %s not conf\n" %(ip)) 122 | return False, "ERR" 123 | 124 | if not confJson.has_key("user"): 125 | os.write(sys.stderr.fileno(), "confJson: %s not user\n" %(str(confJson))) 126 | return False, "ERR" 127 | self.user = confJson["user"] 128 | 129 | if not confJson.has_key("passwd"): 130 | os.write(sys.stderr.fileno(), "confJson: %s not passwd\n" %(str(confJson))) 131 | return False, "ERR" 132 | self.passwd = confJson["passwd"] 133 | 134 | return True, "" 135 | 136 | 137 | def _unzip_package(self, ip, version): 138 | # backup old code 139 | cmd = "cd %s; mv %s %s_%s" %(self.remote_path, self.app_name, self.app_name, version) 140 | bRet, sRet = self._ssh_cmd(ip, cmd) 141 | if not bRet: return False, sRet 142 | 143 | # unzip 144 | cmd = 'cd %s; tar -xvf %s_%s.tar.gz; chown %s.%s %s -R' %(self.remote_path, self.app_name, version, self.remote_owner, self.remote_owner, self.app_name) 145 | bRet, sRet = self._ssh_cmd(ip, cmd) 146 | if not bRet: return False, sRet 147 | 148 | return True, "" 149 | 150 | def _send_package(self, ip): 151 | # send 152 | version = (datetime.datetime.now() - datetime.timedelta(0)).strftime("%Y%m%d") 153 | sourcePath = "%s/%s.tar.gz" %(self.localPath, self.app_name) 154 | dstPath = "%s/%s_%s.tar.gz" %(self.remote_path, self.app_name, version) 155 | bRet, sRet = self._ssh_cp(ip, sourcePath, dstPath) 156 | if not bRet: return bRet, sRet 157 | 158 | # prep srv env 159 | bRet, sRet = self._unzip_package(ip, version) 160 | if not bRet: return bRet, sRet 161 | 162 | return True, "" 163 | 164 | 165 | def _start_srv(self, ip): 166 | cmd = "supervisorctl restart %s" % (self.app_name) 167 | bRet, sRet = self._ssh_cmd(ip, cmd) 168 | if not bRet: return False, sRet 169 | return True, "" 170 | 171 | 172 | def deploy(self, ip): 173 | # get srv conf 174 | bRet, sRet = self._load_conf(ip) 175 | if not bRet: return bRet, sRet 176 | 177 | # package 178 | bRet, sRet = self._package(ip) 179 | if not bRet: return bRet, sRet 180 | 181 | # send package 182 | bRet, sRet = self._send_package(ip) 183 | if not bRet: return bRet, sRet 184 | 185 | # start 186 | bRet, sRet = self._start_srv(ip) 187 | if not bRet: return bRet, sRet 188 | 189 | return True, "" 190 | 191 | 192 | def _install_conf(self, ip): 193 | return True, "" 194 | 195 | 196 | def install(self, ip): 197 | # get srv conf 198 | bRet, sRet = self._load_conf(ip) 199 | if not bRet: return bRet, sRet 200 | 201 | # install conf 202 | bRet, sRet = self._install_conf(ip) 203 | if not bRet: return bRet, sRet 204 | 205 | bRet, sRet = self.deploy(ip) 206 | if not bRet: return bRet, sRet 207 | 208 | return True, "" 209 | 210 | 211 | if __name__ == "__main__": 212 | 213 | if len(sys.argv) < 3: 214 | os.write(sys.stderr.fileno(), "Useage: \n %s deploy $ip\n\n" %(sys.argv[0])) 215 | sys.exit() 216 | 217 | cmd = sys.argv[1] 218 | ip = sys.argv[2] 219 | 220 | hjsWeb = PublishHjsCmsWeb() 221 | if cmd == "deploy": 222 | print hjsWeb.deploy(ip) 223 | 224 | elif cmd == "install": 225 | print hjsWeb.install(ip) 226 | 227 | else: 228 | print "cmd:%s error!" %(cmd) 229 | sys.exit() 230 | 231 | 232 | -------------------------------------------------------------------------------- /install/secret.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2015-12-21 5 | # desc: web server conf ssh. 6 | # 7 | 8 | import sys 9 | 10 | srvSecretConfMap = { 11 | 'online' : { 12 | 'user' : 's0nnet', 13 | 'passwd' : 'you_ssh_srv_passwd' 14 | } 15 | } 16 | 17 | 18 | def get_srv_conf(env, sip): 19 | 20 | if srvSecretConfMap.has_key(sip): 21 | return srvSecretConfMap[sip] 22 | 23 | if srvSecretConfMap.has_key(env): 24 | return srvSecretConfMap[env] 25 | 26 | return None 27 | 28 | -------------------------------------------------------------------------------- /install/supervisor/hjs_cms.conf: -------------------------------------------------------------------------------- 1 | [program:hjs_cms] 2 | command=gunicorn web_main:application --chdir /home/project/hjs_cms/src/web/ -b localhost:5000 -n hjs_cms -w 10 --timeout 120 --access-logfile /home/project/hjs_cms/logs/hjs_cms_web_access.log --error-logfile /home/project/hjs_cms/logs/hjs_cms_web_error.log 3 | autorestart=true 4 | autostart=false 5 | stderr_logfile= /home/project/hjs_cms/logs/hjs_cms_web_stdout.log 6 | stdout_logfile= /home/project/hjs_cms/logs/hjs_cms_web_stderr.log 7 | numprocs=1 8 | numprocs_start=0 9 | user=s0nnet 10 | -------------------------------------------------------------------------------- /install/template_deal.py: -------------------------------------------------------------------------------- 1 | #-*- coding=utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2015-12-21 5 | # desc: 6 | 7 | 8 | import os 9 | import sys 10 | import traceback 11 | from subprocess import * 12 | 13 | def exec_cmd(cmd, bShell = True): 14 | content = "" 15 | try: 16 | p = Popen(cmd, bufsize = 4096, stdout = PIPE, shell = bShell) 17 | 18 | while True: 19 | cont = p.stdout.read() 20 | if cont == "": break 21 | content += cont 22 | retState = p.wait() 23 | 24 | return retState, content 25 | except Exception, e: 26 | sys.stderr.write("(%s)" %(traceback.format_exc())) 27 | return 255, "cmd(%s) err: %s" %(str(cmd), str(e)) 28 | 29 | def _get_local_ip(): 30 | cmd = "/sbin/ifconfig | grep 'inet addr:' | awk '{print $2}'" 31 | bRet, sRet = exec_cmd(cmd) 32 | if bRet != 0: return None 33 | 34 | lineList = sRet.split("\n") 35 | for line in lineList: 36 | ip = line[5 : ] 37 | if ip.startswith("10.") or ip.startswith("172."): 38 | return ip 39 | 40 | return None 41 | 42 | 43 | def _split_line(line): 44 | tmpList = [] 45 | strLen = len(line) 46 | s = 0 47 | while s < strLen: 48 | while s < strLen: 49 | if line[s] == '#': return True, tmpList 50 | if line[s] != ' ' and line[s] != '\t': break 51 | s += 1 52 | if s == strLen: return True, tmpList 53 | 54 | e = s + 1 55 | while e < strLen: 56 | if line[e] == '#': 57 | tmpList.append(line[s : e]) 58 | return True, tmpList 59 | if line[e] == ' ' or line[e] == '\t': break 60 | e += 1 61 | 62 | tmpList.append(line[s : e]) 63 | if e >= strLen: break 64 | 65 | s = e + 1 66 | 67 | return True, tmpList 68 | 69 | 70 | val_sep = " " 71 | def _load_person_conf(confPath, localIp): 72 | keyDict = {} 73 | try: 74 | lines = open(confPath, "r").readlines() 75 | for line in lines: 76 | if len(line) > 0 and line[len(line) - 1] == '\n': line = line[0 : len(line) - 1] 77 | if len(line) > 0 and line[len(line) - 1] == '\r': line = line[0 : len(line) - 1] 78 | bRet, tmpList = _split_line(line) 79 | if len(tmpList) < 3: continue 80 | ip = tmpList[0] 81 | key = tmpList[1] 82 | val = tmpList[2] 83 | i = 3 84 | while i < len(tmpList): 85 | val += val_sep + tmpList[i] 86 | i += 1 87 | 88 | if ip == localIp: 89 | keyDict[key] = val 90 | 91 | return True, keyDict 92 | except Exception, e: 93 | sys.stderr.write("_load_person_conf(%s) ERR(%s)\n" %(localIp, str(e))) 94 | return False, None 95 | 96 | 97 | def _replace_conf(confTemple, conf, keyDict): 98 | try: 99 | 100 | lines = open(confTemple, "r").readlines() 101 | fp = open(conf, "w") 102 | 103 | for line in lines: 104 | if len(line) > 0 and line[len(line) - 1] == '\n': line = line[0 : len(line) - 1] 105 | if len(line) > 0 and line[len(line) - 1] == '\r': line = line[0 : len(line) - 1] 106 | bRet, tmpList = _split_line(line) 107 | 108 | if len(tmpList) > 1: 109 | key = tmpList[0] 110 | if keyDict.has_key(key): 111 | 112 | sepIdx = line.find(key) 113 | sepval = line[0 : sepIdx] 114 | line = "%s%s%s%s" %(sepval, key, val_sep, keyDict[key]) 115 | 116 | fp.write("%s\n" %(line)) 117 | 118 | fp.close() 119 | return True 120 | 121 | except Exception, e: 122 | sys.stderr.write("_replace_conf(%s, %s) ERR(%s)\n" %(confTemple, conf, traceback.format_exc())) 123 | return False 124 | 125 | 126 | def conf_produce(persionConf, confTemplate, dstConfPath, ip): 127 | 128 | bRet, keyDict = _load_person_conf(persionConf, ip) 129 | if not bRet: return bRet 130 | 131 | print keyDict 132 | 133 | return _replace_conf(confTemplate, dstConfPath, keyDict) 134 | 135 | 136 | 137 | 138 | if __name__ == "__main__": 139 | 140 | def test_1(): 141 | 142 | persionConf = "persion.conf" 143 | confTemplate = "/home/s0nnet/hjs_cms/src/hjs_cfg.py" 144 | dstConfPath = "hjs_cfg.py" 145 | ip = "222.24.xx.xx" 146 | 147 | print conf_produce(persionConf, confTemplate, dstConfPath, ip) 148 | 149 | test_1() 150 | 151 | -------------------------------------------------------------------------------- /install/tools/ssh.exp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -- 2 | 3 | if { $argc < 2 } { 4 | send_user "Usage: $argv0 \[PASSWD\] \[SSH_CMD\] \n" 5 | send_user " \[PASSWD\] - password for incoming ssh login\n" 6 | send_user " \[SSH_CMD\] - ssh command to be executed, scp also supported\n" 7 | exit 8 | } 9 | 10 | set passwd [lindex $argv 0] 11 | 12 | set timeout 1800 13 | 14 | eval spawn -nottyinit -noecho [lrange $argv 1 end] 15 | 16 | expect { 17 | "*yes/no*" { 18 | send "yes\r" 19 | exp_continue 20 | } 21 | 22 | "*password:*" { 23 | send "${passwd}\r"; exp_continue 24 | } 25 | 26 | "*Password:*" { 27 | send "${passwd}\r"; exp_continue 28 | } 29 | 30 | "failed" { 31 | exit 1 32 | } 33 | 34 | timeout abort 35 | } 36 | 37 | 38 | catch wait result 39 | 40 | exit [lindex $result 3] 41 | -------------------------------------------------------------------------------- /src/base/bs_base_cfg.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: base conf 6 | 7 | 8 | import os 9 | import sys 10 | 11 | ''' 12 | LOG_LEVEL 13 | DEBUG = 1 14 | INFO = 2 15 | WARINING = 3 16 | ERR = 4 17 | ALERT = 5 18 | CLOSE = 10 19 | ''' 20 | class BaseConf: 21 | 22 | LOG_LEVEL = 2 23 | LOG_DIR = "../../log/" 24 | LOG_PREFIX = "" 25 | IS_CTR_LOG = True 26 | 27 | SQL_HOST = "222.24.XX.XX" 28 | SQL_PORT = 3306 29 | SQL_USER = "hjs_user" 30 | SQL_PASSWD = "xxxx" 31 | SQL_DB = "hjs_cms_db" 32 | -------------------------------------------------------------------------------- /src/base/bs_database_pid.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: MySQL基础操作类封装 6 | 7 | 8 | import MySQLdb 9 | from bs_log import * 10 | 11 | class SqlCmdEnum: 12 | COMMIT_CMD = 0 13 | ROLLBACK_CMD = 1 14 | 15 | class SqlExecEnum: 16 | QUERY = 0 17 | UPDATE = 1 18 | INSERT = 2 19 | DELETE = 3 20 | 21 | 22 | def _new_conn(host, port, user, passwd, db, charset): 23 | try: 24 | conn = MySQLdb.connect(host = host, 25 | port = port, 26 | user = user, 27 | passwd = passwd, 28 | db = db, 29 | charset = charset) 30 | conn.autocommit(True) 31 | Log.debug("conn(host: %s, port: %d, user: %s, passwd: %s, db: %s)" %(host, port, user, passwd, db)) 32 | return conn 33 | except Exception, e: 34 | Log.err("ERR(host: %s, port: %d, user: %s, passwd: %s, db: %s, %s)" %(host, port, user, passwd, db, str(e))) 35 | return None 36 | 37 | class DataBase: 38 | 39 | def __init__(self, 40 | host = BaseConf.SQL_HOST, 41 | port = BaseConf.SQL_PORT, 42 | user = BaseConf.SQL_USER, 43 | passwd = BaseConf.SQL_PASSWD, 44 | db = BaseConf.SQL_DB, 45 | charset = None): 46 | self.host = host 47 | self.port = port 48 | self.user = user 49 | self.passwd = passwd 50 | self.db = db 51 | self.charset = charset 52 | 53 | self.conn = None 54 | 55 | def _check(self): 56 | try: 57 | self.conn.ping() 58 | except Exception, e: 59 | self.conn = _new_conn(self.host, self.port, self.user, self.passwd, self.db, self.charset) 60 | 61 | def _get_conn(self): 62 | if self.conn == None: 63 | self.conn = _new_conn(self.host, self.port, self.user, self.passwd, self.db, self.charset) 64 | else: 65 | self._check() 66 | 67 | def _close_conn(self): 68 | if self.conn != None: 69 | self.conn.commit() 70 | self.conn.close() 71 | self.conn = None 72 | 73 | 74 | def _get_record_list(self, cursor): 75 | 76 | def _get_fieldname_list(cursor): 77 | fieldList = [] 78 | for info in cursor.description: 79 | fieldList.append(info[0]) 80 | return fieldList 81 | 82 | fieldnameList = _get_fieldname_list(cursor) 83 | 84 | retNodeList = [] 85 | recordList = cursor.fetchall() 86 | for record in recordList: 87 | node = {} 88 | for i in range(len(fieldnameList)): 89 | node[fieldnameList[i]] = record[i] 90 | retNodeList.append(node) 91 | 92 | return retNodeList 93 | 94 | 95 | def _exec_cmdstr(self, cmdstr, param, rollback, execType): 96 | 97 | def _encode_param(param): 98 | dParam = [] 99 | for par in param: 100 | if type(par) == unicode: 101 | par = par.encode('utf-8') 102 | dParam.append(par) 103 | return dParam 104 | 105 | if param != None: param = _encode_param(param) 106 | Log.debug("%s\t%s" %(cmdstr, str(param))) 107 | 108 | self._get_conn() 109 | conn = self.conn 110 | if conn == None: 111 | Log.err("mysql not connect!") 112 | return False, "mysql not connect!" 113 | 114 | cursor = conn.cursor() 115 | try: 116 | val = cursor.execute(cmdstr, param) 117 | if execType == SqlExecEnum.QUERY: val = self._get_record_list(cursor) 118 | elif execType == SqlExecEnum.INSERT: val = int(conn.insert_id()) 119 | else: pass 120 | except Exception, e: 121 | Log.warning("sql: %s,%s ERR(%s)" %(cmdstr, str(param), str(e))) 122 | if rollback: 123 | self.cmd_submit(SqlCmdEnum.ROLLBACK_CMD) 124 | else: 125 | self._close_conn() 126 | return False, "%s:%s %s" %(cmdstr, str(param), str(e)) 127 | 128 | if not rollback: 129 | self._close_conn() 130 | 131 | return True, val 132 | 133 | def query_data(self, cmdstr, param, rollback = False): 134 | return self._exec_cmdstr(cmdstr, param, rollback, SqlExecEnum.QUERY) 135 | 136 | def update_data(self, cmdstr, param, rollback = False): 137 | return self._exec_cmdstr(cmdstr, param, rollback, SqlExecEnum.UPDATE) 138 | 139 | def insert_data(self, cmdstr, param, rollback = False): 140 | return self._exec_cmdstr(cmdstr, param, rollback, SqlExecEnum.INSERT) 141 | 142 | def delete_data(self, cmdstr, param, rollback = False): 143 | return self._exec_cmdstr(cmdstr, param, rollback, SqlExecEnum.DELETE) 144 | 145 | def cmd_submit(self, flag): 146 | conn = self.conn 147 | if not conn: self._close_conn(); return 148 | 149 | try: 150 | if flag == SqlCmdEnum.COMMIT_CMD: 151 | conn.commit() 152 | elif flag == SqlCmdEnum.ROLLBACK_CMD: 153 | conn.rollback() 154 | finally: 155 | self._close_conn() 156 | 157 | 158 | if __name__ == "__main__": 159 | 160 | dataBase = DataBase() 161 | 162 | cmdstr = "select * from tb_user limit 10" 163 | print dataBase.query_data(cmdstr, None) 164 | -------------------------------------------------------------------------------- /src/base/bs_email.py: -------------------------------------------------------------------------------- 1 | # -*- coding : UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: smtp邮件发送类 6 | 7 | 8 | import sys 9 | import smtplib 10 | import socket 11 | import re 12 | 13 | from bs_log import * 14 | from bs_process import * 15 | 16 | from email.MIMEMultipart import MIMEMultipart 17 | from email.MIMEText import MIMEText 18 | 19 | class Semail: 20 | def __init__(self, userName = "you_name", 21 | passwd = "you_pswd", 22 | smtpAddr = "smtp_srv_ip", 23 | smtpPort = 25, 24 | fromAddr = "", 25 | toAddrs = ""): 26 | self.userName = userName 27 | self.passwd = passwd 28 | self.smtpAddr = smtpAddr 29 | self.smtpPort = smtpPort 30 | self.fromAddr = fromAddr 31 | self.toAddrs = toAddrs 32 | 33 | def send_email_1(self, subject, text): 34 | 35 | cmd = "echo \"%s\" | mail -s \"%s\" %s" %(text, subject, self.toAddrs) 36 | bs_system(cmd) 37 | 38 | def send_email(self, subject, text): 39 | 40 | bRet = True 41 | 42 | text = re.sub("\n", "
", text) 43 | 44 | msg = MIMEMultipart() 45 | msg["From"] = self.fromAddr 46 | msg["To"] = self.toAddrs 47 | msg['Subject'] = subject 48 | msg.attach(MIMEText(text, 'html', 'utf-8')) 49 | 50 | message = msg.as_string() 51 | try: 52 | #s = smtplib.SMTP(self.smtpAddr) 53 | s = smtplib.SMTP(host=self.smtpAddr, timeout= 3) 54 | #s.set_debuglevel(True) 55 | #s.connect(self.smtpAddr, self.smtpPort) 56 | 57 | s.ehlo() 58 | if s.has_extn('STARTTLS'): 59 | s.starttls() 60 | s.ehlo() 61 | 62 | s.login(self.userName, self.passwd) 63 | s.sendmail(self.fromAddr, self.toAddrs.split(","), message) 64 | s.quit() 65 | except Exception, e: 66 | Log.err("send email error: %s" %(str(e))) 67 | bRet = False 68 | 69 | return bRet 70 | 71 | 72 | if __name__ == "__main__": 73 | try: 74 | email = Semail() 75 | email.send_email("test", "
===test===
") 76 | except Exception, e: 77 | print e 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/base/bs_log.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: 日志模块封装 6 | 7 | 8 | from bs_syshead import * 9 | 10 | class LogLevel: 11 | DEBUG = 1 12 | INFO = 2 13 | WARNING = 3 14 | ERR = 4 15 | ALERT = 5 16 | CLOSE = 10 17 | 18 | def _get_log_level(logLevel): 19 | if logLevel == LogLevel.DEBUG: return "DEBUG" 20 | if logLevel == LogLevel.INFO: return "INFO" 21 | if logLevel == LogLevel.WARNING: return "WARNING" 22 | if logLevel == LogLevel.ERR: return "ERROR" 23 | if logLevel == LogLevel.ALERT: return "ALERT" 24 | return "CLOSE" 25 | 26 | def _get_log_tm(): 27 | "[01/Jan/2013 04:51:46]" 28 | return (datetime.datetime.now()).strftime("[%d/%m/%Y %H:%M:%S]") 29 | 30 | 31 | def _get_file(f): return f[1] 32 | def _get_function(f): return f[3] 33 | def _get_line(f): return f[2] 34 | def _get_location(stackIdx): 35 | f = inspect.stack()[stackIdx] 36 | return "%s::%s(%d)" %(_get_file(f), _get_function(f), _get_line(f)) 37 | 38 | 39 | class LogFile: 40 | 41 | @staticmethod 42 | def rm_file(path, delflag = False): 43 | 44 | if not path: return 45 | if not os.path.exists(path): return 46 | 47 | if os.path.isfile(path): 48 | os.unlink(path) 49 | return 50 | 51 | fileList = os.listdir(path) 52 | if len(fileList) != 0: 53 | for fname in fileList: 54 | filePath = "%s/%s" %(path, fname) 55 | LogFile.rm_file(filePath, True) 56 | 57 | if delflag: 58 | os.rmdir(path) 59 | 60 | def __init__(self): 61 | self.fp = None; 62 | self.maxSzie = 1024 * 1024 63 | self.fName = -1 64 | 65 | def _open_logfile(self): 66 | self.fName += 1 67 | if not os.path.exists(BaseConf.LOG_DIR): 68 | os.makedirs(BaseConf.LOG_DIR) 69 | 70 | curTm = (datetime.datetime.now()).strftime("%Y_%m_%d_%H_%M_%S") 71 | preFix = BaseConf.LOG_PREFIX + "_%s" %(curTm) 72 | tmpName = "%s/%s.txt" %(BaseConf.LOG_DIR, preFix) 73 | 74 | try: 75 | if self.fp: self.fp.close() 76 | self.fp = open(tmpName, "a") 77 | 78 | os.dup2(self.fp.fileno(), sys.stdout.fileno()) 79 | os.dup2(self.fp.fileno(), sys.stderr.fileno()) 80 | except Exception, e: 81 | sys.stderr.write("%s: %s\n" %(_get_location(1), str(e))) 82 | 83 | def _print_log(self, buf): 84 | try: 85 | if self.fp == None or self.fp.tell() >= self.maxSzie: 86 | self._open_logfile() 87 | 88 | self.fp.write(buf) 89 | self.fp.flush() 90 | except Exception, e: 91 | sys.stderr.write("%s: %s" %(_get_location(1), str(e))) 92 | sys.stderr.flush() 93 | 94 | logFile = LogFile() 95 | 96 | 97 | class Log: 98 | 99 | @staticmethod 100 | def _loglog(buf, stackIdx, logLevel): 101 | if logLevel >= BaseConf.LOG_LEVEL: 102 | msg = "%s[%s]%s: %s\n" %(_get_log_tm(), _get_log_level(logLevel), _get_location(stackIdx + 1), buf) 103 | if BaseConf.IS_CTR_LOG: sys.stderr.write(msg); sys.stderr.flush() 104 | else: logFile._print_log(msg) 105 | 106 | 107 | @staticmethod 108 | def debug(buf, stackIdx = 1): 109 | Log._loglog(buf, stackIdx + 1, LogLevel.DEBUG) 110 | 111 | @staticmethod 112 | def info(buf, stackIdx = 1): 113 | Log._loglog(buf, stackIdx + 1, LogLevel.INFO) 114 | 115 | @staticmethod 116 | def warning(buf, stackIdx = 1): 117 | Log._loglog(buf, stackIdx + 1, LogLevel.WARNING) 118 | 119 | @staticmethod 120 | def err(buf, stackIdx = 1): 121 | Log._loglog(buf, stackIdx + 1, LogLevel.ERR) 122 | 123 | @staticmethod 124 | def alert(buf, stackIdx = 1): 125 | Log._loglog(buf, stackIdx + 1, LogLevel.ALERT) 126 | 127 | 128 | if __name__ == "__main__": 129 | Log.debug("Test......") 130 | Log.info("Test.......") 131 | Log.err("Test.......") 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/base/bs_process.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: 进程创建封装 6 | 7 | 8 | from subprocess import * 9 | from bs_log import * 10 | 11 | 12 | def bs_system(cmd, stdout = False, stderr = True): 13 | bRet = False 14 | 15 | if not stderr: cmd = "%s >> /dev/null 2>&1" %(cmd) 16 | elif not stdout: cmd = "%s >> /dev/null" %(cmd) 17 | 18 | try: 19 | retState = os.system(cmd) 20 | except Exception, e: 21 | Log.err("cmd(%s) ERR(%s)" %(cmd, str(e))) 22 | retState = -1 23 | 24 | Log.debug("%s, retstate = %d" %(cmd, retState)) 25 | if retState == 0: bRet = True 26 | return bRet 27 | 28 | 29 | # 管道执行命令, 命令小输出还可以, 如果输出比较大推荐走文件输出流 30 | def exec_cmd(cmd): 31 | 32 | Log.debug("cmd: %s" %(cmd)) 33 | content = "" 34 | try: 35 | p = Popen(cmd, bufsize = 4096, stdout = PIPE, shell = True) 36 | 37 | while True: 38 | cont = p.stdout.read() 39 | if cont == "": break 40 | content += cont 41 | Log.debug("contLen: %d" %(len(cont))) 42 | time.sleep(1) 43 | retState = p.wait() 44 | 45 | return retState, content 46 | except Exception, e: 47 | Log.err("(%s)" %(traceback.format_exc())) 48 | return 255, "cmd(%s) err: %s" %(str(cmd), str(e)) 49 | 50 | 51 | # 进程池 52 | class YgProcessPool: 53 | 54 | def __init__(self, pidNum, fun, args): 55 | 56 | self.pool = [] # 进程池 57 | self.size = pidNum 58 | self.fun = fun 59 | self.args = args 60 | 61 | def start(self, wait = False): 62 | 63 | bRet = True 64 | try: 65 | for i in range(self.size): 66 | pid = os.fork() 67 | if pid == 0: 68 | retCode = 0 69 | try: 70 | bRet = self.fun(i, self.size, self.args) 71 | if not bRet: retCode = -1 72 | except Exception, e: 73 | Log.err("ERR(%s)" %(traceback.format_exc())) 74 | retCode = -1 75 | 76 | os._exit(retCode) 77 | #sys.exit(retCode) 78 | 79 | self.pool.append(pid) 80 | 81 | if wait: 82 | bRet = self.wait() 83 | 84 | except Exception, e: 85 | Log.err("ERR(%s)" %(traceback.format_exc())) 86 | bRet = False 87 | 88 | return bRet 89 | 90 | def wait(self): 91 | 92 | bRet = True 93 | for i in range(self.size): 94 | pid, retCode = os.waitpid(self.pool[i], 0) 95 | if retCode != 0: bRet = False 96 | return bRet 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/base/bs_syshead.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: 相关模块导入 6 | 7 | 8 | import sys 9 | import os 10 | import time 11 | import datetime 12 | import signal 13 | import inspect 14 | import threading 15 | import thread 16 | import signal 17 | import uuid 18 | import re 19 | import traceback 20 | from multiprocessing import Process 21 | 22 | try: 23 | import json 24 | except Exception, e: 25 | import simplejson as json 26 | 27 | from bs_base_cfg import * 28 | -------------------------------------------------------------------------------- /src/base/bs_time.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: 时间处理类封装 6 | 7 | 8 | from bs_log import * 9 | import datetime 10 | import time 11 | 12 | 13 | def get_cur_dtime(): 14 | return int(time.time()) 15 | 16 | 17 | def get_cur_time(tmFormat=None): 18 | if tmFormat == None: tmFormat = "%Y-%m-%d %H:%M:%S" 19 | return (datetime.datetime.now()).strftime(tmFormat) 20 | 21 | 22 | def yg_tm_str_int(strTm, format="%Y-%m-%d %H:%M:%S"): 23 | if type(strTm) == datetime.datetime: 24 | strTm = strTm.strftime(format) 25 | tmTuple = time.strptime(strTm, format) 26 | return time.mktime(tmTuple) 27 | 28 | 29 | def yg_tm_int_str(tm, format="%Y-%m-%d %H:%M:%S"): 30 | # tmObj = time.localtime(tm) 31 | tmObj = time.localtime(tm) 32 | return time.strftime(format, tmObj) 33 | 34 | 35 | def get_cur_day(days=0, format="%Y%m%d"): 36 | return (datetime.datetime.now() - datetime.timedelta(days)).strftime(format) 37 | 38 | 39 | def get_cur_time_2(days=0, format="%Y-%m-%d %H:%M:%S"): 40 | return (datetime.datetime.now() - datetime.timedelta(days)).strftime(format) 41 | 42 | 43 | 44 | 45 | if __name__ == "__main__": 46 | def test1(): 47 | print get_cur_time_2(1, "%Y-%m-%d 00:00:00") 48 | 49 | 50 | print get_cur_day(0,format="%Y-%m-%d") 51 | -------------------------------------------------------------------------------- /src/bean/hjs_custom.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: custom处理逻辑 6 | 7 | if __name__ == "__main__": 8 | import sys 9 | import os 10 | 11 | sys.path.append("..") 12 | sys.path.append("../base") 13 | sys.path.append("../dao") 14 | 15 | from web.utils import * 16 | from hjs_cfg import * 17 | from bs_util import * 18 | from hjs_custom_dao import * 19 | 20 | 21 | class CustomStatus: 22 | NORMAL = 'normal' 23 | CANCEL = 'cancel' 24 | DELETE = 'delete' 25 | ALL = 'all' 26 | 27 | 28 | class HjsCustom: 29 | 30 | 31 | @staticmethod 32 | def _page_data(data_list, status, search, page): 33 | if not isinstance(page, Page): 34 | return data_list 35 | return { 36 | "page_count": page.page_count, 37 | "current": page.page_index, 38 | "custom_list": data_list, 39 | "custom_query": {"status": status, "search": search} 40 | } 41 | 42 | 43 | @staticmethod 44 | def custom_list(page, length, status=None, search=None): 45 | allow_status = [CustomStatus.ALL, CustomStatus.NORMAL, CustomStatus.CANCEL, CustomStatus.DELETE] 46 | if status and (status not in allow_status): 47 | return False, 'param(status) not define' 48 | 49 | bRet, count = HjsCustomDao.query_node_count(status, search) 50 | if not bRet: 51 | return False, count 52 | 53 | pg = Page(count, page, length) 54 | bRet, sRet = HjsCustomDao.query_node_list(pg.offset, pg.limit, status, search) 55 | if not bRet: 56 | Log.err('list custom fail: %s' % str(sRet)) 57 | return False, sRet 58 | if len(sRet) == 0: 59 | return True, None 60 | 61 | customList = list() 62 | for item in sRet: 63 | custom_info = storage() 64 | custom_info.cid = int(item['cid']) 65 | custom_info.name = item['name'] 66 | custom_info.address = item['address'] 67 | custom_info.phone = item['phone'] 68 | custom_info.ctype = item['ctype'] 69 | custom_info.class_priv = item['class'] 70 | custom_info.status = item['status'] 71 | custom_info.remark = item['remark'] 72 | custom_info.insert_tm = str(item['insert_tm'])[2:16] 73 | customList.append(custom_info) 74 | 75 | return True, HjsCustom._page_data(customList, status, search, pg) 76 | 77 | 78 | @staticmethod 79 | def custom_add(nickName, Address, Phone, Ctype, Class, Remark): 80 | bRet, sRet = HjsCustomDao.insert_node(nickName, Address, Phone, Ctype, Class, Remark) 81 | if not bRet: 82 | return False, sRet 83 | return True, sRet 84 | 85 | 86 | @staticmethod 87 | def custom_info(cId): 88 | bRet, cInfo = HjsCustomDao.query_node_by_cid(cId) 89 | if not bRet: 90 | return False, cInfo 91 | custom_info = storage() 92 | custom_info.cid = int(cInfo['cid']) 93 | custom_info.name = cInfo['name'] 94 | custom_info.address = cInfo['address'] 95 | custom_info.phone = cInfo['phone'] 96 | custom_info.ctype = cInfo['ctype'] 97 | custom_info.class_priv = cInfo['class'] 98 | custom_info.status = cInfo['status'] 99 | custom_info.remark = cInfo['remark'] 100 | 101 | return True, custom_info 102 | 103 | 104 | @staticmethod 105 | def custom_update(cId, nickName, Address, Phone, Ctype, Class, Status, Remark): 106 | bRet, sRet = HjsCustomDao.update_node(cId, nickName, Address, Phone, Ctype, Class, Status, Remark) 107 | if not bRet: 108 | return False, sRet 109 | return True, sRet 110 | 111 | 112 | @staticmethod 113 | def custom_del(cId): 114 | bRet, sRet = HjsCustomDao.delete_node_by_cid(cId) 115 | if not bRet: 116 | return False, sRet 117 | return True, sRet 118 | 119 | 120 | if __name__=="__main__": 121 | 122 | def test_custom_list(): 123 | print HjsCustom.custom_list(1, 20, 'normal', '') 124 | 125 | def test_custom_add(): 126 | nickName = "zhangxicheng" 127 | Address = "city_12_a" 128 | Phone = "18829252920" 129 | Ctype = "N" 130 | Class = "A" 131 | Status = "normal" 132 | Remark = "xxxx" 133 | print HjsCustom.custom_add(nickName, Address, Phone, Ctype, Class, Status, Remark) 134 | 135 | def test_custom_info(): 136 | print HjsCustom.custom_info(1002) 137 | 138 | def test_custom_update(): 139 | cId = 1002 140 | nickName = "zhangxicheng" 141 | Address = "city_12_a" 142 | Phone = "18829252920" 143 | Ctype = "N" 144 | Class = "A" 145 | Status = "normal" 146 | Remark = "xxxx" 147 | print HjsCustom.custom_add(nickName, Address, Phone, Ctype, Class, Status, Remark) 148 | 149 | def test_custom_del(): 150 | print HjsCustom.custom_del(1003) 151 | 152 | # test ing ... 153 | 154 | test_custom_info() 155 | 156 | -------------------------------------------------------------------------------- /src/bean/hjs_index.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: index data展示 6 | 7 | if __name__ == "__main__": 8 | import sys 9 | import os 10 | 11 | sys.path.append("..") 12 | sys.path.append("../base") 13 | sys.path.append("../dao") 14 | 15 | from web.utils import * 16 | from hjs_cfg import * 17 | from bs_util import * 18 | from bs_time import * 19 | from hjs_order_dao import * 20 | from hjs_custom_dao import * 21 | 22 | 23 | class HjsIndex: 24 | 25 | @staticmethod 26 | def _get_custom_data(): 27 | bRet, custom_cnt = HjsCustomDao.query_node_by_status('all') 28 | if not bRet: custom_cnt = 0 29 | 30 | bRet, custom_nor = HjsCustomDao.query_node_by_status('normal') 31 | if not bRet: custom_nor = 0 32 | 33 | bRet, custom_can = HjsCustomDao.query_node_by_status('delete') 34 | if not bRet: custom_can = 0 35 | 36 | return { 37 | "custom_cnt": custom_cnt, 38 | "custom_nor": custom_nor, 39 | "custom_can": custom_can 40 | } 41 | 42 | 43 | @staticmethod 44 | def _get_order_data(): 45 | bRet, order_cnt = HjsOrderDao.query_node_by_status('all') 46 | if not bRet: order_cnt = 0 47 | 48 | bRet, order_nor = HjsOrderDao.query_node_by_status('normal') 49 | if not bRet: order_nor = 0 50 | 51 | bRet, order_stop = HjsOrderDao.query_node_by_status('stop') 52 | if not bRet: order_stop = 0 53 | 54 | order_today = '开发中...' 55 | order_today_stop = '开发中...' 56 | 57 | 58 | return { 59 | "order_cnt": order_cnt, 60 | "order_nor": order_nor, 61 | "order_stop": order_stop, 62 | "order_today": order_today, 63 | "order_today_stop": order_today_stop 64 | } 65 | 66 | 67 | @staticmethod 68 | def _get_expire_order(): 69 | bRet, daysList_3 = HjsOrderDao.query_node_by_days(3) 70 | if not bRet: daysList_3 = '' 71 | 72 | bRet, daysList_7 = HjsOrderDao.query_node_by_days(7) 73 | if not bRet: daysList_7 = '' 74 | 75 | return { 76 | "days_3": {"count": len(daysList_3), "list": daysList_3}, 77 | "days_7": {"count": len(daysList_7), "list": daysList_7} 78 | } 79 | 80 | 81 | @staticmethod 82 | def data_show(userName): 83 | datas = { 84 | "dt_custom": HjsIndex._get_custom_data(), 85 | "dt_order": HjsIndex._get_order_data(), 86 | "dt_days": HjsIndex._get_expire_order(), 87 | "update_date": str(get_cur_day(0, "%Y-%m-%d")) 88 | } 89 | 90 | return True, datas 91 | 92 | 93 | 94 | 95 | if __name__ == "__main__": 96 | 97 | bRet, sRet = HjsIndex.data_show('admin') 98 | 99 | print '>>>> ', sRet 100 | 101 | #print HjsIndex._get_expire_order() 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/bean/hjs_order.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: order处理逻辑 6 | 7 | 8 | if __name__ == "__main__": 9 | import sys 10 | import os 11 | 12 | sys.path.append("..") 13 | sys.path.append("../base") 14 | sys.path.append("../dao") 15 | 16 | from web.utils import * 17 | from hjs_cfg import * 18 | from bs_util import * 19 | from bs_time import * 20 | from hjs_user_dao import * 21 | from hjs_order_dao import * 22 | from hjs_ps_order_dao import * 23 | from hjs_custom_dao import * 24 | 25 | 26 | class OrderStatus: 27 | ALL = 'all' 28 | STOP = 'stop' 29 | NORMAL = 'normal' 30 | DELETE = 'delete' 31 | 32 | 33 | class HjsOrder: 34 | 35 | @staticmethod 36 | def _page_data(data_list, status, search, page): 37 | if not isinstance(page, Page): 38 | return data_list 39 | return { 40 | "page_count": page.page_count, 41 | "current": page.page_index, 42 | "order_list": data_list, 43 | "order_query": {"status": status, "search": search} 44 | } 45 | 46 | 47 | @staticmethod 48 | def order_list(page, length, status=None, search=None): 49 | allow_status = [OrderStatus.ALL, OrderStatus.NORMAL, OrderStatus.STOP, OrderStatus.DELETE] 50 | if status and (status not in allow_status): 51 | return False, 'param(status) not define' 52 | 53 | bRet, count = HjsOrderDao.query_node_count(status, search) 54 | if not bRet: 55 | return False, count 56 | 57 | pg = Page(count, page, length) 58 | bRet, sRet = HjsOrderDao.query_node_list(pg.offset, pg.limit, status, search) 59 | if not bRet: 60 | Log.err('list order fail: %s' % str(sRet)) 61 | return False, sRet 62 | if len(sRet) == 0: 63 | return True, None 64 | 65 | orderList = list() 66 | for item in sRet: 67 | order_info = storage() 68 | order_info.oid = int(item['oid']) 69 | order_info.cid = int(item['cid']) 70 | order_info.name = item['name'] 71 | order_info.otype = item['otype']; 72 | order_info.order_tm = str(item['order_tm'])[:10] 73 | order_info.start_tm = str(item['start_tm']) 74 | order_info.end_tm = str(item['end_tm']) 75 | order_info.amount = item['amount'] 76 | order_info.cash = item['cash'] 77 | order_info.status = item['status'] 78 | order_info.remark = item['remark'] 79 | order_info.insert_tm = str(item['insert_tm'])[2:16] 80 | orderList.append(order_info) 81 | 82 | return True, HjsOrder._page_data(orderList, status, search, pg) 83 | 84 | 85 | @staticmethod 86 | def order_today(status='normal', days=0): 87 | tg_date = get_cur_day(days, format="%Y-%m-%d") 88 | bRet, orderList_tmp = HjsOrderDao.query_node_by_date(status, tg_date) 89 | if not bRet: 90 | return False, orderList 91 | 92 | bRet, sRet = HjsOrderPauseDao.query_node_by_date(tg_date) 93 | if not bRet: 94 | return False, sRet 95 | 96 | pauseList = list() 97 | for item in sRet: 98 | if item.has_key('oid'): 99 | pauseList.append(item['oid']) 100 | 101 | orderList = list() 102 | for item in orderList_tmp: 103 | if item['oid'] in pauseList: continue 104 | 105 | order_info = storage() 106 | order_info.oid = int(item['oid']) 107 | order_info.cid = int(item['cid']) 108 | order_info.name = item['name'] 109 | order_info.otype = item['otype'] 110 | order_info.status = item['status'] 111 | order_info.remark = item['remark'] 112 | 113 | bRet, custom_info = HjsCustomDao.query_node_by_cid(order_info.cid) 114 | order_info.address = custom_info['address'] if bRet else '--' 115 | order_info.phone = custom_info['phone'] if bRet else '--' 116 | order_info.ctype = custom_info['ctype'] if bRet else '--' 117 | 118 | orderList.append(order_info) 119 | 120 | return True, orderList 121 | 122 | 123 | @staticmethod 124 | def order_add(cId, otype, order_tm, start_tm, end_tm, amount, cash, remark): 125 | bRet, custom_info = HjsCustomDao.query_node_by_cid(cId) 126 | name = custom_info['name'] if bRet else '' 127 | 128 | return HjsOrderDao.insert_node(cId, name, otype, order_tm, start_tm, end_tm, amount, cash, remark) 129 | 130 | 131 | @staticmethod 132 | def order_update(oId, otype, order_tm, start_tm, end_tm, amount, cash, status, remark): 133 | return HjsOrderDao.update_node(oId, otype, order_tm, start_tm, end_tm, amount, cash, status, remark) 134 | 135 | 136 | @staticmethod 137 | def order_del(oId): 138 | return HjsOrderDao.update_node_status(oId, 'stop') 139 | 140 | 141 | @staticmethod 142 | def order_info(oId): 143 | bRet, sRet = HjsOrderDao.query_node_by_oid(oId) 144 | if not bRet: 145 | return False, sRet 146 | 147 | order_info = storage() 148 | order_info.oid = int(sRet['oid']) 149 | order_info.cid = int(sRet['cid']) 150 | order_info.name = sRet['name'] 151 | order_info.otype = sRet['otype'] 152 | order_info.order_tm = str(sRet['order_tm'])[:10] 153 | order_info.start_tm = str(sRet['start_tm']) 154 | order_info.end_tm = str(sRet['end_tm']) 155 | order_info.amount = sRet['amount'] 156 | order_info.cash = sRet['cash'] 157 | order_info.status = sRet['status'] 158 | order_info.remark = sRet['remark'] 159 | 160 | return True, order_info 161 | 162 | 163 | 164 | if __name__ == "__main__": 165 | 166 | #print HjsOrder.order_today() 167 | 168 | #print HjsOrder.order_info(2003) 169 | 170 | print HjsOrder.order_today() 171 | 172 | 173 | pass 174 | 175 | 176 | -------------------------------------------------------------------------------- /src/bean/hjs_ps_order.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: order 暂取消处理逻辑 6 | 7 | 8 | if __name__ == "__main__": 9 | import sys 10 | import os 11 | 12 | sys.path.append("..") 13 | sys.path.append("../base") 14 | sys.path.append("../dao") 15 | 16 | from web.utils import * 17 | from hjs_cfg import * 18 | from bs_util import * 19 | from hjs_order_dao import * 20 | from hjs_ps_order_dao import * 21 | 22 | class HjsOrderPause: 23 | 24 | @staticmethod 25 | def order_list(): 26 | bRet, sRet = HjsOrderPauseDao.query_node_list() 27 | if not bRet: 28 | Log.err('list pause order fail: %s' % str(sRet)) 29 | return False, sRet 30 | if len(sRet) == 0: 31 | return True, None 32 | 33 | orderPsList = list() 34 | for item in sRet: 35 | pause_info = storage() 36 | pause_info.pid = int(item['pid']) 37 | pause_info.oid = int(item['oid']) 38 | pause_info.cid = int(item['cid']) 39 | pause_info.name = item['name'] 40 | pause_info.pause_tm = str(item['pause_tm']) 41 | pause_info.remark = item['remark'] 42 | pause_info.insert_tm = str(item['insert_tm']) 43 | orderPsList.append(pause_info) 44 | 45 | return True, orderPsList 46 | 47 | 48 | @staticmethod 49 | def order_add(oId, pause_tm, remark): 50 | bRet, order = HjsOrderDao.query_node_by_oid(oId) 51 | if not bRet: 52 | return False, order 53 | 54 | cid = order['cid'] if order.has_key('cid') else '' 55 | name = order['name'] if order.has_key('name') else '' 56 | 57 | return HjsOrderPauseDao.insert_node(oId, cid, name, pause_tm, remark) 58 | 59 | 60 | @staticmethod 61 | def order_del(pId): 62 | bRet, sRet = HjsOrderPauseDao.delete_node_by_pid(pId) 63 | if not bRet: 64 | return False, sRet 65 | 66 | return True, sRet 67 | 68 | 69 | if __name__ == "__main__": 70 | pass 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/bean/hjs_user.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: user处理逻辑 6 | 7 | if __name__ == "__main__": 8 | import sys 9 | import os 10 | 11 | sys.path.append("..") 12 | sys.path.append("../base") 13 | sys.path.append("../dao") 14 | 15 | from web.utils import * 16 | from hjs_cfg import * 17 | from bs_util import * 18 | from hjs_user_dao import * 19 | 20 | 21 | class UserPriv: 22 | VIEW = 1 23 | USER = 2 24 | ADMIN = 3 25 | 26 | 27 | class HjsUser: 28 | 29 | @staticmethod 30 | def user_list(userName): 31 | bRet, sRet = HjsUserDao.query_node_user_list() 32 | if not bRet: 33 | return False, sRet 34 | userList = list() 35 | for item in sRet: 36 | user_info = storage() 37 | user_info.uid = int(item['uid']) 38 | user_info.username = item['username'] 39 | user_info.nickname = item['nickname'] 40 | user_info.password = item['password'] 41 | user_info.phone = item['phone'] 42 | user_info.email = item['email'] 43 | user_info.priv = int(item['privilege']) 44 | user_info.lastlogin = str(item['lastlogin']) 45 | userList.append(user_info) 46 | 47 | return True, userList 48 | 49 | 50 | @staticmethod 51 | def user_add(nickName, userName, passWord, Phone, Email, Priv): 52 | bRet, sRet = HjsUserDao.insert_node_user(nickName, userName, passWord, Phone, Email, Priv) 53 | if not bRet: 54 | return False, sRet 55 | 56 | return True, sRet 57 | 58 | 59 | @staticmethod 60 | def user_info(uId): 61 | bRet, uInfo = HjsUserDao.query_node_by_uid(uId) 62 | 63 | if not bRet: 64 | return False, uInfo 65 | 66 | user_info = storage() 67 | user_info.uid = uInfo['uid'] 68 | user_info.username = uInfo['username'] 69 | user_info.nickname = uInfo['nickname'] 70 | user_info.password = uInfo['password'] 71 | user_info.phone = uInfo['phone'] 72 | user_info.email = uInfo['email']; 73 | user_info.priv = uInfo['privilege'] 74 | 75 | return True, user_info 76 | 77 | 78 | @staticmethod 79 | def user_update(uId, nickName, userName, passWord, Phone, Email, Priv): 80 | bRet, sRet = HjsUserDao.update_node_user(uId, nickName, userName, passWord, Phone, Email, Priv) 81 | if not bRet: 82 | return False, sRet 83 | 84 | return True, sRet 85 | 86 | 87 | @staticmethod 88 | def user_del(uId): 89 | bRet, sRet = HjsUserDao.delete_node_user(uId) 90 | if not bRet: 91 | return False, sRet 92 | 93 | return True, sRet 94 | 95 | 96 | @staticmethod 97 | def get_user_uid(userName): 98 | bRet, sRet = HjsUserDao.query_node_by_username(userName) 99 | if not bRet: 100 | return False, sRet 101 | uid = int(sRet['uid']) 102 | 103 | return True, uid 104 | 105 | 106 | @staticmethod 107 | def is_admin(userName): 108 | bRet, sRet = HjsUserDao.query_node_by_username(userName) 109 | if not bRet: 110 | return False, sRet 111 | if not sRet['privilege']: 112 | return False, 'get user priv error' 113 | if sRet['privilege'] != UserPriv.ADMIN: # is_admin user 114 | return True, False 115 | 116 | return True, True 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | if __name__ == "__main__": 126 | #print HjsUser.user_list('admin') 127 | 128 | 129 | print HjsUser.user_info(105) 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/dao/hjs_custom_dao.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: tb_custom_dao 6 | 7 | 8 | ''' 9 | # 客户表 10 | CREATE TABLE `tb_custom` ( 11 | `cid` int(10) NOT NULL AUTO_INCREMENT, 12 | `name` varchar(50) NOT NULL, 13 | `address` varchar(100) NOT NULL, 14 | `phone` varchar(50) DEFAULT NULL, 15 | `ctype` enum('N', 'O') NOT NULL DEFAULT 'N', 16 | `class` varchar(10) DEFAULT 'A', 17 | `status` enum('normal','cancel', 'delete') NOT NULL DEFAULT 'normal', 18 | `remark` text, 19 | `insert_tm` datetime DEFAULT NULL, 20 | PRIMARY KEY (`cid`) 21 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 22 | ''' 23 | 24 | if __name__ == "__main__": 25 | import sys 26 | sys.path.append("..") 27 | sys.path.append("../base") 28 | 29 | from hjs_cfg import * 30 | from bs_util import * 31 | from bs_database_pid import * 32 | 33 | 34 | class HjsCustomDao: 35 | 36 | @staticmethod 37 | def query_node_list(offset, limit, status, search): 38 | dataBase = DataBase() 39 | sql = "select * from tb_custom where 1=1 " 40 | param = [] 41 | if status and status != 'all': 42 | sql += "and status = %s " 43 | param.append(status) 44 | if search: 45 | search = "%%%s%%" % (search) 46 | sql += "and (name like %s or address like %s or phone like %s)" 47 | param.append(search) 48 | param.append(search) 49 | param.append(search) 50 | 51 | sql += "order by cid desc limit %s, %s" 52 | param.append(offset) 53 | param.append(limit) 54 | 55 | param = tuple(param) 56 | bRet, sRet = dataBase.query_data(sql, param) 57 | if not bRet: 58 | return False, sRet 59 | 60 | return True, sRet 61 | 62 | 63 | @staticmethod 64 | def query_node_count(status=None, search=None): 65 | dataBase = DataBase() 66 | sql = "select count(*) as cnt from tb_custom where 1=1 " 67 | param = [] 68 | 69 | if status and status != 'all': 70 | sql += "and status = %s" 71 | param.append(status) 72 | if search: 73 | search = "%%%s%%" % (search) 74 | sql += "and (name like %s or address like %s or phone like %s)" 75 | param.append(search) 76 | param.append(search) 77 | param.append(search) 78 | 79 | param = tuple(param) 80 | bRet, sRet = dataBase.query_data(sql, param) 81 | if not bRet: 82 | return False, sRet 83 | if len(sRet) !=1: 84 | return True, 0 85 | 86 | return True, sRet[0]['cnt'] 87 | 88 | 89 | @staticmethod 90 | def insert_node(nickName, Address, Phone, Ctype, Class, Remark): 91 | 92 | dataBase = DataBase() 93 | sql = "insert into tb_custom(name, address, phone, ctype, class, remark, insert_tm) " \ 94 | "values(%s, %s, %s, %s, %s, %s, %s)" 95 | param = (nickName, Address, Phone, Ctype, Class, Remark, get_cur_time()) 96 | 97 | bRet, sRet = dataBase.insert_data(sql, param) 98 | return bRet, sRet 99 | 100 | 101 | @staticmethod 102 | def update_node(cId, nickName, Address, Phone, Ctype, Class, Status, Remark): 103 | dataBase = DataBase() 104 | sql = "update tb_custom set name = %s, address = %s, phone = %s, ctype = %s, class = %s, " \ 105 | "status = %s, remark = %s where cid = %s" 106 | param = (nickName, Address, Phone, Ctype, Class, Status, Remark, cId) 107 | bRet, sRet = dataBase.update_data(sql, param) 108 | if not bRet: 109 | return False, sRet 110 | 111 | return True, sRet 112 | 113 | 114 | # just update the status when delete custom_info. 115 | @staticmethod 116 | def delete_node_by_cid(cId): 117 | dataBase = DataBase() 118 | sql = "update tb_custom set status = %s where cid = %s" 119 | param = ('delete', cId) 120 | bRet, sRet = dataBase.update_data(sql, param) 121 | if not bRet: 122 | return False, sRet 123 | 124 | return True, sRet 125 | 126 | 127 | @staticmethod 128 | def query_node_by_status(status): 129 | dataBase = DataBase() 130 | sql = "select count(*) as cnt from tb_custom where 1=1 " 131 | param = [] 132 | 133 | if status == 'all': 134 | pass 135 | else: 136 | sql += 'and status = %s' 137 | param.append(status) 138 | 139 | param = tuple(param) 140 | bRet, sRet = dataBase.query_data(sql, param) 141 | if not bRet: 142 | return False, sRet 143 | if len(sRet) != 1: 144 | return True, 0 145 | return True, sRet[0]['cnt'] 146 | 147 | 148 | @staticmethod 149 | def query_node_by_cid(cId): 150 | dataBase = DataBase() 151 | sql = "select * from tb_custom where cid = %s" 152 | param = (cId, ) 153 | bRet, sRet = dataBase.query_data(sql, param) 154 | if (not bRet) or (len(sRet) != 1): 155 | return False, sRet 156 | 157 | return True, sRet[0] 158 | 159 | 160 | 161 | 162 | if __name__ == "__main__": 163 | 164 | print HjsCustomDao.query_node_by_status('delete') 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /src/dao/hjs_order_dao.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: tb_order_dao 6 | 7 | 8 | ''' 9 | # 订单表 10 | CREATE TABLE `tb_order` ( 11 | `oid` int(10) NOT NULL AUTO_INCREMENT, 12 | `cid` int(10) NOT NULL, 13 | `name` varchar(50) NOT NULL, 14 | `otype` varchar(10) NOT NULL DEFAULT 'A', 15 | `order_tm` datetime NOT NULL, 16 | `start_tm` date NOT NULL, 17 | `end_tm` date NOT NULL, 18 | `amount` float NOT NULL, 19 | `cash` float NOT NULL, 20 | `status` enum('normal','stop') DEFAULT 'normal', 21 | `remark` text NOT NULL, 22 | `insert_tm` datetime NOT NULL, 23 | PRIMARY KEY (`oid`), 24 | KEY `cid` (`cid`), 25 | CONSTRAINT `tb_order_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `tb_custom` (`cid`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 27 | ''' 28 | 29 | 30 | 31 | if __name__ == "__main__": 32 | import sys 33 | sys.path.append("..") 34 | sys.path.append("../base") 35 | 36 | from hjs_cfg import * 37 | from bs_util import * 38 | from bs_database_pid import * 39 | 40 | 41 | class HjsOrderDao: 42 | 43 | @staticmethod 44 | def insert_node(cId, name, otype, order_tm, start_tm, end_tm, amount, cash, remark): 45 | 46 | dataBase = DataBase() 47 | sql = "insert into tb_order(cid, name, otype, order_tm, start_tm, end_tm, amount, cash, remark, insert_tm) " \ 48 | "values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" 49 | param = (cId, name, otype, order_tm, start_tm, end_tm, amount, cash, remark, get_cur_time()) 50 | 51 | bRet, sRet = dataBase.insert_data(sql, param) 52 | return bRet, sRet 53 | 54 | 55 | @staticmethod 56 | def update_node(oId, otype, order_tm, start_tm, end_tm, amount, cash, status, remark): 57 | 58 | dataBase = DataBase() 59 | sql = "update tb_order set otype=%s, order_tm=%s, start_tm=%s, end_tm=%s, amount=%s, cash=%s, " \ 60 | "status = %s, remark=%s where oid= %s" 61 | param = (otype, order_tm, start_tm, end_tm, amount, cash, status, remark, oId) 62 | 63 | bRet, sRet = dataBase.update_data(sql, param) 64 | return bRet, sRet 65 | 66 | 67 | @staticmethod 68 | def update_node_status(oId, status): 69 | dataBase = DataBase() 70 | sql = "update tb_order set status = %s where oid = %s" 71 | param = (status, oId) 72 | 73 | bRet, sRet = dataBase.update_data(sql, param) 74 | if not bRet: 75 | return False, sRet 76 | 77 | return True, sRet 78 | 79 | 80 | @staticmethod 81 | def query_node_list(offset, limit, status, search): 82 | dataBase = DataBase() 83 | sql = "select * from tb_order where 1=1 " 84 | param = [] 85 | if status and status != 'all': 86 | sql += "and status = %s " 87 | param.append(status) 88 | if search: 89 | search = "%%%s%%" % (search) 90 | sql += "and (cid like %s or name like %s)" 91 | param.append(search) 92 | param.append(search) 93 | 94 | sql += "order by oid desc limit %s, %s" 95 | param.append(offset) 96 | param.append(limit) 97 | 98 | param = tuple(param) 99 | bRet, sRet = dataBase.query_data(sql, param) 100 | if not bRet: 101 | return False, sRet 102 | 103 | return True, sRet 104 | 105 | 106 | @staticmethod 107 | def query_node_count(status=None, search=None): 108 | dataBase = DataBase() 109 | sql = "select count(*) as cnt from tb_order where 1=1 " 110 | param = [] 111 | 112 | if status and status != 'all': 113 | sql += "and status = %s" 114 | param.append(status) 115 | if search: 116 | search = "%%%s%%" % (search) 117 | sql += "and (cid like %s or name like %s)" 118 | param.append(search) 119 | param.append(search) 120 | 121 | param = tuple(param) 122 | bRet, sRet = dataBase.query_data(sql, param) 123 | if not bRet: 124 | return False, sRet 125 | if len(sRet) !=1: 126 | return True, 0 127 | 128 | return True, sRet[0]['cnt'] 129 | 130 | @staticmethod 131 | def query_node_by_oid(oId): 132 | dataBase = DataBase() 133 | sql = "select * from tb_order where oid = %s" 134 | param = (oId, ) 135 | 136 | bRet, sRet = dataBase.query_data(sql, param) 137 | if (not bRet) or (len(sRet) != 1): 138 | return False, sRet 139 | 140 | return True, sRet[0] 141 | 142 | 143 | @staticmethod 144 | def query_node_by_status(status): 145 | dataBase = DataBase() 146 | sql = "select count(*) as cnt from tb_order where 1=1 " 147 | param = [] 148 | 149 | if status == 'all': 150 | pass 151 | else: 152 | sql += 'and status = %s' 153 | param.append(status) 154 | 155 | param = tuple(param) 156 | bRet, sRet = dataBase.query_data(sql, param) 157 | if not bRet: 158 | return False, sRet 159 | if len(sRet) != 1: 160 | return True, 0 161 | 162 | return True, sRet[0]['cnt'] 163 | 164 | 165 | @staticmethod 166 | def query_node_by_days(days): 167 | dataBase = DataBase() 168 | sql = "select oid, cid, name, date_format(end_tm, '%%Y-%%m-%%d') as end_tm from tb_order " \ 169 | "where end_tm >= curdate() and end_tm < curdate() + %s" 170 | param = (days, ) 171 | 172 | bRet, sRet = dataBase.query_data(sql, param) 173 | if not bRet: 174 | return False, sRet 175 | 176 | return True, sRet 177 | 178 | 179 | @staticmethod 180 | def query_node_by_date(status, tg_date): 181 | dataBase = DataBase() 182 | sql = "select * from tb_order where status = %s and start_tm <= %s and %s <= end_tm" 183 | param = (status, tg_date, tg_date) 184 | 185 | bRet, sRet = dataBase.query_data(sql, param) 186 | if not bRet: 187 | return False, sRet 188 | 189 | return True, sRet 190 | 191 | 192 | if __name__ == "__main__": 193 | #print HjsOrderDao.query_node_by_status('stop') 194 | 195 | print HjsOrderDao.query_node_by_date('normal', '2017-01-02') 196 | 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /src/dao/hjs_ps_order_dao.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: tb_order_dao 6 | 7 | 8 | ''' 9 | # 暂取消订单表 10 | CREATE TABLE `tb_ps_order` ( 11 | `pid` int(11) NOT NULL AUTO_INCREMENT, 12 | `oid` int(10) NOT NULL, 13 | `cid` int(10) NOT NULL, 14 | `name` varchar(50) NOT NULL, 15 | `pause_tm` date NOT NULL, 16 | `remark` text NOT NULL, 17 | `insert_tm` datetime NOT NULL, 18 | PRIMARY KEY (`pid`), 19 | KEY `oid` (`oid`), 20 | KEY `cid` (`cid`), 21 | CONSTRAINT `tb_ps_order_ibfk_1` FOREIGN KEY (`oid`) REFERENCES `tb_order` (`oid`), 22 | CONSTRAINT `tb_ps_order_ibfk_2` FOREIGN KEY (`cid`) REFERENCES `tb_custom` (`cid`) 23 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 24 | ''' 25 | 26 | if __name__ == "__main__": 27 | import sys 28 | sys.path.append("..") 29 | sys.path.append("../base") 30 | 31 | from hjs_cfg import * 32 | from bs_util import * 33 | from bs_database_pid import * 34 | 35 | 36 | class HjsOrderPauseDao: 37 | 38 | @staticmethod 39 | def insert_node(oid, cid, name, pause_tm, remark): 40 | 41 | dataBase = DataBase() 42 | sql = "insert into tb_ps_order(oid, cid, name, pause_tm, remark, insert_tm) " \ 43 | "values(%s, %s, %s, %s, %s, %s)" 44 | param = (oid, cid, name, pause_tm, remark, get_cur_time()) 45 | 46 | bRet, sRet = dataBase.insert_data(sql, param) 47 | return bRet, sRet 48 | 49 | @staticmethod 50 | def query_node_list(offset, limit, status, search): 51 | dataBase = DataBase() 52 | sql = "select * from tb_order where 1=1 " 53 | param = [] 54 | if status and status != 'all': 55 | sql += "and status = %s " 56 | param.append(status) 57 | if search: 58 | search = "%%%s%%" % (search) 59 | sql += "and (cid like %s or name like %s)" 60 | param.append(search) 61 | param.append(search) 62 | 63 | sql += "order by oid desc limit %s, %s" 64 | param.append(offset) 65 | param.append(limit) 66 | 67 | param = tuple(param) 68 | bRet, sRet = dataBase.query_data(sql, param) 69 | if not bRet: 70 | return False, sRet 71 | 72 | return True, sRet 73 | 74 | 75 | @staticmethod 76 | def query_node_count(status=None, search=None): 77 | dataBase = DataBase() 78 | sql = "select count(*) as cnt from tb_order where 1=1 " 79 | param = [] 80 | 81 | if status and status != 'all': 82 | sql += "and status = %s" 83 | param.append(status) 84 | if search: 85 | search = "%%%s%%" % (search) 86 | sql += "and (cid like %s or name like %s)" 87 | param.append(search) 88 | param.append(search) 89 | 90 | param = tuple(param) 91 | bRet, sRet = dataBase.query_data(sql, param) 92 | if not bRet: 93 | return False, sRet 94 | if len(sRet) !=1: 95 | return True, 0 96 | 97 | return True, sRet[0]['cnt'] 98 | 99 | 100 | @staticmethod 101 | def delete_node_by_pid(pId): 102 | dataBase = DataBase() 103 | sql = "delete from tb_ps_order where pid = %s" 104 | param = (pId, ) 105 | 106 | bRet, sRet = dataBase.delete_data(sql, param) 107 | if not bRet: 108 | return False, sRet 109 | 110 | return True, sRet 111 | 112 | 113 | @staticmethod 114 | def query_node_by_date(tg_date): 115 | dataBase = DataBase() 116 | sql = "select * from tb_ps_order where pause_tm = %s" 117 | param = (tg_date, ) 118 | 119 | bRet, sRet = dataBase.query_data(sql, param) 120 | if not bRet: 121 | return False, sRet 122 | 123 | return True, sRet 124 | 125 | 126 | 127 | if __name__ == "__main__": 128 | #print HjsOrderDao.query_node_by_status('stop') 129 | 130 | #print HjsOrderDao.query_node_by_date(3) 131 | print HjsOrderPauseDao.delete_node_by_pid(3) 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /src/dao/hjs_user_dao.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: tb_user_dao 6 | 7 | 8 | ''' 9 | # 用户操作 10 | CREATE TABLE `tb_user` ( 11 | `uid` int(10) NOT NULL AUTO_INCREMENT, 12 | `username` varchar(50) NOT NULL, 13 | `nickname` varchar(50) NOT NULL, 14 | `password` varchar(50) NOT NULL, 15 | `phone` varchar(50) DEFAULT NULL, 16 | `email` varchar(50) DEFAULT NULL, 17 | `privilege` int(1) NOT NULL DEFAULT '1', 18 | `remark` text, 19 | PRIMARY KEY (`uid`) 20 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 21 | ''' 22 | 23 | if __name__ == "__main__": 24 | import sys 25 | 26 | sys.path.append("..") 27 | sys.path.append("../base") 28 | 29 | from hjs_cfg import * 30 | from bs_util import * 31 | from bs_database_pid import * 32 | 33 | 34 | class HjsUserDao: 35 | 36 | @staticmethod 37 | def query_node_by_username(userName): 38 | dataBase = DataBase() 39 | sql = "select * from tb_user where username = %s" 40 | param = (userName, ) 41 | 42 | bRet, sRet = dataBase.query_data(sql, param) 43 | if not bRet: 44 | return False, sRet 45 | 46 | return True, sRet[0] 47 | 48 | 49 | @staticmethod 50 | def query_node_by_uid(uid): 51 | dataBase = DataBase() 52 | sql = "select * from tb_user where uid = %s" 53 | param = (uid, ) 54 | 55 | bRet, sRet = dataBase.query_data(sql, param) 56 | if not bRet: 57 | return False, sRet 58 | 59 | return True, sRet[0] 60 | 61 | 62 | @staticmethod 63 | def query_node_user_list(): 64 | dataBase = DataBase() 65 | sql = "select * from tb_user" 66 | 67 | bRet, sRet = dataBase.query_data(sql, None) 68 | if not bRet: 69 | return False, sRet 70 | 71 | return True, sRet 72 | 73 | 74 | @staticmethod 75 | def insert_node_user(nickName, userName, passWord, Phone, Email, Priv): 76 | dataBase = DataBase() 77 | sql = "insert into tb_user(nickname, username, password, phone, email, privilege, lastlogin) values(%s, %s, %s, %s, %s, %s, %s)" 78 | param = (nickName, userName, passWord, Phone, Email, Priv, get_cur_time()) 79 | 80 | bRet, sRet = dataBase.insert_data(sql, param) 81 | if not bRet: 82 | return False, sRet 83 | 84 | return True, sRet 85 | 86 | 87 | @staticmethod 88 | def update_node_user(uId, nickName, userName, passWord, Phone, Email, Priv): 89 | dataBase = DataBase() 90 | sql = "update tb_user set nickname = %s, username = %s, password = %s, phone = %s, email = %s, privilege= %s where uid = %s" 91 | param = (nickName, userName, passWord, Phone, Email, Priv, uId) 92 | 93 | bRet, sRet = dataBase.update_data(sql, param) 94 | if not bRet: 95 | return False, sRet 96 | 97 | return True, sRet 98 | 99 | 100 | @staticmethod 101 | def delete_node_user(uId): 102 | dataBase = DataBase() 103 | sql = "delete from tb_user where uid = %s" 104 | param = (uId, ) 105 | 106 | bRet, sRet = dataBase.delete_data(sql, param) 107 | if not bRet: 108 | return False, sRet 109 | 110 | return True, sRet 111 | 112 | @staticmethod 113 | def update_lastlogin(uId): 114 | dataBase = DataBase() 115 | sql = "update tb_user set lastlogin = %s where uid = %s" 116 | param = (get_cur_time(), uId) 117 | 118 | return dataBase.update_data(sql, param) 119 | 120 | 121 | 122 | 123 | 124 | if __name__ == "__main__": 125 | #print HjsUserDao.query_node_by_username('admin') 126 | print HjsUserDao.query_node_user_list() 127 | 128 | pass 129 | -------------------------------------------------------------------------------- /src/hjs_cfg.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: 简易订单系统 6 | 7 | 8 | from bs_base_cfg import * 9 | 10 | class EnvEnum: 11 | T_DEV = "dev" 12 | T_ONLINE = "online" 13 | 14 | CUR_ENV = EnvEnum.T_DEV 15 | 16 | if CUR_ENV == EnvEnum.T_DEV: 17 | 18 | BaseConf.IS_CTR_LOG = True 19 | BaseConf.LOG_LEVEL = 1 20 | BaseConf.SQL_HOST = "222.xx.xx.xx" 21 | BaseConf.SQL_PORT = 3306 22 | BaseConf.SQL_USER = "db_user" 23 | BaseConf.SQL_PASSWD = "db_passwd" 24 | BaseConf.SQL_DB = "hjs_cms_db" 25 | 26 | 27 | else: 28 | BaseConf.IS_CTR_LOG = False 29 | BaseConf.LOG_LEVEL = 2 30 | BaseConf.SQL_HOST = "127.0.0.1" 31 | BaseConf.SQL_PORT = 3306 32 | BaseConf.SQL_USER = "db_user" 33 | BaseConf.SQL_PASSWD = "db_passwd" 34 | BaseConf.SQL_DB = "hjs_cms_db" 35 | 36 | 37 | 38 | # with local cfg, so do not modify the file when test in the local env. 39 | if os.path.exists(os.path.join(os.path.dirname(__file__), 'hjs_local_cfg.py')): 40 | from hjs_local_cfg import * 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/web/sessions/debbfa68ae475a5b8f82f961b149a19ef8526f5e: -------------------------------------------------------------------------------- 1 | KGRwMQpTJ3VzZXJuYW1lJwpwMgpTJ2FkbWluJwpwMwpzUydpcCcKcDQKVjEyNy4wLjAuMQpwNQpz 2 | UydzZXNzaW9uX2lkJwpwNgpTJ2RlYmJmYTY4YWU0NzVhNWI4ZjgyZjk2MWIxNDlhMTllZjg1MjZm 3 | NWUnCnA3CnMu 4 | -------------------------------------------------------------------------------- /src/web/static/css/component.css: -------------------------------------------------------------------------------- 1 | /* General styles for all menus */ 2 | .cbp-spmenu { 3 | background: #47a3da; 4 | position: fixed; 5 | } 6 | 7 | .cbp-spmenu h3 { 8 | color: #afdefa; 9 | font-size: 1.9em; 10 | padding: 20px; 11 | margin: 0; 12 | font-weight: 300; 13 | background: #0d77b6; 14 | } 15 | 16 | .cbp-spmenu a { 17 | display: block; 18 | color: #fff; 19 | font-size: 1.1em; 20 | font-weight: 300; 21 | } 22 | 23 | .cbp-spmenu a:hover { 24 | background: #258ecd; 25 | } 26 | 27 | .cbp-spmenu a:active { 28 | background: #afdefa; 29 | color: #47a3da; 30 | } 31 | 32 | /* Orientation-dependent styles for the content of the menu */ 33 | 34 | .cbp-spmenu-vertical { 35 | width: 240px; 36 | height: 100%; 37 | top: 0; 38 | z-index: 1000; 39 | } 40 | 41 | .cbp-spmenu-vertical a { 42 | border-bottom: 1px solid #258ecd; 43 | padding: 1em; 44 | } 45 | 46 | .cbp-spmenu-horizontal { 47 | width: 100%; 48 | height: 150px; 49 | left: 0; 50 | z-index: 1000; 51 | overflow: hidden; 52 | } 53 | 54 | .cbp-spmenu-horizontal h3 { 55 | height: 100%; 56 | width: 20%; 57 | float: left; 58 | } 59 | 60 | .cbp-spmenu-horizontal a { 61 | float: left; 62 | width: 20%; 63 | padding: 0.8em; 64 | border-left: 1px solid #258ecd; 65 | } 66 | 67 | /* Vertical menu that slides from the left or right */ 68 | 69 | .cbp-spmenu-left { 70 | left: -240px; 71 | } 72 | 73 | .cbp-spmenu-right { 74 | right: -240px; 75 | } 76 | 77 | .cbp-spmenu-left.cbp-spmenu-open { 78 | left: 0px; 79 | } 80 | 81 | .cbp-spmenu-right.cbp-spmenu-open { 82 | right: 0px; 83 | } 84 | 85 | /* Horizontal menu that slides from the top or bottom */ 86 | 87 | .cbp-spmenu-top { 88 | top: -150px; 89 | } 90 | 91 | .cbp-spmenu-bottom { 92 | bottom: -150px; 93 | } 94 | 95 | .cbp-spmenu-top.cbp-spmenu-open { 96 | top: 0px; 97 | } 98 | 99 | .cbp-spmenu-bottom.cbp-spmenu-open { 100 | bottom: 0px; 101 | } 102 | 103 | /* Push classes applied to the body */ 104 | 105 | .cbp-spmenu-push { 106 | overflow-x: hidden; 107 | position: relative; 108 | left: 0; 109 | } 110 | 111 | .cbp-spmenu-push-toright { 112 | left: 240px; 113 | } 114 | 115 | .cbp-spmenu-push-toleft { 116 | left: -240px; 117 | } 118 | 119 | /* Transitions */ 120 | 121 | .cbp-spmenu, 122 | .cbp-spmenu-push { 123 | -webkit-transition: all 0.3s ease; 124 | -moz-transition: all 0.3s ease; 125 | transition: all 0.3s ease; 126 | } 127 | 128 | /* Example media queries */ 129 | 130 | @media screen and (max-width: 55.1875em){ 131 | 132 | .cbp-spmenu-horizontal { 133 | font-size: 75%; 134 | height: 110px; 135 | } 136 | 137 | .cbp-spmenu-top { 138 | top: -110px; 139 | } 140 | 141 | .cbp-spmenu-bottom { 142 | bottom: -110px; 143 | } 144 | 145 | } 146 | 147 | @media screen and (max-height: 26.375em){ 148 | 149 | .cbp-spmenu-vertical { 150 | font-size: 90%; 151 | width: 190px; 152 | } 153 | 154 | .cbp-spmenu-left, 155 | .cbp-spmenu-push-toleft { 156 | left: -190px; 157 | } 158 | 159 | .cbp-spmenu-right { 160 | right: -190px; 161 | } 162 | 163 | .cbp-spmenu-push-toright { 164 | left: 190px; 165 | } 166 | } -------------------------------------------------------------------------------- /src/web/static/css/hack.css: -------------------------------------------------------------------------------- 1 | @charset"UTF-8"; 2 | /* hack css */ 3 | #TopMain, 4 | #BtmMain, 5 | .selectbox, 6 | .txtbox, 7 | #Popup #BtmBtn 8 | {display:inline-block;} 9 | 10 | 11 | #TopMain:after, 12 | #BtmMain:after, 13 | .selectbox:after, 14 | .txtbox:after, 15 | #Popup #BtmBtn:after 16 | {content: ".";display: block;height: 0;clear: both;visibility: hidden;overflow: hidden;} 17 | 18 | 19 | 20 | /* Hide from IE-mac \*/ 21 | *html #TopMain, 22 | *html #BtmMain, 23 | *html .selectbox, 24 | *html .txtbox, 25 | *html #Popup #BtmBtn 26 | {height: 1%;} 27 | 28 | 29 | #TopMain, 30 | #BtmMain, 31 | .selectbox, 32 | .txtbox, 33 | #Popup #BtmBtn 34 | {display: block;} 35 | /* End hide fromIE-mac*/ 36 | 37 | -------------------------------------------------------------------------------- /src/web/static/css/haiersoft.css: -------------------------------------------------------------------------------- 1 | @import "reset.css"; 2 | @import "base.css"; 3 | @import "hack.css"; 4 | @import "(print.css)print"; -------------------------------------------------------------------------------- /src/web/static/css/login.css: -------------------------------------------------------------------------------- 1 | *{ 2 | font: 13px/1.5 '微软雅黑', Verdana, Helvetica, Arial, sans-serif; 3 | -webkit-box-sizing: border-box; 4 | -moz-box-sizing: border-box; 5 | -box-sizing: border-box; 6 | padding:0; 7 | margin:0; 8 | list-style:none; 9 | box-sizing: border-box; 10 | } 11 | 12 | body,html{ 13 | height:100%; 14 | overflow:hidden; 15 | } 16 | body{ 17 | background:url(../images/web_login_bg.jpg) no-repeat center; 18 | background-size: cover; 19 | } 20 | a{ 21 | color:#27A9E3; 22 | text-decoration:none; 23 | cursor:pointer; 24 | } 25 | .login{ 26 | margin: 150px auto 0 auto; 27 | min-height: 420px; 28 | max-width: 420px; 29 | padding: 40px; 30 | background-color: #ffffff; 31 | margin-left: auto; 32 | margin-right: auto; 33 | border-radius: 4px; 34 | /* overflow-x: hidden; */ 35 | box-sizing: border-box; 36 | } 37 | a.logo{ 38 | display: block; 39 | height: 58px; 40 | width: 167px; 41 | margin: 0 auto 30px auto; 42 | background-size: 167px 42px; 43 | } 44 | .message { 45 | margin: 10px 0 0 -58px; 46 | padding: 18px 10px 18px 60px; 47 | background: #27A9E3; 48 | position: relative; 49 | color: #fff; 50 | font-size: 16px; 51 | } 52 | #darkbannerwrap { 53 | background: url(../images/aiwrap.png); 54 | width: 18px; 55 | height: 10px; 56 | margin: 0 0 20px -58px; 57 | position: relative; 58 | } 59 | 60 | input[type=text], 61 | input[type=file], 62 | input[type=password], 63 | input[type=email], select { 64 | border: 1px solid #DCDEE0; 65 | vertical-align: middle; 66 | border-radius: 3px; 67 | height: 50px; 68 | padding: 0px 16px; 69 | font-size: 14px; 70 | color: #555555; 71 | outline:none; 72 | width:100%; 73 | } 74 | input[type=text]:focus, 75 | input[type=file]:focus, 76 | input[type=password]:focus, 77 | input[type=email]:focus, select:focus { 78 | border: 1px solid #27A9E3; 79 | } 80 | 81 | 82 | input[type=submit], 83 | input[type=button]{ 84 | display: inline-block; 85 | vertical-align: middle; 86 | padding: 12px 24px; 87 | margin: 0px; 88 | font-size: 18px; 89 | line-height: 24px; 90 | text-align: center; 91 | white-space: nowrap; 92 | vertical-align: middle; 93 | cursor: pointer; 94 | color: #ffffff; 95 | background-color: #27A9E3; 96 | border-radius: 3px; 97 | border: none; 98 | -webkit-appearance: none; 99 | outline:none; 100 | width:100%; 101 | } 102 | hr.hr15 { 103 | height: 15px; 104 | border: none; 105 | margin: 0px; 106 | padding: 0px; 107 | width: 100%; 108 | } 109 | hr.hr20 { 110 | height: 20px; 111 | border: none; 112 | margin: 0px; 113 | padding: 0px; 114 | width: 100%; 115 | } 116 | 117 | .copyright{ 118 | font-size:14px; 119 | color:rgba(255,255,255,0.85); 120 | display:block; 121 | position:absolute; 122 | bottom:15px; 123 | right:15px; 124 | } -------------------------------------------------------------------------------- /src/web/static/css/print.css: -------------------------------------------------------------------------------- 1 | @charset"UTF-8"; 2 | 3 | #Side, 4 | #Header ul 5 | {display: none;} 6 | 7 | #Wrap{border:none;} 8 | #Contents{} 9 | #Main{padding:10px 54px;float:none;} 10 | address{} 11 | -------------------------------------------------------------------------------- /src/web/static/css/reset.css: -------------------------------------------------------------------------------- 1 | @charset"UTF-8"; 2 | 3 | body{margin:0px;padding:0px;font-family:Verdana, Arial, Helvetica, Meiryo, '微软雅黑', sans-serif;font-size: 12px; background-color:#f1f1f1; color:#333;} 4 | div, 5 | form, 6 | h1,h2,h3,h4, 7 | ul,li, 8 | dl,dt,dd, 9 | p{margin:0px;padding:0px;line-height: 1.5em;} 10 | p,dt,dd{text-align:justify;text-justify:distribute;} 11 | a img,img{border:0;} 12 | li{list-style-type:none;} 13 | 14 | *{transition:color 200ms,background 200ms,border 200ms,opacity 300ms; 15 | -moz-transition:color 200ms,background 200ms,border 200ms,opacity 300ms; 16 | -webkit-transition:color 200ms,background 200ms,border 200ms,opacity 300ms; 17 | -o-transition:color 200ms,background 200ms,border 200ms,opacity 300ms} -------------------------------------------------------------------------------- /src/web/static/images/aiwrap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/aiwrap.png -------------------------------------------------------------------------------- /src/web/static/images/common/clear.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/clear.gif -------------------------------------------------------------------------------- /src/web/static/images/common/ico01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico01.png -------------------------------------------------------------------------------- /src/web/static/images/common/ico02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico02.png -------------------------------------------------------------------------------- /src/web/static/images/common/ico03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico03.png -------------------------------------------------------------------------------- /src/web/static/images/common/ico04.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico04.gif -------------------------------------------------------------------------------- /src/web/static/images/common/ico05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico05.png -------------------------------------------------------------------------------- /src/web/static/images/common/ico06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico06.png -------------------------------------------------------------------------------- /src/web/static/images/common/ico07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico07.png -------------------------------------------------------------------------------- /src/web/static/images/common/ico_arrow01.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico_arrow01.gif -------------------------------------------------------------------------------- /src/web/static/images/common/ico_uer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/ico_uer.gif -------------------------------------------------------------------------------- /src/web/static/images/common/left.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/left.gif -------------------------------------------------------------------------------- /src/web/static/images/common/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/logo.png -------------------------------------------------------------------------------- /src/web/static/images/common/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/logo2.png -------------------------------------------------------------------------------- /src/web/static/images/common/right.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/right.gif -------------------------------------------------------------------------------- /src/web/static/images/common/懒人图库.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/common/懒人图库.txt -------------------------------------------------------------------------------- /src/web/static/images/web_login_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/static/images/web_login_bg.jpg -------------------------------------------------------------------------------- /src/web/static/js/classie.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * classie - class helper functions 3 | * from bonzo https://github.com/ded/bonzo 4 | * 5 | * classie.has( elem, 'my-class' ) -> true/false 6 | * classie.add( elem, 'my-new-class' ) 7 | * classie.remove( elem, 'my-unwanted-class' ) 8 | * classie.toggle( elem, 'my-class' ) 9 | */ 10 | 11 | /*jshint browser: true, strict: true, undef: true */ 12 | 13 | ( function( window ) { 14 | 15 | 'use strict'; 16 | 17 | // class helper functions from bonzo https://github.com/ded/bonzo 18 | 19 | function classReg( className ) { 20 | return new RegExp("(^|\\s+)" + className + "(\\s+|$)"); 21 | } 22 | 23 | // classList support for class management 24 | // altho to be fair, the api sucks because it won't accept multiple classes at once 25 | var hasClass, addClass, removeClass; 26 | 27 | if ( 'classList' in document.documentElement ) { 28 | hasClass = function( elem, c ) { 29 | return elem.classList.contains( c ); 30 | }; 31 | addClass = function( elem, c ) { 32 | elem.classList.add( c ); 33 | }; 34 | removeClass = function( elem, c ) { 35 | elem.classList.remove( c ); 36 | }; 37 | } 38 | else { 39 | hasClass = function( elem, c ) { 40 | return classReg( c ).test( elem.className ); 41 | }; 42 | addClass = function( elem, c ) { 43 | if ( !hasClass( elem, c ) ) { 44 | elem.className = elem.className + ' ' + c; 45 | } 46 | }; 47 | removeClass = function( elem, c ) { 48 | elem.className = elem.className.replace( classReg( c ), ' ' ); 49 | }; 50 | } 51 | 52 | function toggleClass( elem, c ) { 53 | var fn = hasClass( elem, c ) ? removeClass : addClass; 54 | fn( elem, c ); 55 | } 56 | 57 | window.classie = { 58 | // full names 59 | hasClass: hasClass, 60 | addClass: addClass, 61 | removeClass: removeClass, 62 | toggleClass: toggleClass, 63 | // short names 64 | has: hasClass, 65 | add: addClass, 66 | remove: removeClass, 67 | toggle: toggleClass 68 | }; 69 | 70 | })( window ); -------------------------------------------------------------------------------- /src/web/static/js/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * project: hjs_cms 3 | * author: s0nnet 4 | * 5 | */ 6 | 7 | 8 | /*用户列表*/ 9 | function get_data_count(){ 10 | $.ajax({ 11 | type: "GET", 12 | async: true, 13 | dataType: "json", 14 | url: "/api/data/count", 15 | error: function(){ 16 | console.log("/api/data/count/error"); 17 | }, 18 | success: function(data){ 19 | if(data.code == 101){ 20 | alert(data.message); 21 | } 22 | if(data.code == 201){ 23 | if(!data.result){ 24 | return; 25 | } 26 | 27 | var dt_custom = data.result.dt_custom; 28 | $("#custom_cnt").html(dt_custom.custom_cnt); 29 | $("#custom_nor").html(dt_custom.custom_nor); 30 | $("#custom_can").html(dt_custom.custom_can); 31 | 32 | var dt_order = data.result.dt_order; 33 | $("#order_cnt").html(dt_order.order_cnt); 34 | $("#order_nor").html(dt_order.order_nor); 35 | $("#order_stop").html(dt_order.order_stop); 36 | $("#order_today").html(dt_order.order_today); 37 | $("#order_today_stop").html(dt_order.order_today_stop); 38 | 39 | var dt_days = data.result.dt_days; 40 | 41 | var days_3_count = dt_days.days_3.count; 42 | var days_3_list = dt_days.days_3.list; 43 | var lists = '人 -> '; 44 | for(var i=0; i < days_3_list.length; i++){ 45 | res = days_3_list[i]; 46 | oid = res['oid']; 47 | name = res['name']; 48 | end_tm = res['end_tm']; 49 | lists += '['+oid+' '+name+' '+end_tm+'],'; 50 | } 51 | var days3 = days_3_count + lists; 52 | $("#days_3").html(days3); 53 | 54 | var days_7_count = dt_days.days_7.count; 55 | var days_7_list = dt_days.days_7.list; 56 | var lists = '人 -> '; 57 | for(var i=0; i < days_7_list.length; i++){ 58 | res = days_3_list[i]; 59 | oid = res['oid']; 60 | name = res['name']; 61 | end_tm = res['end_tm']; 62 | lists += '['+oid+' '+name+' '+end_tm+'],'; 63 | } 64 | var days7 = days_7_count + lists; 65 | $("#days_7").html(days7); 66 | 67 | $("#update_date").html(data.result.update_date); 68 | } 69 | } 70 | }); 71 | } 72 | -------------------------------------------------------------------------------- /src/web/static/js/modernizr.custom.js: -------------------------------------------------------------------------------- 1 | /* Modernizr 2.6.2 (Custom Build) | MIT & BSD 2 | * Build: http://modernizr.com/download/#-shiv-cssclasses-load 3 | */ 4 | ;window.Modernizr=function(a,b,c){function u(a){j.cssText=a}function v(a,b){return u(prefixes.join(a+";")+(b||""))}function w(a,b){return typeof a===b}function x(a,b){return!!~(""+a).indexOf(b)}function y(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:w(f,"function")?f.bind(d||b):f}return!1}var d="2.6.2",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m={},n={},o={},p=[],q=p.slice,r,s={}.hasOwnProperty,t;!w(s,"undefined")&&!w(s.call,"undefined")?t=function(a,b){return s.call(a,b)}:t=function(a,b){return b in a&&w(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=q.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(q.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(q.call(arguments)))};return e});for(var z in m)t(m,z)&&(r=z.toLowerCase(),e[r]=m[z](),p.push((e[r]?"":"no-")+r));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)t(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},u(""),i=k=null,function(a,b){function k(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function l(){var a=r.elements;return typeof a=="string"?a.split(" "):a}function m(a){var b=i[a[g]];return b||(b={},h++,a[g]=h,i[h]=b),b}function n(a,c,f){c||(c=b);if(j)return c.createElement(a);f||(f=m(c));var g;return f.cache[a]?g=f.cache[a].cloneNode():e.test(a)?g=(f.cache[a]=f.createElem(a)).cloneNode():g=f.createElem(a),g.canHaveChildren&&!d.test(a)?f.frag.appendChild(g):g}function o(a,c){a||(a=b);if(j)return a.createDocumentFragment();c=c||m(a);var d=c.frag.cloneNode(),e=0,f=l(),g=f.length;for(;e",f="hidden"in a,j=a.childNodes.length==1||function(){b.createElement("a");var a=b.createDocumentFragment();return typeof a.cloneNode=="undefined"||typeof a.createDocumentFragment=="undefined"||typeof a.createElement=="undefined"}()}catch(c){f=!0,j=!0}})();var r={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,supportsUnknownElements:j,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:q,createElement:n,createDocumentFragment:o};a.html5=r,q(b)}(this,b),e._version=d,g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+p.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f"+ oid +""+ 89 | ""+ cid +""+ 90 | ""+ name +""+ 91 | ""+ address +""+ 92 | ""+ phone +""+ 93 | ""+ otype +""+ 94 | ""+ ctype +""+ 95 | ""+ status +""+ 96 | ""+ remark +""+ 97 | "" 98 | ); 99 | $("#data_count").html(dataLen); 100 | } 101 | } 102 | } 103 | }); 104 | } 105 | 106 | /*订单数据CSV文件导出*/ 107 | function export_order_today(){ 108 | 109 | $.ajax({ 110 | type: "GET", 111 | async: true, 112 | dataType: "json", 113 | url: "/api/order/today", 114 | data: {"page": 1, "length":10000}, 115 | error: function(){ 116 | console.log("/api/order/today/error"); 117 | }, 118 | success: function(data){ 119 | if(data.code == 101){ 120 | alert("export fail: "+data.message); 121 | } 122 | if(data.code == 201){ 123 | if(!data.result){ 124 | return; 125 | } 126 | jsonData = data.result; 127 | order_jsonTocsv(jsonData, true); 128 | } 129 | } 130 | }); 131 | } 132 | 133 | /*order: jsonTocsv*/ 134 | function order_jsonTocsv(JSONData, ShowLabel) { 135 | var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; 136 | var CSV = ''; 137 | 138 | if (ShowLabel) { 139 |     //add column index 140 | var row = "订单号,客户号,客户姓名,配送地址,联系电话,奶类,客户类型,订单状态,备注,说明1,说明2"; 141 | CSV += row + '\r\n'; 142 | } 143 | 144 | //loop each column 145 | for (var i = 0; i < arrData.length; i++) { 146 | var row = ""; 147 | 148 | item = arrData[i]; 149 | 150 | var status = item.status; 151 | if(status == "normal"){ 152 | status = "正常"; 153 | }else if(status == "stop"){ 154 | status = "暂取消"; 155 | }else{ 156 | status = status; 157 | } 158 | 159 | var ctype = item.ctype; 160 | if(ctype == "O"){ 161 | ctype = "老"; 162 | }else if(ctype == "N"){ 163 | ctype = "新"; 164 | }else{ 165 | ctype = ctype; 166 | } 167 | 168 | row += '"'+ item.oid +'",'+ 169 | '"'+ item.cid +'",'+ 170 | '"'+ item.name +'",'+ 171 | '"'+ item.address +'",'+ 172 | '"'+ item.phone +'",'+ 173 | '"'+ item.otype +'",'+ 174 | '"'+ ctype +'",'+ 175 | '"'+ status +'",'+ 176 | '"'+ item.remark +'",'+'" ",'+'" "'; 177 | 178 | CSV += row + '\r\n'; 179 | } 180 | 181 | if (CSV == '') { 182 | alert("Invalid data"); 183 | return; 184 | } 185 | 186 | var d = new Date(); 187 | var year = d.getFullYear(); 188 | var month = d.getMonth()+1; 189 | var date = d.getDate(); 190 | var hour = d.getHours(); 191 | var minute = d.getMinutes(); 192 | var timestr = year+"_"+month+"_"+date+"_"+hour+"_"+minute; 193 | 194 | var fileName = "今日订单列表_导出_"+timestr; 195 | var uri = 'data:text/csv;charset=utf-8,\uFEFF' + encodeURI(CSV); 196 | 197 | var link = document.createElement("a"); 198 | link.href = uri; 199 | 200 | link.style = "visibility:hidden"; 201 | link.download = fileName + ".csv"; 202 | 203 | document.body.appendChild(link); 204 | link.click(); 205 | document.body.removeChild(link); 206 | } 207 | 208 | 209 | /*订单删除*/ 210 | function del_order(oid){ 211 | if(!confirm("确认删除该用户?")){ 212 | return; 213 | } 214 | $.ajax({ 215 | type: "POST", 216 | async: true, 217 | dataType: "json", 218 | url: "/api/order/del", 219 | data: {"oid": oid}, 220 | error: function() { 221 | console.log("/api/order/del/error"); 222 | }, 223 | success: function(data){ 224 | if(data.code == 201){ 225 | get_order_list(); 226 | }else{ 227 | alert("删除订单失败[Error:" + data.message + "]"); 228 | } 229 | } 230 | }); 231 | } 232 | 233 | 234 | 235 | /*获取URL传过来的参数*/ 236 | function get_request_args(argname){ 237 | var url = document.location.href; 238 | var arrStr = url.substring(url.indexOf("?")+1).split("&"); 239 | 240 | for(var i = 0; i < arrStr.length; i++) { 241 | var loc = arrStr[i].indexOf(argname+"="); 242 | if(loc != -1){ 243 | return arrStr[i].replace(argname+"=","").replace("?",""); 244 | break; 245 | } 246 | } 247 | return ""; 248 | } 249 | 250 | 251 | -------------------------------------------------------------------------------- /src/web/static/js/others.js: -------------------------------------------------------------------------------- 1 | /** 2 | * project: hjs_cms 3 | * author: s0nnet 4 | */ 5 | 6 | 7 | /*选择下拉框*/ 8 | $(function(){ 9 | $(".select").each(function(){ 10 | var s = $(this); 11 | var z = parseInt(s.css("z-index")); 12 | var dt = $(this).children("dt"); 13 | var dd = $(this).children("dd"); 14 | var _show = function(){ 15 | dd.slideDown(200); 16 | dt.addClass("cur"); 17 | s.css("z-index",z+1); 18 | }; 19 | var _hide = function(){ 20 | dd.slideUp(200); 21 | dt.removeClass("cur"); 22 | s.css("z-index",z); 23 | }; 24 | 25 | dt.click(function(){ 26 | dd.is(":hidden")?_show():_hide(); 27 | }); 28 | 29 | dd.find("a").click(function(){ 30 | dt.html($(this).html()); 31 | _hide(); 32 | }); 33 | 34 | $("body").click(function(i){ 35 | !$(i.target).parents(".select").first().is(s) ? _hide():""; 36 | }); 37 | }); 38 | }); 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/web/static/js/popwin.js: -------------------------------------------------------------------------------- 1 | // 通用的弹层插件 2 | //Power By 小新不坏 3 | //QQ:34542928 4 | //Blog:http://www.idboke.com 5 | var popWin = { 6 | scrolling: 'no', 7 | //是否显示滚动条 no,yes,auto 8 | 9 | int: function() { 10 | this.mouseClose(); 11 | this.closeMask(); 12 | //this.mouseDown(); 13 | 14 | }, 15 | 16 | showWin: function(width, height, title, src, params) { 17 | var iframeHeight = height - 52; 18 | var marginLeft = width / 2; 19 | var marginTop = height / 2; 20 | var src = src+"?"+params; 21 | var inntHtml = ''; 22 | inntHtml += '
' 23 | inntHtml += '
' 24 | inntHtml += '
' 25 | inntHtml += '' + title + '' 26 | inntHtml += '
' 27 | inntHtml += '
' 28 | inntHtml += ''; 29 | 30 | $("body").append(inntHtml); 31 | this.int(); 32 | 33 | 34 | }, 35 | 36 | mouseClose: function() { 37 | $("#popWinClose").on('mouseenter', 38 | function() { 39 | $(this).css("background-image", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJwSURBVEhLvZbLSiNBFIb7DVyKiIgb17oQRRAXgor6CIIIeQKXMksfxYUbFbMZRh0Yb6ODMgEddCVmoWkRLzFekukxfay/+lRbqSqTVob+4CyqzuVPV59TaS8JYRhmhM0Ly5MB9tiX4fDPIQq0CpsT9sC1G4JYzmnlMskQCRPCrrnOh0EuanC5+ojAL5wXc5/LUW5qitba2ynreTWGPfgQY4JaXNaNKfZ0dkY7g4OWyHuGWOTovCuKI+AYib+8TF+bmpyF6xlykKuD2iwTITbQIPE7Q4Kr2EdMF0VtaLCcFJxjnzySzzyZaaihHy80WE4Kxq3vemcns7PStzsyYvn+zMxQUCzSRne35UMtBTSUWIb3ZKeZSRCrBoH0lwsF2u7vj32/JyepWi5L3/3hIW319dXkwvTuhRYE53kt29tMMAlub2lvdJRy09MUVqu8G3GxsGDlo6YCWhCMryvXnO0OD1PF9zkiQj5VGPIqonhwQOsdHVY+aiqgVfMIZrCy7YEBCm5uOMqmdHTkFFOmk0gQ9nNoiF4eHznyjed8nr41NztzlOkkFsQ7cwmWz89ps6fHmaNMJ5Gg7MZKhaNs/pVK8thduTCdhk2DOVNjoXg6PaW/V1e8ikBj7Y2NWflW06BVee0cC/x6nYfjY/nOfnR1yRHRucxmrXzXWNQdfNwgGGpwt79Pa21tsQ+XAC4D4K+s0GpLS00uzBp8vm3qXm1bvb1UWFyk752dlu/X+Dj5S0vOTnVebUAsUr+80/17AmIjvT9ghXCk94mhMEUBOg3t7ZpT7MGnd6OioZgCRyAsnc9EhUhI70PYRBT4T5/6nvcKYG1hElXAZggAAAAASUVORK5CYII=)"); 40 | 41 | }); 42 | 43 | $("#popWinClose").on('mouseleave', 44 | function() { 45 | $(this).css("background-image", "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJeSURBVEhLvZbPq2lRFMf9B4bSTTIxZiBSMlCI9ycoKX+Bod7w/il3YIL4NyhFmYmBKD2Sp0ix3vqes/e529n74t33Op9astevr3PO2tvxvcLtdquzfbAtyAV8IlYX6d+DG7yxvbP9Fr2fglxR8ybavAYX/GD7Jfr8NahFD9HuMZz4U9Q5jEYjqlarFA6HiVPuDD7EkOMGvTjna9xi8/mcstmsJvKVIRc1Kl+K4haIHItut0t+v9/Y+JGhBrUq6M2xT9iBAXGeGQrY/U+miqI3NNhvw4t3EbNuyXeuzG3ood5eaLDfhhfO6JueWbPZtGKFQkGLNRoN2u/3FI/HtRh6SaDBPkusLnzWpMlkaRC7XC5WfLVaUTqddmKVSoVOp5MVG4/HlEql7mph6vRCC4IfYm2Nt7vAzW63o2KxSLVaja7Xq/DatFotrR49JdCCoHNcmfZZPp+n9XotMmxwVVwnVjbD4ZAikYhWj54SaN1dgjtZWiaToe12K7J0JpOJUUyaykuCsFwuR8fjUWR+slgsKBAIGGukqbwsiGdmElwul5RIJIw10lReEsQ0ns9nkaVzOBys226qhak8HRrsM7ktJLPZjDabjVjZYLBKpZJWrw0NfzzcFvj1KtPp1HpmsVjM2iIq/X5fqzdti4cbHycINjUYDAYUCoWcGA4BHAag1+tRMBi8q4VpGx/wl4dHWzKZpHa7TdFoVIuVy2XqdDrGSTUebYAXnh/e3v49AXZ49wcs4YB3rxgStyjApGG8TfsUPsTUaZQ8FZPgFrB585oo4QLvXoTdcIP/9Krv8/0BDUSOirKWU6wAAAAASUVORK5CYII=)"); 46 | 47 | }); 48 | 49 | }, 50 | 51 | closeMask: function() { 52 | $("#popWinClose").on('click', 53 | function() { 54 | $("#mask,#maskTop").fadeOut(function() { 55 | $(this).remove(); 56 | 57 | }); 58 | 59 | }); 60 | 61 | } 62 | 63 | /*mouseDown : function(){ 64 | var dragging = false; 65 | var iX, iY; 66 | //var elmen = $("div#maskTop"); 67 | $("#maskTop").on('mousedown' , function(e){ 68 | dragging = true; 69 | iX = e.clientX - this.offsetLeft; 70 | iY = e.clientY - this.offsetTop; 71 | this.setCapture && this.setCapture(); 72 | return false; 73 | }); 74 | document.onmousemove = function(e) { 75 | if (dragging) { 76 | var e = e || window.event; 77 | var oX = e.clientX - iX; 78 | var oY = e.clientY - iY; 79 | $("#maskTop").css({"left":oX + "px", "top":oY + "px"}); 80 | return false; 81 | } 82 | }; 83 | $(document).mouseup(function(e) { 84 | dragging = false; 85 | $("#maskTop")[0].releaseCapture(); 86 | e.cancelBubble = true; 87 | }) 88 | },*/ 89 | 90 | }; 91 | -------------------------------------------------------------------------------- /src/web/static/js/select.js: -------------------------------------------------------------------------------- 1 | var selects = document.getElementsByTagName('select'); 2 | var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false; 3 | function $(id) { 4 | return document.getElementById(id); 5 | } 6 | function stopBubbling (ev) { 7 | ev.stopPropagation(); 8 | } 9 | function rSelects() { 10 | for (i=0;i0){ 32 | if (childNode.parentNode.offsetWidth>0){ 33 | childNode.style.left= childNode.parentNode.offsetWidth+'px'; 34 | 35 | }else{ 36 | childNode.style.left='100px'; 37 | }; 38 | 39 | childNode.style.top = '-2px'; 40 | }; 41 | 42 | childNode.style.display ='none'; 43 | MenuHides[depth]=childNode; 44 | 45 | }; 46 | this.closediv = function(obj){ 47 | if (typeof(obj)=="object"){ 48 | if (obj.style.display!='none'){ 49 | obj.style.display='none'; 50 | } 51 | } 52 | } 53 | this.Hide = function(depth){ 54 | var i=0; 55 | if (depth>0){ 56 | i = depth 57 | }; 58 | while(MenuHides[i]!=null && MenuHides[i]!=''){ 59 | this.closediv(MenuHides[i]); 60 | MenuHides[i]=''; 61 | i++; 62 | }; 63 | 64 | }; 65 | this.Clear = function(){ 66 | for(var i=0;i 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/web/templates/custom_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 37 | 60 | 61 |
62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 |
72 |
73 | 74 | 90 | 91 |
92 | 93 | 94 |
95 |
96 |

客户列表

97 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 116 | 117 | 118 | 119 | 120 |
客户号姓名配送地址电话客户类型客户等级客户状态备注添加时间执行相关操作
121 |

共找到0条记录

122 |
123 |
124 | 125 | 126 | 138 | 139 |
140 | 141 | 142 | 143 |
144 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
145 |
146 | 147 | 148 |
149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /src/web/templates/custom_search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | > 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 37 | 60 | 61 |
62 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 |
72 |
73 | 74 | 90 | 91 |
92 | 93 | 94 |
95 | 96 | 97 |
98 | 99 |
100 | 客户状态: 101 |
102 |
全部
103 |
108 |
109 | 110 | 111 | 112 |
113 | 模糊查找: 114 | 115 |
116 | 117 |
118 |
119 | 120 | 121 | 122 |
123 |
124 |

找到匹配客户数据:

125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |
客户号姓名配送地址电话客户类型客户等级客户状态备注添加时间操作
140 |

共找到0条记录

141 |
142 |
143 | 144 |
145 | 146 | 147 | 148 |
149 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
150 |
151 | 152 | 153 |
154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/web/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 35 | 58 | 59 |
60 | 61 | 62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 88 | 89 |
90 | 91 | 92 | 93 |
94 |
95 |
96 | 101 | 102 | 103 | 104 |

客户数据统计

105 | 106 |

历史客户数: ?

107 |

正常客户数: ?

108 |

已删除客户数: ?

109 |
110 |
111 |

订单数据统计

112 |

历史订单数: ?

113 |

正常订单数: ?

114 |

已取消订单数: ?

115 |

今日订单数: ?

116 |

今日取消数: ?

117 |
118 |
119 |

到期订单提醒

120 |

3天内到期:共?

121 |

7天内到期:共?

122 |
123 |

注意:以上数据统计截止今日(?-?),如有未更新数据请及时更新。

124 |
125 |
126 | 127 | 128 | 129 |
130 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
131 |
132 | 133 | 134 |
135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /src/web/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 后台登录 9 | 10 | 11 | 12 | 13 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/web/templates/order_add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/web/templates/order_all.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | > 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 35 | 58 | 59 |
60 | 61 | 62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 88 | 89 |
90 | 91 | 92 |
93 |
94 |

订单列表

95 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 119 | 120 |
订单号客户号客户名奶类起订时间送奶开始送奶结束价格实收状态备注添加时间执行操作
121 |

共找到0条记录

122 |
123 |
124 | 125 | 126 | 138 | 139 |
140 | 141 | 142 | 143 |
144 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
145 |
146 | 147 | 148 |
149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /src/web/templates/order_cancel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 34 | 57 | 58 |
59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 | 67 | 68 |
69 |
70 | 71 | 87 | 88 |
89 | 90 | 91 |
92 |
93 |

今日暂取消订单

94 |
95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 113 |
编号姓名地址电话客户类型客户等级客户状态备注添加时间操作
114 |

共找到0条记录

115 |
116 |
117 | 118 | 119 | 131 | 132 |
133 | 134 | 135 | 136 |
137 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
138 |
139 | 140 | 141 |
142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /src/web/templates/order_edit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/web/templates/order_search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 37 | 59 | 60 |
61 | 62 | 63 | 64 |
65 | 66 | 67 | 68 | 69 | 70 |
71 |
72 | 73 | 89 | 90 |
91 | 92 | 93 | 94 |
95 | 96 | 97 |
98 | 99 | 100 |
101 | 订单状态: 102 |
103 |
全部
104 |
109 |
110 | 111 | 112 | 113 |
114 | 模糊查找: 115 | 116 |
117 | 118 |
119 |
120 | 121 | 122 | 123 |
124 |
125 |

找到匹配客户数据:

126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 |
订单号客户号客户名奶类起订时间送奶开始送奶结束价格实收状态备注添加时间执行操作
143 |

共找到0条记录

144 |
145 |
146 | 147 |
148 | 149 | 150 | 151 |
152 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
153 |
154 | 155 | 156 |
157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /src/web/templates/order_today.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 34 | 57 | 58 |
59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 | 67 | 68 |
69 |
70 | 71 | 87 | 88 |
89 | 90 | 91 |
92 |
93 |

今日订单列表 94 | 101 |
102 |

103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 124 | 125 |
订单号客户号客户姓名配送地址联系电话奶类型客户类型订单状态备注操作
126 |

共找到0条记录

127 |
128 |
129 | 130 | 131 | 143 | 144 |
145 | 146 | 147 | 148 |
149 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
150 |
151 | 152 | 153 |
154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/web/templates/user_add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 35 | 58 | 59 |
60 | 61 | 62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 88 | 89 |
90 | 91 | 92 |
93 |
94 |

添加系统用户

95 | 145 |
146 | 147 | 148 | 149 | 150 |
151 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
152 |
153 | 154 |
155 | 156 |
157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /src/web/templates/user_edit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/web/templates/user_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 35 | 58 | 59 |
60 | 61 | 62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 88 | 89 |
90 | 91 | 92 |
93 |
94 |

系统用户列表

95 |
96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 114 | 115 |
用户编号姓名用户名密码手机号联系邮箱用户等级上次登录操作
116 |
117 |
118 | 119 |
120 | 121 | 122 | 123 |
124 |
瑞昌市黄甲山鲜羊奶有限公司 Copyright © 2017
邮箱:s0nnet@qq.com 技术支持:黄甲山鲜羊奶技术部
125 |
126 | 127 | 128 |
129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/web/url.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | 3 | # author: s0nnet 4 | # time: 2016-11-28 5 | # desc: urls 6 | 7 | from viewset.view_login import * 8 | from viewset.view_index import * 9 | from viewset.view_custom import * 10 | from viewset.view_order import * 11 | from viewset.view_user import * 12 | 13 | urls = ( 14 | "/", ViewIndex, 15 | "/index", ViewIndex, 16 | "/index.html", ViewIndex, 17 | "/custom_list.html", ViewCustomList, 18 | "/custom_search.html", ViewCustomSearch, 19 | "/custom_add.html", ViewCustomAdd, 20 | "/custom_edit.html", ViewCustomEdit, 21 | "/order_all.html", ViewOrderAll, 22 | "/order_today.html", ViewOrderToday, 23 | "/order_cancel.html", ViewOrderCancel, 24 | "/order_add.html", ViewOrderAdd, 25 | "/order_edit.html", ViewOrderEdit, 26 | "/order_search.html", ViewOrderSearch, 27 | "/user_list.html", ViewUserList, 28 | "/user_add.html", ViewUserAdd, 29 | "/user_edit.html", ViewUserEdit, 30 | "/login", ViewLogin, 31 | "/logout", ViewLogout, 32 | "/api/data/count", ViewApiDataCount, 33 | "/api/custom/list", ViewApiCustomList, 34 | "/api/custom/add", ViewApiCustomAdd, 35 | "/api/custom/info", ViewApiCustomInfo, 36 | "/api/custom/update", ViewApiCustomUpdate, 37 | "/api/custom/del", ViewApiCustomDel, 38 | "/api/order/list", ViewApiOrderList, 39 | "/api/order/today", ViewApiOrderToday, 40 | "/api/order/add", ViewApiOrderAdd, 41 | "/api/order/del", ViewApiOrderDel, 42 | "/api/order/info", ViewApiOrderInfo, 43 | "/api/order/update", ViewApiOrderUpdate, 44 | "/api/order/pause_list", ViewApiOrderPauseList, 45 | "/api/order/pause_add", ViewApiOrderPauseAdd, 46 | "/api/order/pause_del", ViewApiOrderPauseDel, 47 | "/api/user/list", ViewApiUserList, 48 | "/api/user/add", ViewApiUserAdd, 49 | "/api/user/info", ViewApiUserInfo, 50 | "/api/user/update", ViewApiUserUpdate, 51 | "/api/user/del", ViewApiUserDel, 52 | ) 53 | -------------------------------------------------------------------------------- /src/web/viewset/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lingerhk/hjs_cms/4baccb6b05350b51e20fec183834b56110ebc648/src/web/viewset/__init__.py -------------------------------------------------------------------------------- /src/web/viewset/view_index.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: index view 6 | 7 | from view_base import * 8 | from hjs_user import * 9 | from hjs_index import * 10 | 11 | 12 | class ViewIndex(ViewBase): 13 | def GET(self): 14 | bRet, sRet = self.check_login() 15 | if not bRet: 16 | Log.err("user not login!") 17 | return web.seeother("/login") 18 | 19 | return render.index() 20 | 21 | def POST(self): 22 | return self.GET() 23 | 24 | 25 | class ViewApiDataCount(ViewBase): 26 | def _deal_data_show(self): 27 | return HjsIndex.data_show(self.get_user_name()) 28 | 29 | 30 | def GET(self): 31 | if not self.check_login(): 32 | return self.make_error("user not login") 33 | 34 | bRet, sRet = self.process(self._deal_data_show) 35 | if not bRet: 36 | Log.err("deal_user_list: %s" % (str(sRet))) 37 | return self.make_error(sRet) 38 | 39 | return self.make_response(sRet) 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/web/viewset/view_login.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: login view 6 | 7 | 8 | import web 9 | from view_base import * 10 | from hjs_user_dao import * 11 | 12 | class ViewLogin(ViewBase): 13 | def __init__(self): 14 | self._rDict = { 15 | "username": {'n': 'userName', 't': str, 'v': None}, 16 | "password": {'n': 'passWord', 't': str, 'v': None} 17 | } 18 | 19 | def _check_param(self): 20 | 21 | if not self.userName: return False, "param(username) is None!" 22 | if not self.passWord: return False, "param(password) is NOne!" 23 | 24 | return True, None 25 | 26 | def GET(self): 27 | return render.login() 28 | 29 | def _deal_login(self): 30 | 31 | bRet, sRet = HjsUserDao.query_node_by_username(self.userName) 32 | if not bRet: return False, "username does not exist!" 33 | 34 | if sRet['password'] != self.passWord: 35 | #if record['passwd'] != comput_md5_text(salt + self.passWord): 36 | return False, u"用户名或密码错误" 37 | 38 | Session.set_val("username", self.userName) 39 | web.setcookie("username", self.userName) 40 | HjsUserDao.update_lastlogin(sRet['uid']) 41 | 42 | return True, None 43 | 44 | def POST(self): 45 | 46 | bRet, sRet = self.process(self._deal_login) 47 | if not bRet: 48 | Log.err("deal_login: %s" % (str(sRet))) 49 | return self.make_error(sRet) 50 | 51 | return render.index() 52 | 53 | 54 | class ViewLogout(ViewBase): 55 | def GET(self): 56 | Session.set_val("username", None) 57 | web.setcookie("username", None) 58 | return web.seeother("/login") 59 | 60 | def POST(self): 61 | return self.GET() 62 | 63 | 64 | if __name__ == "__main__": 65 | 66 | def test_login(): 67 | Session.session = {} 68 | viewLogin = ViewLogin() 69 | viewLogin.userName = 'test' 70 | viewLogin.password = 'test' 71 | bRet, sRet = viewLogin._deal_login() 72 | if not bRet: 73 | Log.err("test_case ERR! %s" % (str(sRet))) 74 | else: 75 | Log.info("test_case SUCCESS!") 76 | 77 | test_login() 78 | -------------------------------------------------------------------------------- /src/web/viewset/view_user.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: user view 6 | 7 | 8 | from view_base import * 9 | from hjs_user import * 10 | 11 | 12 | class ViewUserList(ViewBase): 13 | def GET(self): 14 | if not self.check_login(): 15 | Log.err("user not login") 16 | return web.seeother("/login") 17 | 18 | return render.user_list() 19 | 20 | 21 | class ViewUserAdd(ViewBase): 22 | def GET(self): 23 | if not self.check_login(): 24 | Log.err("user not login") 25 | return web.seeother("/login") 26 | 27 | return render.user_add() 28 | 29 | 30 | class ViewUserEdit(ViewBase): 31 | def GET(self): 32 | if not self.check_login(): 33 | Log.err("user not login!") 34 | return web.seeother("/login") 35 | 36 | return render.user_edit() 37 | 38 | 39 | 40 | class ViewApiUserList(ViewBase): 41 | def _deal_user_list(self): 42 | bRet, is_admin = HjsUser.is_admin(self.get_user_name()) 43 | if not bRet: 44 | return False, sRet 45 | if not is_admin: 46 | return False, 'No permission do user list' 47 | 48 | return HjsUser.user_list(self.get_user_name()) 49 | 50 | def GET(self): 51 | if not self.check_login(): 52 | return self.make_error("user not login") 53 | 54 | bRet, sRet = self.process(self._deal_user_list) 55 | if not bRet: 56 | Log.err("deal_user_list: %s" % (str(sRet))) 57 | return self.make_error(sRet) 58 | 59 | return self.make_response(sRet) 60 | 61 | 62 | class ViewApiUserAdd(ViewBase): 63 | def __init__(self): 64 | self._rDict = { 65 | "nickname": {'n': 'nickName', 't': str, 'v': None}, 66 | "username": {'n': 'userName', 't': str, 'v': None}, 67 | "password": {'n': 'passWord', 't': str, 'v': None}, 68 | "phone": {'n': 'Phone', 't': str, 'v': None}, 69 | "email": {'n': 'Email', 't': str, 'v': ''}, 70 | "priv": {'n': 'Priv', 't': int, 'v': 1} 71 | } 72 | 73 | def _check_param(self): 74 | bRet, sRet = super(ViewApiUserAdd, self)._check_param() 75 | if not bRet: 76 | return bRet, sRet 77 | 78 | return True, None 79 | 80 | def _deal_user_add(self): 81 | bRet, is_admin = HjsUser.is_admin(self.get_user_name()) 82 | if not bRet: 83 | return False, sRet 84 | if not is_admin: 85 | return False, 'No permission do user add' 86 | 87 | return HjsUser.user_add(self.nickName, self.userName, self.passWord, self.Phone, self.Email, self.Priv) 88 | 89 | def POST(self): 90 | if not self.check_login(): 91 | return self.make_error("user not login") 92 | 93 | bRet, sRet = self.process(self._deal_user_add) 94 | if not bRet: 95 | Log.err("add user error: %s" % (str(sRet))) 96 | return self.make_error(sRet) 97 | 98 | return self.make_response(ViewBase.RetMsg.MSG_SUCCESS) 99 | 100 | 101 | class ViewApiUserInfo(ViewBase): 102 | def __init__(self): 103 | self._rDict = { 104 | "uid": {'n': 'uId', 't': int, 'v': None} 105 | } 106 | 107 | def _check_param(self): 108 | bRet, sRet = super(ViewApiUserInfo, self)._check_param() 109 | if not bRet: 110 | return False, sRet 111 | 112 | return True, None 113 | 114 | def _deal_user_info(self): 115 | bRet, is_admin = HjsUser.is_admin(self.get_user_name()) 116 | if not bRet: 117 | return False, sRet 118 | if not is_admin: 119 | return False, 'No permission do user info' 120 | bRet, user_id = HjsUser.get_user_uid(self.get_user_name()) 121 | if not bRet: 122 | return False, user_id 123 | 124 | return HjsUser.user_info(self.uId) 125 | 126 | def GET(self): 127 | if not self.check_login(): 128 | return self.make_error("user not login") 129 | 130 | bRet, sRet = self.process(self._deal_user_info) 131 | if not bRet: 132 | Log.err("deal_user_info: %s" % (str(sRet))) 133 | return self.make_error(sRet) 134 | 135 | return self.make_response(sRet) 136 | 137 | 138 | class ViewApiUserUpdate(ViewBase): 139 | def __init__(self): 140 | self._rDict = { 141 | "uid": {'n': 'uId', 't': int, 'v': None}, 142 | "nickname": {'n': 'nickName', 't': str, 'v': None}, 143 | "username": {'n': 'userName', 't': str, 'v': None}, 144 | "password": {'n': 'passWord', 't': str, 'v': None}, 145 | "phone": {'n': 'Phone', 't': str, 'v': None}, 146 | "email": {'n': 'Email', 't': str, 'v': ''}, 147 | "priv": {'n': 'Priv', 't': str, 'v':None} 148 | } 149 | 150 | def _check_param(self): 151 | bRet, sRet = super(ViewApiUserUpdate, self)._check_param() 152 | if not bRet: 153 | return bRet, sRet 154 | 155 | return True, None 156 | 157 | def _deal_user_update(self): 158 | bRet, is_admin = HjsUser.is_admin(self.get_user_name()) 159 | if not bRet: 160 | return False, sRet 161 | if not is_admin: 162 | return False, 'No permission do user update' 163 | 164 | return HjsUser.user_update(self.uId, self.nickName, self.userName, self.passWord, self.Phone, self.Email, self.Priv) 165 | 166 | def POST(self): 167 | if not self.check_login(): 168 | return self.make_error("user not login") 169 | 170 | bRet, sRet = self.process(self._deal_user_update) 171 | if not bRet: 172 | Log.err("update user error: %s" % (str(sRet))) 173 | return self.make_error(sRet) 174 | 175 | return self.make_response(ViewBase.RetMsg.MSG_SUCCESS) 176 | 177 | 178 | class ViewApiUserDel(ViewBase): 179 | def __init__(self): 180 | self._rDict = { 181 | "uid": {'n': 'uId', 't': int, 'v': None} 182 | } 183 | 184 | def _check_param(self): 185 | bRet, sRet = super(ViewApiUserDel, self)._check_param() 186 | if not bRet: 187 | return bRet, sRet 188 | 189 | return True, None 190 | 191 | def _deal_user_del(self): 192 | bRet, is_admin = HjsUser.is_admin(self.get_user_name()) 193 | if not bRet: 194 | return False, sRet 195 | if not is_admin: 196 | return False, 'No permission do user del' 197 | bRet, user_id = HjsUser.get_user_uid(self.get_user_name()) 198 | if not bRet: 199 | return False, user_id 200 | if user_id == self.uId: 201 | return False, 'do not allow delete yourself' 202 | 203 | return HjsUser.user_del(self.uId) 204 | 205 | def POST(self): 206 | if not self.check_login(): 207 | return self.make_error("user not login") 208 | 209 | bRet, sRet = self.process(self._deal_user_del) 210 | if not bRet: 211 | Log.err("deal_user_del: %s" % (str(sRet))) 212 | return self.make_error(sRet) 213 | 214 | return self.make_response(ViewBase.RetMsg.MSG_SUCCESS) 215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /src/web/viewset/web_util.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: web.py 框架相关方法封装 6 | 7 | 8 | if __name__ == "__main__": 9 | import sys 10 | sys.path.append("../base") 11 | 12 | import web 13 | from bs_log import * 14 | from bs_util import * 15 | 16 | 17 | # webpy 框架环境有关的方法 18 | def get_req_all_param(): 19 | params = web.input() 20 | 21 | retParams = {} 22 | for node in params.items(): 23 | if type(node[1]) == unicode: 24 | retParams[node[0]] = node[1].encode('utf-8') 25 | else: 26 | retParams[node[0]] = node[1] 27 | 28 | return retParams 29 | 30 | 31 | def get_req_path_info(): 32 | return web.ctx.env['PATH_INFO'] 33 | 34 | 35 | def get_req_method(): 36 | return web.ctx.env['REQUEST_METHOD'] 37 | 38 | 39 | def is_get_method(): 40 | if get_req_method() == 'GET': return True 41 | return False 42 | 43 | 44 | def get_client_ip(): 45 | if web.ctx.env.has_key('HTTP_X_FORWARDED_FOR'): 46 | return web.ctx.env['HTTP_X_FORWARDED_FOR'] 47 | else: 48 | return web.ctx.env['REMOTE_ADDR'] 49 | 50 | 51 | def set_cookie(key, value): 52 | web.setcookie(key, value, 3600 + 24 * 3600) 53 | 54 | 55 | def get_cookie(key): 56 | try: 57 | cookies = web.cookies() 58 | return cookies.get(key) 59 | except: 60 | return None 61 | 62 | 63 | def get_req_qstr(key, defaultVal=None, ttype=str): 64 | if is_get_method(): 65 | val = web.input().get(key, defaultVal) 66 | else: 67 | val = getattr(web.input(), key, defaultVal) 68 | 69 | if type(val) == unicode: 70 | val = val.encode('utf-8') 71 | 72 | # Log.debug("key = %s, val = %s, default = %s, dtype = %s" % (key, val, defaultVal, ttype)) 73 | 74 | if val == None or val == "": 75 | return defaultVal 76 | if ttype == int: 77 | return int(val) 78 | if ttype == str: 79 | return val 80 | 81 | return defaultVal 82 | 83 | 84 | def get_result_json(bret, val): 85 | if val == None: 86 | if bret == True: 87 | val = "SUCCESS!" 88 | else: 89 | val = "ERROR!" 90 | 91 | retDict = { 92 | 'return_code': int(bret), 93 | 'return_str': str(val) 94 | } 95 | web.header('Content-Type', 'application/json') 96 | return json.dumps(retDict) 97 | 98 | 99 | def decode_all(sMsg): 100 | def decode(source, encoding): 101 | try: 102 | return source.decode(encoding) 103 | except: 104 | return None 105 | 106 | dMsg = decode(sMsg, 'GB') 107 | if dMsg: return dMsg 108 | 109 | dMsg = decode(sMsg, 'UTF8') 110 | if dMsg: return dMsg 111 | 112 | return sMsg 113 | 114 | 115 | def get_web_ip_port(): 116 | cmd = "ps aux | grep python | grep ms_web_main.py | awk '{print $13}'" 117 | 118 | bRet, sRet = exec_cmd(cmd) 119 | if bRet == 0 and sRet != "": 120 | sRet = sRet.split("\n")[0] 121 | return True, sRet 122 | 123 | # ip = get_local_ip() 124 | # if ip != None: 125 | # return True, ip 126 | 127 | return False, None 128 | 129 | 130 | if __name__ == "__main__": 131 | print get_web_ip_port() 132 | -------------------------------------------------------------------------------- /src/web/web_main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # author: s0nnet 4 | # time: 2016-11-08 5 | # desc: web.py 入口主函数 6 | 7 | 8 | import os 9 | path = os.path.dirname(os.path.realpath(__file__)) 10 | os.chdir(path) 11 | 12 | import sys 13 | sys.path.append("../base") 14 | sys.path.append("../dao") 15 | sys.path.append("../bean") 16 | sys.path.append("..") 17 | sys.path.append(".") 18 | 19 | reload(sys) 20 | sys.setdefaultencoding("utf-8") 21 | 22 | os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs' 23 | 24 | import web 25 | from viewset.view_base import * 26 | from url import urls 27 | 28 | 29 | # 权限校验 30 | def user_check(handler): 31 | return handler() 32 | 33 | 34 | # 启动 35 | app = web.application(urls, globals()) 36 | app.add_processor(user_check) 37 | Session.init(app) 38 | 39 | if __name__ == "__main__": 40 | try: 41 | Log.info("ms_web work start!") 42 | app.run() 43 | Log.info("ms_web work end!") 44 | 45 | except Exception, e: 46 | Log.err("ms_web work err(%s)" % (str(e))) 47 | 48 | else: 49 | application = app.wsgifunc() 50 | --------------------------------------------------------------------------------