diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php new file mode 100644 index 000000000..099160da1 --- /dev/null +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -0,0 +1,154 @@ +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 + */ + public function orderTransferAdvanceOrder() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $params['mark'] = '订单转预定单'; + $result = BeforehandOrderLogic::orderTransferAdvanceOrder($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); + } + + /** + * 导出标签 + */ + public function export() + { + $params = $this->request->post(); + $outbound_id = BeforehandOrder::where('id', $params['id'])->value('outbound_id'); + if(!$outbound_id){ + return $this->fail('未生成出库单'); + } + $warehouseOrder = WarehouseOrder::where('id', $outbound_id)->field('store_id,delivery_time')->find(); + $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name'); + $data = WarehouseProduct::where('oid', $outbound_id)->field('product_id,nums')->select() + ->each(function ($item) use ($system_store,$warehouseOrder) { + $item['system_store'] = $system_store; + $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find(); + $item['store_name'] = $find['store_name']; + $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']); + }) + ->toArray(); + $file_path=(new Beforehand())->export($data, $system_store); + return $this->success('导出成功', ['url' => $file_path]); + } +} 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..deb30eee9 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,26 +58,12 @@ class SystemStoreStorageController extends BaseAdminController */ public function edit() { - return $this->fail('暂不支持入库操作'); - - // $params = (new SystemStoreStorageValidate())->post()->goCheck('edit'); - // $params['admin_id']=$this->adminId; - // $result = SystemStoreStorageLogic::edit($params); - // if (true === $result) { - // return $this->success('编辑成功', [], 1, 1); - // } - // return $this->fail(SystemStoreStorageLogic::getError()); $id = $this->request->post('id',0); 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(); - return $this->success('操作成功',[]); - } - return $this->fail('操作失败'); + SystemStoreStorageLogic::edit(['id'=>$id,'admin_id'=>$this->adminId]); + return $this->success('操作成功',[]); } diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index 5c0a32030..b6b4c6fa1 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -17,6 +17,7 @@ use app\common\model\system_store\SystemStore; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; +use app\common\service\xlsx\Beforehand; use app\common\service\xlsx\OrderDetail; use app\common\service\xlsx\WarehouseOrdeRentry; use support\exception\BusinessException; @@ -275,4 +276,25 @@ class WarehouseOrderController extends BaseAdminController return $this->success('导出成功', ['url' => $file_path]); } + + /** + * 导出标签 + */ + public function export_tags() + { + $id = $this->request->post('id'); + $warehouseOrder = WarehouseOrder::where('id', $id)->field('store_id,delivery_time')->find(); + $system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('name'); + $data = WarehouseProduct::where('oid', $id)->where('financial_pm',0)->field('product_id,nums')->select() + ->each(function ($item) use ($system_store,$warehouseOrder) { + $item['system_store'] = $system_store; + $find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->find(); + $item['store_name'] = $find['store_name']; + $unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); + $item['unit_name'] = $item['nums'].'/'.$unit_name.' '.date('m-d',$warehouseOrder['delivery_time']); + }) + ->toArray(); + $file_path=(new Beforehand())->export($data, $system_store); + 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/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php new file mode 100644 index 000000000..51a1532aa --- /dev/null +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -0,0 +1,255 @@ + $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 orderTransferAdvanceOrder(array $params): bool + { + Db::startTrans(); + try { + $datas = []; + + $order=StoreOrder::where('id', $params['id'])->find(); + $info=StoreOrderCartInfo::where('oid', $params['id'])->select(); + $total_num = $order['total_num']; + $total_price = $order['total_price']; + $uid = $order['uid']; + foreach ($info as $k => $v) { + $datas[$k]['product_id'] = $v['product_id']; + $datas[$k]['uid'] = $uid; + $datas[$k]['cart_num'] = $v['cart_num']; + $datas[$k]['purchase'] = $v['purchase']; + $datas[$k]['price'] = $v['price']; + $datas[$k]['total_price'] = $v['total_price']; + $datas[$k]['create_time'] = time(); + $datas[$k]['update_time'] = time(); + $total_num += $v['nums']; + } + $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 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/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 21eea8686..f1c0d8847 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -2,7 +2,7 @@ namespace app\admin\logic\system_store_storage; - +use app\admin\logic\store_product\StoreProductLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue; use app\common\model\system_store_storage\SystemStoreStorage; @@ -61,18 +61,25 @@ class SystemStoreStorageLogic extends BaseLogic */ public static function edit(array $params): bool { - return true; Db::startTrans(); try { - SystemStoreStorage::where('id', $params['id'])->update([ - 'nums' => $params['nums'], - 'admin_id' => $params['admin_id'], - 'status' => 0, - 'mark' => '', - ]); + $find=SystemStoreStorage::where(['id' => $params['id']])->find(); + + if($find){ + $find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'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'], 0, $storeProduct); + $storeBranchProduct->stock = $find['nums']; + $storeBranchProduct->save(); + } + } Db::commit(); return true; - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); 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/order/OrderController.php b/app/api/controller/order/OrderController.php index 9b0e7b86c..c5ef5d356 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -462,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 a9b554b3b..c79f33f5d 100644 --- a/app/api/controller/store/StoreController.php +++ b/app/api/controller/store/StoreController.php @@ -205,13 +205,13 @@ class StoreController extends BaseApiController */ public function menu_list(){ $menu=[ - ['name'=>'每日配送统计','url'=>'/pagesOrder/deliveryOrder/index'], - ['name'=>'累计配送统计','url'=>'/pagesOrder/deliveryOrder/count'], + // ['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'], + // ['name'=>'店铺收支','url'=>'/pagesOrder/statistics/index'], ]; return $this->success('ok',['menu'=>$menu]); } diff --git a/app/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php index a9eb68379..2088a7ba3 100644 --- a/app/api/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -2,11 +2,13 @@ namespace app\api\controller\system_store_storage; - +use app\admin\logic\store_product\StoreProductLogic; +use app\admin\logic\system_store_storage\SystemStoreStorageLogic; use app\api\controller\BaseApiController; use app\api\lists\system_store_storage\SystemStoreStorageLists; use app\api\lists\system_store_storage\SystemStoreStorageGroupLists; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\system_store\SystemStoreStaff; use app\common\model\system_store_storage\SystemStoreStorage; @@ -25,11 +27,11 @@ class SystemStoreStorageController extends BaseApiController */ public function lists() { - $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); - if(!$store_id){ + $store_id = SystemStoreStaff::where('uid', $this->userId)->value('store_id'); + if (!$store_id) { return $this->fail('请先绑定店铺'); } - $this->request->__set('store_id',$store_id); + $this->request->__set('store_id', $store_id); return $this->dataLists(new SystemStoreStorageLists()); } /** @@ -40,26 +42,22 @@ class SystemStoreStorageController extends BaseApiController */ public function group_lists() { - $store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); - if(!$store_id){ + $store_id = SystemStoreStaff::where('uid', $this->userId)->value('store_id'); + if (!$store_id) { return $this->fail('请先绑定店铺'); } - $this->request->__set('store_id',$store_id); + $this->request->__set('store_id', $store_id); return $this->dataLists(new SystemStoreStorageGroupLists()); } /** * @notes 门店入库 */ - public function warehousing_add() { + public function warehousing_add() + { $params = $this->request->post(); - $find=SystemStoreStorage::where('id',$params['id'])->find(); - if($find){ - $find->status=1; - $find->save(); - StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update(); - return $this->success('操作成功'); - } - return $this->fail('操作失败'); + $id = SystemStoreStaff::where('uid', $this->userId)->value('id'); + SystemStoreStorageLogic::edit(['id'=>$params['id'],'staff_id'=>$id,'admin_id'=>0]); + return $this->success('操作成功'); } } diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 8f39e9738..cf361f98e 100644 --- a/app/common/logic/CommissionProductLogic.php +++ b/app/common/logic/CommissionProductLogic.php @@ -23,11 +23,9 @@ class CommissionProductLogic extends BaseLogic */ function calculate_product_flow($find, $order, $village_uid = 0, $brigade_uid = 0, $user_ship = 0, $spread_user_ship = 0) { - if(isset($order['source']) && $order['source'] == 2){ - $product = StoreBranchProduct::where('product_id', $find['product_id'])->where('store_id', $order['store_id'])->find(); - }else{ - $product = StoreProduct::where('id', $find['product_id'])->find(); - } + + $product = StoreProduct::where('id', $find['product_id'])->find(); + if ($product) { //活动商品 if ($product['product_type'] == 4) { @@ -64,11 +62,11 @@ class CommissionProductLogic extends BaseLogic public function a($find, $order, $village_uid, $brigade_uid, $user_ship, $product) { $total_price = bcmul($find['price'], $find['cart_num'], 2); - $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $purchase_price = bcmul($find['purchase'], $find['cart_num'], 2); $price = $find['price']; $rose=0; - $rose_price = bcsub($price, $product['purchase'], 2); + $rose_price = bcsub($price, $find['purchase'], 2); if ($rose_price > 0) { //利润除于零售 $price_div = bcdiv($rose_price, $price, 2); @@ -171,11 +169,11 @@ class CommissionProductLogic extends BaseLogic public function b($find, $order, $product, $user_ship) { $total_price = bcmul($find['price'], $find['cart_num'], 2); - $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $purchase_price = bcmul($find['purchase'], $find['cart_num'], 2); $price = $find['price']; $rose=0; - $rose_price = bcsub($price, $product['purchase'], 2); + $rose_price = bcsub($price, $find['purchase'], 2); if ($rose_price > 0) { //利润除于零售 $price_div = bcdiv($rose_price, $price, 2); @@ -220,11 +218,11 @@ class CommissionProductLogic extends BaseLogic public function c($find, $order,$product) { $total_price = bcmul($find['price'], $find['cart_num'], 2); - $purchase_price = bcmul($product['purchase'], $find['cart_num'], 2); + $purchase_price = bcmul($find['purchase'], $find['cart_num'], 2); $price = $find['price']; $rose=0; - $rose_price = bcsub($price, $product['purchase'], 2); + $rose_price = bcsub($price, $find['purchase'], 2); if ($rose_price > 0) { //利润除于零售 $price_div = bcdiv($rose_price, $price, 2); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 2647d6275..f744c12df 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -684,7 +684,7 @@ class PayNotifyLogic extends BaseLogic } try { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,price,purchase,cart_num')->select(); + $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,purchase,price,total_price,cart_num')->select(); $comm = new CommissionProductLogic(); foreach ($info as $k => $v) { $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); 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 @@ +getActiveSheet(); + + // 合并单元格A1到K1 + $kk1=1; + $kk2=2; + $kk3=3; + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 14, + ], + ]; + foreach ($data as $k => $v) { + $sheet->mergeCells('A'. ($k + $kk1).':B'.($k + $kk1)); + $sheet->setCellValue('A' . ($k + $kk1), $v['system_store'])->getStyle('A'. ($k + $kk1))->applyFromArray($styleArray); + $sheet->mergeCells('A'. ($k + $kk2).':B'.($k + $kk2)); + $sheet->setCellValue('A' . ($k + $kk2), $v['store_name'])->getStyle('A'. ($k + $kk2))->applyFromArray($styleArray); + $sheet->mergeCells('A'. ($k + $kk3).':B'.($k + $kk3)); + $sheet->setCellValue('A' . ($k + $kk3), $v['unit_name'])->getStyle('A'. ($k + $kk3))->applyFromArray($styleArray); + $kk1=$kk1+2; + $kk2=$kk2+2; + $kk3=$kk3+2; + } + $writer = new Xlsx($spreadsheet); + $url = '/export/' . date('Y-m') . '/' . $system_store.'标签单-'.date('Y-m-d H:i') . '.xlsx'; + $file_path = public_path() . $url; + // 保存文件到 public 下 + $writer->save($file_path); + return getenv('APP_URL').$url; + } +} diff --git a/app/store/controller/system_store_storage/SystemStoreStorageController.php b/app/store/controller/system_store_storage/SystemStoreStorageController.php index 2f87b0381..f50a30d09 100644 --- a/app/store/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/store/controller/system_store_storage/SystemStoreStorageController.php @@ -40,13 +40,8 @@ class SystemStoreStorageController extends BaseAdminController if($id==0){ return $this->fail('参数错误'); } - $res=SystemStoreStorage::where(['id' => $id,'store_id'=>$this->adminInfo['store_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(); - return $this->success('操作成功',[]); - } - return $this->fail('操作失败'); + SystemStoreStorageLogic::edit(['id'=>$id,'staff_id'=>$this->adminId,'admin_id'=>0]); + return $this->success('操作成功'); }