初始化项目
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,18 @@
<?php
namespace App\Http\Controllers\Api\CodeGeneration;
use App\BaseApp\BaseController;
use App\Service\CodeGeneration\ProductClassificationService;
class ProductClassificationController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->insertField = ["name","cover","pid"];
$this->updateField = ["id","name","cover","pid"];
$this->service = ProductClassificationService::getInstance();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers\Api\CodeGeneration;
use App\BaseApp\BaseController;
use App\Service\CodeGeneration\ProductService;
class ProductController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->insertField = ["title","introduction","cover", "images","description","price","classification_id"];
$this->updateField = ["id","title","introduction","cover", "images","description","price","classification_id"];
$this->service = ProductService::getInstance();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers\Api\CodeGeneration;
use App\BaseApp\BaseController;
use App\Service\CodeGeneration\ProductImageService;
class ProductImageController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->insertField = ["url","product_id"];
$this->updateField = ["id","url","product_id"];
$this->service = ProductImageService::getInstance();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers\Api\CodeGeneration;
use App\BaseApp\BaseController;
use App\Service\CodeGeneration\ProductLabelService;
class ProductLabelController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->insertField = ["name"];
$this->updateField = ["id","name"];
$this->service = ProductLabelService::getInstance();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers\Api\CodeGeneration;
use App\BaseApp\BaseController;
use App\Service\CodeGeneration\StoreClassificationService;
class StoreClassificationController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->insertField = ["name","pid"];
$this->updateField = ["id","name","pid"];
$this->service = StoreClassificationService::getInstance();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers\Api\CodeGeneration;
use App\BaseApp\BaseController;
use App\Service\CodeGeneration\StoreService;
class StoreController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->insertField = ["name","level","avatar","introduction","description","phone","person", "classification_id","id_card","is_featured","business_license","id_card_portrait_side","id_card_national_emblem_side","chain","business_suspended"];
$this->updateField = ["id","name","level","avatar","introduction","description","phone","person", "classification_id","is_featured","business_license","id_card_portrait_side","id_card_national_emblem_side","chain","business_suspended"];
$this->service = StoreService::getInstance();
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use App\BaseApp\BaseModel;
class ProductClassificationModel extends BaseModel
{
protected $table = 'product_classification';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $guarded = [];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use App\BaseApp\BaseModel;
class ProductImageModel extends BaseModel
{
protected $table = 'product_image';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $guarded = [];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use App\BaseApp\BaseModel;
class ProductLabelModel extends BaseModel
{
protected $table = 'product_label';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $guarded = [];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use App\BaseApp\BaseModel;
use Illuminate\Database\Eloquent\Relations\HasMany;
class ProductModel extends BaseModel
{
protected $table = 'product';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $guarded = [];
public function images(): HasMany
{
return $this->hasMany(ProductImageModel::class, 'product_id', 'id');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use App\BaseApp\BaseModel;
class StoreClassificationModel extends BaseModel
{
protected $table = 'store_classification';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $guarded = [];
}

17
app/Models/StoreModel.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use App\BaseApp\BaseModel;
class StoreModel extends BaseModel
{
protected $table = 'store';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $guarded = [];
}

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);
}
}

View File

@@ -162,6 +162,22 @@ class UtilsService
}
}
/**
* 检查身份证号格式
* @param string $idCard
* @return true|void
* @throws Exception
*/
public function checkIdCard(string $idCard)
{
$idCard = trim($idCard);
if (preg_match('/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/', $idCard)) {
return true;
} else {
self::errorThrow('身份证号格式不正确');
}
}
/**
* 生成订单号
* @param int $type

View File

@@ -9,6 +9,13 @@ export async function getupperCamelCaseListApi(data: any) {
return requestClient.get<any>(`${prefix}list`, { params: data });
}
/**
* 获取模板名称下拉列表
*/
export async function getupperCamelCaseOptionApi() {
return requestClient.get<any>(`${prefix}option`);
}
/**
* 获取模板名称详情
* @param id