Ejemplo n.º 1
0
def update_image():
    user_id = auth_helper()
    task_id = request.args.get("task_id")
    if not task_id:
        return jsonify(error="任务ID不能为空"), 400
    task = Task.get_by_id(task_id=task_id)
    if not task:
        return jsonify(error="该任务不存在"), 400
    if task.creator_id != user_id:
        return jsonify(error="权限不足"), 403
    flag, msg = upload_file(f"task-{task_id}")
    if not flag:
        return jsonify(error=msg), 400
    task.image = msg
    db.session.commit()
    return jsonify(data=msg), 200
Ejemplo n.º 2
0
def finish_participate():   # 乙方确认完成任务
    user_id = auth_helper()
    form = request.get_json(True, True)
    task_id = form.get('task_id')
    if not task_id:
        return jsonify(error='请指定任务'), 400
    task = Task.get_by_id(task_id)
    if not task:
        return jsonify(error='任务不存在'), 400
    participate = Participate.get(user_id=user_id, task_id=task_id)
    if not participate or participate[0].status == ParticipateStatus.APPLYING.value:
        return jsonify(error='未参与该任务'), 400
    participate = participate[0]
    if participate.status == ParticipateStatus.FINISH.value:
        return jsonify(error='已完成该任务')
    participate.status = ParticipateStatus.CHECK.value
    db.session.commit()
    # 发消息告知甲方 乙方完成任务
    user = User.get_by_id(user_id)
    message = Message(user_id=task.creator_id, content=f'用户 {user.username} 已完成任务 {task.title}, 请进行验收',
                      msg_type=MessageType.FINISH.value, send_from=user.id)
    db.session.add(message)
    db.session.commit()
    return jsonify(data='确认成功'), 200