|
@@ -10,6 +10,7 @@ from wechat_action import sql_tools
|
|
|
import threading
|
|
|
from web_module import user_action
|
|
|
from sqlalchemy import Table
|
|
|
+import json
|
|
|
import pickle
|
|
|
|
|
|
# TODO:需要添加上supervisor,来维护进程
|
|
@@ -55,22 +56,25 @@ class create_ad_plan_remote(BaseHandler):
|
|
|
|
|
|
class create_ad_plan_local(BaseHandler):
|
|
|
def post(self):
|
|
|
- user_id = self.get_argument("user_id", None)
|
|
|
- ad_plan_typesetting = self.get_argument("plan_typesetting", None)
|
|
|
- ad_plan_name = self.get_argument("plan_name", None)
|
|
|
- print(user_id, ad_plan_typesetting, ad_plan_name)
|
|
|
+ request_dict = json.loads(self.request.body, encoding='utf-8')
|
|
|
+ user_id = request_dict['user_id']
|
|
|
+ ad_plan_list = request_dict['plan_list']
|
|
|
+
|
|
|
+ print(user_id, ad_plan_list)
|
|
|
sql_session = db.DBSession()
|
|
|
- if user_id is None or ad_plan_name is None or ad_plan_typesetting is None:
|
|
|
+ if user_id is None or ad_plan_list is None:
|
|
|
self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
|
|
|
return
|
|
|
# 落地页名字精确到毫秒,默认是全局唯一
|
|
|
# TODO:检查一下plan--内容 有无问题-----和前端确定一下
|
|
|
-
|
|
|
- ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name, 'typesetting': ad_plan_typesetting}
|
|
|
- ad_plan_typesetting_inserte = sql_tools.save_ad_plan_typesetting_info(
|
|
|
- ad_plan_typesetting_info=ad_plan_typesetting_info,
|
|
|
- table_ad_plan_typesetting=ad_plan_typesetting_table)
|
|
|
- sql_session.execute(ad_plan_typesetting_inserte)
|
|
|
+ for _ in ad_plan_list:
|
|
|
+ ad_plan_name = _['title']
|
|
|
+ ad_plan_typesetting_info = {'user_id': user_id, 'name': ad_plan_name,
|
|
|
+ 'typesetting': json.dumps(_, ensure_ascii=False)}
|
|
|
+ ad_plan_typesetting_inserte = sql_tools.save_ad_plan_typesetting_info(
|
|
|
+ ad_plan_typesetting_info=ad_plan_typesetting_info,
|
|
|
+ table_ad_plan_typesetting=ad_plan_typesetting_table)
|
|
|
+ sql_session.execute(ad_plan_typesetting_inserte)
|
|
|
sql_session.commit()
|
|
|
self.write({'status': {'msg': 'success', "RetCode": 200}})
|
|
|
|
|
@@ -86,12 +90,12 @@ class get_ad_plan_local(BaseHandler):
|
|
|
# 落地页名字精确到毫秒,默认是全局唯一
|
|
|
if layout_name:
|
|
|
result = sql_tools.get_plan_typesetting_rough(sql_session=sql_session, user_id=user_id,
|
|
|
- typesetting_name=layout_name)
|
|
|
+ typesetting_name=layout_name)
|
|
|
else:
|
|
|
# TODO:之后修改一下,让其查询效率高点,like效率过低
|
|
|
layout_name = ''
|
|
|
result = sql_tools.get_plan_typesetting_rough(sql_session=sql_session, user_id=user_id,
|
|
|
- typesetting_name=layout_name)
|
|
|
+ typesetting_name=layout_name)
|
|
|
print(result)
|
|
|
result_ = []
|
|
|
for i in range(len(result)):
|
|
@@ -107,6 +111,7 @@ class get_ad_plan_local(BaseHandler):
|
|
|
self.write({'statu': {'msg': 'success', "RetCode": 200},
|
|
|
'local_ad_plan_info': result_})
|
|
|
|
|
|
+
|
|
|
class create_ad_layout_remote(BaseHandler):
|
|
|
# 1.批量创建落地页
|
|
|
def post(self):
|
|
@@ -339,6 +344,7 @@ class delete_ad_layout(BaseHandler):
|
|
|
typesetting_name=layout_name)
|
|
|
self.write({'status': {'msg': 'success', "RetCode": 200}})
|
|
|
|
|
|
+
|
|
|
class delete_ad_plan(BaseHandler):
|
|
|
def get(self):
|
|
|
user_id = self.get_argument('user_id', None)
|
|
@@ -350,9 +356,50 @@ class delete_ad_plan(BaseHandler):
|
|
|
# 落地页名字精确到毫秒,默认是全局唯一
|
|
|
|
|
|
sql_tools.delete_ad_plan_typesetting_vir(sql_session=sql_session, user_id=user_id,
|
|
|
- typesetting_name=plan_name)
|
|
|
+ typesetting_name=plan_name)
|
|
|
self.write({'status': {'msg': 'success', "RetCode": 200}})
|
|
|
|
|
|
+
|
|
|
+class get_ad_wechat_service_name(BaseHandler):
|
|
|
+ # TODO:得到服务商名
|
|
|
+ def get(self):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+class get_ad_wechat_wechat_name(BaseHandler):
|
|
|
+ # TODO:得到公众号名
|
|
|
+ def get(self):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+class get_plan_action_record(BaseHandler):
|
|
|
+ def get(self):
|
|
|
+ user_id = self.get_argument('user_id', None)
|
|
|
+ sql_session = db.DBSession()
|
|
|
+ if user_id is None:
|
|
|
+ self.write({'status': {'msg': 'url parameter error', "RetCode": 400}})
|
|
|
+ return
|
|
|
+ # 落地页名字精确到毫秒,默认是全局唯一
|
|
|
+
|
|
|
+ result = sql_tools.get_plan_record(sql_session=sql_session, user_id=user_id)
|
|
|
+ result_ = []
|
|
|
+ for i in range(len(result)):
|
|
|
+ print(result[i])
|
|
|
+ user_id, name, service_name, wechat_name, create_time, status, typesetting, wechat_id_info = result[i]
|
|
|
+ _ = {}
|
|
|
+ _['typesetting'] = json.loads(typesetting)
|
|
|
+ _['ad_plan_name'] = name
|
|
|
+ _['id'] = i
|
|
|
+ _['create_time'] = create_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ _['service_name'] =service_name
|
|
|
+ _['wechat_name'] = wechat_name
|
|
|
+ _['wechat_id_info'] = wechat_id_info
|
|
|
+ _['status'] = status
|
|
|
+ result_.append(_)
|
|
|
+ self.write({'statu': {'msg': 'success', "RetCode": 200},
|
|
|
+ 'local_ad_plan_info': result_})
|
|
|
+
|
|
|
+
|
|
|
def make_app():
|
|
|
return tornado.web.Application([
|
|
|
("/create_ad_plan_local", create_ad_plan_local),
|
|
@@ -365,7 +412,8 @@ def make_app():
|
|
|
("/create_ad_layout_remote", create_ad_layout_remote),
|
|
|
("/ad_human_info", ad_human_info),
|
|
|
("/ad_wechat_info", ad_wechat_info),
|
|
|
- ("/ad_status", ad_status)
|
|
|
+ ("/ad_status", ad_status),
|
|
|
+ ("/get_plan_action_record", get_plan_action_record)
|
|
|
], debug=True, autoreload=True)
|
|
|
|
|
|
|