Ejemplo n.º 1
0
def showorder_forxianchang(request):
    userid = request.POST.get('userid')
    orders = Xianchangorder.objects.filter(order_userid=userid,
                                           ispay=1).order_by('-id')
    wait = []
    get = []
    if orders.exists:
        for order in orders:
            obj = to_dict(order)
            ordernum = obj['order_num']
            details = Xianchangorder_detail.objects.filter(ordernum=ordernum)
            detail_list = []
            for detail in details:
                inner = {}
                inner['goodname'] = detail.goodname
                inner['goodnum'] = detail.goodnum
                inner['goodprice'] = detail.goodprice
                detail_list.append(inner)
            obj['detail_list'] = detail_list
            sum = 0
            for the in detail_list:
                sum += the['goodnum'] * the['goodprice']
            obj['coupon'] = sum - obj['order_true_pay']
            obj['sum'] = sum
            if obj['isget'] == 0:
                wait.append(obj)
            else:
                get.append(obj)
    return JsonResponse({'waitorder': wait, 'got': get})
Ejemplo n.º 2
0
def indexswiper(request):
    swipers = Indexswiper.objects.all()
    swiper_data = [to_dict(i) for i in swipers]
    #热门活动
    activeties = Activety.objects.order_by('-endtime')[:2]
    activety_data = []
    for i in activeties:
        obj = {}
        obj['img'] = i.img
        obj['activetyid'] = i.id
        obj['endtime'] = str(i.endtime)[:19].replace('T',' ')
        obj['title'] = i.name
        activety_data.append(obj)
    return JsonResponse({'status': 1, 'swiper_data': swiper_data,'activety_data':activety_data})
Ejemplo n.º 3
0
def orderdetail(request):
    orderid = int(request.GET.get('id'))
    order = Xianchangorder.objects.get(id=orderid)
    data = to_dict(order)
    goodsdetails = order.xianchangorder_detail_set.all()
    goodsdetail_list = []
    for i in goodsdetails:
        obj = {}
        obj['goodid'] = i.goodid
        obj['goodnum'] = i.goodnum
        obj['goodname'] = i.goodname
        obj['goodprice'] = i.goodprice
        goodsdetail_list.append(obj)
    data['goodsdetail'] = goodsdetail_list
    return JsonResponse({'status': 1, 'data': data})
Ejemplo n.º 4
0
def showtheorder(request):
    id = request.POST.get('id')
    print("id>>>", id)
    theorder = Zhoubianorders.objects.get(id=id)
    type = theorder.type
    oneorder = {}
    goodcar_detail = theorder.zhoubianorder_detail_set.all()
    goods_detail_list = []
    payNum = 0
    for j in goodcar_detail:
        innerobj = {}
        innerobj['goodid'] = j.goodid
        thegood = Zhoubian.objects.get(id=j.goodid)
        innerobj['goodimg'] = j.goodimg
        innerobj['goodname'] = j.goodname
        innerobj['goodnum'] = j.goodnum
        payNum += j.goodnum
        innerobj['goodprice'] = j.goodprice
        innerobj['goodtype'] = thegood.color + thegood.size
        goods_detail_list.append(innerobj)
    oneorder['goodcar'] = goods_detail_list
    oneorder['orderstatu'] = type
    oneorder['payNum'] = payNum
    oneorder['payMoney'] = theorder.order_true_pay
    oneorder['id'] = theorder.id
    oneorder['order_num'] = theorder.order_num
    oneorder['creat_time'] = theorder.order_start_time
    oneorder['pay_time'] = theorder.pay_time
    oneorder['leavewords'] = theorder.note_cont
    location_id = theorder.location_id
    location = Locationnote.objects.get(id=location_id)
    oneorder['location'] = to_dict(location)
    oneorder['postage'] = theorder.postage_fee
    oneorder['reduce'] = theorder.coupon_reduce
    if type == 0:
        starttime = datetime.datetime.strptime(theorder.order_start_time,
                                               '%Y-%m-%d %H:%M:%S')
        oneorder['logistics'] = ''
        if time.time() - starttime.timestamp() > 1800:
            theorder.type = 3
            theorder.save()
            oneorder['expiry_time'] = ''
        else:
            oneorder['expiry_time'] = str(starttime +
                                          datetime.timedelta(minutes=30))
    elif type == 1:
        oneorder['expiry_time'] = ''
        if theorder.logistics != '':
            logistics = json.loads(theorder.logistics)
            route_list = logistics
        # 物流查询,
        else:
            xml = query_xml(theorder.waybill_id)
            route_list = queryorder(xml)[1:]
            print(route_list)
        oneorder['logistics'] = [{
            'accept_time': '',
            'accept_address': '',
            'remark': '待顺丰网点揽件'
        }] if len(route_list) == 0 else route_list
        if oneorder['logistics'][-1]['accept_time'] != '':
            opcode = []
            for theopcode in route_list:
                opcode.append(theopcode['opcode'])
            if '80' in opcode:
                receivetime = route_list[-1]['accept_time']
                now = time.time()
                receive = datetime.datetime.strptime(
                    receivetime, '%Y-%m-%d %H:%M:%S').timestamp()
                #存储物流信息
                theorder.logistics = json.dumps(route_list)
                theorder.receivetime = receivetime
                if now - receive > 604800:
                    theorder.type = 2
                theorder.save()
    elif type == 2:
        oneorder['expiry_time'] = ''
        logistics = json.loads(theorder.logistics)
        oneorder['logistics'] = logistics
    else:
        oneorder['expiry_time'] = ''
        oneorder['logistics'] = ''
    return JsonResponse({'status': 1, 'orderdata': oneorder})
Ejemplo n.º 5
0
def theactivety(request):
    userid = request.POST.get('userid')
    activetyid = request.POST.get('activetyid')
    #是否已经关注
    if userid is not None:
        isjoin = Join.objects.filter(Q(userid =userid)&Q(activety_id = activetyid))
        isjoin = True if isjoin.exists() else False
    else:
        isjoin = False
    activety = Activety.objects.get(id=activetyid)
    endtime = activety.endtime
    if activety.getprize_nickname != '':
        if activety.getprize_nickname != 'noneprize_foractivety':
            getprize_nickname = activety.getprize_nickname.split(',')
        else:
            getprize_nickname = 'noneprize_foractivety'
        isend = True
    else:
        endstamp = floor(time.mktime(endtime.timetuple()))
        now = ceil(time.time())
        isend = False if now - endstamp < 0 else  True
        if isend is True:
            if activety.getprize_num != 0:
                joins = Join.objects.filter(activety_id=activetyid)
                user_list = [(i.userid,i.username) for i in joins]
                if user_list:
                    getprize = random.sample(user_list,k=activety.getprize_num)
                    getprize_nickname = []
                    getprize_userid =[]
                    for i in getprize:
                        getprize_nickname.append(i[1])
                        getprize_userid.append(i[0])
                    activety.getprize_nickname = ','.join(getprize_nickname)
                    activety.getprize_userid = ','.join(getprize_userid)
                    activety.save()
                else:
                    activety.getprize_nickname = 'noneprize_foractivety'
                    activety.save()
            else:
                activety.getprize_nickname = 'noneprize_foractivety'
                activety.save()
        else:
            getprize_nickname =[]
    thedata = {}
    adtab = {}
    adtab['logurl']= activety.logurl
    adtab['weburl']= activety.weburl
    adtab['appid'] = activety.appid
    adtab['apppage']  = activety.apppage
    adtab['navigatetotype']= 1 if activety.weburl == '' else 0
    thedata['adtab'] = adtab
    activety_joinnum= activety.joinnum
    thedata['img'] = activety.img
    thedata['id'] = activety.id
    thedata['name'] = activety.name
    thedata['support'] = activety.support
    thedata['endtime'] = str(endtime)[:19].replace('T',' ')
    thedata['joinnum'] = activety_joinnum
    thedata['explain'] = activety.explain
    thedata['isvote'] = activety.isvote
    thedata['zhuli_target'] = activety.zhuli_target
    thedata['isjoin'] = isjoin
    thedata['isend'] = isend
    colorlist = ['#86B7F9','#FF95B3','#FF96B9','#8ED673','#BF9DFE']
    #获奖名单
    getprize_nickname_send = []
    if getprize_nickname != 'noneprize_foractivety':
        for i in getprize_nickname:
            obj = {}
            obj['name'] = i
            obj['color'] = random.choice(colorlist)
            getprize_nickname_send.append(obj)
            thedata['getprize_nickname'] = getprize_nickname_send
    else:
        thedata['getprize_nickname'] = []
    join_names = activety.join_set.order_by('-id').all()
    cache.set('join_name'+ activetyid,join_names,10)
    # 参与人列表
    thedata['join_more'] = 1 if len(join_names)>16 else 0
    join_detail = []
    if join_names.exists():
        for i in join_names[:16]:
            obj = {}
            obj['username'] = i.username
            obj['time'] = str(i.time)
            obj['color'] = random.choice(colorlist)
            join_detail.insert(0,obj)
    thedata['join_detail'] = join_detail
    #投票数据列表
    vote_list = []
    if activety.isvote:
        votes = Vote.objects.filter(activety_id = activetyid)
        for vote in votes:
            obj = {}
            chooseid = vote.id
            choosename = vote.choose
            num = vote.num
            percent = "0%" if activety_joinnum==0 else'%.2f%%'%(num/activety_joinnum*100)
            obj['chooseid'] =chooseid
            obj['choosename'] = choosename
            obj['num'] = num
            obj['percent'] = percent
            vote_list.append(obj)
    thedata['vote_detail'] = vote_list
    #添加城市的选项
    if activetyid == '2':
        choose = Addvote.objects.filter(userid=userid)
        if  choose.exists():
            choosename = choose[0].choose
            num = Addvote.objects.filter(choose=choosename).count()
            basenum = 100
            thedata['choosedata'] = {'choose':choosename,
                                     'num':num,
                                     'basenum':basenum}
            thedata['add_choose'] = True
            thedata['isaddchoose'] = True
            if num >= basenum:
                Vote.objects.get_or_create(activety=activety,num=num,choose=choosename)
        else:
            thedata['add_choose'] = True
            thedata['choosedata'] = {}
            thedata['isaddchoose'] = False
    else:
        thedata['add_choose'] = False
        thedata['choosedata'] = {}
        thedata['isaddchoose'] = False
        #助力数据列表
    zhuli_list= []
    if activety.zhuli_target:
        zhuli_targets = Zhouli_stage.objects.filter(activety_id = activetyid)
        for zhuli_target in  zhuli_targets:
            stage= to_dict(zhuli_target)
            stage['percent'] = str(stage['percent']) + '%'
            zhuli_list.append(stage)
    thedata['zhuli_list'] = zhuli_list
    thedata['zhuli_percent'] = '%.2f%%'%((activety.joinnum / activety.zhuli_target)*100) if activety.zhuli_target !=0 else ''
    if activety.joinnum >= activety.zhuli_target:
        thedata['zhuli_percent'] = '100%'
    return JsonResponse({'status':1,'data':thedata})