def message_count(): if not current_user.is_authenticated: return rest.success() count = ChatMessage.objects(take_user=current_user.id, is_read=False).count() content = dict( count=count ) return rest.success(data=content)
def register(): if current_user.is_authenticated: return redirect(request.args.get('next') or url_for('customer.index')) if request.method == 'POST': data = request.form if session['images_code'] != data['code'].lower(): return rest.params_error('验证码错误') for i in list(data.keys()): if not data[i]: return rest.params_error('请确认填写信息') if len(data['mobile']) != 11: return rest.params_error('手机号长度不正确') if User.objects(mobile=data['mobile']).count(): return rest.params_error('手机号已经被注册') if not (6 <= len(data['password']) <= 12): return rest.params_error('密码长度6-12位') c = Customer() c.mobile = data.get('mobile', '') c.username = data.get('username', '') c.sex = data.get('sex', '') c.password = data.get('password', 'abc123') c.save() return rest.success('注册成功!') return rt('admin_main/register.html', a=1)
def rate(tid): if request.method == 'POST': data = request.form c: CustomerTask = CustomerTask.objects(user=current_user.id, id=tid).first() c.is_rate = True c.jishu_score = float(data.get('jishu_score')[0]) c.time_score = float(data.get('time_score')[0]) c.attitude_score = float(data.get('attitude_score')[0]) c.rate_desc = data.get('rate_desc') c.save() c.join_user.worker.ref_score(c.jishu_score, c.time_score, c.attitude_score) return rest.success('评价成功')
def login(): if request.method == 'POST': form = request.form c: User = User.objects( Q(mobile=form.get('mobile')) | Q(mobile=form.get('username'))).first() if c and c.verify_password(form.get('password')): login_user(c) return rest.success(data={ "url": request.args.get('next') or url_for('customer_main.index') }) return rest.params_error('请检查账号密码') return rt('admin_main/login.html')
def task_add(): if request.method == 'POST': data = request.form c = CustomerTask() c.title = data['title'] c.work_type = [ObjectId(i) for i in data.getlist('work_type[]')] c.work_time = float(data['work_time']) c.price = float(data['price']) c.desc = data['desc'] c.images = data.getlist('images[]') c.user = current_user.id c.save() return rest.success(data={"url": url_for(".task_detail")}) wts = WorkerType.objects.all() content = {"wts": wts} return rt('customer_main/task_add.html', **content)
def message_get(uid): u = User.objects(id=uid).first() messages = ChatMessage.objects(send_user=u.id, take_user=current_user.id, is_read=False).order_by('id').all() data = [] for msg in messages: msg: ChatMessage data.append({ "msg": msg.content, 'date': msg.date }) messages.update(is_read=True) return rest.success(data={ "messages": data })
def dashboard_task(): if request.method == 'POST': data = request.form if WorkerType.objects(name=data['text']).count(): return rest.params_error('工种已经存在') WorkerType(name=data['text']).save() return rest.success('添加成功') page = request.args.get('page', 1, type=int) status: str = request.args.get('status') query = {} if status: query['status'] = int(status) if status.isdigit() else -1000 task = CustomerTask.objects(**query).paginate(page, per_page=20) content = { 'task': task, } return rt('admin_main/dashboard_task.html', **content)
def register_worker(): if request.method == "POST": data = request.form if session['images_code'] != data['code'].lower(): return rest.params_error('验证码错误') if not data.get('work_type'): return rest.params_error('请选择工种') if not data.get('work_year'): return rest.params_error('请填写工龄') worker = Worker.objects(user=current_user.id).first() if not worker: worker = Worker() worker.user = current_user.id worker.work_type = [ObjectId(i) for i in data.getlist('work_type')] worker.work_year = float(data.get('work_year')) worker.save() return rest.success('注册成功,请等待审核') wts = WorkerType.objects.all() content = {"wts": wts, "user": current_user} return rt('admin_main/register_worker.html', **content)
def task_jieyue(tid): c = CustomerTask.objects(user=current_user.id, id=tid).first() if c: c.jieyue(request.form.get('text')) return rest.success('操作成功')
def task_success(tid): c = CustomerTask.objects(user=current_user.id, id=tid).first() if c: c.success() return rest.success('操作成功')
def task_verify(tid, status): worker = CustomerTask.objects(id=tid).first() worker.status = int(status) worker.save() return rest.success('操作成功')
def worker_verify(wid, status): worker = Worker.objects(id=wid).first() worker.status = int(status) worker.save() return rest.success('操作成功')