|
@@ -46,6 +46,8 @@ use function PHPUnit\Framework\isNull;
|
|
|
use Overtrue\Pinyin\Pinyin;
|
|
|
use App\Tools\buildTree;
|
|
|
use App\Model\Size;
|
|
|
+use App\Tools\PinyinHelper;
|
|
|
+use Hyperf\HttpServer\Annotation\AutoController;
|
|
|
#[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
@@ -93,11 +95,11 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
|
|
|
/**
|
|
|
* @param array $data
|
|
|
- * @return array
|
|
|
*/
|
|
|
public function createWebsite(array $data): array
|
|
|
{
|
|
|
var_dump("网站数据:", $data);
|
|
|
+ $wzbs = PinyinHelper::getFirstLetter($data['website_name']);
|
|
|
$insertData = [
|
|
|
'website_name' => $data['website_name'],
|
|
|
'logo' => $data['logo'] ?? '',
|
|
@@ -112,22 +114,44 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
// 'city_arr_id'=>$data['city_arr_id']??[0],
|
|
|
'template_id' => $data['template_id'] ?? 0,
|
|
|
'suffix' => $data['suffix'] ?? "",
|
|
|
+ // 'ad_key' => $wzbs,
|
|
|
];
|
|
|
+
|
|
|
+ // return Result::success($result);
|
|
|
+ // 检查网站名称是否重复或者 ad_key 是否重复
|
|
|
+ $web = Website::where('ad_key', $wzbs)->first();
|
|
|
+ // return Result::success(!empty($web->toArray()));
|
|
|
+ if (!empty($web)) {
|
|
|
+ if(!empty($data['ad_key']) && $data['ad_key']!='' && $data['ad_key']!=$wzbs){
|
|
|
+ $web_adkey = Website::where('ad_key', $data['ad_key'])->first();
|
|
|
+ if (!empty($web_adkey)) {
|
|
|
+ return Result::error("网站名称简写重复,请重新填写", 0);
|
|
|
+ }else{
|
|
|
+ $insertData['ad_key'] = $data['ad_key'];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return Result::error("网站名称简写重复,请填写", 0);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $insertData['ad_key'] = $wzbs;
|
|
|
+ }
|
|
|
$result = Website::insertGetId($insertData);
|
|
|
if (empty($result)) {
|
|
|
- return Result::error("创建失败", 0);
|
|
|
+ return Result::error("创建网站失败", 0);
|
|
|
} else {
|
|
|
return Result::success(["id" => $result]);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param int $id
|
|
|
+ * 修改网站头部基础信息
|
|
|
* @param array $data
|
|
|
- * @return array
|
|
|
*/
|
|
|
public function updateWebsite(int $id, array $data): array
|
|
|
{
|
|
|
+
|
|
|
+ $wzbs = PinyinHelper::getFirstLetter($data['website_name']);
|
|
|
$insertData = [
|
|
|
'website_name' => $data['website_name'],
|
|
|
'logo' => $data['logo'] ?? '',
|
|
@@ -143,13 +167,33 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
'template_id' => $data['template_id'] ?? 0,
|
|
|
'suffix' => $data['suffix'] ?? "",
|
|
|
];
|
|
|
- var_dump("=========:", $insertData);
|
|
|
+ $web_templsate = WebsiteTemplateInfo::where('website_id', $data['id'])->first();
|
|
|
+ // `status` tinyint(1) DEFAULT '0' COMMENT '0:未构建 1:未应用 2:已应用',
|
|
|
+ if (!empty($web_templsate) && $web_templsate['status'] == 2) {
|
|
|
+ return Result::error("此网站已应用,不可修改基本信息", 0);
|
|
|
+ }
|
|
|
+ $web = Website::where('ad_key', $wzbs)->first();
|
|
|
+ if (!empty($web)) {
|
|
|
+ if (!empty($data['ad_key']) && $data['ad_key'] != '' && $data['ad_key'] != $wzbs) {
|
|
|
+ $web_adkey = Website::where('ad_key', $data['ad_key'])->first();
|
|
|
+ // return Result::success($web_adkey);
|
|
|
+ if (!empty($web_adkey)) {
|
|
|
+ return Result::error("网站名称简写重复,请重新填写", 0);
|
|
|
+ }else{
|
|
|
+ $insertData['ad_key'] = $data['ad_key'];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return Result::error("网站名称简写重复,请填写", 0);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $insertData['ad_key'] = $wzbs;
|
|
|
+ }
|
|
|
$result = Website::where('id', $id)->update($insertData);
|
|
|
- var_dump("更新站点", $result);
|
|
|
+ // var_dump("更新站点", $result);
|
|
|
if (empty($result)) {
|
|
|
- return Result::error("更新失败", 0);
|
|
|
+ return Result::error("更新网站失败", 0);
|
|
|
} else {
|
|
|
- return Result::success();
|
|
|
+ return Result::success("更新成功");
|
|
|
}
|
|
|
}
|
|
|
|