酒店预订平台
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.
 
 
 
 
 
 

187 lines
6.2 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 16:38
  7. */
  8. namespace app\admin\dao;
  9. use app\admin\command\Util;
  10. use app\admin\model\Purchase;
  11. use app\admin\model\PurchasePrice;
  12. use think\Exception;
  13. class PurchaseDao
  14. {
  15. /**
  16. * 添加酒店项目采购单
  17. * @param $param
  18. * @param $hotelOrder
  19. * @return array
  20. */
  21. public function saveHotelPurchase($param,$hotelOrder):array {
  22. try {
  23. $data = [
  24. "order_id" => $hotelOrder['order_id'],
  25. "prod_type" => 'hotel',
  26. "order_detail_id" => $hotelOrder['id'],
  27. "group_id" => $param['group_id'],
  28. "pro_name" => $hotelOrder['hotel_name'],
  29. "item_name" => $hotelOrder['room_name'],
  30. "item_unit" => $hotelOrder['plan_name'],
  31. "check_in_date" => $param['check_in_date'],
  32. "check_out_date" => $param['check_out_date'],
  33. "supplier_id" => $param['supplier_id'],
  34. "supplier_name" => $param['supplier_name'],
  35. "purchase_user_id" => $param['purchase_user_id'],
  36. "purchase_user" => $param['purchase_user'],
  37. "del_flag"=>0
  38. ];
  39. $model = new Purchase();
  40. if (empty($param['purchase_id'])) {
  41. $id = $model->insertGetId($data);
  42. return Util::returnArrSu("", $id);
  43. }else {
  44. $model->save($data,["id"=>$param['purchase_id']]);
  45. return Util::returnArrSu("", $param['purchase_id']);
  46. }
  47. }catch (Exception $e){
  48. return Util::returnArrEr("新增采购单失败:".$e->getMessage());
  49. }
  50. }
  51. /**
  52. * 添加附加项目采购单
  53. * @param $param
  54. * @param $itemOrder
  55. * @return array
  56. */
  57. public function saveItemPurchase($param, $itemOrder):array {
  58. try {
  59. $data = [
  60. "order_id" => $itemOrder['order_id'],
  61. "prod_type" => 'item',
  62. "order_detail_id" => $itemOrder['id'],
  63. "group_id" => $param['group_id'],
  64. "item_name" => $itemOrder['item_name'],
  65. "item_unit" => $itemOrder['item_unit'],
  66. "check_in_date" => $param['check_in_date'],
  67. "supplier_id" => $param['supplier_id'],
  68. "supplier_name" => $param['supplier_name'],
  69. "purchase_user_id" => $param['purchase_user_id'],
  70. "purchase_user" => $param['purchase_user'],
  71. "del_flag"=>0
  72. ];
  73. $model = new Purchase();
  74. if (empty($param['purchase_id'])) {
  75. $id = $model->insertGetId($data);
  76. return Util::returnArrSu("", $id);
  77. }else {
  78. $model->save($data,["id"=>$param['purchase_id']]);
  79. return Util::returnArrSu("", $param['purchase_id']);
  80. }
  81. }catch (Exception $e){
  82. return Util::returnArrEr("新增采购单失败:".$e->getMessage());
  83. }
  84. }
  85. /**
  86. * 设置采购单 金额
  87. * @param $purchaseId
  88. * @return array
  89. */
  90. public function setPurchaseAmount(int $purchaseId){
  91. try{
  92. $purchasePrice = new PurchasePrice();
  93. $purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray();
  94. $cost = 0;
  95. $amount = 0;
  96. $cnt = 0;
  97. foreach ($purchasePriceList as $price) {
  98. $cost += $price['cost'] * $price["count"];
  99. $amount += $price['price'] * $price["count"];
  100. $cnt += $price['count'];
  101. }
  102. $purchase = new Purchase();
  103. $purchase->save(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt,"profit"=>$amount-$cost],["id"=>$purchaseId]);
  104. return Util::returnArrSu();
  105. }catch (Exception $e){
  106. return Util::returnArrEr("更新采购单金额失败:".$e->getMessage());
  107. }
  108. }
  109. /**
  110. * 删除记录
  111. * @param $order_id
  112. */
  113. public function delete($order_id){
  114. $model = new Purchase();
  115. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  116. }
  117. /**
  118. * 删除子订单
  119. * @param $subOrderId
  120. */
  121. public function deleteBySubOrderId($subOrderId) {
  122. $model = new Purchase();
  123. $model->save(["del_flag"=>1],["order_detail_id"=>$subOrderId]);
  124. }
  125. /**
  126. * 获取采购单列表
  127. * @param $orderId
  128. * @return array
  129. */
  130. public function getListByOrderId($orderId) {
  131. $model = new Purchase();
  132. try {
  133. $list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  134. if (null == $list) {
  135. return Util::returnArrSu("",[]);
  136. }
  137. return Util::returnArrSu("",$list);
  138. }catch (Exception $e) {
  139. return Util::returnArrEr("获取订单的采购单列表失败:".$e->getMessage());
  140. }
  141. }
  142. /**
  143. * 设置
  144. * @param $purchaseList
  145. * @param $purchasePriceList
  146. * @return array
  147. */
  148. public function setPurchaseShow($purchaseList,$purchasePriceList){
  149. $result = [];
  150. foreach ($purchaseList as $purchase) {
  151. $purchaseShow=[
  152. "purchase_id"=>$purchase['id'],
  153. "purchase_user_id"=>$purchase['purchase_user_id'],
  154. "purchase_user"=>$purchase['purchase_user'],
  155. "supplier_id"=>$purchase['supplier_id'],
  156. "supplier_name" =>$purchase['supplier_name'],
  157. "purchasePriceList"=>[]
  158. ];
  159. foreach ($purchasePriceList as $price) {
  160. if ($price['purchase_id'] == $purchase['id']) {
  161. $priceShow = [
  162. "id"=>$price['id'],
  163. "run_date"=>$price['run_date'],
  164. "count"=>$price['count'],
  165. "price"=>$price['price'],
  166. "cost"=>$price['cost']
  167. ];
  168. $purchaseShow["purchasePriceList"][]=$priceShow;
  169. }
  170. }
  171. $result[$purchase['order_detail_id']]= $purchaseShow;
  172. }
  173. return Util::returnArrSu("", $result);
  174. }
  175. }