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

239 lines
8.4 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\service;
  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. if (isset($param['status'])) {
  49. $data['status'] = $param['status'];
  50. }
  51. $receiptOrder = new PaymentOrder();
  52. if (empty($param['id'])) {
  53. $id = $receiptOrder->insertGetId($data);
  54. return Util::returnArrSu("", $id);
  55. } else {
  56. $receiptOrder->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 $param
  66. * @return bool
  67. */
  68. public function checkName($param):bool {
  69. try {
  70. $model = new PaymentOrder();
  71. $infoRe = $model->where(["name" => $param['name']])->find();
  72. if ($infoRe == null) {
  73. return false;
  74. }
  75. $info = $infoRe->toArray();
  76. if (isset($param['id'])) {
  77. if ($param['id'] != $info['id']) {
  78. return true;
  79. }
  80. }else{
  81. return true;
  82. }
  83. return false;
  84. } catch (Exception $e) {
  85. return false;
  86. }
  87. }
  88. /**
  89. * 修改状态
  90. * @param $id
  91. * @param $status
  92. * @return array
  93. */
  94. public function setStatus($id, $status)
  95. {
  96. try {
  97. //设置收购单状态
  98. $receiptOrder = new PaymentOrder();
  99. $receiptOrder->save(['status' => $status], ['id' => $id]);
  100. return Util::returnArrSu();
  101. } catch (Exception $e) {
  102. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  103. }
  104. }
  105. /**
  106. * 获取列表
  107. * @param $param
  108. * @return array
  109. */
  110. public function getList($param)
  111. {
  112. try {
  113. $where = ["a.del_flag"=>0];
  114. if (!empty($param['name'])) {
  115. $where['a.name'] = ["like","%".$param['name']."%"];
  116. }
  117. if ($param['status'] != 'all') {
  118. $where["a.status"] = $param['status'];
  119. }
  120. $offset = ($param['pageNum'] - 1) * $param['pageSize'];
  121. $receiptOrder = new PaymentOrder();
  122. $total = $receiptOrder
  123. ->alias("a")
  124. ->group("a.id")
  125. ->where($where)->count();
  126. $list = $receiptOrder
  127. ->alias("a")
  128. ->field("a.*,
  129. (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',
  130. (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'
  131. ")
  132. ->group("a.id")
  133. ->where($where)
  134. ->limit($offset, $param['pageSize'])
  135. ->order("a.id","DESC")->select();
  136. $data = ["total" => $total, "list" => $list->toArray()];
  137. return Util::returnArrSu("", $data);
  138. } catch (Exception $e) {
  139. return Util::returnArrSu("", ["total" => 0, "list" => []]);
  140. }
  141. }
  142. /**
  143. * 删除
  144. * @param $id
  145. * @return array
  146. */
  147. public function del($id){
  148. try {
  149. //设置收购单状态
  150. $receiptOrder = new PaymentOrder();
  151. $receiptOrder->save(['del_flag' => 1], ['id' => $id]);
  152. return Util::returnArrSu();
  153. } catch (Exception $e) {
  154. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  155. }
  156. }
  157. /**
  158. * 获取子订单列表
  159. * @param $hotel_where
  160. * @param $item_where
  161. * @param $where
  162. * @param $param
  163. * @return array
  164. */
  165. public function getSubOrderListByWhere($hotel_where,$item_where,$where,$param):array {
  166. $limit = $param['pageSize'];
  167. $offset = ($param['pageNum']-1)*$param['pageSize'];
  168. $sqlCnt = "SELECT count(1) cnt
  169. from (
  170. (
  171. SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name',
  172. a.item_unit 'plan_name',
  173. a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type'
  174. ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status
  175. from hbp_order_item a
  176. INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item'
  177. where
  178. $item_where
  179. order by a.create_time desc
  180. )
  181. UNION
  182. (
  183. SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name,
  184. b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type'
  185. ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status
  186. from hbp_order_hotel b
  187. INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel'
  188. where
  189. $hotel_where
  190. order by b.create_time desc
  191. )
  192. ) x
  193. $where
  194. ORDER BY x.create_time desc";
  195. $totalRe = Db::query($sqlCnt);
  196. $sql = "SELECT x.*
  197. from (
  198. (
  199. SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name',
  200. a.item_unit 'plan_name',
  201. a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type'
  202. ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status
  203. from hbp_order_item a
  204. INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item'
  205. where
  206. $item_where
  207. order by a.create_time desc
  208. )
  209. UNION
  210. (
  211. SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name,
  212. b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type'
  213. ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status
  214. from hbp_order_hotel b
  215. INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel'
  216. where
  217. $hotel_where
  218. order by b.create_time desc
  219. )
  220. ) x
  221. ORDER BY x.create_time desc
  222. limit $limit offset $offset";
  223. $list = Db::query($sql);
  224. $result = ["list"=>$list,"total"=>$totalRe[0]['cnt']];
  225. return Util::returnArrSu("",$result);
  226. }
  227. }