mivita/app/Models/ShoppingCollectOrder.php
2022-07-18 18:07:31 +02:00

137 lines
4.4 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use App\User;
/**
* Class ShoppingCollectOrder
*
* @property int $id
* @property int $user_id
* @property int|null $shopping_order_id
* @property float|null $shipping
* @property float|null $shipping_net
* @property float|null $shipping_tax
* @property float|null $price_total_net
* @property float|null $price_total
* @property float|null $tax_total
* @property int $qty_total
* @property int|null $points
* @property string|null $tax_split
* @property AsArrayObject|null $orders
* @property AsArrayObject|null $shop_items
* @property int $status
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property ShoppingOrder|null $shopping_order
* @property User $user
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder query()
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereOrders($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder wherePoints($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder wherePriceTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder wherePriceTotalNet($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereQtyTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShipping($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShippingNet($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShippingTax($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShopItems($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereShoppingOrderId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereTaxSplit($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereTaxTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereUserId($value)
* @mixin \Eloquent
*/
class ShoppingCollectOrder extends Model
{
protected $table = 'shopping_collect_orders';
protected $casts = [
'user_id' => 'int',
'shopping_order_id' => 'int',
'shipping' => 'float',
'shipping_net' => 'float',
'shipping_tax' => 'float',
'price_total_net' => 'float',
'price_total' => 'float',
'tax_total' => 'float',
'qty_total' => 'int',
'points' => 'int',
'status' => 'int',
'tax_split' => 'array',
'orders' => AsArrayObject::class,
'shop_items' => AsArrayObject::class,
];
protected $fillable = [
'user_id',
'shopping_order_id',
//'identifier',
'shipping',
'shipping_net',
'shipping_tax',
'price_total_net',
'price_total',
'tax_total',
'qty_total',
'points',
'tax_split',
'orders',
'shop_items',
'status'
];
public static $statusTypes = [
0 => '',
1 => 'store / pre',
2 => 'order',
];
public function shopping_order()
{
return $this->belongsTo(ShoppingOrder::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function addTaxToSplit($tax_rate, $add_tax)
{
$tax_split = $this->tax_split;
$tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ? round($tax_split[$tax_rate] += $add_tax, 2) : $add_tax;
$this->tax_split = $tax_split;
}
public function addShopItem($shop_item_id, $shop_item)
{
$this->shop_items[$shop_item_id] = $shop_item;
}
public function addOrder($order)
{
$this->orders[] = $order;
}
public function initShoppingOrder($order)
{
$order['shopping_order'] = ShoppingOrder::findOrFail($order['order_id']);
return $order;
}
}