Edit New issue customer referral changes - mvp #4859
This commit is contained in:
parent
9c72b8008f
commit
d4901a02ba
@ -25,17 +25,20 @@ class Controller_api_user extends Crunchbutton_Controller_Rest {
|
||||
$out = [];
|
||||
$out[ 'invite_code' ] = $user->invite_code;
|
||||
$free_delivery = intval( $reward[ Crunchbutton_Reward::CONFIG_KEY_MAX_CAP_POINTS ] );
|
||||
$out[ 'free_delivery' ] = number_format( $free_delivery, 0, '.', ',' );
|
||||
$out[ 'free_delivery' ] = Crunchbutton_Credit::formatPoints( $free_delivery );
|
||||
$out[ 'total' ] = Crunchbutton_Credit::points( $user->id_user );
|
||||
if( $free_delivery > 0 && $free_delivery <= $out[ 'total' ] ){
|
||||
$out[ 'show' ] = $out[ 'free_delivery' ];
|
||||
$out[ 'points_percent' ] = 100;
|
||||
$out[ 'free_delivery_message' ] = true;
|
||||
} else {
|
||||
$out[ 'free_delivery_message' ] = false;
|
||||
$out[ 'show' ] = number_format( $out[ 'total' ], 0, '.', ',' );
|
||||
$out[ 'away_free_delivery' ] = number_format( $free_delivery - $out[ 'total' ], 0, '.', ',' );
|
||||
$out[ 'show' ] = Crunchbutton_Credit::formatPoints( $out[ 'total' ] );
|
||||
$out[ 'points_percent' ] = intval( ( $out[ 'total' ] / $free_delivery * 100 ) );
|
||||
$out[ 'away_free_delivery' ] = Crunchbutton_Credit::formatPoints( $free_delivery - $out[ 'total' ] );
|
||||
}
|
||||
echo json_encode( $out );exit;
|
||||
|
||||
break;
|
||||
// Verify if the login was already taken
|
||||
case 'verify':
|
||||
|
||||
@ -294,12 +294,23 @@ class Crunchbutton_Credit extends Cana_Table
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function formatPoints( $points ){
|
||||
return Util::humanReadableNumbers( $points );
|
||||
}
|
||||
|
||||
public function points( $id_user ){
|
||||
$query = 'SELECT SUM( value ) AS points FROM credit c WHERE c.id_user = ? AND credit_type = ? AND type = ?';
|
||||
$row = Cana::db()->get( $query, [$id_user, Crunchbutton_Credit::CREDIT_TYPE_POINT, Crunchbutton_Credit::TYPE_CREDIT]);
|
||||
if( $row->_items && $row->_items[0] ){
|
||||
$row = $row->_items[0];
|
||||
$spent = ( $row->points && $row->points < 0 ) ? 0 : $row->points;
|
||||
$points = ( $row->points && $row->points < 0 ) ? 0 : $row->points;
|
||||
}
|
||||
$spent = 0;
|
||||
$query = 'SELECT SUM( value ) AS spent FROM credit c WHERE c.id_user = ? AND credit_type = ? AND type = ?';
|
||||
$row = Cana::db()->get( $query, [$id_user, Crunchbutton_Credit::CREDIT_TYPE_POINT, Crunchbutton_Credit::TYPE_DEBIT]);
|
||||
if( $row->_items && $row->_items[0] ){
|
||||
$row = $row->_items[0];
|
||||
$spent = ( $row->spent && $row->spent < 0 ) ? 0 : $row->spent;
|
||||
}
|
||||
return intval( ( $points - $spent ) );
|
||||
}
|
||||
|
||||
@ -2207,16 +2207,15 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange {
|
||||
$reward = new Crunchbutton_Reward;
|
||||
$points = $reward->processOrder( $this->id_order );
|
||||
$shared = $reward->orderWasAlreadyShared( $this->id_order );
|
||||
$out['reward'] = array( 'points' => number_format( $points, 0, '.', ',' ), 'shared' => $shared );
|
||||
|
||||
$out['reward'] = array( 'points' => Crunchbutton_Credit::formatPoints( $points ), 'shared' => $shared );
|
||||
}
|
||||
} else {
|
||||
$reward = new Crunchbutton_Reward;
|
||||
$points = $reward->processOrder( $this->id_order );
|
||||
$out['reward'] = array( 'points' => number_format( $points, 0, '.', ',' ) );
|
||||
$out['reward'] = array( 'points' => Crunchbutton_Credit::formatPoints( $points ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
@ -244,15 +244,17 @@ class Crunchbutton_User extends Cana_Table {
|
||||
$reward = $reward->loadSettings();
|
||||
$free_delivery = intval( $reward[ Crunchbutton_Reward::CONFIG_KEY_MAX_CAP_POINTS ] );
|
||||
$out[ 'points' ] = [];
|
||||
$out[ 'points' ][ 'free_delivery' ] = number_format ( $free_delivery, 0, '.', ',' );
|
||||
$out[ 'points' ][ 'free_delivery' ] = Crunchbutton_Credit::formatPoints( $free_delivery );
|
||||
$out[ 'points' ][ 'total' ] = Crunchbutton_Credit::points( $this->id_user );
|
||||
if( $free_delivery > 0 && $free_delivery <= $out[ 'points' ][ 'total' ] ){
|
||||
$out[ 'points' ][ 'show' ] = $out[ 'points' ][ 'free_delivery' ];
|
||||
$out[ 'points' ][ 'points_percent' ] = 100;
|
||||
$out[ 'points' ][ 'free_delivery_message' ] = true;
|
||||
} else {
|
||||
$out[ 'points' ][ 'free_delivery_message' ] = false;
|
||||
$out[ 'points' ][ 'show' ] = number_format( $out[ 'points' ][ 'total' ], 0, '.', ',' );;
|
||||
$out[ 'points' ][ 'away_free_delivery' ] = number_format( $free_delivery - $out[ 'points' ][ 'total' ], 0, '.', ',' );;
|
||||
$out[ 'points' ][ 'show' ] = Crunchbutton_Credit::formatPoints( $out[ 'points' ][ 'total' ] );
|
||||
$out[ 'points' ][ 'points_percent' ] = intval( ( $out[ 'points' ][ 'total' ] / $free_delivery * 100 ) );
|
||||
$out[ 'points' ][ 'away_free_delivery' ] = Crunchbutton_Credit::formatPoints( $free_delivery - $out[ 'points' ][ 'total' ] );
|
||||
}
|
||||
|
||||
return $out;
|
||||
|
||||
@ -9,6 +9,18 @@ class Crunchbutton_Util extends Cana_Model {
|
||||
( strpos( $_SERVER['HTTP_HOST'], 'dev.pit' ) !== false ) ) ? true : false;
|
||||
}
|
||||
|
||||
// https://gist.github.com/maggiben/9457434
|
||||
public static function humanReadableNumbers( $number ){
|
||||
if( $number < 1000 ){
|
||||
return $number;
|
||||
}
|
||||
$si = [ 'K', 'M', 'G', 'T', 'P', 'H' ];
|
||||
$exp = floor( log( $number ) / log( 1000 ) );
|
||||
$result = $number / pow( 1000, $exp );
|
||||
$result = ( $result % 1 > ( 1 / pow( 1000, $exp - 1 ) ) ? round( $result, 2 ) : round( $result, 0 ) );
|
||||
return $result . $si[ $exp - 1 ];
|
||||
}
|
||||
|
||||
public function frontendTemplates($export = false) {
|
||||
$files = [];
|
||||
|
||||
|
||||
@ -39,7 +39,9 @@
|
||||
<?php */ ?>
|
||||
<a id="credit"></a>
|
||||
<div ng-if="!account.user.points.free_delivery_message && account.user.points.away_free_delivery">
|
||||
0 <span class="points"><progress max="100" value="{{points_percent}}"></progress></span> {{account.user.points.free_delivery}}
|
||||
0 <span class="points"><progress max="100" value="{{account.user.points.points_percent}}"></progress></span> {{account.user.points.free_delivery}}
|
||||
<br/><br/>
|
||||
|
||||
<p>
|
||||
You are <b>{{account.user.points.away_free_delivery}}</b> points away from a free delivery.<br>
|
||||
Earn points by ordering food, sharing your order, or referring friends.<br>
|
||||
@ -52,11 +54,6 @@
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div>Earn points by ordering food, sharing your order, or referring friends.</div><br/>
|
||||
<div>Share this family and friends code and both of you get your next delivery on us.</div><br/>
|
||||
<div><strong>{{account.user.invite_code}}</strong></div>
|
||||
|
||||
<div class="divider"></div>
|
||||
<div class="social-button twitter-button social-button-invite" ng-click="referral.twitter();">
|
||||
<i class="fa fa-twitter"></i><span class="social-button-text">Tweet</span>
|
||||
|
||||
@ -1389,7 +1389,6 @@ NGApp.controller('OrdersCtrl', function ($timeout, $scope, $http, $location, Acc
|
||||
$scope.referral.twitter = function(){
|
||||
window.open('https://twitter.com/intent/tweet?url=' + $scope.referral.invite_url + '&text=#nom','_system');
|
||||
}
|
||||
$scope.points_percent = (($scope.account.user.points.total)/($scope.account.user.points.free_delivery)*100);
|
||||
$scope.hello = 50;
|
||||
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user