From c80be51a0d5f8897319c4e01868840fc2820075a Mon Sep 17 00:00:00 2001 From: TL Date: Wed, 29 Jun 2022 20:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=AE=A2=E6=88=B7=E7=BB=84?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/CustomerController.php | 2 + beike/Models/CustomerGroup.php | 16 ++++ beike/Repositories/AddressRepo.php | 5 +- beike/Repositories/CustomerGroupRepo.php | 75 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 beike/Models/CustomerGroup.php create mode 100644 beike/Repositories/CustomerGroupRepo.php diff --git a/beike/Admin/Http/Controllers/CustomerController.php b/beike/Admin/Http/Controllers/CustomerController.php index b929162e..4e7c7a07 100644 --- a/beike/Admin/Http/Controllers/CustomerController.php +++ b/beike/Admin/Http/Controllers/CustomerController.php @@ -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(), ]; diff --git a/beike/Models/CustomerGroup.php b/beike/Models/CustomerGroup.php new file mode 100644 index 00000000..3f7783c9 --- /dev/null +++ b/beike/Models/CustomerGroup.php @@ -0,0 +1,16 @@ +find($id)->delete(); + $address = Address::query()->find($id); + if ($address) { + $address->delete(); + } } public static function listByCustomer($customer) diff --git a/beike/Repositories/CustomerGroupRepo.php b/beike/Repositories/CustomerGroupRepo.php new file mode 100644 index 00000000..7d628b20 --- /dev/null +++ b/beike/Repositories/CustomerGroupRepo.php @@ -0,0 +1,75 @@ + + * @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; + } +}