酒店预订平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

128 rader
3.8 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 11:26
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\model\OrderHotel;
  11. use app\admin\model\OrderItem;
  12. use app\admin\model\OrderMain;
  13. use think\Exception;
  14. class OrderMainDao
  15. {
  16. /**
  17. * 添加、更新订单信息
  18. * @param $param
  19. * @return array
  20. */
  21. public function save($param) {
  22. try{
  23. $data = [
  24. "commissioner_id"=>$param['commissioner_id'],
  25. "commissioner"=>$param["commissioner"],
  26. "channel_id"=>$param["channel_id"],
  27. "channel_name"=>$param["channel_name"],
  28. "channel_order_no"=>$param["channel_order_no"],
  29. "user_name"=>$param["user_name"],
  30. "user_phone"=>$param["user_phone"],
  31. "order_memo"=>$param["order_memo"]
  32. ];
  33. $orderMain = new OrderMain();
  34. if (empty($param['id'])) {
  35. $id = $orderMain->insertGetId($data);
  36. return Util::returnArrSu($id);
  37. } else {
  38. $orderMain->save($data,['id'=>$param['id']]);
  39. return Util::returnArrSu($param['id']);
  40. }
  41. }catch (Exception $e){
  42. return Util::returnArrEr("更新主订单失败".$e->getMessage());
  43. }
  44. }
  45. /**
  46. * 设置主订单金额
  47. * @param int $orderId
  48. * @return array
  49. */
  50. public function setOrderAmount(int $orderId){
  51. try {
  52. $itemModel = new OrderItem();
  53. $hotelModel = new OrderHotel();
  54. $itemList = $itemModel->where(["order_id" => $orderId])->select();
  55. $hotelList = $hotelModel->where(["order_id" => $orderId])->select();
  56. $amount = 0;
  57. $cost = 0;
  58. foreach ($itemList as $item) {
  59. $amount += $item['total_price'];
  60. $cost += $item['total_cost'];
  61. }
  62. foreach ($hotelList as $hotel) {
  63. $amount += $hotel['total_price'];
  64. $cost += $hotel["total_cost"];
  65. }
  66. //更新金额
  67. OrderMain::update(["total_amount" => $amount, "cost_amount" => $cost])->where(["id" => $orderId]);
  68. return Util::returnArrSu();
  69. }catch (Exception $e){
  70. return Util::returnArrEr("更新主表订单金额失败".$orderId);
  71. }
  72. }
  73. /**
  74. * 根据ID获取详情
  75. * @param $id
  76. * @return array
  77. */
  78. public function getInfoById($id) {
  79. try {
  80. $orderMainModel = new OrderMain();
  81. $orderMain = $orderMainModel->where(["id" => $id])->find();
  82. if (null == $orderMain) {
  83. return Util::returnArrEr("订单查询失败".$id);
  84. }
  85. return Util::returnArrSu($orderMain);
  86. }catch (Exception $e) {
  87. return Util::returnArrEr("订单查询失败".$e->getMessage());
  88. }
  89. }
  90. /**
  91. * 子订单展示
  92. * @param $purchaseShow
  93. * @param $orderHotel
  94. * @param $orderItem
  95. * @return array
  96. */
  97. public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){
  98. $result = [];
  99. foreach ($orderItem as $item) {
  100. $item['prod_type'] = 'item';
  101. foreach ($purchaseShow as $key=> $purchase) {
  102. if ($item['id'] == $key) {
  103. array_merge($item,$purchase);
  104. }
  105. }
  106. $result[] = $item;
  107. }
  108. foreach ($orderHotel as $hotel) {
  109. $hotel['prod_type'] = 'hotel';
  110. foreach ($purchaseShow as $key=> $purchase) {
  111. if ($hotel['id'] == $key) {
  112. array_merge($hotel,$purchase);
  113. }
  114. }
  115. $result[] = $hotel;
  116. }
  117. return Util::returnArrSu($result);
  118. }
  119. }