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

169 lines
4.8 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\service;
  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. if (isset($param['status'])) {
  49. $data['status'] = $param['status'];
  50. }
  51. $receiptOrder = new ReceiptOrder();
  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 ReceiptOrder();
  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 ReceiptOrder();
  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 ReceiptOrder();
  122. $total = $receiptOrder
  123. ->alias("a")
  124. ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
  125. ->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount")
  126. ->group("a.id")
  127. ->where($where)->count();
  128. $list = $receiptOrder
  129. ->alias("a")
  130. ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left')
  131. ->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount")
  132. ->group("a.id")
  133. ->where($where)
  134. ->limit($offset, $param['pageSize'])
  135. ->order("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 ReceiptOrder();
  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. }