酒店预订平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

179 líneas
5.4 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['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['startMoney']) && !empty($param['endMoney'])) {
  119. $having = " total_amount >= {$param['startMoney']} and total_amount <= {$param['endMoney']} ";
  120. }
  121. if(!empty($param['startMoney']) && empty($param['endMoney'])) {
  122. $having = " total_amount >= {$param['startMoney']} ";
  123. }
  124. if(empty($param['startMoney']) && !empty($param['endMoney'])) {
  125. $having = " total_amount <= {$param['endMoney']} ";
  126. }
  127. $offset = ($param['pageNum'] - 1) * $param['pageSize'];
  128. $receiptOrder = new ReceiptOrder();
  129. $total = $receiptOrder
  130. ->alias("a")
  131. ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
  132. ->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount")
  133. ->group("a.id")
  134. ->where($where)
  135. ->having($having)
  136. ->count();
  137. $list = $receiptOrder
  138. ->alias("a")
  139. ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
  140. ->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) order_ids,sum(b.total_amount) total_amount")
  141. ->group("a.id")
  142. ->where($where)
  143. ->having($having)
  144. ->limit($offset, $param['pageSize'])
  145. ->order("id","DESC")->select();
  146. $data = ["total" => $total, "list" => $list->toArray()];
  147. return Util::returnArrSu("", $data);
  148. } catch (Exception $e) {
  149. return Util::returnArrSu("", ["total" => 0, "list" => []]);
  150. }
  151. }
  152. /**
  153. * 删除
  154. * @param $id
  155. * @return array
  156. */
  157. public function del($id){
  158. try {
  159. //设置收购单状态
  160. $receiptOrder = new ReceiptOrder();
  161. $receiptOrder->save(['del_flag' => 1], ['id' => $id]);
  162. return Util::returnArrSu();
  163. } catch (Exception $e) {
  164. return Util::returnArrEr("修改状态失败" . $e->getMessage());
  165. }
  166. }
  167. }