|
|
@@ -1401,6 +1401,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
public function upWebsiteCategory(array $data): array
|
|
|
{
|
|
|
$pinyin = new Pinyin();
|
|
|
+ var_dump("更新数据:", $data);
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
if (!empty($data['category_arr_id'])) {
|
|
|
@@ -1470,14 +1471,14 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
var_dump($data, '--------111----');
|
|
|
$website_id = $data['website_id'];
|
|
|
//获取所有数据
|
|
|
- $result = WebsiteCategory::where(['website_id' => $website_id, 'path' => NULL])->get()->toArray();
|
|
|
+ $result = WebsiteCategory::where(['website_id' => $websiteId, 'path' => NULL])->get()->toArray();
|
|
|
if (empty($result)) {
|
|
|
// return Result::error("没有数据", 0);
|
|
|
}
|
|
|
//处理path
|
|
|
foreach ($result as $key => $value) {
|
|
|
$array_category_arr_id = json_decode($value['category_arr_id'], true);
|
|
|
- $result[$key]['path'] = WebsiteCategory::where('website_id', $website_id)
|
|
|
+ $result[$key]['path'] = WebsiteCategory::where('website_id', $websiteId)
|
|
|
->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
|
|
|
->whereIn('category_id', $array_category_arr_id)
|
|
|
->pluck('aLIas_pinyin')
|
|
|
@@ -1502,8 +1503,39 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
DB::rollBack();
|
|
|
throw $e; // 或者返回错误信息
|
|
|
}
|
|
|
+ //更换级别操作 形成新的上下级;
|
|
|
+ $website_all = WebsiteCategory::where('website_id', $website_id)
|
|
|
+ ->where('pid', '>', 0)
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ foreach ($website_all as $key => $value) {
|
|
|
+ $pidArr = json_decode($value['pid_arr'], true);
|
|
|
+ $validPids = [];
|
|
|
+ $pid = 0;
|
|
|
+ foreach ($pidArr as $pidid => $pid) {
|
|
|
+ $exists = WebsiteCategory::where('website_id', $website_id)
|
|
|
+ ->where('category_id', $pid)->exists();
|
|
|
+ if ($exists) {
|
|
|
+ $validPids[] = $pid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($validPids) != count($pidArr)) {
|
|
|
+ if (count($validPids) == 0) {
|
|
|
+ $validPids = [0];
|
|
|
+ }
|
|
|
+ var_dump($validPids, '--------222----');
|
|
|
+ $pid = end($validPids);
|
|
|
+ $category_arr_id = array_push($validPids, $value['category_id']);
|
|
|
+ // WebsiteCategory::where('id', $value['id'])->update([
|
|
|
+ // 'pid_arr' => json_encode($validPids),
|
|
|
+ // 'pid' => $pid,
|
|
|
+ // 'category_arr_id' => json_encode($category_arr_id)
|
|
|
+ // ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
Db::commit();
|
|
|
+ var_dump("更新数据1:", $data);
|
|
|
return Result::success();
|
|
|
} catch (\Throwable $ex) {
|
|
|
Db::rollBack();
|
|
|
@@ -1789,6 +1821,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
// array_push($where, ['category.city_id', '=', $data['city_id']]);
|
|
|
// }
|
|
|
$result = WebsiteCategory::where($where)
|
|
|
+ ->where('website_category.is_show', 1) //显示
|
|
|
->leftJoin("category", 'website_category.category_id', 'category.id')
|
|
|
->select("website_category.*", "category.name as name")
|
|
|
// ->leftJoin("category", 'website_category.category_id', 'category.id')
|