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

236 lines
8.3 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']])->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];
  111. if (!empty($param['name'])) {
  112. $where['a.name'] = ["like","%".$param['name']."%"];
  113. }
  114. if ($param['status']."" != 'all') {
  115. $where["a.status"] = $param['status'];
  116. }
  117. $offset = ($param['pageNum'] - 1) * $param['pageSize'];
  118. $receiptOrder = new PaymentOrder();
  119. $total = $receiptOrder
  120. ->alias("a")
  121. ->group("a.id")
  122. ->where($where)->count();
  123. $list = $receiptOrder
  124. ->alias("a")
  125. ->field("a.*,
  126. (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>金额:',ifnull( sum( total_price ), '-' )) from hbp_order_item where payment_order_id = a.id) 'item',
  127. (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '</br>金额:',ifnull( sum( total_price ), '-' )) from hbp_order_hotel where payment_order_id = a.id) 'hotel'
  128. ")
  129. ->group("a.id")
  130. ->where($where)
  131. ->limit($offset, $param['pageSize'])
  132. ->order("a.id","DESC")->select();
  133. $data = ["total" => $total, "list" => $list->toArray()];
  134. return Util::returnArrSu("", $data);
  135. } catch (Exception $e) {
  136. return Util::returnArrSu("", ["total" => 0, "list" => []]);
  137. }
  138. }
  139. /**
  140. * 删除
  141. * @param $id
  142. * @return array
  143. */
  144. public function del($id){
  145. try {
  146. //设置收购单状态
  147. $receiptOrder = new PaymentOrder();
  148. $receiptOrder->save(['del_flag' => 1], ['id' => $id]);
  149. return Util::returnArrSu();
  150. } catch (Exception $e) {
  151. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  152. }
  153. }
  154. /**
  155. * 获取子订单列表
  156. * @param $hotel_where
  157. * @param $item_where
  158. * @param $where
  159. * @param $param
  160. * @return array
  161. */
  162. public function getSubOrderListByWhere($hotel_where,$item_where,$where,$param):array {
  163. $limit = $param['pageSize'];
  164. $offset = ($param['pageNum']-1)*$param['pageSize'];
  165. $sqlCnt = "SELECT count(1) cnt
  166. from (
  167. (
  168. SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name',
  169. a.item_unit 'plan_name',
  170. a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type'
  171. ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status
  172. from hbp_order_item a
  173. INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item'
  174. where
  175. $item_where
  176. order by a.create_time desc
  177. )
  178. UNION
  179. (
  180. SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name,
  181. b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type'
  182. ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status
  183. from hbp_order_hotel b
  184. INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel'
  185. where
  186. $hotel_where
  187. order by b.create_time desc
  188. )
  189. ) x
  190. $where
  191. ORDER BY x.create_time desc";
  192. $totalRe = Db::query($sqlCnt);
  193. $sql = "SELECT x.*
  194. from (
  195. (
  196. SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name',
  197. a.item_unit 'plan_name',
  198. a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type'
  199. ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status
  200. from hbp_order_item a
  201. INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item'
  202. where
  203. $item_where
  204. order by a.create_time desc
  205. )
  206. UNION
  207. (
  208. SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name,
  209. b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type'
  210. ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status
  211. from hbp_order_hotel b
  212. INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel'
  213. where
  214. $hotel_where
  215. order by b.create_time desc
  216. )
  217. ) x
  218. ORDER BY x.create_time desc
  219. limit $limit offset $offset";
  220. $list = Db::query($sql);
  221. $result = ["list"=>$list,"total"=>$totalRe[0]['cnt']];
  222. return Util::returnArrSu("",$result);
  223. }
  224. }