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

255 lines
9.6 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/11/17
  6. * Time: 17:29
  7. */
  8. namespace app\admin\dao;
  9. use app\admin\command\Util;
  10. use app\admin\model\PaymentOrder;
  11. use think\Db;
  12. use think\Exception;
  13. class PaymentOrderDao
  14. {
  15. /**
  16. * 获取详情
  17. * @param $id
  18. * @return array
  19. */
  20. public function getInfoById($id){
  21. try{
  22. $model = new PaymentOrder();
  23. $info = $model->where(["id"=>$id])->find();
  24. if ($info == null) {
  25. return Util::returnArrEr("获取付款单信息失败:".$id);
  26. }
  27. return Util::returnArrSu("",$info->toArray());
  28. }catch (Exception $e){
  29. return Util::returnArrEr("获取付款单信息失败:".$e->getMessage());
  30. }
  31. }
  32. /**
  33. * 添加记录
  34. * @param $param
  35. * @return array
  36. */
  37. public function save($param)
  38. {
  39. if ($this->checkName($param)) {
  40. return Util::returnArrEr("名称已经存在");
  41. }
  42. try {
  43. $data = [
  44. 'name' => $param['name'],
  45. "create_id"=>$param['create_id'],
  46. "group_id"=>$param['group_id']
  47. ];
  48. $receiptOrder = new PaymentOrder();
  49. if (empty($param['id'])) {
  50. $id = $receiptOrder->insertGetId($data);
  51. return Util::returnArrSu("", $id);
  52. } else {
  53. $receiptOrder->save($data, ['id' => $param['id']]);
  54. return Util::returnArrSu("", $param['id']);
  55. }
  56. } catch (Exception $e) {
  57. return Util::returnArrEr("更新主订单失败:" . $e->getMessage());
  58. }
  59. }
  60. /**
  61. * 校验名称
  62. * @param $param
  63. * @return bool
  64. */
  65. public function checkName($param):bool {
  66. try {
  67. $model = new PaymentOrder();
  68. $infoRe = $model->where(["name" => $param['name'],"group_id"=>$param['group_id']])->find();
  69. if ($infoRe == null) {
  70. return false;
  71. }
  72. $info = $infoRe->toArray();
  73. if (isset($param['id'])) {
  74. if ($param['id'] != $info['id']) {
  75. return true;
  76. }
  77. }else{
  78. return true;
  79. }
  80. return false;
  81. } catch (Exception $e) {
  82. return false;
  83. }
  84. }
  85. /**
  86. * 修改状态
  87. * @param $id
  88. * @param $status
  89. * @return array
  90. */
  91. public function setStatus($id, $status)
  92. {
  93. try {
  94. //设置收购单状态
  95. $receiptOrder = new PaymentOrder();
  96. $receiptOrder->save(['status' => $status], ['id' => $id]);
  97. return Util::returnArrSu();
  98. } catch (Exception $e) {
  99. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  100. }
  101. }
  102. /**
  103. * 获取列表
  104. * @param $param
  105. * @return array
  106. */
  107. public function getList($param)
  108. {
  109. try {
  110. $where = ["a.del_flag"=>0,"a.group_id"=>$param['group_id']];
  111. if (!empty($param['name'])) {
  112. $where['a.name'] = ["like","%".$param['name']."%"];
  113. }
  114. if ($param['status']."" != 'all' && $param['status']!=="") {
  115. $where["a.status"] = $param['status'];
  116. }
  117. $having = [];
  118. if(!empty($param['startCost']) && !empty($param['endCost'])) {
  119. $having[] = " (itemMoney >= {$param['startCost']} and itemMoney <= {$param['endCost']} ) or (hotelMoney >= {$param['startCost']} and hotelMoney <= {$param['endCost']} ) ";
  120. }
  121. if(!empty($param['startCost']) && empty($param['endCost'])) {
  122. $having[] = " (itemMoney >= {$param['startCost']} ) or (hotelMoney >= {$param['startCost']} ) ";
  123. }
  124. if(empty($param['startCost']) && !empty($param['endCost'])) {
  125. $having[] = " (itemMoney <= {$param['endCost']} ) or (hotelMoney <= {$param['endCost']} ) ";
  126. }
  127. $offset = ($param['pageNum'] - 1) * $param['pageSize'];
  128. $receiptOrder = new PaymentOrder();
  129. $total = $receiptOrder
  130. ->alias("a")
  131. ->field("a.*,
  132. (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_item where payment_order_id = a.id) 'itemMoney',
  133. (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_hotel where payment_order_id = a.id) 'hotelMoney'
  134. ")
  135. ->group("a.id")
  136. ->where($where)
  137. ->having(join("and", $having))
  138. ->count();
  139. $list = $receiptOrder
  140. ->alias("a")
  141. ->field("a.*,
  142. (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_item where payment_order_id = a.id) 'item',
  143. (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_hotel where payment_order_id = a.id) 'hotel',
  144. (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_item where payment_order_id = a.id) 'itemMoney',
  145. (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_hotel where payment_order_id = a.id) 'hotelMoney'
  146. ")
  147. ->group("a.id")
  148. ->where($where)
  149. ->having(join("and", $having))
  150. ->limit($offset, $param['pageSize'])
  151. ->order("a.id","DESC")->select();
  152. $data = ["total" => $total, "list" => $list->toArray()];
  153. return Util::returnArrSu("", $data);
  154. } catch (Exception $e) {
  155. return Util::returnArrSu("", ["total" => 0, "list" => []]);
  156. }
  157. }
  158. /**
  159. * 删除
  160. * @param $id
  161. * @return array
  162. */
  163. public function del($id){
  164. try {
  165. //设置收购单状态
  166. $receiptOrder = new PaymentOrder();
  167. $receiptOrder->save(['del_flag' => 1], ['id' => $id]);
  168. return Util::returnArrSu();
  169. } catch (Exception $e) {
  170. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  171. }
  172. }
  173. /**
  174. * 获取子订单列表
  175. * @param $hotel_where
  176. * @param $item_where
  177. * @param $where
  178. * @param $param
  179. * @return array
  180. */
  181. public function getSubOrderListByWhere($hotel_where,$item_where,$where,$param):array {
  182. $limit = $param['pageSize'];
  183. $offset = ($param['pageNum']-1)*$param['pageSize'];
  184. $sqlCnt = "SELECT count(1) cnt
  185. from (
  186. (
  187. SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name',
  188. a.item_unit 'plan_name',
  189. a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type'
  190. ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status
  191. from hbp_order_item a
  192. INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item'
  193. where
  194. $item_where
  195. order by a.create_time desc
  196. )
  197. UNION
  198. (
  199. SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name,
  200. b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type'
  201. ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status
  202. from hbp_order_hotel b
  203. INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel'
  204. where
  205. $hotel_where
  206. order by b.create_time desc
  207. )
  208. ) x
  209. $where
  210. ";
  211. $totalRe = Db::query($sqlCnt);
  212. $sql = "SELECT x.*
  213. from (
  214. (
  215. SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name',
  216. a.item_unit 'plan_name',
  217. a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type'
  218. ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status
  219. from hbp_order_item a
  220. INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item'
  221. where
  222. $item_where
  223. order by a.create_time desc
  224. )
  225. UNION
  226. (
  227. SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name,
  228. b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type'
  229. ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status
  230. from hbp_order_hotel b
  231. INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel'
  232. where
  233. $hotel_where
  234. order by b.create_time desc
  235. )
  236. ) x
  237. ORDER BY x.create_time desc
  238. limit $limit offset $offset";
  239. $list = Db::query($sql);
  240. $result = ["list"=>$list,"total"=>$totalRe[0]['cnt']];
  241. return Util::returnArrSu("",$result);
  242. }
  243. }