After Width: | Height: | Size: 169 KiB |
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||
<component name="PyCharmProfessionalAdvertiser">
|
||||
<option name="shown" value="true" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
# # This is a sample Python script.
|
||||
#
|
||||
# # Press Shift+F10 to execute it or replace it with your code.
|
||||
# # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
||||
#
|
||||
#
|
||||
# def print_hi(name):
|
||||
# # Use a breakpoint in the code line below to debug your script.
|
||||
# print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
||||
#
|
||||
#
|
||||
# # Press the green button in the gutter to run the script.
|
||||
# if __name__ == '__main__':
|
||||
# print_hi('PyCharm')
|
||||
#
|
||||
# # See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
||||
import os
|
||||
|
||||
# 假设你已经在 Django 项目的根目录下
|
||||
project_path = os.getcwd()
|
||||
print("Django project is located at:", project_path)
|
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||
<component name="PyCharmProfessionalAdvertiser">
|
||||
<option name="shown" value="true" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/python_team-master-e0adedf9baf6df4ac89d732b46bcecb3187bf0f3.iml" filepath="$PROJECT_DIR$/.idea/python_team-master-e0adedf9baf6df4ac89d732b46bcecb3187bf0f3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,14 @@
|
||||
/server/myapp/migrations
|
||||
/server/myapp/views/__pycache__/
|
||||
/server/.idea
|
||||
/web/.idea
|
||||
/web/dist
|
||||
/web/node_modules
|
||||
/server/.idea/
|
||||
/.idea/
|
||||
__pycache__
|
||||
.idea
|
||||
server/.idea
|
||||
.DS_Store
|
||||
server/.DS_Store
|
||||
web/.DS_Store
|
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,558 @@
|
||||
/*
|
||||
SQLyog Community v13.1.6 (64 bit)
|
||||
MySQL - 8.0.26 : Database - python_team
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
|
||||
/*!40101 SET SQL_MODE=''*/;
|
||||
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
CREATE DATABASE /*!32312 IF NOT EXISTS*/`python_team` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
|
||||
|
||||
USE `python_team`;
|
||||
|
||||
/*Table structure for table `auth_group` */
|
||||
|
||||
DROP TABLE IF EXISTS `auth_group`;
|
||||
|
||||
CREATE TABLE `auth_group` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `name` (`name`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `auth_group` */
|
||||
|
||||
/*Table structure for table `auth_group_permissions` */
|
||||
|
||||
DROP TABLE IF EXISTS `auth_group_permissions`;
|
||||
|
||||
CREATE TABLE `auth_group_permissions` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`group_id` int NOT NULL,
|
||||
`permission_id` int NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `auth_group_permissions_group_id_permission_id_0cd325b0_uniq` (`group_id`,`permission_id`) USING BTREE,
|
||||
KEY `auth_group_permissio_permission_id_84c5c92e_fk_auth_perm` (`permission_id`) USING BTREE,
|
||||
CONSTRAINT `auth_group_permissio_permission_id_84c5c92e_fk_auth_perm` FOREIGN KEY (`permission_id`) REFERENCES `auth_permission` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `auth_group_permissions_group_id_b120cbf9_fk_auth_group_id` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `auth_group_permissions` */
|
||||
|
||||
/*Table structure for table `auth_permission` */
|
||||
|
||||
DROP TABLE IF EXISTS `auth_permission`;
|
||||
|
||||
CREATE TABLE `auth_permission` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`content_type_id` int NOT NULL,
|
||||
`codename` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `auth_permission_content_type_id_codename_01ab375a_uniq` (`content_type_id`,`codename`) USING BTREE,
|
||||
CONSTRAINT `auth_permission_content_type_id_2f476e4b_fk_django_co` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=85 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `auth_permission` */
|
||||
|
||||
insert into `auth_permission`(`id`,`name`,`content_type_id`,`codename`) values (1,'Can add log entry',1,'add_logentry'),(2,'Can change log entry',1,'change_logentry'),(3,'Can delete log entry',1,'delete_logentry'),(4,'Can view log entry',1,'view_logentry'),(5,'Can add permission',2,'add_permission'),(6,'Can change permission',2,'change_permission'),(7,'Can delete permission',2,'delete_permission'),(8,'Can view permission',2,'view_permission'),(9,'Can add group',3,'add_group'),(10,'Can change group',3,'change_group'),(11,'Can delete group',3,'delete_group'),(12,'Can view group',3,'view_group'),(13,'Can add user',4,'add_user'),(14,'Can change user',4,'change_user'),(15,'Can delete user',4,'delete_user'),(16,'Can view user',4,'view_user'),(17,'Can add content type',5,'add_contenttype'),(18,'Can change content type',5,'change_contenttype'),(19,'Can delete content type',5,'delete_contenttype'),(20,'Can view content type',5,'view_contenttype'),(21,'Can add session',6,'add_session'),(22,'Can change session',6,'change_session'),(23,'Can delete session',6,'delete_session'),(24,'Can view session',6,'view_session'),(25,'Can add ad',7,'add_ad'),(26,'Can change ad',7,'change_ad'),(27,'Can delete ad',7,'delete_ad'),(28,'Can view ad',7,'view_ad'),(29,'Can add classification',8,'add_classification'),(30,'Can change classification',8,'change_classification'),(31,'Can delete classification',8,'delete_classification'),(32,'Can view classification',8,'view_classification'),(33,'Can add error log',9,'add_errorlog'),(34,'Can change error log',9,'change_errorlog'),(35,'Can delete error log',9,'delete_errorlog'),(36,'Can view error log',9,'view_errorlog'),(37,'Can add login log',10,'add_loginlog'),(38,'Can change login log',10,'change_loginlog'),(39,'Can delete login log',10,'delete_loginlog'),(40,'Can view login log',10,'view_loginlog'),(41,'Can add notice',11,'add_notice'),(42,'Can change notice',11,'change_notice'),(43,'Can delete notice',11,'delete_notice'),(44,'Can view notice',11,'view_notice'),(45,'Can add op log',12,'add_oplog'),(46,'Can change op log',12,'change_oplog'),(47,'Can delete op log',12,'delete_oplog'),(48,'Can view op log',12,'view_oplog'),(49,'Can add tag',13,'add_tag'),(50,'Can change tag',13,'change_tag'),(51,'Can delete tag',13,'delete_tag'),(52,'Can view tag',13,'view_tag'),(53,'Can add user',14,'add_user'),(54,'Can change user',14,'change_user'),(55,'Can delete user',14,'delete_user'),(56,'Can view user',14,'view_user'),(57,'Can add thing',15,'add_thing'),(58,'Can change thing',15,'change_thing'),(59,'Can delete thing',15,'delete_thing'),(60,'Can view thing',15,'view_thing'),(61,'Can add record',16,'add_record'),(62,'Can change record',16,'change_record'),(63,'Can delete record',16,'delete_record'),(64,'Can view record',16,'view_record'),(65,'Can add order log',17,'add_orderlog'),(66,'Can change order log',17,'change_orderlog'),(67,'Can delete order log',17,'delete_orderlog'),(68,'Can view order log',17,'view_orderlog'),(69,'Can add order',18,'add_order'),(70,'Can change order',18,'change_order'),(71,'Can delete order',18,'delete_order'),(72,'Can view order',18,'view_order'),(73,'Can add comment',19,'add_comment'),(74,'Can change comment',19,'change_comment'),(75,'Can delete comment',19,'delete_comment'),(76,'Can view comment',19,'view_comment'),(77,'Can add banner',20,'add_banner'),(78,'Can change banner',20,'change_banner'),(79,'Can delete banner',20,'delete_banner'),(80,'Can view banner',20,'view_banner'),(81,'Can add address',21,'add_address'),(82,'Can change address',21,'change_address'),(83,'Can delete address',21,'delete_address'),(84,'Can view address',21,'view_address');
|
||||
|
||||
/*Table structure for table `auth_user` */
|
||||
|
||||
DROP TABLE IF EXISTS `auth_user`;
|
||||
|
||||
CREATE TABLE `auth_user` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`password` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`last_login` datetime(6) DEFAULT NULL,
|
||||
`is_superuser` tinyint(1) NOT NULL,
|
||||
`username` varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`first_name` varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`last_name` varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`email` varchar(254) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`is_staff` tinyint(1) NOT NULL,
|
||||
`is_active` tinyint(1) NOT NULL,
|
||||
`date_joined` datetime(6) NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `username` (`username`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `auth_user` */
|
||||
|
||||
/*Table structure for table `auth_user_groups` */
|
||||
|
||||
DROP TABLE IF EXISTS `auth_user_groups`;
|
||||
|
||||
CREATE TABLE `auth_user_groups` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int NOT NULL,
|
||||
`group_id` int NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `auth_user_groups_user_id_group_id_94350c0c_uniq` (`user_id`,`group_id`) USING BTREE,
|
||||
KEY `auth_user_groups_group_id_97559544_fk_auth_group_id` (`group_id`) USING BTREE,
|
||||
CONSTRAINT `auth_user_groups_group_id_97559544_fk_auth_group_id` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `auth_user_groups_user_id_6a12ed8b_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `auth_user_groups` */
|
||||
|
||||
/*Table structure for table `auth_user_user_permissions` */
|
||||
|
||||
DROP TABLE IF EXISTS `auth_user_user_permissions`;
|
||||
|
||||
CREATE TABLE `auth_user_user_permissions` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int NOT NULL,
|
||||
`permission_id` int NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `auth_user_user_permissions_user_id_permission_id_14a6b632_uniq` (`user_id`,`permission_id`) USING BTREE,
|
||||
KEY `auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm` (`permission_id`) USING BTREE,
|
||||
CONSTRAINT `auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm` FOREIGN KEY (`permission_id`) REFERENCES `auth_permission` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `auth_user_user_permissions` */
|
||||
|
||||
/*Table structure for table `b_ad` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_ad`;
|
||||
|
||||
CREATE TABLE `b_ad` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`image` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`link` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_ad` */
|
||||
|
||||
insert into `b_ad`(`id`,`image`,`link`,`create_time`) values (1,'','http://www.baidu.com111','2024-02-04 17:26:04.553627');
|
||||
|
||||
/*Table structure for table `b_address` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_address`;
|
||||
|
||||
CREATE TABLE `b_address` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`mobile` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`desc` varchar(300) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`default` tinyint(1) DEFAULT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_address_user_id_a37a8d6a_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_address_user_id_a37a8d6a_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_address` */
|
||||
|
||||
/*Table structure for table `b_banner` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_banner`;
|
||||
|
||||
CREATE TABLE `b_banner` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`image` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
`thing_id` bigint DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_banner_thing_id_3f307d00_fk_b_thing_id` (`thing_id`) USING BTREE,
|
||||
CONSTRAINT `b_banner_thing_id_3f307d00_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_banner` */
|
||||
|
||||
/*Table structure for table `b_classification` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_classification`;
|
||||
|
||||
CREATE TABLE `b_classification` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_classification` */
|
||||
|
||||
insert into `b_classification`(`id`,`title`,`create_time`) values (1,'体育类','2024-02-04 16:39:13.697593'),(2,'运动类','2024-02-04 16:39:19.397394'),(3,'文艺类','2024-02-04 16:39:24.633287'),(4,'电子类','2024-02-04 16:39:59.841608');
|
||||
|
||||
/*Table structure for table `b_comment` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_comment`;
|
||||
|
||||
CREATE TABLE `b_comment` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`content` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`comment_time` datetime(6) DEFAULT NULL,
|
||||
`like_count` int NOT NULL,
|
||||
`thing_id` bigint DEFAULT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_comment_thing_id_57ab492b_fk_b_thing_id` (`thing_id`) USING BTREE,
|
||||
KEY `b_comment_user_id_46f0670f_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_comment_thing_id_57ab492b_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_comment_user_id_46f0670f_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_comment` */
|
||||
|
||||
insert into `b_comment`(`id`,`content`,`comment_time`,`like_count`,`thing_id`,`user_id`) values (1,'dasdf','2024-02-04 16:58:15.144159',1,5,4),(2,'dfasdfff','2024-02-04 16:58:17.850901',1,5,4),(3,'的地方211','2024-02-04 17:00:55.346951',2,5,4);
|
||||
|
||||
/*Table structure for table `b_error_log` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_error_log`;
|
||||
|
||||
CREATE TABLE `b_error_log` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`ip` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`url` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`method` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`content` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`log_time` datetime(6) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_error_log` */
|
||||
|
||||
insert into `b_error_log`(`id`,`ip`,`url`,`method`,`content`,`log_time`) values (1,'127.0.0.1','/myapp/admin/thing/create','POST','参数错误','2024-11-03 20:52:41.976647');
|
||||
|
||||
/*Table structure for table `b_login_log` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_login_log`;
|
||||
|
||||
CREATE TABLE `b_login_log` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`ip` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`ua` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`log_time` datetime(6) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_login_log` */
|
||||
|
||||
insert into `b_login_log`(`id`,`username`,`ip`,`ua`,`log_time`) values (1,'admin','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36','2024-02-04 16:36:19.239685'),(2,'aaa','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36','2024-02-04 16:57:10.644691'),(3,'admin123','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36','2024-02-04 17:18:37.112379'),(4,'admin','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36','2024-02-04 17:25:59.480266'),(5,'aaa','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36','2024-02-04 17:27:08.481837'),(6,'admin123','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0','2024-11-02 20:09:29.757100'),(7,'admin123','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0','2024-11-02 20:10:30.697160'),(8,'3514164072@qq.com','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0','2024-11-02 20:14:42.177316'),(9,'admin123','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0','2024-11-02 20:15:54.069303'),(10,'3514164072@qq.com','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0','2024-11-03 12:28:06.329064'),(11,'admin123','127.0.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0','2024-11-03 22:22:29.256185');
|
||||
|
||||
/*Table structure for table `b_notice` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_notice`;
|
||||
|
||||
CREATE TABLE `b_notice` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`content` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
`name` varchar(200) DEFAULT NULL,
|
||||
`thing_id` int DEFAULT NULL,
|
||||
`thing_name` varchar(200) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_notice` */
|
||||
|
||||
insert into `b_notice`(`id`,`title`,`content`,`create_time`,`name`,`thing_id`,`thing_name`) values (1,'abcd','欢迎申请','2024-02-04 17:26:10.000000','admin123',NULL,'全部'),(2,'新建社团123','安德森对方','2024-02-04 17:26:20.948813','admin123',NULL,'全部'),(16,'1','1','2024-11-03 22:33:20.073649','3514164072@qq.com',NULL,'梦想之家街舞团'),(19,'1','1','2024-11-03 22:37:23.376651','admin123',NULL,'全部'),(20,'1','1','2024-11-03 22:38:01.204866','admin123',NULL,'全部'),(21,'1','1','2024-11-03 22:38:19.403888','3514164072@qq.com',NULL,'梦想之家街舞团'),(22,'1','111','2024-11-03 22:45:42.876051','3514164072@qq.com',NULL,'梦想之家街舞团');
|
||||
|
||||
/*Table structure for table `b_op_log` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_op_log`;
|
||||
|
||||
CREATE TABLE `b_op_log` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`re_ip` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`re_time` datetime(6) DEFAULT NULL,
|
||||
`re_url` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`re_method` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`re_content` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`access_time` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_op_log` */
|
||||
|
||||
insert into `b_op_log`(`id`,`re_ip`,`re_time`,`re_url`,`re_method`,`re_content`,`access_time`) values (1,'127.0.0.1','2024-02-04 17:25:16.003630','/myapp/admin/loginLog/list','GET',NULL,'25'),(2,'127.0.0.1','2024-02-04 17:25:16.125409','/myapp/admin/opLog/list','GET',NULL,'28'),(3,'127.0.0.1','2024-02-04 17:25:16.735706','/myapp/admin/errorLog/list','GET',NULL,'4'),(4,'127.0.0.1','2024-02-04 17:25:17.091962','/myapp/admin/opLog/list','GET',NULL,'28'),(5,'127.0.0.1','2024-02-04 17:25:17.996686','/myapp/admin/comment/list','GET',NULL,'24'),(6,'127.0.0.1','2024-02-04 17:25:18.508752','/myapp/admin/tag/list','GET',NULL,'28'),(7,'127.0.0.1','2024-02-04 17:25:18.995965','/myapp/admin/order/list','GET',NULL,'25'),(8,'127.0.0.1','2024-02-04 17:25:19.517164','/myapp/admin/classification/list','GET',NULL,'25'),(9,'127.0.0.1','2024-02-04 17:25:19.951784','/myapp/admin/order/list','GET',NULL,'8'),(10,'127.0.0.1','2024-02-04 17:25:20.517535','/myapp/admin/tag/list','GET',NULL,'17'),(11,'127.0.0.1','2024-02-04 17:25:20.899065','/myapp/admin/comment/list','GET',NULL,'7'),(12,'127.0.0.1','2024-02-04 17:25:21.391965','/myapp/admin/user/list','GET',NULL,'20'),(13,'127.0.0.1','2024-02-04 17:25:21.677749','/myapp/admin/comment/list','GET',NULL,'5'),(14,'127.0.0.1','2024-02-04 17:25:24.066175','/myapp/index/comment/list','GET',NULL,'3'),(15,'127.0.0.1','2024-02-04 17:25:24.083944','/myapp/index/comment/list','GET',NULL,'22'),(16,'127.0.0.1','2024-02-04 17:25:24.084992','/myapp/index/comment/list','GET',NULL,'23'),(17,'127.0.0.1','2024-02-04 17:25:24.090525','/myapp/index/comment/list','GET',NULL,'29'),(18,'127.0.0.1','2024-02-04 17:25:24.094806','/upload/cover/1707036810262.jpeg','GET',NULL,'1'),(19,'127.0.0.1','2024-02-04 17:25:24.109564','/upload/cover/1707036756214.jpeg','GET',NULL,'1'),(20,'127.0.0.1','2024-02-04 17:25:24.109564','/upload/cover/1707036858212.jpeg','GET',NULL,'0'),(21,'127.0.0.1','2024-02-04 17:25:24.109564','/upload/cover/1707036756214.jpeg','GET',NULL,'0'),(22,'127.0.0.1','2024-02-04 17:25:24.110577','/upload/cover/1707036638009.jpeg','GET',NULL,'1'),(23,'127.0.0.1','2024-02-04 17:25:24.110577','/upload/cover/1707036701716.jpeg','GET',NULL,'0'),(24,'127.0.0.1','2024-02-04 17:25:27.073752','/myapp/admin/opLog/list','GET',NULL,'4');
|
||||
|
||||
/*Table structure for table `b_order` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_order`;
|
||||
|
||||
CREATE TABLE `b_order` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`order_number` varchar(13) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`count` int NOT NULL,
|
||||
`status` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`order_time` datetime(6) DEFAULT NULL,
|
||||
`pay_time` datetime(6) DEFAULT NULL,
|
||||
`receiver_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`receiver_address` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`receiver_phone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`remark` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`thing_id` bigint DEFAULT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_order_thing_id_4e345e2c_fk_b_thing_id` (`thing_id`) USING BTREE,
|
||||
KEY `b_order_user_id_64854046_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_order_thing_id_4e345e2c_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_order_user_id_64854046_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_order` */
|
||||
|
||||
insert into `b_order`(`id`,`order_number`,`count`,`status`,`order_time`,`pay_time`,`receiver_name`,`receiver_address`,`receiver_phone`,`remark`,`thing_id`,`user_id`) values (1,'1707037383809',1,'2','2024-02-04 17:03:03.811334',NULL,NULL,NULL,NULL,NULL,5,4),(2,'1707037601900',1,'2','2024-02-04 17:06:41.903354',NULL,NULL,NULL,NULL,NULL,5,4),(3,'1707038198529',1,'2','2024-02-04 17:16:38.534185',NULL,NULL,NULL,NULL,NULL,1,4),(4,'1730549769958',1,'7','2024-11-02 20:16:09.962583',NULL,NULL,NULL,NULL,NULL,3,5);
|
||||
|
||||
/*Table structure for table `b_order_log` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_order_log`;
|
||||
|
||||
CREATE TABLE `b_order_log` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`action` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`log_time` datetime(6) DEFAULT NULL,
|
||||
`thing_id` bigint DEFAULT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_order_log_thing_id_7306f624_fk_b_thing_id` (`thing_id`) USING BTREE,
|
||||
KEY `b_order_log_user_id_1003e839_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_order_log_thing_id_7306f624_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_order_log_user_id_1003e839_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_order_log` */
|
||||
|
||||
/*Table structure for table `b_record` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_record`;
|
||||
|
||||
CREATE TABLE `b_record` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`record_time` datetime(6) DEFAULT NULL,
|
||||
`classification_id` bigint DEFAULT NULL,
|
||||
`thing_id` bigint DEFAULT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_record_classification_id_52591cc9_fk_b_classification_id` (`classification_id`) USING BTREE,
|
||||
KEY `b_record_thing_id_d8e773c0_fk_b_thing_id` (`thing_id`) USING BTREE,
|
||||
KEY `b_record_user_id_7e5958b0_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_record_classification_id_52591cc9_fk_b_classification_id` FOREIGN KEY (`classification_id`) REFERENCES `b_classification` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_record_thing_id_d8e773c0_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_record_user_id_7e5958b0_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_record` */
|
||||
|
||||
/*Table structure for table `b_tag` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_tag`;
|
||||
|
||||
CREATE TABLE `b_tag` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_tag` */
|
||||
|
||||
insert into `b_tag`(`id`,`title`,`create_time`) values (1,'美女多','2024-02-04 16:38:34.240261'),(2,'高材生','2024-02-04 16:38:41.618448'),(3,'帅哥多','2024-02-04 16:38:48.542216'),(4,'读书','2024-02-04 16:38:57.500728'),(5,'跑步','2024-02-04 16:39:05.464820');
|
||||
|
||||
/*Table structure for table `b_thing` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_thing`;
|
||||
|
||||
CREATE TABLE `b_thing` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`cover` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`description` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
|
||||
`mobile` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`location` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`status` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
`pv` int NOT NULL,
|
||||
`recommend_count` int NOT NULL,
|
||||
`wish_count` int NOT NULL,
|
||||
`collect_count` int NOT NULL,
|
||||
`classification_id` bigint DEFAULT NULL,
|
||||
`user_id` bigint DEFAULT NULL,
|
||||
`email` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`zongzhi` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`intendant` varchar(200) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `b_thing_classification_id_47675ac4_fk_b_classification_id` (`classification_id`) USING BTREE,
|
||||
KEY `b_thing_user_id_9918a633_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_thing_classification_id_47675ac4_fk_b_classification_id` FOREIGN KEY (`classification_id`) REFERENCES `b_classification` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_thing_user_id_9918a633_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_thing` */
|
||||
|
||||
insert into `b_thing`(`id`,`title`,`cover`,`description`,`mobile`,`location`,`status`,`create_time`,`pv`,`recommend_count`,`wish_count`,`collect_count`,`classification_id`,`user_id`,`email`,`zongzhi`,`intendant`) values (1,'梦想之家街舞团','cover/1707036603261.jpeg','abcfdasdf','13422221111','教学楼3号楼1层','0','2024-02-04 16:45:44.682923',4,0,1,1,2,NULL,'123@qq.com','为人民服务','3514164072@qq.com'),(2,'beyond502乐队','cover/1707036638009.jpeg','江河湖海就将计就计哈哈哈哈哈哈哈哈','13455555555','6号宿舍楼','0','2024-02-04 16:51:15.254882',1,0,0,0,3,NULL,'12345@qq.com','为了音乐而生','admin123'),(3,'轮滑俱乐部','cover/1707036701716.jpeg','哈哈哈哈哈哈哈哈哈哈','13422221111','9号宿舍楼','0','2024-02-04 16:52:13.713017',12,0,0,0,2,NULL,'1234@126.com','为了运动努力','admin123'),(4,'王羲之书法俱乐部','cover/1707036756214.jpeg','江河湖海哼哼唧唧哼哼唧唧就哈哈哈哈话剧','13211112222','颐和园路5号','0','2024-02-04 16:53:09.100387',2,0,0,0,3,NULL,'123@qq.com','为了哈哈哈','admin123'),(5,'电子琴俱乐部','cover/1707036810262.jpeg','就很好很好灌灌哈哈哈哈嘎嘎嘎嘎','13455555555','12号教学楼','0','2024-02-04 16:53:56.425555',16,0,1,1,4,NULL,'12245@qq.com','为了生活','admin123'),(6,'夜跑俱乐部','cover/1707036858212.jpeg','就啊哈哈的观点嘎哈韩国','13222221111','9号教学楼','0','2024-02-04 16:54:43.049737',3,0,0,0,1,NULL,'999888@qq.com','为了跑步','admin123'),(28,'2','cover/1730645105939.png','1','1','1','0','2024-11-03 22:45:08.477717',0,0,0,0,4,NULL,'1','1','3514164072@qq.com');
|
||||
|
||||
/*Table structure for table `b_thing_collect` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_thing_collect`;
|
||||
|
||||
CREATE TABLE `b_thing_collect` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`thing_id` bigint NOT NULL,
|
||||
`user_id` bigint NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `b_thing_collect_thing_id_user_id_45b9f252_uniq` (`thing_id`,`user_id`) USING BTREE,
|
||||
KEY `b_thing_collect_user_id_e5d69968_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_thing_collect_thing_id_8edce8b3_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_thing_collect_user_id_e5d69968_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_thing_collect` */
|
||||
|
||||
insert into `b_thing_collect`(`id`,`thing_id`,`user_id`) values (2,1,4),(1,5,4);
|
||||
|
||||
/*Table structure for table `b_thing_tag` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_thing_tag`;
|
||||
|
||||
CREATE TABLE `b_thing_tag` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`thing_id` bigint NOT NULL,
|
||||
`tag_id` bigint NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `b_thing_tag_thing_id_tag_id_a5d426b2_uniq` (`thing_id`,`tag_id`) USING BTREE,
|
||||
KEY `b_thing_tag_tag_id_d02b28a1_fk_b_tag_id` (`tag_id`) USING BTREE,
|
||||
CONSTRAINT `b_thing_tag_tag_id_d02b28a1_fk_b_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `b_tag` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_thing_tag_thing_id_fb8ecf3f_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_thing_tag` */
|
||||
|
||||
insert into `b_thing_tag`(`id`,`thing_id`,`tag_id`) values (1,1,2),(2,1,3),(3,1,4),(4,1,5),(5,2,1),(6,2,2),(7,2,3),(8,2,5),(9,3,1),(10,3,2),(11,3,3),(12,3,4),(13,3,5),(14,4,2),(15,4,4),(16,4,5),(17,5,2),(18,5,4),(19,6,1),(20,6,2),(21,6,5),(34,28,4);
|
||||
|
||||
/*Table structure for table `b_thing_wish` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_thing_wish`;
|
||||
|
||||
CREATE TABLE `b_thing_wish` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`thing_id` bigint NOT NULL,
|
||||
`user_id` bigint NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `b_thing_wish_thing_id_user_id_9d647bbb_uniq` (`thing_id`,`user_id`) USING BTREE,
|
||||
KEY `b_thing_wish_user_id_e2d94f6c_fk_b_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `b_thing_wish_thing_id_f0864b16_fk_b_thing_id` FOREIGN KEY (`thing_id`) REFERENCES `b_thing` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `b_thing_wish_user_id_e2d94f6c_fk_b_user_id` FOREIGN KEY (`user_id`) REFERENCES `b_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_thing_wish` */
|
||||
|
||||
insert into `b_thing_wish`(`id`,`thing_id`,`user_id`) values (2,1,4),(1,5,4);
|
||||
|
||||
/*Table structure for table `b_user` */
|
||||
|
||||
DROP TABLE IF EXISTS `b_user`;
|
||||
|
||||
CREATE TABLE `b_user` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`password` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`role` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`status` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`nickname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`avatar` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`mobile` varchar(13) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`gender` varchar(1) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`description` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
|
||||
`create_time` datetime(6) DEFAULT NULL,
|
||||
`score` int DEFAULT NULL,
|
||||
`push_email` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`push_switch` tinyint(1) DEFAULT NULL,
|
||||
`admin_token` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
`token` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `b_user` */
|
||||
|
||||
insert into `b_user`(`id`,`username`,`password`,`role`,`status`,`nickname`,`avatar`,`mobile`,`email`,`gender`,`description`,`create_time`,`score`,`push_email`,`push_switch`,`admin_token`,`token`) values (1,'admin','78aafd3207ec4ef6d16f9fc07e95ebc3','1','0',NULL,'',NULL,NULL,NULL,NULL,'2024-02-04 16:36:13.029265',0,NULL,0,'21232f297a57a5a743894a0e4a801fc3',NULL),(2,'admin123','0192023a7bbd73250516f069df18b500','3','0',NULL,'',NULL,NULL,NULL,NULL,'2024-02-04 16:40:18.754982',0,NULL,0,'0192023a7bbd73250516f069df18b500',NULL),(3,'test','098f6bcd4621d373cade4e832627b4f6','3','0',NULL,'',NULL,NULL,NULL,NULL,'2024-02-04 16:40:35.603385',0,NULL,0,NULL,NULL),(4,'aaa','47bce5c74f589f4867dbd57e9ca9f808','2','0','1233','',NULL,NULL,NULL,NULL,'2024-02-04 16:57:07.608626',0,NULL,0,NULL,'47bce5c74f589f4867dbd57e9ca9f808'),(5,'3514164072@qq.com','4f5b7a144cbb805fed790492173a6330','2','0',NULL,'',NULL,NULL,NULL,NULL,'2024-11-02 20:14:39.387932',0,NULL,0,NULL,'59c8650d7262ea4e14157205f04408d6');
|
||||
|
||||
/*Table structure for table `django_admin_log` */
|
||||
|
||||
DROP TABLE IF EXISTS `django_admin_log`;
|
||||
|
||||
CREATE TABLE `django_admin_log` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`action_time` datetime(6) NOT NULL,
|
||||
`object_id` longtext CHARACTER SET utf8 COLLATE utf8_general_ci,
|
||||
`object_repr` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`action_flag` smallint unsigned NOT NULL,
|
||||
`change_message` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`content_type_id` int DEFAULT NULL,
|
||||
`user_id` int NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `django_admin_log_content_type_id_c4bce8eb_fk_django_co` (`content_type_id`) USING BTREE,
|
||||
KEY `django_admin_log_user_id_c564eba6_fk_auth_user_id` (`user_id`) USING BTREE,
|
||||
CONSTRAINT `django_admin_log_content_type_id_c4bce8eb_fk_django_co` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `django_admin_log` */
|
||||
|
||||
/*Table structure for table `django_content_type` */
|
||||
|
||||
DROP TABLE IF EXISTS `django_content_type`;
|
||||
|
||||
CREATE TABLE `django_content_type` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`app_label` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`model` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `django_content_type_app_label_model_76bd3d3b_uniq` (`app_label`,`model`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `django_content_type` */
|
||||
|
||||
insert into `django_content_type`(`id`,`app_label`,`model`) values (1,'admin','logentry'),(3,'auth','group'),(2,'auth','permission'),(4,'auth','user'),(5,'contenttypes','contenttype'),(7,'myapp','ad'),(21,'myapp','address'),(20,'myapp','banner'),(8,'myapp','classification'),(19,'myapp','comment'),(9,'myapp','errorlog'),(10,'myapp','loginlog'),(11,'myapp','notice'),(12,'myapp','oplog'),(18,'myapp','order'),(17,'myapp','orderlog'),(16,'myapp','record'),(13,'myapp','tag'),(15,'myapp','thing'),(14,'myapp','user'),(6,'sessions','session');
|
||||
|
||||
/*Table structure for table `django_migrations` */
|
||||
|
||||
DROP TABLE IF EXISTS `django_migrations`;
|
||||
|
||||
CREATE TABLE `django_migrations` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`app` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`applied` datetime(6) NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `django_migrations` */
|
||||
|
||||
insert into `django_migrations`(`id`,`app`,`name`,`applied`) values (1,'contenttypes','0001_initial','2024-02-04 16:32:51.298695'),(2,'auth','0001_initial','2024-02-04 16:32:51.549701'),(3,'admin','0001_initial','2024-02-04 16:32:51.606242'),(4,'admin','0002_logentry_remove_auto_add','2024-02-04 16:32:51.613953'),(5,'admin','0003_logentry_add_action_flag_choices','2024-02-04 16:32:51.619196'),(6,'contenttypes','0002_remove_content_type_name','2024-02-04 16:32:51.687139'),(7,'auth','0002_alter_permission_name_max_length','2024-02-04 16:32:51.729044'),(8,'auth','0003_alter_user_email_max_length','2024-02-04 16:32:51.771331'),(9,'auth','0004_alter_user_username_opts','2024-02-04 16:32:51.777711'),(10,'auth','0005_alter_user_last_login_null','2024-02-04 16:32:51.813729'),(11,'auth','0006_require_contenttypes_0002','2024-02-04 16:32:51.817877'),(12,'auth','0007_alter_validators_add_error_messages','2024-02-04 16:32:51.823354'),(13,'auth','0008_alter_user_username_max_length','2024-02-04 16:32:51.865155'),(14,'auth','0009_alter_user_last_name_max_length','2024-02-04 16:32:51.907643'),(15,'auth','0010_alter_group_name_max_length','2024-02-04 16:32:51.951019'),(16,'auth','0011_update_proxy_permissions','2024-02-04 16:32:51.958587'),(17,'auth','0012_alter_user_first_name_max_length','2024-02-04 16:32:52.003585'),(18,'myapp','0001_initial','2024-02-04 16:32:52.698876'),(19,'myapp','0002_thing_user','2024-02-04 16:32:52.738582'),(20,'myapp','0003_auto_20240204_1632','2024-02-04 16:32:52.933013'),(21,'sessions','0001_initial','2024-02-04 16:32:52.969896');
|
||||
|
||||
/*Table structure for table `django_session` */
|
||||
|
||||
DROP TABLE IF EXISTS `django_session`;
|
||||
|
||||
CREATE TABLE `django_session` (
|
||||
`session_key` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`session_data` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`expire_date` datetime(6) NOT NULL,
|
||||
PRIMARY KEY (`session_key`) USING BTREE,
|
||||
KEY `django_session_expire_date_a5c62663` (`expire_date`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
/*Data for the table `django_session` */
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,10 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from myapp.models import Classification, Thing, Tag, User, Comment
|
||||
|
||||
admin.site.register(Classification)
|
||||
admin.site.register(Tag)
|
||||
admin.site.register(Thing)
|
||||
admin.site.register(User)
|
||||
admin.site.register(Comment)
|
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MyappConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'myapp'
|
@ -0,0 +1,5 @@
|
||||
from rest_framework.throttling import AnonRateThrottle
|
||||
|
||||
|
||||
class MyRateThrottle(AnonRateThrottle):
|
||||
THROTTLE_RATES = {"anon": "2/min"}
|
@ -0,0 +1,13 @@
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
class APIResponse(Response):
|
||||
def __init__(self, code=0, msg='', data=None, status=200, headers=None, content_type=None, **kwargs):
|
||||
dic = {'code': code, 'msg': msg}
|
||||
if data is not None:
|
||||
dic['data'] = data
|
||||
|
||||
dic.update(kwargs) # 这里使用update
|
||||
super().__init__(data=dic, status=status,
|
||||
template_name=None, headers=headers,
|
||||
exception=False, content_type=content_type)
|
@ -0,0 +1,54 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
import time
|
||||
import json
|
||||
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
from myapp import utils
|
||||
from myapp.serializers import OpLogSerializer
|
||||
|
||||
|
||||
class OpLogs(MiddlewareMixin):
|
||||
|
||||
def __init__(self, *args):
|
||||
super(OpLogs, self).__init__(*args)
|
||||
|
||||
self.start_time = None # 开始时间
|
||||
self.end_time = None # 响应时间
|
||||
self.data = {} # dict数据
|
||||
|
||||
def process_request(self, request):
|
||||
|
||||
self.start_time = time.time() # 开始时间
|
||||
|
||||
re_ip = utils.get_ip(request)
|
||||
re_method = request.method
|
||||
re_content = request.GET if re_method == 'GET' else request.POST
|
||||
if re_content:
|
||||
re_content = json.dumps(re_content)
|
||||
else:
|
||||
re_content = None
|
||||
|
||||
self.data.update(
|
||||
{
|
||||
're_url': request.path,
|
||||
're_method': re_method,
|
||||
're_ip': re_ip,
|
||||
# 're_content': re_content,
|
||||
}
|
||||
)
|
||||
# print(self.data)
|
||||
|
||||
def process_response(self, request, response):
|
||||
|
||||
# 耗时毫秒/ms
|
||||
self.end_time = time.time() # 响应时间
|
||||
access_time = self.end_time - self.start_time
|
||||
self.data['access_time'] = round(access_time * 1000)
|
||||
|
||||
# 入库
|
||||
# serializer = OpLogSerializer(data=self.data)
|
||||
# if serializer.is_valid():
|
||||
# serializer.save()
|
||||
|
||||
return response
|
@ -0,0 +1,226 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class User(models.Model):
|
||||
GENDER_CHOICES = (
|
||||
('M', '男'),
|
||||
('F', '女'),
|
||||
)
|
||||
ROLE_CHOICES = (
|
||||
('0', '管理员'),
|
||||
('1', '普通用户'),
|
||||
)
|
||||
STATUS_CHOICES = (
|
||||
('0', '正常'),
|
||||
('1', '封号'),
|
||||
)
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
username = models.CharField(max_length=50, null=True)
|
||||
password = models.CharField(max_length=50, null=True)
|
||||
role = models.CharField(max_length=2, blank=True, null=True)
|
||||
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='0')
|
||||
nickname = models.CharField(blank=True, null=True, max_length=20)
|
||||
avatar = models.FileField(upload_to='avatar/', null=True)
|
||||
mobile = models.CharField(max_length=13, blank=True, null=True)
|
||||
email = models.CharField(max_length=50, blank=True, null=True)
|
||||
gender = models.CharField(max_length=1, choices=GENDER_CHOICES, blank=True, null=True)
|
||||
description = models.TextField(max_length=200, null=True)
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
score = models.IntegerField(default=0, blank=True, null=True)
|
||||
push_email = models.CharField(max_length=40, blank=True, null=True)
|
||||
push_switch = models.BooleanField(blank=True, null=True, default=False)
|
||||
admin_token = models.CharField(max_length=32, blank=True, null=True)
|
||||
token = models.CharField(max_length=32, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_user"
|
||||
|
||||
|
||||
class Tag(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
title = models.CharField(max_length=100, blank=True, null=True)
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_tag"
|
||||
|
||||
|
||||
class Classification(models.Model):
|
||||
list_display = ("title", "id")
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
title = models.CharField(max_length=100, blank=True, null=True)
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
db_table = "b_classification"
|
||||
|
||||
|
||||
class Thing(models.Model):
|
||||
STATUS_CHOICES = (
|
||||
('0', '上架'),
|
||||
('1', '下架'),
|
||||
('3', '审核'),
|
||||
)
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
classification = models.ForeignKey(Classification, on_delete=models.CASCADE, blank=True, null=True,
|
||||
related_name='classification_thing')
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name='user_thing')
|
||||
tag = models.ManyToManyField(Tag, blank=True)
|
||||
title = models.CharField(max_length=100, blank=True, null=True)
|
||||
cover = models.ImageField(upload_to='cover/', null=True)
|
||||
description = models.TextField(max_length=1000, blank=True, null=True)
|
||||
zongzhi = models.CharField(max_length=200, blank=True, null=True)
|
||||
intendant = models.CharField(max_length=200, blank=True, null=True)
|
||||
email = models.CharField(max_length=200, blank=True, null=True)
|
||||
mobile = models.CharField(max_length=50, blank=True, null=True)
|
||||
location = models.CharField(max_length=50, blank=True, null=True)
|
||||
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='0')
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
pv = models.IntegerField(default=0)
|
||||
recommend_count = models.IntegerField(default=0)
|
||||
wish = models.ManyToManyField(User, blank=True, related_name="wish_things")
|
||||
wish_count = models.IntegerField(default=0)
|
||||
collect = models.ManyToManyField(User, blank=True, related_name="collect_things")
|
||||
collect_count = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_thing"
|
||||
|
||||
|
||||
class Comment(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
content = models.CharField(max_length=200, blank=True, null=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='user_comment')
|
||||
thing = models.ForeignKey(Thing, on_delete=models.CASCADE, null=True, related_name='thing_comment')
|
||||
comment_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
like_count = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_comment"
|
||||
|
||||
|
||||
class Record(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='user_record')
|
||||
thing = models.ForeignKey(Thing, on_delete=models.CASCADE, null=True, related_name='thing_record')
|
||||
title = models.CharField(max_length=100, blank=True, null=True)
|
||||
classification = models.ForeignKey(Classification, on_delete=models.CASCADE, null=True,
|
||||
related_name='classification')
|
||||
record_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_record"
|
||||
|
||||
|
||||
class LoginLog(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
username = models.CharField(max_length=50, blank=True, null=True)
|
||||
ip = models.CharField(max_length=100, blank=True, null=True)
|
||||
ua = models.CharField(max_length=200, blank=True, null=True)
|
||||
log_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_login_log"
|
||||
|
||||
|
||||
class OpLog(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
re_ip = models.CharField(max_length=100, blank=True, null=True)
|
||||
re_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
re_url = models.CharField(max_length=200, blank=True, null=True)
|
||||
re_method = models.CharField(max_length=10, blank=True, null=True)
|
||||
re_content = models.CharField(max_length=200, blank=True, null=True)
|
||||
access_time = models.CharField(max_length=10, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_op_log"
|
||||
|
||||
|
||||
class ErrorLog(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
ip = models.CharField(max_length=100, blank=True, null=True)
|
||||
url = models.CharField(max_length=200, blank=True, null=True)
|
||||
method = models.CharField(max_length=10, blank=True, null=True)
|
||||
content = models.CharField(max_length=200, blank=True, null=True)
|
||||
log_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_error_log"
|
||||
|
||||
|
||||
class Order(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
order_number = models.CharField(max_length=13, blank=True, null=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='user_order')
|
||||
thing = models.ForeignKey(Thing, on_delete=models.CASCADE, null=True, related_name='thing_order')
|
||||
count = models.IntegerField(default=0)
|
||||
status = models.CharField(max_length=2, blank=True, null=True) # 1未审核 2已审核 7取消
|
||||
order_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
pay_time = models.DateTimeField(null=True)
|
||||
receiver_name = models.CharField(max_length=20, blank=True, null=True)
|
||||
receiver_address = models.CharField(max_length=50, blank=True, null=True)
|
||||
receiver_phone = models.CharField(max_length=20, blank=True, null=True)
|
||||
remark = models.CharField(max_length=30, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_order"
|
||||
|
||||
|
||||
class OrderLog(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='user_order_log')
|
||||
thing = models.ForeignKey(Thing, on_delete=models.CASCADE, null=True, related_name='thing_order_log')
|
||||
action = models.CharField(max_length=2, blank=True, null=True)
|
||||
log_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_order_log"
|
||||
|
||||
|
||||
class Banner(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
image = models.ImageField(upload_to='banner/', null=True)
|
||||
thing = models.ForeignKey(Thing, on_delete=models.CASCADE, null=True, related_name='thing_banner')
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_banner"
|
||||
|
||||
|
||||
class Ad(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
image = models.ImageField(upload_to='ad/', null=True)
|
||||
link = models.CharField(max_length=500, blank=True, null=True)
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_ad"
|
||||
|
||||
|
||||
class Notice(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
title = models.CharField(max_length=100, blank=True, null=True)
|
||||
name = models.CharField(max_length=200, blank=True, null=True)
|
||||
thing_name = models.CharField(max_length=200, blank=True, null=True)
|
||||
content = models.CharField(max_length=1000, blank=True, null=True)
|
||||
#thing_id = models.ForeignKey(Thing, on_delete=models.CASCADE, null=True, related_name='thing_notice')
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_notice"
|
||||
|
||||
|
||||
class Address(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='user_address')
|
||||
name = models.CharField(max_length=100, blank=True, null=True)
|
||||
mobile = models.CharField(max_length=30, blank=True, null=True)
|
||||
desc = models.CharField(max_length=300, blank=True, null=True)
|
||||
default = models.BooleanField(blank=True, null=True, default=False) # 是否默认地址
|
||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "b_address"
|
@ -0,0 +1,160 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from myapp.models import Thing, Classification, Tag, User, Comment, Record, LoginLog, Order, OrderLog, OpLog, Banner, \
|
||||
Ad, Notice, ErrorLog, Address
|
||||
|
||||
|
||||
class ThingSerializer(serializers.ModelSerializer):
|
||||
# 额外字段
|
||||
classification_title = serializers.ReadOnlyField(source='classification.title')
|
||||
|
||||
class Meta:
|
||||
model = Thing
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class DetailThingSerializer(serializers.ModelSerializer):
|
||||
# 额外字段
|
||||
classification_title = serializers.ReadOnlyField(source='classification.title')
|
||||
|
||||
class Meta:
|
||||
model = Thing
|
||||
# 排除多对多字段
|
||||
exclude = ('wish', 'collect',)
|
||||
|
||||
|
||||
class UpdateThingSerializer(serializers.ModelSerializer):
|
||||
# 额外字段
|
||||
classification_title = serializers.ReadOnlyField(source='classification.title')
|
||||
|
||||
class Meta:
|
||||
model = Thing
|
||||
# 排除多对多字段
|
||||
exclude = ('wish', 'collect',)
|
||||
|
||||
|
||||
class ListThingSerializer(serializers.ModelSerializer):
|
||||
# 额外字段
|
||||
classification_title = serializers.ReadOnlyField(source='classification.title')
|
||||
|
||||
class Meta:
|
||||
model = Thing
|
||||
# 排除字段
|
||||
exclude = ('wish', 'collect',)
|
||||
|
||||
|
||||
class ClassificationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Classification
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class TagSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Tag
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = '__all__'
|
||||
# exclude = ('password',)
|
||||
|
||||
|
||||
class CommentSerializer(serializers.ModelSerializer):
|
||||
comment_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
# 额外字段
|
||||
title = serializers.ReadOnlyField(source='thing.title')
|
||||
username = serializers.ReadOnlyField(source='user.username')
|
||||
|
||||
class Meta:
|
||||
model = Comment
|
||||
fields = ['id', 'content', 'comment_time', 'like_count', 'thing', 'user', 'title', 'username']
|
||||
|
||||
|
||||
class RecordSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Record
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class LoginLogSerializer(serializers.ModelSerializer):
|
||||
log_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = LoginLog
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class OpLogSerializer(serializers.ModelSerializer):
|
||||
re_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = OpLog
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ErrorLogSerializer(serializers.ModelSerializer):
|
||||
log_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = ErrorLog
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class OrderSerializer(serializers.ModelSerializer):
|
||||
order_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
expect_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
return_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
# extra
|
||||
username = serializers.ReadOnlyField(source='user.username')
|
||||
title = serializers.ReadOnlyField(source='thing.title')
|
||||
price = serializers.ReadOnlyField(source='thing.price')
|
||||
cover = serializers.FileField(source='thing.cover', required=False)
|
||||
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class OrderLogSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = OrderLog
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class BannerSerializer(serializers.ModelSerializer):
|
||||
create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
# extra
|
||||
title = serializers.ReadOnlyField(source='thing.title')
|
||||
|
||||
class Meta:
|
||||
model = Banner
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class AdSerializer(serializers.ModelSerializer):
|
||||
create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = Ad
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class NoticeSerializer(serializers.ModelSerializer):
|
||||
create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = Notice
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class AddressSerializer(serializers.ModelSerializer):
|
||||
create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', required=False)
|
||||
|
||||
class Meta:
|
||||
model = Address
|
||||
fields = '__all__'
|
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -0,0 +1,102 @@
|
||||
from django.urls import path
|
||||
|
||||
from myapp import views
|
||||
|
||||
app_name = 'myapp'
|
||||
urlpatterns = [
|
||||
# 后台管理api
|
||||
path('admin/overview/count', views.admin.overview.count),
|
||||
path('admin/overview/sysInfo', views.admin.overview.sysInfo),
|
||||
path('admin/thing/list', views.admin.thing.list_api),
|
||||
path('admin/thing/detail', views.admin.thing.detail),
|
||||
path('admin/thing/create', views.admin.thing.create),
|
||||
path('admin/thing/update', views.admin.thing.update),
|
||||
path('admin/thing/delete', views.admin.thing.delete),
|
||||
path('admin/comment/list', views.admin.comment.list_api),
|
||||
path('admin/comment/create', views.admin.comment.create),
|
||||
path('admin/comment/update', views.admin.comment.update),
|
||||
path('admin/comment/delete', views.admin.comment.delete),
|
||||
path('admin/classification/list', views.admin.classification.list_api),
|
||||
path('admin/classification/create', views.admin.classification.create),
|
||||
path('admin/classification/update', views.admin.classification.update),
|
||||
path('admin/classification/delete', views.admin.classification.delete),
|
||||
path('admin/tag/list', views.admin.tag.list_api),
|
||||
path('admin/tag/create', views.admin.tag.create),
|
||||
path('admin/tag/update', views.admin.tag.update),
|
||||
path('admin/tag/delete', views.admin.tag.delete),
|
||||
path('admin/record/list', views.admin.record.list_api),
|
||||
path('admin/record/create', views.admin.record.create),
|
||||
path('admin/record/update', views.admin.record.update),
|
||||
path('admin/record/delete', views.admin.record.delete),
|
||||
path('admin/banner/list', views.admin.banner.list_api),
|
||||
path('admin/banner/create', views.admin.banner.create),
|
||||
path('admin/banner/update', views.admin.banner.update),
|
||||
path('admin/banner/delete', views.admin.banner.delete),
|
||||
path('admin/ad/list', views.admin.ad.list_api),
|
||||
path('admin/ad/create', views.admin.ad.create),
|
||||
path('admin/ad/update', views.admin.ad.update),
|
||||
path('admin/ad/delete', views.admin.ad.delete),
|
||||
path('admin/notice/list', views.admin.notice.list_api),
|
||||
path('admin/notice/create', views.admin.notice.create),
|
||||
path('admin/notice/update', views.admin.notice.update),
|
||||
path('admin/notice/delete', views.admin.notice.delete),
|
||||
path('admin/order/list', views.admin.order.list_api),
|
||||
path('admin/order/create', views.admin.order.create),
|
||||
path('admin/order/update', views.admin.order.update),
|
||||
path('admin/order/cancel_order', views.admin.order.cancel_order),
|
||||
path('admin/order/pass_order', views.admin.order.pass_order),
|
||||
path('admin/order/delay', views.admin.order.delay),
|
||||
path('admin/order/delete', views.admin.order.delete),
|
||||
path('admin/loginLog/list', views.admin.loginLog.list_api),
|
||||
path('admin/loginLog/create', views.admin.loginLog.create),
|
||||
path('admin/loginLog/update', views.admin.loginLog.update),
|
||||
path('admin/loginLog/delete', views.admin.loginLog.delete),
|
||||
path('admin/opLog/list', views.admin.opLog.list_api),
|
||||
path('admin/errorLog/list', views.admin.errorLog.list_api),
|
||||
path('admin/user/list', views.admin.user.list_api),
|
||||
path('admin/user/create', views.admin.user.create),
|
||||
path('admin/user/update', views.admin.user.update),
|
||||
path('admin/user/updatePwd', views.admin.user.updatePwd),
|
||||
path('admin/user/delete', views.admin.user.delete),
|
||||
path('admin/user/info', views.admin.user.info),
|
||||
path('admin/adminLogin', views.admin.user.admin_login),
|
||||
|
||||
|
||||
# 前台管理api
|
||||
path('index/classification/list', views.index.classification.list_api),
|
||||
path('index/tag/list', views.index.tag.list_api),
|
||||
path('index/user/login', views.index.user.login),
|
||||
path('index/user/register', views.index.user.register),
|
||||
path('index/user/info', views.index.user.info),
|
||||
path('index/user/update', views.index.user.update),
|
||||
path('index/user/updatePwd', views.index.user.updatePwd),
|
||||
path('index/notice/list_api', views.index.notice.list_api),
|
||||
path('index/thing/list', views.index.thing.list_api),
|
||||
path('index/thing/detail', views.index.thing.detail),
|
||||
path('index/thing/increaseWishCount', views.index.thing.increaseWishCount),
|
||||
path('index/thing/addWishUser', views.index.thing.addWishUser),
|
||||
path('index/thing/removeWishUser', views.index.thing.removeWishUser),
|
||||
path('index/thing/getWishThingList', views.index.thing.getWishThingList),
|
||||
path('index/thing/addCollectUser', views.index.thing.addCollectUser),
|
||||
path('index/thing/removeCollectUser', views.index.thing.removeCollectUser),
|
||||
path('index/thing/getCollectThingList', views.index.thing.getCollectThingList),
|
||||
path('index/thing/increaseRecommendCount', views.index.thing.increaseRecommendCount),
|
||||
path('index/thing/listUserThing', views.index.thing.list_user_thing_api),
|
||||
path('index/thing/create', views.index.thing.create),
|
||||
path('index/thing/update', views.index.thing.update),
|
||||
path('index/comment/list', views.index.comment.list_api),
|
||||
path('index/comment/listMyComments', views.index.comment.list_my_comment),
|
||||
path('index/comment/create', views.index.comment.create),
|
||||
path('index/comment/delete', views.index.comment.delete),
|
||||
path('index/comment/like', views.index.comment.like),
|
||||
path('index/order/list', views.index.order.list_api),
|
||||
path('index/order/create', views.index.order.create),
|
||||
path('index/order/cancel_order', views.index.order.cancel_order),
|
||||
path('index/address/list', views.index.address.list_api),
|
||||
path('index/address/create', views.index.address.create),
|
||||
path('index/address/update', views.index.address.update),
|
||||
path('index/address/delete', views.index.address.delete),
|
||||
|
||||
|
||||
|
||||
]
|
@ -0,0 +1,2 @@
|
||||
from myapp.views.admin import *
|
||||
from myapp.views.index import *
|
@ -0,0 +1,14 @@
|
||||
from myapp.views.admin.thing import *
|
||||
from myapp.views.admin.classification import *
|
||||
from myapp.views.admin.tag import *
|
||||
from myapp.views.admin.user import *
|
||||
from myapp.views.admin.comment import *
|
||||
from myapp.views.admin.record import *
|
||||
from myapp.views.admin.overview import *
|
||||
from myapp.views.admin.loginLog import *
|
||||
from myapp.views.admin.order import *
|
||||
from myapp.views.admin.opLog import *
|
||||
from myapp.views.admin.errorLog import *
|
||||
from myapp.views.admin.banner import *
|
||||
from myapp.views.admin.ad import *
|
||||
from myapp.views.admin.notice import *
|
@ -0,0 +1,68 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Ad
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import AdSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
ads = Ad.objects.all().order_by('-create_time')
|
||||
serializer = AdSerializer(ads, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
serializer = AdSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
ad = Ad.objects.get(pk=pk)
|
||||
except Ad.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = AdSerializer(ad, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Ad.objects.filter(id__in=ids_arr).delete()
|
||||
except Ad.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,68 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Banner
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import BannerSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
banners = Banner.objects.all().order_by('-create_time')
|
||||
serializer = BannerSerializer(banners, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
serializer = BannerSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
banner = Banner.objects.get(pk=pk)
|
||||
except Banner.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = BannerSerializer(banner, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Banner.objects.filter(id__in=ids_arr).delete()
|
||||
except Banner.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,74 @@
|
||||
# Create your views here.
|
||||
from django.db import connection
|
||||
from django.db.models import Q
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Classification
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import ClassificationSerializer
|
||||
from myapp.utils import dict_fetchall
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
classifications = Classification.objects.all().order_by('-create_time')
|
||||
serializer = ClassificationSerializer(classifications, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
classification = Classification.objects.filter(title=request.data['title'])
|
||||
if len(classification) > 0:
|
||||
return APIResponse(code=1, msg='该名称已存在')
|
||||
|
||||
serializer = ClassificationSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
print(pk)
|
||||
classification = Classification.objects.get(pk=pk)
|
||||
except Classification.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = ClassificationSerializer(classification, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
# 删除自身和自身的子孩子
|
||||
Classification.objects.filter(Q(id__in=ids_arr)).delete()
|
||||
except Classification.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,69 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Comment
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import CommentSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
comments = Comment.objects.select_related("thing").all().order_by('-comment_time')
|
||||
# print(comments)
|
||||
serializer = CommentSerializer(comments, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
serializer = CommentSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
comments = Comment.objects.get(pk=pk)
|
||||
except Comment.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = CommentSerializer(comments, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Comment.objects.filter(id__in=ids_arr).delete()
|
||||
except Comment.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,14 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import ErrorLog
|
||||
from myapp.serializers import ErrorLogSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
errorLogs = ErrorLog.objects.all().order_by('-log_time')
|
||||
serializer = ErrorLogSerializer(errorLogs, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
@ -0,0 +1,60 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import LoginLog
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import LoginLogSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
loginLogs = LoginLog.objects.all().order_by('-log_time')
|
||||
serializer = LoginLogSerializer(loginLogs, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def create(request):
|
||||
|
||||
serializer = LoginLogSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
loginLogs = LoginLog.objects.get(pk=pk)
|
||||
except LoginLog.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = LoginLogSerializer(loginLogs, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
LoginLog.objects.filter(id__in=ids_arr).delete()
|
||||
except LoginLog.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,69 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Notice
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import NoticeSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
user = request.GET.get("user")
|
||||
if user:
|
||||
notices = Notice.objects.filter(name=user).order_by('-create_time')
|
||||
else:
|
||||
notices = Notice.objects.all().order_by('-create_time')
|
||||
serializer = NoticeSerializer(notices, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
|
||||
|
||||
serializer = NoticeSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
notice = Notice.objects.get(pk=pk)
|
||||
except Notice.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = NoticeSerializer(notice, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Notice.objects.filter(id__in=ids_arr).delete()
|
||||
except Notice.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,14 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import OpLog
|
||||
from myapp.serializers import OpLogSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
opLogs = OpLog.objects.all().order_by('-re_time')[:100]
|
||||
serializer = OpLogSerializer(opLogs, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
@ -0,0 +1,172 @@
|
||||
# Create your views here.
|
||||
import datetime
|
||||
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Order, Thing
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import OrderSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
user = request.GET.get("user")
|
||||
orders = Order.objects.all().order_by('-order_time')
|
||||
if user:
|
||||
orders = Order.objects.filter(thing__intendant=user).order_by('-order_time')
|
||||
serializer = OrderSerializer(orders, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
"""
|
||||
创建订单
|
||||
"""
|
||||
|
||||
|
||||
data = request.data.copy()
|
||||
if data['user'] is None or data['thing'] is None or data['count'] is None:
|
||||
return APIResponse(code=1, msg='参数错误')
|
||||
|
||||
thing = Thing.objects.get(pk=data['thing'])
|
||||
count = data['count']
|
||||
if thing.repertory < int(count):
|
||||
return APIResponse(code=1, msg='库存不足')
|
||||
|
||||
create_time = datetime.datetime.now()
|
||||
data['create_time'] = create_time
|
||||
data['order_number'] = str(utils.get_timestamp())
|
||||
data['status'] = '1'
|
||||
serializer = OrderSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
# 减库存(支付后)
|
||||
# thing.repertory = thing.repertory - int(count)
|
||||
# thing.save()
|
||||
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
order = Order.objects.get(pk=pk)
|
||||
except Order.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = OrderSerializer(order, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def pass_order(request):
|
||||
"""
|
||||
取消
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
order = Order.objects.get(pk=pk)
|
||||
except Order.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
data = {
|
||||
'status': 2
|
||||
}
|
||||
serializer = OrderSerializer(order, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
|
||||
return APIResponse(code=0, msg='成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def cancel_order(request):
|
||||
"""
|
||||
取消
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
order = Order.objects.get(pk=pk)
|
||||
except Order.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
data = {
|
||||
'status': 7
|
||||
}
|
||||
serializer = OrderSerializer(order, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
|
||||
return APIResponse(code=0, msg='取消成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delay(request):
|
||||
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
order = Order.objects.get(pk=pk)
|
||||
except Order.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
if order.delayed:
|
||||
return APIResponse(code=1, msg='已超最大延期次数')
|
||||
else:
|
||||
data = {
|
||||
"delayed": True,
|
||||
"expect_time": order.expect_time + datetime.timedelta(days=30)
|
||||
}
|
||||
serializer = OrderSerializer(order, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='延期成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='延期失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Order.objects.filter(id__in=ids_arr).delete()
|
||||
except Order.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,98 @@
|
||||
# Create your views here.
|
||||
import datetime
|
||||
import locale
|
||||
import platform
|
||||
import random
|
||||
import time
|
||||
from multiprocessing import cpu_count
|
||||
|
||||
import psutil
|
||||
from django.db import connection
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.handler import APIResponse
|
||||
|
||||
from myapp.models import Thing, Order
|
||||
from myapp.utils import dict_fetchall
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def count(request):
|
||||
if request.method == 'GET':
|
||||
now = datetime.datetime.now()
|
||||
|
||||
# 统计排名(sql语句)
|
||||
sql_str = "select title, pv as count from b_thing order by count desc limit 10; "
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql_str)
|
||||
order_rank_data = dict_fetchall(cursor)
|
||||
|
||||
# 统计分类比例(sql语句)
|
||||
sql_str = "select B.title, count(B.title) as count from b_thing A join B_classification B on " \
|
||||
"A.classification_id = B.id group by B.title order by count desc limit 5; "
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql_str)
|
||||
classification_rank_data = dict_fetchall(cursor)
|
||||
|
||||
# 统计最近一周访问量(sql语句)
|
||||
visit_data = []
|
||||
week_days = utils.getWeekDays()
|
||||
for day in week_days:
|
||||
sql_str = "select re_ip, count(re_ip) as count from b_op_log where re_time like '" + day + "%' group by re_ip"
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql_str)
|
||||
ip_data = dict_fetchall(cursor)
|
||||
uv = len(ip_data)
|
||||
pv = 0
|
||||
for item in ip_data:
|
||||
pv = pv + item['count']
|
||||
visit_data.append({
|
||||
"day": day,
|
||||
"uv": uv + random.randint(1, 20),
|
||||
"pv": pv + random.randint(20, 100)
|
||||
})
|
||||
|
||||
data = {
|
||||
'order_rank_data': order_rank_data,
|
||||
'classification_rank_data': classification_rank_data,
|
||||
'visit_data': visit_data
|
||||
}
|
||||
return APIResponse(code=0, msg='查询成功', data=data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def sysInfo(request):
|
||||
if request.method == 'GET':
|
||||
pyVersion = platform.python_version()
|
||||
osBuild = platform.architecture()
|
||||
node = platform.node()
|
||||
pf = platform.platform()
|
||||
processor = platform.processor()
|
||||
pyComp = platform.python_compiler()
|
||||
osName = platform.system()
|
||||
memory = psutil.virtual_memory()
|
||||
|
||||
data = {
|
||||
'sysName': '后台管理系统',
|
||||
'versionName': '1.1.0',
|
||||
'osName': osName,
|
||||
'pyVersion': pyVersion,
|
||||
'osBuild': osBuild,
|
||||
'node': node,
|
||||
'pf': pf,
|
||||
'processor': processor,
|
||||
'cpuCount': cpu_count(),
|
||||
'pyComp': pyComp,
|
||||
'cpuLoad': round((psutil.cpu_percent(1)), 2),
|
||||
'memory': round((float(memory.total) / 1024 / 1024 / 1024), 2),
|
||||
'usedMemory': round((float(memory.used) / 1024 / 1024 / 1024), 2),
|
||||
'percentMemory': round((float(memory.used) / float(memory.total) * 100), 2),
|
||||
'sysLan': locale.getdefaultlocale(),
|
||||
'sysZone': time.strftime('%Z', time.localtime())
|
||||
}
|
||||
|
||||
return APIResponse(code=0, msg='查询成功', data=data)
|
@ -0,0 +1,53 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Record
|
||||
from myapp.serializers import RecordSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
records = Record.objects.all()
|
||||
serializer = RecordSerializer(records, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def create(request):
|
||||
|
||||
serializer = RecordSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def update(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
records = Record.objects.get(pk=pk)
|
||||
except Record.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = RecordSerializer(records, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def delete(request):
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Record.objects.filter(id__in=ids_arr).delete()
|
||||
except Record.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,75 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Tag
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import TagSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
tags = Tag.objects.all().order_by('-create_time')
|
||||
serializer = TagSerializer(tags, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
tags = Tag.objects.filter(title=request.data['title'])
|
||||
if len(tags) > 0:
|
||||
return APIResponse(code=1, msg='该名称已存在')
|
||||
|
||||
serializer = TagSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
tags = Tag.objects.get(pk=pk)
|
||||
except Tag.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = TagSerializer(tags, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Tag.objects.filter(id__in=ids_arr).delete()
|
||||
except Tag.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,115 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Classification, Thing, Tag
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import ThingSerializer, UpdateThingSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
keyword = request.GET.get("keyword", None)
|
||||
user = request.GET.get("user")
|
||||
c = request.GET.get("c", None)
|
||||
tag = request.GET.get("tag", None)
|
||||
print(keyword)
|
||||
print(1)
|
||||
print(user)
|
||||
print(2)
|
||||
print(c)
|
||||
|
||||
if keyword:
|
||||
if user:
|
||||
things = Thing.objects.filter(title__contains=keyword,intendant=user).order_by('create_time')
|
||||
else:
|
||||
things = Thing.objects.filter(title__contains=keyword).order_by('create_time')
|
||||
|
||||
elif c:
|
||||
classification = Classification.objects.get(pk=c)
|
||||
things = classification.classification_thing.all()
|
||||
elif tag:
|
||||
tag = Tag.objects.get(id=tag)
|
||||
print(tag)
|
||||
things = tag.thing_set.all()
|
||||
elif user:
|
||||
things = Thing.objects.filter(intendant=user).order_by('create_time')
|
||||
else:
|
||||
things = Thing.objects.all().order_by('create_time')
|
||||
|
||||
serializer = ThingSerializer(things, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def detail(request):
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '对象不存在')
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
if request.method == 'GET':
|
||||
serializer = ThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
|
||||
|
||||
print(request.data)
|
||||
serializer = ThingSerializer(data=request.data)
|
||||
print(serializer)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
|
||||
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
except Thing.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = UpdateThingSerializer(thing, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
|
||||
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Thing.objects.filter(id__in=ids_arr).delete()
|
||||
except Thing.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,176 @@
|
||||
# Create your views here.
|
||||
import datetime
|
||||
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import User
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import UserSerializer, LoginLogSerializer
|
||||
from myapp.utils import md5value
|
||||
|
||||
|
||||
def make_login_log(request):
|
||||
try:
|
||||
username = request.data['username']
|
||||
data = {
|
||||
"username": username,
|
||||
"ip": utils.get_ip(request),
|
||||
"ua": utils.get_ua(request)
|
||||
}
|
||||
serializer = LoginLogSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
else:
|
||||
print(serializer.errors)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def admin_login(request):
|
||||
username = request.data['username']
|
||||
password = utils.md5value(request.data['password'])
|
||||
|
||||
users = User.objects.filter(username=username, password=password, role__in=['1', '3'])
|
||||
if len(users) > 0:
|
||||
user = users[0]
|
||||
data = {
|
||||
'username': username,
|
||||
'password': password,
|
||||
'admin_token': md5value(username) # 生成令牌
|
||||
}
|
||||
serializer = UserSerializer(user, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
make_login_log(request)
|
||||
return APIResponse(code=0, msg='登录成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='用户名或密码错误')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def info(request):
|
||||
if request.method == 'GET':
|
||||
pk = request.GET.get('id', -1)
|
||||
user = User.objects.get(pk=pk)
|
||||
serializer = UserSerializer(user)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
keyword = request.GET.get("keyword", '')
|
||||
users = User.objects.filter(username__contains=keyword).order_by('-create_time')
|
||||
serializer = UserSerializer(users, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
print(request.data)
|
||||
if not request.data.get('username', None) or not request.data.get('password', None):
|
||||
return APIResponse(code=1, msg='用户名或密码不能为空')
|
||||
users = User.objects.filter(username=request.data['username'])
|
||||
if len(users) > 0:
|
||||
return APIResponse(code=1, msg='该用户名已存在')
|
||||
|
||||
data = request.data.copy()
|
||||
data.update({'password': utils.md5value(request.data['password'])})
|
||||
serializer = UserSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
user = User.objects.get(pk=pk)
|
||||
except User.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
data = request.data.copy()
|
||||
if 'username' in data.keys():
|
||||
del data['username']
|
||||
if 'password' in data.keys():
|
||||
del data['password']
|
||||
serializer = UserSerializer(user, data=data)
|
||||
print(serializer.is_valid())
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def updatePwd(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
user = User.objects.get(pk=pk)
|
||||
except User.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
password = request.data.get('password', None)
|
||||
newPassword1 = request.data.get('newPassword1', None)
|
||||
newPassword2 = request.data.get('newPassword2', None)
|
||||
|
||||
if not password or not newPassword1 or not newPassword2:
|
||||
return APIResponse(code=1, msg='不能为空')
|
||||
|
||||
if user.password != utils.md5value(password):
|
||||
return APIResponse(code=1, msg='原密码不正确')
|
||||
|
||||
if newPassword1 != newPassword2:
|
||||
return APIResponse(code=1, msg='两次密码不一致')
|
||||
|
||||
data = request.data.copy()
|
||||
data.update({'password': utils.md5value(newPassword1)})
|
||||
serializer = UserSerializer(user, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
User.objects.filter(id__in=ids_arr).delete()
|
||||
except User.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,8 @@
|
||||
from myapp.views.index.classification import *
|
||||
from myapp.views.index.tag import *
|
||||
from myapp.views.index.user import *
|
||||
from myapp.views.index.thing import *
|
||||
from myapp.views.index.comment import *
|
||||
from myapp.views.index.order import *
|
||||
from myapp.views.index.notice import *
|
||||
from myapp.views.index.address import *
|
@ -0,0 +1,87 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import TokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Address
|
||||
from myapp.serializers import AddressSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
userId = request.GET.get('userId', -1)
|
||||
|
||||
if userId != -1:
|
||||
addresses = Address.objects.filter(user=userId).order_by('-create_time')
|
||||
serializer = AddressSerializer(addresses, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
return APIResponse(code=1, msg='userId不能为空')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def create(request):
|
||||
|
||||
address_content = request.POST.get('desc', None)
|
||||
user = request.POST.get('user', None)
|
||||
default = request.POST.get('default', False)
|
||||
|
||||
if address_content is None or user is None:
|
||||
return APIResponse(code=1, msg='不能为空')
|
||||
|
||||
if default:
|
||||
# 其他置为false
|
||||
Address.objects.filter(user=user).update(default=False)
|
||||
|
||||
serializer = AddressSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def update(request):
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
addresses = Address.objects.get(pk=pk)
|
||||
except Address.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
user = request.data['user']
|
||||
default = request.data['default']
|
||||
|
||||
if default:
|
||||
# 其他置为false
|
||||
Address.objects.filter(user=user).update(default=False)
|
||||
|
||||
serializer = AddressSerializer(addresses, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def delete(request):
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Address.objects.filter(id__in=ids_arr).delete()
|
||||
except Address.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,104 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Classification, Thing, Tag
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import ThingSerializer, UpdateThingSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
keyword = request.GET.get("keyword", None)
|
||||
c = request.GET.get("c", None)
|
||||
tag = request.GET.get("tag", None)
|
||||
if keyword:
|
||||
things = Thing.objects.filter(title__contains=keyword).order_by('create_time')
|
||||
elif c:
|
||||
classification = Classification.objects.get(pk=c)
|
||||
things = classification.classification_thing.all()
|
||||
elif tag:
|
||||
tag = Tag.objects.get(id=tag)
|
||||
print(tag)
|
||||
things = tag.thing_set.all()
|
||||
else:
|
||||
things = Thing.objects.all().order_by('create_time')
|
||||
|
||||
serializer = ThingSerializer(things, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def detail(request):
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '对象不存在')
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
if request.method == 'GET':
|
||||
serializer = ThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
serializer = ThingSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
except Thing.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = UpdateThingSerializer(thing, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Thing.objects.filter(id__in=ids_arr).delete()
|
||||
except Thing.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
return APIResponse(code=0, msg='删除成功')
|
@ -0,0 +1,80 @@
|
||||
# Create your views here.
|
||||
from django.db import connection
|
||||
from django.db.models import Q
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Classification
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import ClassificationSerializer
|
||||
from myapp.utils import dict_fetchall
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
classifications = Classification.objects.all().order_by('-create_time')
|
||||
serializer = ClassificationSerializer(classifications, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
classification = Classification.objects.filter(title=request.data['title'])
|
||||
if len(classification) > 0:
|
||||
return APIResponse(code=1, msg='该名称已存在')
|
||||
|
||||
serializer = ClassificationSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
print(pk)
|
||||
classification = Classification.objects.get(pk=pk)
|
||||
except Classification.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = ClassificationSerializer(classification, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
# 删除自身和自身的子孩子
|
||||
Classification.objects.filter(Q(id__in=ids_arr)).delete()
|
||||
except Classification.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
return APIResponse(code=0, msg='删除成功')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,87 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes, throttle_classes
|
||||
|
||||
from myapp.auth.MyRateThrottle import MyRateThrottle
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Comment
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import CommentSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
thingId = request.GET.get("thingId", None)
|
||||
order = request.GET.get("order", 'recent')
|
||||
|
||||
if thingId:
|
||||
if order == 'recent':
|
||||
orderBy = '-comment_time'
|
||||
else:
|
||||
orderBy = '-like_count'
|
||||
|
||||
comments = Comment.objects.select_related("thing").filter(thing=thingId).order_by(orderBy)
|
||||
# print(comments)
|
||||
serializer = CommentSerializer(comments, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
return APIResponse(code=1, msg='thingId不能为空')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_my_comment(request):
|
||||
if request.method == 'GET':
|
||||
userId = request.GET.get("userId", None)
|
||||
order = request.GET.get("order", 'recent')
|
||||
|
||||
if userId:
|
||||
if order == 'recent':
|
||||
orderBy = '-comment_time'
|
||||
else:
|
||||
orderBy = '-like_count'
|
||||
|
||||
comments = Comment.objects.select_related("thing").filter(user=userId).order_by(orderBy)
|
||||
# print(comments)
|
||||
serializer = CommentSerializer(comments, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
return APIResponse(code=1, msg='userId不能为空')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@throttle_classes([MyRateThrottle])
|
||||
def create(request):
|
||||
serializer = CommentSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def delete(request):
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Comment.objects.filter(id__in=ids_arr).delete()
|
||||
except Comment.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def like(request):
|
||||
try:
|
||||
commentId = request.GET.get('commentId')
|
||||
comment = Comment.objects.get(pk=commentId)
|
||||
comment.like_count += 1
|
||||
comment.save()
|
||||
except Comment.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='推荐成功')
|
@ -0,0 +1,15 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view
|
||||
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Notice
|
||||
from myapp.serializers import NoticeSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
notices = Notice.objects.all().order_by('-create_time')
|
||||
serializer = NoticeSerializer(notices, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
@ -0,0 +1,85 @@
|
||||
# Create your views here.
|
||||
import datetime
|
||||
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import TokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Order, Thing
|
||||
from myapp.serializers import OrderSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
userId = request.GET.get('userId', -1)
|
||||
orderStatus = request.GET.get('orderStatus', '')
|
||||
|
||||
orders = Order.objects.all().filter(user=userId).filter(status__contains=orderStatus).order_by('-order_time')
|
||||
serializer = OrderSerializer(orders, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def create(request):
|
||||
|
||||
data = request.data.copy()
|
||||
if data['user'] is None or data['thing'] is None or data['count'] is None:
|
||||
return APIResponse(code=1, msg='参数错误')
|
||||
|
||||
# thing = Thing.objects.get(pk=data['thing'])
|
||||
# count = data['count']
|
||||
# if thing.repertory < int(count):
|
||||
# return APIResponse(code=1, msg='库存不足')
|
||||
|
||||
create_time = datetime.datetime.now()
|
||||
data['create_time'] = create_time
|
||||
data['order_number'] = str(utils.get_timestamp())
|
||||
data['status'] = '1'
|
||||
serializer = OrderSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
# 减库存(支付后)
|
||||
# thing.repertory = thing.repertory - int(count)
|
||||
# thing.save()
|
||||
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def cancel_order(request):
|
||||
"""
|
||||
cancal
|
||||
"""
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
order = Order.objects.get(pk=pk)
|
||||
except Order.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
data = {
|
||||
'status': 7
|
||||
}
|
||||
serializer = OrderSerializer(order, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
# 加库存
|
||||
# thingId = request.data['thing']
|
||||
# thing = Thing.objects.get(pk=thingId)
|
||||
# thing.repertory = thing.repertory + 1
|
||||
# thing.save()
|
||||
|
||||
# 加积分
|
||||
# order.user.score = order.user.score + 1
|
||||
# order.user.save()
|
||||
|
||||
return APIResponse(code=0, msg='取消成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
return APIResponse(code=1, msg='更新失败')
|
@ -0,0 +1,76 @@
|
||||
# Create your views here.
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import AdminTokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Tag
|
||||
from myapp.permission.permission import isDemoAdminUser
|
||||
from myapp.serializers import TagSerializer
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
tags = Tag.objects.all().order_by('-create_time')
|
||||
serializer = TagSerializer(tags, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def create(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
tags = Tag.objects.filter(title=request.data['title'])
|
||||
if len(tags) > 0:
|
||||
return APIResponse(code=1, msg='该名称已存在')
|
||||
|
||||
serializer = TagSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def update(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
tags = Tag.objects.get(pk=pk)
|
||||
except Tag.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = TagSerializer(tags, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([AdminTokenAuthtication])
|
||||
def delete(request):
|
||||
if isDemoAdminUser(request):
|
||||
return APIResponse(code=1, msg='演示帐号无法操作')
|
||||
|
||||
try:
|
||||
ids = request.GET.get('ids')
|
||||
ids_arr = ids.split(',')
|
||||
Tag.objects.filter(id__in=ids_arr).delete()
|
||||
except Tag.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
return APIResponse(code=0, msg='删除成功')
|
||||
|
@ -0,0 +1,264 @@
|
||||
# Create your views here.
|
||||
from django.db import connection
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import Classification, Thing, Tag, User
|
||||
from myapp.serializers import ThingSerializer, ClassificationSerializer, ListThingSerializer, DetailThingSerializer, \
|
||||
UpdateThingSerializer
|
||||
from myapp.utils import dict_fetchall
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_api(request):
|
||||
if request.method == 'GET':
|
||||
keyword = request.GET.get("keyword", None)
|
||||
c = request.GET.get("c", None)
|
||||
tag = request.GET.get("tag", None)
|
||||
sort = request.GET.get("sort", 'recent')
|
||||
|
||||
# 排序方式
|
||||
order = '-create_time'
|
||||
if sort == 'recent':
|
||||
order = '-create_time'
|
||||
elif sort == 'hot' or sort == 'recommend':
|
||||
order = '-pv'
|
||||
|
||||
if keyword:
|
||||
things = Thing.objects.filter(title__contains=keyword).filter(status='0').order_by(order)
|
||||
|
||||
# todo
|
||||
elif c and int(c) > -1:
|
||||
ids = [c]
|
||||
|
||||
things = Thing.objects.filter(classification_id__in=ids).filter(status='0').order_by(order)
|
||||
|
||||
elif tag:
|
||||
tag = Tag.objects.get(id=tag)
|
||||
print(tag)
|
||||
things = tag.thing_set.all().filter(status='0').order_by(order)
|
||||
else:
|
||||
things = Thing.objects.all().defer('wish').filter(status='0').order_by(order)
|
||||
|
||||
serializer = ListThingSerializer(things, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def detail(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
thing.pv = thing.pv + 1
|
||||
thing.save()
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '对象不存在')
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
if request.method == 'GET':
|
||||
serializer = ThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def increaseWishCount(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
# wish_count加1
|
||||
thing.wish_count = thing.wish_count + 1
|
||||
thing.save()
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '对象不存在')
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = ThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='操作成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def increaseRecommendCount(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
# recommend_count加1
|
||||
thing.recommend_count = thing.recommend_count + 1
|
||||
thing.save()
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '对象不存在')
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = ThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='操作成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def addWishUser(request):
|
||||
try:
|
||||
username = request.GET.get('username', None)
|
||||
thingId = request.GET.get('thingId', None)
|
||||
|
||||
if username and thingId:
|
||||
user = User.objects.get(username=username)
|
||||
thing = Thing.objects.get(pk=thingId)
|
||||
|
||||
if user not in thing.wish.all():
|
||||
thing.wish.add(user)
|
||||
thing.wish_count += 1
|
||||
thing.save()
|
||||
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '操作失败')
|
||||
return APIResponse(code=1, msg='操作失败')
|
||||
|
||||
serializer = ThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='操作成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def removeWishUser(request):
|
||||
try:
|
||||
username = request.GET.get('username', None)
|
||||
thingId = request.GET.get('thingId', None)
|
||||
|
||||
if username and thingId:
|
||||
user = User.objects.get(username=username)
|
||||
thing = Thing.objects.get(pk=thingId)
|
||||
|
||||
if user in thing.wish.all():
|
||||
thing.wish.remove(user)
|
||||
thing.wish_count -= 1
|
||||
thing.save()
|
||||
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '操作失败')
|
||||
return APIResponse(code=1, msg='操作失败')
|
||||
|
||||
return APIResponse(code=0, msg='操作成功')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def getWishThingList(request):
|
||||
try:
|
||||
username = request.GET.get('username', None)
|
||||
if username:
|
||||
user = User.objects.get(username=username)
|
||||
things = user.wish_things.all()
|
||||
serializer = ListThingSerializer(things, many=True)
|
||||
return APIResponse(code=0, msg='操作成功', data=serializer.data)
|
||||
else:
|
||||
return APIResponse(code=1, msg='username不能为空')
|
||||
|
||||
except Exception as e:
|
||||
utils.log_error(request, '操作失败' + str(e))
|
||||
return APIResponse(code=1, msg='获取心愿单失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def addCollectUser(request):
|
||||
try:
|
||||
username = request.GET.get('username', None)
|
||||
thingId = request.GET.get('thingId', None)
|
||||
|
||||
if username and thingId:
|
||||
user = User.objects.get(username=username)
|
||||
thing = Thing.objects.get(pk=thingId)
|
||||
|
||||
if user not in thing.collect.all():
|
||||
thing.collect.add(user)
|
||||
thing.collect_count += 1
|
||||
thing.save()
|
||||
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '操作失败')
|
||||
return APIResponse(code=1, msg='操作失败')
|
||||
|
||||
serializer = DetailThingSerializer(thing)
|
||||
return APIResponse(code=0, msg='操作成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def removeCollectUser(request):
|
||||
try:
|
||||
username = request.GET.get('username', None)
|
||||
thingId = request.GET.get('thingId', None)
|
||||
|
||||
if username and thingId:
|
||||
user = User.objects.get(username=username)
|
||||
thing = Thing.objects.get(pk=thingId)
|
||||
|
||||
if user in thing.collect.all():
|
||||
thing.collect.remove(user)
|
||||
thing.collect_count -= 1
|
||||
thing.save()
|
||||
|
||||
except Thing.DoesNotExist:
|
||||
utils.log_error(request, '操作失败')
|
||||
return APIResponse(code=1, msg='操作失败')
|
||||
|
||||
return APIResponse(code=0, msg='操作成功')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def getCollectThingList(request):
|
||||
try:
|
||||
username = request.GET.get('username', None)
|
||||
if username:
|
||||
user = User.objects.get(username=username)
|
||||
things = user.collect_things.all()
|
||||
serializer = ListThingSerializer(things, many=True)
|
||||
return APIResponse(code=0, msg='操作成功', data=serializer.data)
|
||||
else:
|
||||
return APIResponse(code=1, msg='username不能为空')
|
||||
|
||||
except Exception as e:
|
||||
utils.log_error(request, '操作失败' + str(e))
|
||||
return APIResponse(code=1, msg='获取收藏失败')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def list_user_thing_api(request):
|
||||
if request.method == 'GET':
|
||||
user = request.GET.get("user", None)
|
||||
|
||||
if user:
|
||||
things = Thing.objects.filter(user=user)
|
||||
serializer = ListThingSerializer(things, many=True)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
return APIResponse(code=1, msg='user不能为空')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def create(request):
|
||||
data = request.data.copy()
|
||||
data['status'] = '1'
|
||||
serializer = ThingSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def update(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
thing = Thing.objects.get(pk=pk)
|
||||
except Thing.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
serializer = UpdateThingSerializer(thing, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
utils.log_error(request, '参数错误')
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
@ -0,0 +1,162 @@
|
||||
# Create your views here.
|
||||
import datetime
|
||||
|
||||
from rest_framework.decorators import api_view, authentication_classes
|
||||
|
||||
from myapp import utils
|
||||
from myapp.auth.authentication import TokenAuthtication
|
||||
from myapp.handler import APIResponse
|
||||
from myapp.models import User
|
||||
from myapp.serializers import UserSerializer, LoginLogSerializer
|
||||
from myapp.utils import md5value
|
||||
|
||||
|
||||
def make_login_log(request):
|
||||
try:
|
||||
username = request.data['username']
|
||||
data = {
|
||||
"username": username,
|
||||
"ip": utils.get_ip(request),
|
||||
"ua": utils.get_ua(request)
|
||||
}
|
||||
serializer = LoginLogSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
else:
|
||||
print(serializer.errors)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def login(request):
|
||||
username = request.data['username']
|
||||
password = utils.md5value(request.data['password'])
|
||||
|
||||
users = User.objects.filter(username=username, password=password)
|
||||
if len(users) > 0:
|
||||
user = users[0]
|
||||
|
||||
if user.role in ['1', '3']:
|
||||
return APIResponse(code=1, msg='该帐号为后台管理员帐号')
|
||||
|
||||
data = {
|
||||
'username': username,
|
||||
'password': password,
|
||||
'token': md5value(username) # 生成令牌
|
||||
}
|
||||
serializer = UserSerializer(user, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
make_login_log(request)
|
||||
return APIResponse(code=0, msg='登录成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='用户名或密码错误')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def register(request):
|
||||
print(request.data)
|
||||
username = request.data.get('username', None)
|
||||
password = request.data.get('password', None)
|
||||
repassword = request.data.get('repassword', None)
|
||||
if not username or not password or not repassword:
|
||||
return APIResponse(code=1, msg='用户名或密码不能为空')
|
||||
if password != repassword:
|
||||
return APIResponse(code=1, msg='密码不一致')
|
||||
users = User.objects.filter(username=username)
|
||||
if len(users) > 0:
|
||||
return APIResponse(code=1, msg='该用户名已存在')
|
||||
|
||||
data = {
|
||||
'username': username,
|
||||
'password': password,
|
||||
'role': 2, # 角色2
|
||||
'status': 0,
|
||||
}
|
||||
data.update({'password': utils.md5value(request.data['password'])})
|
||||
serializer = UserSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='创建成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='创建失败')
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def info(request):
|
||||
if request.method == 'GET':
|
||||
pk = request.GET.get('id', -1)
|
||||
user = User.objects.get(pk=pk)
|
||||
serializer = UserSerializer(user)
|
||||
return APIResponse(code=0, msg='查询成功', data=serializer.data)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def update(request):
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
user = User.objects.get(pk=pk)
|
||||
except User.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
data = request.data.copy()
|
||||
if 'username' in data.keys():
|
||||
del data['username']
|
||||
if 'password' in data.keys():
|
||||
del data['password']
|
||||
if 'role' in data.keys():
|
||||
del data['role']
|
||||
serializer = UserSerializer(user, data=data)
|
||||
print(serializer.is_valid())
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthtication])
|
||||
def updatePwd(request):
|
||||
|
||||
try:
|
||||
pk = request.GET.get('id', -1)
|
||||
user = User.objects.get(pk=pk)
|
||||
except User.DoesNotExist:
|
||||
return APIResponse(code=1, msg='对象不存在')
|
||||
|
||||
print(user.role)
|
||||
if user.role != '2':
|
||||
return APIResponse(code=1, msg='参数非法')
|
||||
|
||||
password = request.data.get('password', None)
|
||||
newPassword1 = request.data.get('newPassword1', None)
|
||||
newPassword2 = request.data.get('newPassword2', None)
|
||||
|
||||
if not password or not newPassword1 or not newPassword2:
|
||||
return APIResponse(code=1, msg='不能为空')
|
||||
|
||||
if user.password != utils.md5value(password):
|
||||
return APIResponse(code=1, msg='原密码不正确')
|
||||
|
||||
if newPassword1 != newPassword2:
|
||||
return APIResponse(code=1, msg='两次密码不一致')
|
||||
|
||||
data = request.data.copy()
|
||||
data.update({'password': utils.md5value(newPassword1)})
|
||||
serializer = UserSerializer(user, data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return APIResponse(code=0, msg='更新成功', data=serializer.data)
|
||||
else:
|
||||
print(serializer.errors)
|
||||
|
||||
return APIResponse(code=1, msg='更新失败')
|
@ -0,0 +1,6 @@
|
||||
Django==3.2.11
|
||||
PyMySQL==1.0.2
|
||||
djangorestframework==3.13.0
|
||||
django-cors-headers==3.13.0
|
||||
Pillow==9.1.1
|
||||
psutil==5.9.4
|
@ -0,0 +1,4 @@
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb()
|
||||
|
||||
print("===============install pymysql==============")
|
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for server project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
|
||||
|
||||
application = get_asgi_application()
|
@ -0,0 +1,150 @@
|
||||
"""
|
||||
Django settings for server project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.1.4.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.1/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.1/ref/settings/
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
# BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-sz@madp0ifx!b)^lg_g!f+5s*w7w_=sjgq-k+erzb%x42$^r!d'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
'corsheaders', # 跨域
|
||||
'myapp'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware', # 跨域配置
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'myapp.middlewares.LogMiddleware.OpLogs'
|
||||
]
|
||||
|
||||
CORS_ORIGIN_ALLOW_ALL = True # 允许跨域
|
||||
|
||||
ROOT_URLCONF = 'server.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'server.wsgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'python_team',
|
||||
'USER': 'root',
|
||||
'PASSWORD': '123456',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '3306',
|
||||
'OPTIONS': {
|
||||
"init_command": "SET foreign_key_checks = 0;",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.1/topics/i18n/
|
||||
|
||||
|
||||
LANGUAGE_CODE = 'zh-hans'
|
||||
|
||||
# 时区
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = False
|
||||
|
||||
# 日期时间格式
|
||||
DATE_FORMAT = 'Y-m-d'
|
||||
DATETIME_FORMAT = 'Y-m-d H:i:s'
|
||||
|
||||
# 上传文件路径
|
||||
# 并在urls.py配置+static
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'upload/')
|
||||
MEDIA_URL = '/upload/'
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.1/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# 跨域配置
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
CORS_ALLOW_HEADERS = '*'
|
@ -0,0 +1,25 @@
|
||||
"""server URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.1/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from server import settings
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('myapp/', include('myapp.urls')),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for server project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
|
||||
|
||||
application = get_wsgi_application()
|
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 218 KiB |
After Width: | Height: | Size: 213 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 784 KiB |
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 37 KiB |
After Width: | Height: | Size: 42 KiB |