酒店预订平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

144 satır
4.6 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. //1、获取渠道
  24. $channelDao = new CfChannelInfoDao();
  25. $channelRe = $channelDao->getInfoById($param['channel_id']);
  26. if (!$channelRe['flag']) {
  27. return $channelRe;
  28. }
  29. //2.获取专员
  30. $adminDao = new AdminDao();
  31. $adminRe = $adminDao->getInfoById($param['commissioner_id']);
  32. if (!$adminRe['flag']) {
  33. return $adminRe;
  34. }
  35. $data = [
  36. "commissioner_id"=>$param['commissioner_id'],
  37. "commissioner"=>$adminRe["data"]['nickname'],
  38. "channel_id"=>$param["channel_id"],
  39. "channel_name"=>$channelRe['data']['channel_name'],
  40. "channel_order_no"=>$param["channel_order_no"],
  41. "user_name"=>$param["user_name"],
  42. "user_phone"=>$param["user_phone"],
  43. "order_memo"=>$param["order_memo"],
  44. "create_id"=>empty($param['create_id'])?0:$param['create_id'],
  45. "group_id"=>empty($param['group_id'])?0:$param['group_id']
  46. ];
  47. $orderMain = new OrderMain();
  48. if (empty($param['id'])) {
  49. $id = $orderMain->insertGetId($data);
  50. return Util::returnArrSu("", $id);
  51. } else {
  52. $orderMain->save($data,['id'=>$param['id']]);
  53. return Util::returnArrSu("", $param['id']);
  54. }
  55. }catch (Exception $e){
  56. return Util::returnArrEr("更新主订单失败:".$e->getMessage());
  57. }
  58. }
  59. /**
  60. * 设置主订单金额
  61. * @param int $orderId
  62. * @return array
  63. */
  64. public function setOrderAmount(int $orderId){
  65. try {
  66. $itemModel = new OrderItem();
  67. $hotelModel = new OrderHotel();
  68. $itemList = $itemModel->where(["order_id" => $orderId])->select()->toArray();
  69. $hotelList = $hotelModel->where(["order_id" => $orderId])->select()->toArray();
  70. $amount = 0;
  71. $cost = 0;
  72. foreach ($itemList as $item) {
  73. $amount += $item['total_price'];
  74. $cost += $item['total_cost'];
  75. }
  76. foreach ($hotelList as $hotel) {
  77. $amount += $hotel['total_price'];
  78. $cost += $hotel["total_cost"];
  79. }
  80. //更新金额
  81. $orderMain = new OrderMain();
  82. $orderMain->save(["total_amount" => $amount, "cost_amount" => $cost,"profit_amount"=>$amount-$cost],["id" => $orderId]);
  83. return Util::returnArrSu();
  84. }catch (Exception $e){
  85. return Util::returnArrEr("更新主表订单金额失败:".$e->getMessage());
  86. }
  87. }
  88. /**
  89. * 根据ID获取详情
  90. * @param $id
  91. * @return array
  92. */
  93. public function getInfoById($id) {
  94. try {
  95. $orderMainModel = new OrderMain();
  96. $orderMain = $orderMainModel->where(["id" => $id])->find()->toArray();
  97. if (null == $orderMain) {
  98. return Util::returnArrEr("订单查询失败:".$id);
  99. }
  100. return Util::returnArrSu("",$orderMain);
  101. }catch (Exception $e) {
  102. return Util::returnArrEr("订单查询失败:".$e->getMessage());
  103. }
  104. }
  105. /**
  106. * 子订单展示
  107. * @param $purchaseShow
  108. * @param $orderHotel
  109. * @param $orderItem
  110. * @return array
  111. */
  112. public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){
  113. $result = [];
  114. foreach ($orderItem as $item) {
  115. $item['prod_type'] = 'item';
  116. foreach ($purchaseShow as $key=> $purchase) {
  117. if ($item['id'] == $key) {
  118. $item = array_merge($item,$purchase);
  119. }
  120. }
  121. $result[] = $item;
  122. }
  123. foreach ($orderHotel as $hotel) {
  124. $hotel['prod_type'] = 'hotel';
  125. foreach ($purchaseShow as $key=> $purchase) {
  126. if ($hotel['id'] == $key) {
  127. $hotel = array_merge($hotel,$purchase);
  128. }
  129. }
  130. $result[] = $hotel;
  131. }
  132. return Util::returnArrSu("",$result);
  133. }
  134. }