getInfoById($param['supplier_id']); if (!$suplierRe['flag']) { return $suplierRe; } //2.获取负责人昵称 $adminDao = new AdminDao(); $adminRe = $adminDao->getInfoById($param['purchase_user_id']); if (!$adminRe['flag']) { return $adminRe; } $data = [ "order_id" => $hotelOrder['order_id'], "prod_type" => 'hotel', "order_detail_id" => $hotelOrder['id'], "group_id" => $param['group_id'], "pro_name" => $hotelOrder['hotel_name'], "item_name" => $hotelOrder['room_name'], "item_unit" => $hotelOrder['plan_name'], "check_in_date" => $param['check_in_date'], "check_out_date" => $param['check_out_date'], "supplier_id" => $param['supplier_id'], "supplier_name" => $suplierRe['data']['supplier_name'], "purchase_user_id" => $param['purchase_user_id'], "purchase_user" => $adminRe['data']['nickname'], "del_flag"=>0 ]; $model = new Purchase(); if (empty($param['purchase_id'])) { $id = $model->insertGetId($data); return Util::returnArrSu("", $id); }else { $model->save($data,["id"=>$param['purchase_id']]); return Util::returnArrSu("", $param['purchase_id']); } }catch (Exception $e){ return Util::returnArrEr("新增采购单失败:".$e->getMessage()); } } /** * 添加附加项目采购单 * @param $param * @param $itemOrder * @return array */ public function saveItemPurchase($param, $itemOrder):array { try { //1.获取供应商名称 $suplierDao = new CfSuplierInfoDao(); $suplierRe = $suplierDao->getInfoById($param['supplier_id']); if (!$suplierRe['flag']) { return $suplierRe; } //2.获取负责人昵称 $adminDao = new AdminDao(); $adminRe = $adminDao->getInfoById($param['purchase_user_id']); if (!$adminRe['flag']) { return $adminRe; } $data = [ "order_id" => $itemOrder['order_id'], "prod_type" => 'hotel', "order_detail_id" => $itemOrder['id'], "group_id" => $param['group_id'], "item_name" => $itemOrder['item_name'], "item_unit" => $itemOrder['item_unit'], "check_in_date" => $param['check_in_date'], "supplier_id" => $param['supplier_id'], "supplier_name" => $suplierRe['data']['supplier_name'], "purchase_user_id" => $param['purchase_user_id'], "purchase_user" => $adminRe['data']['nickname'], "del_flag"=>0 ]; $model = new Purchase(); if (empty($param['purchase_id'])) { $id = $model->insertGetId($data); return Util::returnArrSu("", $id); }else { $model->save($data,["id"=>$param['purchase_id']]); return Util::returnArrSu("", $param['purchase_id']); } }catch (Exception $e){ return Util::returnArrEr("新增采购单失败:".$e->getMessage()); } } /** * 设置采购单 金额 * @param $purchaseId * @return array */ public function setPurchaseAmount(int $purchaseId){ try{ $purchasePrice = new PurchasePrice(); $purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray(); $cost = 0; $amount = 0; $cnt = 0; foreach ($purchasePriceList as $price) { $cost += $price['cost'] * $price["count"]; $amount += $price['price'] * $price["count"]; $cnt += $price['count']; } $purchase = new Purchase(); $purchase->save(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt,"profit"=>$amount-$cost],["id"=>$purchaseId]); return Util::returnArrSu(); }catch (Exception $e){ return Util::returnArrEr("更新采购单金额失败:".$e->getMessage()); } } /** * 删除记录 * @param $order_id */ public function delete($order_id){ $model = new Purchase(); $model->save(["del_flag"=>1],["order_id"=>$order_id]); } /** * 删除子订单 * @param $subOrderId */ public function deleteBySubOrderId($subOrderId) { $model = new Purchase(); $model->save(["del_flag"=>1],["order_detail_id"=>$subOrderId]); } /** * 获取采购单列表 * @param $orderId * @return array */ public function getListByOrderId($orderId) { $model = new Purchase(); try { $list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray(); if (null == $list) { return Util::returnArrSu("",[]); } return Util::returnArrSu("",$list); }catch (Exception $e) { return Util::returnArrEr("获取订单的采购单列表失败:".$e->getMessage()); } } /** * 设置 * @param $purchaseList * @param $purchasePriceList * @return array */ public function setPurchaseShow($purchaseList,$purchasePriceList){ $result = []; foreach ($purchaseList as $purchase) { $purchaseShow=[ "purchase_id"=>$purchase['id'], "purchase_user_id"=>$purchase['purchase_user_id'], "purchase_user"=>$purchase['purchase_user'], "supplier_id"=>$purchase['supplier_id'], "supplier_name" =>$purchase['supplier_name'], "purchasePriceList"=>[] ]; foreach ($purchasePriceList as $price) { if ($price['purchase_id'] == $purchase['id']) { $priceShow = [ "id"=>$price['id'], "run_date"=>$price['run_date'], "count"=>$price['count'], "price"=>$price['price'], "cost"=>$price['cost'] ]; $purchaseShow["purchasePriceList"][]=$priceShow; } } $result[$purchase['order_detail_id']]= $purchaseShow; } return Util::returnArrSu("", $result); } }