You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/admin/controller/Goods.php

206 lines
5.8 KiB

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\controller;
9 months ago
use think\db\exception\DbException;
10 months ago
use think\response\Json;
9 months ago
use cores\exception\BaseException;
use app\store\model\Goods as GoodsModel;
/**
9 months ago
* 商品管理控制器
* Class Goods
* @package app\store\controller
*/
class Goods extends Controller
{
/**
9 months ago
* 商品列表
* @return Json
* @throws DbException
*/
9 months ago
public function list(): Json
{
// 获取列表记录
$model = new GoodsModel;
9 months ago
$params = $this->request->param();
$params['store_id'] = 0;
9 months ago
$list= $model->getAdminList($params);
9 months ago
return $this->renderSuccess(compact('list'));
}
/**
9 months ago
* 根据商品ID集获取列表记录
* @param array $goodsIds
* @return Json
*/
9 months ago
public function listByIds(array $goodsIds): Json
{
9 months ago
// 获取列表记录
$model = new GoodsModel;
$list = $model->getListByIds($goodsIds);
return $this->renderSuccess(compact('list'));
}
9 months ago
/**
* 商品详情(详细信息)
* @param int $goodsId
* @return Json
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function detail(int $goodsId): Json
{
// 获取商品详情
$model = new GoodsModel;
$goodsInfo = $model->getDetail($goodsId);
return $this->renderSuccess(compact('goodsInfo'));
}
/**
* 商品详情(基础信息)
* @param int $goodsId
* @return Json
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function basic(int $goodsId): Json
{
// 获取商品详情
$model = new GoodsModel;
$detail = $model->getBasic($goodsId);
return $this->renderSuccess(compact('detail'));
}
/**
* 添加商品
* @return Json
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function add(): Json
{
$model = new GoodsModel;
if ($model->add($this->postForm())) {
return $this->renderSuccess('添加成功');
}
9 months ago
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 商品编辑
* @param int $goodsId
* @return Json
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit(int $goodsId): Json
{
// 商品详情
$model = GoodsModel::detail($goodsId);
// 更新记录
8 months ago
if ($model->edit($this->postForm(), $model)) {
9 months ago
return $this->renderSuccess('更新成功');
10 months ago
}
9 months ago
return $this->renderError($model->getError() ?: '更新失败');
}
9 months ago
/**
* 修改商品状态(上下架)
* @param array $goodsIds 商品id集
* @param bool $state 为true表示上架
* @return Json
*/
8 months ago
public function state(array $goodsIds, int $is_pool): Json
9 months ago
{
$model = new GoodsModel;
8 months ago
if (!$model->setIsPool($goodsIds, $is_pool)) {
9 months ago
return $this->renderError($model->getError() ?: '操作失败');
}
return $this->renderSuccess('操作成功');
}
8 months ago
/**
* 修改商品状态(上下架)
* @param array $goodsIds 商品id集
* @param bool $state 为true表示上架
* @return Json
*/
8 months ago
public function sale(array $goodsIds, int $is_sale): Json
8 months ago
{
$model = new GoodsModel;
8 months ago
if (!$model->setIsSale($goodsIds, $is_sale)) {
8 months ago
return $this->renderError($model->getError() ?: '操作失败');
}
return $this->renderSuccess('操作成功');
}
8 months ago
8 months ago
/**
* 修改商品状态(上下架)
* @param array $goodsIds 商品id集
* @param bool $state 为true表示上架
* @return Json
*/
public function category(array $goodsIds, array $categoryIds): Json
{
$model = new GoodsModel;
8 months ago
foreach ($goodsIds as $key => $goodsId) {
\app\store\model\GoodsCategoryRel::updates($goodsId, $categoryIds);
}
return $this->renderSuccess('操作成功');
}
9 months ago
/**
* 删除商品
* @param array $goodsIds
* @return Json
*/
public function delete(array $goodsIds): Json
{
$model = new GoodsModel;
if (!$model->setDelete($goodsIds)) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
8 months ago
public function export(){
$model = new GoodsModel;
$params = $this->request->param();
$params['store_id'] = 0;
$list= $model->getAdminList($params);
return $this->renderSuccess(compact('list'));
}
public function addPrice(array $categoryIds, int $rate){
return $this->renderSuccess('加价成功');
}
}