testemich Promotion

This commit is contained in:
Kevin Adametz 2022-04-14 13:21:17 +02:00
parent 38e7fd504a
commit a0f4eda6ea
83 changed files with 1690 additions and 504 deletions

View file

@ -136,7 +136,7 @@ class Category extends Model
public function getShowOnTypes(){
$ret = [];
if(is_array($this->show_on)){
if($this->show_on && is_array($this->show_on)){
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}

View file

@ -73,7 +73,7 @@ class PaymentMethod extends Model
public function getShowOnTypes(){
$ret = [];
if($this->show_on){
if($this->show_on && is_array($this->show_on)){
foreach($this->show_on as $show){
$ret[] = isset(Type::$payShowONs[$show]) ? Type::$payShowONs[$show] : '-';
}

View file

@ -224,6 +224,7 @@ class Product extends Model
public $actions = [
0 => 'payment_for_account',
1 => 'charging_credits',
// 1 => 'payment_for_shop',
// 2 => 'payment_for_shop_upgrade',
// 4 => 'payment_for_lead_upgrade',
@ -425,8 +426,10 @@ class Product extends Model
public function getShowOnTypes(){
$ret = [];
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
if($this->show_on && is_array($this->show_on)){
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
}
return $ret;
}

View file

@ -49,8 +49,10 @@ class ProductCategory extends Model
public function getShowOnTypes(){
$ret = [];
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
if($this->show_on && is_array($this->show_on)){
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
}
return $ret;
}

View file

@ -102,7 +102,7 @@ class PromotionAdminProduct extends Model
public function setPriceAttribute( $value ) {
$this->attributes['price'] = $value ? Util::reFormatNumber($value) : null;
$this->attributes['price'] = $value !== null ? Util::reFormatNumber($value) : null;
}
public function getFormattedPrice()
@ -112,7 +112,7 @@ class PromotionAdminProduct extends Model
public function getRealPrice()
{
if($this->own_price && $this->price){
if($this->own_price && $this->price !== null){
return $this->price;
}
if($this->product && $this->product->price){

View file

@ -121,7 +121,18 @@ class PromotionUser extends Model
return $this->hasMany(PromotionUserProduct::class)->where('active', 1);
}
public function promotion_user_orders()
{
return $this->hasMany(PromotionUserOrder::class);
}
public function getPromotionUserOrders($shopping_order_id)
{
return PromotionUserOrder::where('promotion_user_id', $this->id)->where('shopping_order_id', $shopping_order_id)->get();
}
public function getUrlPreview()
{
return $this->url ? config('app.promo_url')."/".$this->url : "";
@ -182,12 +193,15 @@ class PromotionUser extends Model
public function checkPaymentCredit()
{
if($this->promotion_user_products_active->count() > 0 && $this->getCountOpenItems() > 0){
$prices = $this->calculateCart();
if(isset($prices['price']) && $prices['price'] == 0){
return "okay";
}
$payment_credit = $this->user->payment_credit;
if($payment_credit <= 0){
return "empty";
}
$prices = $this->calculateCart();
if(isset($prices['price']) && $prices['price'] > 0){
if($payment_credit >= $prices['price']){
return "okay";
@ -211,8 +225,12 @@ class PromotionUser extends Model
return false;
}
public static function preCheckPaymentCredit($values, $user){
if($values['count_items'] > 0 && $values['sum_items'] > 0){
if(isset($values['price']) && $values['price'] == 0){
return "okay";
}
$payment_credit = $user->payment_credit;
if($payment_credit <= 0){
return "empty";
@ -227,7 +245,6 @@ class PromotionUser extends Model
return false;
}
public static function preCalculateCart($value, $by = ''){
$price = 0;
$price_net = 0;

View file

@ -71,7 +71,8 @@ class PromotionUserOrder extends Model
'price' => 'float',
'price_net' => 'float',
'tax_rate' => 'float',
'status' => 'int'
'status' => 'int',
'pick_up' => 'bool',
];
protected $fillable = [
@ -86,9 +87,15 @@ class PromotionUserOrder extends Model
'price',
'price_net',
'tax_rate',
'status'
'status',
'pick_up'
];
public static $statusTypes = [
0 => 'bestellt',
10 => 'storniert'
];
public function product()
{
return $this->belongsTo(Product::class);
@ -123,4 +130,29 @@ class PromotionUserOrder extends Model
{
return $this->belongsTo(ShoppingUser::class);
}
public function getStatusType(){
return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : "";
}
public function setStatusTxAction($txaction){
switch ($txaction) {
case 'none':
$this->status = 10;
break;
case 'open':
$this->status = 0;
break;
case 'paid':
$this->status = 3;
break;
}
$this->save();
}
public function setStatusShipped($shipped){
$this->status = $shipped === 'cancel' ? 10 : 0;
$this->save();
}
}

View file

@ -96,4 +96,5 @@ class PromotionUserProduct extends Model
}
return false;
}
}

View file

@ -157,23 +157,49 @@ class ShoppingOrder extends Model
1 => 'in Bearbeitung',
2 => 'versendet',
3 => 'abgeschlossen',
4 => 'Abholung',
10 => 'storniert'
];
public static $paymentForTypes = [
0 => '',
1 => 'wizzard',
2 => 'user_order me',
3 => 'user_order ot',
4 => 'Promotion',
10 => ''
1 => 'Registrierung',
2 => 'Mitgliedschaft',
3 => 'Guthabenaufladung', //guthaben
4 => 'VP.Bestellung Abholung',
5 => 'VP.Bestellung Lieferung',
6 => 'VP.Kundenbestellung',
7 => 'Promotion',
8 => 'Shop',
9 => '-',
10 => 'extern',
11 => ''
];
public static $paymentForColors = [
0 => 'default',
1 => 'warning',
2 => 'warning',
3 => 'secondary',
4 => 'secondary',
5 => 'secondary',
6 => 'info',
7 => 'dark',
8 => 'info',
9 => 'default',
10 => 'info',
11 => 'default'
];
public static $apiShippedTypes = [
0 => 'open', //(Fullfilment durch Händler)',
1 => 'process', //(Fullfilment durch MIVITA: nicht Versand)
2 => 'sent', //(Fullfilment durch MIVITA: Versand erfolgt)'
3 => 'close', //(Fullfilment durch MIVITA: Versand erfolgt)',
4 => 'pick_up', //(Fullfilment durch MIVITA: Versand erfolgt)',
10 => 'cancel'
];
@ -182,6 +208,7 @@ class ShoppingOrder extends Model
1 => 'info',
2 => 'success',
3 => 'secondary',
4 => 'success',
10 => 'danger',
];
@ -272,6 +299,13 @@ class ShoppingOrder extends Model
return isset(self::$shippedColors[$this->shipped]) ? self::$shippedColors[$this->shipped] : "default";
}
public function getPaymentForType(){
return isset(self::$paymentForTypes[$this->payment_for]) ? self::$paymentForTypes[$this->payment_for] : "";
}
public function getPaymentForColor(){
return isset(self::$paymentForColors[$this->payment_for]) ? self::$paymentForColors[$this->payment_for] : "";
}
public function getFormattedTotal()
{
return formatNumber($this->attributes['total']);
@ -319,8 +353,6 @@ class ShoppingOrder extends Model
{
return formatNumber($this->attributes['payment_credit']);
}
public function getFormattedTotalShipping()
{
return formatNumber($this->attributes['total_shipping']);
@ -333,10 +365,14 @@ class ShoppingOrder extends Model
$count += $shopping_order_item->qty;
}
}
return $count;
}
public function isPickUp(){
return $this->shipping_option === 'pick_up' ? true : false;
}
public function isTax(){
return $this->tax > 0 ? true : false;
}
}

View file

@ -56,6 +56,18 @@ class ShoppingOrderItem extends Model
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $casts = [
'shopping_order_id' => 'int',
'product_id' => 'int',
'comp' => 'int',
'free_product_id' => 'int',
'qty' => 'int',
'price' => 'float',
'price_net' => 'float',
'tax_rate' => 'float',
'handle' => 'bool',
];
protected $fillable = [
'shopping_order_id',
'row_id',
@ -67,6 +79,7 @@ class ShoppingOrderItem extends Model
'price_net',
'tax_rate',
'slug',
'handle',
];

View file

@ -251,4 +251,33 @@ class ShoppingUser extends Model
}
return "free";
}
public function getOrderPaymentFor() {
switch($this->is_from){
case 'wizard':
return 1;
case 'membership':
return 2;
case 'user_order':
if($this->is_for === 'cr'){
return 3;
}
if($this->is_for === 'mp'){
return 4;
}
if($this->is_for === 'me'){
return 5;
}
if($this->is_for === 'ot'){
return 6;
}
return 0;
case 'shopping':
return $this->is_for === 'pr' ? 7 : 8; //7 Promotion
case 'extern':
return 10;
}
return 0;
}
}

View file

@ -50,7 +50,10 @@ class UserPayCredit extends Model
4 => 'return from order',
5 => 'deduction from promotion',
6 => 'return from promotion',
7 => 'add credits from charging',
8 => 'remove credits from charging',
];
protected $table = 'user_pay_credits';
protected $casts = [