From a0590484076b8d1de464d199c6a5bec499e96c80 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 12 Jun 2024 10:33:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=B7=BB=E5=8A=A0=E3=80=81=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4=E5=8F=8A=E8=AF=A6=E6=83=85=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductLogic.php | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 app/admin/logic/store_branch_product/StoreBranchProductLogic.php diff --git a/app/admin/logic/store_branch_product/StoreBranchProductLogic.php b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php new file mode 100644 index 000000000..81a64a4ef --- /dev/null +++ b/app/admin/logic/store_branch_product/StoreBranchProductLogic.php @@ -0,0 +1,117 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑门店商品 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/07 13:56 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $data=[ + 'store_name'=>$params['store_name'], + 'image'=>$params['image'], + 'price'=>$params['price'], + 'bar_code'=>$params['bar_code'], + 'unit'=>$params['unit'], + 'status'=>$params['status'], + ]; + if(isset($params['cate_id'])){ + $StoreProduct=StoreBranchProduct::where('id', $params['id'])->find(); + if ($StoreProduct['cate_id'] != $params['cate_id']) { + $find=Db::name('store_product_cate')->where(['cate_id'=>$params['cate_id'],'store_id'=>$StoreProduct['store_id']])->find(); + if($find['pid']>0){ + $two=Db::name('store_product_cate')->where(['cate_id'=>$find['pid'],'store_id'=>$StoreProduct['store_id']])->find(); + Db::name('store_product_cate')->where('id',$find['id'])->dec('count',1)->update(); + Db::name('store_product_cate')->where('id',$two['id'])->dec('count',1)->update(); + if($two['pid']>0){ + Db::name('store_product_cate')->where('id',$two['pid'])->dec('count',1)->update(); + } + } + Redis::send('store-storage', ['product_arr' => ['id' => $params['id'], 'stock' => 0], 'store_id' =>$StoreProduct['store_id'], 'admin_id' => Request()->adminId]); + + } + $data['cate_id']=$params['cate_id']; + } + StoreBranchProduct::where('id', $params['id'])->update($data); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除门店商品 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/07 13:56 + */ + public static function delete(array $params): bool + { + return StoreBranchProduct::destroy($params['id']); + } + + + /** + * @notes 获取门店商品详情 + * @param $params + * @return array + * @author admin + * @date 2024/06/07 13:56 + */ + public static function detail($params): array + { + return StoreBranchProduct::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file