diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index c7172fab..027a06cd 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -14,6 +14,7 @@ namespace app\admin\controller; +use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists; use app\admin\logic\statistic\ProductStatisticLogic; use app\admin\logic\statistic\TradeStatisticLogic; use app\admin\logic\statistic\UserStatisticLogic; @@ -224,6 +225,14 @@ class WorkbenchController extends BaseAdminController return $this->data($data); } + /** + * 实时商品统计 + */ + public function product_order(){ + return $this->dataLists(new StoreOrderCartInfoGroupLists()); + + } + /** * 格式化时间 * @param $time diff --git a/app/admin/controller/purchase_order/PurchaseOrderController.php b/app/admin/controller/purchase_order/PurchaseOrderController.php new file mode 100644 index 00000000..390727d2 --- /dev/null +++ b/app/admin/controller/purchase_order/PurchaseOrderController.php @@ -0,0 +1,41 @@ +dataLists(new PurchaseOrderLists()); + } + public function info_lists() + { + return $this->dataLists(new PurchaseOrderInfoLists()); + } + /** + * 合并今日商户订单 + */ + public function add(){ + PurchaseOrderLogic::StoreTodayOrder(); + return $this->success('合并成功'); + } + /** + * 合并今日平台订单 + */ + public function platform(){ + PurchaseOrderLogic::platformTodayOrder(); + return $this->success('合并成功'); + } + + /** + * 详情 + */ + public function detail(){ + $id=$this->request->get('id'); + $res=PurchaseOrderLogic::detail($id); + return $this->data($res); + } +} \ No newline at end of file diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php index fd451651..8683acbc 100644 --- a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -5,6 +5,7 @@ namespace app\admin\controller\store_order_cart_info; use app\admin\controller\BaseAdminController; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoLists; +use app\admin\lists\store_order_cart_info\StoreOrderCartInfoTwoLists; /** * 订单购物详情控制器 @@ -25,5 +26,8 @@ class StoreOrderCartInfoController extends BaseAdminController { return $this->dataLists(new StoreOrderCartInfoLists()); } - + public function listsTwo() + { + return $this->dataLists(new StoreOrderCartInfoTwoLists()); + } } \ No newline at end of file diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php index 4e9046b0..6ea157ae 100644 --- a/app/admin/controller/store_product/StoreProductController.php +++ b/app/admin/controller/store_product/StoreProductController.php @@ -99,15 +99,16 @@ class StoreProductController extends BaseAdminController $product_arr = $this->request->post('product_arr'); $store_arr = $this->request->post('store_arr'); $stock_type = $this->request->post('stock_type',1); + $warehouse_id = $this->request->post('warehouse_id'); if (count($store_arr) == 1) { $store_id = $store_arr[0]; foreach ($product_arr as $key => $arr) { - Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId]); + Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]); } } else { foreach ($product_arr as $key => $arr) { foreach ($store_arr as $k => $store_id) { - Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId]); + Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]); } } } diff --git a/app/admin/controller/warehouse/WarehouseController.php b/app/admin/controller/warehouse/WarehouseController.php new file mode 100644 index 00000000..8f4506ef --- /dev/null +++ b/app/admin/controller/warehouse/WarehouseController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseLists()); + } + + + /** + * @notes 添加仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function add() + { + $params = (new WarehouseValidate())->post()->goCheck('add'); + $result = WarehouseLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(WarehouseLogic::getError()); + } + + + /** + * @notes 编辑仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function edit() + { + $params = (new WarehouseValidate())->post()->goCheck('edit'); + $result = WarehouseLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseLogic::getError()); + } + + + /** + * @notes 删除仓库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function delete() + { + $params = (new WarehouseValidate())->post()->goCheck('delete'); + WarehouseLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取仓库信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:10 + */ + public function detail() + { + $params = (new WarehouseValidate())->goCheck('detail'); + $result = WarehouseLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php new file mode 100644 index 00000000..6f5817b3 --- /dev/null +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -0,0 +1,108 @@ +dataLists(new WarehouseProductLists()); + } + + + /** + * @notes 添加商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function add() + { + $params = (new WarehouseProductValidate())->post()->goCheck('add'); + $params['admin_id']=$this->adminId; + $result = WarehouseProductLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + } + + + /** + * @notes 编辑商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function edit() + { + $params = (new WarehouseProductValidate())->post()->goCheck('edit'); + $params['admin_id']=$this->adminId; + $result = WarehouseProductLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + } + + + /** + * @notes 删除商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function delete() + { + $params = (new WarehouseProductValidate())->post()->goCheck('delete'); + WarehouseProductLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品仓储信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function detail() + { + $params = (new WarehouseProductValidate())->goCheck('detail'); + $result = WarehouseProductLogic::detail($params); + return $this->data($result); + } + + /** + * 确认操作 + */ + public function enter(){ + $id=$this->request->post('id'); + $result = WarehouseProductLogic::enter($id); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(WarehouseProductLogic::getError()); + return $this->success($result); + } +} \ No newline at end of file diff --git a/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php b/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php new file mode 100644 index 00000000..cfa6f487 --- /dev/null +++ b/app/admin/controller/warehouse_product_storege/WarehouseProductStoregeController.php @@ -0,0 +1,95 @@ +dataLists(new WarehouseProductStoregeLists()); + } + + + // /** + // * @notes 添加仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function add() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('add'); + // $result = WarehouseProductStoregeLogic::add($params); + // if (true === $result) { + // return $this->success('添加成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductStoregeLogic::getError()); + // } + + + // /** + // * @notes 编辑仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function edit() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('edit'); + // $result = WarehouseProductStoregeLogic::edit($params); + // if (true === $result) { + // return $this->success('编辑成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductStoregeLogic::getError()); + // } + + + // /** + // * @notes 删除仓库商品存储 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function delete() + // { + // $params = (new WarehouseProductStoregeValidate())->post()->goCheck('delete'); + // WarehouseProductStoregeLogic::delete($params); + // return $this->success('删除成功', [], 1, 1); + // } + + + // /** + // * @notes 获取仓库商品存储详情 + // * @return \think\response\Json + // * @author admin + // * @date 2024/08/01 10:22 + // */ + // public function detail() + // { + // $params = (new WarehouseProductStoregeValidate())->goCheck('detail'); + // $result = WarehouseProductStoregeLogic::detail($params); + // return $this->data($result); + // } + + +} \ No newline at end of file diff --git a/app/admin/lists/purchase_order/PurchaseOrderLists.php b/app/admin/lists/purchase_order/PurchaseOrderLists.php new file mode 100644 index 00000000..933af29f --- /dev/null +++ b/app/admin/lists/purchase_order/PurchaseOrderLists.php @@ -0,0 +1,97 @@ + ['store_id', 'order_id', 'is_mer','storage'], + ]; + } + + + /** + * @notes 获取采购订单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 17:09 + */ + public function lists(): array + { + if($this->request->get('o_id')){ + $arr=PurchaseOrder::where('id',$this->request->get('o_id'))->value('order_arr'); + if($arr){ + $this->searchWhere[]=['id','in',$arr]; + } + } + return PurchaseOrder::where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + if ($item->store_id) { + $item->system_store = SystemStore::where('id',$item->store_id)->value('name'); + } else { + $item->system_store = '平台'; + } + if ($item->is_mer == 1) { + $item->mer_name = '商户'; + } else { + $item->mer_name = '平台'; + } + if ($item->is_opurchase == 1) { + $item->opurchase_name = '已采购'; + } else { + $item->opurchase_name = '未采购'; + } + switch ($item->storage) { + case 0: + $item->storage_name = '未入库'; + break; + case 1: + $item->storage_name = '部分入库'; + break; + case 2: + $item->storage_name = '已入库'; + break; + default: + $item->storage_name = '未入库'; + } + })->toArray(); + } + + + /** + * @notes 获取采购订单数量 + * @return int + * @author admin + * @date 2024/05/31 17:09 + */ + public function count(): int + { + return PurchaseOrder::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/lists/purchase_order_info/PurchaseOrderInfoLists.php b/app/admin/lists/purchase_order_info/PurchaseOrderInfoLists.php new file mode 100644 index 00000000..b4dacaef --- /dev/null +++ b/app/admin/lists/purchase_order_info/PurchaseOrderInfoLists.php @@ -0,0 +1,85 @@ + ['store_id', 'oid', ], + ]; + } + + + /** + * @notes 获取采购订单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 17:09 + */ + public function lists(): array + { + return PurchaseOrderInfo::where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $find=StoreProduct::where('id',$item->product_id)->field('store_info,unit,store_name,image')->find(); + if($find){ + $item->store_name=$find->store_name; + $item->unit_name=StoreProductUnit::where('id',$find->unit)->value('name'); + $item->store_info=$find->store_info; + $item->image=$find->image; + } + switch ($item->storage) { + case 0: + $item->storage_name = '未入库'; + break; + case 1: + $item->storage_name = '部分入库'; + break; + case 2: + $item->storage_name = '已入库'; + break; + default: + $item->storage_name = '未入库'; + } + })->toArray(); + } + + + /** + * @notes 获取采购订单数量 + * @return int + * @author admin + * @date 2024/05/31 17:09 + */ + public function count(): int + { + return PurchaseOrderInfo::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupLists.php new file mode 100644 index 00000000..37153b05 --- /dev/null +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupLists.php @@ -0,0 +1,122 @@ + 'create_time' + ]; + } + + + /** + * @notes 获取订单购物详情列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:02 + */ + public function lists(): array + { + + if($this->request->get('start_time')==''){ + $this->searchWhere[]=['create_time','between',[strtotime(date('Y-m-d 00:00:00')),strtotime(date('Y-m-d 23:59:59'))]]; + } + return StoreOrderCartInfo::where($this->searchWhere) + ->field('product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group('product_id') + ->limit($this->limitOffset, $this->limitLength) + ->select()->each(function ($item) { + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,cate_id,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['store_name']='';//商品名称 + $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['unit_name']='';// + $item['cate_name']='';// + $item['system_store']='';// + } + return $item; //返回处理后的数据。 + }) + ->toArray(); + } + + + /** + * @notes 获取订单购物详情数量 + * @return int + * @author admin + * @date 2024/05/31 16:02 + */ + public function count(): int + { + return StoreOrderCartInfo::where($this->searchWhere)->group('product_id')->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=[ + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + ]; + return $data; + } +} diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php new file mode 100644 index 00000000..2a8557d5 --- /dev/null +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php @@ -0,0 +1,132 @@ + ['store_id'], + 'between_time' => 'create_time' + ]; + } + + + /** + * @notes 获取订单购物详情列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:02 + */ + public function lists(): array + { + if ($this->request->get('start_time') == '') { + $this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; + } + $query = StoreOrderCartInfo::where($this->searchWhere); + if ($this->request->get('is_group') == 1) { + $query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']); + } else { + $query->field('store_id,product_id,price,total_price,cart_num'); + } + return $query->limit($this->limitOffset, $this->limitLength) + ->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,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')??''; + $item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name')??''; + }else{ + $item['image']='';//商品图片 + $item['store_name']='';//商品名称 + $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['unit_name']='';// + $item['cate_name']='';// + $item['system_store']='';// + } + return $item; //返回处理后的数据。 + }) + ->toArray(); + } + + + /** + * @notes 获取订单购物详情数量 + * @return int + * @author admin + * @date 2024/05/31 16:02 + */ + public function count(): int + { + if ($this->request->get('is_group') == 1) { + return StoreOrderCartInfo::where($this->searchWhere)->group('product_id')->count(); + } else { + return StoreOrderCartInfo::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 = [ + 'system_store' => '门店', + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + ]; + return $data; + } +} diff --git a/app/admin/lists/system_store_storage/SystemStoreStorageLists.php b/app/admin/lists/system_store_storage/SystemStoreStorageLists.php index 59cfcd95..4a380b5b 100644 --- a/app/admin/lists/system_store_storage/SystemStoreStorageLists.php +++ b/app/admin/lists/system_store_storage/SystemStoreStorageLists.php @@ -59,8 +59,8 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI $item['staff_name'] = '无'; } $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find(); - $item['store_name']=$find['store_name']; - $item['image']=$find['image']; + $item['store_name']=$find['store_name']??''; + $item['image']=$find['image']??''; return $item; }) ->toArray(); diff --git a/app/admin/lists/warehouse/WarehouseLists.php b/app/admin/lists/warehouse/WarehouseLists.php new file mode 100644 index 00000000..4552a97c --- /dev/null +++ b/app/admin/lists/warehouse/WarehouseLists.php @@ -0,0 +1,65 @@ + ['name', 'contacts', 'tel'], + ]; + } + + + /** + * @notes 获取仓库信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:10 + */ + public function lists(): array + { + return Warehouse::where($this->searchWhere) + ->field(['id', 'name', 'code', 'contacts', 'tel', 'address', 'notes', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取仓库信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:10 + */ + public function count(): int + { + return Warehouse::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php new file mode 100644 index 00000000..b3c6a4e8 --- /dev/null +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -0,0 +1,97 @@ + ['warehouse_id', 'product_id', 'financial_pm'], + ]; + } + + + /** + * @notes 获取商品仓储信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:55 + */ + public function lists(): array + { + return WarehouseProduct::where($this->searchWhere) + ->field(['id', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'manufacture','expiration_date','status','mark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item){ + if($item->financial_pm==0){ + $item->financial_pm_name='出库'; + }else{ + $item->financial_pm_name='入库'; + } + if($item->status==0){ + $item->status_name='未确认'; + }elseif($item->status==1){ + $item->status_name='已确认'; + }else{ + $item->status_name='库存不足'; + } + if($item->admin_id){ + $item->admin_name=Admin::where('id',$item->admin_id)->value('name'); + }else{ + $item->admin_name=''; + } + if($item->product_id){ + $item->store_name=StoreProduct::where('id',$item->product_id)->value('store_name'); + }else{ + $item->store_name=''; + } + if($item->warehouse_id){ + $item->warehouse_name=Warehouse::where('id',$item->warehouse_id)->value('name'); + }else{ + $item->warehouse_name=''; + } + $item->expiration_date=$item->expiration_date?date('Y-m-d',$item->expiration_date):''; + $item->manufacture=$item->manufacture?date('Y-m-d',$item->manufacture):''; + }) + ->toArray(); + } + + + /** + * @notes 获取商品仓储信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:55 + */ + public function count(): int + { + return WarehouseProduct::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php new file mode 100644 index 00000000..72f7c2c8 --- /dev/null +++ b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php @@ -0,0 +1,85 @@ + ['warehouse_id'], + ]; + } + + + /** + * @notes 获取仓库商品存储列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/08/01 10:22 + */ + public function lists(): array + { + return WarehouseProductStorege::where($this->searchWhere) + ->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item){ + $item->warehouse_name = Warehouse::where('id',$item->warehouse_id)->value('name'); + $find= StoreProduct::where('id',$item->product_id)->find(); + if($find){ + $item->store_name = $find->store_name; + $item->image = $find->image; + $item->bar_code = $find->bar_code; + $item->price = $find->price; + $item->cost = $find->cost; + $item->purchase = $find->purchase; + $item->store_info = $find->store_info; + $item->rose = $find->rose; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name'); + } + $item['stock']=$item['nums']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取仓库商品存储数量 + * @return int + * @author admin + * @date 2024/08/01 10:22 + */ + public function count(): int + { + return WarehouseProductStorege::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/purchase_order/PurchaseOrderLogic.php b/app/admin/logic/purchase_order/PurchaseOrderLogic.php new file mode 100644 index 00000000..cab70096 --- /dev/null +++ b/app/admin/logic/purchase_order/PurchaseOrderLogic.php @@ -0,0 +1,172 @@ + 1, 'refund_status' => 0])->whereDay('create_time')->group('store_id')->column('store_id'); + $purchaseOrderInfo = new PurchaseOrderInfo(); + foreach ($store_arr as $store_id) { + $purchase_order_info = []; + $order_arr = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'store_id' => $store_id])->whereDay('create_time')->column('id'); + $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'store_id' => $store_id])->whereDay('create_time')->field('SUM(pay_price) as pay_price,SUM(total_price) as total_price')->find(); + $data = [ + 'store_id' => $store_id, + 'order_arr' => json_encode($order_arr), + 'order_id' => getNewOrderId('CG'), + 'total' => $price['total_price'], + 'actual' => $price['pay_price'], + 'money' => $price['pay_price'], + 'paid' => 1, + 'is_mer' => 1, + 'create_time' => time(), + 'update_time' => time(), + ]; + $res = PurchaseOrder::create($data); + $info = StoreOrderCartInfo::where('oid', 'in', $order_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select(); + foreach ($info as $item) { + $arr['oid'] = $res['id']; + $arr['store_id'] = $item['store_id']; + $arr['product_id'] = $item['product_id']; + $arr['price'] = $item['price']; + $arr['total_price'] = $item['total_price']; + $arr['cart_num'] = $item['cart_num']; + $arr['status'] = 1; + $purchase_order_info[] = $arr; + } + $purchaseOrderInfo->saveAll($purchase_order_info); + } + 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/08/01 16:32 + */ + public static function platformTodayOrder() + { + Db::startTrans(); + try { + $purchaseOrderInfo = new PurchaseOrderInfo(); + $purchase_order_info=[]; + $order_arr = PurchaseOrder::whereDay('create_time')->where('is_mer',1)->column('id'); + $price = PurchaseOrder::whereDay('create_time')->field('SUM(actual) as pay_price,SUM(total) as total_price')->find(); + $data = [ + 'store_id' => 0, + 'order_arr' => json_encode($order_arr), + 'order_id' => getNewOrderId('PT'), + 'total' => $price['total_price'], + 'actual' => $price['pay_price'], + 'money' => $price['pay_price'], + 'paid' => 1, + 'is_mer' => 2, + 'create_time' => time(), + 'update_time' => time(), + ]; + $res = PurchaseOrder::create($data); + $info = PurchaseOrderInfo::where('oid', 'in', $order_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select(); + foreach ($info as $item) { + $arr['oid'] = $res['id']; + $arr['store_id'] = $item['store_id']; + $arr['product_id'] = $item['product_id']; + $arr['price'] = $item['price']; + $arr['total_price'] = $item['total_price']; + $arr['cart_num'] = $item['cart_num']; + $arr['status'] = 1; + $purchase_order_info[] = $arr; + } + $purchaseOrderInfo->saveAll($purchase_order_info); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + d($e); + self::setError($e->getMessage()); + return false; + } + } + + /** + * @notes 删除采购订单 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/01 16:32 + */ + public static function delete(array $params): bool + { + return PurchaseOrder::destroy($params['id']); + } + + + /** + * @notes 获取采购订单详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/01 16:32 + */ + public static function detail($id): array + { + $data= PurchaseOrder::findOrEmpty($id)->toArray(); + if($data){ + if($data['store_id']){ + $data['system_store']=SystemStore::where('id',$data['store_id'])->value('name'); + }else{ + $data['system_store']='平台'; + } + switch ($data['storage']) { + case 0: + $data['storage_name'] = '未入库'; + break; + case 1: + $data['storage_name'] = '部分入库'; + break; + case 2: + $data['storage_name'] = '已入库'; + break; + default: + $data['storage_name'] = '未入库'; + } + } + return $data; + } +} diff --git a/app/admin/logic/statistic/TradeStatisticLogic.php b/app/admin/logic/statistic/TradeStatisticLogic.php index 7297e10c..e9fc6a7b 100644 --- a/app/admin/logic/statistic/TradeStatisticLogic.php +++ b/app/admin/logic/statistic/TradeStatisticLogic.php @@ -214,7 +214,7 @@ class TradeStatisticLogic extends BaseLogic $OrderChain = countRate($OrderMoney, $lastOrderMoney); $topData[2] = [ 'title' => '商品支付金额', - 'desc' => '选定条件下,用户购买商品的实际支付金额,包括微信支付、余额支付、支付宝支付、线下支付金额(拼团商品在成团之后计入,线下支付订单在后台确认支付后计入)', + 'desc' => '选定条件下,用户购买商品的实际支付金额,包括微信支付、余额支付、支付宝支付、线下支付金额', 'total_money' => $OrderMoney, 'rate' => $OrderChain, 'value' => $OrderCurve['y'], @@ -328,20 +328,21 @@ class TradeStatisticLogic extends BaseLogic ]; $Chain['deposit'] = $OrderDepositCurve; //兑换礼品券 - $userSign = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $where['create_time']], 'sum'); - $userSignTwo = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $dateWhere['create_time']], 'sum', "", $isNum); - $userSignGroup = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $where['create_time']], 'group', 'create_time'); - $userSignRate = countRate($userSign, $userSignTwo); - $topData[9] = [ - 'title' => '礼品券消耗', - 'desc' => '用户下单时使用礼品券实际支付的金额', - 'total_money' => $userSign, - 'rate' => $userSignRate, - 'value' => $userSignGroup['y'], - 'type' => 1, - 'sign' => 'user_sign', - ]; - $Chain['user_sign'] = $userSignGroup; + // $userSign = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $where['create_time']], 'sum'); + // $userSignTwo = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $dateWhere['create_time']], 'sum', "", $isNum); + // $userSignGroup = $this->getOrderTotalMoney(['pay_type' => 19, 'create_time' => $where['create_time']], 'group', 'create_time'); + // $userSignRate = countRate($userSign, $userSignTwo); + // $topData[9] = [ + // 'title' => '礼品券消耗', + // 'desc' => '用户下单时使用礼品券实际支付的金额', + // 'total_money' => $userSign, + // 'rate' => $userSignRate, + // 'value' => $userSignGroup['y'], + // 'type' => 1, + // 'sign' => 'user_sign', + // ]; + // $Chain['user_sign'] = $userSignGroup; + /** 充值金额 */ $rechgeMoneyHome = $this->getRechargeTotalMoney($where, 'sum'); @@ -355,8 +356,8 @@ class TradeStatisticLogic extends BaseLogic $RechgeTotalCurve = $this->totalArrData([$RechgeHomeCurve, $RechgeAdminCurve]); $RechgeChain = countRate($rechgeMoneyTotal, $lastRechgeMoneyTotal); $topData[10] = [ - 'title' => '充值金额', - 'desc' => '选定条件下,用户成功充值的金额', + 'title' => '消费金金额', + 'desc' => '选定条件下,用户购买的消费金', 'total_money' => $rechgeMoneyTotal, 'rate' => $RechgeChain, 'value' => $RechgeTotalCurve['y'], @@ -365,6 +366,15 @@ class TradeStatisticLogic extends BaseLogic ]; $Chain['rechage'] = $RechgeTotalCurve; + $topData[9] = [ + 'title' => '微信渠道金额', + 'desc' => '用户使用微信下单和购买消费金的金额', + 'total_money' => bcadd($wechatOrderMoney,$rechgeMoneyTotal,2), + 'rate' => 0, + 'value' => [], + 'type' => 1, + 'sign' => 'wechat_all', + ]; //支出金额 // $outTotalMoney = bcadd($outYeMoney, $outExtractMoney, 2); // $lastOutTotalMoney = bcadd($lastOutYeMoney, $lastOutExtractMoney, 2); @@ -409,7 +419,7 @@ class TradeStatisticLogic extends BaseLogic $inTotalChain = countRate($inTotalMoney, $lastInTotalMoney); $topData[0] = [ 'title' => '营业额', - 'desc' => '商品支付金额、充值金额、购买付费会员金额、线下收银金额', + 'desc' => '商品支付金额、采购支付、线下收银金额', 'total_money' => $inTotalMoney, 'rate' => $inTotalChain, 'value' => $inTotalCurve['y'], @@ -445,10 +455,10 @@ class TradeStatisticLogic extends BaseLogic $inOrderMoney = $this->getOrderTotalMoney($where, $selectType, "", $isNum); //用户充值收入 - $inRechargeMoneyHome = $this->getRechargeTotalMoney($where, $selectType, "", $isNum); + // $inRechargeMoneyHome = $this->getRechargeTotalMoney($where, $selectType, "", $isNum); $inrechgeMoneyAdmin = $this->getBillYeTotalMoney($where, $selectType, '', $isNum); - $inRechargeMoney = bcadd($inRechargeMoneyHome, $inrechgeMoneyAdmin, 2); + $inRechargeMoney = bcadd(0, $inrechgeMoneyAdmin, 2); //购买会员收入 $inMemberMoney = $this->getMemberTotalMoney($where, $selectType, "", $isNum); diff --git a/app/admin/logic/warehouse/WarehouseLogic.php b/app/admin/logic/warehouse/WarehouseLogic.php new file mode 100644 index 00000000..13568bdb --- /dev/null +++ b/app/admin/logic/warehouse/WarehouseLogic.php @@ -0,0 +1,106 @@ + $params['name'], + 'code' => $params['code'], + 'contacts' => $params['contacts'], + 'tel' => $params['tel'], + 'address' => $params['address'], + 'notes' => $params['notes'], + 'sort' => $params['sort'] + ]); + + 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/07/31 16:10 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Warehouse::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'code' => $params['code'], + 'contacts' => $params['contacts'], + 'tel' => $params['tel'], + 'address' => $params['address'], + 'notes' => $params['notes'], + 'sort' => $params['sort'] + ]); + + 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/07/31 16:10 + */ + public static function delete(array $params): bool + { + return Warehouse::destroy($params['id']); + } + + + /** + * @notes 获取仓库信息详情 + * @param $params + * @return array + * @author admin + * @date 2024/07/31 16:10 + */ + public static function detail($params): array + { + return Warehouse::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php new file mode 100644 index 00000000..66540148 --- /dev/null +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -0,0 +1,178 @@ + $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'financial_pm' => $params['financial_pm'], + 'batch' => $params['batch'], + 'nums' => $params['nums'], + 'price' => $params['price']??'', + 'total_price' => $params['total_price']??'', + 'admin_id' => $params['admin_id'], + 'code' => $params['code']??'', + 'status' => $params['status']??0, + '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); + self::enter($res['id'],$params['financial_pm']); + 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/07/31 16:55 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $data=[ + 'warehouse_id' => $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'financial_pm' => $params['financial_pm'], + 'batch' => $params['batch'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'admin_id' => $params['admin_id'], + 'total_price' => $params['total_price'], + 'code' => $params['code'], + ]; + 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']); + } + WarehouseProduct::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 + * @author admin + * @date 2024/07/31 16:55 + */ + public static function enter($id,$financial_pm=0) + { + Db::startTrans(); + try { + $find=WarehouseProduct::where('id',$id)->find(); + $find->status=1; + $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(); + } + if($storege){ + if($financial_pm==0){ + $storege->nums=bcsub($storege->nums,$find['nums']); + }else{ + $storege->nums=bcadd($storege->nums,$find['nums']); + } + $storege->save(); + + }else{ + WarehouseProductStorege::create([ + 'warehouse_id' => $find['warehouse_id'], + 'product_id' => $find['product_id'], + 'nums' => $find['nums'], + ]); + } + 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/07/31 16:55 + */ + public static function delete(array $params): bool + { + return WarehouseProduct::destroy($params['id']); + } + + + /** + * @notes 获取商品仓储信息详情 + * @param $params + * @return array + * @author admin + * @date 2024/07/31 16:55 + */ + public static function detail($params): array + { + $data= WarehouseProduct::findOrEmpty($params['id'])->toArray(); + if($data){ + $data['manufacture']=date('Y-m-d',$data['manufacture']); + $data['expiration_date']=date('Y-m-d',$data['expiration_date']); + + } + return $data; + } +} \ No newline at end of file diff --git a/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php new file mode 100644 index 00000000..eac41ece --- /dev/null +++ b/app/admin/logic/warehouse_product_storege/WarehouseProductStoregeLogic.php @@ -0,0 +1,104 @@ + $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'status' => $params['status'] + ]); + + 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/08/01 10:22 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + WarehouseProductStorege::where('id', $params['id'])->update([ + 'warehouse_id' => $params['warehouse_id'], + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'status' => $params['status'] + ]); + + 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/08/01 10:22 + */ + public static function delete(array $params): bool + { + return WarehouseProductStorege::destroy($params['id']); + } + + + /** + * @notes 获取仓库商品存储详情 + * @param $params + * @return array + * @author admin + * @date 2024/08/01 10:22 + */ + public static function detail($params): array + { + return WarehouseProductStorege::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/purchase_order/PurchaseOrderValidate.php b/app/admin/validate/purchase_order/PurchaseOrderValidate.php new file mode 100644 index 00000000..3c9ef046 --- /dev/null +++ b/app/admin/validate/purchase_order/PurchaseOrderValidate.php @@ -0,0 +1,86 @@ + 'require', + 'store_id' => 'require', + 'order_id' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'store_id' => '所属商户', + 'order_id' => '单据编号', + ]; + + + /** + * @notes 添加场景 + * @return PurchaseOrderValidate + * @author admin + * @date 2024/08/01 16:32 + */ + public function sceneAdd() + { + return $this->only(['store_id','order_id']); + } + + + /** + * @notes 编辑场景 + * @return PurchaseOrderValidate + * @author admin + * @date 2024/08/01 16:32 + */ + public function sceneEdit() + { + return $this->only(['id','store_id','order_id']); + } + + + /** + * @notes 删除场景 + * @return PurchaseOrderValidate + * @author admin + * @date 2024/08/01 16:32 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return PurchaseOrderValidate + * @author admin + * @date 2024/08/01 16:32 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/warehouse/WarehouseValidate.php b/app/admin/validate/warehouse/WarehouseValidate.php new file mode 100644 index 00000000..e044a6ff --- /dev/null +++ b/app/admin/validate/warehouse/WarehouseValidate.php @@ -0,0 +1,84 @@ + 'require', + 'name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '仓库名称', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneAdd() + { + return $this->only(['name']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneEdit() + { + return $this->only(['id','name']); + } + + + /** + * @notes 删除场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseValidate + * @author admin + * @date 2024/07/31 16:10 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/warehouse_product/WarehouseProductValidate.php b/app/admin/validate/warehouse_product/WarehouseProductValidate.php new file mode 100644 index 00000000..a3a7cb79 --- /dev/null +++ b/app/admin/validate/warehouse_product/WarehouseProductValidate.php @@ -0,0 +1,98 @@ + 'require', + 'warehouse_id' => 'require', + 'product_id' => 'require', + 'financial_pm' => 'require', + 'batch' => 'require', + 'nums' => 'require', + 'price' => 'require', + 'total_price' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'warehouse_id' => '仓库ID', + 'product_id' => '商品ID', + 'financial_pm' => '0 = 出库 1 = 获得', + 'batch' => '批次', + 'nums' => '数量', + 'price' => '价格', + 'total_price' => '总价', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneAdd() + { + return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneEdit() + { + return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price']); + } + + + /** + * @notes 删除场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseProductValidate + * @author admin + * @date 2024/07/31 16:55 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php b/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php new file mode 100644 index 00000000..45905ac9 --- /dev/null +++ b/app/admin/validate/warehouse_product_storege/WarehouseProductStoregeValidate.php @@ -0,0 +1,94 @@ + 'require', + 'warehouse_id' => 'require', + 'product_id' => 'require', + 'nums' => 'require', + 'price' => 'require', + 'total_price' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'warehouse_id' => '仓库ID', + 'product_id' => '商品ID', + 'nums' => '数量', + 'price' => '价格', + 'total_price' => '价格', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneAdd() + { + return $this->only(['warehouse_id','product_id','nums','price','total_price','status']); + } + + + /** + * @notes 编辑场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneEdit() + { + return $this->only(['id','warehouse_id','product_id','nums','price','total_price','status']); + } + + + /** + * @notes 删除场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return WarehouseProductStoregeValidate + * @author admin + * @date 2024/08/01 10:22 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index b3c777f0..140ccd5b 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -2,6 +2,7 @@ namespace app\api\controller; +use app\common\logic\StoreFinanceFlowLogic; use app\admin\logic\store_product\StoreProductLogic; use app\admin\validate\tools\GenerateTableValidate; use app\admin\logic\tools\GeneratorLogic; @@ -10,6 +11,7 @@ use app\common\logic\PayNotifyLogic; use app\common\logic\store_order\StoreOrderLogic; 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\system_store\SystemStore; use app\common\model\user\User; @@ -38,6 +40,36 @@ class IndexController extends BaseApiController { return json([1]); + $financeFlow = new StoreFinanceFlow(); + $order_id=544; + $store_id=3; + $staff_id=3; + Db::startTrans(); + try { + // $res = $financeFlow->where('order_id', $order_id)->update(['store_id' => $store_id, 'staff_id' => $staff_id]); + // if ($res) { + // $order['store_id'] =$store_id; + // } + $financeFlowLogic = new StoreFinanceFlowLogic(); + //other_uid大于0的 + $select_1 = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1,'status'=>0])->where('other_uid','>',0)->select(); + foreach ($select_1 as $k => $v) { + if ($v['other_uid'] > 0) { + $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); + } + } + + $deposit = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 0, 'financial_type' => 11,'status'=>0])->value('number') ?? 0; + $money = $financeFlow->where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 2,'status'=>0])->value('number') ?? 0; + $financeFlowLogic->updateStatusStore($order_id, $store_id, $money, $deposit); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + d($e); + return false; + } + $all_where['paid'] = 1; d(OrderLogic::dayPayPrice($all_where,date('Y-m-d',time()))); $uid=9; diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 9fc8b397..1cdece94 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -83,27 +83,12 @@ class OrderLogic extends BaseLogic self::$fresh_price = 0; //生鲜金额 /** 计算价格 */ $off_activity = Config::where('name', 'off_activity')->value('value'); - $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id,store_info,rose'; + $field = 'id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id,store_info,rose'; foreach ($cart_select as $k => $v) { - $find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->find(); + $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); if (!$find) { - // unset($cart_select[$k]); - // continue; - $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase, id product_id,cate_id,store_info,rose'; - $find = StoreProduct::where(['id' => $v['product_id']])->field($field)->find(); - if ($find) { - $cate_id = StoreCategory::where('id', $find['cate_id'])->value('pid'); - if ($cate_id > 0) { - $cate_id = StoreCategory::where('id', $cate_id)->value('pid'); - if ($cate_id > 0) { - $cate_id = StoreCategory::where('id', $cate_id)->value('pid'); - $find['top_cate_id'] = $cate_id; - } else { - $find['top_cate_id'] = $cate_id; - } - } - } - $cart_select[$k]['status'] = 1; //缺货标识 + self::setError('商品不存在'); + return false; } unset($cart_select[$k]['id']); $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 @@ -152,7 +137,6 @@ class OrderLogic extends BaseLogic $cartInfo['name'] = $find['store_name']; $cartInfo['image'] = $find['image']; $cart_select[$k]['cart_info'] = json_encode($cartInfo); - $cart_select[$k]['branch_product_id'] = $find['branch_product_id']; //理论上每笔都是拆分了 $cart_select[$k]['name'] = $find['store_name']; $cart_select[$k]['imgs'] = $find['image']; @@ -339,11 +323,14 @@ class OrderLogic extends BaseLogic $goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id - $updateData[] = [ - 'id' => $v['branch_product_id'], - 'sales' => ['inc', $v['cart_num']], - 'stock' => ['dec', $v['cart_num']], - ]; + $id=StoreBranchProduct::where('product_id',$v['product_id'])->where('store_id',$params['store_id'])->value('id'); + if($id){ + $updateData[] = [ + 'id' => $id, + 'sales' => ['inc', $v['cart_num']], + 'stock' => ['dec', $v['cart_num']], + ]; + } $updateDataTwo[] = [ 'id' => $v['product_id'], 'sales' => ['inc', $v['cart_num']] @@ -607,6 +594,7 @@ class OrderLogic extends BaseLogic 'writeoff_time' => time(), 'is_writeoff' => YesNoEnum::YES, 'store_id' => $params['store_id'], + 'status' => 1, 'staff_id' => $params['staff_id'] ?? 0, 'update_time' => time(), ], ['oid' => $order['id']]); @@ -617,19 +605,15 @@ class OrderLogic extends BaseLogic } $financeFlowLogic = new StoreFinanceFlowLogic(); //other_uid大于0的 - $select_1 = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1])->where('other_uid','>',0)->select(); + $select_1 = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1,'status'=>0])->where('other_uid','>',0)->select(); foreach ($select_1 as $k => $v) { if ($v['other_uid'] > 0) { $financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']); } } - // $spread_find = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 12, 'other_uid' => $order['spread_uid']])->find(); - // if ($spread_find) { - // $financeFlowLogic->updateStatusUser($spread_find['id'], $order['spread_uid'], $spread_find['number'], $order['id']); - // } - - $deposit = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 0, 'financial_type' => 11])->value('number') ?? 0; - $money = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 2])->value('number') ?? 0; + + $deposit = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 0, 'financial_type' => 11,'status'=>0])->value('number') ?? 0; + $money = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 2,'status'=>0])->value('number') ?? 0; $financeFlowLogic->updateStatusStore($order['id'], $order['store_id'], $money, $deposit); //积分结算 if ($order['is_storage'] == 0 && $order['source'] == 0) { @@ -644,51 +628,6 @@ class OrderLogic extends BaseLogic } } - //不走二次分钱的核销 - public static function lessWriteOff($params): bool - { - $data = StoreOrder::with('store')->where([ - 'verify_code' => $params['verify_code'] - ])->find(); - if (empty($data)) { - return false; - } - Db::startTrans(); - try { - StoreOrder::update([ - 'verify_code' => $params['verify_code'] . '-1', - 'status' => OrderEnum::RECEIVED_GOODS, - 'is_writeoff' => OrderEnum::IS_OK, - 'update_time' => time(), - 'store_id' => $params['store_id'], - 'staff_id' => $params['staff_id'] ?? 0, - ], ['id' => $data['id']]); - (new StoreOrderCartInfo())->update([ - 'verify_code' => $params['verify_code'] . '-1', - 'writeoff_time' => time(), - 'is_writeoff' => YesNoEnum::YES, - 'store_id' => $params['store_id'], - 'staff_id' => $params['staff_id'] ?? 0, - 'update_time' => time(), - ], ['oid' => $data['id']]); - // $financeFlow = (new StoreFinanceFlowLogic)->getStoreOrder($data['id'], $data['store_id']); - // if (!empty($financeFlow)) { - // $capitalFlowLogic = new CapitalFlowLogic($data->store, 'store'); - // $capitalFlowLogic->storeIncome('store_order_income', 'order', $data['id'], $financeFlow['number']); - // } - $order = StoreOrder::where('id', $data['id'])->find(); - PayNotifyLogic::descSwap($order['id']); - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - self::setError($e->getMessage()); - return false; - } - } - - - public static function write_count($info, $params) { diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 9184b601..640bc411 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -160,14 +160,6 @@ class PayNotifyLogic extends BaseLogic ]; UserSign::create($sing); - if ($order && $order['store_id']) { - $params = [ - 'verify_code' => $order['verify_code'], - 'store_id' => $order['store_id'], - 'staff_id' => $order['staff_id'] - ]; - OrderLogic::lessWriteOff($params); - } self::dealProductLog($order); } @@ -329,8 +321,8 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao = new CapitalFlowLogic($user); $deal_money = bcdiv($extra['amount']['refund'], 100, 2); //对应比例得退礼品券逻辑 - $discount = self::getDiscount($user->user_ship); - $total_price = bcmul($order->refund_price, $discount, 2); + // $discount = self::getDiscount($user->user_ship); + // $total_price = bcmul($order->refund_price, $discount, 2); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 $user->now_money = bcadd($user->now_money, $deal_money, 2); @@ -352,6 +344,8 @@ class PayNotifyLogic extends BaseLogic return true; } + //订单购物详情 + StoreOrderCartInfo::where('oid',$order['id'])->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]); //积分 UserSignLogic::RefundOrder($order); //微信日志 user_order_refund @@ -394,6 +388,8 @@ class PayNotifyLogic extends BaseLogic $model->save(); //增加数量 self::addStock($order['id']); + StoreOrderCartInfo::where('oid',$order['id'])->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]); + return true; } diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index a845c7ed..5692b929 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -148,16 +148,21 @@ class StoreFinanceFlowLogic extends BaseLogic { StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1]); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1]); + $store=SystemStore::where('id',$store_id)->find(); + $capitalFlowDao = new CapitalFlowLogic($store); if ($money > 0) { + $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money); SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); } if ($deposit > 0) { + $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $money); SystemStore::where('id', $store_id)->inc('paid_deposit', $deposit)->update(); } $find = StoreFinanceFlow::where(['order_id' => $order_id, 'financial_pm' => 1, 'financial_type' => 16, 'status' => 0])->find(); StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 16])->update(['status' => 1]); if ($find) { if ($find['number'] > 0) { + $capitalFlowDao->storeIncome('store_attrition_add', 'order', $order_id, $money); SystemStore::where('id', $store_id)->inc('attrition', $find['number'])->update(); } } diff --git a/app/common/model/purchase_order/PurchaseOrder.php b/app/common/model/purchase_order/PurchaseOrder.php new file mode 100644 index 00000000..f05cb308 --- /dev/null +++ b/app/common/model/purchase_order/PurchaseOrder.php @@ -0,0 +1,22 @@ +findOrEmpty()->toArray(); if($stock_type == 1){ - $this->ordinary($product_arr,$store_id,$admin_id,$find); + $this->ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id); }elseif($stock_type == 2){ - $this->exchange($product_arr,$store_id,$admin_id,$find); + $this->exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id); } } /**普通 */ - public function ordinary($product_arr,$store_id,$admin_id,$find){ + 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(); @@ -82,7 +85,7 @@ class StoreStorageSend implements Consumer ]; StoreBranchProductAttrValue::create($arr); if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr); + $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); } StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id); Db::commit(); @@ -96,7 +99,7 @@ class StoreStorageSend implements Consumer Db::startTrans(); try { if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr,1); + $this->storage($find, $store_id, $admin_id, $product_arr,1,$warehouse_id); } Db::commit(); return true; @@ -109,7 +112,7 @@ class StoreStorageSend implements Consumer } /**兑换 */ - public function exchange($product_arr,$store_id,$admin_id,$find){ + 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(); @@ -133,7 +136,7 @@ class StoreStorageSend implements Consumer ]; StoreBranchProductExchange::create($product); if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr); + $this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id); } // StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id); Db::commit(); @@ -147,7 +150,7 @@ class StoreStorageSend implements Consumer Db::startTrans(); try { if ($product_arr['stock'] > 0) { - $this->storage($find, $store_id, $admin_id, $product_arr,2); + $this->storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id); } Db::commit(); return true; @@ -158,7 +161,7 @@ class StoreStorageSend implements Consumer } } } - public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1) + public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0) { $storage = [ 'product_id' => $product_arr['id'], @@ -167,13 +170,28 @@ class StoreStorageSend implements Consumer 'admin_id' => $admin_id, 'type' => $stock_type, ]; - if ($find['stock'] < $product_arr['stock']) { - $storage['status'] = -1; - $storage['mark'] = '库存不足,主库存为:' . $find['stock']; + $data=[ + 'warehouse_id'=>$warehouse_id, + 'product_id' => $product_arr['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']; + } SystemStoreStorage::create($storage); + WarehouseProductLogic::add($data); } else { SystemStoreStorage::create($storage); - StoreProduct::where('id', $product_arr['id'])->dec('stock', $product_arr['stock'])->update(); + WarehouseProductLogic::add($data); } } diff --git a/process/Task.php b/process/Task.php index 70503c56..a08bae71 100644 --- a/process/Task.php +++ b/process/Task.php @@ -2,6 +2,7 @@ namespace process; +use app\common\enum\OrderEnum; use app\common\logic\PayNotifyLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; @@ -26,15 +27,20 @@ class Task $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 if ($oid) { StoreOrder::where('id', 'in', $oid)->update(['delete_time' => time()]); + StoreOrderCartInfo::where('oid','in',$oid)->update(['status'=>OrderEnum::REFUND_STATUS_FINISH]); + $arr = StoreOrderCartInfo::where('oid', 'in', $oid)->field('store_id,product_id,cart_num')->select(); $updateData = []; $updateDataTwo = []; foreach ($arr as $v) { - $updateData[] = [ - 'id' => $v['branch_product_id'], - 'sales' => ['dec', $v['cart_num']], - 'stock' => ['inc', $v['cart_num']], - ]; + $id=StoreBranchProduct::where('product_id',$v['product_id'])->where('store_id',$v['store_id'])->value('id'); + if($id){ + $updateData[] = [ + 'id' => $id, + 'sales' => ['dec', $v['cart_num']], + 'stock' => ['inc', $v['cart_num']], + ]; + } $updateDataTwo[] = [ 'id' => $v['product_id'], 'sales' => ['dec', $v['cart_num']]