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/Source.php

79 lines
1.8 KiB

9 months ago
<?php
declare(strict_types=1);
namespace app\admin\controller\goods;
use app\store\model\User;
use think\response\Json;
use app\admin\controller\Controller;
use app\store\model\GoodsSource as GoodsSourceModel;
// yoshop_goods_source
/**
* 商品货源控制器
* Class Source
* @package app\store\controller
*/
class Source extends Controller
{
/**
* 商品货源列表
* @param int $goodsId 商品ID
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function list(): Json
{
$modal = new GoodsSourceModel;
$list = $modal->getList($this->request->param());
$list->each(function ($v, $k){
$v['nickname'] = User::get($v['user_id'])->nick_name ?? '';
});
return $this->renderSuccess(compact('list'));
}
/**
* 货源新增
* return Json
*/
public function add(): Json
{
$modal = new GoodsSourceModel;
if ($modal->add($this->postForm())) {
return $this->renderSuccess('添加成功');
}
return $this->renderError($modal->getError() ?: '添加失败');
}
/**
* 货源编辑
* @param int $sourceId
* @return Json
*/
public function edit(int $sourceId): Json
{
$modal = GoodsSourceModel::detail($sourceId);
if ($modal->edit($this->postForm())) {
return $this->renderSuccess('更新成功');
}
return $this->renderError($modal->getError() ?: '更新失败');
}
/**
* 货源删除
* @param int $sourceId
* @return Json
*/
public function delete(int $sourceId): Json
{
$modal = GoodsSourceModel::detail($sourceId);
if ($modal->setDelete()) {
return $this->renderSuccess('删除成功');
}
return $this->renderError($modal->getError() ?: '删除失败');
}
}