{$message}"); fclose($file); return true; } return false; } date_default_timezone_set('Asia/Shanghai'); /// �ж��Ƿ���Ҫͣ�� if (TIMED_OFF_NEEDED) { $Now = date('H:i:s'); if ($Now >= TIMED_OFF_BEGIN && $Now <= TIMED_OFF_END) { $output = JsonObjectToJsonString([ 'time' => date('Y-m-d H:i:s'), 'code' => ERRORCODE_SERVERTURNOFF, 'info' => sprintf(ERRORINFO_SERVERTURNOFF, TIMED_OFF_BEGIN, TIMED_OFF_END), ]); OutputDebugMessage($output); die($output); } } /// �������ݿ� $owner_param = new ConnectParameter(MASTER_HOSTNAME, MASTER_HOSTPORT, MASTER_DATABASE, MASTER_USERNAME, MASTER_PASSWORD, MASTER_PERSISTENT, MASTER_CHARSET); /// ��Ϸ���ݿ� if (DEBUG_MODE) $external_param = new ConnectParameter('rm-bp16sbf0l9cavp7h9o.mysql.rds.aliyuncs.com', 3306, 'youle_games', 'develop', 'develop123!@#', MASTER_PERSISTENT, MASTER_CHARSET); else $external_param = new ConnectParameter('rm-bp1749tfxu2rpq670lo.mysql.rds.aliyuncs.com', 3306, 'game_db', 'games', 'Games0791!!', MASTER_PERSISTENT, MASTER_CHARSET); //$external_param = new ConnectParameter('rm-bp1x3i28se22s9z75o.mysql.rds.aliyuncs.com', 3306, 'game_db', 'games', 'Games2017@)!&', MASTER_PERSISTENT, MASTER_CHARSET); /** @var IPDOHelper $owner_db */ $owner_db = new PDODelegator(DATABASE_TYPE); /** @var IPDOHelper $external_db */ $external_db = new PDODelegator(DATABASE_TYPE); if (!$owner_db->connect($owner_param)) { OutputDebugMessage($owner_db->geterrors()); die (JsonObjectToJsonString($owner_db->geterrors())); } if (!$external_db->connect($external_param)) { OutputDebugMessage($external_db->geterrors()); die (JsonObjectToJsonString($external_db->geterrors())); } $processcount = isset($_REQUEST['processcount']) ? intval($_REQUEST['processcount']) : 100; if (empty($processcount)) $processcount = 100; $command = <<request($command); $succeeded = ''; $failed = ''; $succeededcount = 0; $failedcount = 0; $totalcount = count($logs); if (0 == $totalcount) { $output = JsonObjectToJsonString([ 'time' => date('Y-m-d H:i:s'), 'total' => $totalcount, 'succeeded' => $succeededcount, 'failed' => $failedcount, ]); die ($output); } $owner_db->begintransaction(); $external_db->begintransaction(); try { if ($totalcount > 0) { $error_code = 0; $error_info = 'success'; foreach ($logs as $log) { switch ($log->uspl_opt) { case 1: /// 1:������ï¿? $line = __LINE__; $data = JsonStringToJsonObject($log->uspl_optdata); /// {"openid":"openid100001", "unionid":"unionid100001", "nickname":"nickname100001","avatar":"","sex":1,"province":"����","city":"�ϲ�"} if (!is_object($data)) { $failed .= $log->idx . ','; OutputDebugMessage('sync error: invalid json data' . PHP_EOL . 'data: ' . JsonObjectToJsonString($log)); $failedcount++; break; } /// �����������Ï? $command = /** @lang text */<<execute($command, $log->uspl_agentid, $log->uspl_channelid, $log->uspl_playerid, $data->openid, $data->unionid, $data->nickname, $data->avatar, $data->sex, $data->province, $data->city, $log->uspl_opttime); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } /// ��ѯ�Ƿ���ƥ��Ĵ�����Ï?��unionid��openidƥ�䣩 if (!empty($data->unionid)) { $command = /** @lang text */<<request($command, $log->uspl_agentid, $log->uspl_channelid, $data->unionid); } elseif (!empty($data->openid)) { $command = /** @lang text */<<request($command, $log->uspl_agentid, $log->uspl_channelid, $data->openid); } if (!$owner_db->isdone()) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } elseif (!empty($ret)) { $command = /** @lang text */'update sales_user set player_id = ?, saus_salesman = 1 where idx = ?'; $ret = $owner_db->execute($command, $log->uspl_playerid, $ret[0]->idx); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } } else { /// ����һ��������Ϣ $command = /** @lang text */'update ct_agent_list set max_sales_id = max_sales_id + floor(rand() * (12-6) + 6) where agent_id = ?'; $ret = $owner_db->execute($command, $log->uspl_agentid); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } $command = /** @lang text */'select max_sales_id as agen_maxsalesid, default_sales_power as agen_salespower from ct_agent_list where agent_id = ?'; $agent = $owner_db->request($command, $log->uspl_agentid); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } elseif (empty($agent)) { $ret = false; $line = __LINE__; $error_code = -1; $error_info = "�Ҳ���ָ�����������{$log->uspl_agentid}"; goto end_case_1; } $sales_id = $agent[0]->agen_maxsalesid; $sales_power = $agent[0]->agen_salespower; $password = md5(rand(1000, 9999)); $command = /** @lang text */<<execute($command, $log->uspl_agentid, $log->uspl_channelid, $sales_id, $sales_power, $data->openid, $data->unionid, $data->nickname, $data->avatar, $data->sex, $data->province, $data->city, $log->uspl_opttime, $log->uspl_opttime, $log->uspl_opttime, $log->uspl_playerid, $password); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } $sales_user = [ 'id' => 0, 'agentid' => $log->uspl_agentid, 'channelid' => $log->uspl_channelid, 'openid' => $data->openid, 'unionid' => $data->unionid, 'nickname' => $data->nickname, 'avatar' => $data->avatar, 'sex' => $data->sex, 'province' => $data->province, 'city' => $data->city, 'firsttime' => $log->uspl_opttime, 'lasttime' => $log->uspl_opttime, 'salesman' => 1, 'salesid' => $sales_id, 'level' => 0, 'parentid' => null, 'salestype' => 1, 'roomcard' => 0, 'bean' => 0, 'saletime' => $log->uspl_opttime, 'tel' => null, 'wechat' => null, 'invitecode' => null, 'power' => null, 'pushrate1' => 33, 'pushrate2' => 8, 'pushmoney1' => 0, 'pushmoney2' => 0, ]; $command = /** @lang text */<<execute($command, $log->uspl_agentid, $log->uspl_channelid, $sales_id, JsonObjectToJsonString($sales_user), 'Ŀ���û�Ϊע��Ĵ�����Ï?��oper_dataΪ�û�unionid��', time()); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_1; } } end_case_1: if ($ret && $owner_db->isdone()) { $succeeded .= $log->idx . ','; $succeededcount++; $output = 'sync done: ' . JsonObjectToJsonString($log); } else { $failed .= $log->idx . ','; $failedcount++; $output = sprintf('sync error: %s(%d) on line %d.' . PHP_EOL . 'data: %s.', $error_info, $error_code, $line, JsonObjectToJsonString($log)); } OutputDebugMessage($output); break; case 2: /// 2:�������� $line = __LINE__; /// �޸���ҵ������ï¿? $command = /** @lang text */<<execute($command, $log->uspl_optdata, $log->uspl_agentid, $log->uspl_channelid, $log->uspl_playerid); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } /// ��ȡ��Ӧ�Ĵ�����¼ $command = /** @lang text */'select idx from sales_user where saus_agentid = ? and saus_channelid = ? and player_id = ?'; $ret = $owner_db->request($command, $log->uspl_agentid, $log->uspl_channelid, $log->uspl_playerid); if (!$owner_db->isdone()) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } elseif (!empty($ret)) { /// �������ж�Ӧ�Ĵ����˻���󶨶�Ӧ�Ĵ�����Ï? $id = $ret[0]->idx; } else { /// ������û�ж�Ӧ�Ĵ����˻��������ɶ�Ӧ�Ĵ����˻� /// �Ȳ�ѯ��Ӧ�������ϸ��Ï? $command = /** @lang text */'select play_openid openid, play_unionid unionid, play_nickname nickname, play_avatar avatar, play_sex sex, play_province province, play_city city from player where play_agentid = ? and play_channelid = ? and play_playerid = ?'; $data = $owner_db->request($command, $log->uspl_agentid, $log->uspl_channelid, $log->uspl_playerid); if (!$owner_db->isdone()) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } elseif (empty($data)) { $data = $external_db->request($command, $log->uspl_agentid, $log->uspl_channelid, $log->uspl_playerid); if (!$external_db->isdone()) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } elseif (empty($data)) { $data = (object)[ 'openid' => null, 'unionid' => $log->uspl_unionid, 'nickname' => null, 'avatar' => null, 'sex' => null, 'province' => null, 'city' => null, ]; } else { $data = $data[0]; } } else { $data = $data[0]; } /// ��ѯ�Ƿ���ƥ��Ĵ�����Ï?��unionid��openidƥ�䣩 if (!empty($data->unionid)) { $command = /** @lang text */'select idx from sales_user where saus_agentid = ? and saus_channelid = ? and saus_unionid = ?'; $ret = $owner_db->request($command, $log->uspl_agentid, $log->uspl_channelid, $data->unionid); } elseif (!empty($data->openid)) { $command = /** @lang text */'select idx from sales_user where saus_agentid = ? and saus_channelid = ? and saus_openid = ?'; $ret = $owner_db->request($command, $log->uspl_agentid, $log->uspl_channelid, $data->openid); } if (!$owner_db->isdone()) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } elseif (!empty($ret)) { $id = $ret[0]->idx; } else { /// ����һ��������Ϣ $command = /** @lang text */ 'update ct_agent_list set max_sales_id = max_sales_id + floor(rand() * (12-6) + 6) where agent_id = ?'; $ret = $owner_db->execute($command, $log->uspl_agentid); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } $command = /** @lang text */ 'select max_sales_id as agen_maxsalesid, default_sales_power as agen_salespower from ct_agent_list where agent_id = ?'; $agent = $owner_db->request($command, $log->uspl_agentid); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } $sales_id = $agent[0]->agen_maxsalesid; $sales_power = $agent[0]->agen_salespower; $password = md5(rand(1000, 9999)); $command = /** @lang text */<<execute($command, $log->uspl_agentid, $log->uspl_channelid, $sales_id, $sales_power, $data->openid, $data->unionid, $data->nickname, $data->avatar, $data->sex, $data->province, $data->city, $log->uspl_opttime, $log->uspl_opttime, $log->uspl_opttime, $log->uspl_playerid, $password); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } $id = $owner_db->lastinsertid(); $sales_user = [ 'id' => $id, 'agentid' => $log->uspl_agentid, 'channelid' => $log->uspl_channelid, 'openid' => $data->openid, 'unionid' => $data->unionid, 'nickname' => $data->nickname, 'avatar' => $data->avatar, 'sex' => $data->sex, 'province' => $data->province, 'city' => $data->city, 'firsttime' => $log->uspl_opttime, 'lasttime' => $log->uspl_opttime, 'salesman' => 1, 'salesid' => $sales_id, 'level' => 0, 'parentid' => null, 'salestype' => 1, 'roomcard' => 0, 'bean' => 0, 'saletime' => $log->uspl_opttime, 'tel' => null, 'wechat' => null, 'invitecode' => null, 'power' => null, 'pushrate1' => 33, 'pushrate2' => 8, 'pushmoney1' => 0, 'pushmoney2' => 0, ]; /// ��¼������������־ $command = /** @lang text */<<execute($command, $log->uspl_agentid, $log->uspl_channelid, $sales_id, JsonObjectToJsonString($sales_user), 'Ŀ���û�Ϊע��Ĵ�����Ï?��oper_dataΪ�û�unionid��', time()); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } } } /// ��ȡ�����Ƿ�ͬ������������ï¿? $command = /** @lang text */'select sync_invitecode from ct_channel_list where agent_id = ? and channel_id = ?'; $ret = $owner_db->request($command, $log->uspl_agentid, $log->uspl_channelid); $sync_invitecode = empty($ret) ? 0 : intval($ret[0]->sync_invitecode); if (0 != $sync_invitecode) { /// �޸Ķ�Ӧ������¼�������� $command = /** @lang text */<<execute($command, $log->uspl_optdata, $log->uspl_optdata, $log->uspl_playerid, $id); if (!$ret) { $line = __LINE__; $error_code = $owner_db->GetErrorCode(); $error_info = $owner_db->GetErrorInfo(); goto end_case_2; } } end_case_2: if ($ret && $owner_db->isdone()) { $succeeded .= $log->idx . ','; $succeededcount++; $output = 'sync done: ' . JsonObjectToJsonString($log); } else { $failed .= $log->idx . ','; $failedcount++; $output = sprintf('sync error: %s(%d) on line %d.' . PHP_EOL . 'data: %s.', $error_info, $error_code, $line, JsonObjectToJsonString($log)); } OutputDebugMessage($output); break; default: break; } } /// �ɹ������ļ�¼��״̬�޸�Ϊ1 if (!empty($succeeded)) { $succeeded = substr($succeeded, 0, strlen($succeeded) - 1); $command = /** @lang text */<<execute($command); } /// ����ʧ�ܵļ�¼��״̬�޸�Ϊ-1 if (!empty($failed)) { $failed = substr($failed, 0, strlen($failed) - 1); $command = /** @lang text */<<execute($command); } } if (!$owner_db->commit()) throw new Exception($owner_db->GetErrorInfo(), $owner_db->GetErrorCode()); if (!$external_db->commit()) throw new Exception($external_db->GetErrorInfo(), $external_db->GetErrorCode()); $output = JsonObjectToJsonString([ 'time' => date('Y-m-d H:i:s'), 'total' => $totalcount, 'succeeded' => $succeededcount, 'failed' => $failedcount, ]); if (($succeededcount + $failedcount) != $totalcount) OutputDebugMessage($output); } catch (Exception $Exception) { $owner_db->rollback(); $external_db->rollback(); $output = JsonObjectToJsonString([ 'time' => date('Y-m-d H:i:s'), 'code' => $Exception->getCode(), 'info' => $Exception->getMessage(), ]); OutputDebugMessage($output); } die ($output); /* insert into ct_user_process_log(to_agent, to_channel, to_user, oper_type, oper_data, remark, oper_time, is_process) select saus_agentid, saus_channelid, saus_salesid, 21, concat('{', '"id":"', ifnull(idx, 0), '","agentid":"', ifnull(saus_agentid, ''), '","channelid":"', ifnull(saus_channelid, ''), '","openid":"', ifnull(saus_openid, ''), '","unionid":"', ifnull(saus_unionid, ''), '","nickname":"', ifnull(saus_nickname, ''), '","avatar":"', ifnull(saus_avatar, ''), '","sex":"', ifnull(saus_sex, ''), '","province":"', ifnull(saus_province, ''), '","city":"', ifnull(saus_city, ''), '","firsttime":"', ifnull(saus_firsttime, ''), '","lasttime":"', ifnull(saus_lasttime, ''), '","salesman":"', ifnull(saus_salesman, 0), '","salesid":"', ifnull(saus_salesid, ''), '","level":"', ifnull(saus_level, ''), '","parentid":"', ifnull(saus_parentid, ''), '","salestype":"', ifnull(saus_salestype, ''), '","roomcard":"', ifnull(saus_roomcard, 0), '","bean":"', ifnull(saus_bean, 0), '","saletime":"', ifnull(saus_saletime, ''), '","tel":"', ifnull(saus_tel, ''), '","wechat":"', ifnull(saus_wechat, ''), '","invitecode":"', ifnull(saus_invitecode, 0), '","power":"', ifnull(saus_power, ''), '","pushrate1":"', ifnull(saus_pushrate1, 0), '","pushrate2":"', ifnull(saus_pushrate2, 0), '","pushmoney1":"', ifnull(saus_pushmoney1, 0), '","pushmoney2":"', ifnull(saus_pushmoney2, 0), '"}' ), 'Ŀ���û�Ϊע��Ĵ�����Ï?��oper_dataΪ�û�unionid��', unix_timestamp(), 0 from sales_user where saus_agentid = 'veRa0qrBf0df2K1G4de2tgfmVxB2jxpv' and saus_channelid = 'FtJf073aa0d6rI1xD8J1Y42fINTm0ziK' and saus_salesid = 240973 */