def sign_in(request): body = loads(request.body) userid = body.get('userid', '') password = body.get('passWord', '') vailate_id = body.get('vid', '') vailate_str = body.get('vstr', '') try: v = ValidateImg.objects.get(id=vailate_id) if vailate_str.upper() != v.validate_str: return error('03', '验证码错误!') except ValidateImg.DoesNotExist: return error('02', '验证码无效!请刷新重试!') user = authenticate(username=userid, password=password) if user is not None: login(request, user) u = UserInfo.objects.get(user_id=user.username) res_data = serialize(u) res_data['defaultAddr'] = dict() try: def_addr = AddressInfo.objects.get(addr_type='send', is_default='1') res_data['defaultAddr'] = serialize(def_addr) except AddressInfo.DoesNotExist: pass return success(res_data) else: return error('01', '用户名或密码错误!')
def get_user_info(request): user_info = UserInfo.objects.get(user_id=request.user.username) res_data = serialize(user_info) res_data['defaultAddr'] = dict() try: def_addr = AddressInfo.objects.get(addr_type='send', is_default='1') res_data['defaultAddr'] = serialize(def_addr) except AddressInfo.DoesNotExist: pass return success(res_data)
def charge_list(request): body = loads(request.body) user_id = body.get('userId') flow_date = body.get('chargeDate') bgn_date = None end_date = None if flow_date[0] != '': bgn_date = parse_datetime(flow_date[0]) if flow_date[1] != '': end_date = parse_datetime(flow_date[1]) flow_min_amt = body.get('chargeMinAmt', -1) flow_max_amt = body.get('chargeMaxAmt', -1) page_size = int(body.get('pageSize', 10)) page = body.get('page', 1) charges = ChargeInfo.objects.filter( user_id__contains=user_id).order_by('-create_date') if all([bgn_date, end_date]): charges = charges.filter(create_date__gt=bgn_date, create_date__lt=end_date) if flow_min_amt != -1: charges = charges.filter(amt__gt=flow_min_amt) if flow_max_amt != -1: charges = charges.filter(amt__lt=flow_max_amt) res = dict() p = Paginator(charges, page_size) res['total'] = p.count res['pageSize'] = page_size res['pageNum'] = page res['data'] = serialize(p.page(page).object_list) return success(res)
def order_list(request): body = loads(request.body) order_status = body.get('orderStatus', '') order_id = body.get('orderId', '') tid = body.get('tid', '') flow_date = body.get('chargeDate') bgn_date = None end_date = None if flow_date[0] != '': bgn_date = parse_datetime(flow_date[0]) if flow_date[1] != '': end_date = parse_datetime(flow_date[1]) page_size = int(body.get('pageSize', 10)) page = body.get('page', 1) consumes = ConsumeInfo.objects.filter( user_id=request.user.username).order_by('-update_date') if order_status != '': consumes = consumes.filter(status=order_status) if order_id != '': consumes = consumes.filter(order_id=order_id) if tid != '': consumes = consumes.filter(ec_id=tid) if all([bgn_date, end_date]): consumes = consumes.filter(create_date__gt=bgn_date, create_date__lt=end_date) res = dict() p = Paginator(consumes, page_size) res['total'] = p.count res['pageSize'] = page_size res['pageNum'] = page res['data'] = serialize(p.page(page).object_list) return success(res)
def order_list(request): body = loads(request.body) user_id = body.get('userId', '') order_id = body.get('orderId', '') tid = body.get('tid', '') express_type = body.get('expressType', '') flow_date = body.get('orderDate') print_date = body.get('printDate') order_status = body.get('orderStatus', '') bgn_date = None end_date = None print_bgn_date = None print_end_date = None if flow_date[0] != '': bgn_date = parse_datetime(flow_date[0]) if flow_date[1] != '': end_date = parse_datetime(flow_date[1]) if print_date[0] != '': print_bgn_date = parse_datetime(print_date[0]) if print_date[1] != '': print_end_date = parse_datetime(print_date[1]) page_size = int(body.get('pageSize', 10)) page = body.get('page', 1) consumes = ConsumeInfo.objects.filter( user_id__contains=user_id).order_by('-update_date') if order_id != '': consumes = consumes.filter(order_id=order_id) if tid != '': consumes = consumes.filter(ec_id=tid) if order_status != '': consumes = consumes.filter(status=order_status) if express_type is not None and express_type != '': consumes = consumes.filter(express_type=express_type) if all([bgn_date, end_date]): consumes = consumes.filter(create_date__gt=bgn_date, create_date__lt=end_date) if all([print_bgn_date, print_end_date]): consumes = consumes.filter(print_date__isnull=False).filter( print_date__gt=print_bgn_date, print_date__lt=print_end_date) res = dict() p = Paginator(consumes, page_size) res['total'] = p.count res['pageSize'] = page_size res['pageNum'] = page res['data'] = serialize(p.page(page).object_list) for dt in res['data']: addr = AddressInfo.objects.get(id=dt['send_id']) dt['org_name'] = addr.org_name return success(res)
def order_get(request): body = loads(request.body) order_id = body.get('orderId', '') consumes = None if order_id != '': consumes = ConsumeInfo.objects.filter(order_id=order_id) res = dict() try: res['total'] = 0 if consumes is None else consumes.count() res['data'] = serialize(consumes) except: res['total'] = 0 res['data'] = [] return success(res)
def order_list(request): body = loads(request.body) order_status = body.get('orderStatus', '') order_id = body.get('orderId', '') tid = body.get('tid', '') send_id = body.get('id', '') flow_date = body.get('chargeDate') bgn_date = None end_date = None if flow_date[0] != '': bgn_date = parse_datetime(flow_date[0]) if flow_date[1] != '': end_date = parse_datetime(flow_date[1]) page_size = int(body.get('pageSize', 10)) page = body.get('page', 1) users = UserInfo.objects.filter(reference=request.user.username) user_ids = [u.user_id for u in users] today = now() consumes = ConsumeInfo.objects.filter(user_id__in=user_ids, update_date__date=datetime.date( today.year, today.month, today.day)).order_by( 'batch', 'idx', '-update_date') if order_status != '': consumes = consumes.filter(status=order_status) if order_id != '': consumes = consumes.filter(order_id=order_id) if send_id != '': consumes = consumes.filter(send_id=send_id) if tid != '': consumes = consumes.filter(ec_id=tid) if all([bgn_date, end_date]): consumes = consumes.filter(create_date__gt=bgn_date, create_date__lt=end_date) res = dict() p = Paginator(serialize(consumes), page_size) res['total'] = p.count res['pageSize'] = page_size res['pageNum'] = page res['data'] = p.page(page).object_list return success(res)
def user_list(request): body = loads(request.body) user_id = body.get('userId', '') proxy_id = body.get('proxyId', '') page_size = int(body.get('pageSize', 10)) page = body.get('page', 1) users = UserInfo.objects.filter( role='custom', user_id__contains=user_id).order_by('-create_date') if proxy_id != '': users = users.filter(reference=proxy_id) res = dict() p = Paginator(users, page_size) res['total'] = p.count res['pageSize'] = page_size res['pageNum'] = page res['data'] = serialize(p.page(page).object_list) return success(res)
def order_send(request): body = loads(request.body) c = ConsumeInfo.objects.get(id=body.get('id')) addr = AddressInfo.objects.get(id=c.send_id) order_info = { 'tid': c.ec_id, 'goods_name': c.goods_name, 'send_city': c.send_city, 'send_addr': c.send_addr, 'send_county': c.send_county, 'send_prov': c.send_prov, 'send_tel': c.sender_tel, 'send_name': c.sender, 'recv_city': c.receive_city, 'recv_addr': c.receive_addr, 'recv_county': c.receive_county, 'recv_prov': c.receive_prov, 'recv_tel': c.receiver_tel, 'recv_name': c.receiver, } order_res = send_package(order_info, addr.agent_id) if order_res.get('status') == '00' and order_res.get( 'waybill_code') is not None: order_id = order_res.get('waybill_code') status = 'done' if order_res.get('is_printed') else 'pending' c.order_id = order_id c.status = status c.task_id = order_res.get('task_id') c.print_date = order_res.get('print_date') c.save() user = UserInfo.objects.select_for_update().get(user_id=c.user_id) user.bal = float(user.bal) - float(c.amt) user.save() return success(serialize(c)) else: return error(msg=order_res.get('message'))
def address_list(request): res_data = AddressInfo.objects.filter(valid='1').order_by('-update_date') return success(serialize(res_data))
def place_order(request): body = loads(request.body) order_id = '' tid = body.get('tid', '') if tid == '' or tid == 'null': cli = MyRedis.connect('127.0.0.1') tid = cli.incr('ecId', limit=99) tid = format_datetime(now(), YYYYMMDDHHMMSS) + str(tid).zfill(2) recv_addr = parse_address(body.get('receiveAddr', '')) order_info = { 'tid': tid, 'goods_name': body.get('goodsName', '') if body.get('goodsName', '') != '' else '礼品', 'send_city': body.get('sendCity', ''), 'send_addr': body.get('sendAddr', ''), 'send_county': body.get('sendCounty', ''), 'send_prov': body.get('sendProv', ''), 'send_tel': body.get('senderTel', ''), 'send_name': body.get('sender', ''), 'recv_city': recv_addr.get('city', ''), 'recv_addr': recv_addr.get('addr', ''), 'recv_county': recv_addr.get('county', ''), 'recv_prov': recv_addr.get('prov', ''), 'recv_tel': body.get('receiverTel', ''), 'recv_name': body.get('receiver', ''), } status = 'fail' print_date = None task_id = '' order_res = send_package(order_info, body.get('agentId')) # 收件人区县错误,重新解析 if order_res.get('status') == '01' and order_res.get('code') == 9009: clean_addr = address_clean( body.get('receiver', '') + body.get('receiveAddr', '')) if clean_addr.get('status') == '00': recv_addr = clean_addr order_info['recv_city'] = recv_addr.get('city', '') order_info['recv_addr'] = recv_addr.get('addr', '') order_info['recv_county'] = recv_addr.get('county', '') order_info['recv_prov'] = recv_addr.get('prov', '') order_res = send_package(order_info, body.get('agentId')) if order_res.get('status') == '00' and order_res.get( 'waybill_code') is not None: order_id = order_res.get('waybill_code') print_date = order_res.get('print_date') task_id = order_res.get('task_id') status = 'done' if order_res.get('is_printed') else 'pending' user = UserInfo.objects.get(user_id=request.user.username) proxy_share = 0 if user.reference != '': proxy = UserInfo.objects.get(user_id=user.reference) proxy_share = proxy.price if proxy.price > 0 else 0 res = ConsumeInfo.objects.create( user_id=request.user.username, express_type=body.get('expressType', ''), ec_id=tid, order_id=order_id, goods_name=body.get('goodsName', ''), send_addr=body.get('sendAddr', ''), send_id=body.get('sendId', ''), send_prov=body.get('sendProv', ''), send_city=body.get('sendCity', ''), send_county=body.get('sendCounty', ''), receive_addr=recv_addr.get('addr', ''), receive_prov=recv_addr.get('prov', ''), receive_city=recv_addr.get('city', ''), receive_county=recv_addr.get('county', ''), sender=body.get('sender', ''), sender_postid=body.get('senderPostid', ''), sender_tel=body.get('senderTel', ''), receiver=body.get('receiver', ''), receiver_postid=body.get('receiverPostid', ''), receiver_tel=body.get('receiverTel', ''), status=status, amt=body.get('amt'), cost=body.get('cost'), proxy_share=proxy_share, batch=body.get('batch', ''), idx=body.get('idx', ''), print_date=print_date, task_id=task_id) if order_id != '': user = UserInfo.objects.select_for_update().get( user_id=request.user.username) user.bal = float(user.bal) - body.get('amt') user.save() return success(serialize(res))
def charge_list(request): cl = ChargeInfo.objects.filter( user_id=request.user.username).order_by('-create_date') return success(serialize(cl))
def member_list(request): users = UserInfo.objects.filter( reference=request.user.username).order_by('-create_date') return success(serialize(users))
def update_history(request): body = loads(request.body) res_data = UserUpdateHistory.objects.all() if body.get('userId', '') != '': res_data = res_data.filter(user_id=body.get('userId', '')) return success(serialize(res_data))
def notice_list(request): ns = PublicNotice.objects.all().order_by('-create_date') return success(serialize(ns))
def kf_list(request): kfs = QQServiceInfo.objects.all() return success(serialize(kfs))
def express_list(request): orgs = OrgMap.objects.all().order_by('-create_date') return success(serialize(orgs))