/** 根据订单编号查看订单消耗情况 */
 @RequestMapping(value = "/getOrderBack", method = RequestMethod.GET)
 @ResponseBody
 public Object getOrderBack(long order_id) {
   String order_note = orderService.getOrderNote(order_id);
   List<Snacks> orderItems = orderItemService.getOrderitemByDefaultOrderId_4(order_id);
   List<Snacks> sellItems = orderItemService.getSellitemByOrderId_1(order_id);
   for (Snacks s : sellItems) {
     for (Snacks ss : orderItems) {
       if (ss.getSnacks_id() == s.getSnacks_id()) {
         ss.setEat_number(s.getSnacks_number());
       }
     }
   }
   JSONObject js = new JSONObject();
   js.put("order_note", order_note);
   js.put("orderItems", orderItems);
   return CommonUtil.constructResponse(1, "success", js);
 }
  /**
   * 订单管理页面手机端载入
   *
   * @param page 页码,默认为1
   * @param pageSize 页面大小,默认为10
   * @param order_status 订单状态,为空时查找所有状态(0未分配状态,10表示未配送,20表示配送中,30表示配送完成,40表示结算完成,50表示返回入库,60表示已返回入库)
   */
  @RequestMapping(value = "/getAllOrderByPhone", method = RequestMethod.POST)
  @ResponseBody
  public JSONObject getAllOrderByPhone(
      HttpSession httpSession,
      @RequestParam(required = false, value = "page") Long page,
      @RequestParam(required = false, value = "pageSize") Integer pageSize,
      @RequestParam(required = false, value = "order_status") Integer order_status) {

    staff staff = (staff) httpSession.getAttribute("staff"); // 获取员工
    if (staff == null) {
      return CommonUtil.constructResponse(0, "员工不存在", null);
    }
    JSONObject jo = new JSONObject();
    List<Order> orders = new ArrayList<Order>();
    if ((Long) page == null || page <= 0) { // 默认page为1
      page = Long.valueOf(1);
    }
    if ((Integer) pageSize == null || pageSize <= 0) { // 默认pageSize为10
      pageSize = 10;
    }
    long total = orderService.getCountOrderManageByPhone(staff.getStaff_id(), order_status);
    if (total > 0) {
      orders =
          orderService.getOrderManageByPhone(staff.getStaff_id(), order_status, page, pageSize);
      for (Order o : orders) {
        o.setPhones(customerSerice.getPhones(o.getDormitory_id()));
        o.setItems(orderItemService.getOrderitemByDefaultOrderId_3(o.getDefault_order_id()));
        if (o.getOrder_status() >= 40) {
          o.setSell_items(orderItemService.getSellitemByOrderId(o.getOrder_id()));
        } else {
          o.setSell_items(new ArrayList<Snacks>());
        }
      }
    }
    jo.put("total", total);
    jo.put("nowPage", page);
    jo.put("orders", orders);
    return CommonUtil.constructResponse(1, "success", jo);
  }
 /**
  * @param需要提供订单id,物品的消耗情况
  * @need 订单进行结算,将状态修改为40,插入一条销售记录,并计算出对应订单的销售金*额的并修改(信息来源配送人员)
  */
 @RequestMapping(value = "/order_balance_update", method = RequestMethod.POST)
 @ResponseBody
 public JSONObject order_balance_update(
     HttpSession httpSession, long order_id, String sell_items) {
   staff staff = (staff) httpSession.getAttribute("staff"); // 获取员工
   if (staff == null) {
     return CommonUtil.constructResponse(0, "员工不存在", null);
   }
   JSONObject jsonObject = JSONObject.parseObject(sell_items);
   JSONArray goods = (JSONArray) jsonObject.get("foods");
   List<Snacks> snacks = orderItemService.getOrderitemByDefaultOrderId_4(order_id);
   Float order_cost_money = Float.valueOf(0);
   Float order_sell_money = Float.valueOf(0);
   for (Object j : goods) {
     JSONObject jo = JSONObject.parseObject(j.toString());
     for (Snacks s : snacks) {
       long snacks_id = Long.valueOf(jo.get("snacks_id").toString());
       if (snacks_id == s.getSnacks_id()) {
         Integer nu = jo.getInteger("snacks_num");
         if (nu == null || nu < 0 || nu > s.getSnacks_number()) {
           return CommonUtil.constructResponse(0, "食品数量返回错误", null);
         } else {
           order_cost_money += nu * s.getSnacks_cost_price();
           order_sell_money += nu * s.getSnacks_sell_price();
         }
       }
     }
   }
   for (Object j : goods) {
     JSONObject jo = JSONObject.parseObject(j.toString());
     long snacks_id = Long.valueOf(jo.get("snacks_id").toString());
     Integer snacks_number = jo.getInteger("snacks_num");
     sellItemService.insertsell_items(snacks_id, snacks_number, order_id);
   }
   orderService.update_order_price_1(order_id, order_cost_money, order_sell_money);
   loadTask.delTask(order_id + "", "BalanceJob");
   loadTask.delTask(order_id + "", "BalanceJob_1");
   return CommonUtil.constructResponse(1, "结算完成", 0);
 }