def index(): resjson.action_code = 10 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() data = MeStaticMethodsService.detail(uid) # 未读消息数 unread_count = UserStaticMethodsService.unread_count(uid) data['unread_count'] = unread_count # 封装下个人信息 data['user'] = { 'uid': data['uid'], 'nickname': data['nickname'], 'avatar': data['avatar'] } return resjson.print_json(0, u'ok', data)
def collect(): """ 我的收藏列表 """ resjson.action_code = 17 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() args = request.args p = toint(args.get('p', '1')) ps = toint(args.get('ps', '10')) if p <= 0 or ps <= 0: return resjson.print_json(resjson.PARAM_ERROR) params = {'uid': uid, 'p': p, 'ps': ps} data = LikeStaticMethodsService.likes(params) return resjson.print_json(0, u'ok', {'likes': data['likes']})
def image(): """上传图片""" resjson.action_code = 10 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) wtf_form = UploadImageForm() if not wtf_form.validate_on_submit(): for key, value in wtf_form.errors.items(): msg = value[0] return resjson.print_json(10, msg) try: fus = FileUploadService() image = fus.save_storage(wtf_form.image.data, wtf_form.prefix.data) except Exception as e: return resjson.print_json(10, _(u'上传失败,请检查云存储配置')) return resjson.print_json(0, u'ok', {'image': image})
def action(): """ 点赞或取消点赞 """ resjson.action_code = 10 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) args = request.args like_type = toint(args.get('like_type', 0)) ttype = toint(args.get('ttype', 0)) tid = toint(args.get('tid', 0)) ls = LikeService(like_type, ttype, tid) if not ls.check(): return resjson.print_json(11, ls.msg) ls.action() ls.commit() return resjson.print_json(0, u'ok', {'action_code': ls.action_code})
def comment_detail(og_id): """手机站 - 查看评价""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() order_goods = OrderGoods.query.get(og_id) good = Goods.query.get(order_goods.goods_id) comment = Comment.query.filter( Comment.comment_id == order_goods.comment_id).filter( Comment.uid == uid).first() if not comment: return redirect(url_for('mobile.index.pagenotfound')) return render_template('mobile/order/comment_detail.html.j2', order_goods=order_goods, comment=comment, good=good)
def detail(): """ 交易明细详情 """ resjson.action_code = 11 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() fd_id = toint(request.args.get('fd_id', '0')) if fd_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) detail = FundsDetail.query.filter(FundsDetail.fd_id == fd_id).filter( FundsDetail.uid == uid).first() if not detail: return resjson.print_json(10, _(u'交易明细不存在')) return resjson.print_json(0, u'ok', {'detail': detail})
def collect(): """pc站 - 我的收藏""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login_qrcode')) uid = get_uid() params = request.args.to_dict() params['uid'] = uid data = LikeStaticMethodsService.likes(params, True) goods = {} for like in data["likes"]: good = db.session.query( Goods.goods_price, Goods.market_price).filter(Goods.goods_id == like.tid).first() goods[like.tid] = good data['goods'] = goods return render_template('pc/me/collect.html.j2', **data)
def address(ua_id): """手机站 - 添加收货地址""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() address = {} if ua_id > 0: address = UserAddress.query.filter(UserAddress.ua_id == ua_id).filter( UserAddress.uid == uid).first() if not address: return redirect(url_for('mobile.index.pagenotfound')) wtf_form = AddressForm() return render_template('mobile/me/address.html.j2', ua_id=ua_id, address=address, wtf_form=wtf_form)
def index(): """订单列表页""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login_qrcode')) uid = get_uid() data = OrderStaticMethodsService.orders(uid, request.args.to_dict(), True) # pc端订单列表支持,支付、详情、售后3个指令,其余指令排除,即排除[2,3,4,5,6] if data.get("orders"): excel_code = [2, 3, 4, 5, 6] action_code = data.get('codes') for order in data.get("orders"): temp = set(action_code[order.order_id]) - set(excel_code) action_code[order.order_id] = list(temp) data['tab_status'] = request.args.get('tab_status', '0') return render_template('pc/order/index.html.j2', **data)
def messages(): """ 消息列表 """ resjson.action_code = 16 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() args = request.args p = toint(args.get('p', '1')) ps = toint(args.get('ps', '10')) if p <= 0 or ps <= 0: return resjson.print_json(resjson.PARAM_ERROR) params = {'uid': uid, 'p': p, 'ps': ps} data = MessageStaticMethodsService.messages(params) UserStaticMethodsService.reset_last_time(uid, 1) return resjson.print_json(0, u'ok', {'messages': data['messages']})
def track(): """查询物流""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() args = request.args order_id = toint(args.get('order_id', 0)) order = Order.query.\ filter(Order.order_id == order_id).\ filter(Order.uid == uid).first() order_address = OrderAddress.query.\ filter(OrderAddress.order_id == order_id).first() shipping = None express_msg = '' express_data = [] if order and order.shipping_status == 2: try: trackservice = TrackServiceFactory.get_trackservice() _express_data = trackservice.track(order.shipping_id, order.shipping_sn, order_address.mobile) express_data = _express_data shipping = trackservice.shipping express_msg = 'ok' except ShippingException as e: express_msg = e.msg data = { 'express_msg': express_msg, 'express_data': express_data, 'order': order, 'shipping': shipping } return render_template('mobile/order/track.html.j2', **data)
def comment_detail(): """手机站 - 查看评价""" resjson.action_code = 22 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() og_id = toint(request.args.get('og_id', '0')) if og_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) order_goods = OrderGoods.query.get(og_id) good = Goods.query.get(order_goods.goods_id) comment = Comment.query.filter( Comment.comment_id == order_goods.comment_id).filter(Comment.uid == uid).first() if not comment: return resjson.print_json(10, u'评价不存在') data = {'order_goods': order_goods, 'comment': comment, 'good': good} return resjson.print_json(0, u'ok', data)
def deliver(): """确认收货""" resjson.action_code = 15 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() args = request.args order_id = toint(args.get('order_id', 0)) if order_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) ods = OrderDeliverService(order_id, uid) try: ods.deliver() except OrderException as e: msg = u'%s' % e.msg return resjson.print_json(10, msg) return resjson.print_json(0, u'ok')
def apply(): """申请售后""" resjson.action_code = 10 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() wtf_form = AfterSalesForm() if not wtf_form.validate_on_submit(): for key, value in wtf_form.errors.items(): msg = value[0] return resjson.print_json(11, msg) og_id = toint(request.form.get('og_id', '0')) order_id = toint(request.form.get('order_id', '0')) quantity = toint(request.form.get('quantity', '0')) aftersales_type = toint(request.form.get('aftersales_type', '0')) deliver_status = toint(request.form.get('deliver_status', '0')) content = request.form.get('content', '').strip() img_data = request.form.get('img_data', '[]').strip() data = { 'uid': uid, 'order_id': order_id, 'og_id': og_id, 'quantity': quantity, 'aftersales_type': aftersales_type, 'deliver_status': deliver_status, 'content': content, 'img_data': img_data } ascs = AfterSalesCreateService(**data) if not ascs.check(): return resjson.print_json(12, ascs.msg) aftersales_id = ascs.create() return resjson.print_json(0, u'ok', {'aftersales_id': aftersales_id})
def track(): """ 售后服务流水跟踪 """ resjson.action_code = 15 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() aftersales_id = toint(request.args.get('aftersales_id', '0')) if aftersales_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) aftersales = Aftersales.query.filter(Aftersales.aftersales_id == aftersales_id).\ filter(Aftersales.uid == uid).first() if not aftersales: return resjson.print_json(resjson.SYSTEM_PAGE_NOT_FOUND) logs = AftersalesLogs.query.filter(AftersalesLogs.aftersales_id == aftersales.aftersales_id).\ order_by(AftersalesLogs.al_id.desc()).all() return resjson.print_json(0, u'ok', {'logs': logs})
def return_goods(): """寄回商品""" resjson.action_code = 12 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() aftersales_id = toint(request.form.get('aftersales_id', '0')) return_shipping_sn = request.form.get('return_shipping_sn', '').strip() current_time = current_timestamp() if aftersales_id <= 0 or return_shipping_sn == '': return resjson.print_json(resjson.PARAM_ERROR) aftersales = Aftersales.query.\ filter(Aftersales.aftersales_id == aftersales_id).\ filter(Aftersales.uid == uid).first() if not aftersales: return resjson.print_json(10, _(u'售后不存在')) if aftersales.aftersales_type not in [2, 3]: return resjson.print_json(11, _(u'售后类型错误')) if aftersales.return_status != 1: return resjson.print_json(12, _(u'寄回状态错误')) data = {'return_shipping_sn': return_shipping_sn, 'return_status': 2} model_update(aftersales, data) content = _(u'快递单号:%s,我们收到退货/换货商品后,需要1-3个工作日处理,请耐心等待。' % return_shipping_sn) AfterSalesStaticMethodsService.add_log(aftersales_id, content, 6, current_time, commit=True) return resjson.print_json(0, u'ok')
def create_comment(og_id): """手机站 - 发表评价""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() order_goods = OrderGoods.query.get(og_id) order = Order.query.filter(Order.order_id == order_goods.order_id).filter( Order.uid == uid).first() if not order: return redirect(url_for('mobile.index.pagenotfound')) if order_goods.comment_id > 0: return redirect(url_for('mobile.index.servererror')) wtf_form = CommentOrderGoodsForm() return render_template('mobile/order/create_comment.html.j2', order_goods=order_goods, wtf_form=wtf_form)
def index(): """ 我的钱包 """ resjson.action_code = 10 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() args = request.args p = toint(args.get('p', '1')) ps = toint(args.get('ps', '10')) if p <= 0 or ps <= 0: return resjson.print_json(resjson.PARAM_ERROR) funds = Funds.query.filter(Funds.uid == uid).first() _data = FundsStaticMethodsService.details(uid, request.args.to_dict()) data = {'funds': funds, 'details': _data['details']} log_info(data) return resjson.print_json(0, _(u'ok'), data)
def checkout(): """确认订单""" resjson.action_code = 16 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() args = request.args order_id = toint(args.get('order_id', 0)) # 已有订单,获取订单数据 if order_id > 0: data = CartStaticMethodsService.pay_page(order_id, uid, 'api') if not data[0]: return resjson.print_json(11, data[1]) return resjson.print_json(0, u'ok', data[2]) buy_now = toint(args.get('buy_now', 0)) goods_id = toint(args.get('goods_id', 0)) carts_id = args.get('carts_id', '') if buy_now not in [0, 1]: return resjson.print_json(resjson.PARAM_ERROR) # 立即购买 if buy_now == 1 and goods_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) # 购物车购买 if buy_now == 0 and carts_id == '': return resjson.print_json(resjson.PARAM_ERROR) # 结算页面 data = CartStaticMethodsService.checkout_page(uid, 'api') if not data[0]: return resjson.print_json(12, data[1]) return resjson.print_json(0, u'ok', data[2])
def paging(): """加载分页""" if not check_login(): session['weixin_login_url'] = url_for('mobile.aftersales.root') return redirect(url_for('api.weixin.login')) uid = get_uid() params = request.args.to_dict() params['uid'] = uid _data = AfterSalesStaticMethodsService.aftersales(params) aftersales_status_text = {} for aftersale in _data['aftersales']: status_text, action_code = AfterSalesStaticMethodsService.aftersale_status_text_and_action_code( aftersale) aftersales_status_text[aftersale.aftersales_id] = status_text data = { 'aftersales': _data['aftersales'], 'aftersales_status_text': aftersales_status_text } return render_template('mobile/aftersales/paging.html.j2', **data)
def address_change(oa_id): """手机站 - 未付款修改地址""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() order_address = OrderAddress.query.get(oa_id) if not order_address: return redirect(url_for('mobile.index.pagenotfound')) order = Order.query.\ filter(Order.order_id == order_address.order_id).\ filter(Order.uid == uid).first() if not order: return redirect(url_for('mobile.index.pagenotfound')) if order.pay_status != 1: return redirect(url_for('mobile.index.servererror')) return render_template('mobile/order/address-change.html.j2', order_address=order_address)
def update(): """更新订单""" resjson.action_code = 13 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() form = request.form order_id = toint(form.get('order_id', '0')) ua_id = toint(form.get('ua_id', '0')) shipping_id = toint(form.get('shipping_id', '0')) coupon_id = toint(form.get('coupon_id', '0')) ous = OrderUpdateService(uid, order_id, ua_id, shipping_id, coupon_id) try: ous.update() except OrderException as e: msg = u"%s" % e.msg return resjson.print_json(11, msg) ous.update() return resjson.print_json(0, u'ok')
def cancel(): """取消订单""" resjson.action_code = 14 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() args = request.args order_id = toint(args.get('order_id', 0)) cancel_desc = args.get('cancel_desc', '').strip() if order_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) ocs = OrderCancelService(order_id, uid, cancel_desc) try: ocs.cancel() except OrderException as e: msg = u'%s' % e.msg return resjson.print_json(11, msg) return resjson.print_json(0, u'ok')
def recharge(): """手机站 - 钱包充值""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() order_id = toint(request.args.get('order_id', '0')) recharge_amount = 0 pay_success_url = '' # 订单付款 if order_id > 0: # 检查 order = Order.query.filter(Order.order_id == order_id).filter( Order.uid == uid).first() if not order: return redirect(url_for('mobile.index.pagenotfound')) recharge_amount = order.pay_amount pay_success_url = url_for('mobile.pay.success', order_id=order_id) openid = '' opentime = session.get('jsapi_weixin_opentime', 0) current_time = current_timestamp() is_expire_opentime = opentime < (current_time - 30 * 60) if not is_expire_opentime: openid = session.get('jsapi_weixin_openid', '') data = { 'order_id': order_id, 'recharge_amount': recharge_amount, 'openid': openid, 'pay_success_url': pay_success_url } return render_template('mobile/wallet/recharge.html.j2', **data)
def checkout(): """结算""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() args = request.args order_id = toint(args.get('order_id', '0')) is_pay_now = toint(args.get('is_pay_now', '1')) # 订单付款页面 if order_id > 0: ret, msg, data, url = CartStaticMethodsService.pay_page( order_id, uid, 'mobile') if not ret: return redirect(url) data['openid'] = '' opentime = session.get('jsapi_weixin_opentime', 0) current_time = current_timestamp() is_expire_opentime = opentime < (current_time - 30 * 60) if not is_expire_opentime: data['openid'] = session.get('jsapi_weixin_openid', '') data['pay_success_url'] = url_for('mobile.pay.success', order_id=order_id) data['is_pay_now'] = is_pay_now return render_template('mobile/cart/pay.html.j2', **data) # 结算页面 ret, msg, data, url = CartStaticMethodsService.checkout_page(uid, 'mobile') if not ret: return redirect(url) return render_template('mobile/cart/checkout.html.j2', **data)
def update_address(): """更新订单收货地址""" resjson.action_code = 20 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() wtf_form = OrderAddressForm() current_time = current_timestamp() if not wtf_form.validate_on_submit(): for key, value in wtf_form.errors.items(): msg = value[0] return resjson.print_json(11, msg) order_address = OrderAddress.query.get(wtf_form.oa_id.data) if not order_address: return resjson.print_json(12, _(u'订单地址不存在')) order = Order.query.\ filter(Order.order_id == order_address.order_id).\ filter(Order.uid == uid).first() if not order: return resjson.print_json(13, _(u'订单不存在')) if order.pay_status != 1: return resjson.print_json(14, _(u'未付款订单才可以修改地址')) data = {'name': wtf_form.name.data, 'mobile': wtf_form.mobile.data, 'province': wtf_form.province.data, 'city': wtf_form.city.data, 'district': wtf_form.district.data, 'address': wtf_form.address.data, 'update_time': current_time} model_update(order_address, data, commit=True) return resjson.print_json(0, u'ok')
def root(): """pc站 - 售后服务记录""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login_qrcode')) uid = get_uid() params = request.args.to_dict() params['uid'] = uid _data = AfterSalesStaticMethodsService.aftersales(params, True) aftersales_status_text = {} for aftersale in _data['aftersales']: status_text, action_code = AfterSalesStaticMethodsService.aftersale_status_text_and_action_code( aftersale) aftersales_status_text[aftersale.aftersales_id] = status_text data = { 'aftersales': _data['aftersales'], 'aftersales_status_text': aftersales_status_text, 'pagination': _data['pagination'] } return render_template('pc/aftersales/index.html.j2', **data)
def apply(): """手机站 - 申请售后""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() order_id = toint(request.args.get('order_id', '0')) og_id = toint(request.args.get('og_id', '0')) if order_id <= 0 and og_id <= 0: return redirect(url_for('mobile.index.pagenotfound')) wtf_form = AfterSalesForm() if order_id > 0: ascs = AfterSalesCreateService(uid, order_id=order_id, og_id=0, quantity=1, aftersales_type=1, deliver_status=1) ret = ascs._check_order() if not ret: return redirect(url_for('mobile.index.pagenotfound')) data = { 'wtf_form': wtf_form, 'order_id': order_id, 'goods_data': ascs.goods_data, 'refunds_amount': ascs.refunds_amount } return render_template('mobile/aftersales/apply_order.html.j2', **data) else: aftersales_type = 2 ascs = AfterSalesCreateService(uid, order_id=0, og_id=og_id, quantity=1, aftersales_type=aftersales_type, deliver_status=1) ret = ascs._check_order_goods() if not ret: if ascs.msg != u'超过有效退款时间': return redirect(url_for('mobile.index.pagenotfound')) aftersales_type = 3 ascs = AfterSalesCreateService(uid, order_id=0, og_id=og_id, quantity=1, aftersales_type=aftersales_type, deliver_status=1) ret = ascs._check_order_goods() if not ret: return redirect(url_for('mobile.index.pagenotfound')) data = { 'wtf_form': wtf_form, 'goods_data': ascs.goods_data, 'refunds_amount': ascs.refunds_amount, 'order_address': ascs.order_address, 'aftersales_type': aftersales_type } return render_template('mobile/aftersales/apply.html.j2', **data)
def apply_info(): """ 申请售后 """ resjson.action_code = 16 if not check_login(): return resjson.print_json(resjson.NOT_LOGIN) uid = get_uid() order_id = toint(request.args.get('order_id', '0')) og_id = toint(request.args.get('og_id', '0')) if order_id <= 0 and og_id <= 0: return resjson.print_json(resjson.PARAM_ERROR) if order_id > 0: ascs = AfterSalesCreateService(uid, order_id=order_id, og_id=0, quantity=1, aftersales_type=1, deliver_status=1) ret = ascs._check_order() if not ret: return resjson.print_json(resjson.SYSTEM_PAGE_NOT_FOUND) data = { 'order_id': order_id, 'goods_data': ascs.goods_data, 'refunds_amount': ascs.refunds_amount } return resjson.print_json(0, u'ok', data) else: aftersales_type = 2 ascs = AfterSalesCreateService(uid, order_id=0, og_id=og_id, quantity=1, aftersales_type=aftersales_type, deliver_status=1) ret = ascs._check_order_goods() if not ret: if ascs.msg != u'超过有效退款时间': return resjson.print_json(resjson.SYSTEM_PAGE_NOT_FOUND) aftersales_type = 3 ascs = AfterSalesCreateService(uid, order_id=0, og_id=og_id, quantity=1, aftersales_type=aftersales_type, deliver_status=1) ret = ascs._check_order_goods() if not ret: return resjson.print_json(resjson.SYSTEM_PAGE_NOT_FOUND) data = { 'goods_data': ascs.goods_data, 'refunds_amount': ascs.refunds_amount, 'order_address': ascs.order_address, 'aftersales_type': aftersales_type } return resjson.print_json(0, u'ok', data)
def apply_step1(): """pc站 - 申请售后服务-第一步""" if not check_login(): session['weixin_login_url'] = request.url return redirect(url_for('api.weixin.login')) uid = get_uid() order_id = int(request.args.to_dict().get('order_id', '0')) og_id = int(request.args.to_dict().get('og_id', '0')) if order_id <= 0 and og_id <= 0: return redirect(url_for('pc.index.pagenotfound')) wtf_form = AfterSalesForm() # order_id大于0则整单操作,否则指定商品操作 if order_id > 0: ascs = AfterSalesCreateService(uid, order_id=order_id, og_id=0, quantity=1, aftersales_type=1, deliver_status=1) ret = ascs._check_order() if not ret: if ascs.msg == u'售后状态错误' and ascs.aftersales: return redirect( url_for('pc.aftersales.detail', aftersales_id=ascs.aftersales.aftersales_id)) return redirect(url_for('pc.index.pagenotfound')) data = { 'wtf_form': wtf_form, 'order_id': order_id, 'og_id': og_id, 'items': ascs.order_goods_list, 'goods_data': ascs.goods_data, 'refunds_amount': ascs.refunds_amount, 'current_time': current_timestamp(), 'aftersales_type': 1, 'order_address': ascs.order_address } return render_template('pc/aftersales/apply_step1.html.j2', **data) else: aftersales_type = 2 ascs = AfterSalesCreateService(uid, order_id=0, og_id=og_id, quantity=1, aftersales_type=aftersales_type, deliver_status=1) ret = ascs._check_order_goods() if not ret: if ascs.msg != u'超过有效退款时间': return redirect(url_for('pc.index.pagenotfound')) aftersales_type = 3 ascs = AfterSalesCreateService(uid, order_id=0, og_id=og_id, quantity=1, aftersales_type=aftersales_type, deliver_status=1) ret = ascs._check_order_goods() if not ret: return redirect(url_for('pc.index.pagenotfound')) data = { 'wtf_form': wtf_form, 'order_id': order_id, 'og_id': og_id, 'items': ascs.order_goods_list, 'goods_data': ascs.goods_data, 'refunds_amount': ascs.refunds_amount, 'aftersales_type': aftersales_type, 'current_time': current_timestamp(), 'order_address': ascs.order_address } return render_template('pc/aftersales/apply_step1.html.j2', **data)