酒店预订平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

239 linhas
7.6 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 11:26
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\model\OrderHotel;
  11. use app\admin\model\OrderItem;
  12. use app\admin\model\OrderMain;
  13. use think\Exception;
  14. class OrderMainDao
  15. {
  16. /**
  17. * 添加、更新订单信息
  18. * @param $param
  19. * @return array
  20. */
  21. public function save($param) {
  22. try{
  23. //1、获取渠道
  24. $channelDao = new CfChannelInfoDao();
  25. $channelRe = $channelDao->getInfoById($param['channel_id']);
  26. if (!$channelRe['flag']) {
  27. return $channelRe;
  28. }
  29. //2.获取专员
  30. $adminDao = new AdminDao();
  31. $adminRe = $adminDao->getInfoById($param['commissioner_id']);
  32. if (!$adminRe['flag']) {
  33. return $adminRe;
  34. }
  35. $data = [
  36. "commissioner_id"=>$param['commissioner_id'],
  37. "commissioner"=>$adminRe["data"]['nickname'],
  38. "channel_id"=>$param["channel_id"],
  39. "channel_name"=>$channelRe['data']['channel_name'],
  40. "channel_order_no"=>$param["channel_order_no"],
  41. "user_name"=>$param["user_name"],
  42. "user_phone"=>$param["user_phone"],
  43. "order_memo"=>$param["order_memo"],
  44. "create_id"=>empty($param['create_id'])?0:$param['create_id'],
  45. "group_id"=>empty($param['group_id'])?0:$param['group_id']
  46. ];
  47. $orderMain = new OrderMain();
  48. if (empty($param['id'])) {
  49. $id = $orderMain->insertGetId($data);
  50. return Util::returnArrSu("", $id);
  51. } else {
  52. $orderMain->save($data,['id'=>$param['id']]);
  53. return Util::returnArrSu("", $param['id']);
  54. }
  55. }catch (Exception $e){
  56. return Util::returnArrEr("更新主订单失败:".$e->getMessage());
  57. }
  58. }
  59. /**
  60. * 设置主订单金额
  61. * @param int $orderId
  62. * @return array
  63. */
  64. public function setOrderAmount(int $orderId){
  65. try {
  66. $itemModel = new OrderItem();
  67. $hotelModel = new OrderHotel();
  68. $itemList = $itemModel->where(["order_id" => $orderId])->select()->toArray();
  69. $hotelList = $hotelModel->where(["order_id" => $orderId])->select()->toArray();
  70. $amount = 0;
  71. $cost = 0;
  72. foreach ($itemList as $item) {
  73. $amount += $item['total_price'];
  74. $cost += $item['total_cost'];
  75. }
  76. foreach ($hotelList as $hotel) {
  77. $amount += $hotel['total_price'];
  78. $cost += $hotel["total_cost"];
  79. }
  80. //更新金额
  81. $orderMain = new OrderMain();
  82. $orderMain->save(["total_amount" => $amount, "cost_amount" => $cost,"profit_amount"=>$amount-$cost],["id" => $orderId]);
  83. return Util::returnArrSu();
  84. }catch (Exception $e){
  85. return Util::returnArrEr("更新主表订单金额失败:".$e->getMessage());
  86. }
  87. }
  88. /**
  89. * 根据ID获取详情
  90. * @param $id
  91. * @return array
  92. */
  93. public function getInfoById($id) {
  94. try {
  95. $orderMainModel = new OrderMain();
  96. $orderMain = $orderMainModel->where(["id" => $id])->find();
  97. if (null == $orderMain) {
  98. return Util::returnArrEr("订单查询失败:".$id);
  99. }
  100. return Util::returnArrSu("",$orderMain->toArray());
  101. }catch (Exception $e) {
  102. return Util::returnArrEr("订单查询失败:".$e->getMessage());
  103. }
  104. }
  105. /**
  106. * 子订单展示
  107. * @param $purchaseShow
  108. * @param $orderHotel
  109. * @param $orderItem
  110. * @return array
  111. */
  112. public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){
  113. $result = [];
  114. foreach ($orderItem as $item) {
  115. $item['prod_type'] = 'item';
  116. foreach ($purchaseShow as $key=> $purchase) {
  117. if ($item['id'] == $key) {
  118. $item = array_merge($item,$purchase);
  119. }
  120. }
  121. $result[] = $item;
  122. }
  123. foreach ($orderHotel as $hotel) {
  124. $hotel['prod_type'] = 'hotel';
  125. foreach ($purchaseShow as $key=> $purchase) {
  126. if ($hotel['id'] == $key) {
  127. $hotel = array_merge($hotel,$purchase);
  128. }
  129. }
  130. $result[] = $hotel;
  131. }
  132. return Util::returnArrSu("",$result);
  133. }
  134. /**
  135. * 更新采购单下的订单信息
  136. * @param $receiptOrderId
  137. * @param $status
  138. * @return array
  139. */
  140. public function setReceiptOrderStatus($receiptOrderId, $status){
  141. try{
  142. $model = new OrderMain();
  143. $model->save(['receipt_order_status'=>$status],['receipt_order_id'=>$receiptOrderId]);
  144. return Util::returnArrSu();
  145. }catch (Exception $e){
  146. return Util::returnArrEr("更新收款单子啊的主订单状态失败".$e->getMessage());
  147. }
  148. }
  149. /**
  150. * 添加主订单到采购单下
  151. * @param $receiptOrder
  152. * @param $orderIds
  153. * @return array
  154. */
  155. public function addOrderMainInReceipt($receiptOrder,$orderIds){
  156. try{
  157. $data = [
  158. "receipt_order_id"=>$receiptOrder['id'],
  159. "receipt_order_status"=>$receiptOrder['status'],
  160. "receipt_order_name"=>$receiptOrder['name']
  161. ];
  162. $model = new OrderMain();
  163. $model->save($data,["id"=>["in",$orderIds]]);
  164. return Util::returnArrSu();
  165. }catch (Exception $e){
  166. return Util::returnArrEr("添加主订单到采购单下失败".$e->getMessage());
  167. }
  168. }
  169. /**
  170. * 将主订单从采购单下移除
  171. * @param $orderIds
  172. * @return array
  173. */
  174. public function removeOrderMainFormReceipt($orderIds){
  175. try{
  176. $data = [
  177. "receipt_order_id"=>0,
  178. "receipt_order_status"=>0,
  179. "receipt_order_name"=>""
  180. ];
  181. $model = new OrderMain();
  182. $model->save($data,["id"=>["in",$orderIds]]);
  183. return Util::returnArrSu();
  184. }catch (Exception $e){
  185. return Util::returnArrEr("将主订单从采购单下移除失败".$e->getMessage());
  186. }
  187. }
  188. /**
  189. * 获取订单列表
  190. * @param $where
  191. * @param $param
  192. * @return array
  193. */
  194. public function getOrderListByWhere($where,$param){
  195. try {
  196. $offset = ($param['pageNum'] - 1) * $param['pageSize'];
  197. $model = new OrderMain();
  198. $count = $model->where($where)->count();
  199. $list = $model->where($where)->limit($offset,$param['pageSize'])->order("id","DESC")->select();
  200. return Util::returnArrSu("", ["total" => $count, "list" => $list->toArray()]);
  201. }catch (Exception $e){
  202. return Util::returnArrSu("", ["total" => 0, "list" => []]);
  203. }
  204. }
  205. /**
  206. * 删除采购单
  207. * @param $id
  208. * @return array
  209. */
  210. public function delReceiptOrder($id){
  211. try{
  212. $data = [
  213. "receipt_order_id"=>0,
  214. "receipt_order_status"=>0,
  215. "receipt_order_name"=>""
  216. ];
  217. $model = new OrderMain();
  218. $model->save($data,["receipt_order_id"=>$id]);
  219. return Util::returnArrSu();
  220. }catch (Exception $e){
  221. return Util::returnArrEr("将主订单从采购单下移除失败".$e->getMessage());
  222. }
  223. }
  224. }