提交说明:

移除 'task' 配置项以避免潜在的混淆
This commit is contained in:
mkm 2024-05-31 15:38:56 +08:00
parent cc79d7444f
commit 37fa6d93c6
15 changed files with 832 additions and 9 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\store_category;
use app\admin\controller\BaseAdminController;
use app\admin\lists\store_category\StoreCategoryLists;
use app\admin\logic\store_category\StoreCategoryLogic;
use app\admin\validate\store_category\StoreCategoryValidate;
/**
* 商品分类控制器
* Class StoreCategoryController
* @package app\admin\controller\store_category
*/
class StoreCategoryController extends BaseAdminController
{
/**
* @notes 获取商品分类列表
* @return \think\response\Json
* @author admin
* @date 2024/05/31 11:33
*/
public function lists()
{
return $this->dataLists(new StoreCategoryLists());
}
/**
* @notes 添加商品分类
* @return \think\response\Json
* @author admin
* @date 2024/05/31 11:33
*/
public function add()
{
$params = (new StoreCategoryValidate())->post()->goCheck('add');
$result = StoreCategoryLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(StoreCategoryLogic::getError());
}
/**
* @notes 编辑商品分类
* @return \think\response\Json
* @author admin
* @date 2024/05/31 11:33
*/
public function edit()
{
$params = (new StoreCategoryValidate())->post()->goCheck('edit');
$result = StoreCategoryLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(StoreCategoryLogic::getError());
}
/**
* @notes 删除商品分类
* @return \think\response\Json
* @author admin
* @date 2024/05/31 11:33
*/
public function delete()
{
$params = (new StoreCategoryValidate())->post()->goCheck('delete');
StoreCategoryLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取商品分类详情
* @return \think\response\Json
* @author admin
* @date 2024/05/31 11:33
*/
public function detail()
{
$params = (new StoreCategoryValidate())->goCheck('detail');
$result = StoreCategoryLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\store_product_attr_value;
use app\admin\controller\BaseAdminController;
use app\admin\lists\store_product_attr_value\StoreProductAttrValueLists;
use app\admin\logic\store_product_attr_value\StoreProductAttrValueLogic;
use app\admin\validate\store_product_attr_value\StoreProductAttrValueValidate;
/**
* 商品属性值控制器
* Class StoreProductAttrValueController
* @package app\admin\controller\store_product_attr_value
*/
class StoreProductAttrValueController extends BaseAdminController
{
/**
* @notes 获取商品属性值列表
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
public function lists()
{
return $this->dataLists(new StoreProductAttrValueLists());
}
/**
* @notes 添加商品属性值
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
public function add()
{
$params = (new StoreProductAttrValueValidate())->post()->goCheck('add');
$result = StoreProductAttrValueLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(StoreProductAttrValueLogic::getError());
}
/**
* @notes 编辑商品属性值
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
public function edit()
{
$params = (new StoreProductAttrValueValidate())->post()->goCheck('edit');
$result = StoreProductAttrValueLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(StoreProductAttrValueLogic::getError());
}
/**
* @notes 删除商品属性值
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
public function delete()
{
$params = (new StoreProductAttrValueValidate())->post()->goCheck('delete');
StoreProductAttrValueLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取商品属性值详情
* @return \think\response\Json
* @author admin
* @date 2024/05/31 14:10
*/
public function detail()
{
$params = (new StoreProductAttrValueValidate())->goCheck('detail');
$result = StoreProductAttrValueLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\store_category;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\store_category\StoreCategory;
use app\common\lists\ListsSearchInterface;
/**
* 商品分类列表
* Class StoreCategoryLists
* @package app\admin\listsstore_category
*/
class StoreCategoryLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/05/31 11:33
*/
public function setSearch(): array
{
return [
'=' => ['name','pid'],
];
}
/**
* @notes 获取商品分类列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/05/31 11:33
*/
public function lists(): array
{
return StoreCategory::where($this->searchWhere)
->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取商品分类数量
* @return int
* @author admin
* @date 2024/05/31 11:33
*/
public function count(): int
{
return StoreCategory::where($this->searchWhere)->count();
}
}

View File

@ -6,7 +6,8 @@ namespace app\admin\lists\store_product;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_unit\StoreProductUnit;
/**
* 商品列表列表
@ -43,10 +44,14 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
public function lists(): array
{
return StoreProduct::where($this->searchWhere)
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'unit_name', 'sales', 'stock', 'is_show', 'is_new', 'add_time', 'is_postage', 'is_del', 'cost'])
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'is_show', 'unit', 'cost','rose','purchase'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->select()->each(function ($item) {
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
return $item;
})
->toArray();
}
@ -61,5 +66,4 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
{
return StoreProduct::where($this->searchWhere)->count();
}
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\store_product_attr_value;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\lists\ListsSearchInterface;
/**
* 商品属性值列表
* Class StoreProductAttrValueLists
* @package app\admin\listsstore_product_attr_value
*/
class StoreProductAttrValueLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/05/31 14:10
*/
public function setSearch(): array
{
return [
'=' => ['product_id'],
];
}
/**
* @notes 获取商品属性值列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/05/31 14:10
*/
public function lists(): array
{
return StoreProductAttrValue::where($this->searchWhere)
->field(['id', 'product_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取商品属性值数量
* @return int
* @author admin
* @date 2024/05/31 14:10
*/
public function count(): int
{
return StoreProductAttrValue::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace app\admin\logic\store_category;
use app\common\model\store_category\StoreCategory;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 商品分类逻辑
* Class StoreCategoryLogic
* @package app\admin\logic\store_category
*/
class StoreCategoryLogic extends BaseLogic
{
/**
* @notes 添加商品分类
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 11:33
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
StoreCategory::create([
'pid' => $params['pid'],
'name' => $params['name'],
'data' => $params['data'],
'pic' => $params['pic'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑商品分类
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 11:33
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
StoreCategory::where('id', $params['id'])->update([
'pid' => $params['pid'],
'name' => $params['name'],
'data' => $params['data'],
'pic' => $params['pic'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除商品分类
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 11:33
*/
public static function delete(array $params): bool
{
return StoreCategory::destroy($params['id']);
}
/**
* @notes 获取商品分类详情
* @param $params
* @return array
* @author admin
* @date 2024/05/31 11:33
*/
public static function detail($params): array
{
return StoreCategory::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -5,6 +5,8 @@ namespace app\admin\logic\store_product;
use app\common\model\store_product\StoreProduct;
use app\common\logic\BaseLogic;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use think\facade\Db;
@ -28,9 +30,33 @@ class StoreProductLogic extends BaseLogic
{
Db::startTrans();
try {
StoreProduct::create([
'store_name' => $params['store_name']
$data = [
'store_name' => $params['store_name'],
'image' => $params['image'],
'bar_code' => $params['bar_code'] ?? '',
'cate_id' => $params['cate_id'],
'unit' => $params['unit'],
'stock' => $params['stock'],
'cost' => $params['cost'],
'purchase' => $params['purchase'],
'rose' => $params['rose'],
];
$rose_price = bcmul($params['cost'], $params['rose'], 2);
$data['price'] = bcadd($params['cost'], $rose_price, 2);
$res = StoreProduct::create($data);
StoreProductAttrValue::create([
"bar_code" => $params["bar_code"] ?? '',
"image" => $params["image"] ?? '',
"cost" => $params['cost'],
"purchase" => $params['purchase'],
"unit" => $params["unit"],
"price" => $data['price'],
"stock" => $params['stock'],
"product_id" => $res['id'],
"unique" => setUnique($res['id'], '', 0),
'sales' => 0,
]);
StoreCategory::where('id', $params['cate_id'])->inc('three')->update();
Db::commit();
return true;
@ -52,7 +78,12 @@ class StoreProductLogic extends BaseLogic
public static function edit(array $params): bool
{
Db::startTrans();
$StoreProduct = StoreProduct::where('id', $params['id'])->find();
try {
if ($StoreProduct['cate_id'] != $params['cate_id']) {
StoreCategory::where('id', $params['cate_id'])->inc('three')->update();
StoreCategory::where('id', $StoreProduct['cate_id'])->dec('three')->update();
}
StoreProduct::where('id', $params['id'])->update([
'store_name' => $params['store_name']
]);
@ -91,4 +122,27 @@ class StoreProductLogic extends BaseLogic
{
return StoreProduct::findOrEmpty($params['id'])->toArray();
}
}
/**
* 更新商品分类
*/
public static function updateGoodsclass($id, $type = 0)
{
$pid = StoreCategory::where('id', $id)->value('pid');
if ($pid) {
$goodsclass = StoreCategory::where('id', $pid)->field('pid,children')->find();
if ($goodsclass) {
if (count($goodsclass['children']) >= 1) {
if (!in_array($id, $goodsclass['children'])) {
$arr = $goodsclass['children'];
array_push($arr, $id);
StoreCategory::where('id', $pid)->update(['children' => $arr]);
if ($goodsclass['pid'] != 0 && $type == 0) {
self::updateGoodsclass($pid, 1);
}
}
}
}
}
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\admin\logic\store_product_attr_value;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 商品属性值逻辑
* Class StoreProductAttrValueLogic
* @package app\admin\logic\store_product_attr_value
*/
class StoreProductAttrValueLogic extends BaseLogic
{
/**
* @notes 添加商品属性值
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 14:10
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
StoreProductAttrValue::create([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑商品属性值
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 14:10
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
StoreProductAttrValue::where('id', $params['id'])->update([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除商品属性值
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 14:10
*/
public static function delete(array $params): bool
{
return StoreProductAttrValue::destroy($params['id']);
}
/**
* @notes 获取商品属性值详情
* @param $params
* @return array
* @author admin
* @date 2024/05/31 14:10
*/
public static function detail($params): array
{
return StoreProductAttrValue::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace app\admin\validate\store_category;
use app\common\validate\BaseValidate;
/**
* 商品分类验证器
* Class StoreCategoryValidate
* @package app\admin\validate\store_category
*/
class StoreCategoryValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'pid' => 'require',
'name' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'pid' => '所属ID',
'name' => '分类名称',
];
/**
* @notes 添加场景
* @return StoreCategoryValidate
* @author admin
* @date 2024/05/31 11:33
*/
public function sceneAdd()
{
return $this->only(['pid','name']);
}
/**
* @notes 编辑场景
* @return StoreCategoryValidate
* @author admin
* @date 2024/05/31 11:33
*/
public function sceneEdit()
{
return $this->only(['id','pid','name']);
}
/**
* @notes 删除场景
* @return StoreCategoryValidate
* @author admin
* @date 2024/05/31 11:33
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return StoreCategoryValidate
* @author admin
* @date 2024/05/31 11:33
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\admin\validate\store_product_attr_value;
use app\common\validate\BaseValidate;
/**
* 商品属性值验证器
* Class StoreProductAttrValueValidate
* @package app\admin\validate\store_product_attr_value
*/
class StoreProductAttrValueValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return StoreProductAttrValueValidate
* @author admin
* @date 2024/05/31 14:10
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return StoreProductAttrValueValidate
* @author admin
* @date 2024/05/31 14:10
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return StoreProductAttrValueValidate
* @author admin
* @date 2024/05/31 14:10
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return StoreProductAttrValueValidate
* @author admin
* @date 2024/05/31 14:10
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -15,7 +15,8 @@ class AdminAccountSafeCache extends BaseCache
{
parent::__construct();
$ip = \request()->getLocalIp();
$this->key = $this->tagName . $ip;
// $this->key = $this->tagName . $ip;
$this->key = 'admin_' . $ip;
}
/**

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\store_category;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 商品分类模型
* Class StoreCategory
* @package app\common\model\store_category
*/
class StoreCategory extends BaseModel
{
use SoftDelete;
protected $name = 'store_category';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\store_product_attr_value;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 商品属性值模型
* Class StoreProductAttrValue
* @package app\common\model\store_product_attr_value
*/
class StoreProductAttrValue extends BaseModel
{
use SoftDelete;
protected $name = 'store_product_attr_value';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\store_product_unit;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 计量单位
* Class StoreProductUnit
* @package app\common\model\store_product_unit
*/
class StoreProductUnit extends BaseModel
{
use SoftDelete;
protected $name = 'store_product_unit';
protected $deleteTime = 'delete_time';
}

View File

@ -328,3 +328,17 @@ if (!function_exists('getNewOrderId')) {
return $orderId;
}
}
if (!function_exists('setUnique')) {
/**
* @notes 唯一值
* @param $type
* @return string
*/
function setUnique(int $id, $sku, int $type)
{
return substr(md5($sku . $id), 12, 11) . $type;
}
}