예제 #1
0
def new_member_reward(from_user: int = 1):
    # 拉新邀请奖励
    from_user_id = from_user

    is_new_member = Redis.hget(is_new_member_key, from_user_id)

    if is_new_member:

        logger.info('parentid: is_new_member:' + is_new_member)
        parent_id = is_new_member
        is_sendbalance_redis = is_sendbalance_key + str(parent_id)

        is_send_balance = Redis.sismember(is_sendbalance_redis, from_user_id)

        # not in the set that means the mid not send balance to the parent_id
        if not is_send_balance:

            user = db.session.query(EtMember).filter(
                EtMember.id == parent_id).first()

            logger.info(f'{is_sendbalance_redis}:' + str(is_send_balance))

            drp_send = db.session.query(EtMemberDrp).filter(
                EtMemberDrp.member_id == parent_id,
                EtMemberDrp.from_task_id == 9999_9999,
                EtMemberDrp.from_member_id == from_user_id).first()
            logger.info(drp_send)
            if not drp_send:
                # from_task_id give a max value
                # add drp records
                drp_earning_dict = {
                    "member_id": parent_id,
                    "from_task_id": 9999_9999,
                    "amounts": 1,
                    "from_member_id": from_user_id,
                }
                new_drp_earning = EtMemberDrp(**drp_earning_dict)
                db.session.add(new_drp_earning)

                update_dict = {
                    "balance": 100 + user.balance,
                    "balance_version": int(time.time())
                }

                # update member balance
                db.session.query(EtMember).filter(
                    EtMember.id == user.id, EtMember.balance_version ==
                    user.balance_version).update(update_dict)
            try:
                db.session.commit()

                # update user cache
                Redis.delete(user_center_key + str(user.id))
                Redis.delete(user_info_key + str(user.mobile))
                Redis.delete(user_task_earnings_key + str(user.id))
                Redis.delete(user_appretice_detail_key + str(user.id))
                Redis.delete(user_apprentice_key + str(user.id))

                # update set of the send mids under the parentid
                Redis.sadd(is_sendbalance_redis, from_user_id)

                logger.info(f'from {from_user_id} to {parent_id} 发放邀请奖励成功')

            except Exception as why:

                logger.info(str(why))
예제 #2
0
def handle_verifytaskorder():
    """
    用户提交任务审核接口(交单)
    @todo 审核流程优化
    :return: json
    """
    res = ResMsg()
    req = request.get_json(force=True)
    
    taskorder_id= int(req.get("id", 1))
    status= int(req.get("status", 1))
    verify_log = req.get("verify_log", '')

    account_name= session.get("user_name")

    if not account_name:
        res.update(code=ResponseCode.Success, data={},msg=f'账户{account_name}数据异常')
        return res.data
    
    user = db.session.query(EtAccount.id).filter(EtAccount.name == account_name).first()
    
    if not status:
        res.update(code=ResponseCode.Success, data={},msg='未提交审核数据,操作已经撤销')
        return res.data

    update_dict = {
        "status": status,
        "account_id": user.id,
        "verify_log":verify_log
    }
    task_order= db.session.query(EtTaskOrder.id,EtTaskOrder.task_id,EtTaskOrder.member_id).filter(EtTaskOrder.id == taskorder_id).first()
    
    user = db.session.query(EtMember.id, EtMember.nickname, EtMember.status, EtMember.m_class, EtMember.realname, EtMember.mobile, EtMember.IIUV,EtMember.balance,EtMember.balance_version, EtMember.setreal, EtMember.alipayid).filter(EtMember.id == EtTaskOrder.member_id).first()
    user_info = (dict(zip(user.keys(), user)))

    if task_order:

        db.session.query(EtTaskOrder).filter(EtTaskOrder.id == taskorder_id).update(update_dict)
        task_order_dict= dict(zip(task_order.keys(), task_order))
        
        if status == 4:

            up_sql= f"UPDATE et_tasks SET tasks_fulfil = tasks_fulfil+1 WHERE id ={task_order_dict['task_id']}"
            up_num= db.session.execute(up_sql)

        try:


            db.session.commit()
            res_data= dict()
            
            res_data.update(task_order_dict)
            
            u_task_key=f"user_tasks_:{task_order_dict['member_id']}"
            Redis.delete(u_task_key)

            if status == 5:
                Redis.sadd(f"{task_complete_key}{task_order.task_id}", task_order.member_id)
                
                Redis.sadd(f"{complete_tasks_uid_key}{task_order.member_id}", task_order.task_id)
                
                Redis.expire(f"{task_complete_key}{task_order.task_id}", 60 * 60 * 10)
                res.update(code=ResponseCode.Success, data={}, msg='该单未通过审核')
            
            if status == 4:
                task_limit=20
                counts = db.session.execute(f"SELECT count(id) FROM et_task_orders WHERE status=4 AND member_id={task_order_dict['member_id']}").first()
                
                # update member status 2
                if int(counts[0]) == task_limit:
                    update_dict = {
                        "m_class": 2,
                    }
                    update_dict_ready = helpers.rmnullkeys( update_dict )
                    db.session.query(EtMember).filter(EtMember.id == memberid).update(update_dict_ready)
                    try:
                        db.session.commit()
                        
                        Redis.delete(user_center_key + str(user_info['id']))
                        Redis.delete(user_info_key + str(user_info['mobile']))

                    except Exception as why:
                        res.update(code=ResponseCode.Success, data={}, msg=f'修改失败,请稍后再试{why}')
                        return res.data

                Redis.sadd(f"{task_verifyed_key}{task_order.task_id}", task_order.member_id)
                Redis.expire(f"{task_verifyed_key}{task_order.task_id}", 60 * 60 * 10)
                
                Redis.sadd(f"{task_complete_key}{task_order.task_id}", task_order.member_id)
                Redis.expire(f"{task_complete_key}{task_order.task_id}", 60 * 60 * 10)
                
                calculating_earnings(task_order_dict, task_order.task_id, type_set=1 )
                
                res.update(code=ResponseCode.Success, data=res_data, msg=f'任务订单审核成功,对该用户发放收益')
            
            update_dict_com = {
                "status": 4,
                "account_id": user.id,
                "verify_log":verify_log
            }

            db.session.query(EtTaskOrder).filter(EtTaskOrder.id == taskorder_id).update(update_dict_com)

            return res.data
        except Exception as why:

            res.update(code=ResponseCode.Success, data={},msg=f'任务订单审核失败,{why}')
            return res.data