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

189 lines
6.5 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\service;
  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" => empty($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" => empty($param['supplier_id'])?0:$param['supplier_id'],
  34. "supplier_name" => empty($param['supplier_name'])?"":$param['supplier_name'],
  35. "purchase_user_id" => empty($param['purchase_user_id'])?0:$param['purchase_user_id'],
  36. "purchase_user" => empty($param['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" => 'hotel',
  62. "order_detail_id" => $itemOrder['id'],
  63. "group_id" => $param['group_id'],
  64. "pro_name" => $itemOrder['hotel_name'],
  65. "item_name" => $itemOrder['item_name'],
  66. "item_unit" => $itemOrder['item_unit'],
  67. "check_in_date" => $param['check_in_date'],
  68. "check_out_date" => $param['check_out_date'],
  69. "supplier_id" => $param['supplier_id'],
  70. "supplier_name" => $param['supplier_name'],
  71. "purchase_user_id" => $param['purchase_user_id'],
  72. "purchase_user" => $param['purchase_user'],
  73. "del_flag"=>0
  74. ];
  75. $model = new Purchase();
  76. if (empty($param['purchase_id'])) {
  77. $id = $model->insertGetId($data);
  78. return Util::returnArrSu("", $id);
  79. }else {
  80. $model->save($data,["id"=>$param['purchase_id']]);
  81. return Util::returnArrSu("", $param['purchase_id']);
  82. }
  83. }catch (Exception $e){
  84. return Util::returnArrEr("新增采购都失败:".$e->getMessage());
  85. }
  86. }
  87. /**
  88. * 设置采购单 金额
  89. * @param $purchaseId
  90. * @return array
  91. */
  92. public function setPurchaseAmount(int $purchaseId){
  93. try{
  94. $purchasePrice = new PurchasePrice();
  95. $purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray();
  96. $cost = 0;
  97. $amount = 0;
  98. $cnt = 0;
  99. foreach ($purchasePriceList as $price) {
  100. $cost += $price['cost'] * $price["count"];
  101. $amount += $price['price'] * $price["count"];
  102. $cnt += $price['count'];
  103. }
  104. $purchase = new Purchase();
  105. $purchase->save(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt,"profit"=>$amount-$cost],["id"=>$purchaseId]);
  106. return Util::returnArrSu();
  107. }catch (Exception $e){
  108. return Util::returnArrEr("更新采购单金额失败:".$e->getMessage());
  109. }
  110. }
  111. /**
  112. * 删除记录
  113. * @param $order_id
  114. */
  115. public function delete($order_id){
  116. $model = new Purchase();
  117. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  118. }
  119. /**
  120. * 删除子订单
  121. * @param $subOrderId
  122. */
  123. public function deleteBySubOrderId($subOrderId) {
  124. $model = new Purchase();
  125. $model->save(["del_flag"=>1],["order_detail_id"=>$subOrderId]);
  126. }
  127. /**
  128. * 获取采购单列表
  129. * @param $orderId
  130. * @return array
  131. */
  132. public function getListByOrderId($orderId) {
  133. $model = new Purchase();
  134. try {
  135. $list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  136. if (null == $list) {
  137. return Util::returnArrSu("",[]);
  138. }
  139. return Util::returnArrSu("",$list);
  140. }catch (Exception $e) {
  141. return Util::returnArrEr("获取订单的采购单列表失败:".$e->getMessage());
  142. }
  143. }
  144. /**
  145. * 设置
  146. * @param $purchaseList
  147. * @param $purchasePriceList
  148. * @return array
  149. */
  150. public function setPurchaseShow($purchaseList,$purchasePriceList){
  151. $result = [];
  152. foreach ($purchaseList as $purchase) {
  153. $purchaseShow=[
  154. "purchase_id"=>$purchase['id'],
  155. "purchase_user_id"=>$purchase['purchase_user_id'],
  156. "purchase_user"=>$purchase['purchase_user'],
  157. "supplier_id"=>$purchase['supplier_id'],
  158. "supplier_name" =>$purchase['supplier_name'],
  159. "purchasePriceList"=>[]
  160. ];
  161. foreach ($purchasePriceList as $price) {
  162. if ($price['purchase_id'] == $purchase['id']) {
  163. $priceShow = [
  164. "id"=>$price['id'],
  165. "run_date"=>$price['run_date'],
  166. "count"=>$price['count'],
  167. "price"=>$price['price'],
  168. "cost"=>$price['cost']
  169. ];
  170. $purchaseShow["purchasePriceList"][]=$priceShow;
  171. }
  172. }
  173. $result[$purchase['order_detail_id']]= $purchaseShow;
  174. }
  175. return Util::returnArrSu("", $result);
  176. }
  177. }