酒店预订平台
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.

OrderMainDao.php 4.0 KiB

3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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"=>empty($param['commissioner_id'])?0:$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()->toArray();
  55. $hotelList = $hotelModel->where(["order_id" => $orderId])->select()->toArray();
  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 = new OrderMain();
  68. $orderMain->save(["total_amount" => $amount, "cost_amount" => $cost,"profit_amount"=>$amount-$cost],["id" => $orderId]);
  69. return Util::returnArrSu();
  70. }catch (Exception $e){
  71. return Util::returnArrEr("更新主表订单金额失败:".$e->getMessage());
  72. }
  73. }
  74. /**
  75. * 根据ID获取详情
  76. * @param $id
  77. * @return array
  78. */
  79. public function getInfoById($id) {
  80. try {
  81. $orderMainModel = new OrderMain();
  82. $orderMain = $orderMainModel->where(["id" => $id])->find()->toArray();
  83. if (null == $orderMain) {
  84. return Util::returnArrEr("订单查询失败:".$id);
  85. }
  86. return Util::returnArrSu("",$orderMain);
  87. }catch (Exception $e) {
  88. return Util::returnArrEr("订单查询失败:".$e->getMessage());
  89. }
  90. }
  91. /**
  92. * 子订单展示
  93. * @param $purchaseShow
  94. * @param $orderHotel
  95. * @param $orderItem
  96. * @return array
  97. */
  98. public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){
  99. $result = [];
  100. foreach ($orderItem as $item) {
  101. $item['prod_type'] = 'item';
  102. foreach ($purchaseShow as $key=> $purchase) {
  103. if ($item['id'] == $key) {
  104. $item = array_merge($item,$purchase);
  105. }
  106. }
  107. $result[] = $item;
  108. }
  109. foreach ($orderHotel as $hotel) {
  110. $hotel['prod_type'] = 'hotel';
  111. foreach ($purchaseShow as $key=> $purchase) {
  112. if ($hotel['id'] == $key) {
  113. $hotel = array_merge($hotel,$purchase);
  114. }
  115. }
  116. $result[] = $hotel;
  117. }
  118. return Util::returnArrSu("",$result);
  119. }
  120. }