Esempio n. 1
0
def get_player_list(player_line):
    player_info = {
        'player_id': player_line['id'],
        'name': json.loads(player_line['nickname']),
        'phone': player_line['phone'],
        'join_time': common.time_to_str(player_line['add_time']),
        'status': 0,
    }

    return player_info
Esempio n. 2
0
    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
Esempio n. 3
0
    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
    def update_client(self, client_sid, data):
        client = self.get_client_by_sid(client_sid)
        imei = data.split()[0].split('IMEI')[1]
        pos = data.split()[1].split(',')
        client.update_client_info_by_heart(imei, pos)
        client_sid = client.get_sid()

        self.clean_same_client(imei, client_sid)
        # 关闭所有同imei不同sid的客户端
        print('[', common.time_to_str(int(time.time())), 'SID:', client_sid,
              ']RECEIVE')
        print('客户端', imei, client_sid, '发生更新')
        print('=====================================================')
        return
Esempio n. 5
0
    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
Esempio n. 6
0
    def post(self):
        print('get_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)

        data = self.get_post_data()
        try:
            admin_temp_name = data['admin_temp_name']
            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 admin_temp_name == '':
            admin_temp_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())

        res = Data.select('admin_temp',
                          [('name', 'like', '%{}%'.format(admin_temp_name)),
                           ('status', '=', 0)])
        admin_temp_list = []

        if res:
            for temp in res:
                if start_time <= int(temp['ctime']) <= end_time:
                    if status == temp['status']:
                        temp['ctime'] = time_to_str(int(temp['ctime']))
                        admin_temp_list.append(temp)

        result = {'auth_temp_list': admin_temp_list}
        self.send_ok(result)

        return
Esempio n. 7
0
 def create_device(self):
     params = {
         'imei': self.get_imei(),
         'sn': self.get_imei(),
         'valid_time': common.time_to_str(int(time.time())),
         'lastshakingtime': common.time_to_str(int(time.time())),
         'lastlowbatterytime': common.time_to_str(0),
         'lastlosingexternalpowertime': common.time_to_str(0),
         'lastcrossingbordertime': common.time_to_str(0),
         'lastoverspeedtime': common.time_to_str(0),
     }
     Data.insert('CWS_APP.devices', params)
     print('创建设备imei', self.get_imei())
Esempio n. 8
0
    def update_devices_info(self):
        res = Data.find('CWS_APP.devices', [('imei', '=', self.imei)])
        if res == None:
            self.create_device()

        # 创建全新的设备信息
        report = {
            'imei': self.get_imei(),
            'lng': self.get_pos()[0],
            'lat': self.get_pos()[1],
            'time': common.time_to_str(int(time.time())),
            'status': 'heart',
        }
        resp = Data.find('CWS_APP.latestreport', [('imei', '=', self.imei)])
        if resp == None:
            Data.insert('CWS_APP.latestreport', report)
        else:
            Data.update('CWS_APP.latestreport', [('imei', '=', self.imei)],
                        report)
            print(self.get_imei(), '写入通讯表')
        return
Esempio n. 9
0
    def test_guanjia_doaddpwds(self):
        """
        test body
        :return:
        """
        # 给get或者post方法配置Http地址
        self.localConfigHttp = configHttp_new.ConfigHttp(env_old_new='old')
        # 接口地址存储在excel文件里,读取出来
        self.localConfigHttp.set_url(self.service_id)
        # set params
        data = json.loads(self.data)
        data['start_time'] = common.time_to_str(data['start_time'])
        data['end_time'] = common.time_to_str(data['end_time'])
        # 判断是否需要token
        if self.token == 1:
            f = open(token_fiel_path, 'r')
            token_tmp = f.readline()
            data['access_token'] = token_tmp
            print '获取到的最新token:', data['access_token']
        # 判断是否需要获取验证码
        if 'sms_code' in data:
            sql = localReadConfig.get_sql('sql_yzm')
            yzm = configDB.MyDB().zhiyu_yzm(sql)
            data['sms_code'] = yzm
        # 获取house_id,如果excel表格里house_id为空,则取ini文件里的house_id,否则取excel里的house_id
        if 'house_id' in data:
            if data['house_id'] == '':
                house_id = localReadConfig.get_ini('PARAMS', 'house_id')
                data['house_id'] = house_id
        # # 获取时间戳
        # time_now = common.get_time_now()
        # data['timestamp'] = time_now
        # AES加密
        params_miwen = encryptLib.zhiyu_des_encode(data)
        # 真正的入参
        params = {
            'client_id': '1fobqa5ofzixluyjlum7icdufabjfo25',
            'param': params_miwen
        }

        self.localConfigHttp.set_params(params)
        # 获取响应结果信息
        if self.method.lower() == 'get':
            self.response = self.localConfigHttp.get()
            print 'get'
        elif self.method.lower() == 'post':
            self.response = self.localConfigHttp.post()
            print 'post'
        # 显示响应结果信息
        common.show_return_msg(self.response)
        self.info = self.response.text
        # Json响应信息转成字典格式
        self.info = json.loads(self.info)
        # 存储token,只有正确登录的时候才有token
        if 'access_token' in self.info['data']:
            token_temp = self.info['data']['access_token']
            localReadConfig.set_headers('token_temp', token_temp)
        # 断言返回状态码
        self.assertEqual(self.info['err_no'], self.expect_state)
        # 断言返回message
        mes_reponse = self.info['err_msg'].encode('utf-8')
        self.assertEqual(mes_reponse, self.expect_msg)
Esempio n. 10
0
    def post(self):
        try:
            data = self.get_post_data()
            inv_code = data['inv_code']
            phone = data['phone']
            passwd = data['passwd']
            passwd_confirm = data['passwd_confirm']
            verify_code = data['verify_code']
            name = data['name']
        except Exception as e:
            print(e)
            print('有没填的信息')
            return self.send_faild(error.ERROR_PARAM)

        if inv_code == '':
            print('没有邀请码')
            return self.send_faild(error.ERROR_PARAM)
        # 没有邀请码拒绝注册
        if VERIFY_CODE != '1234':
            res = Data.find('tel_verify', [('tel', '=', phone),
                                           ('code', '=', verify_code),
                                           ('status', '=', 0)])
            if res is None:
                return self.send_faild(error.ERROR_CODE_WRONG)
                # 验证码错误
            if int(time.time()) - res['c_time'] > 600:
                return self.send_faild(error.ERROR_CODE_WRONG)
                # 验证超时,十分钟

            # 验证失败
            Data.update('tel_verify', [('tel', '=', phone),
                                       ('code', '=', verify_code)],
                        {'status': 1})

        res = Data.find('openluat_user', [('phone', '=', phone)])
        if res is not None:
            return self.send_faild(error.ERROR_PHONE_EXISTS)
        # 账号已经存在

        inv_info = Data.find('invite_code', [('inv_code', '=', inv_code)])
        if inv_info is None:
            print('邀请码不存在')
            return self.send_faild(error.ERROR_PARAM)
        # 邀请码不存在

        if passwd != passwd_confirm:
            return self.send_faild(error.ERROR_PW_DIFF)
        # 密码不同

        passwd = generate_password_hash(passwd)
        openluat_user_params = {
            'name': name,
            'phone': phone,
            'password_hash': passwd,
            'creation_time': common.time_to_str(int(time.time())),
            'realname': name,
            'have_shop': 1,
        }
        Data.insert('openluat_user', openluat_user_params)
        # 写入记录
        # 写入openluat_user表
        user_base = Data.find('openluat_user', [('phone', '=', phone)])

        inv_params = {
            'user_id': user_base['id'],
            'inv_code': common.create_invite_code(),
            'inviter': inv_info['user_id'],
        }
        Data.insert('invite_code', inv_params)
        # 创建商家专属邀请码
        distr_param = {
            'user_id': user_base['id'],
            'upper_id': inv_info['user_id'],
            'is_super': 0
        }
        Data.insert('distr_relation', distr_param)
        # 写入业务员关系数据表

        shop_distr_params = {
            'user_id': user_base['id'],
        }

        # 查询分润比例
        share_info = Data.find('share_record', [('id', '!=', 0)],
                               order=['id', 'desc'])
        if share_info is None:
            shop_distr_params['shop_share_min'] = share_info['shop_share_min']
            shop_distr_params['shop_share_max'] = share_info['shop_share_max']

        Data.insert('shop_share_type', {
            'shop_id': user_base['id'],
            'share_id': 1
        })

        Data.insert('shop_distr', shop_distr_params)
        # 写入商户分润表
        Data.insert('shop_machine_setting', {'shop_id': user_base['id']})
        print('插入')
        # Data.insert('shop_machine_setting', {'shop_id': user_base['id']})
        reply = {'sign_status': 0}
        self.send_ok(reply)

        return