Esempio n. 1
0
 def get(self):
     form = MerchantForm()
     message = ''
     merchant_id = self.get_argument('nid', None)
     if not merchant_id:
         crumbs = '添加商户'
         method = 'POST'
         print(crumbs)
     else:
         crumbs = '编辑商户'
         # 依赖注入
         Mapper.register(modelMerchantService, MerchantRepository())
         Mapper.register(MerchantService, modelMerchantService())
         merchant_service = MerchantService()
         # 获取当前商户的详细信息
         detail = merchant_service.get_merchant_detail_by_nid(merchant_id)
         # print(detail.success)
         # print(detail.message)
         # print(detail.rows)
         # 获取错误信息,默认空字符串
         message = detail.message
         county_caption = detail.rows.pop('county_caption')
         county_id = detail.rows.get('county_id')
         form.county_id.widget.choices.append({
             'value': county_id,
             'text': county_caption
         })
         method = 'PUT'  # put方法用来做修改操作
         form.init_value(detail.rows)
     self.render('Merchant/MerchantEdit.html',
                 form=form,
                 crumbs=crumbs,
                 method=method,
                 summary=message,
                 nid=merchant_id)
Esempio n. 2
0
    def post(self):
        # 依赖注入
        Mapper.register(ModelProductService, ProductRepository())
        Mapper.register(ProductService, ModelProductService())
        product_service = ProductService()

        jd_buy_cookie = self.get_cookie('jd_buy_list')
        buy_str = escape.url_unescape(jd_buy_cookie)
        buy_list = json.loads(buy_str)
        data_list = []
        for item in buy_list:
            print(item)
            temp = {}
            product_title = item['product_title']
            product_img = item['product_img']

            count = item['count']
            price_id = item['price_id']
            temp["count"] = count
            temp["price_id"] = price_id

            result = product_service.fetch_price_detail(int(price_id))

            data_list.append(temp)
        print(data_list)
        print(result)
        self.write(json.dumps(data_list))
Esempio n. 3
0
    def get(self, *args, **kwargs):
        product_id = kwargs.get('product_id', None)
        price_id = kwargs.get('price_id', None)
        if not product_id or not price_id:
            self.redirect('/Index.html')
            return

        # 依赖注入
        Mapper.register(ModelProductService, ProductRepository())
        Mapper.register(ProductService, ModelProductService())
        product_service = ProductService()
        # 根据商品ID获取商品信息,商户信息,价格列表,图片
        # p = ProductService(ProductRepository())
        product_dict = product_service.fetch_product_detail(
            product_id, price_id)

        self.render('Home/Detail.html', product_dict=product_dict.rows)
Esempio n. 4
0
    def put(self):
        """
        修改
        """
        # 依赖注入
        Mapper.register(modelMerchantService, MerchantRepository())
        Mapper.register(MerchantService, modelMerchantService())
        merchant_service = MerchantService()

        message = ''
        form = MerchantForm()
        merchant_id = self.get_argument('nid', None)
        try:
            is_valid = form.valid(self)

            if is_valid:
                if form._value_dict['county_id'] == '0':
                    form._error_dict['county_id'] = '请选择县(区)ID'
                else:
                    nid = form._value_dict.pop('nid')
                    del form._value_dict['city_id']
                    del form._value_dict['province_id']

                    merchant_service.update_merchant(nid, **form._value_dict)
                    self.redirect('MerchantManager.html')
                    return
            else:
                form.init_value(form._value_dict)

        except Exception as e:
            message = str(e)

        detail = merchant_service.get_merchant_detail_by_nid(merchant_id)
        county_caption = detail.rows.pop('county_caption')
        county_id = detail.rows.get('county_id')
        form.county_id.widget.choices.append({
            'value': county_id,
            'text': county_caption
        })

        self.render('Merchant/MerchantEdit.html',
                    form=form,
                    crumbs='编辑商户',
                    method='PUT',
                    summary=message,
                    nid=merchant_id)
Esempio n. 5
0
    def get(self):
        """
        根据参数,获取产品信息(type:自营(商户ID),type:所有商品)
        后台管理用户登陆成功后,Session中保存自营ID
        自营ID=1
        """
        # 手动获取京东自营ID为14
        merchant_id = 14
        page = int(self.get_argument('page', 1))
        rows = int(self.get_argument('rows', 10))
        start = (page - 1) * rows
        # 依赖注入
        Mapper.register(modelProductService, ProductRepository())
        Mapper.register(ProductService, modelProductService())
        product_service = ProductService()

        response = product_service.get_page_by_merchant_id(
            merchant_id, start, rows)
Esempio n. 6
0
    def delete(self):
        """
        删除
        """
        # 依赖注入
        Mapper.register(modelMerchantService, MerchantRepository())
        Mapper.register(MerchantService, modelMerchantService())
        merchant_service = MerchantService()

        ret = {'success': False, 'message': ''}
        merchant_id = self.get_argument('nid', None)
        # print(merchant_id)
        if not merchant_id:
            ret['message'] = '请选着要删除的行'
        else:
            rows = merchant_service.delete_merchant(int(merchant_id))
            ret = rows.__dict__
        print(ret)
        self.write(json.dumps(ret))
Esempio n. 7
0
    def post(self):
        """
        创建商户
        """
        method = self.get_argument('_method', None)

        if method == 'PUT':
            return self.put(self)

        message = ''
        form = MerchantForm()
        try:
            is_valid = form.valid(self)
            if is_valid:
                if form._value_dict['county_id'] == '0':
                    form._error_dict['county_id'] = '请选择县(区)ID'
                else:
                    del form._value_dict['nid']
                    del form._value_dict['city_id']
                    del form._value_dict['province_id']
                    print(form._value_dict)
                    # 依赖注入
                    Mapper.register(modelMerchantService, MerchantRepository())
                    Mapper.register(MerchantService, modelMerchantService())
                    merchant_service = MerchantService()

                    merchant_service.create_merchant(**form._value_dict)
                    self.redirect('/MerchantManager.html')
                    return
            else:
                form.init_value(form._value_dict)
        except IntegrityError as e:
            message = '商户名称或登陆用户必须唯一'
        except Exception as e:
            message = str(e)

        self.render('Merchant/MerchantEdit.html',
                    form=form,
                    crumbs='添加商户',
                    method='POST',
                    summary=message,
                    nid=None)
Esempio n. 8
0
    def get(self):
        # 依赖注入
        Mapper.register(modelMerchantService, MerchantRepository())
        Mapper.register(MerchantService, modelMerchantService())
        merchant_service = MerchantService()

        ret = {'success': False, 'message': ""}
        # MerchantManager.html发送过来的
        req_type = self.get_argument('type', None)
        if req_type == 'pagination':
            page = int(self.get_argument('page', 1))
            rows = int(self.get_argument('rows', 10))
            start = (page - 1) * rows
            rows_list = merchant_service.get_merchant_by_page(start, rows)
            rows_count = merchant_service.get_merchant_count()
            ret['success'] = all([rows_list.success, rows_count.success])
            ret['message'] = rows_list.message + rows_count.message
            ret.update({'total': rows_count.rows, 'rows': rows_list.rows})
            # print(ret)
            self.write(json.dumps(ret))
            return
        self.render('Merchant/MerchantManager.html')
Esempio n. 9
0
 def post(self):
     post_data = self.get_argument('post_data', None)
     post_data_dict = json.loads(post_data)
     if self.session['CheckCode'].upper() == post_data_dict.get(
             'checkcode').upper():
         user = post_data_dict.get('username', None)
         if re.match(pattern, user):
             email = user
             user = None
         else:
             email = None
         pwd = post_data_dict.get('password', None)
         # Service层
         user_request = UserRequest(username=user,
                                    email=email,
                                    password=pwd)
         Mapper.register(ModelUserService, UserRepository())
         Mapper.register(UserService, ModelUserService())
         user_service = UserService()  # 依赖注入Model(业务逻辑层)的对应‘协调’
         response = user_service.check_login(user_request)
         if response.status:
             self.session['is_login'] = True
         response_str = json.dumps(response.status, cls=JsonCustomEncoder)
         self.write(response_str)
Esempio n. 10
0
    def get(self, *args, **kwargs):
        # 依赖注入
        Mapper.register(ModelCategoryService, CategoryRepository())
        Mapper.register(CategoryService, ModelCategoryService())
        category_service = CategoryService()
        # 获取一级分类
        # 循环一级分类,获取二级分类
        # 循环二级分类,获取三级分类
        # c = CategoryService(CategoryRepository())
        category_list = category_service.get_all_category()
        # print(category_list)

        # 依赖注入
        Mapper.register(ModelProductService, ProductRepository())
        Mapper.register(ProductService, ModelProductService())
        product_service = ProductService()
        # p = ProductService(ProductRepository())
        product_dict = product_service.fetch_index_product()
        # print(product_dict)
        self.render('Home/Index.html',
                    category_list=category_list,
                    product_dict=product_dict.rows)
Esempio n. 11
0
 def __init__(self, opts=None, inject=dict):
     print('init engine')
     Mapper.register(Core, inject)
     self.core = Core()