예제 #1
0
def spreadperfreCard():
    # print(request.method)
    if request.method == "POST":
        id = request.form["id"]
        print(request.form)
        checkId = redis_store.get("{}_spreadCard".format(id)).decode("utf-8")
        if checkId != "True":
            return jsonify({"code": 5000})
        else:
            try:
                # print(id)
                card1 = int(request.form["card1"])
                card2 = int(request.form["card2"])
                card3 = int(request.form["card3"])
                _spreadCard(id, card1, 800)
                _spreadCard(id, card2, 500)
                _spreadCard(id, card3, 300)
            except Exception as e:
                print(e)
            return redirect(url_for("admin.getperfreCard"))

    else:
        id = request.args.get("id")
        redis_store.set("{}_spreadCard".format(id), "True", ex=30000)
        return render_template("admin/manage/spreadPreferCard.html", id=id)
예제 #2
0
def check_spread():
    if request.path == url_for("admin.spreadSalary"):
        id = request.args.get("id")
        # print(id, redis_store.get("spreadId"))
        if id and id == redis_store.get("spreadId").decode("utf-8"):
            # 发放工资
            return redirect(url_for("admin.index"))
예제 #3
0
def setSalarys(id):
    if request.method == "POST":
        account = request.form["account"]
        # print(request.form)
        salaryNum = request.form["salaryNum"]
        tag = redis_store.get("salaryset_{}".format(id))
        # print(tag)
        assert account == id
        if tag:
            user = User.query.filter(User.account == id).first()
            salaryStandLink = user.salaryStandLink.first()
            if salaryStandLink:
                salaryStandLink.salaryNum = salaryNum
                salaryStandLink.userId = id
            else:
                salaryStandLink = SalaryStand()
                salaryStandLink.salaryNum = salaryNum
                salaryStandLink.userId = id
            db.session.add(salaryStandLink)
            db.session.commit()
        return redirect(url_for("admin.manageSalary"))
        # if id:
        #     user = User.query.filter(User.account=id).first()
        #     salaryInfo = user.salaryStandLink.first()
        #     if salaryInfo:
        #         salaryInfo.salaryNum =
        pass
    else:
        user = User.query.filter(User.account == id).first()
        if user:
            redis_store.set("salaryset_{}".format(user.account), "tag", ex=30000)
            return render_template("admin/manage/setSalary2.html", user=user)
예제 #4
0
def activedUser():
    user = g.user
    if request.method == "POST":
        try:
            formdata = request.form
            # print(formdata)
            username = formdata["username"]
            sex = formdata["sex"]
            age = formdata["age"]
            addr = formdata["province"] +"  " + formdata["city"]
            tele = formdata["telephone"]
            email = formdata["email"]
            # 验证效验码
            checkNum = formdata["checkNum"]
            print(user.account)
            check = redis_store.get("email_{}".format(g.user.account))
            print(check.decode("utf-8"), checkNum)
            if check.decode("utf-8") != checkNum:
                return redirect(url_for("manage.activedUser"))
            photo = request.files.get("upload")
            fileend = photo.filename.split(".")[-1]
            if fileend not in ["jpg", "png", "jpeg"]:
                return redirect(url_for("manage.activedUser"))
        except Exception as e:
            print(e)
            return redirect(url_for("manage.activedUser"))
            
        try:
            if username and sex and age and addr and tele and email:
                buser = User.query.filter_by(account=user.account).first()
                buser.username = username
                buser.sex = User.SEX.get(sex, None)
                # buser.addr = addr
                buser.telephone = tele
                buser.email = email
                buser.age=age
                # 检查是否可以激活
                buser.addr = addr
                buser.actived = True
                # buser.confirmCode
                basepath = os.path.abspath(os.path.curdir)
                photopath = os.path.join(
                    basepath,
                    "backend/static/img/{}-{}.jpg".format(
                        user.account, random.randrange(1, 100000)
                    ),
                )
                photo.save(photopath)
                rsp = generate(photopath)
                print(rsp)
                if rsp.get("code")== 200:
                    headPhotoPath=rsp.get("path")
                    os.remove(photopath)
                else:
                    return jsonify({"code": 500})
                buser.head_photo=headPhotoPath
                db.session.add(buser)
                db.session.commit()
        except Exception as e:
            print(e)
            return redirect(url_for("manage.userInfo"))
        finally:
            return redirect(url_for("manage.userInfo"))
    else:
        if g.user.actived == True:
            return redirect(url_for("manage.userInfo"))
        province = list(set([addr.province for addr in UserAddr.query.all()]))
        return render_template("manage/user/actived.html", user=user, provinces=province)
예제 #5
0
def stop():
    if request.method == "POST":
        id = request.args.get("id")
        preferCardId = request.form["prefercard"]
        cardId = None
        if preferCardId != "no":
            cardId = preferCardId.split("_")[0]
        print(id, redis_store.get("{}_payid".format(g.user.account)))
        if id != redis_store.get("{}_payid".format(
                g.user.account)).decode("utf-8"):
            return redirect(url_for("auth.logout"))
        # goto 处理支付功能
        order = Service.query.filter_by(id=id).first()
        # 如果支付
        if request.form["salary"] != redis_store.get("{}_pay".format(
                g.user.account)).decode("utf-8"):
            print("支付不成功")
        # 支付后订单状态
        order.orderType = 32
        # 资金流
        econ = ecomoStream()
        md = md5()
        md.update("{}{}".format(datetime.utcnow(),
                                random.randrange(1000, 10000)).encode("utf-8"))
        # 检查是否使用优惠卡,支付逻辑
        salary = redis_store.get(f"{g.user.account}_pay")
        if salary:
            salary = int(salary.decode("utf-8"))
        else:
            return redis_store(url_for("user.doing"))
        if not cardId is None:
            card = perferCard.query.filter_by(cardId=cardId).first()
            if _check_expire(card.createTime, card.expireTime):
                usercard = card.userlink.first()
                usercard.cardType = True
                db.session.add(usercard)
                db.session.commit()
                salary = order.salary - card.cardNum
        # 添加资金流动流
        rsp = producerPay(account=g.user.account, salaNum=salary)
        print(dir(rsp))
        econId = md.hexdigest()
        econ.createInfo(id=econId,
                        econNum=salary,
                        serviceType=order.info.serviceType)
        econ.econNum = redis_store.get(f"{g.user.account}_pay").decode("utf-8")
        # econ.serviceType =
        order.salary = salary
        db.session.add(econ)
        db.session.commit()

        # 如果未支付
        # order.orderType=16
        # order.salary=0
        # formId = request.form["account"]
        return redirect(url_for("user.doing"))
    else:
        order = []
        user = g.user.baseuserLink.first()
        id = request.args.get("id")
        orderList = [
            order.id for order in user.orderLink.filter_by(orderType=4).all()
        ]
        if id not in orderList:
            return redirect(url_for("auth.logout"))
        else:
            order = Service.query.filter_by(id=id).first()
            curTime = datetime.utcnow()
            print(curTime)
            startTime = order.startTime
            # print(curTime-startTime)
            serviceTime = curTime - startTime
            paySalary = _getSalary(serviceTime, order.salary)
            redis_store.setex("{}_pay".format(order.baseuser.userAc), 300,
                              paySalary)
            redis_store.set("{}_payid".format(order.baseuser.userAc), order.id)
            cards = [
                card for card in user.cardLink.all()
                if card.cardType == False and _check_expire(
                    card.perfercard.createTime, card.perfercard.expireTime)
            ]
            print(cards)
            return render_template(
                "user/stop.html",
                order=order,
                serviceTime=serviceTime,
                curTime=str(curTime).split(".")[0],
                salary=paySalary,
                cards=cards,
            )