commit
636d22f52b
@ -300,19 +300,26 @@ class WorkbenchController extends BaseAdminController
|
||||
*/
|
||||
public function total_warehouse_list()
|
||||
{
|
||||
$parmas=$this->request->get();
|
||||
$data =WarehouseLogic::total_warehouse_list($parmas,$parmas['type']??1);
|
||||
$parmas = $this->request->get();
|
||||
$data = WarehouseLogic::total_warehouse_list($parmas, $parmas['type'] ?? 1);
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 统计门店仓库总库存
|
||||
* @return array
|
||||
*/
|
||||
public function total_warehouse_product_list()
|
||||
{
|
||||
$parmas=$this->request->get();
|
||||
$data =WarehouseLogic::total_warehouse_product_list($parmas,$parmas['type']??1);
|
||||
$parmas = $this->request->get();
|
||||
$data = WarehouseLogic::total_warehouse_product_list($parmas, $parmas['type'] ?? 1);
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
public function negative_inventory()
|
||||
{
|
||||
$parmas = $this->request->get();
|
||||
$data = WarehouseLogic::negativeInventory($parmas);
|
||||
return $this->data($data);
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +70,8 @@ class StoreBranchProductController extends BaseAdminController
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
foreach ($params['data'] as $k => $v) {
|
||||
StoreProductLogic::stock($v);
|
||||
if (StoreProductLogic::hasError()) {
|
||||
return $this->fail(StoreProductLogic::getError());
|
||||
}
|
||||
}
|
||||
return $this->success('操作成功,等待门店确认', [], 1, 1);
|
||||
|
||||
return $this->fail('不能编辑');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,13 +13,14 @@ use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\lists\ListsSortInterface;
|
||||
|
||||
/**
|
||||
* 商品列表列表
|
||||
* Class StoreProductLists
|
||||
* @package app\admin\listsstore_product
|
||||
*/
|
||||
class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
|
||||
class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface,ListsSortInterface
|
||||
{
|
||||
|
||||
|
||||
@ -33,11 +34,26 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
{
|
||||
return [
|
||||
'=' => ['cate_id', 'is_show', 'bar_code'],
|
||||
'<=' => ['stock'],
|
||||
'%like%' => ['store_name'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置支持排序字段
|
||||
* @return string[]
|
||||
* @remark 格式: ['前端传过来的字段名' => '数据库中的字段名'];
|
||||
*/
|
||||
public function setSortFields(): array
|
||||
{
|
||||
return ['stock' => 'stock'];
|
||||
}
|
||||
/**
|
||||
* @notes 设置默认排序
|
||||
* @return string[]
|
||||
*/
|
||||
public function setDefaultOrder(): array
|
||||
{
|
||||
return [ 'p.id' => 'desc','p.stock' => 'desc',];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取商品列表列表
|
||||
@ -64,18 +80,17 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
$list = StoreProduct::where($this->searchWhere)
|
||||
->alias('p') // 为 StoreProduct 表设置别名
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
|
||||
->field('p.id, p.store_name, p.image,
|
||||
->field('p.id, p.store_name, p.image,p.stock as total_stock,
|
||||
(SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales,
|
||||
(SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock,
|
||||
(SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock,
|
||||
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.delete_time IS NULL) AS total_purchase,
|
||||
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount,
|
||||
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount')
|
||||
->order($this->sortOrder)
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
// 计算总库存
|
||||
$item->total_stock = $item->store_stock + $item->warehouse_stock;
|
||||
$item->total_completed_amount=$item->total_completed_amount??0;
|
||||
$item->warehouse_stock=$item->warehouse_stock??0;
|
||||
$item->total_outstanding_amount=$item->total_outstanding_amount??0;
|
||||
@ -139,6 +154,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
'purchase' => '采购价',
|
||||
'cost' => '商户',
|
||||
'price' => '零售',
|
||||
'total_price' => '总采购价',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
@ -8,14 +8,16 @@ use app\common\model\store_extract\StoreExtract;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAuth;
|
||||
use app\common\model\user_ship\UserShip;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
|
||||
/**
|
||||
* 门店提现列表
|
||||
* Class StoreExtractLists
|
||||
* @package app\admin\listsstore_extract
|
||||
*/
|
||||
class StoreExtractLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
class StoreExtractLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
|
||||
{
|
||||
|
||||
|
||||
@ -58,9 +60,11 @@ class StoreExtractLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
}else{
|
||||
$name=$find['mobile'];
|
||||
}
|
||||
$openid=UserAuth::where('user_id',$find['id'])->value('openid');
|
||||
$user_ship=UserShip::where('id',$find['user_ship'])->value('title');
|
||||
$item->nickname=$name.'('.$user_ship.')';
|
||||
// $item->id_card=$name.'('.$user_ship.')';
|
||||
$item->id_card=$find['id_card'];
|
||||
$item->openid=$openid;
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
@ -78,4 +82,33 @@ class StoreExtractLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
return StoreExtract::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 导出文件名
|
||||
* @return string
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setFileName(): string
|
||||
{
|
||||
return '提现列表';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 导出字段
|
||||
* @return string[]
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$data=[
|
||||
'nickname' => '名称',
|
||||
'extract_price' => '提现金额',
|
||||
'id_card' => '身份证',
|
||||
'openid' => 'openid',
|
||||
'create_time' => '时间',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -34,8 +34,6 @@ class WarehouseLogic extends BaseLogic
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
|
||||
|
||||
$topData[] = [
|
||||
'title' => '已结算金额',
|
||||
'desc' => '平台支付给供应商的金额',
|
||||
@ -50,46 +48,48 @@ class WarehouseLogic extends BaseLogic
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$store_stock_1 = StoreBranchProduct::where('stock', '>', 0)->sum('stock');
|
||||
$store_stock_2 = WarehouseProductStorege::where('nums', '>', 0)->sum('nums');
|
||||
$toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '总商品库存',
|
||||
'desc' => '平台统计商品总库存、含门店仓库',
|
||||
'total_money' => bcadd($store_stock_1, $store_stock_2, 2),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $toreProduct['stock'],
|
||||
'cash_title' => $toreProduct['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('nums', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '总仓库库存',
|
||||
'desc' => '平台统计仓库库存',
|
||||
'total_money' => WarehouseProductStorege::sum('nums'),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $warehouseProductStorege['nums'],
|
||||
'cash_title' => $warehouseProductStorege['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$warehouseProductStorege_1 = WarehouseProductStorege::where('nums', '>', 0)->where('warehouse_id', 1)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '海吉星仓库库存',
|
||||
'desc' => '平台统计海吉星仓库库存',
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id', 1)->sum('nums'),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $warehouseProductStorege_1['nums'],
|
||||
'cash_title' => $warehouseProductStorege_1['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$warehouseProductStorege_2 = WarehouseProductStorege::where('nums', '>', 0)->where('warehouse_id', 2)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '泸县集采集配库存',
|
||||
'desc' => '平台统计泸县集采集配库存',
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id', 2)->sum('nums'),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $warehouseProductStorege_2['nums'],
|
||||
'cash_title' => $warehouseProductStorege_2['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '总门店库存',
|
||||
'desc' => '平台统计门店库存',
|
||||
'total_money' => StoreBranchProduct::sum('stock'),
|
||||
'cash_title' => 1,
|
||||
|
||||
'total_money' => $storeBranchProduct['stock'],
|
||||
'cash_title' => $storeBranchProduct['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
@ -100,7 +100,6 @@ class WarehouseLogic extends BaseLogic
|
||||
$data['series'][$k]['desc'] = $v['desc'];
|
||||
$data['series'][$k]['total_value'] = $v['total_money'];
|
||||
$data['series'][$k]['total_money'] = $v['cash_title'] ?? '';
|
||||
|
||||
$data['series'][$k]['type'] = $v['type'];
|
||||
}
|
||||
return $data;
|
||||
@ -110,73 +109,104 @@ class WarehouseLogic extends BaseLogic
|
||||
* 统计门店仓库总库存
|
||||
* @return array
|
||||
*/
|
||||
public static function total_warehouse_list($parmas,$type=1) {
|
||||
if($type==1){
|
||||
$list=StoreBranchProduct::where('stock','>',0)->where('product_id',$parmas['product_id'])
|
||||
->select()->each(function ($item){
|
||||
$item->system_store = SystemStore::where('id',$item['store_id'])->value('name');
|
||||
$item->total_price = bcmul($item->purchase,$item->stock,2);
|
||||
});
|
||||
$count=StoreBranchProduct::where('stock','>',0)->where('product_id',$parmas['product_id'])
|
||||
->count();
|
||||
}else{
|
||||
$list=WarehouseProductStorege::where('nums','>',0)->where('product_id',$parmas['product_id'])->select()->each(function ($item){
|
||||
$item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name');
|
||||
$find = StoreProduct::where('id',$item['product_id'])->find();
|
||||
$item->store_name=$find['store_name'];
|
||||
$item->image=$find['image'];
|
||||
$item->purchase=$find['purchase'];
|
||||
if($find['purchase']>0 && $item->nums>0){
|
||||
$item->total_price = bcmul($find['purchase'],$item->nums,2);
|
||||
}else{
|
||||
public static function total_warehouse_list($parmas, $type = 1)
|
||||
{
|
||||
if ($type == 1) {
|
||||
$list = StoreBranchProduct::where('stock', '>', 0)->where('product_id', $parmas['product_id'])
|
||||
->select()->each(function ($item) {
|
||||
$item->system_store = SystemStore::where('id', $item['store_id'])->value('name');
|
||||
$item->total_price = bcmul($item->purchase, $item->stock, 2);
|
||||
});
|
||||
$count = StoreBranchProduct::where('stock', '>', 0)->where('product_id', $parmas['product_id'])
|
||||
->count();
|
||||
} else {
|
||||
$list = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $parmas['product_id'])->select()->each(function ($item) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name');
|
||||
$find = StoreProduct::where('id', $item['product_id'])->find();
|
||||
$item->store_name = $find['store_name'];
|
||||
$item->image = $find['image'];
|
||||
$item->purchase = $find['purchase'];
|
||||
if ($find['purchase'] > 0 && $item->nums > 0) {
|
||||
$item->total_price = bcmul($find['purchase'], $item->nums, 2);
|
||||
} else {
|
||||
$item->total_price = 0;
|
||||
}
|
||||
});
|
||||
$count=WarehouseProductStorege::where('nums','>',0)->where('product_id',$parmas['product_id'])->count();
|
||||
$count = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $parmas['product_id'])->count();
|
||||
}
|
||||
return ['lists'=>$list,'count'=>$count];
|
||||
return ['lists' => $list, 'count' => $count];
|
||||
}
|
||||
/**
|
||||
* 统计商品采购总价 已结未结
|
||||
* @return array
|
||||
*/
|
||||
public static function total_warehouse_product_list($parmas,$type=1) {
|
||||
$list=[];
|
||||
$count=0;
|
||||
if($type==1){
|
||||
public static function total_warehouse_product_list($parmas, $type = 1)
|
||||
{
|
||||
$list = [];
|
||||
$count = 0;
|
||||
if ($type == 1) {
|
||||
//总采购价
|
||||
$where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1]];
|
||||
$list=WarehouseProduct::where($where)->select()->each(function ($item){
|
||||
$item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name');
|
||||
$item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name');
|
||||
$find = StoreProduct::where('id',$item['product_id'])->find();
|
||||
$item->store_name=$find['store_name'];
|
||||
$item->image=$find['image'];
|
||||
$where = [['product_id', '=', $parmas['product_id']], ['nums', '>', 0], ['financial_pm', '=', 1]];
|
||||
$list = WarehouseProduct::where($where)->select()->each(function ($item) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name');
|
||||
$item->supplier_name = Supplier::where('id', $item['supplier_id'])->value('mer_name');
|
||||
$find = StoreProduct::where('id', $item['product_id'])->find();
|
||||
$item->store_name = $find['store_name'];
|
||||
$item->image = $find['image'];
|
||||
});
|
||||
$count=WarehouseProduct::where($where)->count();
|
||||
}elseif($type==2){
|
||||
//已结算采购价
|
||||
$where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1],['is_pay','=',1]];
|
||||
$list=WarehouseProduct::where($where)->select()->each(function ($item){
|
||||
$item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name');
|
||||
$item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name');
|
||||
$find = StoreProduct::where('id',$item['product_id'])->find();
|
||||
$item->store_name=$find['store_name'];
|
||||
$item->image=$find['image'];
|
||||
$count = WarehouseProduct::where($where)->count();
|
||||
} elseif ($type == 2) {
|
||||
//已结算采购价
|
||||
$where = [['product_id', '=', $parmas['product_id']], ['nums', '>', 0], ['financial_pm', '=', 1], ['is_pay', '=', 1]];
|
||||
$list = WarehouseProduct::where($where)->select()->each(function ($item) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name');
|
||||
$item->supplier_name = Supplier::where('id', $item['supplier_id'])->value('mer_name');
|
||||
$find = StoreProduct::where('id', $item['product_id'])->find();
|
||||
$item->store_name = $find['store_name'];
|
||||
$item->image = $find['image'];
|
||||
});
|
||||
$count=WarehouseProduct::where($where)->count();
|
||||
}elseif($type==3){
|
||||
//未结算采购价
|
||||
$where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1],['is_pay','=',0]];
|
||||
$list=WarehouseProduct::where($where)->select()->each(function ($item){
|
||||
$item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name');
|
||||
$item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name');
|
||||
$find = StoreProduct::where('id',$item['product_id'])->find();
|
||||
$item->store_name=$find['store_name'];
|
||||
$item->image=$find['image'];
|
||||
$count = WarehouseProduct::where($where)->count();
|
||||
} elseif ($type == 3) {
|
||||
//未结算采购价
|
||||
$where = [['product_id', '=', $parmas['product_id']], ['nums', '>', 0], ['financial_pm', '=', 1], ['is_pay', '=', 0]];
|
||||
$list = WarehouseProduct::where($where)->select()->each(function ($item) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name');
|
||||
$item->supplier_name = Supplier::where('id', $item['supplier_id'])->value('mer_name');
|
||||
$find = StoreProduct::where('id', $item['product_id'])->find();
|
||||
$item->store_name = $find['store_name'];
|
||||
$item->image = $find['image'];
|
||||
});
|
||||
$count=WarehouseProduct::where($where)->count();
|
||||
$count = WarehouseProduct::where($where)->count();
|
||||
}
|
||||
return ['lists'=>$list,'count'=>$count];
|
||||
return ['lists' => $list, 'count' => $count];
|
||||
}
|
||||
|
||||
/**
|
||||
* 负库存检测
|
||||
*/
|
||||
public static function negativeInventory($parmas)
|
||||
{
|
||||
if ($parmas['type'] == 1) {
|
||||
$list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray();
|
||||
$count = StoreProduct::where('stock', '<', 0)->count();
|
||||
} elseif ($parmas['type'] == 2) {
|
||||
$list = StoreBranchProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()
|
||||
->each(function ($item) {
|
||||
$item->remark = SystemStore::where('id', $item['store_id'])->value('name');
|
||||
})
|
||||
->toArray();
|
||||
$count = StoreBranchProduct::where('stock', '<', 0)->count();
|
||||
} elseif ($parmas['type'] == 3) {
|
||||
$list = WarehouseProductStorege::where('nums', '<', 0)->page($parmas['page_no'], 15)->select()
|
||||
->each(function ($item) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->find();
|
||||
$item->store_name = $find['store_name'];
|
||||
$item->image = $find['image'];
|
||||
$item->stock = $item['nums'];
|
||||
$item->remark = Warehouse::where('id', $item['warehouse_id'])->value('name');
|
||||
})->toArray();
|
||||
$count = WarehouseProductStorege::where('nums', '<', 0)->count();
|
||||
}
|
||||
return ['lists' => $list, 'count' => $count];
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace app\admin\logic\store_branch_product;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use think\facade\Db;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
@ -41,7 +42,6 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑门店商品
|
||||
* @param array $params
|
||||
@ -65,25 +65,7 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
'unit'=>$params['unit'],
|
||||
'status'=>$params['status'],
|
||||
];
|
||||
if(isset($params['cate_id'])){
|
||||
if ($StoreProduct['cate_id'] != $params['cate_id']) {
|
||||
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id']);
|
||||
}
|
||||
$data['cate_id']=$params['cate_id'];
|
||||
}else{
|
||||
if($params['status']!=$StoreProduct['status']){
|
||||
if($params['status']==1){
|
||||
StoreProductLogic::updateGoodsclass($StoreProduct['cate_id'],$StoreProduct['store_id']);
|
||||
}else{
|
||||
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id'],0);
|
||||
|
||||
}
|
||||
}
|
||||
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id']);
|
||||
|
||||
}
|
||||
StoreBranchProduct::where('id', $params['id'])->update($data);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -92,20 +74,38 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function store_product_cate_update($id,$cate_id,$store_id,$type=1)
|
||||
/**
|
||||
* @notes 库存管理
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/06/07 13:56
|
||||
*/
|
||||
public static function stock(array $params,$type=1): bool
|
||||
{
|
||||
$find=Db::name('store_product_cate')->where(['cate_id'=>$cate_id,'store_id'=>$store_id])->find();
|
||||
if($find &&$find['pid']>0){
|
||||
$two=Db::name('store_product_cate')->where(['cate_id'=>$find['pid'],'store_id'=>$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();
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($type==1){
|
||||
StoreBranchProduct::where('id', $params['id'])->inc('stock',$params['nums'])->update();
|
||||
$find=StoreProduct::where('id', $params['product_id'])->find();
|
||||
if($find){
|
||||
$stock=bcadd($find['stock'],$params['nums'],2);
|
||||
$find->update(['stock'=>$stock,'total_price'=>bcmul($stock,$find['purchase'],2)]);
|
||||
}
|
||||
}else{
|
||||
StoreBranchProduct::where('id', $params['id'])->dec('stock',$params['nums'])->update();
|
||||
$find=StoreProduct::where('id', $params['product_id'])->find();
|
||||
if($find){
|
||||
$stock=bcsub($find['stock'],$params['nums'],2);
|
||||
$find->update(['stock'=>$stock,'total_price'=>bcmul($stock,$find['purchase'],2)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($type==1){
|
||||
StoreProductLogic::updateGoodsclass($cate_id,$store_id);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -122,7 +122,8 @@ class StoreBranchProductLogic extends BaseLogic
|
||||
self::setError('商品库存不为0,无法删除');
|
||||
return false;
|
||||
}
|
||||
return StoreBranchProduct::destroy($params['id']);
|
||||
StoreBranchProduct::destroy($params['id']);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,9 +82,10 @@ class StoreProductLogic extends BaseLogic
|
||||
if ($params['is_store_all'] == 1) {
|
||||
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
||||
foreach ($store_arr as $store_id) {
|
||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||
if ($store_id != 5) {
|
||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||
}
|
||||
}
|
||||
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]);
|
||||
} else {
|
||||
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
||||
foreach ($params['store_arr'] as $key => $store_id) {
|
||||
@ -92,7 +93,6 @@ class StoreProductLogic extends BaseLogic
|
||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||
}
|
||||
}
|
||||
// Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]);
|
||||
}
|
||||
}
|
||||
if (getenv('STORE_ID')) {
|
||||
@ -267,90 +267,6 @@ class StoreProductLogic extends BaseLogic
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品分类
|
||||
*/
|
||||
public static function updateGoodsclass($cate_id, $store_id = 0, $type = 0)
|
||||
{
|
||||
$one = StoreCategory::where('id', $cate_id)->find();
|
||||
if ($one) {
|
||||
//查二级分类
|
||||
$two = StoreCategory::where('id', $one['pid'])->find();
|
||||
if ($two) {
|
||||
if ($two['pid'] != 0) {
|
||||
self::cate_update($cate_id, $two['id'], $store_id, 3);
|
||||
self::cate_update($two['id'], $two['pid'], $store_id, 2);
|
||||
self::cate_update($two['pid'], 0, $store_id, 1);
|
||||
} else {
|
||||
if ($one['pid'] == 0) {
|
||||
self::cate_update($one['id'], 0, $store_id, 1);
|
||||
} else {
|
||||
self::cate_update($one['id'], $one['pid'], $store_id, 2);
|
||||
self::cate_update($one['pid'], 0, $store_id, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function cate_update($cate_id = 0, $pid = 0, $store_id = 0, $level = 1)
|
||||
{
|
||||
$find = Db::name('store_product_cate')->where(['store_id' => $store_id, 'cate_id' => $cate_id, 'level' => $level])->find();
|
||||
if ($find) {
|
||||
Db::name('store_product_cate')->where('id', $find['id'])->inc('count', 1)->update();
|
||||
} else {
|
||||
Db::name('store_product_cate')->insert(['pid' => $pid, 'store_id' => $store_id, 'cate_id' => $cate_id, 'count' => 1, 'level' => $level, 'create_time' => time(), 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制商品到门店
|
||||
*/
|
||||
public static function copy($id, $store_id, $stock = 0)
|
||||
{
|
||||
$find = StoreProduct::where('id', $id)->findOrEmpty()->toArray();
|
||||
$store_find = StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->findOrEmpty()->toArray();
|
||||
if ($find && !$store_find) {
|
||||
$attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$dealCate = self::dealChangeCate($find['cate_id']);
|
||||
$product = [
|
||||
'product_id' => $find['id'],
|
||||
'image' => $find['image'],
|
||||
'store_name' => $find['store_name'],
|
||||
'store_info' => $find['store_info'],
|
||||
'keyword' => $find['keyword'],
|
||||
'bar_code' => $find['bar_code'],
|
||||
'cate_id' => $find['cate_id'],
|
||||
'top_cate_id' => $dealCate['top_cate_id'],
|
||||
'two_cate_id' => $dealCate['two_cate_id'],
|
||||
'price' => $find['price'],
|
||||
'unit' => $find['unit'],
|
||||
'store_id' => $store_id,
|
||||
'sales' => 0,
|
||||
'stock' => $stock,
|
||||
'manufacturer_information' => $find['manufacturer_information'] ?? '',
|
||||
];
|
||||
StoreBranchProduct::create($product);
|
||||
$arr = [
|
||||
'product_id' => $id,
|
||||
'store_id' => $store_id,
|
||||
'sales' => 0,
|
||||
'type' => 0,
|
||||
'bar_code' => $attr_value['bar_code']
|
||||
];
|
||||
StoreBranchProductAttrValue::create($arr);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除门店商品
|
||||
*/
|
||||
@ -370,83 +286,47 @@ class StoreProductLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加库存
|
||||
*/
|
||||
public static function stock($data)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find = StoreBranchProduct::where(['id' => $data['id']])->find();
|
||||
SystemStoreStorage::create([
|
||||
'product_id' => $find['product_id'],
|
||||
'store_id' => $find['store_id'],
|
||||
'nums' => $data['stock'],
|
||||
'admin_id' => Request()->adminId,
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**普通 */
|
||||
public static function ordinary($product_arr, $store_id, $admin_id, $find)
|
||||
{
|
||||
$store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray();
|
||||
if ($find && !$store_find) {
|
||||
//创建门店商品
|
||||
$attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$dealCate = self::dealChangeCate($find['cate_id']);
|
||||
$product = [
|
||||
'product_id' => $find['id'],
|
||||
'image' => $find['image'],
|
||||
'store_name' => $find['store_name'],
|
||||
'store_info' => $find['store_info'],
|
||||
'keyword' => $find['keyword'],
|
||||
'bar_code' => $find['bar_code'],
|
||||
'cate_id' => $find['cate_id'],
|
||||
'top_cate_id' => $dealCate['top_cate_id'],
|
||||
'two_cate_id' => $dealCate['two_cate_id'],
|
||||
'price' => $find['price'],
|
||||
// 'cost' => $find['cost'], //v1.0
|
||||
'cost' => $find['cost'],
|
||||
'purchase' => $find['purchase'],
|
||||
'vip_price' => $find['vip_price'],
|
||||
'manufacturer_information' => $find['manufacturer_information'] ?? '',
|
||||
'unit' => $find['unit'],
|
||||
'batch' => $find['batch'],
|
||||
'store_batch' => $find['store_batch'],
|
||||
'store_id' => $store_id,
|
||||
'sales' => 0,
|
||||
'product_type' => $find['product_type'],
|
||||
'stock' => 0,
|
||||
'rose' => $find['rose'],
|
||||
];
|
||||
$branch = StoreBranchProduct::create($product);
|
||||
$arr = [
|
||||
'product_id' => $product_arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'unique' => setUnique($branch['id'], '', 0),
|
||||
'sales' => 0,
|
||||
'type' => 0,
|
||||
'bar_code' => $attr_value['bar_code']
|
||||
];
|
||||
StoreBranchProductAttrValue::create($arr);
|
||||
Db::commit();
|
||||
return $branch;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$dealCate = self::dealChangeCate($find['cate_id']);
|
||||
$product = [
|
||||
'product_id' => $find['id'],
|
||||
'image' => $find['image'],
|
||||
'store_name' => $find['store_name'],
|
||||
'store_info' => $find['store_info'],
|
||||
'keyword' => $find['keyword'],
|
||||
'bar_code' => $find['bar_code'],
|
||||
'cate_id' => $find['cate_id'],
|
||||
'top_cate_id' => $dealCate['top_cate_id'],
|
||||
'two_cate_id' => $dealCate['two_cate_id'],
|
||||
'price' => $find['price'],
|
||||
// 'cost' => $find['cost'], //v1.0
|
||||
'cost' => $find['cost'],
|
||||
'purchase' => $find['purchase'],
|
||||
'vip_price' => $find['vip_price'],
|
||||
'manufacturer_information' => $find['manufacturer_information'] ?? '',
|
||||
'unit' => $find['unit'],
|
||||
'batch' => $find['batch'],
|
||||
'store_batch' => $find['store_batch'],
|
||||
'store_id' => $store_id,
|
||||
'sales' => 0,
|
||||
'product_type' => $find['product_type'],
|
||||
'stock' => 0,
|
||||
'rose' => $find['rose'],
|
||||
];
|
||||
$branch = StoreBranchProduct::create($product);
|
||||
$arr = [
|
||||
'product_id' => $product_arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'unique' => setUnique($branch['id'], '', 0),
|
||||
'sales' => 0,
|
||||
'type' => 0,
|
||||
'bar_code' => $find['bar_code']
|
||||
];
|
||||
StoreBranchProductAttrValue::create($arr);
|
||||
return $branch;
|
||||
}
|
||||
|
||||
/**兑换 */
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\admin\logic\warehouse_product;
|
||||
|
||||
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
@ -32,83 +33,94 @@ class WarehouseProductLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function add(array $params,$type=1)
|
||||
public static function add(array $params, $type = 1)
|
||||
{
|
||||
// Db::startTrans();
|
||||
try {
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
if ($params['financial_pm'] == 0) {
|
||||
$after_nums = $storege['nums'] - $params['nums'];
|
||||
// if ($after_nums < 0) {
|
||||
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||
// }
|
||||
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
|
||||
//门店加库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id',$params['store_id'])->find();
|
||||
if(!$storeBranchProduct){
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
if ($params['financial_pm'] == 0) {
|
||||
$after_nums = $storege['nums'] - $params['nums'];
|
||||
// if ($after_nums < 0) {
|
||||
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||
// }
|
||||
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
|
||||
//门店加库存
|
||||
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find();
|
||||
if (!$storeBranchProduct) {
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $params['product_id']], $params['store_id'], $params['admin_id'], $storeProduct);
|
||||
}
|
||||
if ($params['nums'] > 0 && $type == 1) {
|
||||
StoreBranchProductLogic::stock(['id' => $storeBranchProduct['id'], 'product_id' => $params['product_id'], 'nums' => $params['nums']]);
|
||||
}
|
||||
} else {
|
||||
$after_nums = $storege['nums'] + $params['nums'];
|
||||
if ($type == 1) {
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]);
|
||||
}
|
||||
$storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct);
|
||||
}
|
||||
if ($params['nums'] > 0&&$type==1) {
|
||||
StoreBranchProduct::where('id', $storeBranchProduct['id'])->inc('stock',$params['nums'])->update();
|
||||
}
|
||||
$before_nums = $storege['nums'];
|
||||
} else {
|
||||
$after_nums = $storege['nums'] + $params['nums'];
|
||||
if($type==1){
|
||||
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
|
||||
$after_nums = $params['nums'];
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
}
|
||||
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||
WarehouseProductStorege::create([
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'total_price'=>$total_price
|
||||
]);
|
||||
}
|
||||
$before_nums = $storege['nums'];
|
||||
} else {
|
||||
$after_nums=$params['nums'];
|
||||
WarehouseProductStorege::create([
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
]);
|
||||
}
|
||||
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||
'oid' => $params['oid'] ?? 0,
|
||||
'store_id' => $params['store_id'] ?? 0,
|
||||
'product_id' => $params['product_id'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
// 'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
// 'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'status' => 1,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
];
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$data['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res = WarehouseProduct::create($data);
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
// 'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
// 'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code'] ?? '',
|
||||
'status' => 1,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
];
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$data['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res = WarehouseProduct::create($data);
|
||||
|
||||
//更改采购订单状态
|
||||
if(isset($params['purchase_product_offer_id']) &&$params['purchase_product_offer_id']!=''){
|
||||
PurchaseProductOffer::where('id',$params['purchase_product_offer_id'])->update(['is_storage'=>1,'supplier_id'=>$params['supplier_id']??0]);
|
||||
}
|
||||
// self::enter($res['id'], $params['financial_pm']);
|
||||
// Db::commit();
|
||||
return $res;
|
||||
//更改采购订单状态
|
||||
if (isset($params['purchase_product_offer_id']) && $params['purchase_product_offer_id'] != '') {
|
||||
PurchaseProductOffer::where('id', $params['purchase_product_offer_id'])->update(['is_storage' => 1, 'supplier_id' => $params['supplier_id'] ?? 0]);
|
||||
}
|
||||
// self::enter($res['id'], $params['financial_pm']);
|
||||
// Db::commit();
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
// Db::rollback();
|
||||
|
@ -572,25 +572,22 @@ class PayNotifyLogic extends BaseLogic
|
||||
*/
|
||||
public static function afterPay($order, $transaction_id = 0)
|
||||
{
|
||||
$updateData = [];
|
||||
$updateDataTwo = [];
|
||||
StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]);
|
||||
$arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select();
|
||||
foreach ($arr as $k => $v) {
|
||||
$updateData[] = [
|
||||
'store_id' => $v['store_id'],
|
||||
'product_id' => $v['product_id'],
|
||||
'sales' => ['inc', $v['cart_num']],
|
||||
'stock' => ['dec', $v['cart_num']],
|
||||
];
|
||||
|
||||
$updateDataTwo[] = [
|
||||
'id' => $v['product_id'],
|
||||
'sales' => ['inc', $v['cart_num']]
|
||||
];
|
||||
$branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find();
|
||||
if($branchProduct){
|
||||
$stock=bcsub($branchProduct['stock'],$v['cart_num'],2);
|
||||
StoreProduct::where('id',$branchProduct['id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
|
||||
'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]);
|
||||
}
|
||||
$storeProduct=StoreProduct::where('id', $v['product_id'])->find();
|
||||
if($storeProduct){
|
||||
$stock=bcsub($storeProduct['stock'],$v['cart_num'],2);
|
||||
StoreProduct::where('id', $v['product_id'])->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2),
|
||||
'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]);
|
||||
}
|
||||
}
|
||||
(new StoreBranchProduct())->saveAll($updateData);
|
||||
(new StoreProduct())->saveAll($updateDataTwo);
|
||||
$financeLogic = new StoreFinanceFlowLogic();
|
||||
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||
$village_uid = 0;
|
||||
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 复制商品
|
||||
*/
|
||||
class CopyProductSend implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'copy-product';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
$store_arr=$data['store_arr'];
|
||||
$stock=$data['stock']??0;
|
||||
$admin_id=$data['admin_id']??0;
|
||||
foreach ($store_arr as $key => $id) {
|
||||
StoreProductLogic::copy($data['product_id'],$id,0);
|
||||
if($stock>0){
|
||||
$stocks=StoreProduct::where('id',$data['product_id'])->value('stock');
|
||||
if($stocks>=$stock){
|
||||
SystemStoreStorage::create(['product_id'=>$data['product_id'],'store_id'=>$id,'nums'=>$stock,'admin_id'=>$admin_id]);//设置库存
|
||||
StoreProduct::where('id',$data['product_id'])->dec('stock',$stock)->update();//减少库存
|
||||
}else{
|
||||
SystemStoreStorage::create(['product_id'=>$data['product_id'],'store_id'=>$id,'nums'=>$stock,'admin_id'=>$admin_id,'status'=>-1,'mark'=>'库存不足']);//设置库存
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
$package['max_attempts']=0;
|
||||
Log::error('复制商品失败product_id:'.$package['data']['product_id']);
|
||||
return $package;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user