示例#1
0
    def post(self):
        try:
            #dpt_id = self.check_arg('dpt_id', u'^\d{1,2}$')
            dpt_id = self.get_argument('dpt_id')
            staf_name = self.check_arg('name', u'^[\u4e00-\u9fa5\w\s]{1,16}$')
            staf_email = self.check_arg('email', u'^[\w\d@.]{1,64}$', '')
            staf_phone = self.check_arg('mobi', u'^[0-9_-]{4,16}$', '')
            staf_job = self.check_arg('title', u'^[\u4e00-\u9fa5\w\s]{1,16}$',
                                      '')

            svr_dpt = DptShowServices(self.db)
            department = svr_dpt.check_user_dpt(
                self.get_current_user().get('Fmerchant_id'), dpt_id)
            if not department:
                raise Error(1, "dpt not exist")

            staffer_service = StafferServices(self.db)
            staffer_service.add_department_staff(
                self.get_current_user().get('Fmerchant_id'), department,
                staf_name, staf_phone, staf_email, staf_job)
            self.write(Error(0, 'succ').__dict__)

        except MissingArgumentError, e:
            err_msg = "lack param[%s]" % e.arg_name
            return self.write(Error(1, err_msg).__dict__)
示例#2
0
    def post(self):
        self.get_paras_dict()
        _id = self.qdict.get('id')
        data = []

        department_service = DepartmentService(self.db)
        if not _id:
            departments = department_service.get_dpt_by_level(
                self.get_current_user().get('Fmerchant_id'), 0)
            for d in departments:
                dept = {
                    'id': d.Fid,
                    'pId': d.Fdepartment_father,
                    'name': d.Fname,
                    'isParent': True
                }

                #dept={'id':d[0], 'pId':d[4], 'name':d[1],'isParent':True}
                data.append(dept)

        else:
            departments = department_service.get_children_by_parent_id(
                self.get_current_user().get('Fmerchant_id'), _id)
            for d in departments:
                dept = {
                    'id': d.Fid,
                    'pId': d.Fdepartment_father,
                    'name': d.Fname
                }
                data.append(dept)
            #departments = department_service.get_dpt_list(self.get_current_user().get('Fmerchant_id'))
        self.write(ujson.dumps(data))
示例#3
0
    def get(self, dpt_id=None):
        """ 获取当前用户的所有部门 """
        try:
            staffer_service = StafferServices(self.db)
            if dpt_id == '0':
                dpt_id = None
            staffers = staffer_service.get_staffers_by_department_id(
                self.get_current_user().get('Fmerchant_id'), dpt_id)
            svr_dpt = DepartmentService(self.db)
            departments = svr_dpt.get_dpt_list(
                self.get_current_user().get('Fmerchant_id'))

            if not dpt_id:
                dpt_id = ''

            self.echo(
                'crm/department/department_list_py.html', {
                    'staffers': staffers,
                    'departments': departments,
                    '_MERCHANG_DEPARTMENT_TITLES': _MERCHANG_DEPARTMENT_TITLES,
                    'dpt_id': dpt_id,
                })
        except Exception, e:
            if self.settings.get('debug'):
                self.write(str(e))
                raise e
            self.echo('crm/404.html')
示例#4
0
    def post(self, stf_id):
        try:
            stf_id = int(stf_id)
            uid_mct = self.get_current_user().get('Fmerchant_id')
            dpt_id = self.get_argument('dpt_id')
            staf_name = self.check_arg('name', u'^[\u4e00-\u9fa5\w\s]{1,16}$')
            staf_email = self.check_arg('email', u'^[\w\d@.]{1,64}$', '')
            staf_phone = self.check_arg('mobi', u'^[0-9_-]{4,16}$', '')
            staf_job = self.check_arg('title', u'^[\u4e00-\u9fa5\w\s]{1,16}$',
                                      '')

            if stf_id:  #编辑
                data = {}
                data['Fname'] = staf_name
                data['Fdepartment_id'] = dpt_id
                data['Ftitle'] = staf_job
                data['Femail'] = staf_email
                data['Fmobi'] = staf_phone

                svr_dpt = DptShowServices(self.db)
                svr_stf = StafferServices(self.db)
                department = svr_dpt.check_user_dpt(uid_mct,
                                                    data['Fdepartment_id'])
                staffer = svr_stf.get_staffer_by_id(uid_mct, stf_id)
                if not department or not staffer:
                    raise Error(1, "dpt/staffer not exist")

                data['Fdepartment_name'] = department.Ffull_department_name

                if 'staffer_img' in self.request.files:
                    is_ok, filenames = svr_stf.upload_to_server(
                        self, param_name='staffer_img', file_prex='staffers')
                    if is_ok:
                        data['staffer_img_url'] = '/' + filenames[0][
                            'full_name']  # 存数据库的时候在前面要加‘/’

                svr_stf.update_staffer_by_id(stf_id, **data)

            else:  #新增
                svr_dpt = DptShowServices(self.db)
                department = svr_dpt.check_user_dpt(
                    self.get_current_user().get('Fmerchant_id'), dpt_id)
                if not department:
                    raise Error(1, "dpt not exist")

                staffer_service = StafferServices(self.db)
                staffer_service.add_department_staff(
                    self.get_current_user().get('Fmerchant_id'), department,
                    staf_name, staf_phone, staf_email, staf_job)

            self.write(Error(0, 'succ').__dict__)

        except MissingArgumentError, e:
            err_msg = "lack param[%s]" % e.arg_name
            return self.write(Error(1, err_msg).__dict__)
示例#5
0
    def get(self, dpt_id=None):
        staffer_service = StafferServices(self.db)
        staffers = staffer_service.get_staffers_by_department_id(
            self.get_current_user().get('Fmerchant_id'), dpt_id)
        svr_dpt = DptShowServices(self.db)
        departments = svr_dpt.get_dpt_list(
            self.get_current_user().get('Fmerchant_id'))

        self.echo(
            'crm/member/staffers_list_py.html', {
                'staffers': staffers,
                'departments': departments,
                '_MERCHANG_DEPARTMENT_TITLES': _MERCHANG_DEPARTMENT_TITLES
            })
示例#6
0
    def get(self, depart_id=None):
        """ 获取当前部门下的所有子部门 """
        try:
            uid_mct = self.get_current_user().get('Fmerchant_id')
            db_dpt = DepartmentService(self.db)

            #整理成json
            lst_dept = []  #所有部门
            #根,即检索level 0的部门
            Level0_dpt = db_dpt.get_dpt_by_level(uid_mct, 0)
            if Level0_dpt:
                Level0_dpt = Level0_dpt[0]
                dic_dept = {}
                dic_dept['id'] = Level0_dpt.Fid
                dic_dept['text'] = str(Level0_dpt.Fname)
                dic_dept['type'] = 'root'
                dic_dept_state = {}
                dic_dept_state['opened'] = 'true'
                if depart_id == dic_dept.get('id') or depart_id == '':
                    depart_id = Level0_dpt.Fid
                    dic_dept_state['selected'] = 'true'
                dic_dept['state'] = dic_dept_state
                children = []
                #检索level 1的部门
                Level1_dpts = db_dpt.get_dpt_by_level(uid_mct, 1)
                for L1 in Level1_dpts:
                    dpts = self.getAllDeparts(uid_mct, depart_id, L1.Fid)
                    children.append(dpts)
                dic_dept['children'] = children
                lst_dept.append(dic_dept)
            else:  #第一次,没有任何部门,直接创建根部门
                db_ds = DepartmentService(self.db)
                cur_dept = db_ds.add_dpt(uid_mct, '公司名称', -1)
                db_ds.update_dpt(uid_mct,
                                 cur_dept.Fid,
                                 Ffull_departm_id='/' + str(cur_dept.Fid))

                dic_dept = {}
                dic_dept['id'] = cur_dept.Fid
                dic_dept['text'] = str(cur_dept.Fname)
                dic_dept['type'] = 'root'

                lst_dept.append(dic_dept)

            result = ujson.dumps(lst_dept)
            self.write(result)
        except Exception, e:
            if self.settings.get('debug'):
                self.write(str(e))
                raise e
            self.write('')
示例#7
0
    def get(self):
        department_service = DepartmentService(self.db)
        merchant_id = self.get_current_user().get('Fmerchant_id')
        departments = department_service.get_dpt_list(merchant_id)
        order_serice.set_db(self.db)
        orders_from = order_serice.query_order_from_conf(merchant_id)
        data = []
        for d in departments:
            dept = {'id': d[0], 'pId': d[4] and d[4] or 0, 'name': d[1]}
            data.append(dept)

        return self.echo(
            'crm/order/order_add_py.html', {
                'data': data,
                'orders_from': orders_from,
                'now': datetime_format(format='%Y-%m-%d')
            })
示例#8
0
    def get(self, order_id):
        try:
            uid_mct = self.get_current_user().get('Fmerchant_id')

            db_schedule = ShowServices(self.db)
            db_schedule.check_order_owner(uid_mct, order_id)
            schedules = db_schedule.get_schedule(order_id)

            db_staffers = StafferServices(self.db)
            staffers = db_staffers.get_staffers(uid_mct)

            db_site = TemplateServer(self.db)
            sites = db_site.get_site_template(uid_mct)

            department_service = DepartmentService(self.db)
            departments = department_service.get_dpt_list(uid_mct)
            data = []
            for d in departments:
                dept = {'id': d[0], 'pId': d[4] and d[4] or 0, 'name': d[1]}
                data.append(dept)

            db_order = OrderShowServices(self.db)
            db_order.check_order_owner(uid_mct, order_id)
            order, stf = db_order.get_order_info(order_id, uid_mct)
            order.Forder_type_str = _TYPE_ORDER[int(order.Forder_type)]

            schedule_service.set_db(self.db)
            schedule_categorys = schedule_service.query_schedule_category(
                uid_mct)

            self.echo(
                'crm/order/schedule_list_py.html', {
                    'items': schedules,
                    'order': order,
                    'order_id': order_id,
                    'stfs': staffers,
                    'schedule_categorys': schedule_categorys,
                    'sites': sites,
                    'data': data
                })

        except Error, e:
            return self.write(e.__dict__)
示例#9
0
    def getAllDeparts(self, uid_mct, L1_depart_id, depart_id):
        db_dpt = DepartmentService(self.db)
        dpt = db_dpt.get_dpt_by_id(uid_mct, depart_id)

        dic_dept = {}
        dic_dept['id'] = dpt.Fid
        dic_dept['text'] = str(dpt.Fname)
        dic_dept_state = {}
        dic_dept_state['opened'] = 'true'
        if L1_depart_id == str(dic_dept.get('id')):
            dic_dept_state['selected'] = 'true'
        dic_dept['state'] = dic_dept_state

        child_dpts = db_dpt.get_dpt_by_father_id(uid_mct, dpt.Fid)
        if child_dpts:  #存在子
            lst_c_dpts = []
            for c_dpt in child_dpts:
                lst_c_dpts.append(
                    self.getAllDeparts(uid_mct, L1_depart_id, c_dpt.Fid))
            dic_dept['children'] = lst_c_dpts

        return dic_dept
示例#10
0
    def post(self):
        """ 添加部门 """
        dic_result = {}
        dic_result['stat'] = 'succ'
        dic_result['msg'] = ''

        try:
            uid_mct = self.get_current_user().get('Fmerchant_id')
            name = self.check_arg('dpt_name', u'^[\u4e00-\u9fa5\w\s]{1,21}$')
            dpt_id = self.get_argument('dpt_pre_id', '0')
            if dpt_id == 'NaN':
                pre_id = 0
            else:
                pre_id = self.check_arg('dpt_pre_id', u'^\d{1,8}$')

            db_orders = DepartmentService(self.db)
            dpt = db_orders.add_dpt(uid_mct, name, pre_id)
            dic_result['id'] = dpt.Fid
            self.write(ujson.dumps(dic_result))

        except MissingArgumentError, e:
            err_msg = "lack param[%s]" % e.arg_name
            return self.write(Error(1, err_msg).__dict__)
示例#11
0
    def post(self):
        """ 修改部门名称 """
        try:
            uid_mct = self.get_current_user().get('Fmerchant_id')
            name = self.check_arg('dpt_name',
                                  u'^[\u4e00-\u9fa5\w\s]{1,21}$')  #要更新的名称
            dpt_id = self.check_arg('dpt_id', u'^\d{1,8}$')

            #检索当前对象
            db_orders = DepartmentService(self.db)
            cur_dept = db_orders.get_dpt_by_id(uid_mct, dpt_id)
            if not cur_dept:
                if int(dpt_id) == 0:  #根,直接新建
                    cur_dept = db_orders.add_dpt(uid_mct, name, -1)

                    db_orders.update_dpt(uid_mct,
                                         cur_dept.Fid,
                                         Ffull_departm_id='/' +
                                         str(cur_dept.Fid))
                else:  #其他子部门
                    raise '部门不存在!'

            #准备全路径名称
            old_name = cur_dept.Fname
            new_full_depart_name = ''
            old_full_depart_name = cur_dept.Ffull_department_name
            if old_full_depart_name[-(len(old_name) + 1):] == (
                    '/' + old_name):  #首,结尾匹配
                new_full_depart_name = old_full_depart_name[:-(
                    len(old_name) + 1)] + ('/' + name)
            elif old_full_depart_name.find('/' + old_name + '/') > -1:  #中间匹配
                new_full_depart_name = old_full_depart_name.replace(
                    '/' + old_name + '/', ('/' + name + '/'))
            else:  #未匹配到时,根据父的全路径重建???
                pass

            #更新
            db_orders.update_dpt(uid_mct,
                                 cur_dept.Fid,
                                 Fname=name,
                                 Ffull_department_name=new_full_depart_name)

            #更新子的全路径名称
            staffer_service = StafferServices(self.db)
            child_dpts = db_orders.get_child_dpts(uid_mct,
                                                  cur_dept.Ffull_departm_id)
            for c_dpt in child_dpts:
                c_new_full_depart_name = c_dpt.Ffull_department_name
                c_new_full_depart_name = new_full_depart_name + c_new_full_depart_name[
                    len(old_full_depart_name):]
                db_orders.update_dpt(
                    uid_mct,
                    c_dpt.Fid,
                    Ffull_department_name=c_new_full_depart_name)

                #更新员工表中的部门全路径
                staffer_service.update_staffer_full_depart_name(
                    c_dpt.Fid, c_new_full_depart_name)

            #更新员工表中的部门全路径
            staffer_service.update_staffer_full_depart_name(
                cur_dept.Fid, new_full_depart_name)

            self.write(Error(0, 'succ').__dict__)

        except MissingArgumentError, e:
            err_msg = "lack param[%s]" % e.arg_name
            return self.write(Error(1, err_msg).__dict__)
示例#12
0
    def get(self, order_id):
        try:
            uid = self.get_current_user().get('Fmerchant_id')
            db_orders = ShowServices(self.db)
            order_serice.set_db(self.db)
            #db_orders.check_order_owner(uid, order_id)
            o, staffs = db_orders.get_order_info(order_id, uid)
            item = {}
            item['order_id'] = o.Fid
            item['order_id_user'] = o.Forder_id_user
            item['order_name'] = o.Fuser_name
            item['order_mobi'] = o.Fuser_mobi
            item['order_user_birth'] = str(o.Fuser_birth)
            item['order_type'] = o.Forder_type
            if o.Forder_type in (1, '1'):  # 婚纱
                item['order_name_ex'] = o.Fuser_name_ex
                item['order_mobi_ex'] = o.Fuser_mobi_ex
                item['order_birth_ex'] = str(o.Fuser_birth_ex)
            item['order_amount'] = int(o.Famount)
            item['order_date'] = str(o.Fcreate_time)
            item['order_comment'] = o.Fcomment
            item['order_stf_id'] = o.Fuid_stf  #.replace('&', ' ')
            if staffs:
                item['order_stf_name'] = ' '.join([n.Fname for n in staffs])
            else:
                item['order_stf_name'] = ''
            item['pre_order_acount'] = o.Fdeposit
            department_service = DepartmentService(self.db)
            departments = department_service.get_dpt_list(uid)
            starff_service.set_db(self.db)
            if item['order_stf_id']:
                user_ids = item['order_stf_id'].split('&')
            else:
                user_ids = []
            department_ids = []

            _order_from = ','.join([
                str(d[0]) for d in order_serice.query_orderfromids_by_order_id(
                    o.Fid, uid)
            ])
            orders_fron_conf = order_serice.query_order_from_conf(uid)
            retainages = order_serice.query_retainages(o.Fid)
            if user_ids:
                department_ids = starff_service.get_department_id_by_user(
                    user_ids)
                department_ids = list(set([d[0] for d in department_ids if d]))

            data = []
            for d in departments:
                dept = {'id': d[0], 'pId': d[4] and d[4] or 0, 'name': d[1]}
                data.append(dept)
            self.echo(
                'crm/order/order_edit_py.html', {
                    'item': item,
                    'retainages': retainages,
                    'data': data,
                    'staffers': staffs,
                    'department_ids': department_ids,
                    '_order_from': _order_from,
                    'orders_from': orders_fron_conf
                })
        except Exception, e:
            print e
            if self.settings.get('debug'):
                self.write(str(e))
                raise
            self.write(Error(3, 'error').__dict__)