继承 base model
This commit is contained in:
parent
b5f6249f87
commit
faf3d09084
|
|
@ -11,11 +11,10 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Address extends Model
|
||||
class Address extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* Base.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-07-21 18:27:45
|
||||
* @modified 2022-07-21 18:27:45
|
||||
*/
|
||||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Base extends Model
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -2,11 +2,9 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Cart extends Model
|
||||
class Cart extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,9 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CartProduct extends Model
|
||||
class CartProduct extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Category extends Model
|
||||
class Category extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CategoryDescription extends Model
|
||||
class CategoryDescription extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class CategoryPath extends Model
|
||||
class CategoryPath extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,10 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Country extends Model
|
||||
class Country extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Currency extends Model
|
||||
class Currency extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,8 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
class CustomerGroup extends Model
|
||||
class CustomerGroup extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomerGroupDescription extends Model
|
||||
class CustomerGroupDescription extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class CustomerWishlist extends Model
|
||||
class CustomerWishlist extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Language extends Model
|
||||
class Language extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Order extends Model
|
||||
class Order extends Base
|
||||
{
|
||||
protected $fillable = [
|
||||
'number', 'customer_id', 'customer_group_id', 'shipping_address_id', 'payment_address_id', 'customer_name',
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderProduct extends Model
|
||||
class OrderProduct extends Base
|
||||
{
|
||||
protected $fillable = [
|
||||
'product_id', 'order_number', 'product_sku', 'name', 'image', 'quantity', 'price',
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Plugin extends Model
|
||||
class Plugin extends Base
|
||||
{
|
||||
protected $fillable = ['type', 'code'];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Product extends Model
|
||||
class Product extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductCategory extends Model
|
||||
class ProductCategory extends Base
|
||||
{
|
||||
protected $table = 'product_categories';
|
||||
protected $fillable = ['product_id', 'category_id'];
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductDescription extends Model
|
||||
class ProductDescription extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductSku extends Model
|
||||
class ProductSku extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
/**
|
||||
* Region.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-07-21 16:55:16
|
||||
* @modified 2022-07-21 16:55:16
|
||||
*/
|
||||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Region extends Base
|
||||
{
|
||||
public function zones(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Zone::class, 'region_zones');
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Setting extends Model
|
||||
class Setting extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,10 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class VerifyCode extends Model
|
||||
class VerifyCode extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Zone extends Model
|
||||
class Zone extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
/**
|
||||
* TaxService.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-07-21 16:29:54
|
||||
* @modified 2022-07-21 16:29:54
|
||||
*/
|
||||
|
||||
namespace Beike\Services;
|
||||
|
||||
class TaxService
|
||||
{
|
||||
private $tax_rates = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->config = $registry->get('config');
|
||||
$this->db = $registry->get('db');
|
||||
}
|
||||
|
||||
public function unsetRates() {
|
||||
$this->tax_rates = array();
|
||||
}
|
||||
|
||||
public function setShippingAddress($country_id, $zone_id) {
|
||||
$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'shipping' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");
|
||||
|
||||
foreach ($tax_query->rows as $result) {
|
||||
$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => $result['type'],
|
||||
'priority' => $result['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function setPaymentAddress($country_id, $zone_id) {
|
||||
$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'payment' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");
|
||||
|
||||
foreach ($tax_query->rows as $result) {
|
||||
$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => $result['type'],
|
||||
'priority' => $result['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function setStoreAddress($country_id, $zone_id) {
|
||||
$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'store' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");
|
||||
|
||||
foreach ($tax_query->rows as $result) {
|
||||
$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => $result['type'],
|
||||
'priority' => $result['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function calculate($value, $tax_class_id, $calculate = true) {
|
||||
if ($tax_class_id && $calculate) {
|
||||
$amount = 0;
|
||||
|
||||
$tax_rates = $this->getRates($value, $tax_class_id);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if ($calculate != 'P' && $calculate != 'F') {
|
||||
$amount += $tax_rate['amount'];
|
||||
} elseif ($tax_rate['type'] == $calculate) {
|
||||
$amount += $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
return $value + $amount;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTax($value, $tax_class_id) {
|
||||
$amount = 0;
|
||||
|
||||
$tax_rates = $this->getRates($value, $tax_class_id);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
$amount += $tax_rate['amount'];
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function getRateName($tax_rate_id) {
|
||||
$tax_query = $this->db->query("SELECT name FROM " . DB_PREFIX . "tax_rate WHERE tax_rate_id = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
if ($tax_query->num_rows) {
|
||||
return $tax_query->row['name'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRates($value, $tax_class_id) {
|
||||
$tax_rate_data = array();
|
||||
|
||||
if (isset($this->tax_rates[$tax_class_id])) {
|
||||
foreach ($this->tax_rates[$tax_class_id] as $tax_rate) {
|
||||
if (isset($tax_rate_data[$tax_rate['tax_rate_id']])) {
|
||||
$amount = $tax_rate_data[$tax_rate['tax_rate_id']]['amount'];
|
||||
} else {
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
if ($tax_rate['type'] == 'F') {
|
||||
$amount += $tax_rate['rate'];
|
||||
} elseif ($tax_rate['type'] == 'P') {
|
||||
$amount += ($value / 100 * $tax_rate['rate']);
|
||||
}
|
||||
|
||||
$tax_rate_data[$tax_rate['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $tax_rate['tax_rate_id'],
|
||||
'name' => $tax_rate['name'],
|
||||
'rate' => $tax_rate['rate'],
|
||||
'type' => $tax_rate['type'],
|
||||
'amount' => $amount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $tax_rate_data;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue