Example #1
0
 def put(self):
     # 抢单动作
     logger.info("[D] [功能 客户经理抢单动作]")
     req = self.validate_data
     logger_req(req)
     manager = request.current_user
     facesign_code = req["facesign_code"]
     facesign = TbFaceSignUser.query.filter_by(code=facesign_code,
                                               status=0).first()
     if not facesign:
         logger.info("[T] [The facesign does not exist]")
         return Msg.MANAGER_FACESIGN_NOT_EXIST, -200
     if redis.zadd("support_facesign_order", facesign.update_time,
                   facesign.code) == 0:
         logger.info("[T] [The redis.zadd is fail]")
         return Msg.MANAGER_FACESIGN_NOT_EXIST, -200
     if facesign.status != 0:
         logger.info("[T] [Check status is not 0 ]")
         return Msg.MANAGER_FACESIGN_NOT_EXIST, -200
     try:
         facesign.manager_code = manager.code
         facesign.manager_name = manager.name
         facesign.status = 1
         facesign.update_time = utc_timestamp()
         db.session.commit()
         logger.info(
             "[T] [Update tb_manager where manager_code= {}]".format(
                 manager.code))
     except Exception as e:
         logger.info("[T] {}".format(str(e)))
         return str(e)
     redis.zremrangebyscore("support_facesign_order", 0, utc_timestamp())
     return get_data(facesign, TbFaceSignUser, exclude=["id", "extend"])
Example #2
0
    def get(self):
        # 刷新商户经理获取抢单列表
        logger.info("[D] [功能 刷新商户经理获取抢单列表]")
        req = self.validate_data
        logger_req(req)
        manager = request.current_user
        refresh_face_sign(manager.code)
        # 筛选条件
        time_start = req.get("time_start", "")
        time_end = req.get("time_end", "")
        address_code = req.get("address_code", "")
        orderby_time = req.get("orderby_time", "")

        a = TbFaceSignUser.merchant_code == manager.merchant_code  # 商户编码
        b = (TbFaceSignUser.order_time >= time_start
             ) if time_start else True  # 预约起始起始时间
        c = (TbFaceSignUser.order_time <= time_end
             ) if time_end else True  # 预约结束时间
        d = (TbFaceSignUser.order_address_code.op("regexp")(
            r"^" +
            re_address_code(address_code))) if address_code else True  # 省市区筛选
        e = TbFaceSignUser.status == 0  # 状态为待面签条件
        f = (TbFaceSignUser.update_time) if orderby_time == "1" else (
            -TbFaceSignUser.update_time)  # 时间正反序
        ke = [a, b, c, d, e]
        facesign = TbFaceSignUser.query.filter(*ke).order_by(f)

        return get_data(
            facesign,
            TbFaceSignUser,
            exclude=["id", "manager_code", "manager_name", "extend"])
Example #3
0
 def get(self):
     # 获取商户产品开关列表
     merchant_code = request.args.get("merchant_code")
     if merchant_code:
         merchant = TbMerchant.query.filter_by(code=merchant_code).first()
         if not merchant:
             return Msg.MERCHANT_NOT_EXIST, 400
         production = TbProduction.query.filter_by(
             merchant_code=merchant_code)
         return get_data(production, TbProduction, exclude=self.exclude)
     return "缺少必须参数", 400
Example #4
0
 def put(self):
     # 修改产品开关
     merchant_code = request.json.pop("merchant_code", None)
     production_code = request.json.pop("production_code", None)
     production_flag = request.json.pop("production_flag", None)
     request.json.pop("id", None)
     production = TbProduction.query.filter(
         TbProduction.code == production_code,
         TbMerchant.code == merchant_code).first()
     if not production:
         return Msg.PRODUCTION_NOT_EXIST, 400
     if not isinstance(production_flag, bool):
         return "参数错误", 400
     production.status = production_flag
     # 删除 redis 产品的缓存
     appid_key = "tb_production:merchant_code:{}".format(
         production.merchant_code)
     redis_delete(appid_key)
     db.session.commit()
     return get_data(production, TbProduction, exclude=self.exclude)
Example #5
0
    def get(self):
        # 获取商户面签单信息,抢单之后的信息
        logger.info("[D] [功能 获取商户面签单信息]")
        req = self.validate_data
        logger_req(req)
        manager = request.current_user
        refresh_face_sign(manager.code)
        status = status_to_list(req.get("status"))
        username_phone = req.get("username_phone", "")
        select_all = req.get("select_all", "")
        time_start = req.get("time_start", "")
        time_end = req.get("time_end", "")
        orderby_time = req.get("orderby_time", "")
        try:
            u_p = int(username_phone)
        except ValueError:
            u_p = username_phone
        if isinstance(u_p, int):
            search = (TbFaceSignUser.phone.contains(username_phone))
        else:
            search = (TbFaceSignUser.username.contains(username_phone))
        # 筛选条件
        a = TbFaceSignUser.merchant_code == manager.merchant_code  # 只查当前商户条件
        b = (search) if username_phone else True  # C端用户姓名模糊查询
        c = (TbFaceSignUser.status.in_(status)) if status else (
            TbFaceSignUser.status != 0)  # 状态status 选择查询
        d = (TbFaceSignUser.manager_code
             == manager.code) if select_all != "1" else True  # 是否全查询:1为全查询
        e = (TbFaceSignUser.order_time >= time_start
             ) if time_start else True  # 预约起始起始时间
        f = (TbFaceSignUser.order_time <= time_end
             ) if time_end else True  # 预约结束时间
        h = (TbFaceSignUser.update_time) if orderby_time == "1" else (
            -TbFaceSignUser.update_time)  # 时间正反序
        ke = [a, b, c, d, e, f]

        facesign = TbFaceSignUser.query.filter(*ke).order_by(h)
        return get_data(facesign, TbFaceSignUser, exclude=["id", "extend"])
Example #6
0
 def get(self):
     # 获取商户经理
     logger.info("[D] [功能 获取商户经理信息]")
     req = self.validate_data
     logger_req(req)
     if req.get("page_size") == -1:
         all = TbManager.query.filter_by(merchant_code=req["merchant_code"], is_delete=False)\
             .order_by(-TbManager.create_time).count()
         managers = TbManager.query.filter_by(merchant_code=req["merchant_code"], is_delete=False)\
             .order_by(-TbManager.create_time)\
             .paginate(page=req["page"], per_page=all)
     else:
         a = (TbManager.phone
              == req.get("phone")) if req.get("phone") else True
         b = (TbManager.name.contains(
             req.get("name"))) if req.get("name") else True
         c = TbManager.is_delete == False
         d = TbManager.merchant_code == req["merchant_code"]
         kw = [a, b, c, d]
         try:
             managers = TbManager.query.filter(*kw)\
                 .order_by(-TbManager.create_time)\
                 .paginate(page=req["page"], per_page=req["page_size"])
         except Exception as e:
             logger.info(str(e))
             return str(e), 400
     try:
         data = [{
             "name":
             i.name,
             "phone":
             i.phone,
             "sex":
             i.sex,
             "address":
             i.address,
             "merchant_code":
             i.merchant_code,
             "create_time":
             str(i.create_time),
             "update_time":
             str(i.update_time),
             "creator":
             i.creator,
             "status":
             i.status,
             "id_card":
             i.id_card,
             "id_img":
             i.id_img,
             "head_img":
             i.head_img,
             "id_img_back":
             i.id_img_back,
             "code":
             i.code,
             "be_served_merchant":
             get_data(instance=TbBeServedMerchant.query.filter_by(
                 manager_code=i.code),
                      model=TbBeServedMerchant,
                      only=["merchant_code"],
                      pure=True),
             "working_address":
             get_data(instance=TbManagerWorkingAddress.query.filter_by(
                 manager_code=i.code),
                      model=TbManagerWorkingAddress,
                      exclude=["id"],
                      pure=True)
         } for i in managers.items]
     except Exception as e:
         logger.info(str(e))
         return str(e), 400
     return {
         "total": managers.total,
         "pages": managers.pages,
         "page": managers.page,
         "page_size": managers.per_page,
         "results": data
     }