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

195 lines
6.0 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/11/10
  6. * Time: 10:20
  7. */
  8. namespace app\admin\dao;
  9. use app\admin\command\Util;
  10. use app\admin\model\OrderMain;
  11. use app\admin\model\ReceiptOrder;
  12. use think\Exception;
  13. class ReceiptOrderDao
  14. {
  15. /**
  16. * 获取详情
  17. * @param $id
  18. * @return array
  19. */
  20. public function getInfoById($id){
  21. try{
  22. $model = new ReceiptOrder();
  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 ReceiptOrder();
  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 ReceiptOrder();
  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 ReceiptOrder();
  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['order_id'])) {
  112. $orderMainModel = new OrderMain();
  113. $orderMain = $orderMainModel->where(["id"=>$param['order_id']])->find();
  114. if ($orderMain == null || empty($orderMain['receipt_order_id'])) {
  115. $where["a.id"] = 0;
  116. }else{
  117. $where["a.id"] = $orderMain['receipt_order_id'];
  118. }
  119. }
  120. if (!empty($param['name'])) {
  121. $where['a.name'] = ["like","%".$param['name']."%"];
  122. }
  123. if ($param['status']."" != 'all' && $param['status']!=="") {
  124. $where["a.status"] = $param['status'];
  125. }
  126. if (!empty($param["id"])) {
  127. $where["a.id"] = $param["id"];
  128. }
  129. if (!empty($param['create_id'])) {
  130. $where["a.create_id"] = $param["create_id"];
  131. }
  132. $having = "";
  133. if(!empty($param['startMoney']) && !empty($param['endMoney'])) {
  134. $having = " total_amount >= {$param['startMoney']} and total_amount <= {$param['endMoney']} ";
  135. }
  136. if(!empty($param['startMoney']) && empty($param['endMoney'])) {
  137. $having = " total_amount >= {$param['startMoney']} ";
  138. }
  139. if(empty($param['startMoney']) && !empty($param['endMoney'])) {
  140. $having = " total_amount <= {$param['endMoney']} ";
  141. }
  142. $offset = ($param['pageNum'] - 1) * $param['pageSize'];
  143. $receiptOrder = new ReceiptOrder();
  144. $total = $receiptOrder
  145. ->alias("a")
  146. ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
  147. ->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount")
  148. ->group("a.id")
  149. ->where($where)
  150. ->having($having)
  151. ->count();
  152. $list = $receiptOrder
  153. ->alias("a")
  154. ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
  155. ->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) order_ids,sum(b.total_amount) total_amount")
  156. ->group("a.id")
  157. ->where($where)
  158. ->having($having)
  159. ->limit($offset, $param['pageSize'])
  160. ->order("id","DESC")->select();
  161. $data = ["total" => $total, "list" => $list->toArray()];
  162. return Util::returnArrSu("", $data);
  163. } catch (Exception $e) {
  164. return Util::returnArrSu("", ["total" => 0, "list" => []]);
  165. }
  166. }
  167. /**
  168. * 删除
  169. * @param $id
  170. * @return array
  171. */
  172. public function del($id){
  173. try {
  174. //设置收购单状态
  175. $receiptOrder = new ReceiptOrder();
  176. $receiptOrder->save(['del_flag' => 1], ['id' => $id]);
  177. return Util::returnArrSu();
  178. } catch (Exception $e) {
  179. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  180. }
  181. }
  182. }