E-commerce back office from January 25, 2020 to January 31, 2020

Time:2021-2-24

Background of E-commerce mall

1、 Project construction

1.1 prepare the front page

1.2 background preparation environment

  • 1. Install Django restful framework
  • 2. Install Django CORS headers to realize cross region
  • 3. Install djangorestframework JWT to keep the state

1.3. Establish project

  • Establish sub application background and register

2、 User login

2.1 interface analysis

  • Interface path

    • meiduo_admin/authorizations/
  • Request method

    • post
  • Request parameters

    • username,userpassword

      • JSON format
  • Return parameters

    • username,userpasword token

      • json

2.2 business logic

  • 1. Using the verification method of Django module, you need to change it to be able to verify the user name and mobile phone

  • 2. The view can directly use the method obtain provided by Django rest framework JWT_ jwt_ token

  • 3. Need to rewrite the view return value

    • 1. Modify the return value

      def jwt_ response_ payload_ handler(token, user=None, request=None):
    • 2. Configure a new return value method in configuration

      JWT configuration

      JWT_AUTH = {
          'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
          'JWT_RESPONSE_PAYLOAD_HANDLER': 'meiduo_admin.utils.jwt_response.jwt_response_payload_handler',
      }

      3、 Data statistics

3.1 total number of users

  • Interface analysis

    • route

      • /meiduo_admin/statistical/total_count/
    • method

      • GET
    • parameter

      • Passing JWT token data through request header
    • Return value JSON

      {

      "Count": "total number of users,",

      }

  • Business logic

    • 1. Get the current date datetime

    • 2. Get the total number of users

    • 3. Return data

    • 4. View inherits apiview

    • 5. Back end implementation

      class UserTotalCountView(APIView):

      3.2 total number of daily users

  • Interface analysis

    • route

      • /meiduo_admin/statistical/day_increment/
    • method

      • get
    • parameter

      • Passing JWT token data through request header
    • Return value

      {

      "Count": "number of new users,",

      }

  • Business logic

    • 1. Get the current date datetime

    • 2. Get the total number of daily users

    • 3. Return data

    • 4. View inherits apiview

    • 5. Background implementation

      class UserDayCountView(APIView):

      3.3 total number of active users

  • Interface analysis

    • route

      • /meiduo_admin/statistical/day_active/
    • method

      • get
    • parameter

      • Passing JWT token data through request header
    • Return value

      {

      "Count": "number of active users,",

      }

  • Business logic

    • 1. Get the current date datetime

    • 2. Get the total number of daily active users

    • 3. Return data

    • 4. View inherits apiview

    • 5. Background implementation

      class UserActiveCountView(APIView):

      3.4 total orders

  • Interface analysis

    • route

      • /meiduo_admin/statistical/day_orders/
    • method

      • get
    • parameter

      • token
    • Return value

      {

      "Count": "number of single users,",

      }

  • Business logic

    • 1. Get the current date datetime

    • 2. Get the total number of daily order users

    • 3. Return data

    • 4. View inherits apiview

    • 5. Background implementation

      class UserOrderCountView(APIView):

      Statistics of additional users in March and may

  • Interface analysis

    • route

      • /meiduo_admin/statistical/month_increment/
    • method

      • get
    • parameter

      • token
    • Return value

      [

      {
  • Business logic

    • 1. Get the current date datetime

    • 2. Get datetime one month ago

    • 2. Get the total number of daily users

    • 3. Return data

    • 4. View inherits apiview

    • 5. Background implementation

      class UserMonthCountView(APIView):

      3.6 visit statistics of commodity classification visit day

  • Interface analysis

    • route

      • /meiduo_admin/statistical/goods_day_views/
    • method

      • get
    • parameter

      • token
    • Return value

      [

      {
  • Business logic

    • 1. Get the current date datetime

    • 2. Construct and use commodity access statistics table to build serializer

      class GoodsSerializer(serializers.ModelSerializer):

      #Specifies the return category name
    • 3. Serialize data

    • 3. Return data

    • 4. View inherits apiview

    • 5. Background implementation

      class GoodsDayView(APIView):

      4、 User management

4.1 obtaining query users

  • Interface analysis

    • route

      • /meiduo_ Admin / users /? Keyword = < search content > & page = < page number > & PageSize = < page size >
    • method

      • get
    • parameter

      • token
    • Return value

      {
  • Business logic

    • 1. Get keywords to get all user data

      #Rewrite get_ The queryset method returns different query results according to whether the front end passes the keyword value
    • 2. Pagination

      class UserPageNum(PageNumberPagination):
    • 3. Build a serializer

      class UserSerializer(serializers.ModelSerializer):
      
          class Meta:
              model=User
              fields=('id','username','mobile','email')
    • 4. Return data

    • 5. Background implementation

      class UserView(ListAPIView):

      4.2 new users

  • Interface analysis

    • route

      • /meiduo_admin/users/
    • method

      • post
    • parameter

      {
      • token
    • Return value

      {
  • Business logic

    • 1. Create a serializer

      class UserAddSerializer( serializers.ModelSerializer ):
    • 2. Rewrite the Create method

    • 3. Rewrite to get the serializer method

    • 3. Background implementation

      class UserView(ListCreateAPIView):

      5、 Commodity management

5.1 specification sheet management

  • obtain

    • 1. Organize the data into the format required by the front end, and use the serializer
      {
  • newly added

    • 1. Need to get the simple information of SPU product, ID and name
    • 2. Add one more simple method to the view set
    • 3. The route specifies a new path, corresponding to the simple method
  • modify

    • Implementation using modelviewset
  • delete

    • Implementation using modelviewset

5.2 commodity picture management

  • obtain

    • 1. Organize the data into the format required by the front end, and use nested serializer
  • newly added

    • 1. Need to get simple information of SKU product, ID and name
    • 2. Add one more simple method to the view set
    • 3. The route specifies a new path, corresponding to the simple method
    • 4. Rewrite the serializer create method to save the image to the data storage system FDFS
    • 5. Update the static page asynchronously
  • modify

    • 1. Rewrite the serializer update method to save the image to the data storage system FDFS
    • 2. Update static page asynchronously
  • delete

    • Implementation using modelviewset

5.3 SKU management

  • obtain

    • 1. Organize the data into the format required by the front end, use nested serializer, and rewrite get_ Queryset method to determine whether to pass the keyword query parameter
  • newly added

    • 1. Get the three-level classification information and specify the new route
    • 2. Get the name data of SPU table and specify the new route
    • 3. Get SPU product specification information and specify new route
    • 4. Rewrite the Create method of the serializer, design two table operations, and use atomic transaction operations to ensure that the data is correct
    • 5. Update the static page asynchronously
  • modify

    • 1. Rewrite the update method of the serializer, design two table operations, and use atomic transaction operations to ensure that the data is correct
    • 2. Update static page asynchronously
  • delete

    • Implementation using modelviewset

5.4 the logic of other tables is not bad

6、 Order management

6.1 access

  • 1. Rewrite get_ Queryset method to determine whether to pass the keyword query parameter
  • 2. Rewrite get_ serializer_ Class, judge whether to obtain single or multiple data, use different serializers to organize the data into the format required by the front end, and use nested serializers

6.2 modification

  • 1. Order status can only be modified
  • 2. Set up a new way to deal with it

7、 System management

7.1 authority management

  • obtain

    • 1. Use Django built-in model class to generate serializer and return front-end data
  • newly added

    • 1. Get the list data of permission type, and use new key to route
  • modify

    • Implementation using modelviewset
  • delete

    • Implementation using modelviewset

7.2 user group management

  • obtain

    • 1. Use Django built-in model class to generate serializer and return front-end data
  • newly added

    • 1. Get the data of permission table and process the new key route
  • modify

    • Implementation using modelviewset
  • delete

    • Implementation using modelviewset

7.3 administrator management

  • obtain

    • 1. User model class to generate the serializer (password setting is write only), and return the front-end data
  • newly added

    • 1. Get packet table data, new key routing processing
    • 2. Rewrite the Create method of the serializer and store it in the password format
  • modify

    • 1. Rewrite the update method of the serializer and store it in password format
  • delete

    • Implementation using modelviewset

This work adoptsCC agreementReprint must indicate the author and the link of this article