初始化项目
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled

This commit is contained in:
2025-05-19 16:54:25 +08:00
parent fa27b46caf
commit 5bd5938e5c
26 changed files with 2638 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\ProductClassificationModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ProductClassificationService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "cover", "pid", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => 'like','pid' => '=,status='];
$this->model = ProductClassificationModel::class;
}
/**
* 获取商品分类列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
return $this->getPageList();
}
/**
* 获取商品分类详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 商品分类下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name'];
return $this->getOption();
}
/**
* 创建商品分类
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
return $this->insert($params);
}
/**
* 编辑商品分类
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
return $this->save($id, $params);
}
/**
* 删除商品分类
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\ProductImageModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ProductImageService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "url", "product_id", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['url' => 'like','product_id' => '=,status='];
$this->model = ProductImageModel::class;
}
/**
* 获取商品图片列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
return $this->getPageList();
}
/**
* 获取商品图片详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 商品图片下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name'];
return $this->getOption();
}
/**
* 创建商品图片
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
return $this->insert($params);
}
/**
* 编辑商品图片
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
return $this->save($id, $params);
}
/**
* 删除商品图片
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\ProductLabelModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ProductLabelService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => '=,status='];
$this->model = ProductLabelModel::class;
}
/**
* 获取商品标签列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
return $this->getPageList();
}
/**
* 获取商品标签详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 商品标签下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name'];
return $this->getOption();
}
/**
* 创建商品标签
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
return $this->insert($params);
}
/**
* 编辑商品标签
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
return $this->save($id, $params);
}
/**
* 删除商品标签
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}

View File

@@ -0,0 +1,163 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\ProductImageModel;
use App\Models\ProductModel;
use Exception;
use Illuminate\Support\Facades\DB;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ProductService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "title", "mall_id", "user_id", "introduction", "cover", "description", "quantity_sold", "price", "classification_id", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['title' => 'like','mall_id' => '=','classification_id' => '=,status='];
$this->model = ProductModel::class;
$this->with = [
'images:id,product_id,url'
];
}
/**
* 获取产品列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
$result = $this->getPageList();
foreach ($result['items'] as &$v) {
$v['images'] = array_column($v['images'], 'url');
}
return $result;
}
/**
* 获取产品详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 产品下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name'];
return $this->getOption();
}
/**
* 创建产品
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
$images = $params['images'];
unset($params['images']);
$params['user_id'] = $this->userId;
DB::beginTransaction();
try {
$result = $this->insert($params);
$insertData = [];
foreach ($images as $v) {
$insertData[] = [
'product_id' => $result,
'url' => $v
];
}
$imageModel = ProductImageModel::insert($insertData);
DB::commit();
} catch (Exception $e) {
DB::rollBack();
$this->utils->errorThrow($e->getMessage());
}
return $imageModel;
}
/**
* 编辑产品
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
DB::beginTransaction();
try {
$images = $params['images'];
unset($params['images']);
// 1. 更新产品基本信息
$model = $this->save($id, $params);
// 2. 处理图片逻辑
if (isset($images)) {
$newImages = $images;
// 获取当前产品已有的图片URL列表
$existingImages = ProductImageModel::where('product_id', $id)
->pluck('url')
->toArray();
// 计算新增的图片和被删除的图片
$addedImages = array_diff($newImages, $existingImages);
$deletedImages = array_diff($existingImages, $newImages);
// 删除不再需要的图片记录
if (!empty($deletedImages)) {
ProductImageModel::where('product_id', $id)
->whereIn('url', $deletedImages)
->delete();
}
// 添加新图片记录
if (!empty($addedImages)) {
$insertData = [];
foreach ($addedImages as $url) {
$insertData[] = [
'product_id' => $id,
'url' => $url
];
}
ProductImageModel::insert($insertData);
}
}
DB::commit();
} catch (Exception $e) {
DB::rollBack();
$this->utils->errorThrow($e->getMessage());
}
// 返回更新后的产品信息
return $model;
}
/**
* 删除产品
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\StoreClassificationModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class StoreClassificationService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "pid", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => 'like','pid' => '=,status='];
$this->model = StoreClassificationModel::class;
}
/**
* 获取店铺行业列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
return $this->getPageList();
}
/**
* 获取店铺行业详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 店铺行业下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name', 'pid'];
$this->where[] = ['pid', '=', 0];
$result = $this->getOption();
$result = $result->toArray();
$ids = array_column($result, 'id');
$this->whereIn = ['pid', $ids];
// 查询所有的子分类,然后放在父级分类下面
$this->where = [['deleted_at', '=', 0]];
$children = $this->getOption();
$children = $children->toArray();
$arr = array_merge($result, $children);
$data = tree($arr);
array_unshift($data, ['id' => 0, 'name' => '不分类', 'pid' => 0]);
return $data;
}
/**
* 创建店铺行业
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
return $this->insert($params);
}
/**
* 编辑店铺行业
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
return $this->save($id, $params);
}
/**
* 删除店铺行业
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\StoreModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class StoreService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "level", "avatar", "introduction", "classification_id", "description", "phone", "person", "id_card", "qr_code", "is_featured", "business_license", "id_card_portrait_side", "id_card_national_emblem_side", "chain", "business_suspended", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => '=','level' => '=','phone' => 'like','person' => '=','classification_id' => '=','is_featured' => '=','chain' => '=','business_suspended' => '=,status='];
$this->model = StoreModel::class;
}
/**
* 获取店铺管理列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
return $this->getPageList();
}
/**
* 获取店铺管理详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 店铺管理下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name'];
return $this->getOption();
}
/**
* 创建店铺管理
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
$this->utils->checkPhone($params['phone']);
$this->utils->checkIdCard($params['id_card']);
return $this->insert($params);
}
/**
* 编辑店铺管理
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
$this->utils->checkPhone($params['phone']);
return $this->save($id, $params);
}
/**
* 删除店铺管理
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}