From 3d37bdb594734a3c81d98d262d39b791785808af Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 21 Sep 2024 17:58:12 +0800 Subject: [PATCH] 1 --- .../StoreBranchProductLists.php | 41 +++++++++++++++---- .../WarehouseProductLists.php | 2 + .../StoreOrderCartInfoLogic.php | 27 ++++++------ app/api/controller/IndexController.php | 36 ++++++++++++++++ 4 files changed, 85 insertions(+), 21 deletions(-) diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index 3feb38d73..f6a7fa958 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -12,7 +12,11 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\lists\ListsExcelInterface; use app\common\lists\ListsSortInterface; +use app\common\model\store_finance_flow\StoreFinanceFlow; +use app\common\model\store_order\StoreOrder; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\model\warehouse_product\WarehouseProduct; /** * 门店商品辅助表 @@ -32,7 +36,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI public function setSearch(): array { return [ - '=' => ['product_id', 'cate_id', 'store_id', 'status','bar_code'], + '=' => ['product_id', 'cate_id', 'status','bar_code'], '%pipe_like%' => ['store_name_code' => 'store_name|bar_code'], '%like%' => ['store_name'], ]; @@ -82,6 +86,9 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI if ($where) { $this->searchWhere[] = $where; } + // //$store_id=18;//酒店商贩 + // $store_id=17;//一条龙门店 + $this->searchWhere[] = ['store_id', '=', 17]; return StoreBranchProduct::where($this->searchWhere) ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price','bar_code', 'manufacturer_information','total_price']) ->when(!empty($this->adminInfo['store_id']), function ($query) { @@ -91,10 +98,28 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI ->order($this->sortOrder) ->select() ->each(function ($item) use($export) { - $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); + // $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); if($export==2){ + $rose = 0; + //零售-供货 + $rose_price = bcsub($item['price'], $item['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $item['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $arr=StoreOrderCartInfo::where('product_id', $item['product_id'])->where('store_id', $item['store_id'])->where('is_pay', 1)->where('create_time','>=','1726847999')->group('oid')->column('oid'); + $ids=StoreOrder::where('id','in',$arr)->where('paid',1)->where('status','in',[0,1,2,3])->where('refund_status',0)->column('id'); + $item['village']=StoreFinanceFlow::where('order_id','in',$ids)->where('financial_type',14)->where('financial_pm',1)->where('status','in',[0,1])->sum('number'); + $item['brigade']=StoreFinanceFlow::where('order_id','in',$ids)->where('financial_type',15)->where('financial_pm',1)->where('status','in',[0,1])->sum('number'); + $item['loss']=StoreFinanceFlow::where('order_id','in',$ids)->where('financial_type',16)->where('financial_pm',1)->where('status','in',[0,1])->sum('number'); + $item['user']=StoreFinanceFlow::where('order_id','in',$ids)->where('financial_type',12)->where('financial_pm',1)->where('status','in',[0,1])->sum('number'); + $item['store']=StoreFinanceFlow::where('order_id','in',$ids)->where('financial_type','in',[3,11])->where('status','in',[0,1])->where('financial_pm',1)->sum('number'); + + $item['warehouse_product']=WarehouseProduct::where('product_id',$item['product_id'])->where('store_id',$item['store_id'])->where('financial_pm',0)->sum('nums')??0; + $item['rose'] = $rose; $item['total_price'] = bcmul($item['purchase'],$item['stock'],2); } return $item; @@ -145,16 +170,18 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI $data = [ 'product_id' => '商品ID', 'store_name' => '商品名称', - 'store_info' => '规格', 'unit_name' => '单位', 'cate_name' => '分类', 'stock' => '库存', + 'warehouse_product' => '铺货数量', 'sales' => '销量', + 'rose' => '毛利率', 'purchase' => '供货价', - 'cost' => '商户价', - 'vip_price' => '会员价', - 'price' => '零售价', - 'bar_code' => '条码', + 'village' => '村长利润', + 'brigade' => '队长利润', + 'user' => '厨师其他会员利润', + 'store' => '门店利润', + 'loss' => '损耗', 'total_price' => '价值', ]; return $data; diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index db24996c7..3b9a989af 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -188,6 +188,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt 'financial_pm_name' => '出入库', 'system_store_name' => '门店', 'nums' => '数量', + 'purchase' => '供货价', + 'total_price' => '总价', 'create_time' => '操作时间', ]; } diff --git a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php index 711996c56..365b23747 100644 --- a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -32,16 +32,16 @@ class StoreOrderCartInfoLogic extends BaseLogic try { $cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find(); - if($cart_info['is_pay']==1){ - throw new BusinessException('已支付订单无法追加'); - } - $value=DictData::where('type_value','vendors_store')->column('value'); - if(!$value){ - throw new BusinessException('请先配置店铺'); - } - if(!in_array($cart_info['store_id'],$value)){ - throw new BusinessException('该订单不属于可设置店铺'); - } + // if($cart_info['is_pay']==1){ + // throw new BusinessException('已支付订单无法追加'); + // } + // $value=DictData::where('type_value','vendors_store')->column('value'); + // if(!$value){ + // throw new BusinessException('请先配置店铺'); + // } + // if(!in_array($cart_info['store_id'],$value)){ + // throw new BusinessException('该订单不属于可设置店铺'); + // } foreach($params['product_arr'] as $k=>$v){ $find=StoreProduct::where('id',$v['product_id'])->find(); @@ -77,16 +77,15 @@ class StoreOrderCartInfoLogic extends BaseLogic $aa[$k]['total_price']=$cart_select['pay_price']; } (new StoreOrderCartInfo())->saveAll($aa); - $total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price'); - $total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count(); + // $total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price'); + // $total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count(); - StoreOrder::where('id', $params['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); + // StoreOrder::where('id', $params['oid'])->update(['total_price' => $total_price, 'pay_price' => $total_price, 'cost' => $total_price, 'total_num' => $total_count]); Db::commit(); return true; } catch (\Throwable $e) { Db::rollback(); - d($e); throw new BusinessException('编辑商品失败' . $e->getMessage()); } } diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 4021947d1..e1aba6664 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -7,6 +7,7 @@ use app\common\logic\StoreFinanceFlowLogic; use app\admin\logic\store_product\StoreProductLogic; use app\admin\validate\tools\GenerateTableValidate; use app\admin\logic\tools\GeneratorLogic; +use app\api\logic\order\CartLogic; use app\api\logic\order\OrderLogic as OrderOrderLogic; use app\common\logic\PayNotifyLogic; use app\common\logic\store_order\StoreOrderLogic; @@ -14,6 +15,7 @@ use app\common\model\Config as ModelConfig; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\system_store\SystemStore; use app\common\model\user\User; @@ -44,6 +46,40 @@ class IndexController extends BaseApiController public function index() { + // $product_arr=[ + // ['product_id'=>1166,'stock'=>17.2], + // ['product_id'=>374,'stock'=>29.6], + // ['product_id'=>823,'stock'=>20], + // ]; + // $user_id=0; + // //$store_id=18;//酒店商贩 + // $store_id=17;//一条龙门店 + // $oid=1390; + // foreach ($product_arr as $k => $v) { + // $v['uid'] = $user_id; + // $v['store_id'] = $store_id; + // $v['cart_num'] = $v['stock']; + // $res = CartLogic::add($v); + // $cartId[] = $res['id']; + // } + // if($user_id > 0){ + // $user = User::where('id', $user_id)->find(); + // }else{ + // $user=null; + // } + + // $orderInfo = OrderOrderLogic::cartIdByOrderInfo($cartId, null, $user, ['store_id' => $store_id,'source'=>2]); + // $goods_list = $orderInfo['cart_list']; + + + // foreach ($goods_list as $k => $v) { + // $goods_list[$k]['oid'] = $oid; + // $goods_list[$k]['uid'] = $user_id; + // $goods_list[$k]['cart_id'] = implode(',', $cartId); + // $goods_list[$k]['delivery_id'] = $store_id; //商家id + // } + // $a=(new StoreOrderCartInfo())->saveAll($goods_list); + // d($a); return json(1); $financeFlow = new StoreFinanceFlow();