|
- <?php
- /**
- * Created by PhpStorm.
- * User: nizongfeng
- * Date: 2021/10/27
- * Time: 13:36
- */
-
- namespace app\admin\dao;
-
-
- use app\admin\command\Util;
- use app\admin\model\CfHotelInfo;
- use app\admin\model\CfRoomInfo;
- use app\admin\model\CfRoomPlan;
- use app\admin\model\OrderHotel;
- use app\admin\model\Purchase;
- use think\Exception;
-
- class OrderHotelDao
- {
- /**
- * 更新记录
- * @param $param
- * @param $orderId
- * @return array|string
- */
- public function modify($param, $orderId)
- {
- $hotelInfo = $this->getHotelInfo($param['hotel_id']);
- if (!$hotelInfo['flag']){
- return $hotelInfo;
- }
- $roomInfo = $this->getRoomInfo($param['room_id']);
- if (!$roomInfo['flag']){
- return $roomInfo;
- }
- $roomPlan = $this->getRoomPlan($param['plan_id']);
- if (!$roomPlan['flag']) {
- return $roomPlan;
- }
- try {
- //设置入参
- $data = [
- "order_id" => $orderId,
- "hotel_id" => $param['hotel_id'],
- "hotel_name" => $hotelInfo['data']['hotel_name'],
- "hotel_phone" => $hotelInfo['data']['hotel_phone'],
- "province_name" => $hotelInfo['data']['province_name'],
- "city_name" => $hotelInfo['data']['city_name'],
- "area_name" => $hotelInfo['data']['area_name'],
- "detail_address" => $hotelInfo['data']['detail_address'],
- //房型
- "room_id" => $param['room_id'],
- "room_name" => $roomInfo['data']['room_name'],
- "room_memo" => $roomInfo['data']['room_memo'],
- //价格方案
- "plan_id" => $param['plan_id'],
- "plan_name" => $roomPlan['data']['plan_name'],
- "plan_memo" => $roomPlan['data']['plan_memo'],
- //其他
- "check_in_date" => $param['check_in_date'],
- "check_out_date" => $param['check_out_date'],
- "confirm_status" => $param['confirm_status'],
- "confirm_no" => $param['confirm_no'],
- "customer_name" => $param['customer_name'],
- "customer_comments" => empty($param['customer_comments'])?"":$param['customer_comments'],
- "trade_order_number" => $param['trade_order_number'],
- "purchase_user_id" => $param['purchase_user_id'],
- "purchase_user" => $param['purchase_user'],
- "supplier_id" => $param['supplier_id'],
- "supplier_name" => $param['supplier_name'],
- "del_flag"=>0
- ];
- $orderHotelModel = new OrderHotel();
- if (empty($param['id'])) {
- $data["create_id"]= $param['create_id'];
- $data["group_id"]= $param['group_id'];
- $id = $orderHotelModel->insertGetId($data);
- return Util::returnArrSu("", $id);
- }else {
- $orderHotelModel->save($data, ["id" => $param['id']]);
- return Util::returnArrSu("", $param['id']);
- }
- }catch (Exception $e){
- return Util::returnArrEr("更新酒店子订单失败:".$e->getMessage());
- }
- }
-
- /**
- * 获取酒店信息
- * @param $id
- * @return array
- */
- public function getHotelInfo($id)
- {
- try {
- $model = new CfHotelInfo();
- $result = $model->where(["id" => $id])->find();
- if ($result == null) {
- return Util::returnArrEr("获取酒店信息失败:" . $id);
- }
- return Util::returnArrSu("",$result->toArray());
- } catch (Exception $e) {
- return Util::returnArrEr("获取酒店信息失败:" . $id);
- }
- }
-
- /**
- * 获取房型详情
- * @param $id
- * @return array
- */
- public function getRoomInfo($id)
- {
- try {
- $model = new CfRoomInfo();
- $result = $model->where(["id" => $id])->find();
- if ($result == null) {
- return Util::returnArrEr("获取房型信息失败:" . $id);
- }
- return Util::returnArrSu("", $result->toArray());
- } catch (Exception $e) {
- return Util::returnArrEr("获取房型信息失败:" . $id);
- }
- }
-
- /**
- * 获取房型价格方案
- * @param $id
- * @return array
- */
- public function getRoomPlan($id)
- {
- try {
- $model = new CfRoomPlan();
- $result = $model->where(["id" => $id])->find();
- if ($result == null) {
- return Util::returnArrEr("获取价格方案信息失败:" . $id);
- }
- return Util::returnArrSu("",$result->toArray());
- } catch (Exception $e) {
- return Util::returnArrEr("获取价格方案信息失败:" . $id);
- }
- }
-
- /**
- * 设置子订单金额
- * @param int $subOrderId
- * @return array
- */
- public function setSubOrderAmount( int $subOrderId) {
- try{
- $purchaseModel = new Purchase();
- $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select()->toArray();
- $cost = 0;
- $amount = 0;
- $count = 0;
- foreach ($purchaseList as $purchase) {
- $cost += $purchase['total_cost'];
- $amount += $purchase['total_price'];
- $count += $purchase['count'];
- }
- $orderHotel = new OrderHotel();
- $orderHotel->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count, "profit"=>$amount-$cost],["id"=>$subOrderId]);
- return Util::returnArrSu();
- }catch (Exception $e){
- return Util::returnArrEr("更新酒店订单子表金额失败:".$subOrderId);
- }
-
- }
-
- /**
- * 获取详情
- * @param $id
- * @return array
- */
- public function getInfoById($id) {
- try {
- $model = new OrderHotel();
- $result = $model->where(["id" => $id])->find();
- if ($result == null) {
- return Util::returnArrEr("获取子订单信息失败:" . $id);
- }
- return Util::returnArrSu("",$result->toArray());
- } catch (Exception $e) {
- return Util::returnArrEr("获取子订单信息失败:" . $id);
- }
- }
-
- /**
- * 删除记录
- * @param $order_id
- */
- public function delete($order_id){
- $model = new OrderHotel();
- $model->save(["del_flag"=>1],["order_id"=>$order_id]);
- }
-
- /**
- * 删除记录
- * @param $id
- */
- public function delById($id) {
- $model = new OrderHotel();
- $model->save(["del_flag"=>1],["id"=>$id]);
- }
-
- /**
- * 获取酒店子订单列表
- * @param $orderId
- * @return array
- */
- public function getListByOrderId($orderId){
- $subOrderModel = new OrderHotel();
- try {
- $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
- if (null == $subOrderList) {
- return Util::returnArrSu("",[]);
- }
- return Util::returnArrSu("", $subOrderList);
- }catch (Exception $e) {
- 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 addSubOrderInPayment($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 removeSubOrderFormPayment($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());
- }
- }
-
- /**
- * 删除采购单
- * @param $id
- * @return array
- */
- public function delPaymentOrder($id){
- try{
- $data = [
- "payment_order_id"=>0,
- "payment_order_status"=>0,
- "payment_order_name"=>""
- ];
- $model = new OrderHotel();
- $model->save($data,["payment_order_id"=>$id]);
- return Util::returnArrSu();
- }catch (Exception $e){
- return Util::returnArrEr("将酒店订单从付款单下移除失败".$e->getMessage());
- }
- }
-
- /**
- * 获取主订单ID
- * @param $payment_order_id
- * @return array
- */
- public function getOrderMainIdByPayment($payment_order_id){
- $subOrderModel = new OrderHotel();
- try {
- $subOrderList = $subOrderModel->where(["payment_order_id" => $payment_order_id, "del_flag" => 0])->select()->toArray();
- if (null == $subOrderList) {
- return [];
- }
- $id = [];
- foreach ($subOrderList as $val){
- $id[] = $val['order_id'];
- }
- return array_unique($id);
- }catch (Exception $e) {
- return [];
- }
- }
-
- /**
- * 获取订单列表
- * @param $orderIds
- * @return array
- */
- public function getOrderListByOrderIds($orderIds){
- $subOrderModel = new OrderHotel();
- try {
- $subOrderList = $subOrderModel->where(["order_id" => ["in",$orderIds], "del_flag" => 0])->select()->toArray();
- if (null == $subOrderList) {
- return [];
- }
- return $subOrderList;
- }catch (Exception $e) {
- return [];
- }
- }
- }
|