function interact($socket) { global $fh; global $command_path; global $firstInteraction; global $remip; global $remport; global $imei; $loopcount = 0; $conn_imei = ""; /* TALK TO YOUR CLIENT */ $rec = ""; // Variavel que indica se comando est� em banco ou arquivo. $tipoComando = "banco"; //"arquivo"; //Checando o protocolo $isGIMEI = false; $isGPRMC = false; $send_cmd = ""; $last_status = ""; # Read the socket but don't wait for data.. while (@socket_recv($socket, $rec, 2048, 0x40) !== 0) { //if($last_status != ''){ // socket_send($socket, $last_status, strlen($last_status), 0); // } # If we know the imei of the phone and there is a pending command send it. if ($conn_imei != "") { if ($tipoComando == "arquivo" and file_exists("{$command_path}/{$conn_imei}")) { $send_cmd = file_get_contents("{$command_path}/{$conn_imei}"); /**/ $sendcmd = trataCommand($send_cmd, $conn_imei); socket_send($socket, $sendcmd, strlen($sendcmd), 0); unlink("{$command_path}/{$conn_imei}"); printLog($fh, "Arquivo de comandos apagado: " . $sendcmd . " imei: " . $conn_imei); } else { if ($tipoComando == "banco" and file_exists("{$command_path}/{$conn_imei}")) { //Conecta e pega o comando pendente $cnx = mysql_connect("cloudservice.cgejdsdl842e.sa-east-1.rds.amazonaws.com", "gpstracker", "d1\$1793689") or die("Could not connect: " . mysql_error()); mysql_select_db('tracker', $cnx); $res = mysql_query("SELECT c.command FROM command c WHERE c.imei = '{$conn_imei}' ORDER BY date DESC LIMIT 1", $cnx); $sendcmd = ''; while ($data = mysql_fetch_assoc($res)) { $sendcmd = trataCommand($data['command'], $conn_imei); } // Deletando comando //mysql_query("DELETE FROM command WHERE imei = $conn_imei"); socket_send($socket, $sendcmd, strlen($sendcmd), 0); mysql_close($cnx); unlink("{$command_path}/{$conn_imei}"); printLog($fh, "Comandos do arquivo apagado: " . $sendcmd . " imei: " . $conn_imei); } else { //Se nao tiver comando na fila e for a primeira iteracao, obtem o ultimo comando v�lido enviado if ($firstInteraction == true) { sleep(1); $firstInteraction = false; } } } } if (file_exists("{$command_path}/{$conn_imei}")) { $send_cmd = file_get_contents("{$command_path}/{$conn_imei}"); if ($send_cmd == 'shutdown') { unlink("{$command_path}/{$conn_imei}"); socket_shutdown($socket, 2); } } # Some pacing to ensure we don't split any incoming data. sleep(1); # Timeout the socket if it's not talking... # Prevents duplicate connections, confusing the send commands $loopcount++; if ($loopcount > 120) { return; } #remove any whitespace from ends of string. if ($rec != "") { $isGt06 = false; $tempString = $rec . ""; //verifica se é gt06 $retTracker = hex_dump($rec . ""); $arCommands = explode(' ', trim($retTracker)); if (count($arCommands) > 0) { if ($arCommands[0] . $arCommands[1] == '7878') { $isGt06 = true; } } if ($isGt06) { $arCommands = explode(' ', $retTracker); $tmpArray = array_count_values($arCommands); $count = $tmpArray[78]; $count = $count / 2; $tmpArCommand = array(); if ($count >= 1) { $ar = array(); for ($i = 0; $i < count($arCommands); $i++) { if (strtoupper(trim($arCommands[$i])) == "78" && isset($arCommands[$i + 1]) && strtoupper(trim($arCommands[$i + 1])) == "78") { $ar = array(); if (strlen($arCommands[$i]) == 4) { $ar[] = substr($arCommands[$i], 0, 2); $ar[] = substr($arCommands[$i], 2, 2); } else { $ar[] = $arCommands[$i]; } } elseif (isset($arCommands[$i + 1]) && strtoupper(trim($arCommands[$i + 1])) == "78" && strtoupper(trim($arCommands[$i])) != "78" && isset($arCommands[$i + 2]) && strtoupper(trim($arCommands[$i + 2])) == "78") { if (strlen($arCommands[$i]) == 4) { $ar[] = substr($arCommands[$i], 0, 2); $ar[] = substr($arCommands[$i], 2, 2); } else { $ar[] = $arCommands[$i]; } $tmpArCommand[] = $ar; } elseif ($i == count($arCommands) - 1) { if (strlen($arCommands[$i]) == 4) { $ar[] = substr($arCommands[$i], 0, 2); $ar[] = substr($arCommands[$i], 2, 2); } else { $ar[] = $arCommands[$i]; } $tmpArCommand[] = $ar; } else { if (strlen($arCommands[$i]) == 4) { $ar[] = substr($arCommands[$i], 0, 2); $ar[] = substr($arCommands[$i], 2, 2); } else { $ar[] = $arCommands[$i]; } } } } for ($i = 0; $i < count($tmpArCommand); $i++) { $arCommands = $tmpArCommand[$i]; $sizeData = $arCommands[2]; $protocolNumber = strtoupper(trim($arCommands[3])); if ($protocolNumber == '01') { $imei = ''; for ($i = 4; $i < 12; $i++) { $imei = $imei . $arCommands[$i]; } $imei = substr($imei, 1, 15); $conn_imei = $imei; abrirArquivoLog($imei); $sendCommands = array(); $send_cmd = '78 78 05 01 ' . strtoupper($arCommands[12]) . ' ' . strtoupper($arCommands[13]); atualizarBemSerial($conn_imei, strtoupper($arCommands[12]) . ' ' . strtoupper($arCommands[13])); $newString = ''; $newString = chr(0x5) . chr(0x1) . $rec[12] . $rec[13]; $crc16 = GetCrc16($newString, strlen($newString)); $crc16h = floor($crc16 / 256); $crc16l = $crc16 - $crc16h * 256; $crc = dechex($crc16h) . ' ' . dechex($crc16l); //$crc = crcx25('05 '.$protocolNumber.' '.strtoupper($arCommands[12]).' '.strtoupper($arCommands[13])); //$crc = str_replace('ffff','',dechex($crc)); //$crc = strtoupper(substr($crc,0,2)).' '.strtoupper(substr($crc,2,2)); $send_cmd = $send_cmd . ' ' . $crc . ' 0D 0A'; $sendCommands = explode(' ', $send_cmd); printLog($fh, date("d-m-y h:i:sa") . " Imei: {$imei} Got: " . implode(" ", $arCommands)); printLog($fh, date("d-m-y h:i:sa") . " Imei: {$imei} Sent: {$send_cmd} Length: " . strlen($send_cmd)); $send_cmd = ''; for ($i = 0; $i < count($sendCommands); $i++) { $send_cmd .= chr(hexdec(trim($sendCommands[$i]))); } socket_send($socket, $send_cmd, strlen($send_cmd), 0); } else { if ($protocolNumber == '12') { printLog($fh, date("d-m-y h:i:sa") . " Imei: {$imei} Got: " . implode(" ", $arCommands)); $dataPosition = hexdec($arCommands[4]) . '-' . hexdec($arCommands[5]) . '-' . hexdec($arCommands[6]) . ' ' . hexdec($arCommands[7]) . ':' . hexdec($arCommands[8]) . ':' . hexdec($arCommands[9]); $gpsQuantity = $arCommands[10]; $lengthGps = hexdec(substr($gpsQuantity, 0, 1)); $satellitesGps = hexdec(substr($gpsQuantity, 1, 1)); $latitudeHemisphere = ''; $longitudeHemisphere = ''; $speed = hexdec($arCommands[19]); //78 78 1f 12 0e 05 1e 10 19 05 c4 01 2c 74 31 03 fa b2 b2 07 18 ab 02 d4 0b 00 b3 00 24 73 00 07 5b 59 0d 0a //18 ab //0001100010101011 //01 2b af f6 //03 fa 37 88 if (isset($arCommands[20]) && isset($arCommands[21])) { $course = decbin(hexdec($arCommands[20])); while (strlen($course) < 8) { $course = '0' . $course; } $status = decbin(hexdec($arCommands[21])); while (strlen($status) < 8) { $status = '0' . $status; } $courseStatus = $course . $status; $gpsRealTime = substr($courseStatus, 2, 1) == '0' ? 'F' : 'D'; $gpsPosition = substr($courseStatus, 3, 1) == '0' ? 'F' : 'L'; //$gpsPosition = 'S'; $gpsPosition == 'F' ? 'S' : 'N'; $latitudeHemisphere = substr($courseStatus, 5, 1) == '0' ? 'S' : 'N'; $longitudeHemisphere = substr($courseStatus, 4, 1) == '0' ? 'E' : 'W'; } $latHex = hexdec($arCommands[11] . $arCommands[12] . $arCommands[13] . $arCommands[14]); $lonHex = hexdec($arCommands[15] . $arCommands[16] . $arCommands[17] . $arCommands[18]); $latitudeDecimalDegrees = $latHex * 90 / 162000000; $longitudeDecimalDegrees = $lonHex * 180 / 324000000; $latitudeHemisphere == 'S' && ($latitudeDecimalDegrees = $latitudeDecimalDegrees * -1); $longitudeHemisphere == 'W' && ($longitudeDecimalDegrees = $longitudeDecimalDegrees * -1); if (isset($arCommands[30]) && isset($arCommands[30])) { atualizarBemSerial($conn_imei, strtoupper($arCommands[30]) . ' ' . strtoupper($arCommands[31])); } else { echo 'Imei: ' . $imei . ' Got:' . $retTracker; } $dados = array($gpsPosition, $latitudeDecimalDegrees, $longitudeDecimalDegrees, $latitudeHemisphere, $longitudeHemisphere, $speed, $imei, $dataPosition, 'tracker', '', 'S', $gpsRealTime); tratarDados($dados); // echo "[PROTOCOLO 12] Lat/Long: ".$latitudeDecimalDegrees.", ".$longitudeDecimalDegrees."****************"; } else { if ($protocolNumber == '13') { //heatbeat $terminalInformation = decbin(hexdec($arCommands[4])); while (strlen($terminalInformation) < 8) { $terminalInformation = '0' . $terminalInformation; } //00101110 $gasOil = substr($terminalInformation, 0, 1) == '0' ? 'S' : 'N'; $gpsTrack = substr($terminalInformation, 1, 1) == '1' ? 'S' : 'N'; $alarm = ''; //78 78 0a 13 05 06 04 00 02 00 18 68 47 0d 0a //76543210 //00000101 //0d1$17936897 switch (substr($terminalInformation, 2, 3)) { case '100': $alarm = 'help me'; break; case '011': $alarm = 'low battery'; break; case '010': $alarm = 'dt'; break; case '001': $alarm = 'move'; break; case '000': $alarm = 'tracker'; break; } $ativo = substr($terminalInformation, 7, 1) == '1' ? 'S' : 'S'; $charge = substr($terminalInformation, 5, 1) == '1' ? 'S' : 'N'; $acc = substr($terminalInformation, 6, 1) == '1' ? 'S' : 'N'; //$defense = substr($terminalInformation,7,1) == '1' ? 'S' : 'N'; $voltageLevel = hexdec($arCommands[5]); $gsmSignal = hexdec($arCommands[6]); $alarmLanguage = hexdec($arCommands[7]); switch ($alarmLanguage) { case 0: $alarm = 'tracker'; break; case 1: $alarm = 'help me'; break; case 2: $alarm = 'dt'; break; case 3: $alarm = 'move'; break; case 4: $alarm = 'stockade'; break; case 5: $alarm = 'stockade'; break; } $sendCommands = array(); if (strlen($arCommands[9]) == 4 && count($arCommands) == 10) { $arCommands[9] = substr($terminalInformation, 0, 2); $arCommands[] = substr($terminalInformation, 2, 2); } $send_cmd = '78 78 05 13 ' . strtoupper($arCommands[9]) . ' ' . strtoupper($arCommands[10]); $newString = ''; $newString = chr(0x5) . chr(0x13) . $rec[9] . $rec[10]; $crc16 = GetCrc16($newString, strlen($newString)); $crc16h = floor($crc16 / 256); $crc16l = $crc16 - $crc16h * 256; $crc = dechex($crc16h) . ' ' . dechex($crc16l); //$crc = crcx25('05 13 '.strtoupper($arCommands[9]).' '.strtoupper($arCommands[10])); //$crc = str_replace('ffff','',dechex($crc)); //$crc = strtoupper(substr($crc,0,2)).' '.strtoupper(substr($crc,2,2)); $send_cmd = $send_cmd . ' ' . $crc . ' 0D 0A'; $sendCommands = explode(' ', $send_cmd); atualizarBemSerial($conn_imei, strtoupper($arCommands[9]) . ' ' . strtoupper($arCommands[10])); printLog($fh, date("d-m-y h:i:sa") . " Imei: {$imei} Got: " . implode(" ", $arCommands)); printLog($fh, date("d-m-y h:i:sa") . " Imei: {$imei} Sent: {$send_cmd} Length: " . strlen($send_cmd)); $send_cmd = ''; for ($i = 0; $i < count($sendCommands); $i++) { $send_cmd .= chr(hexdec(trim($sendCommands[$i]))); } socket_send($socket, $send_cmd, strlen($send_cmd), 0); $con = mysql_connect("cloudservice.cgejdsdl842e.sa-east-1.rds.amazonaws.com", "gpstracker", "d1\$1793689"); if ($con !== false) { mysql_select_db('tracker', $con); $res = mysql_query("SELECT * FROM loc_atual WHERE imei = '{$imei}'", $con); if ($res !== false) { $data = mysql_fetch_assoc($res); mysql_close($con); $dados = array($gpsTrack, $data['latitudeDecimalDegrees'], $data['longitudeDecimalDegrees'], $data['latitudeHemisphere'], $data['longitudeHemisphere'], 0, $imei, date('Y-m-d'), $alarm, $acc, $ativo); tratarDados($dados); // echo "[PROTOCOLO 13] Lat/Long: ".$data['latitudeDecimalDegrees'].", ".$data['longitudeDecimalDegrees']."****************"; } } } else { if ($protocolNumber == '15') { printLog($fh, date("d-m-y h:i:sa") . " Got: {$retTracker}"); $msg = ''; for ($i = 9; $i < count($arCommands) - 8; $i++) { $msg .= chr(hexdec($arCommands[$i])); } $con = mysql_connect("cloudservice.cgejdsdl842e.sa-east-1.rds.amazonaws.com", "gpstracker", "d1\$1793689"); if ($con !== false) { mysql_select_db('tracker', $con); $alerta = ''; if (strpos($msg, 'Already') > -1) { $alerta = 'Bloqueio já efetuado!'; } if (strpos($msg, 'DYD=Suc') > -1) { $alerta = 'Bloqueio efetuado!'; } if (strpos($msg, 'HFYD=Su') > -1) { $alerta = 'Desbloqueio efetuado!'; } mysql_query("INSERT INTO message (imei, message) VALUES ('{$conn_imei}', '{$alerta}')", $con); mysql_close($con); } } else { if ($protocolNumber == '16') { printLog($fh, date("d-m-y h:i:sa") . " Got: " . implode(" ", $arCommands)); $dataPosition = hexdec($arCommands[4]) . '-' . hexdec($arCommands[5]) . '-' . hexdec($arCommands[6]) . ' ' . hexdec($arCommands[7]) . ':' . hexdec($arCommands[8]) . ':' . hexdec($arCommands[9]); $gpsQuantity = $arCommands[10]; $lengthGps = hexdec(substr($gpsQuantity, 0, 1)); $satellitesGps = hexdec(substr($gpsQuantity, 1, 1)); $latitudeHemisphere = ''; $longitudeHemisphere = ''; $speed = hexdec($arCommands[19]); $course = decbin(hexdec($arCommands[20])); while (strlen($course) < 8) { $course = '0' . $course; } $status = decbin(hexdec($arCommands[21])); while (strlen($status) < 8) { $status = '0' . $status; } $courseStatus = $course . $status; $gpsRealTime = substr($courseStatus, 2, 1); $gpsPosition = substr($courseStatus, 3, 1) == '0' ? 'F' : 'L'; $gpsPosition = 'S'; $latitudeHemisphere = substr($courseStatus, 5, 1) == '0' ? 'S' : 'N'; $longitudeHemisphere = substr($courseStatus, 4, 1) == '0' ? 'E' : 'W'; $latHex = hexdec($arCommands[11] . $arCommands[12] . $arCommands[13] . $arCommands[14]); $lonHex = hexdec($arCommands[15] . $arCommands[16] . $arCommands[17] . $arCommands[18]); $latitudeDecimalDegrees = $latHex * 90 / 162000000; $longitudeDecimalDegrees = $lonHex * 180 / 324000000; $latitudeHemisphere == 'S' && ($latitudeDecimalDegrees = $latitudeDecimalDegrees * -1); $longitudeHemisphere == 'W' && ($longitudeDecimalDegrees = $longitudeDecimalDegrees * -1); //78 78 25 16 0e 02 1b 11 11 26 c3 02 73 a8 0c 04 a6 5c 77 02 18 11 09 02 d4 0b 15 91 00 1e 0b 66 01 04 01 02 00 10 fe 67 0d 0a //66 01100110 $terminalInformation = decbin(hexdec($arCommands[31])); while (strlen($terminalInformation) < 8) { $terminalInformation = '0' . $terminalInformation; } $gasOil = substr($terminalInformation, 0, 1) == '0' ? 'S' : 'N'; $gpsTrack = substr($terminalInformation, 1, 1) == '1' ? 'S' : 'N'; $alarm = ''; switch (substr($terminalInformation, 2, 3)) { case '100': $alarm = 'help me'; break; case '011': $alarm = 'low battery'; break; case '010': $alarm = 'dt'; break; case '001': $alarm = 'move'; break; case '000': $alarm = 'tracker'; break; } $con = mysql_connect("cloudservice.cgejdsdl842e.sa-east-1.rds.amazonaws.com", "gpstracker", "d1\$1793689"); if ($con !== false) { mysql_select_db('tracker', $con); if ($alarm == "help me") { mysql_query("INSERT INTO message (imei, message) VALUES ('{$conn_imei}', 'SOS!')", $con); } mysql_close($con); } $charge = substr($terminalInformation, 5, 1) == '1' ? 'S' : 'N'; $acc = substr($terminalInformation, 6, 1) == '1' ? 'acc on' : 'acc off'; $defense = substr($terminalInformation, 7, 1) == '1' ? 'S' : 'N'; $voltageLevel = hexdec($arCommands[32]); $gsmSignal = hexdec($arCommands[33]); $alarmLanguage = hexdec($arCommands[34]); /* switch($alarmLanguage){ case 0: $alarm = 'normal'; break; case 1: $alarm = 'help me'; break; case 2: $alarm = 'dt'; break; case 3: $alarm = 'move'; break; case 4: $alarm = 'stockade'; break; case 5: $alarm = 'stockade'; break; } */ $dados = array($gpsPosition, $latitudeDecimalDegrees, $longitudeDecimalDegrees, $latitudeHemisphere, $longitudeHemisphere, $speed, $imei, $dataPosition, $alarm, $acc); tratarDados($dados); // echo "[PROTOCOLO 16] Lat/Long: ".$latitudeDecimalDegrees.", ".$longitudeDecimalDegrees."****************"; $send_cmd = '78 78 05 16 ' . strtoupper($arCommands[36]) . ' ' . strtoupper($arCommands[37]); //$crc = crcx25('05 16 '.strtoupper($arCommands[36]).' '.strtoupper($arCommands[37])); atualizarBemSerial($conn_imei, strtoupper($arCommands[36]) . ' ' . strtoupper($arCommands[37])); //$crc = str_replace('ffff','',dechex($crc)); //$crc = strtoupper(substr($crc,0,2)).' '.strtoupper(substr($crc,2,2)); $newString = ''; $newString = chr(0x5) . chr(0x16) . $rec[36] . $rec[37]; $crc16 = GetCrc16($newString, strlen($newString)); $crc16h = floor($crc16 / 256); $crc16l = $crc16 - $crc16h * 256; $crc = dechex($crc16h) . ' ' . dechex($crc16l); $send_cmd = $send_cmd . ' ' . $crc . ' 0D 0A'; $sendCommands = explode(' ', $send_cmd); printLog($fh, date("d-m-y h:i:sa") . " Imei: {$imei} Sent: {$send_cmd} Length: " . strlen($send_cmd)); $send_cmd = ''; for ($i = 0; $i < count($sendCommands); $i++) { $send_cmd .= chr(hexdec(trim($sendCommands[$i]))); } socket_send($socket, $send_cmd, strlen($send_cmd), 0); } else { if ($protocolNumber == '1A') { printLog($fh, date("d-m-y h:i:sa") . " Got: " . implode(" ", $arCommands)); } else { if ($protocolNumber == '80') { printLog($fh, date("d-m-y h:i:sa") . " Got: " . implode(" ", $arCommands)); } } } } } } } } } } $rec = ""; } //while }
function errorLog($str) { global $logFileHandle, $adminEmail; printLog($str); closeLogFile(); exit; }
public function run(array $params) { $pageSize = 500; $goodsBasicService = new Goods(); $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array()); for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) { // 查询商品 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize); foreach ($goodsArray as $goodsItem) { $goods_id = $goodsItem['goods_id']; printLog('begin process goods [' . $goods_id . ']'); $goodsObj = $goodsBasicService->loadGoodsById($goods_id); if ($goodsObj->isEmpty()) { printLog('goods [' . $goods_id . '] is empty'); } else { $goodsObj->goods_desc = str_replace('tuan.bangzhufu.com', 'www.bangzhufu.com', $goodsObj->goods_desc); $goodsObj->goods_desc = str_replace('cdn.bzfshop.net', 'img.bangzhufu.com', $goodsObj->goods_desc); $goodsObj->goods_desc = preg_replace('!/Goods/View/goods_id~([0-9]+).html!', '/Goods/View/goods_id-\\1.html', $goodsObj->goods_desc); $goodsObj->update_time = \Core\Helper\Utility\Time::gmTime(); $goodsObj->save(); } unset($goodsObj); printLog('end process goods [' . $goods_id . ']'); } } }
/** * Replace {{skin url=""}} with {{view url=""}} for given table field * * @param \Magento\Framework\ObjectManagerInterface $objectManager * @param string $table * @param string $col * @return void */ function updateFieldForTable($objectManager, $table, $col) { /** @var $installer \Magento\Framework\Setup\ModuleDataSetupInterface */ $installer = $objectManager->create('\\Magento\\Framework\\Setup\\ModuleDataSetupInterface'); $installer->startSetup(); $table = $installer->getTable($table); echo '-----' . "\n"; if ($installer->getConnection()->isTableExists($table)) { echo 'Table `' . $table . "` processed\n"; $indexList = $installer->getConnection()->getIndexList($table); $pkField = array_shift($indexList[$installer->getConnection()->getPrimaryKeyName($table)]['fields']); /** @var $select \Magento\Framework\DB\Select */ $select = $installer->getConnection()->select()->from($table, ['id' => $pkField, 'content' => $col]); $result = $installer->getConnection()->fetchPairs($select); echo 'Records count: ' . count($result) . ' in table: `' . $table . "`\n"; $logMessages = []; foreach ($result as $recordId => $string) { $content = str_replace('{{skin', '{{view', $string, $count); if ($count) { $installer->getConnection()->update($table, [$col => $content], $installer->getConnection()->quoteInto($pkField . '=?', $recordId)); $logMessages['replaced'][] = 'Replaced -- Id: ' . $recordId . ' in table `' . $table . '`'; } else { $logMessages['skipped'][] = 'Skipped -- Id: ' . $recordId . ' in table `' . $table . '`'; } } if (count($result)) { printLog($logMessages); } } else { echo 'Table `' . $table . "` was not found\n"; } $installer->endSetup(); echo '-----' . "\n"; }
/** * 针对notify_url验证消息是否是支付宝发出的合法消息 * * @return 验证结果 */ function verifyNotify() { if (empty($_POST)) { //判断POST来的数组是否为空 return false; } else { //生成签名结果 $isSign = $this->getSignVeryfy($_POST, $_POST["sign"]); //获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息) $responseTxt = 'true'; if (!empty($_POST["notify_id"])) { $responseTxt = $this->getResponse($_POST["notify_id"]); } //验证 //$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关 //isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关 if (preg_match("/true\$/i", $responseTxt) && $isSign) { return true; } //失败,写日志记录 if ($isSign) { $isSignStr = 'true'; } else { $isSignStr = 'false'; } $log_text = "Alipay responseTxt=" . $responseTxt . " notify_url_log:isSign=" . $isSignStr . ","; $log_text = $log_text . createLinkString($_POST); printLog($log_text, 'PAYMENT', Base::ERROR); return false; } }
function printLogL($str, $level) { for ($i = 1; $i <= $level; ++$i) { $str = "\t" . $str; } printLog($str); }
public function run(array $params) { global $f3; // 1. reset 整个数据库 printLog('Begin Reset Database', 'ResetData'); $dbEngine = DataMapper::getDbEngine(); // 解析 sql 文件,导入数据 $sqlFileContent = file_get_contents(CONSOLE_PATH . '/../install/Asset/data/bzfshop.sql'); $sqlFileContent = SqlHelper::removeComment($sqlFileContent); $sqlArray = SqlHelper::splitToSqlArray($sqlFileContent, ';'); unset($sqlFileContent); foreach ($sqlArray as $sqlQuery) { $queryObject = $dbEngine->prepare($sqlQuery); $queryObject->execute(); unset($sqlQuery); unset($queryObject); } unset($sqlArray); printLog('End Reset Database', 'ResetData'); // 2. 删除 /data 目录下的所有目录 printLog('remove everything under /data', 'ResetData'); $this->removeAllDirInsideDir($f3->get('sysConfig[data_path_root]')); // 3. 删除 RunTime 目录下所有目录 printLog('remove everything in Runtime', 'ResetData'); $this->removeAllDirInsideDir($f3->get('sysConfig[runtime_path]') . DIRECTORY_SEPARATOR . 'Log/'); $this->removeAllDirInsideDir($f3->get('sysConfig[runtime_path]') . DIRECTORY_SEPARATOR . 'Smarty/'); $this->removeAllDirInsideDir($f3->get('sysConfig[runtime_path]') . DIRECTORY_SEPARATOR . 'Temp/'); // 4. 清除 F3 的缓存 $f3->clear('CACHE'); printLog('ResetData Done', 'ResetData'); }
/** * Replace {{skin url=""}} with {{view url=""}} for given table field * * @param string $table * @param string $col */ function updateFieldForTable($table, $col) { /** @var $installer Mage_Core_Model_Resource_Setup */ $installer = Mage::getResourceModel('Mage_Core_Model_Resource_Setup', array('resourceName' => 'core_setup')); $installer->startSetup(); $table = $installer->getTable($table); print '-----' . "\n"; if ($installer->getConnection()->isTableExists($table)) { print 'Table `' . $table . "` processed\n"; $indexList = $installer->getConnection()->getIndexList($table); $pkField = array_shift($indexList[$installer->getConnection()->getPrimaryKeyName($table)]['fields']); /** @var $select Varien_Db_Select */ $select = $installer->getConnection()->select()->from($table, array('id' => $pkField, 'content' => $col)); $result = $installer->getConnection()->fetchPairs($select); print 'Records count: ' . count($result) . ' in table: `' . $table . "`\n"; $logMessages = array(); foreach ($result as $recordId => $string) { $content = str_replace('{{skin', '{{view', $string, $count); if ($count) { $installer->getConnection()->update($table, array($col => $content), $installer->getConnection()->quoteInto($pkField . '=?', $recordId)); $logMessages['replaced'][] = 'Replaced -- Id: ' . $recordId . ' in table `' . $table . '`'; } else { $logMessages['skipped'][] = 'Skipped -- Id: ' . $recordId . ' in table `' . $table . '`'; } } if (count($result)) { printLog($logMessages); } } else { print 'Table `' . $table . "` was not found\n"; } $installer->endSetup(); print '-----' . "\n"; }
/** * 生成搜索的具体 instance * * @return ISearch * @throws \InvalidArgumentException */ protected static function getSearchInstance() { if (!static::$searchInstance) { static::$searchInstance = new static::$searchImplementClass(); if (!static::$searchInstance instanceof ISearch) { throw new \InvalidArgumentException(static::$searchImplementClass . ' is invalid search implement'); } if (!static::$searchInstance->init(static::$searchImplementInitParamArray)) { printLog(static::$searchImplementClass . ' init failed with param ' . print_r(static::$searchImplementInitParamArray, true), __CLASS__, \Core\Log\Base::ERROR); throw new \InvalidArgumentException('can not init ' . static::$searchImplementClass); } } return static::$searchInstance; }
/** * 根据 task_class 参数加载并实例化 Cron 任务对象 * * @param string $task_class * * @return ICronTask 对象 */ public static function loadTaskClass($task_class) { if (!class_exists($task_class)) { printLog('class [' . $task_class . '] does not exist', __CLASS__, BaseLog::ERROR); return null; } $taskInstance = new $task_class(); if (!is_a($taskInstance, '\\Core\\Cron\\ICronTask')) { printLog('class [' . $task_class . '] does not implement ICronTask', __CLASS__, BaseLog::ERROR); unset($taskInstance); return null; } return $taskInstance; }
/** * 添加一个用于 class autoload 的路径 * * 注意:我们允许 plugin 覆盖系统本身的功能,所以如果你的 path 里面包含和系统名字一样的 Controller, * 你就可能会覆盖系统已有的操作 * * @param string $path * @param bool $addToHead 是否加入搜索路径的开头,如果你的类不常用,请加入到搜索末尾有利于提高搜索效率 * */ public static function addAutoloadPath($path, $addToHead = false) { if (!file_exists($path)) { printLog('[' . $path . '] does not exist', 'SystemHelper', \Core\Log\Base::WARN); return; } $path = realpath($path); global $f3; if ($addToHead) { // 加到搜索路径开头 $f3->set('AUTOLOAD', $path . '/;' . $f3->get('AUTOLOAD')); } else { // 加到搜索路径末尾 $f3->set('AUTOLOAD', $f3->get('AUTOLOAD') . $path . '/;'); } }
/** * 调用对应的对象方法 * * @param $func * @param array $args * * @return mixed * @throws \InvalidArgumentException */ static function __callstatic($func, array $args) { foreach (static::$registerClassArray as $className => $initParam) { $instance = static::loadClassInstance($className, $initParam); // 检查方法是否存在 if (!method_exists($instance, $func)) { throw new \InvalidArgumentException('class [' . $className . '] has no method [' . $func . ']'); } global $f3; if ($f3->get('DEBUG') > 2) { printLog('call [' . $className . '] method [' . $func . ']', __CLASS__, \Core\Log\Base::DEBUG); } // 调用对象方法 call_user_func_array(array($instance, $func), $args); // 释放内存 unset($instance); } }
private function loadModule($searchType) { // 检查对应的搜索模块是否存在 $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $searchType . '.php'; if (!file_exists($filePath)) { // 没有对应的搜索模块,失败 printLog($searchType . ' does not exist', __CLASS__, \Core\Log\Base::ERROR); return false; } require_once $filePath; // 生成搜索模块 $searchType = __NAMESPACE__ . '\\' . $searchType; $searchModule = new $searchType(); if (!$searchModule || !$searchModule instanceof ISearch) { throw new \InvalidArgumentException($searchType . ' is an invalid ISearch'); } return $searchModule; }
public function run(array $params) { global $f3; // 每次处理多少条记录 $batchProcessCount = 100; // 图片所在的根目录 $dataPathRoot = $f3->get('sysConfig[data_path_root]'); $image_thumb_width = $f3->get('sysConfig[image_thumb_width]'); $image_thumb_height = $f3->get('sysConfig[image_thumb_height]'); $goodsGalleryService = new GoodsGalleryService(); $baseService = new BaseService(); $totalGoodsGalleryCount = $baseService->_countArray('goods_gallery', null); // 记录处理开始 for ($offset = 0; $offset < $totalGoodsGalleryCount; $offset += $batchProcessCount) { $goodsGalleryArray = $baseService->_fetchArray('goods_gallery', '*', null, array('order' => 'img_id asc'), $offset, $batchProcessCount); foreach ($goodsGalleryArray as $goodsGalleryItem) { if (!is_file($dataPathRoot . '/' . $goodsGalleryItem['img_original'])) { continue; // 文件不存在,不处理 } $pathInfoArray = pathinfo($goodsGalleryItem['img_original']); //生成缩略图 $imageThumbFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $image_thumb_width . 'x' . $image_thumb_height . '.jpg'; //重新生存缩略图 printLog('Re-generate File :' . $imageThumbFileRelativeName); StorageImageHelper::resizeImage($dataPathRoot, $goodsGalleryItem['img_original'], $imageThumbFileRelativeName, $image_thumb_width, $image_thumb_height); // 更新 goods_gallery 设置 printLog('update goods_gallery img_id [' . $goodsGalleryItem['img_id'] . ']'); $goodsGallery = $goodsGalleryService->loadGoodsGalleryById($goodsGalleryItem['img_id']); if (!$goodsGallery->isEmpty()) { $goodsGallery->thumb_url = $imageThumbFileRelativeName; $goodsGallery->save(); } // 主动释放资源 unset($goodsGallery); unset($pathInfoArray); unset($imageThumbFileRelativeName); } unset($goodsGalleryArray); printLog('re-generate thumb image offset : ' . $offset); } printLog('re-generate thumb image finished , offset : ' . $offset); }
public static function SelectValue($retrieveValue, $tablename, $conditions) { $mydb = self::getFactory()->getConnection(); $values = array(); $condclauses = array(); foreach ($conditions as $key => $value) { $condclauses[] = $key . "=?"; $values[] = $value; } $stmtString = "SELECT " . $retrieveValue . " FROM " . $tablename . " WHERE "; $stmtString .= getArrayInString($condclauses, 'and'); $stmt = $mydb->prepare($stmtString); $start = microtime(true); $stmt->execute($values); $time = microtime(true) - $start; self::$log[] = array('query' => $stmt->queryString, 'time' => round($time * 1000, 3)); return $stmt->fetchColumn(); printLog(); }
public function run(array $params) { global $f3; // 每次处理多少条记录 $batchProcessCount = 100; $baseService = new BaseService(); $totalGoodsCount = $baseService->_countArray('goods', null); // 记录处理开始 for ($offset = 0; $offset < $totalGoodsCount; $offset += $batchProcessCount) { $goodsArray = $baseService->_fetchArray('goods', 'goods_id', null, array('order' => 'goods_id asc'), $offset, $batchProcessCount); foreach ($goodsArray as $goodsItem) { $sql = "update " . DataMapper::tableName('goods') . ' set ' . ' user_buy_number = (select sum(goods_number) from ' . DataMapper::tableName('order_goods') . ' where goods_id = ? )' . ' ,user_pay_number = (select sum(goods_number) from ' . DataMapper::tableName('order_goods') . ' where goods_id = ? and order_goods_status > 0)' . ' where goods_id = ? order by goods_id asc limit 1 '; $dbEngine = DataMapper::getDbEngine(); $dbEngine->exec($sql, array(1 => $goodsItem['goods_id'], $goodsItem['goods_id'], $goodsItem['goods_id'])); } unset($goodsArray); printLog('calculate goods buy number offset : ' . $offset); } printLog('calculate goods buy number finished , offset : ' . $offset); }
public function run(array $params) { printLog('Begin CreateDictionary', 'CreateDictionary'); $metaDictionaryService = new MetaDictionaryService(); // 用于 order_refer 中显示订单来源渠道 utm_source $metaDictionaryService->saveWord('SELF', '网站自身', '网站自身', ''); $metaDictionaryService->saveWord('TUAN360CPS', '360团购导航', '360团购导航', ''); $metaDictionaryService->saveWord('YIQIFACPS', '亿起发', '亿起发', ''); $metaDictionaryService->saveWord('DUOMAICPS', '多麦', '多麦', ''); // 用于 order_refer 中显示订单来源渠道 utm_medium $metaDictionaryService->saveWord('QQCAIBEI', 'QQ彩贝', 'QQ彩贝', ''); $metaDictionaryService->saveWord('TUAN360TEQUAN', '360特权', '360特权', ''); $metaDictionaryService->saveWord('TUAN360WAP', '360手机WAP', '360手机WAP', ''); // 用于 order_refer 中显示订单登陆方式 login_type $metaDictionaryService->saveWord('normal', '普通登陆', '普通登陆', ''); $metaDictionaryService->saveWord('qqcaibei', 'QQ彩贝登陆', 'QQ彩贝登陆', ''); $metaDictionaryService->saveWord('qqlogin', 'QQ登陆', 'QQ登陆', ''); $metaDictionaryService->saveWord('tuan360auth', '360联合登陆', '360联合登陆', ''); printLog('Finish CreateDictionary', 'CreateDictionary'); }
public function run(array $params) { global $f3; $outputFile = $f3->get('TEMP') . 'CheckGoodsInnerImageUrl.log'; $imageHostAllow = array('img.bangzhufu.com'); $pageSize = 500; $goodsBasicService = new Goods(); $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array()); for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) { // 查询商品 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize); foreach ($goodsArray as $goodsItem) { $goods_id = $goodsItem['goods_id']; printLog('begin process goods [' . $goods_id . ']'); $goodsObj = $goodsBasicService->loadGoodsById($goods_id); if ($goodsObj->isEmpty()) { printLog('goods [' . $goods_id . '] is empty'); } else { $patternMatch = array(); preg_match_all('/<img(.*?)src="(.*?)"(.*?)\\/?>/', $goodsObj->goods_desc, $patternMatch, PREG_SET_ORDER); $isFirst = true; // 处理每一个图片 foreach ($patternMatch as $matchItem) { $imageUrl = $matchItem[2]; $urlInfo = parse_url($imageUrl); if (!in_array(@$urlInfo['host'], $imageHostAllow)) { if ($isFirst) { $isFirst = false; $f3->write($outputFile, "\n\ngoods_id:" . $goodsObj->goods_id . "\n", true); } $f3->write($outputFile, "\t" . $matchItem[2] . "\n", true); printLog('illegal image url [' . $matchItem[2] . ']'); } } unset($patternMatch); } unset($goodsObj); printLog('end process goods [' . $goods_id . ']'); } } }
/** * 驱动 Cron 任务执行 * * @param $f3 */ public function Run($f3) { $taskCount = 0; while (($cronTask = CronHelper::loadNextUnRunCronTask(Time::gmTime())) && $taskCount++ < self::$maxRunTaskCount) { $cronResult = array('code' => -1, 'message' => '任务内部错误,请查看日志'); // 加载 Task Class $taskInstance = CronHelper::loadTaskClass($cronTask['task_class']); // 无法实例化 task class,打印错误日志 if (null == $taskInstance) { printLog('can not instantiate task ' . json_encode($cronTask->toArray()), __CLASS__, \Core\Log\Base::ERROR); } else { // 执行任务 $cronResult = call_user_func_array(array($taskInstance, 'run'), array(json_decode($cronTask['task_param'], true))); } // 释放内存 unset($taskInstance); // 更新任务执行状态 $cronTask->task_run_time = Time::gmTime(); $cronTask->return_code = @$cronResult['code']; $cronTask->return_message = @$cronResult['message']; $cronTask->save(); unset($cronTask); } }
/** * 把一个表的数据转换到另外一个表中 * * @param string $srcTableName 源表名 * @param array $condArray * array( * array('supplier_id = ?', $supplier_id) * array('is_on_sale = ?', 1) * array('supplier_price > ? or supplier_price < ?', $priceMin, $priceMax) * ) * @param array $optionArray 排序分页等条件 ,格式例如 array('order' => 'goods_id asc', 'offset' => 100, 'limit' => '10') * @param string $dstTableName 目的表名 * @param array $columnMap 列对应,格式如 array('id' => 'goods_id' , 'name' => 'goods_name') * @param array $srcValueConvertFuncArray * 对源数据做装换,例如: array('id' => function($srcValue, $srcRecord){ return $srcValue + 1;} , ...),用闭包函数做转化 * @param callable $recordPreFunc 在查询到 src 的记录之后调用 ,函数原型 function(&$srcRecord){ ... } * @param callable $recordPostFunc 在 src 已经往 dst 赋值完成之后,dst 还没有写入数据库之前调用,函数原型 function(&$srcRecord, &dstRecord){...} * */ public function convertTable($srcTableName, $condArray, $optionArray, $dstTableName, $columnMap, $srcValueConvertFuncArray, $recordPreFunc = null, $recordPostFunc = null) { $srcFieldArray = array(); $dstFieldArray = array(); foreach ($columnMap as $srcField => $dstField) { $srcFieldArray[] = $srcField; $dstFieldArray[] = $dstField; } $srcTable = new SrcDataMapper($srcTableName); // 构造查询条件 $filter = null; if (!empty($condArray)) { $filter = QueryBuilder::buildAndFilter($condArray); } // 获得总数 $totalRecordCount = $srcTable->count($filter); printLog('begin convertTable ' . $srcTableName . '-->' . $dstTableName . ' totalRecordCount:' . $totalRecordCount, self::$loggerSource); $recordLeft = $totalRecordCount; // 剩余多少记录需要处理 $queryOffset = 0; // 查询的起始位置 while ($recordLeft > 0) { // 这次需要处理多少记录 $processCount = $recordLeft > $this->batchProcessCount ? $this->batchProcessCount : $recordLeft; // 记录处理进度 printLog('totalRecordCount:' . $totalRecordCount . ' recordLeft:' . $recordLeft . ' processCount:' . $processCount, self::$loggerSource); $recordLeft -= $processCount; // 从源表查询数据 $srcField = '*'; if (!empty($srcFieldArray)) { $srcField = implode(',', $srcFieldArray); } // 处理查询的起始位置 $optionArray = array_merge($optionArray, array('offset' => $queryOffset, 'limit' => $processCount)); $queryOffset += $processCount; // 查询数据 $srcRecordList = $srcTable->select($srcField, $filter, $optionArray); // 转换数据到目标表中 foreach ($srcRecordList as $srcRecordItem) { // PreFunc 处理 if ($recordPreFunc) { $recordPreFunc($srcRecordItem); } $dstTable = new DstDataMapper($dstTableName); //字段复制 foreach ($columnMap as $srcField => $dstField) { // 无意义的字段,不复制 if (null == $dstField) { continue; } if (isset($srcValueConvertFuncArray) && isset($srcValueConvertFuncArray[$srcField])) { if (!is_callable($srcValueConvertFuncArray[$srcField])) { printLog($srcField . ' value convert is not function ', self::$loggerSource, \Core\Log\Base::ERROR); continue; } // 做数据转化 $dstTable->{$dstField} = $srcValueConvertFuncArray[$srcField]($srcRecordItem[$srcField], $srcRecordItem); } else { $dstTable->{$dstField} = $srcRecordItem[$srcField]; } } // postFunc 处理 if ($recordPostFunc) { $recordPostFunc($srcRecordItem, $dstTable); } $dstTable->save(); unset($dstTable); // 及时释放数据,优化内存使用 } unset($srcRecordList); // 及时释放数据,优化内存使用 gc_collect_cycles(); // 主动做一次垃圾回收 } printLog('finish convertTable ' . $srcTableName . '-->' . $dstTableName . ' totalRecordCount:' . $totalRecordCount, self::$loggerSource); }
public function doReturnUrl($f3) { printLog('CreditPay returnUrl success', 'PAYMENT', Base::INFO); // 设置 order_id $this->orderId = $f3->get('GET[order_id]'); return true; }
public function post($f3) { //首先验证参数签名 $map = $_POST; unset($map['Vkey']); //读取除了vkey外的所有参数,并且放入数组map中 ksort($map); //进行按参数的升序排序 //进行签名,注意考虑到md5加密输出的大小写问题,所有约定md5的输出均为小写 $vkey = implode('', array_values($map)); $md5_1 = strtolower(md5($vkey . YiqifaCpsPlugin::getOptionValue('qqcaibei_key1'))); $vkey = strtolower(md5($md5_1 . YiqifaCpsPlugin::getOptionValue('qqcaibei_key2'))); if ($vkey != $_POST['Vkey']) { // 参数签名错误 goto out; } // 保存额外的 亿起发 参数 $orderRefer = array(); $orderRefer['utm_medium'] = 'QQCAIBEI'; //设置 cookie ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration')); $f3->set('SESSION[yiqifa_caibei_order_refer]', ReferHelper::parseOrderRefer($f3)); // 取得QQ彩贝传递过来的参数 //$acct = @$_POST['Acct']; $url = @$_POST['Url']; $openId = @$_POST['OpenId']; //$clubInfo = @intval($_POST['ClubInfo']); // 会员等级信息,目前没用 $viewInfo = @$_POST['ViewInfo']; if (get_magic_quotes_gpc()) { $viewInfo = stripslashes($viewInfo); } $viewInfoArray = array(); parse_str($viewInfo, $viewInfoArray); //解析 viewInfoArray 数组 //$f3->set('SESSION[qqcaibei_viewinfoarray]', json_encode($viewInfoArray)); //放入到 session 里面 // 设置 ClientData ClientData::saveClientData('qqcaibei_viewinfoarray', json_encode($viewInfoArray)); if (empty($openId)) { // 没有 openId 没法登陆,直接退出 goto out; } // 这里做 QQ彩贝 联合登陆 $sns_login = "******"; // 用户登陆操作 $userBasicService = new UserBasicService(); $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false); if ($authUser) { goto out_login_user; } // 之前没有登陆过,自动注册用户 $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true); printLog('注册QQ用户:' . print_r($viewInfoArray, true), 'QQLOGIN', \Core\Log\Base::INFO); out_login_user: AuthHelper::saveAuthUser($authUser->toArray(), 'qqcaibei'); // 设置用户名在网页显示 ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true); ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ彩贝用户:' . $viewInfoArray['NickName']); out: // 页面跳转到商品 $redirectUrl = empty($url) ? '/' : $url; RouteHelper::reRoute($this, $redirectUrl); return; }
} } for ($i = 0; $i < count($seller_emails); $i++) { $emailer = new email_handler(); $emailer->assign_vars(array('ID' => $seller_emails[$i]['id'], 'TITLE' => $seller_emails[$i]['title'], 'NAME' => $seller_emails[$i]['name'], 'LINK' => $system->SETTINGS['siteurl'] . 'pay.php?a=7&auction_id=' . $Auction['id'])); $emailer->email_uid = $seller_emails[$i]['uid']; $emailer->email_sender($seller_emails[$i]['email'], 'final_value_fee.inc.php', $system->SETTINGS['sitename'] . ' - ' . $MSG['523']); } // Purging thumbnails cache if (!file_exists($upload_path . 'cache')) { mkdir($upload_path . 'cache', 0777); } if (!file_exists($upload_path . 'cache/purge')) { touch($upload_path . 'cache/purge'); } $purgecachetime = filectime($upload_path . 'cache/purge'); if (time() - $purgecachetime > 86400) { $dir = $upload_path . 'cache'; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != 'purge' && !is_dir($dir . '/' . $file) && time() - filectime($dir . '/' . $file) > 86400) { unlink($dir . '/' . $file); } } closedir($dh); } touch($upload_path . 'cache/purge'); } // finish cron script printLog("=========================== ENDING CRON: " . gmdate('F d, Y H:i:s') . "\n");
public function run(array $params) { printLog('Begin CreatePrivilege', 'CreatePrivilege'); $metaPrivilegeService = new MetaPrivilegeService(); // 商品管理权限 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_goods', '商品管理', '管理网站的所有商品'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_create', '新建商品', '创建一个新商品'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_search', '查看商品列表', '查看商品列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_edit_edit_get', '商品编辑-查看', '查看商品编辑的内容'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_edit_edit_post', '商品编辑-保存', '保存商品编辑的内容'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_attrgroup_listattrgroup', '查看商品类型列表', '查看商品类型列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_attrgroup_create', '新建商品类型', '新建商品类型'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_attrgroup_edit', '编辑商品类型', '编辑商品类型'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_category_edit', '编辑商品分类', '编辑商品分类'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_comment_listcomment', '查看用户评价列表', '查看用户评价列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_comment_edit', '编辑用户评价', '编辑用户评价'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_goods_comment_create', '新建用户评价', '新建用户评价'); // 订单管理权限 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_order', '订单管理', '管理网站的订单'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_order_search', '查看订单列表', '查看订单列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_order_detail', '查看订单详情', '查看订单详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_order_markpay', '订单标记付款', '手动设置订单状态为已经付款'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_search', '查看售出商品列表', '查看售出商品列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_detail', '查看售出商品详情', '查看售出商品详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_update_set_extra_discount', '商品额外优惠', '售出商品给顾客额外优惠'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_update_set_suppliers_price', '商品修改供货价', '售出商品订单单独修改供货价'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_update_set_shipping_no', '设置快递信息', '设置售出商品的快递信息'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_update_set_memo', '售出商品备注', '对售出商品增加备注信息'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_update_set_refund', '商品申请退款', '对售出商品申请退款'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_goods_update_set_extra_refund', '商品额外退款', '对售出商品操作额外退款'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_refund_search', '查看商品退款', '查看商品退款列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_refund_confirm', '确认商品退款', '确认商品退款'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_excel_download', '批量下载订单', '批量下载订单'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_excel_upload', '批量上传快递', '批量上传快递单号'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_statistics_listgoods', '查看商品销售排行', '查看商品的销售排行'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_settle', '订单结算', '对订单做结算操作'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_settle_listsettle', '查看结算历史', '查看订单结算历史'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_settle_listordergoods', '查看结算明细', '查看订单结算明细'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_settle_ajaxdetail', '查看结算详情', '查看订单结算详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_order_settle_update', '修改结算详情', '修改订单结算详情'); // 文章管理 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_article', '文章管理', '管理网站的文章'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_article_article_edit', '编辑文章', '编辑文章内容'); // 账号管理权限 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_account', '账号管理', '管理网站的各种账号'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_supplier_create', '新建供货商', '新建供货商账号'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_supplier_listuser', '查看供货商列表', '查看供货商列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_supplier_edit_get', '查看供货商详情', '查看供货商详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_supplier_edit_post', '修改供货商详情', '修改供货商详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_supplier_edit_change_account_password', '修改供货商密码', '修改供货商的登陆账号、登陆密码'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_create', '新建管理员', '新建管理员账号'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_listuser', '查看管理员列表', '查看管理员列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_edit_get', '查看管理员详情', '查看管理员详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_edit_post', '修改管理员详情', '修改管理员详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_edit_change_account_password', '修改管理员密码', '修改管理员的登陆账号、登陆密码'); // 用户管理权限 $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_user_search', '查看用户列表', '查看用户列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_user_charge', '给用户充值', '给用户充值'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_user_money', '查看用户资金', '查看用户资金变动明细'); // 给其它用户授权的权限 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_privilege_grant', '用户授权', '给其他用户授权'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_privilege_get', '查看管理员权限', '查看管理员拥有的权限'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_admin_privilege_post', '修改管理员权限', '修改管理员拥有的权限'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_role_listrole', '查看角色列表', '查看角色列表'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_role_create', '创建角色', '创建角色,比如客服角色'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_role_edit_get', '查询角色详情', '查询角色详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_role_edit_post', '修改角色详情', '修改角色详情'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_role_privilege_get', '查看角色权限', '查看用户角色拥有的权限'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_account_role_privilege_post', '修改角色权限', '修改用户角色拥有的权限'); // 杂项设置 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_misc', '杂项设置', '网站杂七杂八的其它设置'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_misc_cache', '缓存管理', '管理系统的各种缓存数据'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_misc_express_edit', '编辑快递公司', '编辑快递公司的信息'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_misc_cron', '定时任务', '管理系统的定时任务'); // 数据统计 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_stat', '数据统计', '网站的各种数据统计'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_stat_order_refer_get', '来源渠道统计', '订单来源渠道的利润统计'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_stat_order_refer_download', '来源渠道订单下载', '根据来源渠道下载订单'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_stat_kaohe_kefu', '查看客服考核', '查看所有客服的考核业绩'); // 插件管理 $privilegeGroup = $metaPrivilegeService->savePrivilegeGroup('manage_plugin', '插件主题', '插件和系统主题的管理'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_plugin_installplugin', '插件安装', '给系统安装新的插件'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_plugin_uninstallplugin', '插件卸载', '卸载系统已经安装的插件'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_plugin_activateplugin', '启用插件', '启用系统已经安装的插件'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_plugin_deactivateplugin', '停用插件', '停用系统已经安装的插件'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_plugin_configure', '配置插件', '调用插件的配置功能'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_theme_installtheme', '主题安装', '给系统安装新的主题'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_theme_uninstalltheme', '主题卸载', '卸载系统已经安装的主题'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_theme_activatetheme', '启用主题', '启用系统已经安装的主题'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_theme_configure', '配置主题', '调用主题的配置功能'); $metaPrivilegeService->savePrivilegeItem($privilegeGroup['meta_id'], 'manage_plugin_theme_adv_configure', '广告设置', '设置主题的广告位置'); printLog('Finish CreatePrivilege', 'CreatePrivilege'); }
/** * 清除所有的 Asset */ public function clearAllAsset() { $saeKv = $this->getSaeKv(); $clearCount = 0; for (;;) { // 每次取 100 个 $keyValueArray = $saeKv->pkrget(self::$saeKeyPrefix, 100, false); if (empty($keyValueArray)) { goto out; } // 清除数据 foreach ($keyValueArray as $key => $value) { $saeKv->delete($key); $clearCount++; } } out: printLog('clear SaeAsset success count [' . $clearCount . ']', __CLASS__); }
/** * 合并文件,并且返回合并之后的文件名 * * @param string $moduleUniqueId * @param array $fileRelativePathArray * @param string $fileExt 合并之后的文件扩展名 * @param callback $fileContentFilter 对每个文件的内容做 filter * * @return string 合并之后的文件名 */ private function mergeAssetCssJsFile($moduleUniqueId, array $fileRelativePathArray, $fileExt, $fileContentFilter = null) { if (empty($fileRelativePathArray)) { throw new \InvalidArgumentException('fileRelativePathArray can not be empty'); } $targetModuleBasePath = $this->assetBasePath . DIRECTORY_SEPARATOR . $this->getModulePublishRelativeDir($moduleUniqueId) . DIRECTORY_SEPARATOR; // 计算合并之后的文件名 $targetFileNameSource = ''; foreach ($fileRelativePathArray as $relativeAssetPath) { // 智能发布资源 $this->publishAsset($moduleUniqueId, $relativeAssetPath); $sourcePath = $targetModuleBasePath . $relativeAssetPath; if (!is_file($sourcePath)) { printLog('Calculate FileNameSource Error : [' . $sourcePath . '] is not a regular file', 'AssetManager', \Core\Log\Base::ERROR); continue; } $targetModifyTime = filemtime($sourcePath); $targetFileNameSource .= '{' . $sourcePath . '[' . $targetModifyTime . ']}'; } // 目标文件名 $targetFileNameSourceMd5 = md5($targetFileNameSource); $targetFileName = $targetFileNameSourceMd5 . '.min' . $fileExt; // 合并文件已经存在,直接退出就可以了 if (is_file($targetModuleBasePath . $targetFileName)) { goto out; } // 打印 log printLog($targetFileNameSource, 'AssetManager'); // 做文件的合并 $filterArray = array(); // 建立对应的 filter if ('.js' == $fileExt) { $filterArray = array(new JSMinFilter()); } elseif ('.css' == $fileExt) { $filterArray = array(new CssImportFilter(), new CssRewriteFilter(), new CssMinFilter()); } else { // do nothing } $mergeFileContent = ''; foreach ($fileRelativePathArray as $relativeAssetPath) { $sourcePath = $targetModuleBasePath . $relativeAssetPath; if (!is_file($sourcePath)) { printLog('Merge File Error : [' . $sourcePath . '] is not a regular file', 'AssetManager', \Core\Log\Base::ERROR); continue; } // 我们采用 Assetic 来做文件处理 $fileAsset = new FileAsset($targetModuleBasePath . $relativeAssetPath, $filterArray, $targetModuleBasePath, $relativeAssetPath); $fileAsset->setTargetPath('.'); $mergeFileContent .= $fileContentFilter ? call_user_func_array($fileContentFilter, array($relativeAssetPath, $fileAsset->dump())) : $fileAsset->dump(); unset($fileAsset); // 释放内存 } // 生成合并之后的文件 file_put_contents($targetModuleBasePath . $targetFileName, $mergeFileContent); out: return $targetFileName; }
public function run(array $params) { ini_set('memory_limit', '1024M'); // 内存 1G 应该够用了 global $f3; printLog('Begin initDataSource', 'MigrateZuiTu'); $this->initDataSource(); //快递数据的转化 //printLog('Begin convertZone', 'MigrateZuiTu'); //$this->convertZone(); //商品分类的转化 printLog('Begin convertCategory', 'MigrateZuiTu'); $this->convertCategory(); //供货商账号的转化 printLog('Begin convertSuppliers', 'MigrateZuiTu'); $this->convertSuppliers(); //商品的转化 printLog('Begin convertGoods', 'MigrateZuiTu'); $this->convertGoods(); //商品团购信息的转化 printLog('Begin convertGoodsTeam', 'MigrateZuiTu'); $this->convertGoodsTeam(); //商品推广渠道信息转化 printLog('Begin convertGoodsPromote', 'MigrateZuiTu'); $this->convertGoodsPromote(); //管理员账号转化 printLog('Begin convertAdminUser', 'MigrateZuiTu'); $this->convertAdminUser(); //普通用户账号转化 printLog('Begin convertUsers', 'MigrateZuiTu'); $this->convertUsers(); //清除一些无关的表 printLog('Begin clearTable', 'MigrateZuiTu'); $this->clearTable(); printLog('Finish Migrate', 'MigrateZuiTu'); }
/** * 加载所有 Active 的 theme * * @param string $system * @param string $excludeSystemTheme 排除某个系统 */ public static function loadActiveTheme($system, $excludeSystemTheme = null) { $activeThemeArray = ThemeHelper::getActiveThemeArray(); if (empty($activeThemeArray)) { return; } foreach ($activeThemeArray as $activeTheme) { // 排除某个系统 if ($excludeSystemTheme == $activeTheme) { printLog('exclude theme [' . $activeTheme . ']', 'PLUGIN', \Core\Log\Base::DEBUG); continue; } $instance = static::loadPluginInstance($activeTheme); if (!$instance) { printLog('theme [' . $activeTheme . '] does not exist', 'PLUGIN', \Core\Log\Base::ERROR); continue; } //调用插件的 load 方法做初始化 if (true !== $instance->pluginLoad($system)) { // 如果加载失败,就不要做后面的操作了 printLog('load theme [' . $activeTheme . '] failed', 'PLUGIN', \Core\Log\Base::DEBUG); unset($instance); continue; } global $f3; if ($f3->get('DEBUG')) { printLog('load theme [' . $activeTheme . '] success', 'PLUGIN', \Core\Log\Base::DEBUG); } // 把插件放入到列表中 static::$pluginInstanceArray[$activeTheme] = $instance; unset($instance); } }
public function doReturnUrl($f3) { // 把 GET 都赋值给 POST $_POST = $_GET; $ret = $this->doNotifyUrl($f3); if ($ret) { printLog('Tenpay returnUrl success', 'PAYMENT', Base::INFO); } else { printLog('Tenpay returnUrl fail', 'PAYMENT', Base::ERROR); } return $ret; }
$writer->writeElement('creation-date', date("d/m/y : H:i:s", time())); writeOffers($items, $writer); writeOffers($itemsMetro, $writer); writeOffers($itemsNeigh, $writer); $writer->endDocument(); $writer->flush(); printLog('Finished feed for ' . $cityData['sufix']); } $stmt = $db->prepare($citiesSql); $res = $stmt->execute(); if ($res === false) { print_r($stmt->errorInfo()); die; } $stmt->setFetchMode(PDO::FETCH_ASSOC); $smallCitiesItems = $stmt->fetchAll(); $stmt->closeCursor(); $smallCitiesItems = prepareSmallCitiesItems($smallCitiesItems); printLog('Filling feed for other cities'); $writer = new XMLWriter(); $writer->openURI($file_path . 'context_rk_realty_other.xml'); $writer->startDocument('1.0', 'UTF-8'); $writer->setIndent(TRUE); $writer->startElement('root'); $writer->writeElement('creation-date', date("d/m/y : H:i:s", time())); writeOffers($smallCitiesItems, $writer); $writer->endDocument(); $writer->flush(); printLog('Finished feed for other cities'); printLog('Finished script');