diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php new file mode 100644 index 000000000..cfbd4a466 --- /dev/null +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -0,0 +1,110 @@ +dataLists(new BeforehandOrderLists()); + } + + public function warehousing_lists() + { + return $this->dataLists(new BeforehandOrderTwoLists()); + } + public function outbound_lists() + { + return $this->dataLists(new BeforehandOrderThreeLists()); + } + + /** + * @notes 添加预订单表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:26 + */ + public function add() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $result = BeforehandOrderLogic::add($params); + return $this->success('添加成功', [], 1, 1); + } + /** + * 一键出库 + */ + public function createOutboundOrder() + { + $params=$this->request->post(); + $params['admin_id'] = $this->adminId; + $result = BeforehandOrderLogic::createOutboundOrder($params); + + return $this->success('出库成功', [], 1, 1); + } + + /** + * @notes 编辑预订单表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:26 + */ + public function edit() + { + $params = $this->request->post(); + $result = BeforehandOrderLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(BeforehandOrderLogic::getError()); + } + + + /** + * @notes 删除预订单表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:26 + */ + public function delete() + { + $params = $this->request->post(); + BeforehandOrderLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取预订单表详情 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:26 + */ + public function detail() + { + $params = (new BeforehandOrderValidate())->goCheck('detail'); + $result = BeforehandOrderLogic::detail($params); + return $this->data($result); + } +} diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php new file mode 100644 index 000000000..e5376131e --- /dev/null +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -0,0 +1,125 @@ +dataLists(new BeforehandOrderCartInfoLists()); + } + + + /** + * @notes 添加预订单购物详情表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:32 + */ + public function add() + { + $params = $this->request->post(); + $result = BeforehandOrderCartInfoLogic::add($params); + return $this->success('添加成功', [], 1, 1); + + } + /** + * @notes 添加预订单购物详情表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:32 + */ + public function append_add() + { + $params = $this->request->post(); + $result = BeforehandOrderCartInfoLogic::appendAdd($params); + return $this->success('追加成功', [], 1, 1); + + } + + /** + * @notes 编辑预订单购物详情无需采购 + */ + public function procurement_status(){ + $id=$this->request->post('id'); + $res=BeforehandOrderCartInfo::where('id',$id)->update(['is_buyer'=>-1]); + if($res){ + return $this->success('操作成功',[],1,1); + }else{ + return $this->fail('操作失败'); + } + } + + + /** + * @notes 一键入库 + */ + public function one_click_storage(){ + $params=$this->request->post(); + $params['admin_id']=$this->adminId; + BeforehandOrderCartInfoLogic::oneClickStorage($params); + return $this->success('入库成功', [], 1, 1); + } + /** + * @notes 编辑预订单购物详情表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:32 + */ + public function edit() + { + $params = $this->request->post(); + $result = BeforehandOrderCartInfoLogic::edit($params); + return $this->success('编辑成功', [], 1, 1); + + } + + + /** + * @notes 删除预订单购物详情表 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:32 + */ + public function delete() + { + $params = $this->request->post(); + BeforehandOrderCartInfoLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取预订单购物详情表详情 + * @return \think\response\Json + * @author admin + * @date 2024/09/30 11:32 + */ + public function detail() + { + $params = $this->request->get(); + $result = BeforehandOrderCartInfoLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index 0e92a4f87..f1c5eb635 100644 --- a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -40,10 +40,8 @@ class PurchaseProductOfferController extends BaseAdminController { $params = (new PurchaseProductOfferValidate())->post()->goCheck('add'); $result = PurchaseProductOfferLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } - return $this->fail(PurchaseProductOfferLogic::getError()); + return $this->success('设置成功', [], 1, 1); + } @@ -64,12 +62,22 @@ class PurchaseProductOfferController extends BaseAdminController return $this->fail('参数错误'); break; } - if (PurchaseProductOfferLogic::hasError()) { - return $this->fail(PurchaseProductOfferLogic::getError()); - } return $this->success('设置成功', [], 1, 1); } + /** + * @notes 设置采购信息 + * @return \think\response\Json + * @author admin + * @date 2024/08/14 15:06 + */ + public function setProcureInfo() + { + $params = $this->request->post(); + PurchaseProductOfferLogic::setProcureInfo($params); + + return $this->success('设置成功', [], 1, 1); + } /** diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index efa371bbe..450daca0d 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -213,7 +213,7 @@ class StoreOrderController extends BaseAdminController 'warehouse_id' => $warehouse_id, 'store_id' => $store_id, 'supplier_id' => 0, - 'code' => getNewOrderId('PS'), + 'code' => getNewOrderId('CK'), 'admin_id' => $this->adminId, 'financial_pm' => 0, 'batch' => 0, diff --git a/app/admin/controller/system_store_storage/SystemStoreStorageController.php b/app/admin/controller/system_store_storage/SystemStoreStorageController.php index 475cd5f86..e33c3ebb2 100644 --- a/app/admin/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/admin/controller/system_store_storage/SystemStoreStorageController.php @@ -5,9 +5,11 @@ namespace app\admin\controller\system_store_storage; use app\admin\controller\BaseAdminController; use app\admin\lists\system_store_storage\SystemStoreStorageLists; +use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\system_store_storage\SystemStoreStorageLogic; use app\admin\validate\system_store_storage\SystemStoreStorageValidate; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\system_store_storage\SystemStoreStorage; /** @@ -56,7 +58,7 @@ class SystemStoreStorageController extends BaseAdminController */ public function edit() { - return $this->fail('暂不支持入库操作'); + // return $this->fail('暂不支持入库操作'); // $params = (new SystemStoreStorageValidate())->post()->goCheck('edit'); // $params['admin_id']=$this->adminId; @@ -69,10 +71,21 @@ class SystemStoreStorageController extends BaseAdminController if($id==0){ return $this->fail('参数错误'); } - $res=SystemStoreStorage::where(['id' => $id])->update(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]); - if($res){ - $find=SystemStoreStorage::where(['id' => $id])->find(); - StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update(); + $find=SystemStoreStorage::where(['id' => $id])->find(); + + if($find){ + $find->save(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]); + $branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find(); + if($branch_product){ + $branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]); + }else{ + $storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty(); + $storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], $this->adminId, $storeProduct); + $storeBranchProduct->stock = $find['nums']; + $storeBranchProduct->save(); + } + + return $this->success('操作成功',[]); } return $this->fail('操作失败'); diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 787347de1..5c0a32030 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -10,6 +10,7 @@ use app\admin\logic\warehouse_order\WarehouseOrderLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\admin\validate\warehouse_order\WarehouseOrderValidate; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_order\StoreOrder; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; @@ -228,9 +229,9 @@ class WarehouseOrderController extends BaseAdminController $total_price=0; foreach ($data as $key => &$value) { if(in_array($order['store_id'],[17,18])){ - $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->find(); + $find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->withTrashed()->find(); }else{ - $find = StoreProduct::where('id', $value->product_id)->find(); + $find = StoreProduct::where('id', $value->product_id)->withTrashed()->find(); } $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; @@ -263,6 +264,13 @@ class WarehouseOrderController extends BaseAdminController $order['delivery_time']=date('Y-m-d H:i:s',$order['delivery_time']); $order['pay_time']=$order['create_time']; $order['order_id']=$order['code']; + + if($order['oid']>0){ + $orders=StoreOrder::where('id',$order['oid'])->findOrEmpty(); + $order['real_name']=$orders['real_name']; + $order['user_phone']=$orders['user_phone']; + $order['user_address']=$orders['user_address']; + } $file_path = $xlsx->export($data, $system_store, $order); return $this->success('导出成功', ['url' => $file_path]); diff --git a/app/admin/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php new file mode 100644 index 000000000..0026a05de --- /dev/null +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -0,0 +1,71 @@ + ['store_id', 'order_id', 'uid','paid','status',], + ]; + } + + + /** + * @notes 获取预订单表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/09/30 11:26 + */ + public function lists(): array + { + return BeforehandOrder::where($this->searchWhere) + ->field(['id','order_id', 'uid','total_num','total_price','admin_id', 'pay_price', 'deduction_price','create_time', 'status', 'mark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item){ + if($item->admin_id){ + $item->admin_name=Admin::where(['id'=>$item->admin_id])->value('name'); + }else{ + $item->admin_name=''; + } + }) + ->toArray(); + } + + + /** + * @notes 获取预订单表数量 + * @return int + * @author admin + * @date 2024/09/30 11:26 + */ + public function count(): int + { + return BeforehandOrder::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php b/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php new file mode 100644 index 000000000..38ff72fc0 --- /dev/null +++ b/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php @@ -0,0 +1,85 @@ +request->get('id'))->value('outbound_id'); + if(empty($outbound_id)){ + return []; + } + $this->searchWhere[]=['oid','=',$outbound_id]; + $this->searchWhere[]=['financial_pm','=',0]; + return WarehouseProduct::where($this->searchWhere)->select() + ->each(function($item){ + $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,unit')->withTrashed()->find(); + $item['store_name']=$find['store_name']; + $item['image']=$find['image']; + if($item['unit']==0){ + $item['unit_name']=StoreProductUnit::where('id',$find['unit'])->value('name'); + }else{ + $item['unit_name']=StoreProductUnit::where('id',$item['unit'])->value('name'); + } + if($item['supplier_id']){ + $item['supplier_name']=Supplier::where('id',$item['supplier_id'])->value('mer_name'); + }else{ + $item['supplier_name']=''; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取预订单表数量 + * @return int + * @author admin + * @date 2024/09/30 11:26 + */ + public function count(): int + { + return WarehouseProduct::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php b/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php new file mode 100644 index 000000000..539019f23 --- /dev/null +++ b/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php @@ -0,0 +1,85 @@ +request->get('id'))->value('warehousing_id'); + if(empty($warehousing_id)){ + return []; + } + $this->searchWhere[]=['oid','=',$warehousing_id]; + $this->searchWhere[]=['financial_pm','=',1]; + return WarehouseProduct::where($this->searchWhere)->select() + ->each(function($item){ + $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,unit')->withTrashed()->find(); + $item['store_name']=$find['store_name']; + $item['image']=$find['image']; + if($item['unit']==0){ + $item['unit_name']=StoreProductUnit::where('id',$find['unit'])->value('name'); + }else{ + $item['unit_name']=StoreProductUnit::where('id',$item['unit'])->value('name'); + } + if($item['supplier_id']){ + $item['supplier_name']=Supplier::where('id',$item['supplier_id'])->value('mer_name'); + }else{ + $item['supplier_name']=''; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取预订单表数量 + * @return int + * @author admin + * @date 2024/09/30 11:26 + */ + public function count(): int + { + return WarehouseProduct::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php new file mode 100644 index 000000000..be622775b --- /dev/null +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -0,0 +1,82 @@ + ['bhoid', 'uid', 'product_id'], + ]; + } + + + /** + * @notes 获取预订单购物详情表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/09/30 11:32 + */ + public function lists(): array + { + return BeforehandOrderCartInfo::where($this->searchWhere) + ->field(['id', 'bhoid', 'uid', 'is_buyer','buyer_uid','product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $find=StoreProduct::where('id',$item['product_id'])->field('store_name,image,unit')->withTrashed()->find(); + $item['warehouse_stock']=WarehouseProductStorege::where('product_id',$item['product_id'])->value('nums')??0; + $item['store_name']=$find['store_name']; + $item['image']=$find['image']; + $item['unit']=$find['unit']; + if($item->bhoid){ + $status=PurchaseProductOffer::where('order_id',$item->bhoid)->where('product_id',$item->product_id)->value('status'); + if($status==1){ + $item->status_name='已完成'; + }else{ + $item->status_name='采购中'; + } + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取预订单购物详情表数量 + * @return int + * @author admin + * @date 2024/09/30 11:32 + */ + public function count(): int + { + return BeforehandOrderCartInfo::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php index 565a3c411..afd7ed30e 100644 --- a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -9,6 +9,7 @@ use app\common\lists\ListsSearchInterface; use app\common\model\delivery_service\DeliveryService; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\supplier\Supplier; /** * 采购供应链商品列表 @@ -67,6 +68,11 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc $item->buyer_confirm_name='采购完成'; } } + if($item->supplier_id>0){ + $item->supplier_name=Supplier::where('id',$item->supplier_id)->value('mer_name'); + }else{ + $item->supplier_name=''; + } if($item->is_storage==1){ $item->is_storage_name='已入库'; }else{ diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php index 7a6dab6aa..e2441d5e6 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -53,7 +53,7 @@ class StoreOrderCartInfoLists extends BaseAdminDataLists implements ListsSearchI return StoreOrderCartInfo::where($this->searchWhere) ->field('id,oid,uid,product_id,store_id,cart_num,price,total_price,create_time')->limit($this->limitOffset, $this->limitLength) ->select()->each(function ($item) { - $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->find(); + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,store_name,store_info')->withTrashed()->find(); $item['nickname']='无'; $item['mobile']=''; if($find){ diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php index 6d5716796..b07e8d8c8 100644 --- a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoTwoLists.php @@ -14,6 +14,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; +use app\common\model\user\User; /** * 订单购物详情列表 @@ -64,22 +65,40 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear $this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; } $is_group=$this->request->get('is_group'); + $export=$this->request->get('export'); $this->searchWhere[] = ['is_pay', '=', 1]; $this->searchWhere[] = ['status', '>=', 0]; $query = StoreOrderCartInfo::where($this->searchWhere); if ($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,create_time'); + $query->field('store_id,product_id,price,total_price,cart_num,create_time,uid,oid'); } return $query->limit($this->limitOffset, $this->limitLength) - ->select()->each(function ($item) use($is_group){ + ->select()->each(function ($item) use($is_group,$export){ $find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,store_name,store_info')->find(); + $item['nickname']=''; + $item['mobile']=''; + $item['order_id']=''; + if($export==2){ + $item['order_id']=StoreOrder::where('id',$item['oid'])->value('order_id'); + } if ($find) { $item['image'] = $find['image']; //商品图片 if($is_group==1){ $item['store_name'] = $find['store_name'].'-'.$item['create_time']; //商品名称 }else{ + if(isset($item['uid'])&&$item['uid']>0){ + $user=User::where('id',$item['uid'])->field('real_name,mobile')->find(); + if($user){ + $item['mobile']=$user['mobile']; + if($user['real_name']!=''){ + $item['nickname']=$user['real_name']; + }else{ + $item['nickname']=$user['mobile']; + } + } + } $item['store_name'] = $find['store_name']; //商品名称 } $item['store_info'] = $find['store_info']; //商品规格 @@ -148,6 +167,7 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear ]; } else { $data = [ + 'order_id' => '订单', 'system_store' => '门店', 'store_name' => '商品名称', 'store_info' => '规格', @@ -156,6 +176,8 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear 'cart_num' => '数量', 'price' => '单价', 'total_price' => '总价', + 'nickname' => '用户', + 'mobile' => '手机', 'create_time' => '时间', ]; } diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index db24996c7..5ca083b90 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -52,7 +52,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt { if ($this->request->get('product_id')) { $product_id = $this->request->get('product_id'); - $ids = StoreProduct::where('store_name', 'like', '%' . $product_id . '%')->column('id'); + $ids = StoreProduct::where('store_name', 'like', '%' . $product_id . '%')->withTrashed()->column('id'); if ($ids) { $this->searchWhere[] = ['product_id', 'in', $ids]; $this->ids = $ids; @@ -62,7 +62,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt } if ($this->request->get('bar_code')) { $bar_code = $this->request->get('bar_code'); - $ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->column('id'); + $ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->withTrashed()->column('id'); if ($ids) { $this->searchWhere[] = ['product_id', 'in', $ids]; $this->ids = $ids; diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php new file mode 100644 index 000000000..2d56ed909 --- /dev/null +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -0,0 +1,202 @@ + $v) { + $datas[$k]['product_id'] = $v['product_id']; + $datas[$k]['uid'] = $uid; + $datas[$k]['cart_num'] = $v['nums']; + $datas[$k]['price'] = $v['purchase']; + $datas[$k]['total_price'] = $v['total_price']; + $datas[$k]['create_time'] = time(); + $datas[$k]['update_time'] = time(); + $total_num += $v['nums']; + $total_price += $v['total_price']; + } + $order = BeforehandOrder::create([ + 'order_id' => getNewOrderId('YG'), + 'admin_id' => $params['admin_id'] ?? 0, + 'uid' => $uid, + 'total_num' => $total_num, + 'total_price' => $total_price, + 'pay_price' => 0, + 'pay_type' => 0, + 'deduction_price' => 0, + 'paid' => 0, + 'mark' => $params['mark'] ?? '' + ]); + foreach ($datas as $k => $v) { + $datas[$k]['bhoid'] = $order['id']; + } + (new BeforehandOrderCartInfo())->saveAll($datas); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑预订单表 + * @param array $params + * @return bool + * @author admin + * @date 2024/09/30 11:26 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + BeforehandOrder::where('id', $params['id'])->update([ + 'store_id' => $params['store_id'], + 'order_id' => $params['order_id'], + 'uid' => $params['uid'], + 'cart_id' => $params['cart_id'], + 'total_num' => $params['total_num'], + 'total_price' => $params['total_price'], + 'pay_price' => $params['pay_price'], + 'deduction_price' => $params['deduction_price'], + 'paid' => $params['paid'], + 'pay_time' => $params['pay_time'], + 'pay_type' => $params['pay_type'], + 'source' => $params['source'], + 'status' => $params['status'], + 'mark' => $params['mark'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + /** + * @notes 一键入库 + * @param array $params + * @return bool + * @author admin + * @date 2024/09/30 11:26 + */ + public static function createOutboundOrder(array $params): bool + { + $warehouse_id = $params['warehouse_id']; + $store_id = $params['store_id']; + $admin_id = $params['admin_id']; + $delivery_time = $params['delivery_time']; + $mark = $params['remark'] ?? ''; + $order = BeforehandOrder::where('id', $params['bhoid'])->find(); + if (!$order) { + throw new BusinessException('该订单不存在'); + } + if ($order['outbound_id'] > 0) { + throw new BusinessException('该订单已创建出库单'); + } + $info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select(); + Db::startTrans(); + try { + $arr = [ + 'oid' => 0, + 'warehouse_id' => $warehouse_id, + 'store_id' => $store_id, + 'supplier_id' => 0, + 'code' => getNewOrderId('CK'), + 'admin_id' => $admin_id, + 'financial_pm' => 0, + 'batch' => 0, + 'mark' => $mark, + ]; + $arr['delivery_time'] = strtotime($delivery_time); + $res = WarehouseOrder::create($arr); + foreach ($info as $key => $arr) { + $data = [ + 'warehouse_id' => $warehouse_id, + 'product_id' => $arr['product_id'], + 'store_id' => $store_id, + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $arr['cart_num'], + 'status' => 1, + 'admin_id' => $admin_id, + 'total_price' => $arr['total_price'], + 'purchase' => $arr['price'], + 'oid' => $res['id'], + 'code' => $res['code'], + ]; + WarehouseProductLogic::setOutbound($data); + } + $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); + BeforehandOrder::update(['outbound_id' => $res['id']], ['id' => $params['bhoid']]); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + /** + * @notes 删除预订单表 + * @param array $params + * @return bool + * @author admin + * @date 2024/09/30 11:26 + */ + public static function delete(array $params): bool + { + return BeforehandOrder::destroy($params['id']); + } + + + /** + * @notes 获取预订单表详情 + * @param $params + * @return array + * @author admin + * @date 2024/09/30 11:26 + */ + public static function detail($params): array + { + return BeforehandOrder::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php new file mode 100644 index 000000000..5a3ad6766 --- /dev/null +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -0,0 +1,190 @@ + $params['oid'], + 'uid' => $params['uid'], + 'product_id' => $params['product_id'], + 'attr_value_id' => $params['attr_value_id'], + 'is_pay' => $params['is_pay'], + 'purchase' => $params['purchase'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + 'cart_num' => $params['cart_num'], + 'old_cart_id' => $params['old_cart_id'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + /** + * @notes 追加预订单购物详情表 + */ + public static function appendAdd(array $params): bool + { + Db::startTrans(); + try { + $datas = []; + $uid = $params['uid'] ?? 0; + $bhoid = $params['id']; + foreach ($params['product_arr'] as $k => $v) { + $datas[$k]['product_id'] = $v['id']; + $datas[$k]['uid'] = $uid; + $datas[$k]['bhoid'] = $bhoid; + $datas[$k]['cart_num'] = $v['nums']; + $datas[$k]['price'] = $v['purchase']; + $datas[$k]['total_price'] = $v['total_price']; + $datas[$k]['create_time'] = time(); + $datas[$k]['update_time'] = time(); + } + (new BeforehandOrderCartInfo())->saveAll($datas); + + $info = BeforehandOrderCartInfo::where('bhoid', $bhoid)->field('sum(cart_num) as cart_num,sum(total_price) as total_price')->find(); + BeforehandOrder::where('id', $bhoid)->update(['total_price' => $info['total_price'], 'total_num' => $info['cart_num']]); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑预订单购物详情表 + * @param array $params + * @return bool + * @author admin + * @date 2024/09/30 11:32 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + BeforehandOrderCartInfo::where('id', $params['id'])->update([ + 'price' => $params['purchase'], + 'total_price' => $params['total_price'], + 'cart_num' => $params['nums'], + ]); + $bhoid = $params['bhoid']; + $info = BeforehandOrderCartInfo::where('bhoid', $bhoid)->field('sum(cart_num) as cart_num,sum(total_price) as total_price')->find(); + BeforehandOrder::where('id', $bhoid)->update(['total_price' => $info['total_price'], 'total_num' => $info['cart_num']]); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + /** + * 一键入库 + */ + public static function oneClickStorage($params) + { + $count = PurchaseProductOffer::where(['order_id' => $params['bhoid'], 'is_storage' => 0, 'buyer_nums' => 0])->count('id'); + $warehousing_id = BeforehandOrder::where('id', $params['bhoid'])->value('warehousing_id'); + + if ($count > 0 || $warehousing_id > 0) { + throw new BusinessException('请勿重复入库'); + } + $offer_list = PurchaseProductOffer::where(['order_id' => $params['bhoid'], 'is_storage' => 0])->select(); + Db::startTrans(); + try { + $code = getNewOrderId('RK'); + $arr = [ + 'warehouse_id' => $params['warehouse_id'], + 'supplier_id' => 0, + 'admin_id' => $params['admin_id'], + 'financial_pm' => 1, + 'batch' => 0, + 'code' => $code, + 'mark' => $params['remark'] ?? '', + 'total_price' => $params['total_price'], + 'completed_amount' => $params['completed_amount'] ?? 0, + 'outstanding_amount' => $params['outstanding_amount'] ?? 0, + ]; + $res = WarehouseOrder::create($arr); + foreach ($offer_list as $k => $v) { + $data['admin_id'] = $params['admin_id']; + $data['store_id'] = 0; + $data['oid'] = $res['id']; + $data['supplier_id'] = $v['supplier_id']; + $data['warehouse_id'] = $params['warehouse_id']; + $data['code'] = $code; + $data['product_id'] = $v['product_id']; + $data['nums'] = $v['buyer_nums']; + $data['purchase'] = $v['price']; + $data['total_price'] = $v['total_price']; + $data['financial_pm'] = 1; + WarehouseProductLogic::add($data); + PurchaseProductOffer::where('id', $v['id'])->update(['status' => 1, 'is_storage' => 1]); + } + BeforehandOrder::where('id', $params['bhoid'])->update(['warehousing_id' => $res['id']]); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + /** + * @notes 删除预订单购物详情表 + * @param array $params + * @return bool + * @author admin + * @date 2024/09/30 11:32 + */ + public static function delete(array $params): bool + { + return BeforehandOrderCartInfo::destroy($params['id']); + } + + + /** + * @notes 获取预订单购物详情表详情 + * @param $params + * @return array + * @author admin + * @date 2024/09/30 11:32 + */ + public static function detail($params): array + { + return BeforehandOrderCartInfo::findOrEmpty($params['id'])->toArray(); + } +} diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 32fd6aac4..54822b384 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -5,7 +5,7 @@ namespace app\admin\logic\purchase_product_offer; use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\logic\BaseLogic; -use app\common\model\delivery_service\DeliveryService; +use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use support\exception\BusinessException; use think\facade\Db; @@ -31,25 +31,17 @@ class PurchaseProductOfferLogic extends BaseLogic Db::startTrans(); try { PurchaseProductOffer::create([ - 'supplier_id' => $params['supplier_id'], 'order_id' => $params['order_id'], 'product_id' => $params['product_id'], - 'price' => $params['price'], - 'nums' => $params['nums'], 'unit' => $params['unit'], 'is_buyer' => $params['is_buyer'], - 'buyer_confirm' => $params['buyer_confirm'], - 'is_storage' => $params['is_storage'], - 'is_stream' => $params['is_stream'], 'need_num' => $params['need_num'], - 'notes' => $params['notes'], + 'notes' => $params['notes'] ?? '', 'buyer_id' => $params['buyer_id'], - 'status' => $params['status'], - 'stream_admin_id' => $params['stream_admin_id'], - 'stream_time' => $params['stream_time'], - 'storage_admin_id' => $params['storage_admin_id'] - ]); + 'status' => 0, + ]); + BeforehandOrderCartInfo::where(['bhoid'=>$params['order_id'],'product_id'=>$params['product_id']])->update(['is_buyer'=>1]); Db::commit(); return true; } catch (\Exception $e) { @@ -92,7 +84,39 @@ class PurchaseProductOfferLogic extends BaseLogic Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + /** + * @notes 设置采购信息 + * @param array $params + * @return bool + * @author admin + * @date 2024/08/14 15:06 + */ + public static function setProcureInfo(array $params): bool + { + Db::startTrans(); + try { + $offer=PurchaseProductOffer::where(['id'=>$params['id']])->find(); + $offer->save([ + 'buyer_nums' => $params['buyer_nums'], + 'supplier_id' => $params['supplier_id'], + 'price' => $params['purchase'], + 'total_price' => $params['total_price'], + ]); + $find=BeforehandOrderCartInfo::where(['bhoid'=>$params['bhoid'],'product_id'=>$offer['product_id']])->find(); + if($find){ + $find->purchase=$params['purchase']; + $find->total_price=bcmul($find['cart_num'],$params['price'],2); + $find->price=$params['price']; + $find->save(); + } + Db::commit(); + return true; + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } @@ -103,20 +127,20 @@ class PurchaseProductOfferLogic extends BaseLogic */ public static function buyer($params) { - if($params['is_buyer']==1){ - if($params['buyer_id']==''){ + if ($params['is_buyer'] == 1) { + if ($params['buyer_id'] == '') { throw new BusinessException('采购人不能为空'); } - $data['buyer_id']=$params['buyer_id']; - $data['buyer_nums']=$params['buyer_nums']; + $data['buyer_id'] = $params['buyer_id']; + $data['buyer_nums'] = $params['buyer_nums']; } Db::startTrans(); try { - $data['is_buyer']=$params['is_buyer']; + $data['is_buyer'] = $params['is_buyer']; PurchaseProductOffer::where('id', $params['id'])->update($data); Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 02a3e8f97..57a1a28d2 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -49,7 +49,12 @@ class StoreOrderLogic extends BaseLogic $v['store_id'] = $params['store_id']; $v['cart_num'] = $v['stock']; if(in_array($params['store_id'],$vendors_store)){ - StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $v['price']]); + if(isset($v['purchase']) && $v['purchase'] > 0){ + $purchase = $v['purchase']; + }else{ + $purchase=$v['price']; + } + StoreBranchProduct::where('id', $v['id'])->update(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]); } unset($v['id']); $res = CartLogic::add($v); @@ -127,49 +132,21 @@ class StoreOrderLogic extends BaseLogic $refund = (new \app\common\logic\store_order\StoreOrderLogic()) ->refund($params['order_id'], $money, $pay_price); if ($refund) { - $refund_price = $params['refund_price']; - $refund_num = 0; - foreach ($params['product_arr'] as $k => $v) { - $find = StoreOrderCartInfo::where('oid', $detail['id'])->where('product_id', $v['product_id'])->find(); - if ($find) { - $refund_num += $v['cart_num']; - $cart_num = bcsub($find['cart_num'], $v['cart_num']); - $total_price = bcmul($find['price'], $cart_num); - $data = ['cart_num' => $cart_num, 'total_price' => $total_price]; - StoreOrderCartInfo::where('id', $find['id'])->update($data); - $arr = StoreFinanceFlowProduct::where('oid', $detail['id'])->where('product_id', $v['product_id'])->select()->toArray(); - foreach ($arr as $key => $value) { - $value['cart_num'] = $cart_num; - $value['total_price'] = bcmul($cart_num, $value['price'], 2); - $value['number'] = bcmul($value['total_price'], $value['rate'], 2); - StoreFinanceFlowProduct::where('id', $value['id'])->update(['delete_time' => time()]); - unset($value['id']); - $value['create_time'] = strtotime($value['create_time']); - $value['update_time'] = strtotime($value['update_time']); - StoreFinanceFlowProduct::create($value); - } - } - } - $village_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 14)->value('other_uid'); - $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); - $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); - StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); - $detail['refund_price']=$refund_price; - CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); - - StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); + self::refundProduct($detail, $params); return '退款成功'; } } //余额支付 采购款支付 if (in_array($detail['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { PayNotifyLogic::balance_purchase_refund($detail,0,$params['refund_price']); + self::refundProduct($detail, $params); return '退款成功'; } //现金支付 if ($detail['pay_type'] = PayEnum::CASH_PAY) { PayNotifyLogic::cash_refund($params['order_id']); + self::refundProduct($detail, $params); return '退款成功'; } @@ -203,7 +180,7 @@ class StoreOrderLogic extends BaseLogic } } - public function refundProduct($detail, $params) + public static function refundProduct($detail, $params) { $refund_price = $params['refund_price']; $refund_num = 0; @@ -232,9 +209,9 @@ class StoreOrderLogic extends BaseLogic $brigade_uid = StoreFinanceFlow::where('order_id', $detail['id'])->where('financial_type', 15)->value('other_uid'); $transaction_id = StoreFinanceFlow::where('order_id', $detail['id'])->value('transaction_id'); StoreFinanceFlow::where('order_id', $detail['id'])->update(['delete_time' => time()]); + $detail['refund_price']=$refund_price; CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); - StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]); } } diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 336528981..69b21bbb1 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -52,7 +52,7 @@ class WarehouseProductLogic extends BaseLogic // if ($after_nums < 0) { // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // } - WarehouseProductStorege::update(['nums'=>$after_nums, 'total_price' => $total_price],['id'=> $storege['id']]); + WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]); //门店加库存 $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); @@ -74,7 +74,7 @@ class WarehouseProductLogic extends BaseLogic throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); - WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price],['id'=>$storege['id']]); + WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]); } } $before_nums = $storege['nums']; @@ -85,16 +85,16 @@ class WarehouseProductLogic extends BaseLogic throw new BusinessException('商品不存在'); } $total_price = bcmul($after_nums, $storeProduct['purchase'], 2); - $data=[ + $data = [ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], 'nums' => $params['nums'], - 'total_price'=>$total_price + 'total_price' => $total_price ]; - if($params['financial_pm']==0){ - $data['nums']=-$params['nums']; + if ($params['financial_pm'] == 0) { + $data['nums'] = -$params['nums']; } - $storege=WarehouseProductStorege::create($data); + $storege = WarehouseProductStorege::create($data); } $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 = [ @@ -141,6 +141,59 @@ class WarehouseProductLogic extends BaseLogic } } + /** + * 设置出库商品 + */ + public static function setOutbound(array $params, $type = 1) + { + Db::startTrans(); + try { + $after_nums = 0; + $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); + if ($storege) { + SystemStoreStorage::create([ + 'store_id' => $params['store_id'], + 'admin_id' => $params['admin_id'], + 'staff_id' => 0, + 'type' => 1, + 'product_id' => $params['product_id'], + 'nums' => $params['nums'], + 'status' =>0 + ]); + $after_nums = bcsub($storege['nums'], $params['nums']); + $total_price = bcmul($after_nums, $params['purchase'], 2); + WarehouseProductStorege::update(['nums' =>bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]); + } else { + throw new BusinessException('仓库商品不存在'); + } + + $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' => $storege['nums'], + 'after_nums' => $after_nums, + 'purchase' => $params['purchase'] ?? '', + 'total_price' => $params['total_price'] ?? '', + 'admin_id' => $params['admin_id'], + 'code' => $params['code'] ?? '', + 'status' => 1, + 'mark' => $params['mark'] ?? '', + ]; + $res = WarehouseProduct::create($data); + Db::commit(); + return $res; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } /** * @notes 编辑商品仓储信息 @@ -156,28 +209,28 @@ class WarehouseProductLogic extends BaseLogic try { $before_nums = 0; $after_nums = 0; - $find=WarehouseOrder::where('id',$params['oid'])->find(); - if($find){ + $find = WarehouseOrder::where('id', $params['oid'])->find(); + if ($find) { $res = WarehouseProduct::where('id', $params['id'])->find(); - if($find['financial_pm']==1){ - WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums',$res['nums'])->update(); - StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->dec('stock',$res['nums'])->update(); - - $warehouseProductStorege=WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->find(); - WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums',$params['nums'])->update(); - StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->inc('stock',$params['nums'])->update(); - $before_nums=$warehouseProductStorege['nums']; - $after_nums=$warehouseProductStorege['nums']+$params['nums']; - }else{ - WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums',$res['nums'])->update(); - StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->dec('stock',$res['nums'])->update(); - - $warehouseProductStorege=WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->find(); - WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums',$params['nums'])->update(); - StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->inc('stock',$params['nums'])->update(); - $before_nums=$warehouseProductStorege['nums']; - $after_nums=bcsub($warehouseProductStorege['nums'],$params['nums'],2); + if ($find['financial_pm'] == 1) { + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update(); + StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update(); + + $warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find(); + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $params['nums'])->update(); + StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update(); + $before_nums = $warehouseProductStorege['nums']; + $after_nums = $warehouseProductStorege['nums'] + $params['nums']; + } else { + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update(); + StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update(); + + $warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find(); + WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $params['nums'])->update(); + StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update(); + $before_nums = $warehouseProductStorege['nums']; + $after_nums = bcsub($warehouseProductStorege['nums'], $params['nums'], 2); } WarehouseProduct::where('id', $params['id'])->update([ 'nums' => $params['nums'], @@ -241,14 +294,15 @@ class WarehouseProductLogic extends BaseLogic * @param $id * @return void */ - public static function settlement($id){ + public static function settlement($id) + { Db::startTrans(); try { - $find=WarehouseProduct::where(['id'=>$id,'financial_pm'=>1,'is_pay'=>0])->find(); - if($find){ - $find->is_pay=1; + $find = WarehouseProduct::where(['id' => $id, 'financial_pm' => 1, 'is_pay' => 0])->find(); + if ($find) { + $find->is_pay = 1; $find->save(); - } else{ + } else { throw new BusinessException('没有查到出入库信息'); } Db::commit(); diff --git a/app/admin/validate/purchase_product_offer/PurchaseProductOfferValidate.php b/app/admin/validate/purchase_product_offer/PurchaseProductOfferValidate.php index fedc5e9a7..2322ebcbb 100644 --- a/app/admin/validate/purchase_product_offer/PurchaseProductOfferValidate.php +++ b/app/admin/validate/purchase_product_offer/PurchaseProductOfferValidate.php @@ -52,7 +52,7 @@ class PurchaseProductOfferValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['supplier_id','product_id','price','nums','is_buyer','need_num']); + return $this->only(['product_id','is_buyer','need_num']); } diff --git a/app/api/controller/branch_product/BranchProductController.php b/app/api/controller/branch_product/BranchProductController.php new file mode 100644 index 000000000..df4786119 --- /dev/null +++ b/app/api/controller/branch_product/BranchProductController.php @@ -0,0 +1,22 @@ +userId)->value('store_id'); + $this->request->__set('store_id',$store_id); + return $this->dataLists(new BranchProductLists()); + } +} diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 3a126f617..c5ef5d356 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -339,18 +339,12 @@ class OrderController extends BaseApiController public function detail() { $order_id = (int)$this->request->get('order_id'); - $lat = $this->request->get('lat', ''); - $lng = $this->request->get('long', ''); $where = [ 'id' => $order_id, 'uid' => $this->userId, ]; $url = 'https://' . $this->request->host(true); - $parm = [ - 'lat' => $lat, - 'long' => $lng - ]; - $order = OrderLogic::detail($where, $url, $parm); + $order = OrderLogic::detail($where, $url); if ($order) { return $this->data($order); } else { @@ -468,9 +462,9 @@ class OrderController extends BaseApiController $params = (new OrderValidate())->post()->goCheck('add'); $uid = $this->userId; //拆单逻辑 - $res = OrderLogic::dealRefund($uid, $params); - $detail = StoreOrder::where('id', $params['id'])->where('refund_status', 1)->find(); - if ($detail && $res != 2) { + // $res = OrderLogic::dealRefund($uid, $params); + $detail = StoreOrder::where('id', $params['id'])->where('uid',$uid)->where('status','<>',2)->where('paid',1)->find(); + if ($detail) { $res = StoreOrderLogic::refund($detail, ['order_id' => $detail['order_id']]); if ($res != false) { return $this->success($res); diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php index cbf9528f2..a9b554b3b 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -13,10 +13,15 @@ use app\common\enum\PayEnum; use app\common\logic\PaymentLogic; use app\common\logic\PayNotifyLogic; use app\common\model\Config; +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\system_store\SystemStoreStaff; use app\common\model\user\User; use app\common\model\user\UserAddress; use app\common\model\user_create_log\UserCreateLog; use app\common\model\user_recharge\UserRecharge; +use app\common\model\warehouse_product\WarehouseProduct; use app\common\service\Curl; use Exception; use support\Cache; @@ -194,4 +199,58 @@ class StoreController extends BaseApiController return $this->success('ok',['count'=>$count,'create_log'=>$createLog]); } + + /** + * 小程序导航 + */ + public function menu_list(){ + $menu=[ + ['name'=>'每日配送统计','url'=>'/pagesOrder/deliveryOrder/index'], + ['name'=>'累计配送统计','url'=>'/pagesOrder/deliveryOrder/count'], + ['name'=>'每日销量统计','url'=>'/pagesOrder/productSales/index'], + ['name'=>'累计销量统计','url'=>'/pagesOrder/productSales/count'], + ['name'=>'商品库存','url'=>'/pagesOrder/store_product/index'], + ['name'=>'订单列表','url'=>'/pagesOrder/delivery/index'], + ['name'=>'店铺收支','url'=>'/pagesOrder/statistics/index'], + ]; + return $this->success('ok',['menu'=>$menu]); + } + + /** + * 店铺收支 + */ + public function store_statistics(){ + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + if(!$store_id){ + return $this->fail('请先绑定店铺'); + } + $total_price=WarehouseProduct::where('store_id',$store_id)->where('financial_pm',0)->sum('total_price'); + $order=StoreOrder::where('store_id',$store_id)->where('refund_status',0)->field('sum(refund_price) as refund_price,sum(pay_price) as pay_price')->find(); + $pay_price=bcsub($order['pay_price'],$order['refund_price'],2); + + $commission=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',3)->sum('number'); + $bond=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',11)->sum('number'); + $vip=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',12)->sum('number'); + $village=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',14)->sum('number'); + $brigade=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',15)->sum('number'); + $attrition=StoreFinanceFlow::where('store_id',$store_id)->where('financial_pm',0)->where('financial_type',16)->sum('number'); + + $money=bcadd($commission,$bond,2); + $money=bcadd($money,$vip,2); + $money=bcadd($money,$village,2); + $money=bcadd($money,$brigade,2); + $expenditure=bcadd($money,$attrition,2); + + + $store_money=SystemStore::where('id',$store_id)->value('store_money'); + + $list=[ + ['name'=>'手续费','data'=>[$commission]], + ['name'=>'保证金','data'=>[$bond]], + ['name'=>'厨师','data'=>[$vip]], + ['name'=>'村长','data'=>[$village]], + ['name'=>'队长','data'=>[$brigade]], + ]; + return $this->success('ok',['total_price'=>$total_price,'pay_price'=>$pay_price,'list'=>$list,'attrition'=>$attrition,'store_money'=>$store_money,'expenditure'=>$expenditure]); + } } diff --git a/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php new file mode 100644 index 000000000..5134d6129 --- /dev/null +++ b/app/api/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -0,0 +1,37 @@ +userId)->value('store_id'); + $this->request->__set('store_id',$store_id); + return $this->dataLists(new StoreOrderCartInfoLists()); + } + + public function group_lists() + { + $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); + $this->request->__set('store_id',$store_id); + return $this->dataLists(new StoreOrderCartInfoGroupLists()); + } +} diff --git a/app/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php new file mode 100644 index 000000000..37a98012e --- /dev/null +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -0,0 +1,79 @@ +userId)->value('store_id'); + if (!$store_id) { + return $this->fail('请先绑定店铺'); + } + $this->request->__set('store_id', $store_id); + return $this->dataLists(new SystemStoreStorageLists()); + } + /** + * @notes 获取商品分类列表 + * @return + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function group_lists() + { + $store_id = SystemStoreStaff::where('uid', $this->userId)->value('store_id'); + if (!$store_id) { + return $this->fail('请先绑定店铺'); + } + $this->request->__set('store_id', $store_id); + return $this->dataLists(new SystemStoreStorageGroupLists()); + } + + /** + * @notes 门店入库 + */ + public function warehousing_add() + { + $params = $this->request->post(); + $find = SystemStoreStorage::where('id', $params['id'])->find(); + if ($find) { + $id = SystemStoreStaff::where('uid', $this->userId)->value('id'); + $find->staff_id = $id; + $find->mark = '入库时间:' . date('Y-m-d H:i:s'); + $find->status = 1; + $find->save(); + + $branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find(); + if($branch_product){ + $branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]); + }else{ + $storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty(); + $storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct); + $storeBranchProduct->stock = $find['nums']; + $storeBranchProduct->save(); + } + return $this->success('操作成功'); + } + return $this->fail('操作失败'); + } +} diff --git a/app/api/lists/branch_product/BranchProductLists.php b/app/api/lists/branch_product/BranchProductLists.php new file mode 100644 index 000000000..d4853886e --- /dev/null +++ b/app/api/lists/branch_product/BranchProductLists.php @@ -0,0 +1,98 @@ + [ 'cate_id', 'top_cate_id', 'two_cate_id'], + '%pipe_like%' => ['store_name' => 'store_name|bar_code'], + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['sell' => 'price', 'sales' => 'sales',]; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['sort'=>'desc','price' => 'asc', 'id' => 'desc']; + } + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function lists(): array + { + $store_id = $this->request->__get('store_id'); + if (!$store_id) return []; + + $fields = 'id,top_cate_id,cate_id,product_id,store_name,cost,vip_price,purchase,price,bar_code,image,sales,store_info,unit,batch,two_cate_id,stock,total_price'; + + $this->searchWhere[] = ['status', '=', 1]; + $this->searchWhere[] = ['store_id', '=', $store_id]; + $this->searchWhere[] = ['product_type', 'in', [0,4]]; + return StoreBranchProduct::where($this->searchWhere) + ->field($fields) + ->with(['className', 'unitName']) + ->limit($this->limitOffset, $this->limitLength) + ->order($this->sortOrder) + ->select()->each(function($item){ + $item->distribution_nums=WarehouseProduct::where(['store_id'=>$item['store_id'],'product_id'=>$item['product_id'],'financial_pm'=>0])->sum('nums'); + $item->sales=StoreOrderCartInfo::where(['product_id'=>$item['product_id'],'store_id'=>$item['store_id'],'is_pay'=>1])->sum('cart_num'); + }) + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + return StoreBranchProduct::where($this->searchWhere) + ->count(); + } +} diff --git a/app/api/lists/order/OrderList.php b/app/api/lists/order/OrderList.php index 5e6652654..525ebac18 100644 --- a/app/api/lists/order/OrderList.php +++ b/app/api/lists/order/OrderList.php @@ -46,7 +46,6 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface $userId = $this->request->userId; if (!$userId) return []; $data = StoreOrder::with(['store'])->where($this->searchWhere)->where(['uid'=>$userId]) - ->whereIn('shipping_type',[1,2]) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() diff --git a/app/api/lists/store_order_cart_info/StoreOrderCartInfoGroupLists.php b/app/api/lists/store_order_cart_info/StoreOrderCartInfoGroupLists.php new file mode 100644 index 000000000..31aaa6659 --- /dev/null +++ b/app/api/lists/store_order_cart_info/StoreOrderCartInfoGroupLists.php @@ -0,0 +1,96 @@ + 'create_time' + ]; + } + + + /** + * @notes 获取地址列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @date 2024/04/27 11:26 + */ + public function lists(): array + { + $store_id = $this->request->__get('store_id'); + if (!$store_id) return []; + if ($this->request->get('store_name')) { + $store_name = $this->request->get('store_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + } else { + return []; + } + } + $this->searchWhere[] = ['is_pay', '=', 1]; + $this->searchWhere[] = ['status', '>=', 0]; + $this->searchWhere[] = ['store_id', '=', $store_id]; + $query = StoreOrderCartInfo::where($this->searchWhere); + $query->field('store_id,product_id,price,sum(total_price) as total_price,sum(cart_num) as cart_num'); + return $query->limit($this->limitOffset, $this->limitLength) + ->group('product_id') + ->select()->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->field('image,unit,cate_id,store_name,store_info')->withTrashed()->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 + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return StoreOrderCartInfo::where($this->searchWhere)->count(); + } +} diff --git a/app/api/lists/store_order_cart_info/StoreOrderCartInfoLists.php b/app/api/lists/store_order_cart_info/StoreOrderCartInfoLists.php new file mode 100644 index 000000000..b15faf5b0 --- /dev/null +++ b/app/api/lists/store_order_cart_info/StoreOrderCartInfoLists.php @@ -0,0 +1,96 @@ + 'create_time' + ]; + } + + + /** + * @notes 获取地址列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @date 2024/04/27 11:26 + */ + public function lists(): array + { + $store_id=$this->request->__get('store_id'); + if(!$store_id) return []; + if ($this->request->get('store_name')) { + $store_name = $this->request->get('store_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + } else { + return []; + } + } + $this->searchWhere[] = ['is_pay', '=', 1]; + $this->searchWhere[] = ['status', '>=', 0]; + $this->searchWhere[] = ['store_id', '=', $store_id]; + $query = StoreOrderCartInfo::where($this->searchWhere); + $query->field('store_id,product_id,price,total_price,cart_num,create_time,uid,oid'); + 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')->withTrashed()->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 + * @date 2024/04/27 11:26 + */ + public function count(): int + { + return StoreOrderCartInfo::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php b/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php new file mode 100644 index 000000000..f44c869fc --- /dev/null +++ b/app/api/lists/system_store_storage/SystemStoreStorageGroupLists.php @@ -0,0 +1,120 @@ + 'create_time', + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return []; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['id' => 'desc']; + } + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function lists(): array + { + $store_id=$this->request->__get('store_id'); + if(!$store_id){ + return []; + } + $this->searchWhere[] = ['store_id', '=', $store_id]; + $fields = 'store_id,product_id,sum(nums) as nums,mark'; + if ($this->request->get('store_name')) { + $store_name = $this->request->get('store_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + } else { + return []; + } + } + $this->searchWhere[] = ['type', '=', 1]; + $this->searchWhere[] = ['status', '=', 1]; + return SystemStoreStorage::where($this->searchWhere) + ->field($fields) + ->group('product_id') + ->limit($this->limitOffset, $this->limitLength) + ->order($this->sortOrder) + ->select()->each(function ($item) { + $find=StoreProduct::where('id', $item['product_id'])->with(['className', 'unitName']) + ->field('id,store_name,image,unit,cate_id,store_info')->find(); + if($find){ + $item['store_name'] = $find['store_name']; + $item['image'] = $find['image']; + $item['unit_name'] = $find['unit_name']; + $item['class_name'] = $find['class_name']; + $item['store_info'] = $find['store_info']; + }else{ + $item['product_name'] = ''; + $item['product_image'] = ''; + $item['product_unit'] = ''; + $item['product_cate'] = ''; + $item['store_info'] = ''; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + return SystemStoreStorage::where($this->searchWhere) + ->count(); + } +} diff --git a/app/api/lists/system_store_storage/SystemStoreStorageLists.php b/app/api/lists/system_store_storage/SystemStoreStorageLists.php new file mode 100644 index 000000000..eccaa3362 --- /dev/null +++ b/app/api/lists/system_store_storage/SystemStoreStorageLists.php @@ -0,0 +1,122 @@ + 'create_time', + ]; + } + /** + * @notes 设置支持排序字段 + * @return string[] + * @date 2021/12/29 10:07 + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return []; + } + + + /** + * @notes 设置默认排序 + * @return string[] + * @date 2021/12/29 10:06 + */ + public function setDefaultOrder(): array + { + return ['id' => 'desc']; + } + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function lists(): array + { + $store_id=$this->request->__get('store_id'); + if(!$store_id){ + return []; + } + $this->searchWhere[] = ['store_id', '=', $store_id]; + + $fields = 'id,store_id,staff_id,product_id,warehouse_id,nums,mark,status'; + if ($this->request->get('store_name')) { + $store_name = $this->request->get('store_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + } else { + return []; + } + } + $this->searchWhere[] = ['type', '=', 1]; + return SystemStoreStorage::where($this->searchWhere) + ->field($fields) + ->limit($this->limitOffset, $this->limitLength) + ->order($this->sortOrder) + ->select()->each(function ($item) { + if($item['staff_id']>0){ + $item['staff_name']=SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name'); + } + $find=StoreProduct::where('id', $item['product_id'])->with(['className', 'unitName']) + ->field('id,store_name,image,unit,cate_id,store_info')->find(); + if($find){ + $item['store_name'] = $find['store_name']; + $item['image'] = $find['image']; + $item['unit_name'] = $find['unit_name']; + $item['class_name'] = $find['class_name']; + $item['store_info'] = $find['store_info']; + }else{ + $item['product_name'] = ''; + $item['product_image'] = ''; + $item['product_unit'] = ''; + $item['product_cate'] = ''; + $item['store_info'] = ''; + } + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/04/23 11:28 + */ + public function count(): int + { + return SystemStoreStorage::where($this->searchWhere) + ->count(); + } +} diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index dcffaa11f..ecd3643f6 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -8,6 +8,7 @@ use app\common\enum\UserShipEnum; use app\common\enum\YesNoEnum; use app\common\logic\BaseLogic; use app\common\logic\CapitalFlowLogic; +use app\common\logic\CommissionnLogic; use app\common\logic\PayNotifyLogic; use app\common\logic\StoreFinanceFlowLogic; use app\common\logic\UserSignLogic; @@ -218,7 +219,6 @@ class OrderLogic extends BaseLogic // } //成本价 收益 $order = [ - 'create_time' => time(), 'order_id' => $params['order_id'] ?? getNewOrderId('PF'), 'total_price' => self::$total_price, //总价 'cost' => self::$cost, //成本价1- @@ -352,7 +352,7 @@ class OrderLogic extends BaseLogic Db::commit(); return $order; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } @@ -501,13 +501,11 @@ class OrderLogic extends BaseLogic if ($find) { $find['goods_list'] = StoreOrderCartInfo::where('oid', $find['id']) - ->field('product_id,cart_num nums,store_id')->select()->each(function ($item) use ($find) { + ->field('product_id,cart_num nums,store_id,price')->select()->each(function ($item) { $find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find(); - $item['store_name'] = $find['store_name']; $item['nums'] = floatval($item['nums']); $item['image'] = $find['image']; - $item['price'] = $find['price']; $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? ''; $item['msg'] = '预计48小时发货'; return $item; @@ -524,22 +522,6 @@ class OrderLogic extends BaseLogic $tmpFilename = $generator->getBarcode($find['verify_code'], $generator::TYPE_CODE_128); $find['verify_base64'] = 'data:image/png;base64,' . base64_encode($tmpFilename); } - //处理返回最近的店铺 - if ($param['lat'] && $param['long']) { - $storeAll = SystemStore::field('id,name,phone,address,detailed_address,latitude,longitude')->select()->toArray(); - $nearestStore = null; - $minDistance = PHP_FLOAT_MAX; - foreach ($storeAll as $value) { - $value['distance'] = haversineDistance($value['latitude'], $value['longitude'], $param['lat'], $param['long']); - if ($value['distance'] < $minDistance) { - $minDistance = $value['distance']; - $nearestStore = $value; - } - } - if ($nearestStore) { - $find['near_store'] = $nearestStore; - } - } } return $find; } @@ -585,8 +567,7 @@ class OrderLogic extends BaseLogic 'store_id' => $params['store_id'], 'staff_id' => $params['staff_id'] ?? 0, ], ['id' => $order['id']]); - //修改商品统计记录标识 - (new StoreProductLog())->where('oid', $order['id'])->update(['store_id' => $params['store_id']]); + (new StoreOrderCartInfo())->update([ 'verify_code' => $params['verify_code'] . '-1', 'writeoff_time' => time(), diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index b48840957..cf361f98e 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -118,9 +118,15 @@ class CommissionProductLogic extends BaseLogic $data[] =$this->attrition('零售损耗', $order, $find, $price, $total_price,$attrition_number); } } elseif ($user['user_ship'] == 1) { - $vip_number = bcmul($total_price, 0.06, 2); //会员利润 - $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); - $number1 = bcadd($number1, $vip_number, 2); + if($order['pay_type']==18 && bcsub($user['total_recharge_amount'],$user['purchase_funds'],2)<$user['first_purchase_funds']){ + + }else{ + if($rose>=10){ + $vip_number = bcmul($total_price, 0.06, 2); //会员利润 + $data[] = $this->vip_user('零售会员', $order, $find, $uid, $price, $total_price, $vip_number,0.06); + $number1 = bcadd($number1, $vip_number, 2); + } + } if ($rose >= 12 && $village_uid>0) { $village_number = bcmul($total_price, 0.01, 2); //村长利润 $data[] =$this->village('零售村长', $order, $find, $village_uid, $price, $total_price, $village_number,0.01); @@ -154,7 +160,6 @@ class CommissionProductLogic extends BaseLogic if ($rose >= 6) { $data[] = $this->platform('零售平台', $order, $find, $price, $total_price,$platform_number); } - (new StoreFinanceFlowProduct())->saveAll($data); } diff --git a/app/common/logic/CommissionnLogic.php b/app/common/logic/CommissionnLogic.php index 44b9ae9b1..d070ea47a 100644 --- a/app/common/logic/CommissionnLogic.php +++ b/app/common/logic/CommissionnLogic.php @@ -77,26 +77,35 @@ class CommissionnLogic extends BaseLogic $financeLogic->in($transaction_id, bcsub($order['pay_price'],$order['refund_price'],2), OrderEnum::USER_ORDER_PAY, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //用户订单支付 //缴纳齐全了就加商户没有就加到平台 + //查询保证金额度 和已交保证金 $money_limt = SystemStore::where('id', $order['store_id'])->field('paid_deposit,security_deposit')->find(); - $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); //保证金剩余额度 + //保证金剩余额度 + $deposit = bcsub($money_limt['security_deposit'], $money_limt['paid_deposit'], 2); + //门店利润 $store_profit = StoreFinanceFlowProduct::where('oid', $order['id'])->where('type', $type)->sum('number'); if ($deposit > 0) { + //如果保证金大于利润就全部扣除利润到保证金中 if ($deposit > $store_profit) { if ($store_profit > 0) { + //添加到门店保证中 $financeLogic->out($transaction_id, $store_profit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); + //添加到门店余额中 $financeLogic->in($transaction_id, 0, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } else { + //利润减去保证金 $money = bcsub($store_profit, $deposit, 2); if ($deposit > 0) { $financeLogic->out($transaction_id, $deposit, OrderEnum::ORDER_MARGIN, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); } if ($money) { + //添加到门店余额中 $financeLogic->in($transaction_id, $money, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } } else { if ($store_profit > 0) { + //添加到门店余额中 $financeLogic->in($transaction_id, $store_profit, OrderEnum::MERCHANT_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']); //平台手续费 } } diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index d2a0dea39..f744c12df 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -855,7 +855,7 @@ class PayNotifyLogic extends BaseLogic $updateData[] = [ 'id' => $StoreBranchProduct['id'], 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], - // 'sales' => ['inc', $v['cart_num']] + 'sales' => ['dec', $v['cart_num']] // 'sales' => ['inc', $v['cart_num']] ]; } diff --git a/app/common/logic/PaymentLogic.php b/app/common/logic/PaymentLogic.php index 433c6a625..f834602a8 100644 --- a/app/common/logic/PaymentLogic.php +++ b/app/common/logic/PaymentLogic.php @@ -90,7 +90,7 @@ class PaymentLogic extends BaseLogic 'auth_code' => (string)$auth_code ], 'amount' => [ - 'total' => intval($order['pay_price'] * 100), + 'total' => intval(bcmul($order['pay_price'],100)), ], 'scene_info' => [ "store_info" => [ diff --git a/app/common/logic/StoreFinanceFlowLogic.php b/app/common/logic/StoreFinanceFlowLogic.php index 98b3131be..1a2e06f8a 100644 --- a/app/common/logic/StoreFinanceFlowLogic.php +++ b/app/common/logic/StoreFinanceFlowLogic.php @@ -146,13 +146,20 @@ class StoreFinanceFlowLogic extends BaseLogic */ public function updateStatusStore($order_id, $store_id, $money, $deposit) { - 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, 'store'); if ($money > 0) { - $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money'); - SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); + //判断是否是押金 + if($store['paid_deposit']<$store['security_deposit']){ + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 11])->update(['status' => 1,'number'=>$money]); + StoreFinanceFlow::where(['order_id' => $order_id, 'financial_type' => 2])->update(['status' => 1,'number'=>0]); + + $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $money,'','paid_deposit'); + SystemStore::where('id', $store_id)->inc('paid_deposit', $money)->update(); + }else{ + $capitalFlowDao->storeIncome('store_money_add', 'order', $order_id, $money,'','store_money'); + SystemStore::where('id', $store_id)->inc('store_money', $money)->update(); + } } if ($deposit > 0) { $capitalFlowDao->storeIncome('store_paid_deposit_add', 'order', $order_id, $deposit,'','paid_deposit'); diff --git a/app/common/model/beforehand_order/BeforehandOrder.php b/app/common/model/beforehand_order/BeforehandOrder.php new file mode 100644 index 000000000..e7944436d --- /dev/null +++ b/app/common/model/beforehand_order/BeforehandOrder.php @@ -0,0 +1,22 @@ +hasOne(StoreProduct::class,'id','product_id'); } - + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where),'branch_product','更新前'); + } + } + } catch (Throwable $e) { + Log::error('branch_product:' . $e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'branch_product','更新前'); channelLog($data->toArray(),'branch_product','更新后'); }catch(Throwable $e){ Log::error('branch_product:'.$e->getMessage()); diff --git a/app/common/model/store_finance_flow/StoreFinanceFlow.php b/app/common/model/store_finance_flow/StoreFinanceFlow.php index 38f79b90c..c1e701280 100644 --- a/app/common/model/store_finance_flow/StoreFinanceFlow.php +++ b/app/common/model/store_finance_flow/StoreFinanceFlow.php @@ -36,10 +36,22 @@ class StoreFinanceFlow extends BaseModel { return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); } - + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'store_finance_flow','更新前'); + } + } + } catch (Throwable $e) { + Log::error('store_finance_flow:' . $e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'store_finance_flow','更新前'); channelLog($data->toArray(),'store_finance_flow','更新后'); }catch(Throwable $e){ Log::error('store_finance_flow:'.$e->getMessage()); diff --git a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php index bea36cb01..daa72cf84 100644 --- a/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php +++ b/app/common/model/store_finance_flow_product/StoreFinanceFlowProduct.php @@ -18,13 +18,4 @@ class StoreFinanceFlowProduct extends BaseModel use SoftDelete; protected $name = 'store_finance_flow_product'; protected $deleteTime = 'delete_time'; - - public static function onAfterWrite($data){ - try{ - channelLog($data->getOrigin(),'store_finance_flow_product','更新前'); - channelLog($data->toArray(),'store_finance_flow_product','更新后'); - }catch(Throwable $e){ - Log::error('store_finance_flow_product:'.$e->getMessage()); - } - } } \ No newline at end of file diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index 815958362..e373c780f 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -101,12 +101,26 @@ class StoreOrder extends BaseModel ->group('days')->select()->toArray(); } + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where),'store_order','更新前'); + } + } + } catch (Throwable $e) { + Log::error('store_order:更新前' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'store_order','更新前'); channelLog($data->toArray(),'store_order','更新后'); }catch(Throwable $e){ - Log::error('store_order:'.$e->getMessage()); + Log::error('store_order:更新后'.$e->getMessage()); } } } diff --git a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php index 93b2b3518..a3c407b10 100644 --- a/app/common/model/store_order_cart_info/StoreOrderCartInfo.php +++ b/app/common/model/store_order_cart_info/StoreOrderCartInfo.php @@ -21,9 +21,23 @@ class StoreOrderCartInfo extends BaseModel return $this->hasOne(StoreBranchProduct::class,'id','product_id')->bind(['store_name','image','unit','price']); } + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'store_order_cart_info','更新前'); + } + } + } catch (Throwable $e) { + Log::error('store_order_cart_info:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'store_order_cart_info','更新前'); channelLog($data->toArray(),'store_order_cart_info','更新后'); }catch(Throwable $e){ Log::error('store_order_cart_info:'.$e->getMessage()); diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index ddcfe97e9..9dcaed539 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -33,10 +33,22 @@ class StoreProduct extends BaseModel return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); } - + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if ($find) { + channelLog(array_merge($find->toArray(), $where), 'product', '更新前'); + } + } + } catch (Throwable $e) { + Log::error('product:' . $e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'product','更新前'); channelLog($data->toArray(),'product','更新后'); }catch(Throwable $e){ Log::error('product:'.$e->getMessage()); diff --git a/app/common/model/system_store/SystemStore.php b/app/common/model/system_store/SystemStore.php index ff209e545..320d93f30 100644 --- a/app/common/model/system_store/SystemStore.php +++ b/app/common/model/system_store/SystemStore.php @@ -19,9 +19,23 @@ class SystemStore extends BaseModel protected $name = 'system_store'; protected $deleteTime = 'delete_time'; + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'system_store','更新前'); + } + } + } catch (Throwable $e) { + Log::error('system_store:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'system_store','更新前'); channelLog($data->toArray(),'system_store','更新后'); }catch(Throwable $e){ Log::error('system_store:'.$e->getMessage()); diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 704b7ed2a..78c226694 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -197,9 +197,21 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } + public static function onBeforeWrite($data){ + try{ + $where=$data->getWhere(); + if($data){ + $find=self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(),$where),'user','更新前'); + } + } + }catch(Throwable $e){ + Log::error('user:'.$e->getMessage()); + } + } public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'user','更新前'); channelLog($data->toArray(),'user','更新后'); }catch(Throwable $e){ Log::error('user:'.$e->getMessage()); diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index 24e61c73e..fb086e088 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -19,9 +19,23 @@ class WarehouseProduct extends BaseModel protected $name = 'warehouse_product'; protected $deleteTime = 'delete_time'; + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where),'warehouse_product','更新前'); + } + } + } catch (Throwable $e) { + Log::error('warehouse_product:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ try{ - channelLog($data->getOrigin(),'warehouse_product','更新前'); channelLog($data->toArray(),'warehouse_product','更新后'); }catch(Throwable $e){ Log::error('warehouse_product:'.$e->getMessage()); diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index 9d86d6924..172b611f8 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -18,10 +18,24 @@ class WarehouseProductStorege extends BaseModel use SoftDelete; protected $name = 'warehouse_product_storege'; protected $deleteTime = 'delete_time'; + + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if($find){ + channelLog(array_merge($find->toArray(), $where), 'warehouse_product_storege', '更新前'); + } + } + } catch (Throwable $e) { + Log::error('warehouse_product_storege:' . $e->getMessage()); + } + } public static function onAfterWrite($data) { try { - channelLog($data->getOrigin(), 'warehouse_product_storege', '更新前'); channelLog($data->toArray(), 'warehouse_product_storege', '更新后'); } catch (Throwable $e) { Log::error('warehouse_product_storege:' . $e->getMessage()); diff --git a/app/common/service/xlsx/OrderDetail.php b/app/common/service/xlsx/OrderDetail.php index 2fa5e115d..d210cad63 100644 --- a/app/common/service/xlsx/OrderDetail.php +++ b/app/common/service/xlsx/OrderDetail.php @@ -109,8 +109,16 @@ class OrderDetail $sheet->setCellValue('A' . $count + 12, '下单人',); $sheet->mergeCells('B' . ($count + 12) . ':C' . $count + 12); + $sheet->setCellValue('B' . ($count + 12), $order['real_name']??''); + $sheet->setCellValue('D' . $count + 12, '电话'); - + $sheet->mergeCells('E' . ($count + 12) . ':F' . $count + 12); + $sheet->setCellValue('E' . ($count + 12), $order['user_phone']??''); + + $sheet->setCellValue('G' . $count + 12, '地址'); + $sheet->mergeCells('H' . ($count + 12) . ':J' . $count + 12); + $sheet->setCellValue('H' . ($count + 12), $order['user_address']??''); + $sheet->setCellValue('A' . $count + 13, '仓库',); $sheet->mergeCells('B' . ($count + 13) . ':C' . $count + 13); $sheet->setCellValue('D' . $count + 13, '送货');