@@ -2,6 +2,7 @@ | |||
namespace app\admin\controller; | |||
use app\admin\service\PaymentOrderService; | |||
use app\common\controller\Backend; | |||
/** | |||
@@ -35,6 +36,84 @@ class PaymentOrder extends Backend | |||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 | |||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 | |||
*/ | |||
/** | |||
* 保存记录 | |||
* @return \think\response\Json | |||
*/ | |||
public function save(){ | |||
$params=$this->request->post(); | |||
$params['create_id']=$this->auth->id; | |||
$params['group_id']=$this->auth->getGroupId(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->save($params); | |||
return json($result); | |||
} | |||
/** | |||
* 获取列表 | |||
* @return \think\response\Json | |||
*/ | |||
public function getList(){ | |||
$params=$this->request->post(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->getList($params); | |||
return json($result); | |||
} | |||
/** | |||
* 状态设置 | |||
* @return \think\response\Json | |||
*/ | |||
public function setStatus(){ | |||
$params=$this->request->post(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->setStatus($params['id'],$params['status']); | |||
return json($result); | |||
} | |||
/** | |||
* 添加到收款单 | |||
* @return \think\response\Json | |||
*/ | |||
public function addOrderMain(){ | |||
$params=$this->request->post(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->addOrderMain($params['id'],$params['order_id']); | |||
return json($result); | |||
} | |||
/** | |||
* 移除收购单 | |||
* @return \think\response\Json | |||
*/ | |||
public function removeOrderMain(){ | |||
$params=$this->request->post(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->removeOrderMain($params['order_id']); | |||
return json($result); | |||
} | |||
/** | |||
* 获取订单列表 | |||
* @return \think\response\Json | |||
*/ | |||
public function getOrderMainList(){ | |||
$params=$this->request->post(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->getOrderMainList($params); | |||
return json($result); | |||
} | |||
/** | |||
* 删除收款单 | |||
*/ | |||
public function delAll(){ | |||
$params=$this->request->post(); | |||
$service = new PaymentOrderService(); | |||
$result = $service->delAll($params['id']); | |||
return json($result); | |||
} | |||
} |
@@ -257,7 +257,7 @@ class ReceiptOrder extends Backend | |||
} | |||
/** | |||
* 删除采购单 | |||
* 删除收款单 | |||
*/ | |||
public function delAll(){ | |||
$params=$this->request->post(); | |||
@@ -218,4 +218,63 @@ class OrderHotelDao | |||
return Util::returnArrEr("获取酒店订单列表异常:".$e->getMessage()); | |||
} | |||
} | |||
/**=====================================**/ | |||
/** | |||
* 更新付款单下的状态 | |||
* @param $paymentOrderId | |||
* @param $status | |||
* @return array | |||
*/ | |||
public function setPaymentOrderStatus($paymentOrderId, $status){ | |||
try{ | |||
$model = new OrderHotel(); | |||
$model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新收款单下的酒店订单状态失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 添加酒店订单到付款单下 | |||
* @param $paymentOrder | |||
* @param $orderIds | |||
* @return array | |||
*/ | |||
public function addOrderMainInPayment($paymentOrder,$orderIds){ | |||
try{ | |||
$data = [ | |||
"payment_order_id"=>$paymentOrder['id'], | |||
"payment_order_status"=>$paymentOrder['status'], | |||
"payment_order_name"=>$paymentOrder['name'] | |||
]; | |||
$model = new OrderHotel(); | |||
$model->save($data,["id"=>["in",$orderIds]]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("添加酒店订单到付款单下失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 将酒店订单从付款单下移除 | |||
* @param $orderIds | |||
* @return array | |||
*/ | |||
public function removeOrderMainFormPayment($orderIds){ | |||
try{ | |||
$data = [ | |||
"payment_order_id"=>0, | |||
"payment_order_status"=>0, | |||
"payment_order_name"=>"" | |||
]; | |||
$model = new OrderHotel(); | |||
$model->save($data,["id"=>["in",$orderIds]]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("将酒店订单从付款单下移除失败".$e->getMessage()); | |||
} | |||
} | |||
} |
@@ -169,4 +169,62 @@ class OrderItemDao | |||
} | |||
/**=====================================**/ | |||
/** | |||
* 更新付款单下的状态 | |||
* @param $paymentOrderId | |||
* @param $status | |||
* @return array | |||
*/ | |||
public function setPaymentOrderStatus($paymentOrderId, $status){ | |||
try{ | |||
$model = new OrderItem(); | |||
$model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新收款单下的附加项目订单状态失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 添加附加项目订单到付款单下 | |||
* @param $paymentOrder | |||
* @param $orderIds | |||
* @return array | |||
*/ | |||
public function addOrderMainInPayment($paymentOrder,$orderIds){ | |||
try{ | |||
$data = [ | |||
"payment_order_id"=>$paymentOrder['id'], | |||
"payment_order_status"=>$paymentOrder['status'], | |||
"payment_order_name"=>$paymentOrder['name'] | |||
]; | |||
$model = new OrderItem(); | |||
$model->save($data,["id"=>["in",$orderIds]]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("添加附加项目订单到付款单下失败".$e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 将附加项目订单从付款单下移除 | |||
* @param $orderIds | |||
* @return array | |||
*/ | |||
public function removeOrderMainFormPayment($orderIds){ | |||
try{ | |||
$data = [ | |||
"payment_order_id"=>0, | |||
"payment_order_status"=>0, | |||
"payment_order_name"=>"" | |||
]; | |||
$model = new OrderItem(); | |||
$model->save($data,["id"=>["in",$orderIds]]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("将附加项目订单从付款单下移除失败".$e->getMessage()); | |||
} | |||
} | |||
} |
@@ -0,0 +1,166 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/11/17 | |||
* Time: 17:29 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\PaymentOrder; | |||
use think\Exception; | |||
class PaymentOrderDao | |||
{ | |||
/** | |||
* 获取详情 | |||
* @param $id | |||
* @return array | |||
*/ | |||
public function getInfoById($id){ | |||
try{ | |||
$model = new PaymentOrder(); | |||
$info = $model->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'] | |||
]; | |||
if (isset($param['status'])) { | |||
$data['status'] = $param['status']; | |||
} | |||
$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']])->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]; | |||
if (!empty($param['name'])) { | |||
$where['a.name'] = ["like","%".$param['name']."%"]; | |||
} | |||
if ($param['status'] != 'all') { | |||
$where["a.status"] = $param['status']; | |||
} | |||
$offset = ($param['pageNum'] - 1) * $param['pageSize']; | |||
$receiptOrder = new PaymentOrder(); | |||
$total = $receiptOrder | |||
->alias("a") | |||
->group("a.id") | |||
->where($where)->count(); | |||
$list = $receiptOrder | |||
->alias("a") | |||
->join('hbp_order_hotel b', 'a.id = b.receipt_order_id', 'left') | |||
->join('hbp_order_item c', 'a.id = c.receipt_order_id', 'left') | |||
->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) hotel_ids,sum(b.total_amount) hotel_amount,GROUP_CONCAT(c.id ORDER BY c.id DESC) hotel_ids,sum(c.total_amount) hotel_amount") | |||
->group("a.id") | |||
->where($where) | |||
->limit($offset, $param['pageSize']) | |||
->order("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()); | |||
} | |||
} | |||
} |
@@ -0,0 +1,74 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: nizongfeng | |||
* Date: 2021/11/17 | |||
* Time: 17:29 | |||
*/ | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use think\Db; | |||
class PaymentOrderService | |||
{ | |||
/** | |||
* 保存详情 | |||
* @param $param | |||
* @return array | |||
*/ | |||
public function save($param){ | |||
//保存 | |||
$dao = new PaymentOrderDao(); | |||
$addRe = $dao->save($param); | |||
if (!$addRe['flag']) { | |||
return $addRe; | |||
} | |||
return Util::returnArrSu(); | |||
} | |||
/** | |||
* 获取列表 | |||
* @param $param | |||
* @return array | |||
*/ | |||
public function getList($param){ | |||
$dao = new PaymentOrderDao(); | |||
return $dao->getList($param); | |||
} | |||
/** | |||
* 设置状态 | |||
* @param $id | |||
* @param $status | |||
* @return array | |||
*/ | |||
public function setStatus($id,$status) { | |||
Db::startTrans(); | |||
//1.设置收购单状态 | |||
$dao = new PaymentOrderDao(); | |||
$statusRe = $dao->setStatus($id,$status); | |||
if (!$statusRe['flag']) { | |||
Db::rollback(); | |||
return$statusRe; | |||
} | |||
//2.设置所有订单表的状态 | |||
$hotelDao = new OrderHotelDao(); | |||
$hotelRe = $hotelDao->setPaymentOrderStatus($id,$status); | |||
if (!$hotelRe['flag']) { | |||
Db::rollback(); | |||
return $hotelRe; | |||
} | |||
$itemDao = new OrderItemDao(); | |||
$itemRe = $itemDao->setPaymentOrderStatus($id,$status); | |||
if (!$itemRe['flag']) { | |||
Db::rollback(); | |||
return $itemRe; | |||
} | |||
Db::commit(); | |||
return Util::returnArrSu(); | |||
} | |||
} |
@@ -139,7 +139,7 @@ class ReceiptOrderDao | |||
$list = $receiptOrder | |||
->alias("a") | |||
->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left') | |||
->field("a.*,GROUP_CONCAT(b.id) order_ids,sum(b.total_amount) total_amount") | |||
->field("a.*,GROUP_CONCAT(b.id ORDER BY b.id DESC) order_ids,sum(b.total_amount) total_amount") | |||
->group("a.id") | |||
->where($where) | |||
->limit($offset, $param['pageSize']) | |||