where(["id"=>$id])->find(); if ($info == null) { return Util::returnArrEr("获取付款单信息失败:".$id); } return Util::returnArrSu("",$info->toArray()); }catch (Exception $e){ return Util::returnArrEr("获取付款单信息失败:".$e->getMessage()); } } /** * 添加记录 * @param $param * @return array */ public function save($param) { if ($this->checkName($param)) { return Util::returnArrEr("名称已经存在"); } try { $data = [ 'name' => $param['name'], "create_id"=>$param['create_id'], "group_id"=>$param['group_id'] ]; $receiptOrder = new PaymentOrder(); if (empty($param['id'])) { $id = $receiptOrder->insertGetId($data); return Util::returnArrSu("", $id); } else { $receiptOrder->save($data, ['id' => $param['id']]); return Util::returnArrSu("", $param['id']); } } catch (Exception $e) { return Util::returnArrEr("更新主订单失败:" . $e->getMessage()); } } /** * 校验名称 * @param $param * @return bool */ public function checkName($param):bool { try { $model = new PaymentOrder(); $infoRe = $model->where(["name" => $param['name'],"group_id"=>$param['group_id']])->find(); if ($infoRe == null) { return false; } $info = $infoRe->toArray(); if (isset($param['id'])) { if ($param['id'] != $info['id']) { return true; } }else{ return true; } return false; } catch (Exception $e) { return false; } } /** * 修改状态 * @param $id * @param $status * @return array */ public function setStatus($id, $status) { try { //设置收购单状态 $receiptOrder = new PaymentOrder(); $receiptOrder->save(['status' => $status], ['id' => $id]); return Util::returnArrSu(); } catch (Exception $e) { return Util::returnArrEr("修改状态失败" . $e->getMessage()); } } /** * 获取列表 * @param $param * @return array */ public function getList($param) { try { $where = ["a.del_flag"=>0,"a.group_id"=>$param['group_id']]; if (!empty($param['name'])) { $where['a.name'] = ["like","%".$param['name']."%"]; } if ($param['status']."" != 'all' && $param['status']!=="") { $where["a.status"] = $param['status']; } $having = []; if(!empty($param['startCost']) && !empty($param['endCost'])) { $having[] = " (itemMoney >= {$param['startCost']} and itemMoney <= {$param['endCost']} ) or (hotelMoney >= {$param['startCost']} and hotelMoney <= {$param['endCost']} ) "; } if(!empty($param['startCost']) && empty($param['endCost'])) { $having[] = " (itemMoney >= {$param['startCost']} ) or (hotelMoney >= {$param['startCost']} ) "; } if(empty($param['startCost']) && !empty($param['endCost'])) { $having[] = " (itemMoney <= {$param['endCost']} ) or (hotelMoney <= {$param['endCost']} ) "; } $offset = ($param['pageNum'] - 1) * $param['pageSize']; $receiptOrder = new PaymentOrder(); $total = $receiptOrder ->alias("a") ->field("a.*, (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_item where payment_order_id = a.id) 'itemMoney', (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_hotel where payment_order_id = a.id) 'hotelMoney' ") ->group("a.id") ->where($where) ->having(join("and", $having)) ->count(); $list = $receiptOrder ->alias("a") ->field("a.*, (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '
成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_item where payment_order_id = a.id) 'item', (SELECT concat('订单:',ifnull( GROUP_CONCAT( id ORDER BY id DESC ), '-' ), '
成本:',ifnull( sum( total_cost ), '-' )) from hbp_order_hotel where payment_order_id = a.id) 'hotel', (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_item where payment_order_id = a.id) 'itemMoney', (SELECT ifnull( sum( total_cost ), 0 ) from hbp_order_hotel where payment_order_id = a.id) 'hotelMoney' ") ->group("a.id") ->where($where) ->having(join("and", $having)) ->limit($offset, $param['pageSize']) ->order("a.id","DESC")->select(); $data = ["total" => $total, "list" => $list->toArray()]; return Util::returnArrSu("", $data); } catch (Exception $e) { return Util::returnArrSu("", ["total" => 0, "list" => []]); } } /** * 删除 * @param $id * @return array */ public function del($id){ try { //设置收购单状态 $receiptOrder = new PaymentOrder(); $receiptOrder->save(['del_flag' => 1], ['id' => $id]); return Util::returnArrSu(); } catch (Exception $e) { return Util::returnArrEr("修改状态失败" . $e->getMessage()); } } /** * 获取子订单列表 * @param $hotel_where * @param $item_where * @param $where * @param $param * @return array */ public function getSubOrderListByWhere($hotel_where,$item_where,$where,$param):array { $limit = $param['pageSize']; $offset = ($param['pageNum']-1)*$param['pageSize']; $sqlCnt = "SELECT count(1) cnt from ( ( SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name', a.item_unit 'plan_name', a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type' ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status from hbp_order_item a INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item' where $item_where order by a.create_time desc ) UNION ( SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name, b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type' ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status from hbp_order_hotel b INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel' where $hotel_where order by b.create_time desc ) ) x $where "; $totalRe = Db::query($sqlCnt); $sql = "SELECT x.* from ( ( SELECT a.order_id,a.id,d.supplier_name,a.trade_order_number,a.item_type 'hotel_name',a.item_name 'room_name', a.item_unit 'plan_name', a.check_in_date,a.check_in_date 'check_out_date',d.count,a.create_time,'item' as 'prod_type' ,a.payment_order_name,a.payment_order_status,a.payment_order_id,a.customer_name,a.total_cost,a.total_price,a.confirm_status from hbp_order_item a INNER JOIN hbp_purchase d on a.id = d.order_detail_id and d.prod_type='item' where $item_where order by a.create_time desc ) UNION ( SELECT b.order_id,b.id,c.supplier_name,b.trade_order_number,b.hotel_name ,b.room_name ,b.plan_name, b.check_in_date,b.check_out_date,c.count,b.create_time,'hotel' as 'prod_type' ,b.payment_order_name,b.payment_order_status,b.payment_order_id,b.customer_name,b.total_cost,b.total_price,b.confirm_status from hbp_order_hotel b INNER JOIN hbp_purchase c on b.id=c.order_detail_id and c.prod_type='hotel' where $hotel_where order by b.create_time desc ) ) x ORDER BY x.create_time desc limit $limit offset $offset"; $list = Db::query($sql); $result = ["list"=>$list,"total"=>$totalRe[0]['cnt']]; return Util::returnArrSu("",$result); } }