酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PurchasePriceDao.php 2.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 19:19
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\model\PurchasePrice;
  11. use think\Exception;
  12. class PurchasePriceDao
  13. {
  14. /**
  15. * 添加采购单每日价格
  16. * @param $param
  17. * @param int $order_id
  18. * @param string $prod_type
  19. * @param int $order_detail_id
  20. * @param int $purchase_id
  21. * @return array
  22. */
  23. public function saveList($param, int $order_id, string $prod_type, int $order_detail_id, int $purchase_id)
  24. {
  25. try {
  26. //删除记录
  27. $this->delete($order_detail_id);
  28. //循环添加
  29. foreach ($param as $value) {
  30. $data = [
  31. "order_id" => $order_id,
  32. "prod_type" => $prod_type,
  33. "order_detail_id" => $order_detail_id,
  34. "purchase_id" => $purchase_id,
  35. "run_date" => $value['run_date'],
  36. "count" => $value['count'],
  37. "price" => $value['price'],
  38. "cost" => $value['cost'],
  39. "del_flag" => 0
  40. ];
  41. $model = new PurchasePrice();
  42. if (empty($value['id'])) {
  43. $model->insertGetId($data);
  44. } else {
  45. $model->save($data, ["id" => $value['id']]);
  46. }
  47. }
  48. return Util::returnArrSu();
  49. } catch (Exception $e) {
  50. return Util::returnArrEr("添加/更新采购单每日价格失败:" . $e->getMessage());
  51. }
  52. }
  53. /**
  54. * 删除数据
  55. * @param $purchase_id
  56. */
  57. public function delete($purchase_id)
  58. {
  59. $model = new PurchasePrice();
  60. $model->save(["del_flag" => 1], ["purchase_id" => $purchase_id]);
  61. }
  62. /**
  63. * 删除子订单对于的每日价格
  64. * @param $subOrderId
  65. */
  66. public function deleteBySubOrderId($subOrderId) {
  67. $model = new PurchasePrice();
  68. $model->save(["del_flag" => 1], ["order_detail_id" => $subOrderId]);
  69. }
  70. /**
  71. * 获取采购单金额
  72. * @param $orderId
  73. * @return array
  74. */
  75. public function getPurchasePriceListByOrderId($orderId) {
  76. $model = new PurchasePrice();
  77. try {
  78. $list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  79. if (null == $list) {
  80. return Util::returnArrSu("", []);
  81. }
  82. return Util::returnArrSu("", $list);
  83. }catch (Exception $e) {
  84. return Util::returnArrEr("获取采购单金额异常".$e->getMessage());
  85. }
  86. }
  87. }