修改商品添加
This commit is contained in:
parent
65a0257739
commit
524d47423c
@ -26,11 +26,24 @@ class LocalStoreGoods extends Api
|
||||
}
|
||||
|
||||
// 商家添加商品
|
||||
public function addGoods()
|
||||
public function saveGoods()
|
||||
{
|
||||
$form = $this->request->post();
|
||||
(new LocalStoreGoodsValidate())->goCheck();
|
||||
$result = LocalStoreGoodsLogic::addGoods($form, $this->user_id);
|
||||
$result = LocalStoreGoodsLogic::saveGoods($form, $this->user_id);
|
||||
if ($result === false) {
|
||||
$error = LocalStoreGoodsLogic::getError() ?: '提交失败';
|
||||
return JsonServer::error($error);
|
||||
}
|
||||
return JsonServer::success('提交成功', [], 1, 1);
|
||||
}
|
||||
|
||||
// 商家修改商品
|
||||
public function editGoods()
|
||||
{
|
||||
$form = $this->request->post();
|
||||
(new LocalStoreGoodsValidate())->goCheck();
|
||||
$result = LocalStoreGoodsLogic::editGoods($form, $this->user_id);
|
||||
if ($result === false) {
|
||||
$error = LocalStoreGoodsLogic::getError() ?: '提交失败';
|
||||
return JsonServer::error($error);
|
||||
|
||||
@ -51,8 +51,9 @@ class LocalStoreGoodsLogic extends Logic
|
||||
}
|
||||
|
||||
// 添加商品
|
||||
public static function addGoods($form, $user_id)
|
||||
public static function saveGoods($form, $user_id)
|
||||
{
|
||||
dump($form);die;
|
||||
try {
|
||||
$form['user_id'] = $user_id;
|
||||
$form['create_time'] = time();
|
||||
@ -77,6 +78,37 @@ class LocalStoreGoodsLogic extends Logic
|
||||
}
|
||||
}
|
||||
|
||||
public static function editGoods($form, $user_id)
|
||||
{
|
||||
try {
|
||||
$form['user_id'] = $user_id;
|
||||
$form['update'] = time();
|
||||
$form['state'] = 1;
|
||||
|
||||
$pic = $form['url'];
|
||||
unset($form['url']);
|
||||
$id = LocalStoreGoods::update([
|
||||
'title' => $form['title'],
|
||||
'price' => $form['price'],
|
||||
'desc' => $form['desc'],
|
||||
'details' => $form['details'],
|
||||
]);
|
||||
|
||||
$data = [];
|
||||
foreach ($pic as $k => &$v) {
|
||||
$data[$k]['lsg_id'] = $id;
|
||||
$data[$k]['url'] = basename($v);
|
||||
}
|
||||
|
||||
LocalStoreGoodsPic::insertAll($data);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取商品详情
|
||||
public static function details($get)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user