Example #1
0
    def post(self):
        print('get_player_info')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            player_id = data['player_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)
        player = Data.find('player', [('id', '=', player_id)])
        player_info = {}
        if player:
            player_info['nickname'] = player['nickname']
            player_info['phone'] = player['phone']
            player_info['sex'] = player['sex']
            player_info['add_time'] = player['add_time']
            player_info['open_id'] = player['open_id']
            player_info['union_id'] = player['union_id']

        result = {'player_info': player_info}
        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='会员详细信息',
                           player_id=player_id)

        return
Example #2
0
    def post(self):
        print('update_auth_template')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            temp_id = data['temp_id']
            name = data['name']
            auth = data['auth']
            comment = data['comment']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        params = {}
        params['name'] = name
        params['auth'] = auth
        params['comment'] = comment
        params['utime'] = int(time.time())

        Data.update('admin_temp', [('id', '=', temp_id)], params)

        result = {'commit': 1}

        self.send_ok(result)

        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='修改权限模板',
                           temp_id=data['temp_id'])
        return
Example #3
0
    def post(self):
        print('del_adv')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            adv_id = data['adv_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)
        info = Data.find('adv', [('id', '=', adv_id)])
        if info is None:
            return self.send_faild(error.ERROR_DATA_NOT_FOUND)

        if info['status'] == 0:
            status = 1
        else:
            status = 0

        Data.update('adv', [('id', '=', adv_id)], {'status': status})
        result = {'commit': 1}
        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='启用/禁用广告',
                           adv_id=adv_id)

        return
Example #4
0
    def post(self):
        print('get_adv_info')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            adv_id = data['adv_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)
        adv = Data.find('adv', [('id', '=', adv_id)])
        adv_info = {}
        if adv:
            adv_info['adv_name'] = adv['adv_name']
            adv_info['postion'] = adv['postion']
            adv_info['url'] = adv['url']
            adv_info['ctime'] = adv['ctime']
            adv_info['comment'] = adv['comment']
            adv_info['status'] = adv['status']
            img = Data.find('adv_photo', [('adv_id', '=', adv_id)])
            adv_info['img'] = img['photo_url']

        result = {'adv_info': adv_info}
        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='广告详细信息',
                           adv_id=adv_id)

        return
Example #5
0
    def post(self):
        print('delete_auth_template')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            temp_id = data['temp_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        res = Data.find('admin_temp', [('id', '=', temp_id)])
        if res is None:
            return self.send_faild(error.ERROR_DATA_NOT_FOUND)

        Data.update('admin_temp', [('id', '=', temp_id)], {'status': 1})

        result = {'commit': 1}

        self.send_ok(result)

        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='删除权限模板',
                           temp_id=data['temp_id'])
        return
    def post(self):
        print('update_admin_detail')

        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            admin_id = data['admin_id']
            status = data['status']
            auth_temp = data['admin_temp_id']
            comment = data['comment']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        if admin_id == 1:
            print('初始账号不能改信息')
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        admin_info = Data.find('admin_auth', [('admin_id', '=', admin_id)])
        if admin_info is None:
            return self.send_faild(error.ERROR_NO_USER)

        god_info = Data.find('admin', [('id', '=', admin_id)])
        if god_info is None:
            return self.send_faild(error.ERROR_NO_USER)

        # 更新模板
        Data.update('admin_auth', [('id', '=', admin_id)], {'auth_id': auth_temp})

        god_info = {
            'utime': common.time_to_str(int(time.time())),
            'status': status,
            'comment': comment
        }

        try:
            Data.update('admin', [('id', '=', admin_id)], god_info)
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_TIMEOUT)

        result = {
            'commit': 1
        }
        self.send_ok(result)

        write_admin_record(operate_id=admin_base['id'], operate_desc='更新管理员详情', admin_id=admin_id)
        return
Example #7
0
    def post(self):
        print('send_advphoto')
        admin_base = self.get_admin_base()
        if admin_base is None:
            self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            adv_id = data['adv_id']
            pic_body = data['title']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        adv_info = Data.find('adv', [('id', '=', adv_id)])
        if adv_info is None:
            return self.send_faild(error.ERROR_NO_USER)

        adv_id = adv_info['id']

        img_data = pic_body.split(',')[1]

        img_data = base64.b64decode(img_data)
        path = 'pics/' + common.get_file_md5(img_data) + '_title' + '.jpg'

        open(path, 'wb').write(img_data)

        title_line = Data.find('adv_photo', [('adv_id', '=', adv_id),
                                             ('is_title', '=', 1)])

        if title_line is None:
            params = {
                'adv_id': adv_id,
                'photo_url': config.logical_url + '/' + path.split('/')[-1],
            }
            Data.insert('adv_photo', params)
        else:
            params = {
                'photo_url': config.logical_url + '/' + path.split('/')[-1],
            }
            Data.update('adv_photo', [('adv_id', '=', adv_id)], params)
            # 记录进数据库

        reply = {'pic_done': 0}
        self.send_ok(reply)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='上传广告图片',
                           adv_id=adv_id)

        return
    def post(self):
        print('add_admin')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            username = data['username']
            pw = data['pswd']
            status = data['status']
            auth_temp = data['admin_temp_id']
            comment = data['comment']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        if_user = Data.find('admin', [('username', '=', username)])
        if if_user is not None:
            return self.send_faild(error.ERROR_INSERT_USER)

        admin_params = {
            'username': username,
            'password_hash': generate_password_hash(pw),
            'status': status,
            'comment': comment,
            'ctime': common.time_to_str(int(time.time())),
            'auth_id': auth_temp,
        }

        Data.insert('admin', admin_params)
        new_admin_info = Data.find('admin', [('username', '=', username)])
        if new_admin_info is None:
            return self.send_faild(error.ERROR_DATA_NOT_FOUND)
        admin_id = new_admin_info['id']

        admin_auth_info = {
            'auth_id': auth_temp,
            'god_id': admin_id
        }
        Data.insert('admin_auth', admin_auth_info)
        result = {
            'commit': 1
        }
        self.send_ok(result)

        write_admin_record(operate_id=admin_base['id'], operate_desc='添加管理员', admin_id=admin_id)
        return
Example #9
0
    def post(self):
        print('get_device_detail')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            imei = data['imei']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        test_list = []
        test_info_list = Data.select('user_test_result', [('imei', '=', imei)])
        if test_info_list != None:
            for test_info in test_info_list:
                params = {}
                player_id = test_info['user_id']
                player_info = Data.find('player_member',
                                        [('id', '=', player_id)])
                if player_info == None:
                    continue
                params['player_name'] = player_info['name']
                params['phone'] = player_info['phone']
                params['comment'] = test_info['comment']
                params['left_eye'] = test_info['left_eye']
                params['right_eye'] = test_info['right_eye']
                if test_info['astigmatism_left'] + test_info[
                        'astigmatism_left'] > 0:
                    params['astigmatism'] = 1
                else:
                    params['astigmatism'] = 0
                test_list.append(params)

        result = {'test_list': test_list}

        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='获取设备测试记录',
                           device_id=device_id)

        return
    def post(self):
        print('delete_admin')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            admin_id = data['admin_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        admin_info = Data.find('admin_auth', [('id', '=', admin_id)])
        if admin_info is None:
            return self.send_faild(error.ERROR_NO_USER)

        god_info = Data.find('admin', [('id', '=', admin_info['god_id'])])
        if god_info['status'] == 0:
            params = {
                'utime': common.time_to_str(int(time.time())),
                'status': 1,
            }
            Data.update('admin', [('id', '=', admin_info['god_id'])], params)
        else:
            params = {
                'utime': common.time_to_str(int(time.time())),
                'status': 0,
            }
            Data.update('admin', [('id', '=', admin_info['god_id'])], params)

        result = {
            'commit': 1
        }
        self.send_ok(result)

        write_admin_record(operate_id=admin_base['id'], operate_desc='禁用/启用管理员', admin_id=admin_id)
        return
Example #11
0
    def post(self):
        print('get_device_detail')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            device_id = data['device_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        device_info = Data.find('devices', [('id', '=', device_id)])
        if device_info == None:
            return self.send_faild(error.ERROR_DATA_NOT_FOUND)
        params = {}
        params['imei'] = device_info['imei']
        params['ctime'] = device_info['ctime']
        params['times'] = device_info['times']
        params['status'] = device_info['status']
        params['user_id'] = device_info['user_id']
        user_info = Data.find('player', [('id', '=', params['user_id'])])
        if user_info is None:
            return self.send_faild(error.ERROR_DATA_NOT_FOUND)
        params['user_nickname'] = user_info['nickname']

        result = {
            'device_info': params,
        }

        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='获取设备详情',
                           device_id=device_id)

        return
Example #12
0
    def post(self):
        print('add_adv')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            adv_name = data['adv_name']
            postion = data['postion']
            url = data['url']
            comment = data['comment']
            status = data['status']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        ctime = int(time.time())

        adv_info = {}
        adv_info['adv_name'] = adv_name
        adv_info['postion'] = postion
        adv_info['ctime'] = ctime
        adv_info['comment'] = comment
        adv_info['status'] = status

        Data.insert('adv', adv_info)
        adv = Data.find_last('adv', [('id', '!=', 0)], info='id', limit=1)
        result = {'commit': 1}
        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='新增广告',
                           adv_id=adv['id'])

        return
    def post(self):
        print('get_admin_detail')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            admin_id = data['admin_id']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        admin_info = Data.find('admin_auth', [('god_id', '=', admin_id)])
        if admin_info is None:
            return self.send_faild(error.ERROR_NO_USER)

        god_info = Data.find('admin', [('id', '=', admin_info['god_id'])])
        if god_info is None:
            return self.send_faild(error.ERROR_NO_USER)
        admin = {
            'username': god_info['username'],
            'status': god_info['status'],
            'ctime': god_info['ctime'],
            'admin_temp_id': admin_info['auth_id']
        }

        result = {
            'admin_info':admin
        }

        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'], operate_desc='获取管理员详情', admin_id=admin_id)

        return
Example #14
0
    def post(self):
        print('create_auth_template')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            name = data['name']
            auth = data['auth']
            comment = data['comment']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        params = {}
        params['name'] = name
        params['auth'] = auth
        params['comment'] = comment
        params['ctime'] = int(time.time())
        Data.insert('admin_temp', params)

        # 记录本条权限模板的id
        temp_info = Data.find_last('admin_temp', [('id', '!=', 0)],
                                   info='id',
                                   limit=1)

        result = {'commit': 1}

        self.send_ok(result)

        write_admin_record(operate_id=admin_base['id'],
                           operate_desc='创建权限模板',
                           temp_id=temp_info['id'])
        return
Example #15
0
    def post(self):
        print('get_adv_list')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            adv_name = data['adv_name']
            postion = data['postion']
            start_time = data['start_time']
            end_time = data['end_time']
            status = data['status']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        if adv_name == '':
            adv_name = "%"
        if start_time != '':
            start_time += ' 00:00:00'
            start_time = str_to_time(start_time)
        else:
            start_time = 0
        if end_time != '':
            end_time += ' 00:00:00'
            end_time = str_to_time(end_time)
        else:
            end_time = int(time.time())

        adv = []
        adv_list = Data.select('adv',
                               [('adv_name', 'like', '%{}%'.format(adv_name))],
                               order=('add_time', 'desc'))

        if adv_list:
            for ad in adv_list:
                if start_time <= int(ad['add_time']) <= end_time:
                    params = {}
                    params['adv_name'] = ad['adv_name']
                    params['postion'] = ad['postion']
                    params['img'] = ad['img']
                    params['url'] = ad['url']
                    params['ctime'] = ad['ctime']
                    params['comment'] = ad['comment']
                    params['status'] = ad['status']
                    adv.append(params)

        res = []
        if adv:
            for i in adv:
                if i == None:
                    continue
                if postion != '':
                    if postion in i['postion']:
                        res.append(i)
                else:
                    res.append(i)

        res1 = []
        for i in res:
            if int(status) == i['status']:
                res1.append(i)

        result = {'adv_info_list': res1}
        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'], operate_desc='广告列表')

        return
Example #16
0
    def post(self):
        print('get_player_list')
        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if not self.is_god():
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            player_name = data['player_name']
            player_phone = data['player_phone']
            start_time = data['start_time']
            end_time = data['end_time']
            status = data['status']  # 0代表用户账户正常,1代表冻结
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        if player_phone == '':
            player_phone = "%"
        if start_time != '':
            start_time += ' 00:00:00'
            start_time = str_to_time(start_time)
        else:
            start_time = 0
        if end_time != '':
            end_time += ' 00:00:00'
            end_time = str_to_time(end_time)
        else:
            end_time = int(time.time())

        players = []
        player_list = Data.select(
            'player', [('phone', 'like', '%{}%'.format(player_phone))],
            order=('join_time', 'desc'))

        if player_list:
            for player in player_list:
                if start_time <= int(player['join_time']) <= end_time:
                    players.append(player)
            res_list = list(map(admin_tools.get_player_list, players))
        else:
            res_list = []

        res = []
        for i in res_list:
            if i == None:
                continue
            if player_name != '':
                if player_name in i['name']:
                    res.append(i)
            else:
                res.append(i)

        res1 = []
        for i in res:
            if int(status) == i['status']:
                res1.append(i)

        result = {'player_info_list': res1}
        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'], operate_desc='会员管理首页')

        return
Example #17
0
    def post(self):
        print('get_devices_list')

        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            imei = data['imei']
            player_name = data['player_name']
            phone = data['phone']
            start_time = data['start_time']
            end_time = data['end_time']
            status = data['status']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        if start_time != '':
            start_time += ' 00:00:00'
            start_time = str_to_time(start_time)
        else:
            start_time = 0
        if end_time != '':
            end_time += ' 00:00:00'
            end_time = str_to_time(end_time)
        else:
            end_time = int(time.time())

        devices = Data.select('devices', [('id', '!=', 0)])
        devices_list = []
        if devices:
            for device in devices:
                user_id = device['user_id']
                user_info = Data.find('player', [('id', '=', user_id)])
                if user_info is None:
                    continue
                dev_info = Data.find('dev_main', [('id', '=', device['id'])])
                if dev_info is None:
                    continue
                params = {}
                params['id'] = device['id']
                params['player_name'] = user_info['nickname']
                params['phone'] = user_info['phone']
                params['imei'] = device['imei']
                params['ctime'] = device['ctime']
                params['status'] = device['status']
                devices_list.append(params)

        # 筛选
        res = []
        res1 = []
        res2 = []
        res3 = []
        res4 = []
        if len(devices_list) > 0:
            for i in devices_list:
                if start_time <= str_to_time(i['ctime']) <= end_time:
                    res.append(i)
            for i in res:
                if imei in i['imei']:
                    res1.append(i)
            for i in res1:
                if player_name in i['player_name']:
                    res2.append(i)
            for i in res2:
                if phone in i['phone']:
                    res3.append(i)
            for i in res3:
                if status == i['status']:
                    res4.append(i)

        result = {'devices_list': res4}

        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'], operate_desc='获取设备列表')

        return
    def post(self):
        print('get_admin_list')

        admin_base = self.get_admin_base()
        if admin_base is None:
            return self.send_faild(error.ERROR_NO_LOGIN)
        if self.is_god() is False:
            return self.send_faild(error.ERROR_AUTH_PERMISSION)

        try:
            data = self.get_post_data()
            username = data['username']
            start_time = data['start_time']
            end_time = data['end_time']
            status = data['status']
        except Exception as e:
            print(e)
            return self.send_faild(error.ERROR_PARAM)

        if username == '':
            username = "******"
        if start_time != '':
            start_time += ' 00:00:00'
            start_time = str_to_time(start_time)
        else:
            start_time = 0
        if end_time != '':
            end_time += ' 00:00:00'
            end_time = str_to_time(end_time)
        else:
            end_time = int(time.time())

        god_info = Data.select('admin', [('username', 'like', '%{}%'.format(username))])

        admins = []
        for item in god_info:
            params = {}
            admin_data = Data.find('admin_auth', [('god_id', '=', item['id'])])
            if admin_data:
                if start_time <= str_to_time(item['ctime']) <= end_time:
                    if status == item['status']:
                        params['admin_id'] = item['admin_id']
                        params['username'] = item['username']
                        params['ctime'] = str(item['ctime'])
                        params['status'] = item['status']
                        params['temp_id'] = admin_data['auth_id']
                        temp_data = Data.find('admin_temp', [('id', '=', admin_data['auth_id']), ('status', '=', 0)])
                        if temp_data:
                            params['temp_name'] = temp_data['name']
                        else:
                            params['temp_name'] = '无权限'
                        admins.append(params)

        result = {
            'admin_list': admins
        }

        self.send_ok(result)
        write_admin_record(operate_id=admin_base['id'], operate_desc='获取管理员列表')

        return