Skip to content

Instantly share code, notes, and snippets.

@nanasess
Last active August 29, 2015 13:58
Show Gist options
  • Save nanasess/10111224 to your computer and use it in GitHub Desktop.
Save nanasess/10111224 to your computer and use it in GitHub Desktop.
execute interval.
<?php
require_once("../../../require.php");
mb_http_output('pass');
header('Content-type: text/html');
$objWksConnMethod = new SC_WakasaConnectMethod();
$objWksConnMethod->setSalesClass($_POST["stype"]);
//$objWksConnMethod->parseXmlFlag = false;
//$objWksConnMethod->convertCharEncodeFlag = false;
// デフォルト値
$detail_nextday = date('Y/m/d', strtotime('+ 10 days'));
$arrPostAll = array(
array(
'ORDER_KIND' => 1,
'SEQ' => 1,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0001',
'ITEM_QTY' => 1,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 1,
'SEQ' => 2,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0004',
'ITEM_QTY' => 2,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 1,
'SEQ' => 3,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0170',
'ITEM_QTY' => 3,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 2,
'SEQ' => 4,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0035',
'ITEM_QTY' => 4,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 2,
'SEQ' => 5,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0002',
'ITEM_QTY' => 5,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 1,
'SEQ' => 6,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0226',
'ITEM_QTY' => 2,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 1,
'SEQ' => 7,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0227',
'ITEM_QTY' => 3,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 1,
'SEQ' => 8,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0229',
'ITEM_QTY' => 4,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 2,
'SEQ' => 9,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0227',
'ITEM_QTY' => 5,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
array(
'ORDER_KIND' => 2,
'SEQ' => 10,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0229',
'ITEM_QTY' => 1,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
),
);
$arrPost =array(
'ORDER_KIND' => 2,
'SEQ' => 10,
'DETAIL_STARTDAY' => '',
'ITEM_ID' => '0004',
'ITEM_QTY' => 2,
'DETAIL_NEXTDAY' => $detail_nextday,
'REGULAR_NUMBER' => '',
'WEBKBN' => '1'
);
if(isset($_POST['CUSTOMER_WEBID']) && strlen($_POST['CUSTOMER_WEBID']) > 0) {
$nPost = count($_POST['SEQ']);
$uniqid = uniqid();
$arrPostAll = array();
for($i = 0; $i < $nPost; $i++) {
foreach($arrPost as $key => $val) {
$arrPostAll[$i]['SESS_ID'] = $uniqid;
$arrPostAll[$i]['CUSTOMER_WEBID'] = trim($_POST['CUSTOMER_WEBID']);
$arrPostAll[$i][$key] = $_POST[$key][$i];
}
}
$arrRet = $objWksConnMethod->JSSQL_GETUNITPRICE($arrPostAll);
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.0.min.js"></script>
<style>
table#post_list {
border-collapse: collapse;
font-size: 0.9em;
}
table#post_list td {
border: 1px solid black;
padding: 3px 5px;
background-color: #f8f8f8;
}
table#post_list tr.table_header td {
background-color: #aaaaff;
font-weight: normal;
}
</style>
<script>
$(function() {
var $message = $('#message');
$('#execute').click(function() {
var customer_ids = $('#customer_ids').val().split(/\n/);
var promises = [];
$.each(customer_ids, function(i, customer_id) {
var d = $.Deferred();
process(i, customer_id, $message, d);
promises.push(d);
})
$.when.apply($, promises)
.done(function () {
var d = $.Deferred();
var msg = '実行完了しました';
alert(msg);
$message.text(msg);
d.resolve();
return d;
});
});
});
var process = function(i, customer_id, $message, d) {
var id = setTimeout(function() {
var
ORDER_KIND = [],
SEQ = [],
DETAIL_STARTDAY = [],
ITEM_ID = [],
ITEM_QTY = [],
DETAIL_NEXTDAY = [],
REGULAR_NUMBER = [],
WEBKBN = [];
var v = i % 2;
var stype = 1;
if (v == 0) {
stype = 1;
} else {
stype = 2;
}
$('input[id^=SEQ]').each(function() {
var rel = $(this).attr('rel');
ORDER_KIND.push($('#ORDER_KIND_' + rel).val());
SEQ.push($('#SEQ_' + rel).val());
DETAIL_STARTDAY.push($('#DETAIL_STARTDAY_' + rel).val());
ITEM_ID.push($('#ITEM_ID_' + rel).val());
ITEM_QTY.push($('#ITEM_QTY_' + rel).val());
DETAIL_NEXTDAY.push($('#DETAIL_NEXTDAY_' + rel).val());
REGULAR_NUMBER.push($('#REGULAR_NUMBER_' + rel).val());
WEBKBN.push($('#WEBKBN_' + rel).val());
});
var postData = {
CUSTOMER_WEBID: customer_id,
stype: stype,
ORDER_KIND: ORDER_KIND,
SEQ: SEQ,
DETAIL_STARTDAY: DETAIL_STARTDAY,
ITEM_ID: ITEM_ID,
ITEM_QTY: ITEM_QTY,
DETAIL_NEXTDAY: DETAIL_NEXTDAY,
REGULAR_NUMBER: REGULAR_NUMBER,
WEBKBN: WEBKBN
};
var call = $('#call').val();
if (call == undefined || call < 1) {
call = 1;
}
window.console.log('execute ' + i + ' JSSQL_GETCUST: ' + customer_id );
$.ajax({
type: 'POST',
url: "/shopping/admin/lockon/tools/wksMethods/JSSQL_GETCUST.php",
dataType: 'html',
data: {CUSTOMER_WEBID: customer_id},
error: function(jqXHR, textStatus, errorThrown) {
window.console.log(errorThrown);
},
success: function(data, textStatus, jqXHR) {
window.console.log('success JSSQL_GETCUST: ' + customer_id );
}
});
for (var n = 0; n < call; n++) {
window.console.log('execute ' + n + ' JSSQL_GETUNITPRICE: ' + customer_id );
$.ajax({
type: 'POST',
url: "<?php echo $_SERVER['PHP_SELF']; ?>",
dataType: 'html',
data: postData,
error: function(jqXHR, textStatus, errorThrown) {
window.console.log(errorThrown);
},
success: function(data, textStatus, jqXHR) {
window.console.log('success JSSQL_GETUNITPRICE: ' + customer_id );
}
});
}
$message.text(customer_id + ' を実行しています');
d.resolve();
}, $('#interval').val() * 1000 * i);
};
</script>
</head>
<body style="font-size: 0.8em;">
<h1>単価取得メソッドのバッチ実行(JSSQL_GETUNITPRICE)</h1>
<hr />
<div id="message">&nbsp;</div>
<hr />
<form method="post" action="?">
<div><input type="button" id="execute" value="実行" /></div>
各WEBIDを <input type="text" value="1" id="interval" name="interval" size="5" /> 秒ごとに JSSQL_GETCUST を実行し<br />
JSQL_GETUNITPRICE を <input type="text" value="9" id="call" name="call" size="5" /> 回ずつ実行します。<br />
WEBID:<br /><textarea id="customer_ids" rows="30">
W009999999
W009999999
W009999999
W009999999
W009999999</textarea>
<table id="post_list">
<tr class="table_header">
<? foreach($arrPost as $key => $val) { ?>
<td><?=$key?></td>
<? } ?>
</tr>
<? foreach($arrPostAll as $seq => $arrPost) { ?>
<tr>
<? foreach($arrPost as $key => $val) { ?>
<td><input type="text" rel="<?=$seq+1?>" id="<?=$key?>_<?=$seq+1?>" name="<?=$key?>[]" value="<?=htmlspecialchars($val)?>" style="width: 100px" /></td>
<? } ?>
</tr>
<? } ?>
</table>
</form>
<hr />
<pre>
<?
if(!is_null($arrRet)) {
sfPrintR(delAttrElement($arrRet), "#390000");
}
?>
</pre>
</body>
</html>
<?
/**
* XMLを配列に変換すると含まれている属性を削除する。
*
* @param array $var 対象の配列
* @return array 配列
*/
function delAttrElement($var) {
if(is_array($var)) {
foreach($var as $k => $v) {
if(strpos($k, ' attr') != false){
unset($var[$k]);
} else if(is_array($v)) {
$var[$k] = delAttrElement($v);
}
}
}
return $var;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment