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 00000000..81a64a4e --- /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