コード例 #1
0
ファイル: sdb_user_tixian_02.py プロジェクト: edwordx/kaka
 def handle(self, phone, *args, **options):
     now = datetime.now()
     print "__sync sdb user child two tixian"
     print now
     if phone == "all":
         objs = models.SDBUserRMB.objects.filter(is_auto=True)
         tixian(objs)
     else:
         user = get_user_by_username(phone)
         if not user:
             print "no user", phone
             return
         if hasattr(user, "sdbuserrmb"):
             objs = [user.sdbuserrmb]
             tixian(objs)
     print "ok"
コード例 #2
0
def terminal_change(request):
    user = request.user
    terminals = dbutils.get_sdb_pos(user)
    child_objs = user.children.all()
    users = []
    for child in child_objs:
        info = {
            "title": child.name,
            "value": child.phone
        }
        users.append(info)
    data = {"terminals": json.dumps(terminals), "users": json.dumps(users)}
    if request.method == 'POST':
        phone = request.POST.get("phone")
        terminal = request.POST.get("terminal", "")  # 逗号间隔
        terminal_list = terminal.split(",")
        ok_terminal_list = [t for t in terminal_list if t in terminals]
        child_user = get_user_by_username(phone)
        if child_user:
            objs = SDBPos.objects.filter(user=user).filter(terminal__in=ok_terminal_list)
            objs.update(user=child_user)
        return redirect("terminal_list")
    return render(request, "sdb/terminal_change.html", data)
コード例 #3
0
def set_fenrun(request, child):
    data = {}
    user = request.user
    # 关系判断
    child_user = get_user_by_username(child)
    children = [obj.phone for obj in request.user.children.all()]
    if not child_user or child not in children:
        error = [u"用户不存在或者不是您邀请来的"]
        data.update({"error": error})
        return render(request, "sdb/set_fenrun.html", data)
    # try:
    #     f_child_point = float(child_user.sdbfenrun.point)
    #     f_child_point_yun = float(child_user.sdbfenrun.point_yun)
    # except Exception, e:
    #     print e
    #     error = [u"此用户未设置过分润, 请联系管理员设置"]
    #     data.update({"error": error})
    #     return render(request, "sdb/set_fenrun.html", data)
    # 分润
    if hasattr(user, "sdbfenrun"):
        f_point = float(user.sdbfenrun.point)
        f_point_yun = float(user.sdbfenrun.point_yun)
        f_fanxian = float(user.sdbfenrun.fanxian_rmb)
        point_list = [x[0] for x in SDBFenRun.POINT_CHOICE if float(x[0]) >= f_point]
        point_yun_list = [x[0] for x in SDBFenRun.POINT_CHOICE_YUN if float(x[0]) >= f_point_yun]
        fanxian_list = [x[0] for x in SDBFenRun.FX_RMB_CHOICE if float(x[0]) <= f_fanxian]
        child_fenrun = {
            "point": json.dumps(point_list),
            "point_yun": json.dumps(point_yun_list),
            "fanxian": json.dumps(fanxian_list)
        }
    else:
        point_list = []
        point_yun_list = []
        fanxian_list = []
        child_fenrun = {}
    data.update(child_fenrun)

    if request.method == 'POST':
        # 操作频繁
        key = 'sdb_setfenrun_locked_%s' % (user.id)
        locked = rclient.get(key)
        if locked:
            error = [u"操作太频繁"]
            data.update({"error": error})
            return render(request, "sdb/set_fenrun.html", data)
        else:
            rclient.set(key, True)
            rclient.expire(key, 10)
        # 数值判断
        point = request.POST.get("point")
        point_yun = request.POST.get("point_yun")
        fanxian = request.POST.get("fanxian")
        if point not in point_list or point_yun not in point_yun_list or fanxian not in fanxian_list:
            error = [u"分润点错误"]
            data.update({"error": error})
            return render(request, "sdb/set_fenrun.html", data)
        # 保存改动
        if hasattr(child_user, "sdbfenrun"):
            child_user.sdbfenrun.point = point
            child_user.sdbfenrun.point_yun = point_yun
            child_user.sdbfenrun.fanxian_rmb = fanxian
            child_user.sdbfenrun.save()
        else:
            # 全部继承上级的数据
            SDBFenRun.objects.create(
                user=child_user,
                hardware_point=user.sdbfenrun.hardware_point,
                point=point,
                hardware_point_yun=user.sdbfenrun.hardware_point_yun,
                point_yun=point_yun,
                hardware_point_yin=user.sdbfenrun.hardware_point_yin,
                hardware_point_wx=user.sdbfenrun.hardware_point_wx,
                fanxian_rmb=fanxian,
                profit=user.sdbfenrun.profit,
                tax=user.sdbfenrun.tax,
            )
        return redirect("friend_list")
    return render(request, "sdb/set_fenrun.html", data)