final adjustments - ready to test on beta

This commit is contained in:
Daniel Camargo 2014-02-26 17:35:19 -03:00
parent 2f0c88b07c
commit f8a128686e
9 changed files with 129 additions and 58 deletions

View File

@ -2,6 +2,9 @@ ALTER TABLE `support` ADD `id_admin` int(10) unsigned DEFAULT NULL;
ALTER TABLE `support` ADD INDEX ( `id_admin` ); ALTER TABLE `support` ADD INDEX ( `id_admin` );
ALTER TABLE `support` ADD CONSTRAINT support_ibfk_6 FOREIGN KEY (id_admin) REFERENCES `admin`(id_admin); ALTER TABLE `support` ADD CONSTRAINT support_ibfk_6 FOREIGN KEY (id_admin) REFERENCES `admin`(id_admin);
ALTER TABLE support MODIFY COLUMN type ENUM( 'SMS','BOX_NEED_HELP', 'WARNING' );
CREATE TABLE `support_message` ( CREATE TABLE `support_message` (
`id_support_message` int(11) unsigned NOT NULL AUTO_INCREMENT, `id_support_message` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_support` int(11) unsigned DEFAULT NULL, `id_support` int(11) unsigned DEFAULT NULL,

View File

@ -98,11 +98,11 @@
<restaurant>_PHONE_</restaurant> <restaurant>_PHONE_</restaurant>
</phone> </phone>
<text> <text>
<!-- <Judd>_PHONE_</Judd> <Judd>_PHONE_</Judd>
<David>_PHONE_</David> <David>_PHONE_</David>
<Nick>_PHONE_</Nick> <Nick>_PHONE_</Nick>
<Tyler>_PHONE_</Tyler> --> <Tyler>_PHONE_</Tyler> -->
<Daniel>***REMOVED***</Daniel> <!-- <Daniel>***REMOVED***</Daniel> -->
<!-- <Daniel>***REMOVED***</Daniel> --> <!-- <Daniel>***REMOVED***</Daniel> -->
</text> </text>
<stripe> <stripe>

View File

@ -11,7 +11,8 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account {
$resultsPerPage = 15; $resultsPerPage = 15;
$page = ( $_REQUEST[ 'page' ] ) ? $_REQUEST[ 'page' ] : 1; $page = ( $_REQUEST[ 'page' ] ) ? $_REQUEST[ 'page' ] : 1;
$status = ( $_REQUEST[ 'status' ] ) ? $_REQUEST[ 'status' ] : '*'; $status = ( $_REQUEST[ 'status' ] ) ? $_REQUEST[ 'status' ] : 'all';
$type = ( $_REQUEST[ 'type' ] ) ? $_REQUEST[ 'type' ] : 'all';
$paginationLink = '/support/plus/content?'; $paginationLink = '/support/plus/content?';
@ -23,11 +24,20 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account {
$where = ' AND id_restaurant IN( ' . join( $restaurants, ',' ) . ')'; $where = ' AND id_restaurant IN( ' . join( $restaurants, ',' ) . ')';
} }
if( $status != '*' && $status != '' ){ if( $status != 'all' && $status != '' ){
$where = ' AND status = "' . $status . '"'; $where = ' AND status = "' . $status . '"';
$paginationLink .= '&status=' . $status; $paginationLink .= '&status=' . $status;
} }
if( $type != 'all' && $type != '' ){
if( $type == 'warning' ){
$where = ' AND type = "' . Crunchbutton_Support::TYPE_WARNING . '"';
} else if( 'support' ){
$where = ' AND ( type = "' . Crunchbutton_Support::TYPE_BOX_NEED_HELP . '" OR type = "' . Crunchbutton_Support::TYPE_SMS . '" ) ';
}
$paginationLink .= '&type=' . $type;
}
$query = "SELECT * FROM support WHERE 1=1 {$where} ORDER BY id_support DESC LIMIT {$limit}"; $query = "SELECT * FROM support WHERE 1=1 {$where} ORDER BY id_support DESC LIMIT {$limit}";
$tickets = Support::q( $query ); $tickets = Support::q( $query );
@ -43,8 +53,9 @@ class Controller_Support_Plus_Content extends Crunchbutton_Controller_Account {
c::view()->tickets = $tickets; c::view()->tickets = $tickets;
c::view()->total = $total; c::view()->total = $total;
c::view()->type = $type;
c::view()->page = $page; c::view()->page = $page;
c::view()->status = ( $status == '' || $status == '*' ) ? 'all' : $status; c::view()->status = ( $status == '' ) ? 'all' : $status;
c::view()->startingAt = $startingAt; c::view()->startingAt = $startingAt;
c::view()->endingAt = $endingAt; c::view()->endingAt = $endingAt;
c::view()->resultsPerPage = $resultsPerPage; c::view()->resultsPerPage = $resultsPerPage;

View File

@ -14,20 +14,12 @@ class Controller_api_Support extends Crunchbutton_Controller_Rest {
$tsess->phone = $this->request()['phone']; $tsess->phone = $this->request()['phone'];
$tsess->data = json_encode( $_REQUEST ); $tsess->data = json_encode( $_REQUEST );
$tsess->save(); $tsess->save();
$support = new Crunchbutton_Support; $support = Crunchbutton_Support::createNewBoxTicket( [ 'phone' => $this->request()['phone'],
$support->type = Crunchbutton_Support::TYPE_BOX_NEED_HELP; 'name' => $this->request()['name'],
$support->name = $this->request()['name']; 'body' => $this->request()['message'],
$support->phone = $this->request()['phone']; 'id_session_twilio' => $tsess->id_session_twilio ] );
$support->message = $this->request()['message'];
$support->ip = $_SERVER['REMOTE_ADDR'];
$support->id_session_twilio = $tsess->id_session_twilio;
$support->date = date('Y-m-d H:i:s');
if( c::user()->id_user ){
$support->id_user = c::user()->id_user;
}
$support->save();
echo $support->json(); echo $support->json();
$support->queNotify(); $support->notify();
break; break;
case 'say': case 'say':
$this->say(); $this->say();

View File

@ -32,12 +32,12 @@ class Controller_api_twilio_sms extends Crunchbutton_Controller_Rest {
} }
} }
foreach ( $sendSMSTo as $supportName => $supportPhone ) { $admin = Admin::getByPhone( $phone );
if ($supportPhone == $phone) {
$type = 'rep'; if( $admin->id_admin ){
$rep = $supportName; $rep = $admin;
Log::debug( [ 'action' => 'rep valid', 'rep' => $supportName, 'rep phone' => $supportPhone, 'type' => 'sms' ] ); $type = 'rep';
} Log::debug( [ 'action' => 'rep valid', 'rep' => $admin->name, 'rep phone' => $admin->phone, 'type' => 'sms' ] );
} }
switch ($type) { switch ($type) {
@ -45,7 +45,7 @@ class Controller_api_twilio_sms extends Crunchbutton_Controller_Rest {
case 'rep': case 'rep':
foreach ( $sendSMSTo as $supportName => $supportPhone) { foreach ( $sendSMSTo as $supportName => $supportPhone) {
if ($supportName == $rep) continue; if ($supportPhone == $phone) continue;
$nums[] = $supportPhone; $nums[] = $supportPhone;
} }
@ -65,7 +65,7 @@ class Controller_api_twilio_sms extends Crunchbutton_Controller_Rest {
if( $body != '' ){ if( $body != '' ){
$this->reply( $rsess->id_session_twilio, $phone, $body, $twilio ); $this->reply( $rsess->id_session_twilio, $phone, $body, $twilio );
} else { } else {
$msg = "$rep is now replying to @".$rsess->id_session_twilio.'. Type a message to respond.'; $msg = $rep->name . " is now replying to @".$rsess->id_session_twilio.'. Type a message to respond.';
} }
} }
} }

View File

@ -91,23 +91,7 @@ class Crunchbutton_Order_Rules extends Cana_Model {
$message = $this->createAlert( $rule[ 'alert' ], $result ); $message = $this->createAlert( $rule[ 'alert' ], $result );
$support = new Crunchbutton_Support(); $support = Crunchbutton_Support::createNewWarning( [ 'id_order' => $order->id_order, 'body' => $message ] );
$support->status = 'open';
$support->id_user = $order->id_user;
$support->id_order = $order->id_order;
$support->id_restaurant = $order->id_restaurant;
$support->name = $message;
$support->phone = $order->phone;
$support->ip = $_SERVER['REMOTE_ADDR'];
$support->datetime = date('Y-m-d H:i:s');
$support->save();
$note = new Support_Note();
$note->id_support = $support->id_support;
$note->text = $message;
$note->from = 'system';
$note->visibility = 'internal';
$note->save();
$message .= ' - '; $message .= ' - ';
$message .= ' U: ' . $order->name; $message .= ' U: ' . $order->name;

View File

@ -4,6 +4,7 @@ class Crunchbutton_Support extends Cana_Table {
const TYPE_SMS = 'SMS'; const TYPE_SMS = 'SMS';
const TYPE_BOX_NEED_HELP = 'BOX_NEED_HELP'; const TYPE_BOX_NEED_HELP = 'BOX_NEED_HELP';
const TYPE_WARNING = 'WARNING';
const STATUS_OPEN = 'open'; const STATUS_OPEN = 'open';
const STATUS_CLOSED = 'closed'; const STATUS_CLOSED = 'closed';
@ -75,6 +76,46 @@ class Crunchbutton_Support extends Cana_Table {
return Crunchbutton_Support::o( $support->id_support ); return Crunchbutton_Support::o( $support->id_support );
} }
public function createNewBoxTicket( $params = [] ){
$messageParams = [];
$support = new Crunchbutton_Support();
$support->type = Crunchbutton_Support::TYPE_BOX_NEED_HELP;
$support->phone = $params[ 'phone' ];
$support->status = Crunchbutton_Support::STATUS_OPEN;
$support->ip = $_SERVER[ 'REMOTE_ADDR' ];
$support->id_session_twilio = $params[ 'id_session_twilio' ];
$support->date = date( 'Y-m-d H:i:s' );
if( c::user()->id_user ){
$support->id_user = c::user()->id_user;
}
$support->save();
// Params to create the new Support message
$messageParams[ 'name' ] = $params[ 'name' ];
$messageParams[ 'phone' ] = $params[ 'phone' ];
$messageParams[ 'body' ] = $params[ 'body' ];
$support->addCustomerMessage( $messageParams );
return Crunchbutton_Support::o( $support->id_support );
}
public function createNewWarning( $params = [] ){
$support = new Crunchbutton_Support();
$support->type = Crunchbutton_Support::TYPE_WARNING;
$support->status = Crunchbutton_Support::STATUS_OPEN;
$support->ip = $_SERVER[ 'REMOTE_ADDR' ];
$support->id_session_twilio = null;
$support->date = date( 'Y-m-d H:i:s' );
if( $params[ 'id_order' ] ) {
$order = Order::o( $params[ 'id_order' ] );
$support->id_order = $order->id_order;
$support->id_restaurant = $order->id_restaurant;
$support->id_user = $order->id_user;
$support->phone = $order->phone;
}
$support->save();
$support->addSystemMessage( $params[ 'body' ] );
return Crunchbutton_Support::o( $support->id_support );
}
public function addCustomerMessage( $params = [] ){ public function addCustomerMessage( $params = [] ){
$messageParams[ 'id_admin' ] = NULL; $messageParams[ 'id_admin' ] = NULL;
$messageParams[ 'type' ] = Crunchbutton_Support_Message::TYPE_SMS; $messageParams[ 'type' ] = Crunchbutton_Support_Message::TYPE_SMS;
@ -191,6 +232,8 @@ class Crunchbutton_Support extends Cana_Table {
$twilio = new Twilio(c::config()->twilio->{$env}->sid, c::config()->twilio->{$env}->token); $twilio = new Twilio(c::config()->twilio->{$env}->sid, c::config()->twilio->{$env}->token);
$message = $this->firstMessage();
$message = $message =
"(support-" . $env . "): ". "(support-" . $env . "): ".
$support->name. $support->name.
@ -198,7 +241,7 @@ class Crunchbutton_Support extends Cana_Table {
"phone: ". "phone: ".
$support->phone. $support->phone.
"\n\n". "\n\n".
$support->message; $message->body;
// Log // Log
Log::debug( [ 'action' => 'support', 'message' => $message, 'type' => 'support' ] ); Log::debug( [ 'action' => 'support', 'message' => $message, 'type' => 'support' ] );

View File

@ -15,15 +15,26 @@
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Status: <?php echo $this->status; ?> <span class="caret"></span></button> <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Status: <?php echo $this->status; ?> <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?status=')">All</a></li> <li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?status=open')">Open</a></li> <li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=open')">Open</a></li>
<li><a href="#" onclick="load('/support/plus/content?status=closed')">Closed</a></li> <li><a href="#" onclick="load('/support/plus/content?type=<?php echo $this->type; ?>&status=closed')">Closed</a></li>
</ul> </ul>
</div> </div>
</div> </div>
<div class="span10"> <div class="span1">
<br/>
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Type: <?php echo $this->type; ?> <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#" onclick="load('/support/plus/content?staus=<?php echo $this->status; ?>&type=all')">All</a></li>
<li><a href="#" onclick="load('/support/plus/content?staus=<?php echo $this->status; ?>&type=support')">Support</a></li>
<li><a href="#" onclick="load('/support/plus/content?staus=<?php echo $this->status; ?>&type=warning')">Warning</a></li>
</ul>
</div>
</div>
<div class="span9">
<br/> <br/>
<button onclick="load('/support/plus/content?status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>')" class="btn btn-default"><i class="icon-refresh"></i> Refresh</button> <button onclick="load('/support/plus/content?type=<?php echo $this->type ?>&status=<?php echo $this->status ?>&page=<?php echo $this->page; ?>')" class="btn btn-default"><i class="icon-refresh"></i> Refresh</button>
</div> </div>
<div class="span1" id="warning-loaded" style="display:none;"> <div class="span1" id="warning-loaded" style="display:none;">
<br/> <br/>
@ -37,6 +48,7 @@
<tr> <tr>
<td style="width: 60px;"><div>#</div></td> <td style="width: 60px;"><div>#</div></td>
<td style="width: 140px;"><div>Date</div></td> <td style="width: 140px;"><div>Date</div></td>
<td style="width: 140px;"><div>Type</div></td>
<td style="width: 140px;"><div>Name</div></td> <td style="width: 140px;"><div>Name</div></td>
<td><div>Message</div></td> <td><div>Message</div></td>
<td style="width: 60px;"><div>Status</div></td> <td style="width: 60px;"><div>Status</div></td>
@ -57,6 +69,27 @@
} else { } else {
$class = 'row-green'; $class = 'row-green';
} }
switch ( $support->type ) {
case Crunchbutton_Support::TYPE_SMS:
case Crunchbutton_Support::TYPE_BOX_NEED_HELP:
$type = 'Support';
$name = $support->name();
$driver = $support->order()->driver()->name;
$message = $support->lastCustomerMessage()->body;
$customer_time = $support->lastCustomerMessage()->relativeTime();
$admin_time = $support->lastAdminMessage()->relativeTime();
$chat = true;
break;
case Crunchbutton_Support::TYPE_WARNING:
$name = '-';
$driver = false;
$type = 'System warning';
$message = $support->lastMessage()->body;
$customer_time = '-';
$admin_time = $support->lastMessage()->relativeTime();
$chat = false;
break;
}
?> ?>
<tr class="<?php echo $class.$zebra; ?>"> <tr class="<?php echo $class.$zebra; ?>">
<td style="white-space: nowrap;"> <td style="white-space: nowrap;">
@ -65,25 +98,28 @@
</a> </a>
</td> </td>
<td nowrap><?php echo $support->repTime()->format( 'M/d D H:iA' ); ?></td> <td nowrap><?php echo $support->repTime()->format( 'M/d D H:iA' ); ?></td>
<td nowrap><?php echo $support->name(); ?></td> <td nowrap><?php echo $type; ?></td>
<td><?php echo $support->lastCustomerMessage()->body; ?></td> <td nowrap><?php echo $name; ?></td>
<td><?php echo $message; ?></td>
<td><?php echo $support->status; ?></td> <td><?php echo $support->status; ?></td>
<td nowrap=""><?php if( $support->order()->driver()->name ) { ?> <td nowrap=""><?php if( $driver ) { ?>
<a href="/permissions/users/<?php echo $support->order()->driver()->id_admin ?>"> <a href="/permissions/users/<?php echo $support->order()->driver()->id_admin ?>">
<?php echo $support->order()->driver()->name; ?> <?php echo $support->order()->driver()->name; ?>
</a> </a>
<?php } ?> <?php } else { ?>-<?php } ?>
<td> <td>
<?php echo $support->lastCustomerMessage()->relativeTime(); ?> <?php echo $customer_time; ?>
</td> </td>
<td> <td>
<?php echo $support->lastAdminMessage()->relativeTime(); ?> <?php echo $admin_time; ?>
</td> </td>
</td> </td>
<td> <td>
<a href="javascript://" onclick="SupportChats.createChat( '<?php echo $support->id_support; ?>' )"><button class="btn btn-mini btn-default"><i class="icon-comments"></i></button></a>
&nbsp;
<a href="/support/plus/<?= $support->id_support ?>"><button class="btn btn-mini btn-default">View</button></a> <a href="/support/plus/<?= $support->id_support ?>"><button class="btn btn-mini btn-default">View</button></a>
<?php if( $chat ) { ?>
&nbsp;
<a href="javascript://" onclick="SupportChats.createChat( '<?php echo $support->id_support; ?>' )"><button class="btn btn-mini btn-default"><i class="icon-comments"></i></button></a>
<?php } ?>
</td> </td>
</tr> </tr>
<?php <?php

View File

@ -41,7 +41,9 @@
<div id="container-chats"></div> <div id="container-chats"></div>
<script type="text/javascript"> <script type="text/javascript">
var status = 'open'; var status = 'open';
var type = 'support';
function load( url ){ function load( url ){
$.ajax( { $.ajax( {
@ -53,7 +55,7 @@ function load( url ){
}; };
$(function() { $(function() {
load( '/support/plus/content?status=' + status ); load( '/support/plus/content?status=' + status + '&type=' + type );
} ); } );
$(function() { $(function() {