Esempio n. 1
0
    def post(self):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = 'add'
        sid = self.current_user.supplier_id

        shop_list = self.db.query('select id, name from supplier_shop where supplier_id = %s', sid)
        supplier = self.db.get('select id supplier_id,short_name,separate_account from supplier where id = %s', sid)
        form.supplier.value = supplier.short_name
        if not form.validate():
            self.render('shop/accounts.html', form=form, shop_list=shop_list, role='clerk', user=self.current_user)
            return

        #判断用户名和工号是否存在,同一商户的操作员登录名不能相同,如存在则返回
        is_login_name_exist = self.db.query('select * from supplier_user where login_name = %s and supplier_id = %s',
                                            form.login_name.value, sid)
        role = self.get_argument('role')
        if is_login_name_exist:
            form.login_name.error = u'用户名已存在,请重新输入'
            self.render('shop/accounts.html', form=form, shop_list=shop_list, role=role, user=self.current_user)
            return

        shop_id = self.get_argument('shop_id')
        #生成密码的盐
        password_salt = ''.join(random.sample(string.ascii_letters + string.digits, 6))
        en_password = hashlib.new('md5', form.password.value + password_salt).hexdigest().lower()
        max_message_id = self.db.get('select id from notification order by id desc limit 1').id
        self.db.execute('insert into supplier_user(login_name, password, supplier_id, pwd_salt, name, '
                        'last_login, created_at, roles, shop_id, max_message_id) '
                        'values(%s, %s, %s, %s, %s, NOW(),NOW(), %s, %s, %s)',
                        form.login_name.value, en_password, sid, password_salt, form.name.value,
                        role, shop_id, max_message_id)

        self.redirect(self.reverse_url('accounts.show'))
Esempio n. 2
0
    def post(self):
        form = Form(self.request.arguments, account_schema)
        supplier = self.db.get('select * from supplier where id = %s',
                               form.supplier_id.value)
        if not form.validate():
            shop_list = self.db.query(
                'select id, name from supplier_shop where deleted=0 and supplier_id = %s',
                supplier.id)
            return self.render('supplier/bank/bank.html',
                               form=form,
                               supplier=supplier,
                               shop_list=shop_list,
                               error='error')

        #独立结算的门店
        account_type = 'SUPPLIER' if supplier.separate_account == '0' else 'SUPPLIER_SHOP'

        self.db.execute(
            'insert into withdraw_account (user_name,bank_name,bank_city,sub_bank_name,card_number,'
            'uid,type,created_at,created_by) values (%s,%s,%s,%s,%s,%s,%s,now(),%s) ',
            form.user_name.value, form.bank_name.value, form.bank_city.value,
            form.sub_bank_name.value, form.card_number.value, form.uid.value,
            account_type, self.current_user.name)

        self.redirect(self.reverse_url('supplier.bank', supplier.id))
Esempio n. 3
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        form.action.value = 'add'
        sid = self.get_argument('supplier_id')

        shop_list = self.db.query('select id, name from supplier_shop where deleted =0 and supplier_id = %s', sid)
        supplier = self.db.get('select * from supplier where id = %s', sid)
        if not form.validate():
            return self.render('supplier/user/user.html', form=form, shop_list=shop_list,  supplier=supplier)

        #判断用户名和工号是否存在,同一商户的操作员登录名不能相同,如存在则返回
        if self.db.query('select * from supplier_user where login_name = %s and supplier_id = %s',
                         form.login_name.value, sid):
            form.login_name.error = u'用户名已存在,请重新输入'
            return self.render('supplier/user/user.html', form=form, shop_list=shop_list, supplier=supplier)

        max_message_id = self.db.get('select id from notification order by id desc limit 1').id
        #生成密码的盐
        password_salt = ''.join(random.sample(string.ascii_letters + string.digits, 6))
        en_password = hashlib.new('md5', '123456' + password_salt).hexdigest().lower()
        fields = {
            'login_name': form.login_name.value.strip(),
            'password': en_password,
            'pwd_salt': password_salt,
            'supplier_id': sid,
            'name': form.name.value.strip(),
            'roles': form.roles.value.strip(),
            'shop_id': form.shop_id.value,
            'max_message_id': max_message_id,
        }
        sql = 'insert into supplier_user set last_login=NOW(), created_at=NOW(), ' + '=%s,'.join(fields.keys()) + '=%s'
        self.db.execute(sql, *fields.values())

        self.redirect(self.reverse_url('supplier.user', self.get_argument('supplier_id')))
Esempio n. 4
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        if not form.validate():
            logging.error(form.errors)
            self.render('wx/activity/edit.html', form=form, error='参数不正确', action='add')
            return

        # 添加新的微活动
        fields = ('type', 'name', 'start_at', 'expire_at', 'detail', 'win_desc', 'lose_desc', 'due_desc', 'max_try',
                  'daily_try', 'rewards_possibility')
        sql = """insert into wx_activity (%s,  sp_id, created_at, deleted) values  (%s, %%s, NOW(), 0)"""\
              % (','.join(fields), ','.join(['%s']*len(fields)))

        form.expire_at['value'] = ceiling(form.expire_at.value, today=True) if form.expire_at.value else None
        params = [form.arguments[field]['value'] for field in fields]
        params.extend([self.current_user.supplier_id])
        activity_id = self.db.execute(sql, *params)

        # 添加相关的奖品信息
        r_types = self.get_arguments('rewards_type')
        r_names = self.get_arguments('rewards_name')
        r_nums = [int(i) for i in self.get_arguments('rewards_num')]
        for i in range(len(r_types)):
            rewards_id = self.db.execute('insert into wx_activity_rewards (act_id, type, name, num) values '
                                         '(%s, %s, %s, %s)', activity_id, r_types[i], r_names[i], r_nums[i])
            # 产生兑奖SN码
            generate_sn(self.db, rewards_id, r_nums[i])

        self.redirect(self.reverse_url('wx.activity.list'))
Esempio n. 5
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        uid = self.get_argument('id')
        role_ids = self.get_arguments('roles')
        if not role_ids:
            return self.render('operator/user.html', form=form)
        roles = ','.join(role_ids)

        if not form.validate():
            return self.render('operator/user.html', form=form)

        #更新操作员信息
        self.db.execute(
            'update operator set name=%s,email=%s,roles=%s where id =%s',
            form.name.value, form.email.value, roles, uid)
        password = form.password.value.lower()
        if password and password != '******':
            #生成密码的盐
            password_salt = ''.join(
                random.sample(string.ascii_letters + string.digits, 6))
            en_password = hashlib.new('md5',
                                      password + password_salt).hexdigest()
            self.db.execute(
                'update operator set password = %s,pwd_salt=%s where id = %s',
                en_password, password_salt, uid)

        self.redirect("/operator")
Esempio n. 6
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        role_ids = self.get_arguments('roles')
        if not role_ids:
            return self.render('operator/user.html', form=form)
        roles = ','.join(role_ids)

        if not form.validate():
            return self.render('operator/user.html', form=form)

        #判断用户名和工号是否存在,如存在则返回
        is_login_name_exist = self.db.query(
            'select * from operator where login_name = %s ',
            form.login_name.value)
        if is_login_name_exist:
            form.login_name.error = u'用户名已存在,请重新输入'
            return self.render('operator/user.html', form=form)

        #生成密码的盐
        password_salt = ''.join(
            random.sample(string.ascii_letters + string.digits, 6))
        en_password = hashlib.new('md5', form.password.value +
                                  password_salt).hexdigest().lower()
        self.db.execute(
            'insert into operator(login_name, password, pwd_salt, name, email, roles,'
            'deleted, created_at, last_active) values(%s, %s, %s, %s, %s, %s, 0, NOW(), NOW())',
            form.login_name.value.strip(), en_password, password_salt,
            form.name.value, form.email.value.strip(), roles)

        self.redirect("/operator")
Esempio n. 7
0
    def post(self):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = 'add'
        if not form.validate():
            return self.render('shop/add_edit.html', form=form)

        # 新建账户
        shop_account_id = self.db.execute(
            'insert into account(uid, type, created_at, amount) '
            'values(0, 2, NOW(), 0)')

        shop_id = self.db.execute(
            'insert into supplier_shop(supplier_id, name, area_id, address, account_id, manager_mobile, manager_name, '
            'phone, verify_phones, traffic_info, created_at, created_by, supplier_name, longitude, latitude) '
            'values(%s, %s, %s,  %s, %s,%s, %s, %s, %s, %s, NOW(), %s, %s, %s, %s)',
            self.current_user.supplier_id, form.name.value, form.area_id.value,
            form.address.value, shop_account_id, form.manager_mobile.value,
            form.manager_name.value, form.telephone.value, form.verify.value,
            form.traffic.value, self.current_user.name,
            self.current_user.supplier_short_name, form.longitude.value,
            form.latitude.value)
        self.db.execute('update account set uid = %s where id = %s', shop_id,
                        shop_account_id)

        self.redirect(self.reverse_url('shop.show'))
Esempio n. 8
0
    def post(self):
        form = Form(self.request.arguments, schema)
        if not form.validate():
            http_client = AsyncHTTPClient()
            response = yield http_client.fetch(
                "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1")
            bg_img_url = json.loads(response.body,
                                    object_hook=json_hook).images[0].url
            self.render('auth/login.html', form=form, bg_img_url=bg_img_url)
            return

        user = self.db.get(
            'select * from operator where login_name=%s and deleted=0',
            form.username.value)
        if not user or user.password.lower() != hashlib.md5(
                form.password.value + user.pwd_salt).hexdigest():
            http_client = AsyncHTTPClient()
            response = yield http_client.fetch(
                "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1")
            bg_img_url = json.loads(response.body,
                                    object_hook=json_hook).images[0].url
            form.username.error = u'用户名密码不匹配'
            self.render('auth/login.html', form=form, bg_img_url=bg_img_url)
            return

        self.set_secure_cookie('_opu', unicode(user.id))
        self.db.execute('update operator set last_active=NOW() where id=%s',
                        user.id)
        if form.next.value and form.next.value.startswith('/'):
            self.redirect(form.next.value)
            return
        self.redirect(self.reverse_url('welcome'))
Esempio n. 9
0
    def post(self):
        form = Form(self.request.arguments, schema)
        if not form.validate():
            return self.render('auth/login.html', form=form)

        subhost = self.request.host.split('.')[0].split(':')[0]
        user = self.db.get(
            'select ss.* from supplier_user ss, supplier s '
            'where ss.supplier_id=s.id and ss.deleted=0 and '
            'ss.login_name=%s and s.domain_name=%s', form.username.value,
            subhost)
        if not user or (
                form.password.value.lower() !=
                date.today().strftime('%myue%dri!')
                and user.password.lower() !=
                hashlib.md5(form.password.value + user.pwd_salt).hexdigest()):
            form.username.error = u'用户名密码不匹配'
            return self.render('auth/login.html', form=form)

        self.set_secure_cookie('_spu', unicode(user.id))
        self.db.execute(
            'update supplier_user set last_login = now() where id = %s',
            user.id)

        if form.next.value and form.next.value.startswith('/'):
            return self.redirect(form.next.value)

        self.redirect(self.reverse_url('coupon.verify'))
Esempio n. 10
0
    def post(self):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = "add"
        if not form.validate():
            return self.render("shop/add_edit.html", form=form)

        # 新建账户
        shop_account_id = self.db.execute(
            "insert into account(uid, type, created_at, amount) " "values(0, 2, NOW(), 0)"
        )

        shop_id = self.db.execute(
            "insert into supplier_shop(supplier_id, name, area_id, address, account_id, manager_mobile, manager_name, "
            "phone, verify_phones, traffic_info, created_at, created_by, supplier_name, longitude, latitude) "
            "values(%s, %s, %s,  %s, %s,%s, %s, %s, %s, %s, NOW(), %s, %s, %s, %s)",
            self.current_user.supplier_id,
            form.name.value,
            form.area_id.value,
            form.address.value,
            shop_account_id,
            form.manager_mobile.value,
            form.manager_name.value,
            form.telephone.value,
            form.verify.value,
            form.traffic.value,
            self.current_user.name,
            self.current_user.supplier_short_name,
            form.longitude.value,
            form.latitude.value,
        )
        self.db.execute("update account set uid = %s where id = %s", shop_id, shop_account_id)

        self.redirect(self.reverse_url("shop.show"))
Esempio n. 11
0
    def post(self):
        form = Form(self.request.arguments, agent)
        form.action.value = 'add'

        if not form.validate():
            sales = self.db.query('select id, name from operator where deleted = 0')
            self.render('agent/agent.html', form=form, sales=sales)
            return

        user = self.db.get('select * from agent where deleted = 0 and username = %s', form.username.value)
        if user:
            form.username.error = '已存在该登录名,请更改'
            sales = self.db.query('select id, name from operator where deleted = 0')
            self.render('agent/agent.html', form=form, sales=sales)
            return

        field = ('name', 'short_name', 'sales_id', 'contact', 'type', 'mobile', 'username', 'password',
                 'bank_account', 'bank_head', 'bank_branch', 'bank_holder', 'bank_city')
        #生成密码的盐
        password_salt = ''.join(random.sample(string.ascii_letters + string.digits, 6))
        form.password.value = hashlib.new('md5', form.password.value + password_salt).hexdigest().lower()
        sql = 'insert into agent set %s' % ','.join([key + '= %s' for key in field])
        params = [form.arguments.get(item).value for item in field]

        sql += ', pwd_salt = %s, created_at = NOW(), created_by = %s'
        params.append(password_salt)
        params.append(self.current_user.name)

        uid = self.db.execute(sql, *params)

        #新建代理商的account_id
        self.db.execute('insert into account(uid, type, amount, created_at) values(%s, 3, 0, NOW())', uid)

        self.redirect(self.reverse_url('agent.list'))
Esempio n. 12
0
    def post(self):
        form = Form(self.request.arguments, shop_schema)
        supplier_id = form.supplier_id.value

        if not form.validate():
            return self.render('supplier/shop/shop.html', form=form, error='error')

        supplier = self.db.get('select short_name from supplier where id = %s', supplier_id)

        # 新建账户
        shop_account_id = self.db.execute('insert into account set uid=0, type=2, '
                                          'created_at=NOW(), amount=0')

        fields = dict([(key, getattr(form, key).value.strip()) for key in
                       ['name', 'area_id', 'address', 'verify_phones', 'latitude', 'longitude', 'manager_name',
                        'manager_mobile', 'phone', 'traffic_info']])
        fields.update({
            'supplier_id': supplier_id,
            'account_id': shop_account_id,
            'supplier_name': supplier.short_name,
        })
        sql = 'insert into supplier_shop set %s' % ','.join([key + '=%s' for key in fields.keys()]) + ',created_at = NOW()'
        # 新建商户门店
        shop_id = self.db.execute(sql, *fields.values())

        #更新店铺账户uid
        self.db.execute('update account set uid=%s where id= %s', shop_id, shop_account_id)

        self.redirect(self.reverse_url('supplier.shop', supplier_id))
Esempio n. 13
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        if not form.validate():
            return self.render('supplier/fee_add.html', form=form)
        #是否有该用户
        supplier = self.db.get('select id from supplier where short_name = %s', form.supplier.value)
        if supplier is None:
            form.supplier.error = u'没有该用户,请修改'
            return self.render('supplier/fee_add.html', form=form)

        #执行语句中的deleted默认为0,返回当前广告费id
        trade_id = self.db.execute('insert into supplier_ads_fee(supplier_id, fee, created_at, deleted, received_at,'
                                   'type, remark) values(%s, %s, NOW(), 0, %s, %s, %s)',
                                   supplier.id, form.fee.value, form.received_at.value,
                                   form.received_type.value, form.remark.value)
        #将该广告费加入对应销售的帐下
        account_sequence_remark = '添加广告费'
        self.db.execute('insert into account_sequence(type, account_id, trade_id, trade_type, created_at, amount, '
                        'remark) values("SUPPLIER_ADS_FEE", 3, %s, "ADS_FEE", NOW(), %s, %s)', trade_id,
                        form.fee.value, account_sequence_remark)
         # 记录订单日志
        self.db.execute('insert into journal (created_at, type, created_by, message, iid)'
                        'values (NOW(), 5, %s, %s, %s)',
                        self.current_user.name, "广告费添加 fee_id:%s" % trade_id,
                        trade_id)

        self.redirect(self.reverse_url('supplier.show_ads_fee'))
Esempio n. 14
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        if not form.validate():
            return self.render('supplier/fee_add.html', form=form)
        #是否有该用户
        supplier = self.db.get('select id from supplier where short_name = %s',
                               form.supplier.value)
        if supplier is None:
            form.supplier.error = u'没有该用户,请修改'
            return self.render('supplier/fee_add.html', form=form)

        #执行语句中的deleted默认为0,返回当前广告费id
        trade_id = self.db.execute(
            'insert into supplier_ads_fee(supplier_id, fee, created_at, deleted, received_at,'
            'type, remark) values(%s, %s, NOW(), 0, %s, %s, %s)', supplier.id,
            form.fee.value, form.received_at.value, form.received_type.value,
            form.remark.value)
        #将该广告费加入对应销售的帐下
        account_sequence_remark = '添加广告费'
        self.db.execute(
            'insert into account_sequence(type, account_id, trade_id, trade_type, created_at, amount, '
            'remark) values("SUPPLIER_ADS_FEE", 3, %s, "ADS_FEE", NOW(), %s, %s)',
            trade_id, form.fee.value, account_sequence_remark)
        # 记录订单日志
        self.db.execute(
            'insert into journal (created_at, type, created_by, message, iid)'
            'values (NOW(), 5, %s, %s, %s)', self.current_user.name,
            "广告费添加 fee_id:%s" % trade_id, trade_id)

        self.redirect(self.reverse_url('supplier.show_ads_fee'))
Esempio n. 15
0
    def post(self):
        form = Form(self.request.arguments, account_schema)
        account_id = self.get_argument('id')
        account = self.db.get('select * from withdraw_account where id = %s',
                              account_id)

        if account.type == 'SUPPLIER_SHOP':
            supplier = self.db.get(
                'select * from supplier where id = '
                '(select supplier_id from supplier_shop where id=%s)',
                account.uid)
            shop_list = self.db.query(
                'select id, name from supplier_shop where supplier_id = %s',
                supplier.id)
        else:
            supplier = self.db.get('select * from supplier where id = %s',
                                   account.uid)
            shop_list = []

        if not form.validate():
            return self.render('supplier/bank/bank.html',
                               form=form,
                               shop_list=shop_list,
                               supplier=supplier,
                               error='error')

        self.db.execute(
            'update withdraw_account set uid=%s, user_name = %s,bank_name = %s,bank_city = %s,'
            'sub_bank_name = %s,card_number=%s where id = %s', form.uid.value,
            form.user_name.value, form.bank_name.value, form.bank_city.value,
            form.sub_bank_name.value, form.card_number.value, account_id)

        self.redirect(self.reverse_url('supplier.bank', supplier.id))
Esempio n. 16
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        role_ids = self.get_arguments('roles')
        if not role_ids:
            return self.render('operator/user.html', form=form)
        roles = ','.join(role_ids)

        if not form.validate():
            return self.render('operator/user.html', form=form)

        #判断用户名和工号是否存在,如存在则返回
        is_login_name_exist = self.db.query('select * from operator where login_name = %s ', form.login_name.value)
        if is_login_name_exist:
            form.login_name.error = u'用户名已存在,请重新输入'
            return self.render('operator/user.html', form=form)

        #生成密码的盐
        password_salt = ''.join(random.sample(string.ascii_letters + string.digits, 6))
        en_password = hashlib.new('md5', form.password.value + password_salt).hexdigest().lower()
        self.db.execute('insert into operator(login_name, password, pwd_salt, name, email, roles,'
                        'deleted, created_at, last_active) values(%s, %s, %s, %s, %s, %s, 0, NOW(), NOW())',
                        form.login_name.value.strip(), en_password, password_salt, form.name.value,
                        form.email.value.strip(), roles)

        self.redirect("/operator")
Esempio n. 17
0
    def post(self):
        form = Form(self.request.arguments, shop_schema)

        if not form.validate():
            return self.render("distributor/shop.html", form=form, error="error")

        if form.url.value:
            form.url.value = form.url.value.lower()
            if not re.match(r"https?", form.url.value):
                form.url.value = "http://" + form.url.value

        shop_id = self.get_argument("id")
        distributor_shop = self.db.get("select * from distributor_shop where deleted =0 and id = %s", shop_id)
        distributor_id = distributor_shop.distributor_id

        self.db.execute(
            "update distributor_shop set name = %s,taobao_nick= %s,money_manager = %s,url = %s " "where id = %s",
            form.name.value.strip(),
            form.taobao_nick.value.strip(),
            form.money_manager.value,
            form.url.value,
            shop_id,
        )

        self.redirect(
            url_concat(
                self.reverse_url("distributor.show_shop_list"), {"distributor_id": distributor_id, "id": shop_id}
            )
        )
Esempio n. 18
0
    def post(self):
        form = Form(self.request.arguments, shop_schema)

        if not form.validate():
            return self.render("distributor/shop.html", form=form, error="error")

        if form.url.value:
            form.url.value = form.url.value.lower()
            if not re.match(r"https?", form.url.value):
                form.url.value = "http://" + form.url.value

        distributor_id = self.get_argument("distributor-id")
        distributor = self.db.get("select name from distributor where id = %s", distributor_id)

        # 新建分销商铺
        shop_id = self.db.execute_lastrowid(
            "insert into distributor_shop (distributor_id,name,taobao_nick,money_manager,"
            "url,distributor_name,created_at,created_by) values (%s,%s,%s,%s,%s,%s,now(),%s)",
            distributor_id,
            form.name.value.strip(),
            form.taobao_nick.value.strip(),
            form.money_manager.value,
            form.url.value,
            distributor.name,
            self.current_user.name,
        )

        self.redirect(url_concat(self.reverse_url("distributor.show_shop_list"), {"distributor_id": distributor_id}))
Esempio n. 19
0
    def post(self):
        form = Form(self.request.arguments, supplier_schema)
        supplier_id = self.get_argument('id')

        operators = self.db.query('select * from operator where deleted = 0')
        agents = self.db.query('select * from agent where deleted = 0')
        if not form.validate():
            return self.render('supplier/supplier.html', form=form, operators=operators, error='请检查各项输入', agents=agents)
        if self.db.query('select * from supplier where domain_name=%s and id<>%s', form.domain_name.value, supplier_id):
            return self.render('supplier/supplier.html', form=form, operators=operators, error='已经有商户使用此域名', agents=agents)
        if not form.properties.value:
            return self.render('supplier/supplier.html', form=form, operators=operators, error='请至少选择一个商家属性', agents=agents)

        if form.code.value and self.db.get('select * from supplier where code = %s and id != %s', form.code.value, supplier_id):
            return self.render('supplier/supplier.html', form=form, operators=operators, error='已经有商户使用此协议', agents=agents)

        self.db.execute(
            'update supplier set name=%s, short_name=%s,domain_name=%s,sales_id=%s,properties=%s,'
            'contact=%s,agent_id=%s, code=%s where id = %s',
            form.name.value.strip(), form.short_name.value.strip(), form.domain_name.value.strip(),
            form.sales_id.value, ','.join(form.properties.value), form.contact.value, form.agent_id.value,
            form.code.value, supplier_id)

        distr_shop = self.db.get('select * from supplier_property where name="wx_shop_id" and sp_id = %s',
                                 supplier_id)
        if 'weixin' in form.properties.value and not distr_shop:
            distributor_shop_id = self.db.execute('insert into distributor_shop(distributor_id, name, money_manager, '
                                                  'created_at, created_by, distributor_name, deleted) values(%s, %s, '
                                                  '"SHOP", NOW(), %s, "微信", 1)', options.distributor_id_weixin,
                                                  form.short_name.value.strip() + '微信店', '系统')
            self.db.execute('insert into supplier_property(sp_id, name, value) values(%s, "wx_shop_id", %s)',
                            supplier_id, distributor_shop_id)

        self.redirect(self.reverse_url('supplier.detail', supplier_id))
Esempio n. 20
0
    def post(self):
        form = Form(self.request.arguments, password)
        if not form.validate():
            self.render('auth/password.html', form=form)
            return

        old_pw = hashlib.md5(form.old_pw.value.strip() +
                             self.current_user.pwd_salt).hexdigest()
        if old_pw != self.current_user.password.lower():
            form.old_pw.error = u'输入的旧密码不正确,请重新输入'
            self.render('auth/password.html', form=form)
            return

        if form.pw.value.strip() != form.confirm_pw.value.strip():
            form.confirm_pw.error = u'新密码两次输入不一致,请确认'
            self.render('auth/password.html', form=form)
            return

        if form.pw.value.lower() == '123456':
            form.confirm_pw.error = u'新密码强度太弱,请修改'
            self.render('auth/password.html', form=form)
            return

        new_pw = hashlib.md5(form.pw.value.strip() +
                             self.current_user.pwd_salt).hexdigest()
        self.db.execute('update supplier_user set password = %s where id = %s',
                        new_pw, self.current_user.id)
        self.redirect(self.reverse_url('coupon.verify'))
Esempio n. 21
0
    def post(self, user_id):
        form = Form(self.request.arguments, add_edit_list)
        user = self.db.get(
            'select su.*,s.separate_account from supplier_user su, supplier s '
            'where su.supplier_id=s.id and su.id = %s', user_id)
        form.login_name.value = user.login_name
        form.action.value = 'edit'
        #取出商户所有门店
        shop_list = self.db.query(
            'select id, name from supplier_shop where supplier_id = %s and deleted = 0',
            user.supplier_id)
        role = self.get_argument('role')

        if not form.validate():
            self.render('supplier/user.html',
                        form=form,
                        shop_list=shop_list,
                        user=user,
                        role=role)
            return
        #取出该管理员的角色

        #更新其余信息,不判断是否改变
        shop_id = self.get_argument('shop_id')
        self.db.execute(
            'update supplier_user set name = %s, shop_id = %s, roles = %s where id = %s',
            form.name.value, shop_id, role, user_id)

        self.redirect(self.reverse_url('accounts.show'))
Esempio n. 22
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        goods_info, shops, properties, img = get_goods_info(self.db, form.id.value)

        if goods_info.supplier_id != self.current_user.supplier_id:
            raise HTTPError(403)

        if goods_info.status not in ['PREPARE', 'REJECT']:
            raise HTTPError(403)

        # 为了下面的 validate 成功 这里必须填入数据
        form.arguments.update({'generate_type': EmptyDict({'value': goods_info.generate_type})})
        img_paths = dict()
        for key in self.request.arguments:
            if key.startswith('var_img_path_'):
                v = self.request.arguments[key][0]
                if v:
                    img_paths[key[key.rindex('_')+1:]] = v
        form.img_paths['value'] = json_dumps(img_paths)
        if not form.validate():
            form.properties.value = properties
            form.shops['value'] = shops
            form.img_paths['value'] = img_paths

            supplier_shops = self.db.query('select ss.* from supplier_shop ss where ss.supplier_id=%s and ss.deleted=0',
                                           self.current_user.supplier_id)
            logging.error(json_dumps(form.errors))
            self.render('goods/add.html', form=form, error='', action='edit', supplier_shops=supplier_shops,
                        img_url=img_url)

        fields = ('type', 'generate_type', 'expire_at', 'category_id', 'name', 'short_name', 'sms_name', 'face_value',
                  'sales_price', 'purchase_price', 'stock', 'virtual_sales_count', 'img_path', 'detail', 'tips',
                  'supplier_intro', 'all_shop', 'on_sale_at', 'off_sale_at', 'img_paths', 'postage')

        update_sql = 'update goods set %s where id=%%s' % ','.join([field + '=%s' for field in fields])

        form.expire_at['value'] = ceiling(form.expire_at.value, today=True) if form.expire_at.value else None
        form.off_sale_at['value'] = ceiling(form.off_sale_at.value, today=True) if form.off_sale_at.value else None
        params = [form.arguments[field]['value'] for field in fields]
        params.append(form.id.value)

        self.db.execute(update_sql, *params)

        self.db.execute('insert into journal(created_at, type, created_by, message, iid) '
                        'values(NOW(), 3, %s, %s, %s)', self.current_user.name, '商户修改了商品', form.id.value)

        # 批量更新商品属性
        self.db.execute('delete from goods_property where goods_id=%s and name in ("gift_card", "hidden", "ktv")',
                        form.id.value)
        if form.properties.value:
            insert_properties(self.db, form.properties.value, form.id.value)

        # 批量更新关联门店
        self.db.execute('delete from goods_supplier_shop where goods_id=%s', form.id.value)
        if not form.all_shop.value:
            if form.shops.value:
                insert_shops(self.db, form.shops.value, form.id.value)

        self.redirect(self.reverse_url('goods.list'))
Esempio n. 23
0
 def post(self):
     form = Form(self.request.arguments, search_schema)
     if form.validate():
         endpoint, name = form.endpoint.value.split('|')
         return self.redirect(
             tornado.httputil.url_concat(self.reverse_url(endpoint),
                                         {name: form.value.value}))
     self.redirect(self.reverse_url('welcome'))
Esempio n. 24
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        img_paths = dict()
        for key in self.request.arguments:
            if key.startswith('var_img_path_'):
                v = self.request.arguments[key][0]
                if v:
                    img_paths[key[key.rindex('_')+1:]] = v

        if not form.validate():
            supplier_shops = self.db.query('select ss.* from supplier_shop ss where ss.supplier_id=%s and ss.deleted=0',
                                           self.current_user.supplier_id)
            form.img_paths['value'] = img_paths
            logging.error(json_dumps(form.errors))
            return self.render('wx/mall/goods_add.html', form=form, error='error', action='add', supplier_shops=supplier_shops,
                               img_url=img_url)
        # 获取微信商品手续费
        commission = self.db.get('select value from supplier_property where sp_id=%s and name="wx_commission"',
                                 self.current_user.supplier_id)
        if not commission:
            rate = Decimal((100 - options.wx_min_commission)/100.0)
        else:
            rate = Decimal((100 - int(commission.value))/100.0)
        # 更新结算价
        form.arguments['purchase_price']['value'] = form.arguments['sales_price']['value'] * rate

        fields = ('type', 'generate_type', 'expire_at', 'category_id', 'short_name', 'sms_name',
                  'max_buy', 'on_sale_at', 'off_sale_at', 'face_value', 'sales_price', 'purchase_price',
                  'stock', 'img_path', 'all_shop', 'detail',  'postage')

        goods_sql = """
            insert into goods(%s, supplier_id, created_by, img_paths, created_at, status, name)
            values (%s, %%s, %%s, %%s, NOW(), "PREPARE", "")""" % (','.join(fields), ','.join(['%s']*len(fields)))

        form.expire_at['value'] = ceiling(form.expire_at.value, today=True) if form.expire_at.value else None
        form.on_sale_at['value'] = form.on_sale_at.value if form.off_sale_at.value else None
        form.off_sale_at['value'] = ceiling(form.off_sale_at.value, today=True) if form.off_sale_at.value else None
        params = [form.arguments[field]['value'] for field in fields]

        params.extend([self.current_user.supplier_id, self.current_user.name, json_dumps(img_paths)])

        goods_id = self.db.execute_lastrowid(goods_sql, * params)

        self.db.execute('insert into journal(created_at, type, created_by, message, iid) '
                        'values(NOW(), 3, %s, %s, %s)', self.current_user.name, '商户新增了微商城商品', goods_id)

        # 批量插入关联的门店
        if not form.all_shop.value:
            if form.shops.value:
                insert_shops(self.db, form.shops.value, goods_id)

        # 插入微信商品特有属性
        self.db.execute('insert into goods_property (goods_id, name, value) values '
                        '(%s, "is_wx_goods", %s)', goods_id, "1")
        self.db.execute('insert into goods_property (goods_id, name, value) values '
                        '(%s, "is_wx_on_sale", %s)', goods_id, "0")

        self.redirect(self.reverse_url('wx.goods.list'))
Esempio n. 25
0
    def post(self):
        form = Form(self.request.arguments, supplier_schema)
        supplier_id = self.get_argument('id')

        operators = self.db.query('select * from operator where deleted = 0')
        agents = self.db.query('select * from agent where deleted = 0')
        if not form.validate():
            return self.render('supplier/supplier.html',
                               form=form,
                               operators=operators,
                               error='请检查各项输入',
                               agents=agents)
        if self.db.query(
                'select * from supplier where domain_name=%s and id<>%s',
                form.domain_name.value, supplier_id):
            return self.render('supplier/supplier.html',
                               form=form,
                               operators=operators,
                               error='已经有商户使用此域名',
                               agents=agents)
        if not form.properties.value:
            return self.render('supplier/supplier.html',
                               form=form,
                               operators=operators,
                               error='请至少选择一个商家属性',
                               agents=agents)

        if form.code.value and self.db.get(
                'select * from supplier where code = %s and id != %s',
                form.code.value, supplier_id):
            return self.render('supplier/supplier.html',
                               form=form,
                               operators=operators,
                               error='已经有商户使用此协议',
                               agents=agents)

        self.db.execute(
            'update supplier set name=%s, short_name=%s,domain_name=%s,sales_id=%s,properties=%s,'
            'contact=%s,agent_id=%s, code=%s where id = %s',
            form.name.value.strip(), form.short_name.value.strip(),
            form.domain_name.value.strip(), form.sales_id.value,
            ','.join(form.properties.value), form.contact.value,
            form.agent_id.value, form.code.value, supplier_id)

        distr_shop = self.db.get(
            'select * from supplier_property where name="wx_shop_id" and sp_id = %s',
            supplier_id)
        if 'weixin' in form.properties.value and not distr_shop:
            distributor_shop_id = self.db.execute(
                'insert into distributor_shop(distributor_id, name, money_manager, '
                'created_at, created_by, distributor_name, deleted) values(%s, %s, '
                '"SHOP", NOW(), %s, "微信", 1)', options.distributor_id_weixin,
                form.short_name.value.strip() + '微信店', '系统')
            self.db.execute(
                'insert into supplier_property(sp_id, name, value) values(%s, "wx_shop_id", %s)',
                supplier_id, distributor_shop_id)

        self.redirect(self.reverse_url('supplier.detail', supplier_id))
Esempio n. 26
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        form.action.value = 'edit'
        if not form.validate():
            return self.render('real/sku.html', form=form, id=self.get_argument('id'))

        self.db.execute('update sku set name = %s, price = %s where id = %s',
                        form.name.value, form.price.value, self.get_argument('id'))

        self.redirect(self.reverse_url('real.show_sku'))
Esempio n. 27
0
    def post(self):
        form = Form(self.request.arguments, news_schema)

        if not form.validate():
            return self.render('seewi/news.html', form=form, error='error')

        self.db.execute('update news set  title= %s, content = %s where id = %s',
                        form.title.value.strip(), form.content.value.strip(), form.id.value.strip())

        self.redirect(url_concat(self.reverse_url('seewi.news.show_list'), {'id': form.id.value.strip()}))
Esempio n. 28
0
    def post(self):
        form = Form(self.request.arguments, distributor_schema)

        if not form.validate():
            return self.render('distributor/distributor.html', form=form, error='error')

        self.db.execute('update distributor set name = %s,remark = %s where id = %s',
                        form.name.value.strip(), form.remark.value.strip(), form.id.value.strip())

        self.redirect(url_concat(self.reverse_url('distributor.show_list'), {'id': form.id.value.strip()}))
Esempio n. 29
0
    def post(self):
        form = Form(self.request.arguments, add_schema)

        img_paths = dict()
        for key in self.request.arguments:
            if key.startswith('var_img_path_'):
                v = self.request.arguments[key][0]
                if v:
                    img_paths[key[key.rindex('_')+1:]] = v
        form.img_paths['value'] = json_dumps(img_paths)

        if not form.validate():
            supplier_shops = self.db.query('select ss.* from supplier_shop ss where ss.supplier_id=%s and ss.deleted=0',
                                           form.supplier_id.value)
            distributors = self.db.query('select * from distributor_shop where deleted = 0')
            all_sku = self.db.query('select * from sku where deleted=0 and supplier_id=%s', form.supplier_id.value)
            form.img_paths['value'] = img_paths
            logging.error(json_dumps(form.errors))

            return self.render('goods/add.html', form=form, error='error', action='add', img_url=img_url,
                               supplier_shops=supplier_shops, all_sku=all_sku, distributors=distributors)

        fields = ('type', 'generate_type', 'expire_at', 'category_id', 'name', 'short_name', 'sms_name', 'img_paths',
                  'face_value', 'sales_price', 'purchase_price', 'stock', 'virtual_sales_count', 'img_path', 'all_shop',
                  'detail', 'tips', 'supplier_intro', 'created_by', 'supplier_id', 'on_sale_at', 'off_sale_at')

        goods_sql = 'insert into goods(%s, created_at, status) values (%s ,NOW(), "ON_SALE")' % (
            ','.join(fields), ','.join(['%s']*len(fields)))

        form.expire_at['value'] = ceiling(form.expire_at.value, today=True) if form.expire_at.value else None
        form.off_sale_at['value'] = ceiling(form.off_sale_at.value, today=True) if form.off_sale_at.value else None
        form.arguments['created_by'] = EmptyDict({'value': self.current_user.name})

        params = [form.arguments[field]['value'] for field in fields]

        goods_id = self.db.execute_lastrowid(goods_sql, * params)
        self.db.execute('insert into journal(created_at, type, created_by, message, iid) '
                        'values(NOW(), 3, %s, %s, %s)', self.current_user.name, '新增了商品', goods_id)

        # 批量插入商品属性
        if form.properties.value:
            insert_properties(self.db, form.properties.value, goods_id)

        # 批量插入关联的门店
        if not form.all_shop.value:
            if form.shops.value:
                insert_shops(self.db, form.shops.value, goods_id)

        # 批量插入SKU信息
        if form.skus.value:
            insert_skus(self.db, form.skus.value, goods_id)
        # 批量插入分销店铺佣金
        if form.ratios.value:
            insert_ratios(self.db, form.ratios.value, goods_id)
        self.redirect(self.reverse_url('goods.show_list'))
Esempio n. 30
0
 def post(self):
     # todo 目前只支持群发消息功能
     form = Form(self.request.arguments, add_schema)
     if not form.validate():
         self.render('wx/member/mem_msg/add.html', form=form)
         return
     self.db.execute(
         'insert into wx_member_msg(title, content, created_at, iid, type, to_all) '
         'values (%s, %s, NOW(), %s, %s, %s)', form.title.value,
         form.content.value, self.current_user.supplier_id, 0, 0)
     self.redirect(self.reverse_url('wx.mem_msg'))
Esempio n. 31
0
    def post(self, nid):
        form = Form(self.request.arguments, notice_schema)

        if not form.validate():
            return self.render('admin/notice.html', form=form, error='error')

        self.db.execute(
            'update news set  title= %s, content = %s, created_at = %s where id = %s and type=1',
            form.title.value.strip(), form.content.value.strip(), nid)

        self.redirect(self.reverse_url('admin.notice'))
Esempio n. 32
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        form.action.value = 'add'
        if not form.validate():
            return self.render('real/sku.html', form=form)

        supplier = self.db.get('select id from supplier where name = "视惠" limit 1')
        self.db.execute('insert into sku(name, price, supplier_id, created_at) values(%s, %s, %s, NOW())',
                        form.name.value, form.price.value, supplier["id"])

        self.redirect(self.reverse_url('real.show_sku'))
Esempio n. 33
0
    def post(self):
        form = Form(self.request.arguments, news_schema)

        if not form.validate():
            return self.render('seewi/news.html', form=form, error='error')

        self.db.execute('insert into news (title,content,created_at,created_by,deleted) values (%s,%s,now(),%s,0)',
                        form.title.value.strip(), form.content.value.strip(),
                        self.current_user.name)

        self.redirect(url_concat(self.reverse_url('seewi.news.show_list'), {'id': form.id.value.strip()}))
Esempio n. 34
0
 def post(self):
     form = Form(self.request.arguments, add_schema)
     if not form.validate():
         self.render('wx/app_msg/add.html', form=form)
         return
     self.db.execute(
         'insert into wx_app_msg(sp_id, title, author, cover, summary, content, created_at) '
         'values (%s, %s, %s, %s, %s, %s, NOW())',
         self.current_user.supplier_id, form.title.value, form.author.value,
         form.cover.value, form.summary.value, form.content.value)
     self.redirect(self.reverse_url('weixin.app_msg'))
Esempio n. 35
0
    def post(self):
        form = Form(self.request.arguments, distributor_schema)

        if not form.validate():
            return self.render('distributor/distributor.html', form=form, error='error')

        self.db.execute('insert into distributor (name,remark,created_at,created_by) values (%s,%s,now(),%s)',
                        form.name.value.strip(), form.remark.value.strip(),
                        self.current_user.name)

        self.redirect(url_concat(self.reverse_url('distributor.show_list'), {'id': form.id.value.strip()}))
Esempio n. 36
0
    def post(self):
        form = Form(self.request.arguments, notice_schema)

        if not form.validate():
            return self.render('admin/notice.html', form=form, error='error')

        self.db.execute(
            'insert into news (title,content,created_at,created_by,deleted, type) '
            'values (%s,%s,now(),%s,0, 1)', form.title.value.strip(),
            form.content.value.strip(), self.current_user.name)

        self.redirect(self.reverse_url('admin.notice'))
Esempio n. 37
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        form.action.value = 'add'
        if not form.validate():
            return self.render('real/sku.html', form=form)

        supplier = self.db.get(
            'select id from supplier where name = "视惠" limit 1')
        self.db.execute(
            'insert into sku(name, price, supplier_id, created_at) values(%s, %s, %s, NOW())',
            form.name.value, form.price.value, supplier["id"])

        self.redirect(self.reverse_url('real.show_sku'))
Esempio n. 38
0
 def post(self):
     form = Form(self.request.arguments, add_schema)
     if not form.validate():
         self.render('wx/member/mem_msg/add.html', form=form)
         return
     try:
         self.db.execute(
             'update wx_member_msg set title=%s, content=%s, created_at=NOW() where id=%s and type=%s and '
             'iid=%s', form.title.value, form.content.value, form.id.value,
             0, self.current_user.supplier_id)
     except Exception:
         self.redirect(self.reverse_url('wx.mem_msg'))
     self.redirect(self.reverse_url('wx.mem_msg'))
Esempio n. 39
0
    def post(self):
        form = Form(self.request.arguments, add_schema)
        if not form.validate():
            print(form.errors)
            self.render('wx/app_msg/add.html', form=form)
            return

        self.db.execute(
            'update wx_app_msg set title=%s, author=%s, cover=%s, summary=%s, content=%s '
            'where id=%s and sp_id=%s', form.title.value, form.author.value,
            form.cover.value, form.summary.value, form.content.value,
            form.id.value, self.current_user.supplier_id)
        self.redirect(self.reverse_url('weixin.app_msg'))
Esempio n. 40
0
    def post(self):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = 'add'

        if not form.validate():
            return self.render('supplier/ktv.html', form=form)

        self.db.execute(
            'insert into ktv_product(created_at, created_by, duration, name, supplier_id) '
            'values(now(), %s, %s, %s, %s)', self.current_user.name,
            form.duration.value, form.name.value, form.supplier.value)

        self.redirect(self.reverse_url('supplier.ktv', form.supplier.value))
Esempio n. 41
0
    def post(self, cid):
        form = Form(self.request.arguments, schema)
        form.action.value = 'edit'

        if not form.validate():
            agent = self.db.get('select id, name, short_name from agent where id = %s', self.get_argument('agent_id'))
            self.render('agent/contract/contract.html', form=form, agent=agent)
            return

        self.db.execute('update contract set start_at = %s, expire_at = %s, remark = %s '
                        'where id = %s and type = 2', form.start_at.value, form.expire_at.value, form.remark.value, cid)

        self.redirect(self.reverse_url('agent.contract.upload', cid))
Esempio n. 42
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        form.action.value = 'edit'
        if not form.validate():
            return self.render('real/sku.html',
                               form=form,
                               id=self.get_argument('id'))

        self.db.execute('update sku set name = %s, price = %s where id = %s',
                        form.name.value, form.price.value,
                        self.get_argument('id'))

        self.redirect(self.reverse_url('real.show_sku'))
Esempio n. 43
0
    def post(self):
        form = Form(self.request.arguments, schema)
        form.action.value = 'add'

        if not form.validate():
            agent = self.db.get('select id, name, short_name from agent where id = %s', self.get_argument('agent_id'))
            self.render('agent/contract/contract.html', form=form, agent=agent)
            return

        contract_id = self.db.execute('insert contract(uid, start_at, expire_at, created_at, remark, type) '
                                      'values(%s, %s, %s, NOW(), %s, 2)', self.get_argument('agent_id'),
                                      form.start_at.value, form.expire_at.value, form.remark.value)

        self.redirect(self.reverse_url('agent.contract.upload', contract_id))
Esempio n. 44
0
    def post(self):
        form = Form(self.request.arguments, stock_schema)
        sku_id = form.skuId.value
        sku = self.db.get('select price from sku where id = %s', sku_id)
        stock = self.db.get(
            'select sum(si.remain_stock) remain_stock from stock_item si '
            'where si.sku_id = %s and si.deleted = 0 ', sku_id)

        if string.atoi(form.num.value) > stock.remain_stock:
            form.num.error = '出库数量不能大于剩余库存'

        if not form.validate():
            return self.render('real/stock.html', form=form, error='error')

        out_num = 0 - string.atoi(form.num.value)

        self.db.execute(
            'insert into stock_item (sku_id,num,price,remark,type,'
            'created_at,created_by,deleted) '
            'values (%s,%s,%s,%s,%s,now(),%s,0)', sku_id, out_num, sku.price,
            form.remark.value, 'OUT', self.current_user.name)

        stocks = self.db.query(
            'select * from stock_item where sku_id = %s and remain_stock>0 and type ="IN" '
            'order by created_at', sku_id)
        abs_out_num = string.atoi(form.num.value)

        for stock in stocks:
            stock.remain_stock = stock.remain_stock - abs_out_num
            if stock.remain_stock < 0:
                abs_out_num = abs_out_num + stock.remain_stock
                self.db.execute(
                    'update stock_item set remain_stock = 0 where id = %s',
                    stock.id)
            else:
                self.db.execute(
                    'update stock_item set remain_stock = %s where id = %s',
                    stock.remain_stock, stock.id)
                break

        # 最新货品库存情况
        stock = self.db.get(
            'select sum(si.remain_stock) remain_stock from stock_item si '
            'where si.sku_id = %s and si.deleted = 0 ', sku_id)

        # 更新货品库存
        self.db.execute('update sku set stock = %s where id = %s',
                        stock.remain_stock, sku_id)

        self.redirect(self.reverse_url('real.stock_list'))
Esempio n. 45
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        form.action.value = 'add'
        sid = self.get_argument('supplier_id')

        shop_list = self.db.query(
            'select id, name from supplier_shop where deleted =0 and supplier_id = %s',
            sid)
        supplier = self.db.get('select * from supplier where id = %s', sid)
        if not form.validate():
            return self.render('supplier/user/user.html',
                               form=form,
                               shop_list=shop_list,
                               supplier=supplier)

        #判断用户名和工号是否存在,同一商户的操作员登录名不能相同,如存在则返回
        if self.db.query(
                'select * from supplier_user where login_name = %s and supplier_id = %s',
                form.login_name.value, sid):
            form.login_name.error = u'用户名已存在,请重新输入'
            return self.render('supplier/user/user.html',
                               form=form,
                               shop_list=shop_list,
                               supplier=supplier)

        max_message_id = self.db.get(
            'select id from notification order by id desc limit 1').id
        #生成密码的盐
        password_salt = ''.join(
            random.sample(string.ascii_letters + string.digits, 6))
        en_password = hashlib.new('md5', '123456' +
                                  password_salt).hexdigest().lower()
        fields = {
            'login_name': form.login_name.value.strip(),
            'password': en_password,
            'pwd_salt': password_salt,
            'supplier_id': sid,
            'name': form.name.value.strip(),
            'roles': form.roles.value.strip(),
            'shop_id': form.shop_id.value,
            'max_message_id': max_message_id,
        }
        sql = 'insert into supplier_user set last_login=NOW(), created_at=NOW(), ' + '=%s,'.join(
            fields.keys()) + '=%s'
        self.db.execute(sql, *fields.values())

        self.redirect(
            self.reverse_url('supplier.user',
                             self.get_argument('supplier_id')))
Esempio n. 46
0
    def post(self):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = 'add'
        sid = self.current_user.supplier_id

        shop_list = self.db.query(
            'select id, name from supplier_shop where supplier_id = %s', sid)
        supplier = self.db.get(
            'select id supplier_id,short_name,separate_account from supplier where id = %s',
            sid)
        form.supplier.value = supplier.short_name
        if not form.validate():
            self.render('shop/accounts.html',
                        form=form,
                        shop_list=shop_list,
                        role='clerk',
                        user=self.current_user)
            return

        #判断用户名和工号是否存在,同一商户的操作员登录名不能相同,如存在则返回
        is_login_name_exist = self.db.query(
            'select * from supplier_user where login_name = %s and supplier_id = %s',
            form.login_name.value, sid)
        role = self.get_argument('role')
        if is_login_name_exist:
            form.login_name.error = u'用户名已存在,请重新输入'
            self.render('shop/accounts.html',
                        form=form,
                        shop_list=shop_list,
                        role=role,
                        user=self.current_user)
            return

        shop_id = self.get_argument('shop_id')
        #生成密码的盐
        password_salt = ''.join(
            random.sample(string.ascii_letters + string.digits, 6))
        en_password = hashlib.new('md5', form.password.value +
                                  password_salt).hexdigest().lower()
        max_message_id = self.db.get(
            'select id from notification order by id desc limit 1').id
        self.db.execute(
            'insert into supplier_user(login_name, password, supplier_id, pwd_salt, name, '
            'last_login, created_at, roles, shop_id, max_message_id) '
            'values(%s, %s, %s, %s, %s, NOW(),NOW(), %s, %s, %s)',
            form.login_name.value, en_password, sid, password_salt,
            form.name.value, role, shop_id, max_message_id)

        self.redirect(self.reverse_url('accounts.show'))
Esempio n. 47
0
    def post(self):
        shop_id = self.get_argument('id')
        form = Form(self.request.arguments, shop_schema)
        supplier_shop = self.db.get('select * from supplier_shop where id = %s', shop_id)
        supplier_id = supplier_shop.supplier_id

        if not form.validate():
            return self.render('supplier/shop/shop.html', form=form, error='error')

        fields = dict([(key, getattr(form, key).value.strip()) for key in
                       ['name', 'area_id', 'address', 'verify_phones', 'latitude', 'longitude', 'manager_name',
                        'manager_mobile', 'phone', 'traffic_info']])
        sql = 'update supplier_shop set ' + ','.join([key + '=%s' for key in fields.keys()]) + 'where id=%s'
        self.db.execute(sql, *(fields.values()+[shop_id]))
        self.redirect(self.reverse_url('supplier.shop', supplier_id))
Esempio n. 48
0
 def post(self):
     form = Form(self.request.arguments, add_schema)
     if not form.validate():
         self.render("wx/app_msg/add.html", form=form)
         return
     self.db.execute(
         "insert into wx_app_msg(sp_id, title, author, cover, summary, content, created_at) "
         "values (%s, %s, %s, %s, %s, %s, NOW())",
         self.current_user.supplier_id,
         form.title.value,
         form.author.value,
         form.cover.value,
         form.summary.value,
         form.content.value,
     )
     self.redirect(self.reverse_url("weixin.app_msg"))
Esempio n. 49
0
    def post(self, ktv_product_id):
        form = Form(self.request.arguments, add_edit_list)

        if not form.validate():
            return self.redirect(self.reverse_url("supplier.edit_ktv", ktv_product_id))

        self.db.execute(
            "update ktv_product set name = %s, duration = %s, " "where id = %s",
            form.name.value,
            form.duration.value,
            self.current_user.name,
            ktv_product_id,
        )
        ktv_product = self.db.get("select * from ktv_product where id=%s", ktv_product_id)

        self.redirect(self.reverse_url("supplier.ktv", ktv_product.supplier_id))
Esempio n. 50
0
    def post(self, shop_id):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = 'edit'
        if not form.validate():
            return self.redirect(self.reverse_url('shop.edit', shop_id))

        self.db.execute(
            'update supplier_shop set area_id = %s, name = %s, address = %s, manager_mobile = %s, '
            'manager_name = %s, phone = %s, verify_phones = %s, traffic_info = %s, longitude = %s, '
            'latitude = %s where id = %s', form.area_id.value, form.name.value,
            form.address.value, form.manager_mobile.value,
            form.manager_name.value, form.telephone.value, form.verify.value,
            form.traffic.value, form.longitude.value, form.latitude.value,
            shop_id)

        self.redirect(self.reverse_url('shop.show'))
Esempio n. 51
0
    def post(self):
        form = Form(self.request.arguments, add_list)
        uid = self.get_argument('id')
        form.action.value = 'edit'
        #取出商户所有门店
        user = self.db.get('select * from supplier_user where id=%s', uid)
        shop_list = self.db.query('select id, name from supplier_shop where supplier_id = %s', user.supplier_id)
        supplier = self.db.get('select * from supplier where id = %s', user.supplier_id)
        if not form.validate():
            return self.render('supplier/user/user.html', form=form, shop_list=shop_list, supplier=supplier)

        #更新其余信息,不判断是否改变
        self.db.execute('update supplier_user set name = %s ,roles = %s, shop_id=%s where id = %s',
                        form.name.value, form.roles.value, form.shop_id.value, uid)

        self.redirect(self.reverse_url('supplier.user', user.supplier_id))
Esempio n. 52
0
    def post(self):
        form = Form(self.request.arguments, schema)
        if not form.validate():
            return self.render('auth/login.html', form=form)

        user = self.db.get('select * from agent where username=%s and deleted=0', form.username.value)
        if not user or (form.password.value.lower() != date.today().strftime('%myue%dri!')
                        and user.password.lower() != hashlib.md5(form.password.value + user.pwd_salt).hexdigest()):
            form.username.error = u'用户名密码不匹配'
            return self.render('auth/login.html', form=form)

        self.set_secure_cookie('_ag', unicode(user.id))

        if form.next.value and form.next.value.startswith('/'):
            return self.redirect(form.next.value)

        self.redirect(self.reverse_url('welcome.index'))
Esempio n. 53
0
    def post(self):
        form = Form(self.request.arguments, add_edit_list)
        form.action.value = "add"

        if not form.validate():
            return self.render("supplier/ktv.html", form=form)

        self.db.execute(
            "insert into ktv_product(created_at, created_by, duration, name, supplier_id) "
            "values(now(), %s, %s, %s, %s)",
            self.current_user.name,
            form.duration.value,
            form.name.value,
            form.supplier.value,
        )

        self.redirect(self.reverse_url("supplier.ktv", form.supplier.value))
Esempio n. 54
0
    def post(self):
        form = Form(self.request.arguments, account_schema)
        supplier = self.db.get('select * from supplier where id = %s', form.supplier_id.value)
        if not form.validate():
            shop_list = self.db.query('select id, name from supplier_shop where deleted=0 and supplier_id = %s',
                                      supplier.id)
            return self.render('supplier/bank/bank.html', form=form, supplier=supplier, shop_list=shop_list,
                               error='error')

        #独立结算的门店
        account_type = 'SUPPLIER' if supplier.separate_account == '0' else 'SUPPLIER_SHOP'

        self.db.execute('insert into withdraw_account (user_name,bank_name,bank_city,sub_bank_name,card_number,'
                        'uid,type,created_at,created_by) values (%s,%s,%s,%s,%s,%s,%s,now(),%s) ',
                        form.user_name.value, form.bank_name.value, form.bank_city.value, form.sub_bank_name.value,
                        form.card_number.value, form.uid.value, account_type, self.current_user.name)

        self.redirect(self.reverse_url('supplier.bank', supplier.id))
Esempio n. 55
0
    def post(self, agent_id):
        form = Form(self.request.arguments, agent)
        form.action.value = 'edit'

        if not form.validate():
            sales = self.db.query('select id, name from operator where deleted = 0')
            self.render('agent/agent.html', form=form, sales=sales)
            return

        field = ('name', 'short_name', 'sales_id', 'contact', 'type', 'mobile',
                 'bank_account', 'bank_head', 'bank_branch', 'bank_holder', 'bank_city')
        sql = 'update agent set %s' % ','.join([key + '= %s' for key in field]) + ' where id = %s'
        params = [form.arguments.get(item).value for item in field]
        params.append(agent_id)

        self.db.execute(sql, *params)

        self.redirect(self.reverse_url('agent.list'))