getInfoById($param['channel_id']); if (!$channelRe['flag']) { return $channelRe; } //2.获取专员 $adminDao = new AdminDao(); $adminRe = $adminDao->getInfoById($param['commissioner_id']); if (!$adminRe['flag']) { return $adminRe; } $data = [ "commissioner_id"=>$param['commissioner_id'], "commissioner"=>$adminRe["data"]['nickname'], "channel_id"=>$param["channel_id"], "channel_name"=>$channelRe['data']['channel_name'], "channel_order_no"=>$param["channel_order_no"], "user_name"=>$param["user_name"], "user_phone"=>$param["user_phone"], "order_memo"=>$param["order_memo"], "create_id"=>empty($param['create_id'])?0:$param['create_id'], "group_id"=>empty($param['group_id'])?0:$param['group_id'] ]; $orderMain = new OrderMain(); if (empty($param['id'])) { $id = $orderMain->insertGetId($data); return Util::returnArrSu("", $id); } else { $orderMain->save($data,['id'=>$param['id']]); return Util::returnArrSu("", $param['id']); } }catch (Exception $e){ return Util::returnArrEr("更新主订单失败:".$e->getMessage()); } } /** * 设置主订单金额 * @param int $orderId * @return array */ public function setOrderAmount(int $orderId){ try { $itemModel = new OrderItem(); $hotelModel = new OrderHotel(); $itemList = $itemModel->where(["order_id" => $orderId])->select()->toArray(); $hotelList = $hotelModel->where(["order_id" => $orderId])->select()->toArray(); $amount = 0; $cost = 0; foreach ($itemList as $item) { $amount += $item['total_price']; $cost += $item['total_cost']; } foreach ($hotelList as $hotel) { $amount += $hotel['total_price']; $cost += $hotel["total_cost"]; } //更新金额 $orderMain = new OrderMain(); $orderMain->save(["total_amount" => $amount, "cost_amount" => $cost,"profit_amount"=>$amount-$cost],["id" => $orderId]); return Util::returnArrSu(); }catch (Exception $e){ return Util::returnArrEr("更新主表订单金额失败:".$e->getMessage()); } } /** * 根据ID获取详情 * @param $id * @return array */ public function getInfoById($id) { try { $orderMainModel = new OrderMain(); $orderMain = $orderMainModel->where(["id" => $id])->find(); if (null == $orderMain) { return Util::returnArrEr("订单查询失败:".$id); } return Util::returnArrSu("",$orderMain->toArray()); }catch (Exception $e) { return Util::returnArrEr("订单查询失败:".$e->getMessage()); } } /** * 子订单展示 * @param $purchaseShow * @param $orderHotel * @param $orderItem * @return array */ public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){ $result = []; foreach ($orderItem as $item) { $item['prod_type'] = 'item'; foreach ($purchaseShow as $key=> $purchase) { if ($item['id'] == $key) { $item = array_merge($item,$purchase); } } $result[] = $item; } foreach ($orderHotel as $hotel) { $hotel['prod_type'] = 'hotel'; foreach ($purchaseShow as $key=> $purchase) { if ($hotel['id'] == $key) { $hotel = array_merge($hotel,$purchase); } } $result[] = $hotel; } return Util::returnArrSu("",$result); } /** * 更新采购单下的订单信息 * @param $receiptOrderId * @param $status * @return array */ public function setReceiptOrderStatus($receiptOrderId, $status){ try{ $model = new OrderMain(); $model->save(['receipt_order_status'=>$status],['receipt_order_id'=>$receiptOrderId]); return Util::returnArrSu(); }catch (Exception $e){ return Util::returnArrEr("更新收款单子啊的主订单状态失败".$e->getMessage()); } } /** * 添加主订单到采购单下 * @param $receiptOrder * @param $orderIds * @return array */ public function addOrderMainInReceipt($receiptOrder,$orderIds){ try{ $data = [ "receipt_order_id"=>$receiptOrder['id'], "receipt_order_status"=>$receiptOrder['status'], "receipt_order_name"=>$receiptOrder['name'] ]; $model = new OrderMain(); $model->save($data,["id"=>["in",$orderIds]]); return Util::returnArrSu(); }catch (Exception $e){ return Util::returnArrEr("添加主订单到采购单下失败".$e->getMessage()); } } /** * 将主订单从采购单下移除 * @param $orderIds * @return array */ public function removeOrderMainFormReceipt($orderIds){ try{ $data = [ "receipt_order_id"=>0, "receipt_order_status"=>0, "receipt_order_name"=>"" ]; $model = new OrderMain(); $model->save($data,["id"=>["in",$orderIds]]); return Util::returnArrSu(); }catch (Exception $e){ return Util::returnArrEr("将主订单从采购单下移除失败".$e->getMessage()); } } /** * 获取订单列表 * @param $where * @param $param * @return array */ public function getOrderListByWhere($where,$param){ try { $offset = ($param['pageNum'] - 1) * $param['pageSize']; $model = new OrderMain(); $count = $model->where($where)->count(); $list = $model->where($where)->limit($offset,$param['pageSize'])->order("id","DESC")->select(); return Util::returnArrSu("", ["total" => $count, "list" => $list->toArray()]); }catch (Exception $e){ return Util::returnArrSu("", ["total" => 0, "list" => []]); } } /** * 删除采购单 * @param $id * @return array */ public function delReceiptOrder($id){ try{ $data = [ "receipt_order_id"=>0, "receipt_order_status"=>0, "receipt_order_name"=>"" ]; $model = new OrderMain(); $model->save($data,["receipt_order_id"=>$id]); return Util::returnArrSu(); }catch (Exception $e){ return Util::returnArrEr("将主订单从采购单下移除失败".$e->getMessage()); } } }