From ed151b119f8165ded6eb58251bfddb5cc886fe17 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 20 Sep 2024 09:54:43 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=BB=E8=BE=91=E5=92=8C=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=BD=A3=E9=87=91=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 6 +++--- app/common/logic/CommissionProductLogic.php | 20 +++++++++----------- app/common/logic/PayNotifyLogic.php | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index a3f0b74c8..dcffaa11f 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -149,7 +149,7 @@ class OrderLogic extends BaseLogic //利润 // $cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润 - $cart_select[$k]['purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 + $cart_select[$k]['total_purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本 $cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $price, 2); //订单支付金额 $cart_select[$k]['store_price'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //商户价 $cart_select[$k]['vip_price'] = bcmul($v['cart_num'], $find['vip_price'], 2) ?? 0; //vip售价 @@ -181,13 +181,14 @@ class OrderLogic extends BaseLogic $cart_select[$k]['cart_info'] = json_encode($cartInfo); //理论上每笔都是拆分了 $cart_select[$k]['name'] = $find['store_name']; + $cart_select[$k]['purchase'] = $find['purchase']; $cart_select[$k]['imgs'] = $find['image']; $cart_select[$k]['store_id'] = $params['store_id'] ?? 0; $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); $cart_select[$k]['total_price'] = $cart_select[$k]['pay_price']; self::$total_price = bcadd(self::$total_price, $cart_select[$k]['total_price'], 2); self::$pay_price = bcadd(self::$pay_price, $cart_select[$k]['pay_price'], 2); - self::$cost = bcadd(self::$cost, $cart_select[$k]['purchase'], 2); + self::$cost = bcadd(self::$cost, $cart_select[$k]['total_purchase'], 2); self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价 self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额 // self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额 @@ -344,7 +345,6 @@ class OrderLogic extends BaseLogic $goods_list[$k]['oid'] = $order->id; $goods_list[$k]['uid'] = $uid; $goods_list[$k]['cart_id'] = implode(',', $cartId); - $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; diff --git a/app/common/logic/CommissionProductLogic.php b/app/common/logic/CommissionProductLogic.php index 0e3e29b48..b48840957 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); @@ -166,11 +164,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); @@ -215,11 +213,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 7ec32a306..d2a0dea39 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,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); From 3a100dc66219c94b4a1c6b70fa9a0aaa4830e4a2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 30 Sep 2024 16:44:47 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=A2=84?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=A1=A8=E5=92=8C=E9=A2=84=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=AF=A6=E6=83=85=E8=A1=A8=E7=9A=84API?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeforehandOrderController.php | 92 ++++++++++++ .../BeforehandOrderCartInfoController.php | 104 +++++++++++++ .../beforehand_order/BeforehandOrderLists.php | 65 +++++++++ .../BeforehandOrderCartInfoLists.php | 70 +++++++++ .../beforehand_order/BeforehandOrderLogic.php | 135 +++++++++++++++++ .../BeforehandOrderCartInfoLogic.php | 138 ++++++++++++++++++ .../beforehand_order/BeforehandOrder.php | 22 +++ .../BeforehandOrderCartInfo.php | 22 +++ 8 files changed, 648 insertions(+) create mode 100644 app/admin/controller/beforehand_order/BeforehandOrderController.php create mode 100644 app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php create mode 100644 app/admin/lists/beforehand_order/BeforehandOrderLists.php create mode 100644 app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php create mode 100644 app/admin/logic/beforehand_order/BeforehandOrderLogic.php create mode 100644 app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php create mode 100644 app/common/model/beforehand_order/BeforehandOrder.php create mode 100644 app/common/model/beforehand_order_cart_info/BeforehandOrderCartInfo.php diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php new file mode 100644 index 000000000..683ff87c8 --- /dev/null +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -0,0 +1,92 @@ +dataLists(new BeforehandOrderLists()); + } + + + /** + * @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); + } + + + /** + * @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); + } + + +} \ No newline at end of file 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..7f31a85ec --- /dev/null +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -0,0 +1,104 @@ +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 编辑预订单购物详情表 + * @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/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php new file mode 100644 index 000000000..1526fea26 --- /dev/null +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -0,0 +1,65 @@ + ['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', 'store_id', 'order_id', 'uid', 'total_num', 'total_price', 'pay_price', 'deduction_price','create_time', 'source', 'status', 'mark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->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_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php new file mode 100644 index 000000000..54a3a61d7 --- /dev/null +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -0,0 +1,70 @@ + ['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', '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')->withTrashed()->find(); + $item['store_name']=$find['store_name']; + $item['image']=$find['image']; + 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/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php new file mode 100644 index 000000000..1f9d3796c --- /dev/null +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -0,0 +1,135 @@ + $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, + 'source' => 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 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..837e99643 --- /dev/null +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -0,0 +1,138 @@ + $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()); + } + } + + + /** + * @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(); + } +} \ No newline at end of file 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 @@ + Date: Mon, 30 Sep 2024 17:36:27 +0800 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E6=BA=90=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/beforehand_order/BeforehandOrderLogic.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 1f9d3796c..c9c597871 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -55,7 +55,6 @@ class BeforehandOrderLogic extends BaseLogic 'pay_type' => 0, 'deduction_price' => 0, 'paid' => 0, - 'source' => 0, 'mark' => $params['mark']??'' ]); foreach ($datas as $k => $v) { From 2e4bee3216cefb100b35996a4d4d81ccad73d2ff Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 5 Oct 2024 16:21:09 +0800 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=97=A8=E5=BA=97=E5=88=A9=E6=B6=A6=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=BA=90=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AD=97=E6=AE=B5source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeforehandOrderController.php | 32 ++++++-- .../BeforehandOrderCartInfoController.php | 25 +++++- .../PurchaseProductOfferController.php | 16 +++- .../store_order/StoreOrderController.php | 2 +- .../beforehand_order/BeforehandOrderLists.php | 2 +- .../BeforehandOrderThreeLists.php | 79 +++++++++++++++++++ .../BeforehandOrderTwoLists.php | 79 +++++++++++++++++++ .../BeforehandOrderCartInfoLists.php | 7 +- .../PurchaseProductOfferLists.php | 6 ++ .../beforehand_order/BeforehandOrderLogic.php | 74 ++++++++++++++++- .../BeforehandOrderCartInfoLogic.php | 72 ++++++++++++++--- .../PurchaseProductOfferLogic.php | 53 ++++++++----- .../PurchaseProductOfferValidate.php | 2 +- app/api/controller/order/OrderController.php | 6 +- 14 files changed, 405 insertions(+), 50 deletions(-) create mode 100644 app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php create mode 100644 app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 683ff87c8..cfbd4a466 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -5,6 +5,8 @@ namespace app\admin\controller\beforehand_order; use app\admin\controller\BaseAdminController; use app\admin\lists\beforehand_order\BeforehandOrderLists; +use app\admin\lists\beforehand_order\BeforehandOrderTwoLists; +use app\admin\lists\beforehand_order\BeforehandOrderThreeLists; use app\admin\logic\beforehand_order\BeforehandOrderLogic; @@ -28,6 +30,14 @@ class BeforehandOrderController extends BaseAdminController return $this->dataLists(new BeforehandOrderLists()); } + public function warehousing_lists() + { + return $this->dataLists(new BeforehandOrderTwoLists()); + } + public function outbound_lists() + { + return $this->dataLists(new BeforehandOrderThreeLists()); + } /** * @notes 添加预订单表 @@ -37,12 +47,22 @@ class BeforehandOrderController extends BaseAdminController */ public function add() { - $params =$this->request->post(); + $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 编辑预订单表 @@ -52,7 +72,7 @@ class BeforehandOrderController extends BaseAdminController */ public function edit() { - $params =$this->request->post(); + $params = $this->request->post(); $result = BeforehandOrderLogic::edit($params); if (true === $result) { return $this->success('编辑成功', [], 1, 1); @@ -69,7 +89,7 @@ class BeforehandOrderController extends BaseAdminController */ public function delete() { - $params =$this->request->post(); + $params = $this->request->post(); BeforehandOrderLogic::delete($params); return $this->success('删除成功', [], 1, 1); } @@ -87,6 +107,4 @@ class BeforehandOrderController extends BaseAdminController $result = BeforehandOrderLogic::detail($params); return $this->data($result); } - - -} \ No newline at end of file +} diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php index 7f31a85ec..e5376131e 100644 --- a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -6,8 +6,7 @@ namespace app\admin\controller\beforehand_order_cart_info; use app\admin\controller\BaseAdminController; use app\admin\lists\beforehand_order_cart_info\BeforehandOrderCartInfoLists; use app\admin\logic\beforehand_order_cart_info\BeforehandOrderCartInfoLogic; -use app\admin\validate\beforehand_order_cart_info\BeforehandOrderCartInfoValidate; - +use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; /** * 预订单购物详情表控制器 @@ -57,7 +56,29 @@ class BeforehandOrderCartInfoController extends BaseAdminController } + /** + * @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 diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index 0e92a4f87..f35f8665e 100644 --- a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -64,12 +64,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/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php index 1526fea26..979124c4f 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -43,7 +43,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte public function lists(): array { return BeforehandOrder::where($this->searchWhere) - ->field(['id', 'store_id', 'order_id', 'uid', 'total_num', 'total_price', 'pay_price', 'deduction_price','create_time', 'source', 'status', 'mark']) + ->field(['id','order_id', 'uid','total_num', 'total_price', 'pay_price', 'deduction_price','create_time', 'status', 'mark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() diff --git a/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php b/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php new file mode 100644 index 000000000..be66e40ec --- /dev/null +++ b/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php @@ -0,0 +1,79 @@ +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'); + } + 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..cb5f87803 --- /dev/null +++ b/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php @@ -0,0 +1,79 @@ +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'); + } + 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 index 54a3a61d7..b6c7f5e2e 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\lists\ListsSearchInterface; use app\common\model\store_product\StoreProduct; +use app\common\model\warehouse_product_storege\WarehouseProductStorege; /** * 预订单购物详情表列表 @@ -43,13 +44,15 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe public function lists(): array { return BeforehandOrderCartInfo::where($this->searchWhere) - ->field(['id', 'bhoid', 'uid', 'product_id', 'attr_value_id', 'is_pay', 'purchase', 'price', 'total_price', 'cart_num']) + ->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')->withTrashed()->find(); + $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']; return $item; }) ->toArray(); 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 index c9c597871..503d91528 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -2,10 +2,14 @@ namespace app\admin\logic\beforehand_order; - +use app\admin\logic\store_product\StoreProductLogic; +use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\beforehand_order\BeforehandOrder; use app\common\logic\BaseLogic; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; +use app\common\model\store_product\StoreProduct; +use app\common\model\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; use support\exception\BusinessException; use think\facade\Db; @@ -106,6 +110,74 @@ class BeforehandOrderLogic extends BaseLogic } } + /** + * @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, + ]; + $storeProduct = StoreProduct::where('id', $arr['product_id'])->findOrEmpty()->toArray(); + if ($arr['cart_num'] == 0) { + StoreProductLogic::ordinary($arr, $store_id, $admin_id, $storeProduct); + } else { + $data['total_price'] =$arr['total_price']; + $data['purchase'] = $storeProduct['purchase']; + $data['oid'] = $res['id']; + WarehouseProductLogic::add($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 删除预订单表 diff --git a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php index 837e99643..5a3ad6766 100644 --- a/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php +++ b/app/admin/logic/beforehand_order_cart_info/BeforehandOrderCartInfoLogic.php @@ -2,10 +2,12 @@ namespace app\admin\logic\beforehand_order_cart_info; - +use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\logic\BaseLogic; use app\common\model\beforehand_order\BeforehandOrder; +use app\common\model\purchase_product_offer\PurchaseProductOffer; +use app\common\model\warehouse_order\WarehouseOrder; use support\exception\BusinessException; use think\facade\Db; @@ -58,8 +60,8 @@ class BeforehandOrderCartInfoLogic extends BaseLogic Db::startTrans(); try { $datas = []; - $uid=$params['uid'] ?? 0; - $bhoid=$params['id']; + $uid = $params['uid'] ?? 0; + $bhoid = $params['id']; foreach ($params['product_arr'] as $k => $v) { $datas[$k]['product_id'] = $v['id']; $datas[$k]['uid'] = $uid; @@ -68,12 +70,12 @@ class BeforehandOrderCartInfoLogic extends BaseLogic $datas[$k]['price'] = $v['purchase']; $datas[$k]['total_price'] = $v['total_price']; $datas[$k]['create_time'] = time(); - $datas[$k]['update_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']]); + $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) { @@ -99,9 +101,9 @@ class BeforehandOrderCartInfoLogic extends BaseLogic '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']]); + $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) { @@ -110,7 +112,57 @@ class BeforehandOrderCartInfoLogic extends BaseLogic } } + /** + * 一键入库 + */ + 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 @@ -135,4 +187,4 @@ class BeforehandOrderCartInfoLogic extends BaseLogic { return BeforehandOrderCartInfo::findOrEmpty($params['id'])->toArray(); } -} \ No newline at end of file +} diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 32fd6aac4..bb341c594 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -5,7 +5,6 @@ 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 support\exception\BusinessException; use think\facade\Db; @@ -31,23 +30,15 @@ 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, + ]); Db::commit(); @@ -92,7 +83,31 @@ 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 { + PurchaseProductOffer::update([ + 'buyer_nums' => $params['buyer_nums'], + 'supplier_id' => $params['supplier_id'], + 'price' => $params['price'], + 'total_price' => $params['total_price'], + ],['id'=>$params['id']]); + Db::commit(); + return true; + } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } @@ -103,20 +118,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/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); From 4387eef6f186a1f55353fc70fe0cbdd86ffbd7a9 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 7 Oct 2024 13:30:14 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=85=A5=E5=BA=93=E5=92=8C=E9=87=87=E8=B4=AD=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了商品入库逻辑,支持未在门店的商品直接入库 - 优化了采购报价单操作,包括添加、编辑和查询相关功能 - 调整了仓库商品出库逻辑,支持财务相关操作 - 修复了一些与商品库存相关的逻辑问题 --- .../PurchaseProductOfferController.php | 6 +- .../SystemStoreStorageController.php | 23 +++- .../beforehand_order/BeforehandOrderLists.php | 12 +- .../BeforehandOrderThreeLists.php | 6 + .../BeforehandOrderTwoLists.php | 6 + .../BeforehandOrderCartInfoLists.php | 9 ++ .../beforehand_order/BeforehandOrderLogic.php | 92 +++++++------- .../PurchaseProductOfferLogic.php | 17 ++- .../WarehouseProductLogic.php | 118 +++++++++++++----- .../SystemStoreStorageController.php | 38 ++++-- 10 files changed, 219 insertions(+), 108 deletions(-) diff --git a/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/admin/controller/purchase_product_offer/PurchaseProductOfferController.php index f35f8665e..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); + } 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/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php index 979124c4f..0026a05de 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -6,7 +6,7 @@ namespace app\admin\lists\beforehand_order; use app\admin\lists\BaseAdminDataLists; use app\common\model\beforehand_order\BeforehandOrder; use app\common\lists\ListsSearchInterface; - +use app\common\model\auth\Admin; /** * 预订单表列表 @@ -43,10 +43,16 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte public function lists(): array { return BeforehandOrder::where($this->searchWhere) - ->field(['id','order_id', 'uid','total_num', 'total_price', 'pay_price', 'deduction_price','create_time', 'status', 'mark']) + ->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() + ->select()->each(function ($item){ + if($item->admin_id){ + $item->admin_name=Admin::where(['id'=>$item->admin_id])->value('name'); + }else{ + $item->admin_name=''; + } + }) ->toArray(); } diff --git a/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php b/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php index be66e40ec..38ff72fc0 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderThreeLists.php @@ -8,6 +8,7 @@ use app\common\model\beforehand_order\BeforehandOrder; use app\common\lists\ListsSearchInterface; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\supplier\Supplier; use app\common\model\warehouse_product\WarehouseProduct; /** @@ -59,6 +60,11 @@ class BeforehandOrderThreeLists extends BaseAdminDataLists implements ListsSearc }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(); diff --git a/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php b/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php index cb5f87803..539019f23 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderTwoLists.php @@ -8,6 +8,7 @@ use app\common\model\beforehand_order\BeforehandOrder; use app\common\lists\ListsSearchInterface; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\supplier\Supplier; use app\common\model\warehouse_product\WarehouseProduct; /** @@ -59,6 +60,11 @@ class BeforehandOrderTwoLists extends BaseAdminDataLists implements ListsSearchI }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(); diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php index b6c7f5e2e..be622775b 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -6,6 +6,7 @@ namespace app\admin\lists\beforehand_order_cart_info; use app\admin\lists\BaseAdminDataLists; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\lists\ListsSearchInterface; +use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\store_product\StoreProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; @@ -53,6 +54,14 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe $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(); diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 503d91528..2d56ed909 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -35,9 +35,9 @@ class BeforehandOrderLogic extends BaseLogic Db::startTrans(); try { $datas = []; - $total_num=0; - $total_price=0; - $uid=$params['uid'] ?? 0; + $total_num = 0; + $total_price = 0; + $uid = $params['uid'] ?? 0; foreach ($params['product_arr'] as $k => $v) { $datas[$k]['product_id'] = $v['product_id']; $datas[$k]['uid'] = $uid; @@ -45,13 +45,13 @@ class BeforehandOrderLogic extends BaseLogic $datas[$k]['price'] = $v['purchase']; $datas[$k]['total_price'] = $v['total_price']; $datas[$k]['create_time'] = time(); - $datas[$k]['update_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, + 'admin_id' => $params['admin_id'] ?? 0, 'uid' => $uid, 'total_num' => $total_num, 'total_price' => $total_price, @@ -59,7 +59,7 @@ class BeforehandOrderLogic extends BaseLogic 'pay_type' => 0, 'deduction_price' => 0, 'paid' => 0, - 'mark' => $params['mark']??'' + 'mark' => $params['mark'] ?? '' ]); foreach ($datas as $k => $v) { $datas[$k]['bhoid'] = $order['id']; @@ -119,58 +119,54 @@ class BeforehandOrderLogic extends BaseLogic */ 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){ + $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){ + if ($order['outbound_id'] > 0) { throw new BusinessException('该订单已创建出库单'); } - $info=BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select(); + $info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select(); Db::startTrans(); try { - $arr = [ - 'oid' => 0, + $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, - 'supplier_id' => 0, - 'code' => getNewOrderId('CK'), - 'admin_id' => $admin_id, 'financial_pm' => 0, - 'batch' => 0, - 'mark' => $mark, + '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'], ]; - $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, - ]; - $storeProduct = StoreProduct::where('id', $arr['product_id'])->findOrEmpty()->toArray(); - if ($arr['cart_num'] == 0) { - StoreProductLogic::ordinary($arr, $store_id, $admin_id, $storeProduct); - } else { - $data['total_price'] =$arr['total_price']; - $data['purchase'] = $storeProduct['purchase']; - $data['oid'] = $res['id']; - WarehouseProductLogic::add($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']]); + 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) { diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index bb341c594..54822b384 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -5,6 +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\beforehand_order_cart_info\BeforehandOrderCartInfo; use support\exception\BusinessException; use think\facade\Db; @@ -40,7 +41,7 @@ class PurchaseProductOfferLogic extends BaseLogic 'status' => 0, ]); - + BeforehandOrderCartInfo::where(['bhoid'=>$params['order_id'],'product_id'=>$params['product_id']])->update(['is_buyer'=>1]); Db::commit(); return true; } catch (\Exception $e) { @@ -99,12 +100,20 @@ class PurchaseProductOfferLogic extends BaseLogic { Db::startTrans(); try { - PurchaseProductOffer::update([ + $offer=PurchaseProductOffer::where(['id'=>$params['id']])->find(); + $offer->save([ 'buyer_nums' => $params['buyer_nums'], 'supplier_id' => $params['supplier_id'], - 'price' => $params['price'], + 'price' => $params['purchase'], 'total_price' => $params['total_price'], - ],['id'=>$params['id']]); + ]); + $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) { 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/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php index a9eb68379..37a98012e 100644 --- a/app/api/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -2,11 +2,12 @@ namespace app\api\controller\system_store_storage; - +use app\admin\logic\store_product\StoreProductLogic; 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 +26,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,24 +41,37 @@ 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 = 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(); - StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update(); + + $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('操作失败'); From ae38c2e571c3f579923744b7646e8807583e55eb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 8 Oct 2024 11:40:01 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=BD=AC=E9=A2=84=E5=AE=9A=E5=8D=95=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=A5=E5=BA=93=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderController 中添加 orderTransferAdvanceOrder 方法,实现订单转预定单功能 - 在 BeforehandOrderLogic 中实现 orderTransferAdvanceOrder 逻辑,包括创建预定单和保存预定单商品信息 - 优化 SystemStoreStorageController 和 SystemStoreStorageLogic 的入库操作,简化代码并提高效率 - 在 API 和 Store 控制器中调用 SystemStoreStorageLogic 的 edit 方法完成入库操作 --- .../BeforehandOrderController.php | 12 +++++ .../SystemStoreStorageController.php | 29 +--------- .../beforehand_order/BeforehandOrderLogic.php | 53 +++++++++++++++++++ .../SystemStoreStorageLogic.php | 25 +++++---- .../SystemStoreStorageController.php | 24 ++------- .../SystemStoreStorageController.php | 9 +--- 6 files changed, 89 insertions(+), 63 deletions(-) diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index cfbd4a466..0d4df0b66 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -64,6 +64,18 @@ class BeforehandOrderController extends BaseAdminController 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 diff --git a/app/admin/controller/system_store_storage/SystemStoreStorageController.php b/app/admin/controller/system_store_storage/SystemStoreStorageController.php index e33c3ebb2..deb30eee9 100644 --- a/app/admin/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/admin/controller/system_store_storage/SystemStoreStorageController.php @@ -58,37 +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('参数错误'); } - $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('操作失败'); + SystemStoreStorageLogic::edit(['id'=>$id,'admin_id'=>$this->adminId]); + return $this->success('操作成功',[]); } diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 2d56ed909..51a1532aa 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -7,6 +7,8 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\common\model\beforehand_order\BeforehandOrder; use app\common\logic\BaseLogic; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; +use app\common\model\store_order\StoreOrder; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; @@ -174,7 +176,58 @@ class BeforehandOrderLogic extends BaseLogic 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 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/api/controller/system_store_storage/SystemStoreStorageController.php b/app/api/controller/system_store_storage/SystemStoreStorageController.php index 37a98012e..2088a7ba3 100644 --- a/app/api/controller/system_store_storage/SystemStoreStorageController.php +++ b/app/api/controller/system_store_storage/SystemStoreStorageController.php @@ -3,6 +3,7 @@ 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; @@ -55,25 +56,8 @@ class SystemStoreStorageController extends BaseApiController 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('操作失败'); + $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/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('操作成功'); } From 067f4183b8e4879d0fd94cad2bb573f275cd5acf Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 8 Oct 2024 17:06:53 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A2=84=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现了预订单的导出功能,支持将预订单信息导出为标签 - 新增导出方法,处理导出逻辑,包括查询预订单信息、构建导出数据和调用导出服务 - 引入了相关模型和服务类,以支持导出功能的实现 --- .../BeforehandOrderController.php | 46 ++++++++++++++++--- app/common/service/xlsx/Beforehand.php | 41 +++++++++++++++++ 2 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 app/common/service/xlsx/Beforehand.php diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index 0d4df0b66..099160da1 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -8,7 +8,13 @@ use app\admin\lists\beforehand_order\BeforehandOrderLists; use app\admin\lists\beforehand_order\BeforehandOrderTwoLists; use app\admin\lists\beforehand_order\BeforehandOrderThreeLists; use app\admin\logic\beforehand_order\BeforehandOrderLogic; - +use app\common\model\beforehand_order\BeforehandOrder; +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\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; +use app\common\service\xlsx\Beforehand; /** * 预订单表控制器 @@ -57,10 +63,10 @@ class BeforehandOrderController extends BaseAdminController */ public function createOutboundOrder() { - $params=$this->request->post(); + $params = $this->request->post(); $params['admin_id'] = $this->adminId; $result = BeforehandOrderLogic::createOutboundOrder($params); - + return $this->success('出库成功', [], 1, 1); } @@ -68,10 +74,11 @@ class BeforehandOrderController extends BaseAdminController * @notes 订单转预定单 * @return \think\response\Json */ - public function orderTransferAdvanceOrder(){ - $params=$this->request->post(); - $params['admin_id']=$this->adminId; - $params['mark']='订单转预定单'; + public function orderTransferAdvanceOrder() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $params['mark'] = '订单转预定单'; $result = BeforehandOrderLogic::orderTransferAdvanceOrder($params); return $this->success('转单成功', [], 1, 1); } @@ -119,4 +126,29 @@ class BeforehandOrderController extends BaseAdminController $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/common/service/xlsx/Beforehand.php b/app/common/service/xlsx/Beforehand.php new file mode 100644 index 000000000..9d816e6f8 --- /dev/null +++ b/app/common/service/xlsx/Beforehand.php @@ -0,0 +1,41 @@ +getActiveSheet(); + + // 合并单元格A1到K1 + $sheet->mergeCells('A1:B1'); + $kk1=1; + $kk2=2; + $kk3=3; + $styleArray = [ + 'font' => [ + 'bold' => true, + 'size' => 16, + ], + ]; + foreach ($data as $k => $v) { + $sheet->setCellValue('A' . ($k + $kk1), $v['system_store'])->getStyle('A'. ($k + $kk1))->applyFromArray($styleArray); + $sheet->setCellValue('A' . ($k + $kk2), $v['store_name'])->getStyle('A'. ($k + $kk2))->applyFromArray($styleArray); + $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; + } +} From 16634f5b7668172d76877e46e4e258c588e33ba4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 8 Oct 2024 17:57:07 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=A0=87=E7=AD=BE=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96xlsx=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在WarehouseOrderController中添加export_tags方法,实现标签导出功能 - 修改Beforehand服务类,优化xlsx文件的样式和合并单元格逻辑 --- .../WarehouseOrderController.php | 22 +++++++++++++++++++ app/common/service/xlsx/Beforehand.php | 6 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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/common/service/xlsx/Beforehand.php b/app/common/service/xlsx/Beforehand.php index 9d816e6f8..b9770cb95 100644 --- a/app/common/service/xlsx/Beforehand.php +++ b/app/common/service/xlsx/Beforehand.php @@ -13,19 +13,21 @@ class Beforehand $sheet = $spreadsheet->getActiveSheet(); // 合并单元格A1到K1 - $sheet->mergeCells('A1:B1'); $kk1=1; $kk2=2; $kk3=3; $styleArray = [ 'font' => [ 'bold' => true, - 'size' => 16, + '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; From c4f9320978077b9a64a219bd7cd7c61a89621b9a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 8 Oct 2024 19:28:43 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E8=8F=9C=E5=8D=95=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在StoreController的menu_list方法中,将'每日配送统计'、'累计配送统计'和'店铺收支'菜单项临时注释掉。这可能是为了在特定时间内隐藏或不可用这些功能,而代码未来可能会被重新启用。 --- app/api/controller/store/StoreController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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]); }