更新货源增删改查

pull/1/head
Wayne 9 months ago
parent 57e22aa859
commit 255b72272f
  1. 41
      app/store/controller/goods/Source.php
  2. 32
      app/store/model/GoodsSource.php

@ -30,4 +30,45 @@ class Source extends Controller
$list = $modal->getList($this->request->param());
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() ?: '删除失败');
}
}

@ -39,4 +39,36 @@ class GoodsSource extends GoodSourceModel
'query' => request()->request()
]);
}
/**
* 新增记录
* @param array $data
* @return bool
*/
public function add(array $data): bool
{
// 新增记录
$data['store_id'] = self::$storeId;
return $this->save($data);
}
/**
* 更新记录
* @param array $data
* @return bool
*/
public function edit(array $data): bool
{
// 更新记录
return $this->save($data) !== false;
}
/**
* 删除记录
* @return bool
*/
public function setDelete(): bool
{
return $this->delete();
}
}

Loading…
Cancel
Save