Пример #1
0
def create_company(name, **options):
    result = {'success': False, 'message': ''}
    query = {}
    if not name:
        result['message'] = '公司名称不存在'
        return result
    query['name'] = name
    item = DesignCompany.objects(name=name, deleted=0).first()
    if not item:
        options['name'] = name
        item = DesignCompany(**options)
        ok = item.save()
        if not ok:
            result['message'] = '创建公司信息失败'
            return result
    result['success'] = True
    result['data'] = item
    return result
Пример #2
0
def update_d3in_company_core(d):
    result = {'success': False, 'message': ''}
    if not d['company_name']:
        result['message'] = 'D3in公司不存在!'
        return result
    print("公司名称: %s" % d['company_name'])

    query = {}

    query['d3ing_id'] = d['id']
    # 简称
    if d['company_abbreviation']:
        query['short_name'] = d['company_abbreviation']
    # 分公司数量
    if d['branch_office']:
        query['branch'] = str(d['branch_office'])
    # 英文名称
    if d['company_english']:
        query['english_name'] = d['company_english']
    # 规模
    if d['company_size']:
        query['scale'] = d['company_size']
        query['scale_label'] = d['company_size_val']
    # 简介
    if d['company_profile']:
        query['description'] = d['company_profile']
    # 网址
    if d['web']:
        query['url'] = d['web']
    # LOGO
    if d['logo_image']:
        query['logo_url'] = d['logo_image']['logo']
    ## 联系信息
    if d['province_value']:
        query['province'] = d['province_value']
    if d['city_value']:
        query['city'] = d['city_value']
    if d['address']:
        query['address'] = d['address']
    if d['contact_name']:
        query['contact_name'] = d['contact_name']
    if d['phone']:
        query['contact_phone'] = d['phone']
    if d['email']:
        query['contact_email'] = d['email']

    print("更新字段: %s" % query)

    if not query:
        result['message'] = '更新内容不空!'
        return result

    company = DesignCompany.objects(name=d['company_name'], deleted=0).first()
    # 没有则创建
    if not company:
        query['name'] = d['company_name']
        query['status'] = 1
        company = DesignCompany(**query)
        ok = company.save()
        print("创建新公司: %s" % query['name'])
        if ok:
            cres = submit_company_queue(d['company_name'], d['id'])
            if cres['success']:
                print("已更新到公司队列")
    else:
        ok = company.update(**query)

    if not ok:
        result['message'] = '创建/更新失败!'
        return result
    result['success'] = True
    result['data'] = company
    return result