更新转售商品详情

This commit is contained in:
yaooo 2023-08-18 10:41:37 +08:00
parent 865a6b872b
commit 879a69aa64

View File

@ -470,7 +470,7 @@ class Community extends BaseController
{
[$page, $limit] = $this->getPage();
$status = $this->request->param('status');
$queryBuilder = Db::name('community')->alias('c')->leftJoin('resale r','c.community_id = r.community_id')->where('c.uid', $this->request->uid());
$queryBuilder = Db::name('community')->alias('c')->leftJoin('resale r','c.community_id = r.community_id')->where('c.is_del', 0)->where('c.uid', $this->request->uid());
// 在售商品
if ($status == 1) {
$queryBuilder->where('c.status', 1)->where('c.is_show', 1)->where(function ($query) {
@ -595,4 +595,35 @@ class Community extends BaseController
return app('json')->fail($communityInfo);
}
/**
* 编辑转售商品
* @return mixed
*/
public function editResale($id)
{
$communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find();
if (!$communityInfo) {
app('json')->fail('转售商品不存在');
}
Db::startTrans();
try {
$list = Db::name('resale')->where('community_id', $id)->where('is_del', 0)->where('status', 0)->select();
foreach($list as $prod) {
Db::name('store_product')->where('product_id', $prod['product_id'])->inc('stock', $prod['number'])->update();
Db::name('store_product_attr_value')->where('product_id', $prod['product_id'])->where('unique', $prod['product_attr_unique'])->inc('stock', $prod['number'])->update();
}
Db::name('resale')->where('community_id', $id)->where('status', 0)->update(['is_del' => 1]);
Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->update(['is_del' => 1]);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
return app('json')->fail('编辑转售商品失败');
}
$data = $this->checkParams();
$this->checkUserAuth();
$data['uid'] = $this->request->uid();
$res = $this->repository->create($data);
return app('json')->success(['community_id' => $res]);
}
}