Browse Source

Update qywx app

StrayWarrior 5 months ago
parent
commit
1f9ddb3348
2 changed files with 14 additions and 6 deletions
  1. 13 5
      web/qywx/app.py
  2. 1 1
      web/qywx/templates/index.html

+ 13 - 5
web/qywx/app.py

@@ -25,18 +25,24 @@ def index():
         video_id = request.form['video_id']
 
         if video_id:
-            query = """
+            condition = "b.miniprogram_video_id = %s"
+            if staff_id:
+                condition += " AND a.carrier_id = %s"
+            query = f"""
 	            SELECT a.carrier_id, a.remark, b.miniprogram_video_id, b.send_time,
                        DATEDIFF(NOW(), b.send_time) as days
                 FROM we_com_staff a JOIN we_com_message_attachment b
                 ON a.id = b.staff_id
-                WHERE a.carrier_id = %s AND b.miniprogram_video_id = %s ORDER BY send_time DESC
+                WHERE {condition} ORDER BY send_time DESC
             """
             cursor = mysql.get_db().cursor()
-            cursor.execute(query, (staff_id, video_id))
+            if staff_id:
+                cursor.execute(query, (video_id, staff_id))
+            else:
+                cursor.execute(query, (video_id))
             result = cursor.fetchall()
             cursor.close()
-        else:
+        elif staff_id:
             query = """
 	            SELECT a.carrier_id, a.remark, b.miniprogram_video_id, b.send_time,
                        DATEDIFF(NOW(), b.send_time) as days
@@ -48,9 +54,11 @@ def index():
             cursor.execute(query, (staff_id,))
             result = cursor.fetchall()
             cursor.close()
+        else:
+            return render_template('index.html', results=[], form=request.form)
 
         return render_template('index.html', results=result, form=request.form)
-    return render_template('index.html')
+    return render_template('index.html', results=[], form={'staff_id': '', 'video_id': ''})
 
 if __name__ == '__main__':
     app.run(debug=True)

+ 1 - 1
web/qywx/templates/index.html

@@ -12,7 +12,7 @@
           <label class="form-label" for="staff_id">Staff ID:</label>
           <input class="form-control" type="text" id="staff_id"
                                                   name="staff_id"
-                                                  required value="{{ form["staff_id"] }}">
+                                                  value="{{ form["staff_id"] }}">
         </div>
         <div>
           <label class="form-label" for="video_id">Video ID:</label>