Esempio n. 1
0
    def __login__(self):
        """
        登录
        """

        try:
            self.conn = conn(self.dbconf)
            # 判断是否开启
            statusResult = api.getLoginInfo(self.conn,
                                            self.conf['serviceCode'])
        except Exception as e:
            traceback.print_exc()
            return
        finally:
            self.conn.close()

        loginAuth = base64.b64encode(
            '%s:%s' % (statusResult['username'], statusResult['pw']))

        try:
            loginResponse = requests.post('%s/login_admin' %
                                          self.conf['apiUrl'],
                                          data={'authorization': loginAuth})
            try:
                self.conn = conn(self.dbconf)
                api.updateChingApiStatus(self.conn, 'login_status', 'OK')
            except Exception as e:
                traceback.print_exc()
            finally:
                self.conn.close()
            loginResult = loginResponse.json()

            if 'name' in loginResult and loginResult['name'] == statusResult[
                    'username']:
                self.authCookie = loginResponse.cookies.get_dict()
                tempfile = open(self.tempFile, 'w+')
                tempfile.write(json.dumps(self.authCookie))
                return
            else:
                print(loginResult)
        except Exception as e:
            try:
                self.conn = conn(self.dbconf)
                api.updateChingApiStatus(self.conn, 'login_status', 'FAILED')
            except Exception as e:
                traceback.print_exc()
            finally:
                self.conn.close()
Esempio n. 2
0
    def callback(self):
        try:
            self.conn = conn(self.config['db'])
            self.localSettlement()
        except Exception as e:
            traceback.print_exc()
        finally:
            self.conn.close()

        try:
            self.conn = conn(self.config['db'])
            self.settlement()
        except Exception as e:
            traceback.print_exc()
        finally:
            self.conn.close()
Esempio n. 3
0
    def callback(self):
        try:
            self.conn = conn(self.config['db'])
            # 判断是否开启
            statusResult = api.getLoginInfo(self.conn,
                                            self.conf['serviceCode'])
            # 关闭同步功能
            if not statusResult or statusResult['status'] == 0:
                print('status = 0')
                return

            self.memberInfo = statusResult
            self.cursor = self.conn.cursor()
            # 手动汇入(从本地excel中结算)
            self.localSettlement()
            # 自动汇入(从接口查询结算)
            self.settlement()
            self.cursor.close()
            self.conn.commit()
        except Exception as e:
            print "rollback"
            traceback.print_exc()
            self.cursor.close()
            self.conn.rollback()
        finally:
            self.conn.close()
Esempio n. 4
0
    def callback(self):
        # print ('start...')
        # self.api.
        try:
            self.conn = conn(self.config['db'])
            # 判断是否开启
            statusResult = api.getLoginInfo(self.conn,
                                            self.conf['serviceCode'])
            # 关闭同步功能
            if not statusResult or statusResult['status'] == 0:
                print('coco:autotask:stoped', statusResult['status'])
                self.api.stopBuyinWork()
                return

            # 开启带入提案审批任务
            self.api.startBuyinWork()
            self.settlement()
            # print('status = 1')
            # self.memberInfo = statusResult
            # self.cursor = self.conn.cursor()
            # self.settlement()
            # self.cursor.close()
            # self.conn.commit()
        except Exception as e:
            print "rollback"
            traceback.print_exc()
            # self.cursor.close()
            self.conn.rollback()
        finally:
            self.conn.close()
Esempio n. 5
0
 def __init__(self, conf, dbconf):
     """
 初始化
 """
     self.conn = conn(dbconf)
     apiUser = api.getLoginInfo(self.conn, conf['serviceCode'])
     self.apiUsername = apiUser['username']
     self.apiPwd = apiUser['pw']
     self.apiBack = apiUser['back']  #特殊战局
     self.clubId = apiUser['clubid']
     self.conf = conf
     self.conn.close()
Esempio n. 6
0
    def callback(self):
        self.conn = conn(self.config['db'])
        # 判断是否开启
        statusResult = api.getLoginInfo(
            self.conn, self.config['bzl-provider']['serviceCode'])
        # 关闭同步功能
        if not statusResult or statusResult['status'] == 0:
            return

        list = self.api.getBuyin()
        # list = [{u'status': 2, u'room_name': u'248\U0001f30d123\u9650', u'acc_id': 23, u'agent_balance': 10004098, u'pccname': u'tatacaca', u'total_buyin': 124400, u'firstagent_ps': u'', u'club_name': u'\u7ef4\u591a\u5229\u4e9a\u7684\u79d8\u5bc6', u'room_uuid': 34721208, u'amounts': 400, u'firstagent_balance': 20000596, u'acc_ps': u'2589370531', u'pccid': u'2589370531', u'rake_amounts': 400, u'suggest': -1, u'balance': 221, u'user_uuid': 1068464, u'stack': 400, u'total_result': None, u'operat': 0}, {u'status': 2, u'room_name': u'\U0001f43c24\u9650-151', u'acc_id': None, u'agent_balance': None, u'pccname': u'\u4e0b\u96ea\u6e56', u'total_buyin': 290600, u'firstagent_ps': None, u'club_name': u'\u7ef4\u591a\u5229\u4e9a\u7684\u79d8\u5bc6', u'room_uuid': 34726887, u'amounts': 800, u'firstagent_balance': None, u'acc_ps': None, u'pccid': u'2557331287', u'rake_amounts': 800, u'suggest': -2, u'balance': None, u'user_uuid': 1055336, u'stack': 800, u'total_result': None, u'operat': 0}, {u'status': 2, u'room_name': u'1240\u266679\u965025', u'acc_id': None, u'agent_balance': None, u'pccname': u'\u84dd\u8272\u7684\u77f3\u5934', u'total_buyin': 356000, u'firstagent_ps': None, u'club_name': u'\U0001f30a\u9ed1\u6843\u4ff1\u4e50\u90e8', u'room_uuid': 34723608, u'amounts': 2000, u'firstagent_balance': None, u'acc_ps': None, u'pccid': u'2838728644', u'rake_amounts': 2000, u'suggest': -2, u'balance': None, u'user_uuid': 1170025, u'stack': 2000, u'total_result': None, u'operat': 0}, {u'status': 2, u'room_name': u'512\u266682\u965025', u'acc_id': None, u'agent_balance': None, u'pccname': u'\u7eaa\u5ff5\u7eaa\u5ff5', u'total_buyin': 203500, u'firstagent_ps': None, u'club_name': u'\U0001f30a\u9ed1\u6843\u4ff1\u4e50\u90e8', u'room_uuid': 34724289, u'amounts': 1000, u'firstagent_balance': None, u'acc_ps': None, u'pccid': u'2622565341', u'rake_amounts': 1000, u'suggest': -2, u'balance': None, u'user_uuid': 1081932, u'stack': 1000, u'total_result': None, u'operat': 0}]
        for item in list:
            print item
            if int(item['suggest']) > -2 and int(item['pccid']) == 2525717358:
                purseInfo = purse.getPurseInfoByGameId(self.conn,
                                                       item['pccid'])
                data = {
                    'club_name': item["club_name"],
                    'pccid': item["pccid"],
                    'pccname': item["pccname"],
                    'room_uuid': item["room_uuid"],
                    'stack': item["stack"],
                    'amounts': item["amounts"]
                }
                if purseInfo:
                    if int(purseInfo['cash']) >= int(item['amounts']):
                        code = self.api.acceptBuyin(data)
                        print "审核成功" + str(code)
                        if code == 200:
                            try:
                                purse.syncBuyin(self.conn, purseInfo, item,
                                                -int(item['amounts']))
                            except Exception as e:
                                print e
                            continue
                    else:
                        code = self.api.denyBuyin(data)
                        if code == 200:
                            buyin.addBuyinLog(self.conn, purseInfo, item,
                                              'deny')
                            self.conn.commit()

                # else:
                #     code = self.api.denyBuyin(data)
                #     if code == 200:
                #         purseInfo = {}
                #         purseInfo['frontend_user_id'] = 'no purse'
                #         purseInfo['frontend_user_auth'] = 'no purse'
                #         purseInfo['game_vid'] = item["pccid"]
                #         buyin.addBuyinLog(self.conn, purseInfo, item, 'deny')
                #         self.conn.commit()
        self.conn.close()
Esempio n. 7
0
    def callback(self):
        try:
            self.conn = conn(self.config['db'])
            # 判断是否开启
            statusResult = api.getLoginInfo(self.conn, self.config[self.providerName]['serviceCode'])
            # 关闭同步功能
            if not statusResult or statusResult['status'] == 0:
                return

            print ('-------------------------------whill get data')

            rel =  self.api.getBuyin()
            print(rel)
            if not 'result' in rel:
                return
            list = rel['result']
            # list = [{u'totalGames': 8, u'gameRoomName': u'\u53d1\u53d1\u53d1', u'totalProfit': 1485, u'uuid': 774478, u'gameRoomId': 35047501, u'strNick': u'\u4e5f\u8bb8\u4f1a\u53d8', u'poolRate': 0, u'showId': u'1868828686', u'strSmallCover': u'http://upyun.pokermate.net/images/male_head.png', u'buyStack': 200, u'leagueId': 0, u'totalBuyin': 1100, u'totalHands': 10, u'leagueName': u'', u'clubId': 0}]
            for item in list:
                print item
                uid = item['showId']
                if int(uid) > 0:
                    purseInfo = purse.getPurseInfoByGameId(self.conn, uid)
                    data = {
                        'uuid':item['uuid'], 
                        'gameRoomId':item["gameRoomId"],
                    }
                    print purseInfo
                    if purseInfo:
                        if int(purseInfo['cash']) >= int(item['buyStack']):
                            resp = self.api.acceptBuyin(data)
                            print "审核结果", resp
                            if resp['iErrCode'] == 0:
                                try:
                                    cms.syncCmsBuyin(self.conn, purseInfo, item, -int(item['buyStack']))
                                except Exception as e:
                                    print e
                        else:               
                            resp = self.api.denyBuyin(data)
                            if resp['iErrCode'] == 0:
                                cms.addBuyinLog(self.conn, purseInfo, item, 'deny')
            self.conn.commit()
        except Exception as e:
            traceback.print_exc()
        finally:
            try:
                self.conn.close()
            except Exception as e:
                traceback.print_exc()
Esempio n. 8
0
    def __login__(self):
        try:
            self.conn = conn(self.dbconf)
            statusResult = api.getLoginInfo(self.conn,
                                            self.conf['serviceCode'])
        except Exception as e:
            traceback.print_exc()
            return
        finally:
            self.conn.close()

        try:
            loginResponse = requests.post(
                '%s/auth/login' % self.conf['apiUrl'],
                data={
                    'username': statusResult['username'],
                    'password': statusResult['pw']
                })

            loginResult = loginResponse.json()

            if 'errCode' in loginResult:
                if loginResult['errCode'] == 0:
                    self.authCookie = loginResponse.cookies.get_dict()
                    tempfile = open(self.tempFile, 'w+')
                    tempfile.write(json.dumps(self.authCookie))
                    print('coco:login:success:', loginResponse)
                if loginResult['errCode'] == 1:
                    print('coco:login:password error:', loginResponse)
                if loginResult['errCode'] == 2:
                    print('coco:login:server result error:', loginResponse)
            else:
                print('coco:login:server result error:no errCode:',
                      loginResponse)

        except Exception as e:
            print('coco:login:fail:', e)
            traceback.print_exc()
Esempio n. 9
0
    def __invoke__(self, url, method='post', params={}, needAuth=True):
        """
        调用接口
        """

        if needAuth:
            if hasattr(self, 'authCookie') == False:
                if os.path.exists(self.tempFile) == False:
                    self.__login__()
                else:
                    try:
                        tempfileReader = open(self.tempFile, 'r')
                        self.authCookie = json.loads(tempfileReader.read())
                    except Exception as e:
                        print(e)
                    if not self.authCookie:
                        self.__login__()
        reqUrl = '%s/%s' % (self.conf['apiUrl'], url)
        print reqUrl, params
        i = 0
        while i < 3:
            try:

                if method == 'get':
                    result = requests.get(reqUrl,
                                          params=params,
                                          cookies=self.authCookie).json()
                else:
                    result = requests.post(reqUrl,
                                           data=params,
                                           cookies=self.authCookie).json()

                try:
                    self.conn = conn(self.dbconf)
                    if url == 'club_buyin':
                        api.updateChingApiStatus(self.conn, 'get_buyin_status',
                                                 'OK')
                    elif url == 'query_user_board':
                        api.updateChingApiStatus(self.conn, 'get_game_status',
                                                 'OK')
                except Exception as e:
                    traceback.print_exc()
                finally:
                    self.conn.close()

                if result.has_key('data'):
                    break
                elif result.has_key('status'):
                    if result['status'] == 0:
                        result['data'] = 200
                    else:
                        result['data'] = result['status']
                    break
                elif result.has_key('message') and result['message'] != '':
                    result['data'] = []
                    print result
                    self.__login__()
                else:
                    self.__login__()
                i += 1
            except:
                try:
                    self.conn = conn(self.dbconf)
                    if url == 'club_buyin':
                        api.updateChingApiStatus(self.conn, 'get_buyin_status',
                                                 'FAILED')
                    elif url == 'query_user_board':
                        api.updateChingApiStatus(self.conn, 'get_game_status',
                                                 'FAILED')
                except Exception as e:
                    traceback.print_exc()
                finally:
                    self.conn.close()

        return result['data']
Esempio n. 10
0
    def applyBuyin(self, buyinRecord):
        """
        买入提案逐条审批
        """

        applyConn = conn(self.config['db'])
        applyCursor = applyConn.cursor()
        try:
            purseInfo = purse.getPurseWithCursor(applyCursor,
                                                 buyinRecord['showId'])

            if not purseInfo:
                print('coco:autotask:apply:no id:', buyinRecord)
                return

            # 审批标志
            settle_game_info = ''
            for key in buyinRecord:
                settle_game_info += '%s:%s' % (key, buyinRecord[key])
            settle_game_info = hashlib.md5(
                settle_game_info.encode('utf-8')).hexdigest()

            # 判断是否重复审批
            applyCountReult = cocomodel.getCountApply(applyCursor,
                                                      settle_game_info)
            if applyCountReult['apply_count'] > 0:
                print('coco:autotask:apply:already applyed', buyinRecord)
                return

            applyAction = ''
            applyClubRommName = base64.b64encode(
                ("%s_%s" % (buyinRecord['clubId'],
                            buyinRecord['gameRoomName'])).encode('utf-8'))

            reqData = {
                'clubId': buyinRecord['clubId'],
                'dpqId': buyinRecord['showId'],
                'buyinStack': buyinRecord['buyStack'],
                'roomId': buyinRecord['gameRoomId'],
                'player': buyinRecord['strNick'],
                'clubName': buyinRecord['clubName'],
                'agentName': '',
                'roomName': buyinRecord['gameRoomName'],
                'leagueName': buyinRecord['leagueName'],
                'data[userUuid]': buyinRecord['uuid'],
                'data[roomId]': buyinRecord['gameRoomId'],
            }

            if int(purseInfo['cash']) >= int(buyinRecord['buyStack']):
                print('coco:autotask:apply:apply accept:', reqData)
                try:
                    applyResult = self.api.acceptBuyin(reqData)
                    if applyResult and not applyResult['err']:
                        # 审批成功
                        print('coco:autotask:apply:apply success:',
                              applyResult)
                        purseInfo['settle_game_info'] = settle_game_info
                        # 更新钱包
                        cocomodel.applyUpdatePurse(
                            applyCursor, purseInfo,
                            -int(buyinRecord['buyStack']))
                        applyAction = 'accept'
                    else:
                        # 审批失败
                        print('coco:autotask:apply:apply error:', applyResult)
                except Exception as e:
                    print('coco:autotask:apply:apply exception:', e)
                    traceback.print_exc()
            else:
                print('coco:autotask:apply:apply deny:', reqData)
                applyResult = self.api.denyBuyin(reqData)
                # 拒绝
                applyAction = 'deny'

            # 审批提案日志
            cocomodel.addApplyLog(
                applyCursor,
                (str(purseInfo['frontend_user_id']),
                 str(purseInfo['frontend_user_auth']),
                 str(purseInfo['game_vid']),
                 buyinRecord['clubName'].encode('utf-8'),
                 str(buyinRecord['buyStack']), str(
                     time.time()), str(time.time()), 'connor_coco_buyin',
                 str(applyAction), buyinRecord['gameRoomName'].encode('utf-8'),
                 str(applyClubRommName)))

            applyConn.commit()
        except Exception as e:
            applyConn.rollback()
            print('coco:autotask:apply:exception:', e)
            traceback.print_exc()
        finally:
            applyConn.close()