wyyl/beike/Admin/Services/CustomerGroupService.php

57 lines
1.4 KiB
PHP

<?php
/**
* CustomerGroupService.php
*
* @copyright 2022 opencart.cn - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author TL <mengwb@opencart.cn>
* @created 2022-07-01 11:15:25
* @modified 2022-07-01 11:15:25
*/
namespace Beike\Admin\Services;
use Beike\Repositories\CustomerGroupRepo;
class CustomerGroupService
{
/**
* @param $data
* @return int
*/
public static function create($data)
{
$customerGroup = CustomerGroupRepo::create($data);
$descriptions = [];
foreach ($data['descriptions'] as $locale => $description) {
$description['locale'] = $locale;
$descriptions[] = $description;
}
$customerGroup->descriptions()->createMany($descriptions);
return $customerGroup;
}
public static function update($id, $data)
{
$customerGroup = CustomerGroupRepo::find($id);
if (!$customerGroup) {
throw New \Exception("您更新的ID不存在");
}
$customerGroup->update($data);
$customerGroup->descriptions()->delete();
$descriptions = [];
foreach ($data['descriptions'] as $locale => $description) {
$description['locale'] = $locale;
$descriptions[] = $description;
}
$customerGroup->descriptions()->createMany($descriptions);
return $customerGroup;
}
}