酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

147 regels
4.5 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 13:36
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\model\CfItem;
  11. use app\admin\model\OrderHotel;
  12. use app\admin\model\OrderItem;
  13. use app\admin\model\Purchase;
  14. use think\Exception;
  15. class OrderItemDao
  16. {
  17. /**
  18. * 新增、更新记录
  19. * @param $param
  20. * @param $orderId
  21. * @return array|string
  22. */
  23. public function modify($param, $orderId)
  24. {
  25. $itemInfo = $this->getItemInfo($param['item_id']);
  26. if (!$itemInfo['flag']){
  27. return $itemInfo;
  28. }
  29. try{
  30. //设置入参
  31. $data = [
  32. "order_id" => $orderId,
  33. //附加项目
  34. "item_id"=>$itemInfo['data']['id'],
  35. "item_type"=>$itemInfo['data']['item_type'],
  36. "item_name"=>$itemInfo['data']['item_name'],
  37. "item_memo"=>$itemInfo['data']['item_memo'],
  38. "item_unit"=>$itemInfo['data']['item_unit'],
  39. "country_name" => $itemInfo['data']['country_name'],
  40. "province_name" => $itemInfo['data']['province_name'],
  41. "city_name" => $itemInfo['data']['city_name'],
  42. "detail_address" => $itemInfo['data']['detail_address'],
  43. //其他
  44. "check_in_date" => $param['check_in_date'],
  45. "confirm_status" => $param['confirm_status'],
  46. "confirm_no" => $param['confirm_no'],
  47. "customer_name" => $param['customer_name'],
  48. "customer_comments" => $param['customer_comments'],
  49. "trade_order_number" => $param['trade_order_number'],
  50. "res_person" => $param['res_person'],
  51. "res_person_id" => $param['res_person_id'],
  52. "del_flag"=>0
  53. ];
  54. $orderHotelModel = new OrderHotel();
  55. if (empty($param['id'])) {
  56. $id = $orderHotelModel->insertGetId($data);
  57. return Util::returnArrSu($id);
  58. }else {
  59. $orderHotelModel->save($data,["id"=>$param['id']]);
  60. return Util::returnArrSu($param['id']);
  61. }
  62. }catch (Exception $e){
  63. return Util::returnArrEr("更新附加项目子订单失败".$e->getMessage());
  64. }
  65. }
  66. /**
  67. * 获取附加项目信息
  68. * @param $id
  69. * @return array
  70. */
  71. public function getItemInfo($id)
  72. {
  73. try {
  74. $model = new CfItem();
  75. $result = $model->where(["id" => $id])->find();
  76. if ($result == null) {
  77. return Util::returnArrEr("获取附加项目信息失败" . $id);
  78. }
  79. return Util::returnArrSu($result);
  80. } catch (Exception $e) {
  81. return Util::returnArrEr("获取附加项目信息失败" . $id);
  82. }
  83. }
  84. /**
  85. * 设置子订单金额
  86. * @param int $subOrderId
  87. * @return array
  88. */
  89. public function setSubOrderAmount( int $subOrderId) {
  90. try{
  91. $purchaseModel = new Purchase();
  92. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select();
  93. $cost = 0;
  94. $amount = 0;
  95. $count = 0;
  96. foreach ($purchaseList as $purchase) {
  97. $cost += $purchase['total_cost'];
  98. $amount += $purchase['total_price'];
  99. $count += $purchase['count'];
  100. }
  101. //更新数据
  102. $oderItem = new OrderItem();
  103. $oderItem->update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]);
  104. return Util::returnArrSu();
  105. }catch (Exception $e){
  106. return Util::returnArrEr("更新附加项目订单子表金额失败".$subOrderId);
  107. }
  108. }
  109. /**
  110. * 获取详情
  111. * @param $id
  112. * @return array
  113. */
  114. public function getInfoById($id) {
  115. try {
  116. $model = new OrderItem();
  117. $result = $model->where(["id" => $id])->find();
  118. if ($result == null) {
  119. return Util::returnArrEr("获取子订单信息失败" . $id);
  120. }
  121. return Util::returnArrSu($result);
  122. } catch (Exception $e) {
  123. return Util::returnArrEr("获取子订单信息失败" . $id);
  124. }
  125. }
  126. /**
  127. * 删除记录
  128. * @param $order_id
  129. */
  130. public function delete($order_id){
  131. $model = new OrderItem();
  132. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  133. }
  134. }