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

209 lines
6.0 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/11/10
  6. * Time: 11:06
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\dao\OrderMainDao;
  11. use app\admin\dao\ReceiptOrderDao;
  12. use think\Db;
  13. class ReceiptOrderService
  14. {
  15. /**
  16. * 保存详情
  17. * @param $param
  18. * @return array
  19. */
  20. public function save($param){
  21. //保存
  22. $dao = new ReceiptOrderDao();
  23. $addRe = $dao->save($param);
  24. if (!$addRe['flag']) {
  25. return $addRe;
  26. }
  27. if (!empty($param['id'])) {
  28. $orderModel = new OrderMainDao();
  29. $orderModel->updateReceiptOrderName($param['id'], $param["name"]);
  30. }
  31. return Util::returnArrSu();
  32. }
  33. /**
  34. * 获取列表
  35. * @param $param
  36. * @return array
  37. */
  38. public function getList($param){
  39. $dao = new ReceiptOrderDao();
  40. return $dao->getList($param);
  41. }
  42. /**
  43. * 设置状态
  44. * @param $id
  45. * @param $status
  46. * @return array
  47. */
  48. public function setStatus($id,$status) {
  49. Db::startTrans();
  50. //1.设置收购单状态
  51. $dao = new ReceiptOrderDao();
  52. $statusRe = $dao->setStatus($id,$status);
  53. if (!$statusRe['flag']) {
  54. Db::rollback();
  55. return$statusRe;
  56. }
  57. //2.设置所有订单主表的状态
  58. $orderDao = new OrderMainDao();
  59. $orderRe = $orderDao->setReceiptOrderStatus($id,$status);
  60. if (!$orderRe['flag']) {
  61. Db::rollback();
  62. return $orderRe;
  63. }
  64. //3.设置订单状态
  65. $orderIds = $orderDao->getOrderMainIdsByReceipt($id);
  66. foreach ($orderIds as $orderId) {
  67. $setRe = $orderDao->setOrderAmount($orderId);
  68. if (!$setRe['flag']) {
  69. Db::rollback();
  70. return $setRe;
  71. }
  72. }
  73. Db::commit();
  74. return Util::returnArrSu();
  75. }
  76. /**
  77. * 添加主订单到采购单
  78. * @param $id
  79. * @param $order_id
  80. * @return array
  81. */
  82. public function addOrderMain($id,$order_id){
  83. $model = new ReceiptOrderDao();
  84. $infoRe = $model->getInfoById($id);
  85. if (!$infoRe['flag']) {
  86. return $infoRe;
  87. }
  88. $orderIds = explode(",", $order_id);
  89. $orderMainDao = new OrderMainDao();
  90. $addRe = $orderMainDao->addOrderMainInReceipt($infoRe['data'],$orderIds);
  91. if (!$addRe['flag']) {
  92. return $addRe;
  93. }
  94. return Util::returnArrSu();
  95. }
  96. /**
  97. * 移除采购单
  98. * @param $order_id
  99. * @return array
  100. */
  101. public function removeOrderMain($order_id){
  102. $orderIds = explode(",", $order_id);
  103. $orderMainDao = new OrderMainDao();
  104. return $orderMainDao->removeOrderMainFormReceipt($orderIds);
  105. }
  106. /**
  107. * 获取主订单列表
  108. * @param $param
  109. * @return array
  110. */
  111. public function getOrderMainList($param){
  112. $orderMainDao = new OrderMainDao();
  113. $where = ["id"=>["neq",""],"group_id"=>$param['group_id']];
  114. if (!empty($param['order_id'])) {
  115. $where["id"]=$param['order_id'];
  116. }
  117. if (!empty($param['channel_id'])) {
  118. $where['channel_id'] = $param['channel_id'];
  119. }
  120. if (!empty($param['channel_order_no'])) {
  121. $where['channel_order_no'] = $param['channel_order_no'];
  122. }
  123. if ($param['order_status'] !== '') {
  124. $where['order_status'] = $param['order_status'];
  125. }
  126. if (!empty($param['commissioner_id'])) {
  127. $where['commissioner_id'] = $param['commissioner_id'];
  128. }
  129. if (!empty($param['user_name'])) {
  130. $where['user_name'] = ["like","%".$param['user_name']."%"];
  131. }
  132. if (!empty($param['user_phone'])) {
  133. $where['user_phone'] = $param['user_phone'];
  134. }
  135. if (!empty($param['create_id'])) {
  136. $where['create_id'] = $param['create_id'];
  137. }
  138. //金额区间查询
  139. if (!empty($param['startMoney'])&& empty($param['endMoney'])) {
  140. $where['total_amount'] = [">=",$param['startMoney']];
  141. }
  142. if (!empty($param['endMoney']) && empty($param['startMoney'])) {
  143. $where['total_amount'] = ["<=",$param['endMoney']];
  144. }
  145. if (!empty($param['endMoney']) && !empty($param['startMoney'])) {
  146. $where['total_amount'] = ["between",[$param['startMoney'],$param['endMoney']]];
  147. }
  148. //时间区间查询
  149. if (!empty($param['startTime']) && empty($param['endTime'])) {
  150. $where['create_time'] = [">=",$param['startTime']." 00:00:00"];
  151. }
  152. if (!empty($param['endTime'])&& empty($param['startTime'])) {
  153. $where['create_time'] = ["<=",$param['endTime']." 23:59:59"];
  154. }
  155. if(!empty($param['endTime'])&& !empty($param['startTime'])){
  156. $where['create_time'] = ["between",[$param['startTime']." 00:00:00",$param['endTime']." 23:59:59"]];
  157. }
  158. switch ($param['inReceipt']) {
  159. case 1:
  160. $where["receipt_order_id"] = $param['receipt_order_id'];
  161. break;
  162. case 2:
  163. $where["receipt_order_id"] = ["neq",$param['receipt_order_id']];
  164. break;
  165. case 3:
  166. $where["receipt_order_id"] = "";
  167. }
  168. return $orderMainDao->getOrderListByWhere($where,$param);
  169. }
  170. /**
  171. * 删除采购单
  172. * @param $id
  173. * @return array
  174. */
  175. public function delAll($id){
  176. Db::startTrans();
  177. //1.删除采购单下的主订单
  178. $orderMainDao = new OrderMainDao();
  179. $delReceipt = $orderMainDao->delReceiptOrder($id);
  180. if (!$delReceipt['flag']) {
  181. Db::rollback();
  182. return $delReceipt;
  183. }
  184. //2.删除采购单
  185. $model = new ReceiptOrderDao();
  186. $delRe = $model->del($id);
  187. if (!$delRe['flag']) {
  188. Db::rollback();
  189. return $delRe;
  190. }
  191. Db::commit();
  192. return Util::returnArrSu();
  193. }
  194. }