1.提交缺失的东西

This commit is contained in:
2025-05-18 17:17:10 +08:00
parent 49beb4ee65
commit 6a2f35fa31
5 changed files with 506 additions and 2 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\GoodsLists;
use app\adminapi\logic\GoodsLogic;
use app\adminapi\validate\GoodsValidate;
/**
* Goods控制器
* Class GoodsController
* @package app\adminapi\controller
*/
class GoodsController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function lists()
{
return $this->dataLists(new GoodsLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function add()
{
$params = (new GoodsValidate())->post()->goCheck('add');
$result = GoodsLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(GoodsLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function edit()
{
$params = (new GoodsValidate())->post()->goCheck('edit');
$result = GoodsLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(GoodsLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function delete()
{
$params = (new GoodsValidate())->post()->goCheck('delete');
GoodsLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function detail()
{
$params = (new GoodsValidate())->goCheck('detail');
$result = GoodsLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\Goods;
use app\common\lists\ListsSearchInterface;
/**
* Goods列表
* Class GoodsLists
* @package app\adminapi\lists
*/
class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function setSearch(): array
{
return [
'=' => ['name', 'code', 'first_category_id', 'second_category_id', 'third_category_id', 'brand_id', 'supplier_id', 'status', 'image', 'video', 'poster', 'remark', 'content', 'sort', 'sales_sum', 'virtual_sales_sum', 'click_count', 'virtual_click', 'spec_type', 'max_price', 'min_price', 'market_price', 'stock', 'stock_warn', 'is_show_stock', 'free_shipping_type', 'free_shipping', 'free_shipping_template_id', 'is_commission', 'first_ratio', 'second_ratio', 'three_ratio', 'is_share_bouns', 'region_ratio', 'shareholder_ratio', 'is_new', 'is_best', 'is_like', 'is_team', 'is_integral', 'is_member', 'give_integral_type', 'give_integral', 'del', 'is_express', 'is_selffetch'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function lists(): array
{
return Goods::where($this->searchWhere)
->field(['id', 'name', 'code', 'first_category_id', 'second_category_id', 'third_category_id', 'brand_id', 'supplier_id', 'status', 'image', 'video', 'poster', 'remark', 'content', 'sort', 'sales_sum', 'virtual_sales_sum', 'click_count', 'virtual_click', 'spec_type', 'max_price', 'min_price', 'market_price', 'stock', 'stock_warn', 'is_show_stock', 'free_shipping_type', 'free_shipping', 'free_shipping_template_id', 'is_commission', 'first_ratio', 'second_ratio', 'three_ratio', 'is_share_bouns', 'region_ratio', 'shareholder_ratio', 'is_new', 'is_best', 'is_like', 'is_team', 'is_integral', 'is_member', 'give_integral_type', 'give_integral', 'del', 'is_express', 'is_selffetch'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function count(): int
{
return Goods::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,196 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\model\Goods;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* Goods逻辑
* Class GoodsLogic
* @package app\adminapi\logic
*/
class GoodsLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2025/05/08 15:34
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Goods::create([
'name' => $params['name'],
'code' => $params['code'],
'first_category_id' => $params['first_category_id'],
'second_category_id' => $params['second_category_id'],
'third_category_id' => $params['third_category_id'],
'brand_id' => $params['brand_id'],
'supplier_id' => $params['supplier_id'],
'status' => $params['status'],
'image' => $params['image'],
'video' => $params['video'],
'poster' => $params['poster'],
'remark' => $params['remark'],
'content' => $params['content'],
'sort' => $params['sort'],
'sales_sum' => $params['sales_sum'],
'virtual_sales_sum' => $params['virtual_sales_sum'],
'click_count' => $params['click_count'],
'virtual_click' => $params['virtual_click'],
'spec_type' => $params['spec_type'],
'max_price' => $params['max_price'],
'min_price' => $params['min_price'],
'market_price' => $params['market_price'],
'stock' => $params['stock'],
'stock_warn' => $params['stock_warn'],
'is_show_stock' => $params['is_show_stock'],
'free_shipping_type' => $params['free_shipping_type'],
'free_shipping' => $params['free_shipping'],
'free_shipping_template_id' => $params['free_shipping_template_id'],
'is_commission' => $params['is_commission'],
'first_ratio' => $params['first_ratio'],
'second_ratio' => $params['second_ratio'],
'three_ratio' => $params['three_ratio'],
'is_share_bouns' => $params['is_share_bouns'],
'region_ratio' => $params['region_ratio'],
'shareholder_ratio' => $params['shareholder_ratio'],
'is_new' => $params['is_new'],
'is_best' => $params['is_best'],
'is_like' => $params['is_like'],
'is_team' => $params['is_team'],
'is_integral' => $params['is_integral'],
'is_member' => $params['is_member'],
'give_integral_type' => $params['give_integral_type'],
'give_integral' => $params['give_integral'],
'del' => $params['del'],
'is_express' => $params['is_express'],
'is_selffetch' => $params['is_selffetch']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2025/05/08 15:34
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Goods::where('id', $params['id'])->update([
'name' => $params['name'],
'code' => $params['code'],
'first_category_id' => $params['first_category_id'],
'second_category_id' => $params['second_category_id'],
'third_category_id' => $params['third_category_id'],
'brand_id' => $params['brand_id'],
'supplier_id' => $params['supplier_id'],
'status' => $params['status'],
'image' => $params['image'],
'video' => $params['video'],
'poster' => $params['poster'],
'remark' => $params['remark'],
'content' => $params['content'],
'sort' => $params['sort'],
'sales_sum' => $params['sales_sum'],
'virtual_sales_sum' => $params['virtual_sales_sum'],
'click_count' => $params['click_count'],
'virtual_click' => $params['virtual_click'],
'spec_type' => $params['spec_type'],
'max_price' => $params['max_price'],
'min_price' => $params['min_price'],
'market_price' => $params['market_price'],
'stock' => $params['stock'],
'stock_warn' => $params['stock_warn'],
'is_show_stock' => $params['is_show_stock'],
'free_shipping_type' => $params['free_shipping_type'],
'free_shipping' => $params['free_shipping'],
'free_shipping_template_id' => $params['free_shipping_template_id'],
'is_commission' => $params['is_commission'],
'first_ratio' => $params['first_ratio'],
'second_ratio' => $params['second_ratio'],
'three_ratio' => $params['three_ratio'],
'is_share_bouns' => $params['is_share_bouns'],
'region_ratio' => $params['region_ratio'],
'shareholder_ratio' => $params['shareholder_ratio'],
'is_new' => $params['is_new'],
'is_best' => $params['is_best'],
'is_like' => $params['is_like'],
'is_team' => $params['is_team'],
'is_integral' => $params['is_integral'],
'is_member' => $params['is_member'],
'give_integral_type' => $params['give_integral_type'],
'give_integral' => $params['give_integral'],
'del' => $params['del'],
'is_express' => $params['is_express'],
'is_selffetch' => $params['is_selffetch']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2025/05/08 15:34
*/
public static function delete(array $params): bool
{
return Goods::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2025/05/08 15:34
*/
public static function detail($params): array
{
return Goods::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,122 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* Goods验证器
* Class GoodsValidate
* @package app\adminapi\validate
*/
class GoodsValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'name' => 'require',
'first_category_id' => 'require',
'second_category_id' => 'require',
'third_category_id' => 'require',
'status' => 'require',
'image' => 'require',
'is_show_stock' => 'require',
'free_shipping_type' => 'require',
'is_commission' => 'require',
'is_share_bouns' => 'require',
'is_team' => 'require',
'is_integral' => 'require',
'is_member' => 'require',
'give_integral_type' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'name' => '商品名称',
'first_category_id' => '一级分类id',
'second_category_id' => '二级分类id',
'third_category_id' => '三级分类id',
'status' => '商品状态:-1-回收站0-下架1-上架',
'image' => '商品主图',
'is_show_stock' => '是否显示库存1-是0-否',
'free_shipping_type' => '运费类型1-包邮2-统一运费3-运费模板',
'is_commission' => '分销佣金1-开启0-不开启',
'is_share_bouns' => '区域股东分红1-开启0-不开启',
'is_team' => '是否开启拼团[0=否, 1=是]',
'is_integral' => '积分抵扣1-开启0-不开启',
'is_member' => '会员价1-开启0-不开启',
'give_integral_type' => '赠送积分类型0-不赠送1-赠送固定积分2-按比例赠送积分',
];
/**
* @notes 添加场景
* @return GoodsValidate
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function sceneAdd()
{
return $this->only(['name','first_category_id','second_category_id','third_category_id','status','image','is_show_stock','free_shipping_type','is_commission','is_share_bouns','is_team','is_integral','is_member','give_integral_type']);
}
/**
* @notes 编辑场景
* @return GoodsValidate
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function sceneEdit()
{
return $this->only(['id','name','first_category_id','second_category_id','third_category_id','status','image','is_show_stock','free_shipping_type','is_commission','is_share_bouns','is_team','is_integral','is_member','give_integral_type']);
}
/**
* @notes 删除场景
* @return GoodsValidate
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return GoodsValidate
* @author likeadmin
* @date 2025/05/08 15:34
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -19,11 +19,12 @@
namespace app\common\model;
use app\common\model\BaseModel;
use think\Model;
class Goods extends Model
class Goods extends BaseModel
{
protected $name = 'goods';
const STATUS_RECYCLE = -1; // 回收站
const STATUS_STORAGE = 0; // 下架(仓库中)
const STATUS_SELL = 1; // 上架 (销售中)