def admin_user(id): if current_user.role_name != 'AdminUser': return render_error(403) if id == 'new': u = AdminUser() else: try: id = int(id) except ValueError: return render_error(400) u = db.session.query(AdminUser).filter(AdminUser.id == id).one_or_none() if u is None: return render_error(404) form = AdminUserForm(request.form if request.method == 'POST' else None, obj=u) if form.button_delete.data: db.session.delete(u) db.session.commit() db.session.flush() return redirect(url_for('admin_users')) if form.button_save.data and form.validate(): form.populate_obj(u) db.session.add(u) db.session.commit() if id == 'new': db.session.flush() return redirect(url_for('admin_user', id=u.id)) return render_template('admin_user.html', admin_user=u, form=form)
def get_cg_mobile_user(self): result = {'flag': 0} try: args = eval(self.request.body) except: result['msg'] = '参数错误' return result username = args["username"] password = args["password"] result = {'flag': 0} if username and password: try: user = AdminUser.get(AdminUser.username == username) if user.check_password(password): if user.isactive > 0 and (list(user.roles).count('D') > 0 or list(user.roles).count('B') > 0 or list(user.roles).count('A') > 0 or list(user.roles).count('C') > 0): user.updatesignin() result['flag'] = 1 if list(user.roles).count('R') > 0 or list(user.roles).count('D') > 0: role_intake = 1 else: role_intake = 0 result['msg'] = {'username': user.username, 'mobile': user.mobile, 'id': user.id, 'role_intake':role_intake} else: result['msg'] ="此账户被禁止登录采购系统,请联系管理员。" else: result['msg'] ="密码错误" except Exception, ex: result['msg'] = "此用户不存在"
def post(self): username = self.get_argument("username", None) password = self.get_argument("password", None) if username and password: try: user = AdminUser.get(AdminUser.username == username) if user.check_password(password): if user.isactive == 1: if not user.store: storeid = 0 else: storeid = user.store if not user.front_user: frontuserid = 0 else: frontuserid = user.front_user qstore = Store.select().where(Store.id == storeid) qfront_user = User.select().where( User.id == frontuserid) if qstore.count() > 0 and qfront_user.count() > 0: user.updatesignin() self.session['store'] = user self.session.save() self.redirect("/store/index") return else: self.flash("此帐户未关联经销商或经销商未绑定前台用户。") else: self.flash("此账户被禁止登录,请联系管理员。") else: self.flash("密码错误") except Exception, e: print e self.flash("此用户不存在")
def post(self): result = {"flag": 0, "msg": "", "data": ""} try: args = simplejson.loads(self.request.body) username = args["username"] password = args["password"] if username and password: quser = AdminUser.select().where( AdminUser.username == username) if quser.count() > 0 and quser[0].check_password(password): user = quser[0] if user.isactive == 1: if self.vrole("J", user.roles): if not user.store: storeid = 0 else: storeid = user.store if not user.front_user: frontuserid = 0 else: frontuserid = user.front_user qstore = Store.select().where(Store.id == storeid) qfront_user = User.select().where( User.id == frontuserid) if qstore.count() > 0 and qfront_user.count() > 0: user.updatesignin() result["flag"] = 1 result["data"] = { 'adminid': user.id, 'storeid': qstore[0].id, 'front_user': user.front_user, 'storename': qstore[0].name, } else: result["flag"] = 0 result["msg"] = "此帐户未关联经销商或经销商未绑定前台用户。" else: result["flag"] = 0 result["msg"] = "此账户没有经销商的登录权限。" else: result["flag"] = 0 result["msg"] = "此账户被禁止登录,请联系管理员。" else: if quser.count() > 0: result["flag"] = 0 result["msg"] = "密码错误。" else: result["flag"] = 0 result["msg"] = "此用户不存在" else: result["flag"] = 0 result["msg"] = "请输入用户名或者密码" except Exception, e: result["flag"] = 0 result["msg"] = e
def create_coupon_real(user, total_id, createby, type): try: seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-" sa = [] for i in range(16): sa.append(random.choice(seed)) salt = ''.join(sa) code = uuid.uuid3(uuid.NAMESPACE_DNS, salt + str(int(time.time()))) cp = CouponReal() cp.user = user.id cp.code = code cp.coupon_real_total = total_id cp.status = 1 cp.starttime = int(time.time()) cp.endtime = int( time.mktime( time.strptime( time.strftime("%Y-%m-%d 0:0:0", time.localtime(time.time() + 86400 * 30)), "%Y-%m-%d 0:0:0"))) cp.createby = createby cp.createtime = int(time.time()) cp.save() cp.coupon_real_total.quantity += 1 cp.coupon_real_total.save() gift = Gift() gift.user = user.id gift.product = cp.coupon_real_total.product gift.product_standard = cp.coupon_real_total.product_standard gift.quantity = 1 gift.created = int(time.time()) gift.created_by = AdminUser.get(AdminUser.username == createby).id gift.status = 0 gift.type = type # 对应orderItem表中的item_type gift.end_time = cp.endtime gift.save() cp.status = 1 cp.save() cp.coupon_real_total.used += 1 cp.coupon_real_total.save() msg = u'为用户' + user.username + u'增加实物优惠券成功!' return msg except Exception, ex: msg = u'创建实物优惠券失败,错误信息:' + ex.message email = { u'receiver': ['*****@*****.**', '*****@*****.**'], u'subject': u'创建实物优惠券失败', u'body': msg } create_msg(simplejson.dumps(email), 'email') return msg
def put(self): auth = request.authorization me = AdminUser.verify_auth_token(auth.username) args = me_parser.parse_args() pwd = args['pwd'] avatar = args['avatar'] if not pwd and not avatar: return jsonify({"code": -1, "message": "not modify"}) if pwd: me.password = pwd if avatar: me.avatar = avatar try: db.session.commit() except: return jsonify({"code": -1, "message": "修改失败"}) else: me = AdminUser.verify_auth_token(auth.username) me.token = me.generate_auth_token() #token me = marshal(me, admin_user_fields) return jsonify({"code": 1, "data": me})
def post(self): alipay = Alipay(**self.settings) params = {} ks = self.request.arguments.keys() for k in ks: params[k] = self.get_argument(k) if alipay.notify_verify(params): batch_no = self.get_argument("batch_no", None) # 退款批次号 try: pay_backs = PayBack.select().where( PayBack.batch_no == batch_no) if pay_backs.count() > 0: pay_back = pay_backs[0] if pay_back.status == 0: # 等待退款 pay_back.status = 1 pay_back.pay_response = simplejson.dumps(params) pay_back.save() try: admins = AdminUser.select().where(AdminUser.roles % '%Y%') receivers = [ n.email for n in admins if len(n.email) > 0 ] email = { u'receiver': receivers, u'subject': u'用户退款成功', u'body': u"退款订单编号为:" + pay_back.order.ordernum + u";<br>退款金额:" + str(pay_back.price) + u";" } create_msg(simplejson.dumps(email), 'email') except Exception, e: print e except Exception, ex: logging.error(ex) self.write("success")
def post(self): args = admin_user_parser.parse_args() uname = args['uname'] pwd = '123456' avatar = args['avatar'] role = args['role'] query = AdminUser.query.filter(AdminUser.uname == uname).first() if query: return jsonify({"code": -1, "message": "用户已存在"}) admin_user = AdminUser(uname=uname, password=pwd, avatar=avatar, role=role) try: db.session.add(admin_user) db.session.commit() except: return jsonify({"code": -1, "message": "添加失败"}) else: return jsonify({"code": 1, "message": "添加成功"})
def old_new_user_coupon(promote, user): if promote: result = 0 msg = '' try: oldUser = User.get(User.username == promote) cps = CouponTotal.select().where((CouponTotal.name == '满30减3元') & ( CouponTotal.status == 0)).limit(1) if cps.count() < 1: msg = u'请检查“满30减3元优惠券”是否被禁用或者不存在,老用户' + oldUser.username + u"未获得返卷,请手动补充优惠券后手动补发。" admins = AdminUser.select() receivers = [n.email for n in admins if len(n.email) > 0] email = { u'receiver': receivers, u'subject': u'老推新用户注册返卷失败', u'body': msg } create_msg(simplejson.dumps(email), 'email') else: log = u'系统自动赠送' create_coupon(oldUser, cps[0].id, log) msg = u'恭喜您,您推荐的好友' + user.mobile + u'已经注册成功,您获得3元优惠券一张,请在有效期内使用。' sms = { 'mobile': oldUser.username, 'body': msg, 'signtype': '1', 'isyzm': '1' } create_msg(simplejson.dumps(sms), 'sms') result = 1 up = User_Promote() up.old_user = oldUser.id up.new_user = user.id up.signuped = int(time.time()) if result == 1: up.signup_gift = 1 up.signup_gift_content = msg up.save() except Exception, e: logging.error("推荐人不存在" + e)
def get_offline_user(self): username = self.get_argument("mobile") password = self.get_argument("password") result = '0' if username and password: try: user = AdminUser.select().where(AdminUser.username == username) if user.count() > 0: user = user[0] if user.check_password(password): if user.isactive > 0 : user.updatesignin() result = user.id else: result ="此账户被禁止登录采购系统,请联系管理员。" else: result ="密码错误" else: result = "用户名不存在" except Exception, ex: result = "登陆异常,异常信息:" + ex
def post(self): opassword = self.get_argument("Password", None) password = self.get_argument("NPassword", None) apassword = self.get_argument("RNPassword", None) if opassword and password and apassword: if len(password) < 6: self.flash("请确认输入6位以上新密码") elif password != apassword: self.flash("请确认新密码和重复密码一致") else: user = self.get_store_user() if user.check_password(opassword): user.password = AdminUser.create_password(password) user.save() self.session['admin'] = user self.session.save() self.flash("修改密码成功。") else: self.flash("请输入正确的原始密码") else: self.flash("请输入原始密码和新密码") self.redirect('/store/password')
def get(self): alipay = Alipay(**self.settings) params = {} ks = self.request.arguments.keys() for k in ks: params[k] = self.get_argument(k) msg = "" if alipay.notify_verify(params): tn = self.get_argument("out_trade_no", None) trade_no = self.get_argument("trade_no", None) trade_status = self.get_argument("trade_status", None) logging.info("return:%s - %s - %s" % (tn, trade_no, trade_status)) try: order = None tn1 = tn.split(',') for n in tn1: orders = Order.select().where(Order.ordernum == n) if orders.count() > 0: order = orders[0] if order and order.status == 0: order.status = 1 order.save() order_Item = '' cartProducts = OrderItem.select().where( OrderItem.order == order) for cartproduct in cartProducts: order_Item += u'名称:' + cartproduct.product.name + u' X ' + str( cartproduct.quantity) + u'份;' if cartproduct.item_type == 5: pr = Product_Reserve.get( Product_Reserve.product == cartproduct.product) old_quantity = pr.quantity pr.quantity += cartproduct.quantity pr.save() if (old_quantity < pr.quantity_stage1) & ( pr.quantity >= pr.quantity_stage1): return_reserve_balance( cartproduct.product.id) elif (old_quantity < pr.quantity_stage2) & ( pr.quantity >= pr.quantity_stage2): return_reserve_balance( cartproduct.product.id) for n in cartProducts: if n.product.categoryfront.type == '2': sn = 1 for s in range(n.quantity): sn = sn + s seed = "1234567890" sa = [] for i in range(12): sa.append(random.choice(seed)) salt = ''.join(sa) OrderItemService.create(order_item=n.id, sn=sn, service_code=salt, service_used=0, store=order.store, user=order.user) try: admins = AdminUser.select().where(AdminUser.roles % '%Y%') receivers = [ n.email for n in admins if len(n.email) > 0 ] email = { u'receiver': receivers, u'subject': u'用户下单成功', u'body': u"支付方式:在线支付;<br/>订单编号为:" + n + u";<br>订单金额:" + str(order.currentprice) + u";<br>订单详情:" + order_Item } create_msg(simplejson.dumps(email), 'email') except Exception, e: print e alipay.send_goods_confirm_by_platform(trade_no) msg = "success" self.redirect("/cart/pay?result=" + msg + "&tn=" + tn + "&price=" + str(order.currentprice) + "&ptype=1") except Exception, ex: logging.error(ex)
def post(self): alipay = Alipay(**self.settings) params = {} ks = self.request.arguments.keys() for k in ks: params[k] = self.get_argument(k) if alipay.notify_verify(params): tn = self.get_argument("out_trade_no", None) #订单编号 trade_no = self.get_argument("trade_no", None) #支付宝交易号 trade_status = self.get_argument("trade_status", None) #交易状态 logging.info("notify:%s - %s - %s" % (tn, trade_no, trade_status)) buyer_email = self.get_argument("buyer_email", None) #买家支付宝帐号 notify_time = self.get_argument("notify_time", None) #通知时间 subject = self.get_argument("subject", None) #商品名称 payment_type = self.get_argument("payment_type", None) #支付类型 gmt_create = self.get_argument("gmt_create", None) #交易创建时间 gmt_payment = self.get_argument("gmt_payment", None) #交易付款时间 gmt_close = self.get_argument("gmt_close", None) #交易关闭时间 refund_status = self.get_argument("refund_status", None) #退款状态 gmt_refund = self.get_argument("gmt_refund", None) #退款时间 seller_email = self.get_argument("seller_email", None) #卖家支付宝账号 seller_id = self.get_argument("seller_id", None) #卖家支付宝账户号 buyer_id = self.get_argument("buyer_id", None) #买家支付宝账户号 price = self.get_argument("price", None) #商品单价 total_fee = self.get_argument("total_fee", None) #Number quantity = self.get_argument("quantity", None) #购买数量 body = self.get_argument("body", None) #商品描述 is_total_fee_adjust = self.get_argument("is_total_fee_adjust", None) #是否调整总价 use_coupon = self.get_argument("use_coupon", None) #是否使用红包买家 error_code = self.get_argument("error_code", None) #错误代码 bank_seq_no = self.get_argument("bank_seq_no", None) #网银流水 out_channel_inst = self.get_argument("out_channel_inst", None) #实际支付渠道 pay_response = { 'out_trade_no': tn, 'trade_no': trade_no, 'trade_status': trade_status, 'buyer_email': buyer_email, 'notify_time': notify_time, 'subject': subject, 'payment_type': payment_type, 'gmt_create': gmt_create, 'gmt_payment': gmt_payment, 'gmt_close': gmt_close, 'refund_status': refund_status, 'gmt_refund': gmt_refund, 'seller_email': seller_email, 'seller_id': seller_id, 'buyer_id': buyer_id, 'price': price, 'total_fee': total_fee, 'quantity': quantity, 'body': body, 'is_total_fee_adjust': is_total_fee_adjust, 'use_coupon': use_coupon, 'error_code': error_code, 'bank_seq_no': bank_seq_no, 'out_channel_inst': out_channel_inst } try: order = None tn = tn.split(',') for n in tn: orders = Order.select().where(Order.ordernum == n) if orders.count() > 0: order = orders[0] if order and order.status == 0: order.status = 1 order.pay_account = buyer_email order.trade_no = trade_no order.pay_response = simplejson.dumps(pay_response) order.save() order_Item = '' cartProducts = OrderItem.select().where( OrderItem.order == order) for cartproduct in cartProducts: order_Item += u'名称:' + cartproduct.product.name + u' X ' + str( cartproduct.quantity) + u'份;' if cartproduct.item_type == 5: pr = Product_Reserve.get( Product_Reserve.product == cartproduct.product) old_quantity = pr.quantity pr.quantity += cartproduct.quantity pr.save() if (old_quantity < pr.quantity_stage1) & ( pr.quantity >= pr.quantity_stage1): return_reserve_balance( cartproduct.product.id) elif (old_quantity < pr.quantity_stage2) & ( pr.quantity >= pr.quantity_stage2): return_reserve_balance( cartproduct.product.id) for n in cartProducts: if n.product.categoryfront.type == '2': sn = 1 for s in range(n.quantity): sn = sn + s seed = "1234567890" sa = [] for i in range(12): sa.append(random.choice(seed)) salt = ''.join(sa) OrderItemService.create(order_item=n.id, sn=sn, service_code=salt, service_used=0, store=order.store, user=order.user) try: admins = AdminUser.select().where(AdminUser.roles % '%Y%') receivers = [ n.email for n in admins if len(n.email) > 0 ] email = { u'receiver': receivers, u'subject': u'用户下单成功', u'body': u"支付方式:在线支付;<br/>订单编号为:" + n + u";<br>订单金额:" + str(order.currentprice) + u";<br>订单详情:" + order_Item } create_msg(simplejson.dumps(email), 'email') except Exception, e: print e except Exception, ex: logging.error(ex) if trade_status == 'WAIT_SELLER_SEND_GOODS': alipay.send_goods_confirm_by_platform(trade_no) self.write("success")
def get(self): auth = request.authorization me = AdminUser.verify_auth_token(auth.username) me.token = me.generate_auth_token() #token me = marshal(me, admin_user_fields) return jsonify({"code": 1, "data": me})
def get(self): userid = self.get_argument('userid', None) if userid: user = User.get(id=userid) if user: activities = UserActivity.select().where( UserActivity.user == user) if activities.count() == 0: beginvalue = time.mktime( time.strptime('2015-01-12', "%Y-%m-%d")) endvalue = time.mktime( time.strptime('2015-01-31', "%Y-%m-%d")) q = Order.select(Order.currentprice).where( (Order.user == self.current_user) & (Order.ordered >= beginvalue) & (Order.status < 5) & (Order.ordered < endvalue) & (Order.payment < 9) & (((Order.status > -1) & (Order.payment == 0)) | ( (Order.status > 0) & (Order.payment > 0)))).dicts() price = sum([n['currentprice'] for n in q]) cpcount = int(price / 50.0) if cpcount > 0: cps = Coupon.select(Coupon).join(CouponTotal).where( (CouponTotal.name == '满50减5元') & (Coupon.status == 0)).limit(cpcount) if cps.count() < cpcount: msg = '领取优惠券失败,管理员会立即处理,请谅解,给您带来的不便' admins = AdminUser.select() receivers = [ n.email for n in admins if len(n.email) > 0 ] email = { u'receiver': receivers, u'subject': u'5元优惠券库存不够了', u'body': u'用户:' + str(userid) + u'领取优惠券失败,库存不足。' } try: create_msg(simplejson.dumps(email), 'email') except: pass else: for cp in cps: cp.user = user cp.status = 1 cp.save() cp.coupontotal.quantity += 1 cp.coupontotal.save() UserActivity.create(user=user, catchtime=int(time.time()), status=1) msg = '成功领取' + str( cpcount ) + '张优惠券。您可以在 [个人中心]-[我的优惠券] 中查看详情,感谢您的关注' try: content = '作为车装甲最最重视的用户,非常感谢您对车装甲的支持。送您' + str( cpcount * 5) + '元优惠券,请笑纳。' sms = { 'mobile': user.mobile, 'body': content, 'signtype': '1', 'isyzm': '1' } create_msg(simplejson.dumps(sms), 'sms') except: pass else: msg = '您累计消费不足50元,无法领取优惠券,感谢您的关注' else: msg = '您已经领取过优惠券,感谢您的关注' else: msg = '请先登录车装甲,之后才能领取,感谢您的关注' else: msg = '请先登录车装甲,之后才能领取,感谢您的关注' self.write(msg)
def new_year_send_logic(order): user = order.user beginvalue = time.mktime(time.strptime('2015-01-31', "%Y-%m-%d")) endvalue = time.mktime(time.strptime('2015-02-15', "%Y-%m-%d")) now = int(time.time()) # logger.error(str(now)) needsend = True if now < endvalue and order.status < 5 and order.payment < 9 and \ ((order.status > -1 and order.payment == 0) or (order.status > 0 and order.payment > 0)): #当前为2月15日之前,并且订单状态有效 if user.signuped > beginvalue: #新注册用户,1月31日当天或以后注册的 q = Order.select().where( (Order.user == user) & (Order.id != order.id) & (Order.status < 5) & (Order.payment < 9) & (((Order.status > -1) & (Order.payment == 0)) | ( (Order.status > 0) & (Order.payment > 0)))) ct = q.count() if ct == 0: #新用户第一次购买 needsend = False tencount = int(order.currentprice / 40.0) fivecount = tencount * 2 if fivecount > 0: cps = Coupon.select(Coupon).join(CouponTotal).where( (CouponTotal.name == '满50减5元') & (Coupon.status == 0) & (Coupon.user >> None)).limit(fivecount) if cps.count() < fivecount: admins = AdminUser.select() receivers = [ n.email for n in admins if len(n.email) > 0 ] email = { u'receiver': receivers, u'subject': u'5元优惠劵库存不够了', u'body': u'用户:' + str(user.id) + u'领取优惠劵失败,库存不足。' } try: create_msg(simplejson.dumps(email), 'email') except: pass else: for cp in cps: cp.user = user cp.status = 1 cp.save() cp.coupontotal.quantity += 1 cp.coupontotal.save() if tencount > 0: cps = Coupon.select(Coupon).join(CouponTotal).where( (CouponTotal.name == '满100减10元') & (Coupon.status == 0) & (Coupon.user >> None)).limit(tencount) if cps.count() < tencount: admins = AdminUser.select() receivers = [ n.email for n in admins if len(n.email) > 0 ] email = { u'receiver': receivers, u'subject': u'10元优惠劵库存不够了', u'body': u'用户:' + str(user.id) + u'领取优惠劵失败,库存不足。' } try: create_msg(simplejson.dumps(email), 'email') except: pass else: for cp in cps: cp.user = user cp.status = 1 cp.save() cp.coupontotal.quantity += 1 cp.coupontotal.save() if fivecount > 0: try: content = '小易终于等到您啦~请收下见面礼吧!' + str( tencount * 10 + fivecount * 5) + '元代金券已经放入账户,下单时即可使用。更多优惠请到车装甲' sms = { 'mobile': user.mobile, 'body': content, 'signtype': '1', 'isyzm': '1' } create_msg(simplejson.dumps(sms), 'sms') except: pass if needsend: #老用户下单(含新用户第二次下单),满50送5,满80送5X2;1月31日以前注册的用户 cpcount = 0 if order.currentprice >= 80: cpcount = 2 elif order.currentprice >= 50: cpcount = 1 if cpcount > 0: cps = Coupon.select(Coupon).join(CouponTotal).where( (CouponTotal.name == '满50减5元') & (Coupon.status == 0) & (Coupon.user >> None)).limit(cpcount) if cps.count() < cpcount: admins = AdminUser.select() receivers = [n.email for n in admins if len(n.email) > 0] email = { u'receiver': receivers, u'subject': u'5元优惠劵赠送异常', u'body': u'用户:' + str(user.id) + u'领取优惠劵失败,库存不足。' } try: create_msg(simplejson.dumps(email), 'email') except: pass else: for cp in cps: cp.user = user cp.status = 1 cp.save() cp.coupontotal.quantity += 1 cp.coupontotal.save() try: content = '作为车装甲最最重视的用户,非常感谢您对车装甲的支持。送您' + str( cpcount * 5) + '元优惠券,请笑纳。' sms = { 'mobile': user.mobile, 'body': content, 'signtype': '1', 'isyzm': '1' } create_msg(simplejson.dumps(sms), 'sms') except: pass