后台客户组管理
This commit is contained in:
parent
09bded4a32
commit
c80be51a0d
|
|
@ -13,6 +13,7 @@ namespace Beike\Admin\Http\Controllers;
|
|||
|
||||
use Beike\Admin\Http\Resources\CustomerResource;
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Repositories\CustomerGroupRepo;
|
||||
use Beike\Repositories\CustomerRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ class CustomerController extends Controller
|
|||
{
|
||||
$data = [
|
||||
'customer' => $customer,
|
||||
'customer_groups' => CustomerGroupRepo::list(true),
|
||||
'_redirect' => $this->getRedirect(),
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['total', 'reward_point_factor', 'use_point_factor', 'discount_factor', 'level'];
|
||||
}
|
||||
|
|
@ -56,7 +56,10 @@ class AddressRepo
|
|||
*/
|
||||
public static function delete($id)
|
||||
{
|
||||
Address::query()->find($id)->delete();
|
||||
$address = Address::query()->find($id);
|
||||
if ($address) {
|
||||
$address->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static function listByCustomer($customer)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* AddressRepo.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-06-28 15:22:05
|
||||
* @modified 2022-06-28 15:22:05
|
||||
*/
|
||||
|
||||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\CustomerGroup;
|
||||
|
||||
class CustomerGroupRepo
|
||||
{
|
||||
/**
|
||||
* 创建一个CustomerGroup记录
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$id = CustomerGroup::query()->insertGetId($data);
|
||||
return self::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public static function update($id, $data)
|
||||
{
|
||||
$group = CustomerGroup::query()->find($id);
|
||||
if (!$group) {
|
||||
throw new \Exception("Customer Group id {$id} 不存在");
|
||||
}
|
||||
$group->update($data);
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public static function find($id)
|
||||
{
|
||||
return CustomerGroup::query()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public static function delete($id)
|
||||
{
|
||||
$group = CustomerGroup::query()->find($id);
|
||||
if ($group) {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static function list($onlyEnabled = false)
|
||||
{
|
||||
$builder = CustomerGroup::query();
|
||||
if ($onlyEnabled) {
|
||||
$builder->where('stauts', 1);
|
||||
}
|
||||
$groups = $builder->get();
|
||||
|
||||
return $groups;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue