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

172 lines
5.2 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\OrderItem;
  12. use app\admin\model\Purchase;
  13. use think\Exception;
  14. class OrderItemDao
  15. {
  16. /**
  17. * 新增、更新记录
  18. * @param $param
  19. * @param $orderId
  20. * @return array|string
  21. */
  22. public function modify($param, $orderId)
  23. {
  24. $itemInfo = $this->getItemInfo($param['item_id']);
  25. if (!$itemInfo['flag']){
  26. return $itemInfo;
  27. }
  28. try{
  29. //设置入参
  30. $data = [
  31. "order_id" => $orderId,
  32. //附加项目
  33. "item_id"=>$itemInfo['data']['id'],
  34. "item_type"=>$itemInfo['data']['item_type'],
  35. "item_name"=>$itemInfo['data']['item_name'],
  36. "item_memo"=>$itemInfo['data']['item_memo'],
  37. "item_unit"=>$itemInfo['data']['item_unit'],
  38. "area_name" => $itemInfo['data']['area_name'],
  39. "province_name" => $itemInfo['data']['province_name'],
  40. "city_name" => $itemInfo['data']['city_name'],
  41. "detail_address" => $itemInfo['data']['detail_address'],
  42. //其他
  43. "check_in_date" => $param['check_in_date'],
  44. "confirm_status" => $param['confirm_status'],
  45. "confirm_no" => $param['confirm_no'],
  46. "customer_name" => $param['customer_name'],
  47. "customer_comments" => empty($param['customer_comments'])?"":$param['customer_comments'],
  48. "trade_order_number" => $param['trade_order_number'],
  49. "del_flag"=>0
  50. ];
  51. $model = new OrderItem();
  52. if (empty($param['id'])) {
  53. $id = $model->insertGetId($data);
  54. return Util::returnArrSu("",$id);
  55. }else {
  56. $model->save($data,["id"=>$param['id']]);
  57. return Util::returnArrSu("",$param['id']);
  58. }
  59. }catch (Exception $e){
  60. return Util::returnArrEr("更新附加项目子订单失败:".$e->getMessage());
  61. }
  62. }
  63. /**
  64. * 获取附加项目信息
  65. * @param $id
  66. * @return array
  67. */
  68. public function getItemInfo($id)
  69. {
  70. try {
  71. $model = new CfItem();
  72. $result = $model->where(["id" => $id])->find();
  73. if ($result == null) {
  74. return Util::returnArrEr("获取附加项目信息失败:" . $id);
  75. }
  76. return Util::returnArrSu("",$result->toArray());
  77. } catch (Exception $e) {
  78. return Util::returnArrEr("获取附加项目信息失败:" . $id);
  79. }
  80. }
  81. /**
  82. * 设置子订单金额
  83. * @param int $subOrderId
  84. * @return array
  85. */
  86. public function setSubOrderAmount( int $subOrderId) {
  87. try{
  88. $purchaseModel = new Purchase();
  89. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select()->toArray();
  90. $cost = 0;
  91. $amount = 0;
  92. $count = 0;
  93. foreach ($purchaseList as $purchase) {
  94. $cost += $purchase['total_cost'];
  95. $amount += $purchase['total_price'];
  96. $count += $purchase['count'];
  97. }
  98. //更新数据
  99. $oderItem = new OrderItem();
  100. $oderItem->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count,"profit"=>$amount-$cost],["id"=>$subOrderId]);
  101. return Util::returnArrSu();
  102. }catch (Exception $e){
  103. return Util::returnArrEr("更新附加项目订单子表金额失败:".$subOrderId);
  104. }
  105. }
  106. /**
  107. * 获取详情
  108. * @param $id
  109. * @return array
  110. */
  111. public function getInfoById($id) {
  112. try {
  113. $model = new OrderItem();
  114. $result = $model->where(["id" => $id])->find();
  115. if ($result == null) {
  116. return Util::returnArrEr("获取子订单信息失败:" . $id);
  117. }
  118. return Util::returnArrSu("", $result->toArray());
  119. } catch (Exception $e) {
  120. return Util::returnArrEr("获取子订单信息失败:" . $id);
  121. }
  122. }
  123. /**
  124. * 删除记录
  125. * @param $order_id
  126. */
  127. public function delete($order_id){
  128. $model = new OrderItem();
  129. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  130. }
  131. /**
  132. * 删除记录
  133. * @param $id
  134. */
  135. public function delById($id) {
  136. $model = new OrderItem();
  137. $model->save(["del_flag"=>1],["id"=>$id]);
  138. }
  139. /**
  140. * 获取附加项目子订单列表
  141. * @param $orderId
  142. * @return array
  143. */
  144. public function getListByOrderId($orderId){
  145. $subOrderModel = new OrderItem();
  146. try {
  147. $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  148. if (null == $subOrderList) {
  149. return Util::returnArrSu("",[]);
  150. }
  151. return Util::returnArrSu("", $subOrderList);
  152. }catch (Exception $e) {
  153. return Util::returnArrEr("获取附加项目订单列表异常".$e->getMessage());
  154. }
  155. }
  156. }