163 lines
5.4 KiB
PHP
163 lines
5.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)
|
|
* @property array|null $net_split
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingCollectOrder whereNetSplit($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',
|
|
'net_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',
|
|
'net_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;
|
|
$add_tax = round($add_tax, 2);
|
|
$tax_split[$tax_rate] = isset($tax_split[$tax_rate]) ? round($tax_split[$tax_rate] += $add_tax, 2) : $add_tax;
|
|
|
|
foreach($tax_split as $key=>$value){
|
|
$tax_split[$key] = number_format($value, 2);
|
|
}
|
|
$this->tax_split = $tax_split;
|
|
}
|
|
|
|
public function addNetToSplit($tax_rate, $add_net)
|
|
{
|
|
$net_split = $this->net_split;
|
|
$add_net = round($add_net, 2);
|
|
$net_split[$tax_rate] = isset($net_split[$tax_rate]) ? round($net_split[$tax_rate] += $add_net, 2) : $add_net;
|
|
|
|
foreach($net_split as $key=>$value){
|
|
$net_split[$key] = number_format($value, 2);
|
|
}
|
|
$this->net_split = $net_split;
|
|
}
|
|
|
|
public function addShopItem($shop_item_id, $shop_item)
|
|
{
|
|
$shop_item->user_price_net = number_format($shop_item->user_price_net, 2);
|
|
$shop_item->user_price_total_net = number_format($shop_item->user_price_total_net, 2);
|
|
$shop_item->user_tax = number_format($shop_item->user_tax, 2);
|
|
$shop_item->user_tax_total = number_format($shop_item->user_tax_total, 2);
|
|
|
|
$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;
|
|
}
|
|
}
|