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

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