diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index a8a9aa90..29f8ff80 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -9,13 +9,17 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\lists\ListsExcelInterface; +use app\common\model\store_category\StoreCategory; +use app\common\model\store_order\StoreOrder; +use app\common\model\store_product_unit\StoreProductUnit; /** * 订单购物详情列表 * Class StoreOrderCartInfoLists * @package app\admin\store_order_cart_info */ -class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface +class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface { @@ -45,15 +49,19 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function lists(): array { return StoreOrderCartInfo::where($this->searchWhere) - ->field('cart_info,product_id,store_id')->limit($this->limitOffset, $this->limitLength) + ->field('cart_info,product_id,store_id,cart_num,price,total_price')->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { - $find=StoreProduct::where('id',$item['product_id'])->field('image,store_name,store_info')->find(); + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); if($find){ $item['image']=$find['image'];//商品图片 $item['store_name']=$find['store_name'];//商品名称 $item['store_info']=$find['store_info'];//商品规格 + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; + $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??""; }else{ $item['image']='';//商品图片 + $item['unit_name']='';//商品图片 + $item['cate_name']='';//商品图片 $item['store_name']='';//商品名称 $item['store_info']='';//商品规格-(数据库叫商品简介) } @@ -72,5 +80,41 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI public function count(): int { return StoreOrderCartInfo::where($this->searchWhere)->count(); + } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + if($this->request->get('oid')){ + $order_id=StoreOrder::where('id',$this->request->get('oid'))->value('order_id'); + return '订单'.$order_id.'商品详情'; + } + return '订单商品详情'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data=[ + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + ]; + return $data; } } diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 338ab151..cb942673 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -10,6 +10,7 @@ use app\common\lists\ListsSearchInterface; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; +use app\common\model\warehouse_product_storege\WarehouseProductStorege; /** * 商品列表列表 @@ -64,6 +65,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa ->order(['id' => 'desc']) ->select()->each(function ($item) { $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); + $item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); return $item; })?->toArray(); diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index d5ca3b83..ea5b3477 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -2,17 +2,20 @@ namespace app\admin\logic\store_product; - +use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\store_product\StoreProduct; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue; +use app\common\model\store_branch_product_exchange\StoreBranchProductExchange; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_cate\StoreProductCate; use app\common\model\system_store\SystemStore; use app\common\model\system_store_storage\SystemStoreStorage; +use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\Request; +use Illuminate\Support\Facades\Log; use think\facade\Db; use Webman\RedisQueue\Redis; @@ -392,4 +395,162 @@ class StoreProductLogic extends BaseLogic return false; } } + + + /**普通 */ + public static function ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id){ + $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_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); + if ($product_arr['stock'] > 0) { + self::storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); + return false; + } + } else { + //更新门店库存 + Db::startTrans(); + try { + if ($product_arr['stock'] > 0) { + self::storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); + return false; + } + } + } + + /**兑换 */ + public static function exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id){ + $store_find = StoreBranchProductExchange::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); + if ($find && !$store_find) { + Db::startTrans(); + try { + $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'], + 'price' => $find['price'], + 'cost' => $find['cost'], + 'purchase' => $find['purchase'], + 'vip_price' => $find['vip_price'], + 'unit' => $find['unit'], + 'store_id' => $store_id, + 'sales' => 0, + 'stock' => 0, + ]; + StoreBranchProductExchange::create($product); + if ($product_arr['stock'] > 0) { + self::storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); + return false; + } + } else { + Db::startTrans(); + try { + if ($product_arr['stock'] > 0) { + self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); + return false; + } + } + } + public static function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0) + { + $storage = [ + 'product_id' => $product_arr['id'], + 'store_id' => $store_id, + 'nums' => $product_arr['stock'], + 'admin_id' => $admin_id, + 'type' => $stock_type, + 'warehouse_id'=>$warehouse_id, + ]; + $data=[ + 'warehouse_id'=>$warehouse_id, + 'product_id' => $product_arr['id'], + 'store_id' => $store_id, + 'financial_pm' => 0, + 'batch' => $product_arr['batch']??1, + 'nums' => $product_arr['stock'], + 'status' =>1, + 'admin_id' =>$admin_id, + ]; + $warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find(); + if ($warehouse) { + if($warehouse['nums']< $product_arr['stock']){ + $storage['status'] = -1; + $data['status'] = -1; + $storage['mark'] = '库存不足,分库存为:' .$warehouse['nums']; + $data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock']; + } + $res=WarehouseProductLogic::add($data); + $storage['outbound_id']=$res['id']??0; + SystemStoreStorage::create($storage); + } else { + $res=WarehouseProductLogic::add($data); + $storage['outbound_id']=$res['id']??0; + SystemStoreStorage::create($storage); + } + } } diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 3b7014ec..9e95ec0a 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -78,8 +78,6 @@ class SystemStoreStorageLogic extends BaseLogic 'mark' => '', ]); StoreProduct::where('id', $params['product_id'])->inc('stock',bcsub($find['nums'] ,$params['nums'],2))->update(); - WarehouseProductStorege::where('id',$productStorege['id'])->inc('stock',bcsub($find['nums'] ,$params['nums'],2))->update(); - WarehouseProduct::where('id',$find['outbound_id'])->update(['nums',$params['nums']]); Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 1a79b54e..23b20895 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -7,6 +7,7 @@ use app\common\model\warehouse_product\WarehouseProduct; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product\StoreProduct; +use app\common\model\system_store_storage\SystemStoreStorage; use app\common\model\warehouse_product_storege\WarehouseProductStorege; use support\Log; use think\facade\Db; @@ -57,7 +58,7 @@ class WarehouseProductLogic extends BaseLogic $res = WarehouseProduct::create($data); self::enter($res['id'], $params['financial_pm']); Db::commit(); - return true; + return $res; } catch (\Exception $e) { Db::rollback(); Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine()); @@ -122,12 +123,12 @@ class WarehouseProductLogic extends BaseLogic $find->save(); $storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find(); - if ($financial_pm == 0) { - StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update(); - } else { - StoreProduct::where('id', $find['product_id'])->inc('stock', $find['nums'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]); - StoreBranchProduct::where('product_id', $find['product_id'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]); - } + // if ($financial_pm == 0) { + // StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update(); + // } else { + // StoreProduct::where('id', $find['product_id'])->inc('stock', $find['nums'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]); + // StoreBranchProduct::where('product_id', $find['product_id'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]); + // } if ($storege) { if ($financial_pm == 0) { @@ -156,9 +157,21 @@ class WarehouseProductLogic extends BaseLogic */ public static function delete(array $params): bool { - return WarehouseProduct::destroy($params['id']); - } + $res=WarehouseProduct::where('id',$params['id'])->find(); + if($res){ + $res->delete(); + if($res['financial_pm']==1){ + WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->dec('nums',$res['nums'])->update(); + }elseif($res['financial_pm']==0){ + WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->inc('nums',$res['nums'])->update(); + SystemStoreStorage::where(['outbound_id'=>$res['id']])->delete(); + } + + return true; + } + return false; + } /** * @notes 获取商品仓储信息详情 diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php index 21b9d715..e9dd5bed 100644 --- a/app/queue/redis/StoreStorageSend.php +++ b/app/queue/redis/StoreStorageSend.php @@ -36,166 +36,12 @@ class StoreStorageSend implements Consumer $warehouse_id = $data['warehouse_id']??0; $find = StoreProduct::where('id', $product_arr['id'])->findOrEmpty()->toArray(); if($stock_type == 1){ - $this->ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id); + StoreProductLogic::ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id); }elseif($stock_type == 2){ - $this->exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id); + StoreProductLogic::exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id); } } - /**普通 */ - public function ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id){ - $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_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); - if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); - } - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - return false; - } - } else { - Db::startTrans(); - try { - if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id); - } - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - return false; - } - } - } - - /**兑换 */ - public function exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id){ - $store_find = StoreBranchProductExchange::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); - if ($find && !$store_find) { - Db::startTrans(); - try { - $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'], - 'price' => $find['price'], - 'cost' => $find['cost'], - 'purchase' => $find['purchase'], - 'vip_price' => $find['vip_price'], - 'unit' => $find['unit'], - 'store_id' => $store_id, - 'sales' => 0, - 'stock' => 0, - ]; - StoreBranchProductExchange::create($product); - if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); - } - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - return false; - } - } else { - Db::startTrans(); - try { - if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id); - } - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); - return false; - } - } - } - public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0) - { - $storage = [ - 'product_id' => $product_arr['id'], - 'store_id' => $store_id, - 'nums' => $product_arr['stock'], - 'admin_id' => $admin_id, - 'type' => $stock_type, - 'warehouse_id'=>$warehouse_id, - ]; - $data=[ - 'warehouse_id'=>$warehouse_id, - 'product_id' => $product_arr['id'], - 'store_id' => $store_id, - 'financial_pm' => 0, - 'batch' => $product_arr['batch']??1, - 'nums' => $product_arr['stock'], - 'status' =>1, - 'admin_id' =>$admin_id, - ]; - $warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find(); - if ($warehouse) { - if($warehouse['nums']< $product_arr['stock']){ - $storage['status'] = -1; - $data['status'] = -1; - $storage['mark'] = '库存不足,分库存为:' .$warehouse['nums']; - $data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock']; - } - $res=WarehouseProductLogic::add($data); - $storage['outbound_id']=$res['id']??0; - SystemStoreStorage::create($storage); - } else { - $res=WarehouseProductLogic::add($data); - $storage['outbound_id']=$res['id']??0; - SystemStoreStorage::create($storage); - } - } public function onConsumeFailure(\Throwable $e, $package) { @@ -204,30 +50,4 @@ class StoreStorageSend implements Consumer return $package; } - /* - * 传入三级或者二级分类返还上级分类 一级那全是相同 - */ - public static function dealChangeCate($cate_id) - { - $value =[]; - $last_cate = Db::name('store_category')->where('id',$cate_id)->value('pid'); - if(!empty($last_cate)){ - //2 - $value['two_cate_id'] = $last_cate; - //1 - $first_cate = Db::name('store_category')->where('id',$value['two_cate_id'])->value('pid'); - if(empty($first_cate)){//顶级了 - $value['two_cate_id'] = $cate_id; - $value['top_cate_id'] = $last_cate; - }else{ - $value['top_cate_id'] = $first_cate; - } - - }else{ - //1-2 选的1级目录 - $value['two_cate_id'] = $cate_id; - $value['top_cate_id'] = $cate_id; - } - return $value; - } } diff --git a/app/store/lists/system_store_storage/SystemStoreStorageLists.php b/app/store/lists/system_store_storage/SystemStoreStorageLists.php index 681fe63f..1170e39f 100644 --- a/app/store/lists/system_store_storage/SystemStoreStorageLists.php +++ b/app/store/lists/system_store_storage/SystemStoreStorageLists.php @@ -52,7 +52,7 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI return SystemStoreStorage::where($this->searchWhere) ->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums', 'mark', 'status']) ->limit($this->limitOffset, $this->limitLength) - ->order(['status' => 'aes']) + ->order(['id'=>'desc','status' => 'aes']) ->select()->each(function ($item) { $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name');