This commit is contained in:
mkm 2024-09-21 17:58:12 +08:00
parent 29b750b177
commit 3d37bdb594
4 changed files with 85 additions and 21 deletions

View File

@ -12,7 +12,11 @@ use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\lists\ListsExcelInterface; use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSortInterface; 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\store_product\StoreProduct;
use app\common\model\warehouse_product\WarehouseProduct;
/** /**
* 门店商品辅助表 * 门店商品辅助表
@ -32,7 +36,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
public function setSearch(): array public function setSearch(): array
{ {
return [ 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'], '%pipe_like%' => ['store_name_code' => 'store_name|bar_code'],
'%like%' => ['store_name'], '%like%' => ['store_name'],
]; ];
@ -82,6 +86,9 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
if ($where) { if ($where) {
$this->searchWhere[] = $where; $this->searchWhere[] = $where;
} }
// //$store_id=18;//酒店商贩
// $store_id=17;//一条龙门店
$this->searchWhere[] = ['store_id', '=', 17];
return StoreBranchProduct::where($this->searchWhere) 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']) ->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) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
@ -91,10 +98,28 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
->order($this->sortOrder) ->order($this->sortOrder)
->select() ->select()
->each(function ($item) use($export) { ->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['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
if($export==2){ 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); $item['total_price'] = bcmul($item['purchase'],$item['stock'],2);
} }
return $item; return $item;
@ -145,16 +170,18 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
$data = [ $data = [
'product_id' => '商品ID', 'product_id' => '商品ID',
'store_name' => '商品名称', 'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位', 'unit_name' => '单位',
'cate_name' => '分类', 'cate_name' => '分类',
'stock' => '库存', 'stock' => '库存',
'warehouse_product' => '铺货数量',
'sales' => '销量', 'sales' => '销量',
'rose' => '毛利率',
'purchase' => '供货价', 'purchase' => '供货价',
'cost' => '商户价', 'village' => '村长利润',
'vip_price' => '会员价', 'brigade' => '队长利润',
'price' => '零售价', 'user' => '厨师其他会员利润',
'bar_code' => '条码', 'store' => '门店利润',
'loss' => '损耗',
'total_price' => '价值', 'total_price' => '价值',
]; ];
return $data; return $data;

View File

@ -188,6 +188,8 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
'financial_pm_name' => '出入库', 'financial_pm_name' => '出入库',
'system_store_name' => '门店', 'system_store_name' => '门店',
'nums' => '数量', 'nums' => '数量',
'purchase' => '供货价',
'total_price' => '总价',
'create_time' => '操作时间', 'create_time' => '操作时间',
]; ];
} }

View File

@ -32,16 +32,16 @@ class StoreOrderCartInfoLogic extends BaseLogic
try { try {
$cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find(); $cart_info = StoreOrderCartInfo::where('oid', $params['oid'])->find();
if($cart_info['is_pay']==1){ // if($cart_info['is_pay']==1){
throw new BusinessException('已支付订单无法追加'); // throw new BusinessException('已支付订单无法追加');
} // }
$value=DictData::where('type_value','vendors_store')->column('value'); // $value=DictData::where('type_value','vendors_store')->column('value');
if(!$value){ // if(!$value){
throw new BusinessException('请先配置店铺'); // throw new BusinessException('请先配置店铺');
} // }
if(!in_array($cart_info['store_id'],$value)){ // if(!in_array($cart_info['store_id'],$value)){
throw new BusinessException('该订单不属于可设置店铺'); // throw new BusinessException('该订单不属于可设置店铺');
} // }
foreach($params['product_arr'] as $k=>$v){ foreach($params['product_arr'] as $k=>$v){
$find=StoreProduct::where('id',$v['product_id'])->find(); $find=StoreProduct::where('id',$v['product_id'])->find();
@ -77,16 +77,15 @@ class StoreOrderCartInfoLogic extends BaseLogic
$aa[$k]['total_price']=$cart_select['pay_price']; $aa[$k]['total_price']=$cart_select['pay_price'];
} }
(new StoreOrderCartInfo())->saveAll($aa); (new StoreOrderCartInfo())->saveAll($aa);
$total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price'); // $total_price = StoreOrderCartInfo::where('oid', $params['oid'])->sum('total_price');
$total_count = StoreOrderCartInfo::where('oid', $params['oid'])->count(); // $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(); Db::commit();
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Db::rollback(); Db::rollback();
d($e);
throw new BusinessException('编辑商品失败' . $e->getMessage()); throw new BusinessException('编辑商品失败' . $e->getMessage());
} }
} }

View File

@ -7,6 +7,7 @@ use app\common\logic\StoreFinanceFlowLogic;
use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\store_product\StoreProductLogic;
use app\admin\validate\tools\GenerateTableValidate; use app\admin\validate\tools\GenerateTableValidate;
use app\admin\logic\tools\GeneratorLogic; use app\admin\logic\tools\GeneratorLogic;
use app\api\logic\order\CartLogic;
use app\api\logic\order\OrderLogic as OrderOrderLogic; use app\api\logic\order\OrderLogic as OrderOrderLogic;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\logic\store_order\StoreOrderLogic; 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_branch_product\StoreBranchProduct;
use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_finance_flow\StoreFinanceFlow;
use app\common\model\store_order\StoreOrder; 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\store_product\StoreProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use app\common\model\user\User; use app\common\model\user\User;
@ -44,6 +46,40 @@ class IndexController extends BaseApiController
public function index() 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); return json(1);
$financeFlow = new StoreFinanceFlow(); $financeFlow = new StoreFinanceFlow();