商品、订单部分相关代码生成,下一步先把商品搞完再搞订单
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-20 16:52:47 +08:00
parent 5bd5938e5c
commit 035ab1105c
45 changed files with 1951 additions and 151 deletions

View File

@@ -3,19 +3,19 @@
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\StoreClassificationModel;
use App\Models\MallClassificationModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class StoreClassificationService extends BaseService
class MallClassificationService 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;
$this->model = MallClassificationModel::class;
}
/**

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\MallMembershipLevelModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class MallMembershipLevelService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "experience", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => '=,status='];
$this->model = MallMembershipLevelModel::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

@@ -3,19 +3,19 @@
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\StoreModel;
use App\Models\MallModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class StoreService extends BaseService
class MallService 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;
$this->model = MallModel::class;
}
/**

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\OrderDetailModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class OrderDetailService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "order_id", "product_id", "quantity", "price", "subtotal", "snapshot", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['order_id' => '=','product_id' => '=,status='];
$this->model = OrderDetailModel::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\OrderModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class OrderService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "user_id", "order_no", "order_status", "total_amount", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['user_id' => '=','order_no' => 'like','order_status' => '=,status='];
$this->model = OrderModel::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\ProductLabelRelationsModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ProductLabelRelationsService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "product_id", "label_id", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['product_id' => '=','label_id' => '=,status='];
$this->model = ProductLabelRelationsModel::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

@@ -4,6 +4,7 @@ namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\ProductImageModel;
use App\Models\ProductLabelRelationsModel;
use App\Models\ProductModel;
use Exception;
use Illuminate\Support\Facades\DB;
@@ -19,7 +20,12 @@ class ProductService extends BaseService
$this->queryField = ['title' => 'like','mall_id' => '=','classification_id' => '=,status='];
$this->model = ProductModel::class;
$this->with = [
'images:id,product_id,url'
'images:id,product_id,url',
'mall:id,name,avatar',
'user:id,nick_name,avatar',
'labels',
'classification',
'skus:id,product_id,name,cover,price,inventory',
];
}
@@ -34,6 +40,8 @@ class ProductService extends BaseService
$result = $this->getPageList();
foreach ($result['items'] as &$v) {
$v['images'] = array_column($v['images'], 'url');
$v['labels_name'] = array_column($v['labels'], 'name');
$v['labels'] = array_column($v['labels'], 'id');
}
return $result;
}
@@ -46,7 +54,14 @@ class ProductService extends BaseService
*/
public function detail($id)
{
return $this->getDetail($id);
$result = $this->getDetail($id);
$result = $result->toArray();
$items = [];
foreach ($result['images'] as $v) {
$items[] = $v['url'];
}
$result['images'] = $items;
return $result;
}
/**
@@ -55,7 +70,7 @@ class ProductService extends BaseService
*/
public function option()
{
$this->optionField = ['id', 'name'];
$this->optionField = ['id', 'title'];
return $this->getOption();
}
@@ -68,8 +83,10 @@ class ProductService extends BaseService
public function create($params): mixed
{
$images = $params['images'];
unset($params['images']);
$labels = $params['labels'];
unset($params['images'], $params['labels']);
$params['user_id'] = $this->userId;
$params['mall_id'] = $this->mallId;
DB::beginTransaction();
try {
@@ -81,7 +98,20 @@ class ProductService extends BaseService
'url' => $v
];
}
$imageModel = ProductImageModel::insert($insertData);
$labelInsertData = [];
foreach ($labels as $v) {
$labelInsertData[] = [
'product_id' => $result,
'label_id' => $v
];
}
$labelModel = ProductLabelRelationsModel::insert($labelInsertData);
if (!$imageModel || !$labelModel) {
$this->utils->errorThrow('操作失败');
}
DB::commit();
} catch (Exception $e) {
DB::rollBack();
@@ -102,7 +132,8 @@ class ProductService extends BaseService
DB::beginTransaction();
try {
$images = $params['images'];
unset($params['images']);
$labels = $params['labels'];
unset($params['images'], $params['labels']);
// 1. 更新产品基本信息
$model = $this->save($id, $params);
@@ -139,6 +170,39 @@ class ProductService extends BaseService
}
}
// 3. 处理标签逻辑
if (isset($images)) {
$newLabels = $labels;
// 获取当前产品已有的图片URL列表
$existingLabels = ProductLabelRelationsModel::where('product_id', $id)
->pluck('label_id')
->toArray();
// 计算新增的图片和被删除的图片
$addedLabels = array_diff($newLabels, $existingLabels);
$deletedLabels = array_diff($existingLabels, $newLabels);
// 删除不再需要的图片记录
if (!empty($deletedLabels)) {
ProductLabelRelationsModel::where('product_id', $id)
->whereIn('label_id', $deletedLabels)
->delete();
}
// 添加新图片记录
if (!empty($addedLabels)) {
$insertData = [];
foreach ($addedLabels as $url) {
$insertData[] = [
'product_id' => $id,
'label_id' => $url
];
}
ProductLabelRelationsModel::insert($insertData);
}
}
DB::commit();
} catch (Exception $e) {
DB::rollBack();

View File

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

View File

@@ -0,0 +1,91 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\UserBrowsingHistoryModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class UserBrowsingHistoryService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "user_id", "product_id", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['user_id' => '=','product_id' => '=,status='];
$this->model = UserBrowsingHistoryModel::class;
}
/**
* 获取用户浏览记录列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
$this->with = [
'user:id,nick_name,avatar',
'product'
];
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,91 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\UserCollectModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class UserCollectService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "user_id", "product_id", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['user_id' => '=','product_id' => '=,status='];
$this->model = UserCollectModel::class;
}
/**
* 获取用户收藏列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
$this->with = [
'user:id,nick_name,avatar',
'product'
];
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\UserMembershipModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class UserMembershipService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "experience", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => '=,status='];
$this->model = UserMembershipModel::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\UserReceivingAddressModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class UserReceivingAddressService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "user_id", "province", "city", "district", "detailed_address", "complete_address", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['user_id' => '=','province' => '=','city' => '=','district' => '=','detailed_address' => '=','complete_address' => '=,status='];
$this->model = UserReceivingAddressModel::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,88 @@
<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\UserModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class UserService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "open_id", "nick_name", "phone", "email", "level", "balance", "avatar", "integral", "wx_open_id", "zfb_open_id", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['open_id' => '=','nick_name' => 'like','phone' => '=','email' => '=','level' => '=,status='];
$this->model = UserModel::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
{
$params['open_id'] = $this->utils->genOpenId();
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);
}
}