From 521c503605614665dff21f238f3247bb01b8d973 Mon Sep 17 00:00:00 2001 From: nizongfeng Date: Wed, 17 Nov 2021 17:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E5=8D=95=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/PaymentOrder.php | 81 ++++++++++- application/admin/controller/ReceiptOrder.php | 2 +- application/admin/service/OrderHotelDao.php | 59 ++++++++ application/admin/service/OrderItemDao.php | 58 ++++++++ application/admin/service/PaymentOrderDao.php | 166 ++++++++++++++++++++++ application/admin/service/PaymentOrderService.php | 74 ++++++++++ application/admin/service/ReceiptOrderDao.php | 2 +- 7 files changed, 439 insertions(+), 3 deletions(-) create mode 100644 application/admin/service/PaymentOrderDao.php create mode 100644 application/admin/service/PaymentOrderService.php diff --git a/application/admin/controller/PaymentOrder.php b/application/admin/controller/PaymentOrder.php index c27b4b7..9deaad2 100755 --- a/application/admin/controller/PaymentOrder.php +++ b/application/admin/controller/PaymentOrder.php @@ -2,6 +2,7 @@ namespace app\admin\controller; +use app\admin\service\PaymentOrderService; use app\common\controller\Backend; /** @@ -35,6 +36,84 @@ class PaymentOrder extends Backend * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ - + + /** + * 保存记录 + * @return \think\response\Json + */ + public function save(){ + $params=$this->request->post(); + $params['create_id']=$this->auth->id; + $params['group_id']=$this->auth->getGroupId(); + $service = new PaymentOrderService(); + $result = $service->save($params); + return json($result); + } + + /** + * 获取列表 + * @return \think\response\Json + */ + public function getList(){ + $params=$this->request->post(); + $service = new PaymentOrderService(); + $result = $service->getList($params); + return json($result); + } + + /** + * 状态设置 + * @return \think\response\Json + */ + public function setStatus(){ + $params=$this->request->post(); + $service = new PaymentOrderService(); + $result = $service->setStatus($params['id'],$params['status']); + return json($result); + } + + /** + * 添加到收款单 + * @return \think\response\Json + */ + public function addOrderMain(){ + $params=$this->request->post(); + $service = new PaymentOrderService(); + $result = $service->addOrderMain($params['id'],$params['order_id']); + return json($result); + } + + /** + * 移除收购单 + * @return \think\response\Json + */ + public function removeOrderMain(){ + $params=$this->request->post(); + $service = new PaymentOrderService(); + $result = $service->removeOrderMain($params['order_id']); + return json($result); + } + + + /** + * 获取订单列表 + * @return \think\response\Json + */ + public function getOrderMainList(){ + $params=$this->request->post(); + $service = new PaymentOrderService(); + $result = $service->getOrderMainList($params); + return json($result); + } + + /** + * 删除收款单 + */ + public function delAll(){ + $params=$this->request->post(); + $service = new PaymentOrderService(); + $result = $service->delAll($params['id']); + return json($result); + } } diff --git a/application/admin/controller/ReceiptOrder.php b/application/admin/controller/ReceiptOrder.php index c4376ed..9a15af4 100755 --- a/application/admin/controller/ReceiptOrder.php +++ b/application/admin/controller/ReceiptOrder.php @@ -257,7 +257,7 @@ class ReceiptOrder extends Backend } /** - * 删除采购单 + * 删除收款单 */ public function delAll(){ $params=$this->request->post(); diff --git a/application/admin/service/OrderHotelDao.php b/application/admin/service/OrderHotelDao.php index 5c156ec..0221fd9 100644 --- a/application/admin/service/OrderHotelDao.php +++ b/application/admin/service/OrderHotelDao.php @@ -218,4 +218,63 @@ class OrderHotelDao return Util::returnArrEr("获取酒店订单列表异常:".$e->getMessage()); } } + + /**=====================================**/ + + /** + * 更新付款单下的状态 + * @param $paymentOrderId + * @param $status + * @return array + */ + public function setPaymentOrderStatus($paymentOrderId, $status){ + try{ + $model = new OrderHotel(); + $model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]); + return Util::returnArrSu(); + }catch (Exception $e){ + return Util::returnArrEr("更新收款单下的酒店订单状态失败".$e->getMessage()); + } + } + + /** + * 添加酒店订单到付款单下 + * @param $paymentOrder + * @param $orderIds + * @return array + */ + public function addOrderMainInPayment($paymentOrder,$orderIds){ + try{ + $data = [ + "payment_order_id"=>$paymentOrder['id'], + "payment_order_status"=>$paymentOrder['status'], + "payment_order_name"=>$paymentOrder['name'] + ]; + $model = new OrderHotel(); + $model->save($data,["id"=>["in",$orderIds]]); + return Util::returnArrSu(); + }catch (Exception $e){ + return Util::returnArrEr("添加酒店订单到付款单下失败".$e->getMessage()); + } + } + + /** + * 将酒店订单从付款单下移除 + * @param $orderIds + * @return array + */ + public function removeOrderMainFormPayment($orderIds){ + try{ + $data = [ + "payment_order_id"=>0, + "payment_order_status"=>0, + "payment_order_name"=>"" + ]; + $model = new OrderHotel(); + $model->save($data,["id"=>["in",$orderIds]]); + return Util::returnArrSu(); + }catch (Exception $e){ + return Util::returnArrEr("将酒店订单从付款单下移除失败".$e->getMessage()); + } + } } \ No newline at end of file diff --git a/application/admin/service/OrderItemDao.php b/application/admin/service/OrderItemDao.php index 7f65182..3437384 100644 --- a/application/admin/service/OrderItemDao.php +++ b/application/admin/service/OrderItemDao.php @@ -169,4 +169,62 @@ class OrderItemDao } + /**=====================================**/ + + /** + * 更新付款单下的状态 + * @param $paymentOrderId + * @param $status + * @return array + */ + public function setPaymentOrderStatus($paymentOrderId, $status){ + try{ + $model = new OrderItem(); + $model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]); + return Util::returnArrSu(); + }catch (Exception $e){ + return Util::returnArrEr("更新收款单下的附加项目订单状态失败".$e->getMessage()); + } + } + + /** + * 添加附加项目订单到付款单下 + * @param $paymentOrder + * @param $orderIds + * @return array + */ + public function addOrderMainInPayment($paymentOrder,$orderIds){ + try{ + $data = [ + "payment_order_id"=>$paymentOrder['id'], + "payment_order_status"=>$paymentOrder['status'], + "payment_order_name"=>$paymentOrder['name'] + ]; + $model = new OrderItem(); + $model->save($data,["id"=>["in",$orderIds]]); + return Util::returnArrSu(); + }catch (Exception $e){ + return Util::returnArrEr("添加附加项目订单到付款单下失败".$e->getMessage()); + } + } + + /** + * 将附加项目订单从付款单下移除 + * @param $orderIds + * @return array + */ + public function removeOrderMainFormPayment($orderIds){ + try{ + $data = [ + "payment_order_id"=>0, + "payment_order_status"=>0, + "payment_order_name"=>"" + ]; + $model = new OrderItem(); + $model->save($data,["id"=>["in",$orderIds]]); + return Util::returnArrSu(); + }catch (Exception $e){ + return Util::returnArrEr("将附加项目订单从付款单下移除失败".$e->getMessage()); + } + } } \ No newline at end of file diff --git a/application/admin/service/PaymentOrderDao.php b/application/admin/service/PaymentOrderDao.php new file mode 100644 index 0000000..c7289e0 --- /dev/null +++ b/application/admin/service/PaymentOrderDao.php @@ -0,0 +1,166 @@ +where(["id"=>$id])->find(); + if ($info == null) { + return Util::returnArrEr("获取付款单信息失败:".$id); + } + return Util::returnArrSu("",$info->toArray()); + }catch (Exception $e){ + return Util::returnArrEr("获取付款单信息失败:".$e->getMessage()); + } + } + + /** + * 添加记录 + * @param $param + * @return array + */ + public function save($param) + { + if ($this->checkName($param)) { + return Util::returnArrEr("名称已经存在"); + } + try { + $data = [ + 'name' => $param['name'], + "create_id"=>$param['create_id'], + "group_id"=>$param['group_id'] + ]; + if (isset($param['status'])) { + $data['status'] = $param['status']; + } + $receiptOrder = new PaymentOrder(); + if (empty($param['id'])) { + $id = $receiptOrder->insertGetId($data); + return Util::returnArrSu("", $id); + } else { + $receiptOrder->save($data, ['id' => $param['id']]); + return Util::returnArrSu("", $param['id']); + } + } catch (Exception $e) { + return Util::returnArrEr("更新主订单失败:" . $e->getMessage()); + } + } + + /** + * 校验名称 + * @param $param + * @return bool + */ + public function checkName($param):bool { + try { + $model = new PaymentOrder(); + $infoRe = $model->where(["name" => $param['name']])->find(); + if ($infoRe == null) { + return false; + } + $info = $infoRe->toArray(); + if (isset($param['id'])) { + if ($param['id'] != $info['id']) { + return true; + } + }else{ + return true; + } + return false; + } catch (Exception $e) { + return false; + } + } + + /** + * 修改状态 + * @param $id + * @param $status + * @return array + */ + public function setStatus($id, $status) + { + try { + //设置收购单状态 + $receiptOrder = new PaymentOrder(); + $receiptOrder->save(['status' => $status], ['id' => $id]); + return Util::returnArrSu(); + } catch (Exception $e) { + return Util::returnArrEr("修改状态失败" . $e->getMessage()); + } + } + + + /** + * 获取列表 + * @param $param + * @return array + */ + public function getList($param) + { + try { + $where = ["a.del_flag"=>0]; + if (!empty($param['name'])) { + $where['a.name'] = ["like","%".$param['name']."%"]; + } + if ($param['status'] != 'all') { + $where["a.status"] = $param['status']; + } + $offset = ($param['pageNum'] - 1) * $param['pageSize']; + $receiptOrder = new PaymentOrder(); + $total = $receiptOrder + ->alias("a") + ->group("a.id") + ->where($where)->count(); + + $list = $receiptOrder + ->alias("a") + ->join('hbp_order_hotel b', 'a.id = b.receipt_order_id', 'left') + ->join('hbp_order_item c', 'a.id = c.receipt_order_id', 'left') + ->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) hotel_ids,sum(b.total_amount) hotel_amount,GROUP_CONCAT(c.id ORDER BY c.id DESC) hotel_ids,sum(c.total_amount) hotel_amount") + ->group("a.id") + ->where($where) + ->limit($offset, $param['pageSize']) + ->order("id","DESC")->select(); + $data = ["total" => $total, "list" => $list->toArray()]; + return Util::returnArrSu("", $data); + } catch (Exception $e) { + return Util::returnArrSu("", ["total" => 0, "list" => []]); + } + } + + /** + * 删除 + * @param $id + * @return array + */ + public function del($id){ + try { + //设置收购单状态 + $receiptOrder = new PaymentOrder(); + $receiptOrder->save(['del_flag' => 1], ['id' => $id]); + return Util::returnArrSu(); + } catch (Exception $e) { + return Util::returnArrEr("修改状态失败" . $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/application/admin/service/PaymentOrderService.php b/application/admin/service/PaymentOrderService.php new file mode 100644 index 0000000..b846036 --- /dev/null +++ b/application/admin/service/PaymentOrderService.php @@ -0,0 +1,74 @@ +save($param); + if (!$addRe['flag']) { + return $addRe; + } + return Util::returnArrSu(); + + } + + /** + * 获取列表 + * @param $param + * @return array + */ + public function getList($param){ + $dao = new PaymentOrderDao(); + return $dao->getList($param); + } + + /** + * 设置状态 + * @param $id + * @param $status + * @return array + */ + public function setStatus($id,$status) { + Db::startTrans(); + //1.设置收购单状态 + $dao = new PaymentOrderDao(); + $statusRe = $dao->setStatus($id,$status); + if (!$statusRe['flag']) { + Db::rollback(); + return$statusRe; + } + //2.设置所有订单表的状态 + $hotelDao = new OrderHotelDao(); + $hotelRe = $hotelDao->setPaymentOrderStatus($id,$status); + if (!$hotelRe['flag']) { + Db::rollback(); + return $hotelRe; + } + $itemDao = new OrderItemDao(); + $itemRe = $itemDao->setPaymentOrderStatus($id,$status); + if (!$itemRe['flag']) { + Db::rollback(); + return $itemRe; + } + Db::commit(); + return Util::returnArrSu(); + } +} \ No newline at end of file diff --git a/application/admin/service/ReceiptOrderDao.php b/application/admin/service/ReceiptOrderDao.php index ed1721e..c37c8ac 100644 --- a/application/admin/service/ReceiptOrderDao.php +++ b/application/admin/service/ReceiptOrderDao.php @@ -139,7 +139,7 @@ class ReceiptOrderDao $list = $receiptOrder ->alias("a") ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left') - ->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount") + ->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) order_ids,sum(b.total_amount) total_amount") ->group("a.id") ->where($where) ->limit($offset, $param['pageSize'])