fixes crunchbutton/issues#3
This commit is contained in:
parent
2cf425d04f
commit
6eea1934df
57
include/controllers/default/quick/api/order/index.php
Normal file
57
include/controllers/default/quick/api/order/index.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
class Controller_api_order extends Crunchbutton_Controller_RestAccount {
|
||||
public function init() {
|
||||
|
||||
$order = Order::uuid(c::getPagePiece(2));
|
||||
if (!$order->id_order) {
|
||||
$order = Order::o(c::getPagePiece(2));
|
||||
}
|
||||
|
||||
if (!$order->id_order) {
|
||||
echo json_encode(['error' => 'invalid object']);
|
||||
exit;
|
||||
|
||||
} else {
|
||||
if (get_class($order) != 'Crunchbutton_Order') {
|
||||
$order = $order->get(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (1==1 || $this->method() == 'post') {
|
||||
$res = [];
|
||||
|
||||
switch (c::getPagePiece(3)) {
|
||||
case 'delivery-pickedup':
|
||||
$res['status'] = $order->deliveryPickedup(c::admin());
|
||||
break;
|
||||
|
||||
case 'delivery-delivered':
|
||||
$res['status'] = $order->deliveryDelivered(c::admin());
|
||||
break;
|
||||
|
||||
case 'delivery-accept':
|
||||
$res['status'] = $order->deliveryAccept(c::admin());
|
||||
break;
|
||||
|
||||
case 'delivery-reject':
|
||||
$order->deliveryReject(c::admin());
|
||||
$res['status'] = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
echo json_encode(['error' => 'invalid action']);
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($order->deliveryStatus())
|
||||
$ret = $order->deliveryExports();
|
||||
$ret['status'] = $res['status'];
|
||||
|
||||
echo json_encode($ret);
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,13 @@ class Crunchbutton_Admin extends Cana_Table {
|
||||
return Crunchbutton_Admin::q('select * from admin where login="'.c::db()->escape($login).'" limit 1')->get(0);
|
||||
}
|
||||
|
||||
public function publicExports() {
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'id_admin' => $this->id_admin
|
||||
];
|
||||
}
|
||||
|
||||
public function timezone() {
|
||||
if (!isset($this->_timezone)) {
|
||||
$this->_timezone = new DateTimeZone($this->timezone);
|
||||
|
||||
@ -1491,6 +1491,147 @@ class Crunchbutton_Order extends Cana_Table {
|
||||
}
|
||||
return array_unique( $restaurants_ids );
|
||||
}
|
||||
|
||||
/*
|
||||
get the delivery status of the order based on reps or restaurants actions agaisnt it
|
||||
@todo: add restaurant actions
|
||||
*/
|
||||
public function deliveryStatus($type = null) {
|
||||
if (!$this->_actions) {
|
||||
$this->_actions = Order_Action::q('select * from order_action where id_order="'.$this->id_order.'" order by timestamp');
|
||||
$this->_deliveryStatus = ['accepted' => false, 'delivered' => false, 'pickedup' => false];
|
||||
$acpt = [];
|
||||
|
||||
foreach ($this->_actions as $action) {
|
||||
switch ($action->type) {
|
||||
case 'delivery-delivered':
|
||||
$this->_deliveryStatus['delivered'] = Admin::o($admin);
|
||||
break;
|
||||
|
||||
case 'delivery-pickedup':
|
||||
$this->_deliveryStatus['pickedup'] = Admin::o($admin);
|
||||
break;
|
||||
|
||||
case 'delivery-accepted':
|
||||
$acpt[$action->id_admin] = true;
|
||||
break;
|
||||
|
||||
case 'delivery-rejected':
|
||||
$acpt[$action->id_admin] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($acpt as $admin => $status) {
|
||||
if ($status) {
|
||||
$this->_deliveryStatus['accepted'] = Admin::o($admin);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $type === null ? $this->_deliveryStatus : $this->_deliveryStatus[$type];
|
||||
}
|
||||
|
||||
public function deliveryAccept($admin) {
|
||||
if ($this->deliveryStatus('accepted')) {
|
||||
return false;
|
||||
}
|
||||
(new Order_Action([
|
||||
'id_order' => $this->id_order,
|
||||
'id_admin' => $admin->id_admin,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'type' => 'delivery-accepted'
|
||||
]))->save();
|
||||
$this->_actions = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deliveryReject($admin) {
|
||||
(new Order_Action([
|
||||
'id_order' => $this->id_order,
|
||||
'id_admin' => $admin->id_admin,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'type' => 'delivery-rejected'
|
||||
]))->save();
|
||||
$this->_actions = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deliveryPickedup($admin) {
|
||||
if (!$this->deliveryStatus('accepted')) {
|
||||
die('asd');
|
||||
}
|
||||
if (!$this->deliveryStatus('accepted') || $this->deliveryStatus('accepted')->id_admin != $admin->id_admin) {
|
||||
return false;
|
||||
}
|
||||
(new Order_Action([
|
||||
'id_order' => $this->id_order,
|
||||
'id_admin' => $admin->id_admin,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'type' => 'delivery-pickedup'
|
||||
]))->save();
|
||||
$this->_actions = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deliveryDelivered($admin) {
|
||||
if (!$this->deliveryStatus('accepted')) {
|
||||
die('asd');
|
||||
}
|
||||
if (!$this->deliveryStatus('accepted') || $this->deliveryStatus('accepted')->id_admin != $admin->id_admin) {
|
||||
return false;
|
||||
}
|
||||
(new Order_Action([
|
||||
'id_order' => $this->id_order,
|
||||
'id_admin' => $admin->id_admin,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'type' => 'delivery-delivered'
|
||||
]))->save();
|
||||
$this->_actions = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deliveryReply($admin) {
|
||||
$act = false;
|
||||
foreach ($this->_actions as $action) {
|
||||
if ($action->id_admin && $admin->id_admin) {
|
||||
switch ($action->type) {
|
||||
case 'delivery-delivered':
|
||||
$act = 'delivered';
|
||||
continue;
|
||||
break;
|
||||
|
||||
case 'delivery-pickedup':
|
||||
$act = 'pickedup';
|
||||
continue;
|
||||
break;
|
||||
|
||||
case 'delivery-accepted':
|
||||
$act = 'accepted';
|
||||
continue;
|
||||
break;
|
||||
|
||||
case 'delivery-rejected':
|
||||
$act = 'rejected';
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $act;
|
||||
}
|
||||
|
||||
public function deliveryExports() {
|
||||
return [
|
||||
'id_order' => $this->id_order,
|
||||
'uuid' => $this->uuid,
|
||||
'delivery-status' => [
|
||||
'delivered' => $this->deliveryStatus('delivered') ? $this->deliveryStatus('delivered')->publicExports() : false,
|
||||
'pickedup' => $this->deliveryStatus('pickedup') ? $this->deliveryStatus('pickedup')->publicExports() : false,
|
||||
'accepted' => $this->deliveryStatus('accepted') ? $this->deliveryStatus('accepted')->publicExports() : false
|
||||
],
|
||||
'self-reply' => $this->deliveryReply(c::admin())
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct($id = null) {
|
||||
parent::__construct();
|
||||
|
||||
11
include/library/Crunchbutton/Order/Action.php
Normal file
11
include/library/Crunchbutton/Order/Action.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class Crunchbutton_Order_Action extends Cana_Table {
|
||||
public function __construct($id = null) {
|
||||
parent::__construct();
|
||||
$this
|
||||
->table('order_action')
|
||||
->idVar('id_order_action')
|
||||
->load($id);
|
||||
}
|
||||
}
|
||||
@ -47,19 +47,17 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
}
|
||||
|
||||
.control {
|
||||
|
||||
background-image: -moz-linear-gradient( 90deg, rgb(203,203,203) 0%, rgb(232,232,232) 100%);
|
||||
background-image: -webkit-linear-gradient( 90deg, rgb(203,203,203) 0%, rgb(232,232,232) 100%);
|
||||
background-image: -ms-linear-gradient( 90deg, rgb(203,203,203) 0%, rgb(232,232,232) 100%);
|
||||
box-shadow: 0px 1px 0px 0px rgb( 150, 150, 150 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
.control .buttons {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
text-align: right;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.content {
|
||||
@ -145,7 +143,7 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
.order-comment {
|
||||
background: #00957f;
|
||||
color: #fff;
|
||||
padding: .7em .9em .5em 1em;
|
||||
padding: .9em .9em .8em 1em;
|
||||
border-radius: 4px;
|
||||
margin-bottom: .8em;
|
||||
}
|
||||
@ -286,7 +284,8 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
font-size: 1.3em;
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
text-shadow:1px 1px 0px #fff
|
||||
text-shadow:1px 1px 0px #fff;
|
||||
white-space:nowrap;
|
||||
}
|
||||
|
||||
.button {
|
||||
@ -299,7 +298,6 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
border: 1px solid rgba(0,0,0,.2);
|
||||
box-shadow: 0px 0px 3px rgba(0,0,0,.3);
|
||||
text-shadow: 1px 1px 0 rgba(0,0,0,.4);
|
||||
-webkit-transition: all .09s ease;
|
||||
}
|
||||
|
||||
.button:active {
|
||||
@ -316,19 +314,74 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
background: #dc534b;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.order-status-delivered .status-control:not(.control-delivered) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.order-status-pickedup .status-control:not(.control-pickedup) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.order-status-rejected .status-control:not(.control-rejected) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.order-status-accepted .status-control:not(.control-accepted) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.order-status-accepted-other .status-control:not(.control-accepted-other) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.order-status-none .status-control:not(.control-accept-reject) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<div class="control">
|
||||
<div class="wrap">
|
||||
<div class="message">Accept this order?</div>
|
||||
<div class="wrap <?=$orderStatusClass?>">
|
||||
<div class="status-control control-accept-reject">
|
||||
<div class="message">Accept this order?</div>
|
||||
<div class="buttons">
|
||||
<button class="button button-yes">Yes</button>
|
||||
<button class="button button-no">No</button>
|
||||
<button class="button button-yes button-accept">Yes</button>
|
||||
<button class="button button-no button-reject">No</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-control control-rejected">
|
||||
<div class="message">You rejected. </div>
|
||||
<div class="buttons">
|
||||
<button class="button button-yes button-accept">Accept</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-control control-accepted">
|
||||
<div class="message">You accepted.</div>
|
||||
<div class="buttons">
|
||||
<button class="button button-yes button-pickedup">Picked up</button>
|
||||
<button class="button button-no button-reject">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-control control-accepted-other">
|
||||
This order has been accepted by <span class="delivery-accepted"><?=$this->order->deliveryStatus('accepted') ? $this->order->deliveryStatus('accepted')->name : ''?></span>.
|
||||
</div>
|
||||
<div class="status-control control-pickedup">
|
||||
<div class="message">You picked up.</div>
|
||||
<div class="buttons">
|
||||
<button class="button button-yes button-delivered">Delivered</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-control control-pickedup-other">
|
||||
This order has been picked up by <span class="delivery-pickedup"><?=$this->order->deliveryStatus('pickedup') ? $this->order->deliveryStatus('pickedup')->name : ''?></span>.
|
||||
</div>
|
||||
<div class="status-control control-delivered">
|
||||
This order has been delivered by <span class="delivery-delivered"><?=$this->order->deliveryStatus('delivered') ? $this->order->deliveryStatus('delivered')->name : ''?></span>.
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -342,4 +395,58 @@ input[type="submit"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner,
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="/assets/js/fastclick.js"></script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
var d = <?=json_encode($this->order->deliveryExports())?>;
|
||||
var id_admin = '<?=c::admin()->id_admin?>';
|
||||
var id_order = '<?=$this->order->id_order?>';
|
||||
|
||||
var updateStatus = function(data) {
|
||||
console.log(data);
|
||||
$('.wrap').removeClass('order-status-delivered order-status-pickedup order-status-rejected order-status-accepted order-status-accepted-other order-status-none');
|
||||
|
||||
var className;
|
||||
|
||||
if (data['delivery-status'].delivered) {
|
||||
className = 'order-status-delivered';
|
||||
|
||||
} else if (data['delivery-status'].pickedup) {
|
||||
className = 'order-status-pickedup';
|
||||
|
||||
} else if (data['delivery-status'].accepted && data['delivery-status'].accepted.id_admin != id_admin) {
|
||||
className = 'order-status-accepted-other';
|
||||
|
||||
} else if (data['delivery-status'].accepted && data['delivery-status'].accepted.id_admin == id_admin) {
|
||||
className = 'order-status-accepted';
|
||||
|
||||
} else if (data['self-reply'] == 'rejected') {
|
||||
className = 'order-status-rejected';
|
||||
|
||||
} else {
|
||||
className = 'order-status-none';
|
||||
}
|
||||
|
||||
$('.wrap').addClass(className);
|
||||
};
|
||||
|
||||
$('.button-reject').click(function() {
|
||||
$.post('/api/order/' + id_order + '/delivery-reject', updateStatus,'json');
|
||||
});
|
||||
|
||||
$('.button-accept').click(function() {
|
||||
$.post('/api/order/' + id_order + '/delivery-accept', updateStatus,'json');
|
||||
});
|
||||
|
||||
$('.button-pickedup').click(function() {
|
||||
$.post('/api/order/' + id_order + '/delivery-pickedup', updateStatus,'json');
|
||||
});
|
||||
|
||||
$('.button-delivered').click(function() {
|
||||
$.post('/api/order/' + id_order + '/delivery-delivered', updateStatus,'json');
|
||||
});
|
||||
|
||||
updateStatus(d);
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
@ -53,25 +53,25 @@
|
||||
<div class="order-comment">
|
||||
<p><?=nl2br($this->order->notes)?></p>
|
||||
</div>
|
||||
|
||||
<? else : ?>
|
||||
<br>
|
||||
<? endif ; ?>
|
||||
|
||||
|
||||
<a href="{{order.mapLink}}"><div class="order-map" style="background: url('https://maps.googleapis.com/maps/api/staticmap?&size=640x300&markers=color:green%7Clabel:A%7C<?=str_replace("\n",' ',str_replace('#','',$this->order->address))?>&markers=color:red%7Clabel:B%7C<?=$this->order->restaurant()->lat?>,<?=$this->order->restaurant()->lon?>&sensor=false&visual_refresh=true');"></div></a>
|
||||
<a href="http://maps.apple.com/?daddr=<?=$this->order->address?>&saddr=<?=$this->order->restaurant()->address?>"><div class="order-map" style="background: url('https://maps.googleapis.com/maps/api/staticmap?size=640x300&markers=color:green%7Clabel:A%7C<?=str_replace("\n",' ',str_replace('#','',$this->order->address))?>&markers=color:red%7Clabel:B%7C<?=$this->order->restaurant()->loc_lat?>,<?=$this->order->restaurant()->loc_long?>&sensor=false&visual_refresh=true');"></div></a>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="order-item-block order-map-block">
|
||||
<div class="order-icon"><i class="icon-map-home"></i></div>
|
||||
<div class="order-info">
|
||||
<p class="order-info-address"><a href="{{order.mapLink}}"><?=nl2br($this->order->address)?></a></p>
|
||||
<p class="order-info-address"><a href="http://maps.apple.com/?q=<?=$this->order->address?>"><?=nl2br($this->order->address)?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="order-item-block order-map-block">
|
||||
<div class="order-icon"><i class="icon-map-restaurant"></i></div>
|
||||
<div class="order-info">
|
||||
<p class="order-info-address"><a href="{{order.mapLink}}"><?=nl2br($this->order->restaurant()->address)?></a></p>
|
||||
<p class="order-info-address"><a href="http://maps.apple.com/?q=<?=$this->order->restaurant()->address?>"><?=nl2br($this->order->restaurant()->address)?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -217,15 +217,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user