-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tess3ract
committed
Mar 7, 2014
1 parent
4f7134b
commit e9fcbc3
Showing
14 changed files
with
392 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
class Make extends CI_Controller { | ||
|
||
public function __construct() { | ||
parent::__construct(); | ||
$this->load->helper('ticket'); | ||
$this->load->helper('misc'); | ||
$this->load->helper('user'); | ||
$this->load->helper('product'); | ||
$this->user = get_user(); | ||
if (!$this->user) { | ||
die; | ||
} | ||
} | ||
|
||
public function index() { | ||
// list products and prices | ||
$cates = make_dict($this->db->get('cate')->result_array()); | ||
$subcates = make_dict($this->db->get('subcate')->result_array()); | ||
$products = $this->db->get('product')->result_array(); | ||
$price = make_dict($this->db->get_where('price', array('agent_level' => $this->user['level']))->result_array(), 'product_id'); | ||
$tree = array(); | ||
foreach ($products as $product) { | ||
$cate_id = $product['cate']; | ||
$subcate_id = $product['subcate']; | ||
if (!isset($tree[$cate_id])) { | ||
$tree[$cate_id] = $cates[$cate_id]; | ||
$tree[$cate_id]['subcates'] = array(); | ||
} | ||
if (!isset($tree[$cate_id]['subcates'][$subcate_id])) { | ||
$tree[$cate_id]['subcates'][$subcate_id] = $subcates[$subcate_id]; | ||
$tree[$cate_id]['subcates'][$subcate_id]['products'] = array(); | ||
} | ||
$product['stock_price'] = $price[$product['id']]['stock_price']; | ||
$tree[$cate_id]['subcates'][$subcate_id]['products'][$product['id']] = $product; | ||
} | ||
$this->load->vars('tree', $tree); | ||
$this->load->view('make'); | ||
} | ||
|
||
public function create($product, $product_count, $ticket_count) { | ||
$product = $this->db->get_where('product', array('id' => $product))->row_array(); | ||
if ($product_count > $product['count_max'] || $product_count < $product['count_min']) { | ||
echo json_encode(array('success' => 0, 'max' => $product['count_max'], 'min' => $product['count_min'])); | ||
return; | ||
} | ||
$tickets = array(); | ||
for ($i = 0; $i < $ticket_count; $i ++) { | ||
$number = new_ticket_number($product['id']); | ||
$price = get_price($product['id'], $this->user['level']); | ||
$this->db->insert('ticket', array( | ||
"number" => $number, | ||
"create_time" => time(), | ||
"credit" => $price * $product_count, | ||
"product_id" => $product['id'], | ||
"count" => $product_count, | ||
"state" => 0, | ||
"fulfill_time" => 0, | ||
"agent" => $this->user['id'] | ||
)); | ||
$tickets[] = $number; | ||
} | ||
echo json_encode(array('success' => 1, 'tickets' => $tickets)); | ||
} | ||
|
||
} | ||
|
||
/* End of file */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
|
||
function make_dict($rows, $field = 'id') { | ||
$dict = array(); | ||
foreach ($rows as $row) { | ||
$dict[$row[$field]] = $row; | ||
} | ||
return $dict; | ||
} | ||
|
||
/* End of file */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php $this->load->view('header'); ?> | ||
|
||
<p><?php echo $user['name'];?>様、お帰りなさい。</p> | ||
|
||
<p>お前のアカウントには <?php echo $user['credit_balance'];?>ポイント がありますよ〜</p> | ||
|
||
<div id="stage"> | ||
|
||
</div> | ||
|
||
<script type="text/template" id="tpl-password"> | ||
<form action="<?php echo site_url('/agent/changepwd');?>" method="post" id="form-pwd"> | ||
<p>CURRENT PWD: <input type="password" name="current_password" /></p> | ||
<p>NEW PASSWOD: <input type="password" name="new_password" /></p> | ||
<p><button type="submit" class="btn btn-danger">DO IT</button></p> | ||
<p id="p-err"></p> | ||
</form> | ||
</script> | ||
|
||
<p><button href="<?php echo site_url('/agent/status');?>" class="btn btn-primary btn-status">STATUS</button></p> | ||
|
||
<p><button href="<?php echo site_url('/make');?>" class="btn btn-danger btn-lnk">MAKE TICKET</button></p> | ||
|
||
<p><button class="btn btn-primary btn-password">CHANGE PASSWORD</button></p> | ||
|
||
<p><button href="<?php echo site_url('/agent/log');?>" class="btn btn-info btn-log">CREDIT LOG</button></p> | ||
|
||
<p><button href="<?php echo site_url('/agent/logout');?>" class="btn btn-danger btn-lnk">LOGOUT</button></p> | ||
|
||
<script type="text/javascript"> | ||
function make_request(url, callback) { | ||
$.get(url, function(data) { | ||
if (!data.success) { | ||
$('#stage').html('FAILED TO MAKE REQUEST!'); | ||
} else { | ||
callback(data); | ||
} | ||
}, "json"); | ||
} | ||
$('.btn-lnk').click(function(){ | ||
window.location.href = $(this).attr('href'); | ||
return false; | ||
}); | ||
$('.btn-status').click(function(){ | ||
make_request($(this).attr('href'), function(data) { | ||
$('#stage').html(''); | ||
for (var k in data) { | ||
$('<p>' + k + ': ' + data[k] + '</p>').appendTo('#stage'); | ||
} | ||
}); | ||
}); | ||
$('.btn-log').click(function(){ | ||
make_request($(this).attr('href'), function(data) { | ||
$('#stage').html('これはログです:'); | ||
for (var i in data.logs) { | ||
var row = data.logs[i]; | ||
$('<p>TICKET ' + row.ticket + ': DIFF ' + row.diff + ' BALANCE ' + row.balance + '</p>').appendTo('#stage'); | ||
} | ||
$('<p>ーーー終わるーーー</p>').appendTo('#stage'); | ||
}); | ||
}); | ||
$('.btn-password').click(function(){ | ||
$('#stage').html($('#tpl-password').html()); | ||
$('#form-pwd').submit(function(){ | ||
$.get($(this).attr('action'), $(this).serialize(), function(data) { | ||
if (data.success) { | ||
$('#stage').html('NEW PASSWORD SET!'); | ||
} else { | ||
$('#stage').html('FAILED TO CHANGE PASSWORD!'); | ||
} | ||
}, "json"); | ||
return false; | ||
}); | ||
}); | ||
$('#tab-control').addClass('active'); | ||
</script> | ||
<?php $this->load->view('footer'); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php $this->load->view('header'); ?> | ||
|
||
<form action="<?php echo site_url('/agent/login');?>" method="post" id="form-logging"> | ||
<p>USERNAME: <input type="text" name="name" /></p> | ||
<p>PASSWORD: <input type="password" name="password" /></p> | ||
<p><button type="submit" class="btn btn-primary">LOGIN</button></p> | ||
<p id="p-err"></p> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
$('#form-logging').submit(function(){ | ||
$.get($(this).attr('action'), $(this).serialize(), function(data) { | ||
if (data.success) { | ||
window.location.reload(); | ||
} else { | ||
$('#p-err').html('Incorrect name or password.'); | ||
} | ||
}, "json"); | ||
return false; | ||
}); | ||
$('#tab-logging').addClass('active'); | ||
</script> | ||
<?php $this->load->view('footer'); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.