empty($param['commissioner_id'])?0:$param['commissioner_id'], "commissioner"=>$param["commissioner"], "channel_id"=>$param["channel_id"], "channel_name"=>$param["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()->toArray(); if (null == $orderMain) { return Util::returnArrEr("订单查询失败:".$id); } return Util::returnArrSu("",$orderMain); }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); } }