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

211 line
7.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\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. //1.获取供应商名称
  24. $suplierDao = new CfSuplierInfoDao();
  25. $suplierRe = $suplierDao->getInfoById($param['supplier_id']);
  26. if (!$suplierRe['flag']) {
  27. return $suplierRe;
  28. }
  29. //2.获取负责人昵称
  30. $adminDao = new AdminDao();
  31. $adminRe = $adminDao->getInfoById($param['purchase_user_id']);
  32. if (!$adminRe['flag']) {
  33. return $adminRe;
  34. }
  35. $data = [
  36. "order_id" => $hotelOrder['order_id'],
  37. "prod_type" => 'hotel',
  38. "order_detail_id" => $hotelOrder['id'],
  39. "group_id" => $param['group_id'],
  40. "pro_name" => $hotelOrder['hotel_name'],
  41. "item_name" => $hotelOrder['room_name'],
  42. "item_unit" => $hotelOrder['plan_name'],
  43. "check_in_date" => $param['check_in_date'],
  44. "check_out_date" => $param['check_out_date'],
  45. "supplier_id" => $param['supplier_id'],
  46. "supplier_name" => $suplierRe['data']['supplier_name'],
  47. "purchase_user_id" => $param['purchase_user_id'],
  48. "purchase_user" => $adminRe['data']['nickname'],
  49. "del_flag"=>0
  50. ];
  51. $model = new Purchase();
  52. if (empty($param['purchase_id'])) {
  53. $id = $model->insertGetId($data);
  54. return Util::returnArrSu("", $id);
  55. }else {
  56. $model->save($data,["id"=>$param['purchase_id']]);
  57. return Util::returnArrSu("", $param['purchase_id']);
  58. }
  59. }catch (Exception $e){
  60. return Util::returnArrEr("新增采购单失败:".$e->getMessage());
  61. }
  62. }
  63. /**
  64. * 添加附加项目采购单
  65. * @param $param
  66. * @param $itemOrder
  67. * @return array
  68. */
  69. public function saveItemPurchase($param, $itemOrder):array {
  70. try {
  71. //1.获取供应商名称
  72. $suplierDao = new CfSuplierInfoDao();
  73. $suplierRe = $suplierDao->getInfoById($param['supplier_id']);
  74. if (!$suplierRe['flag']) {
  75. return $suplierRe;
  76. }
  77. //2.获取负责人昵称
  78. $adminDao = new AdminDao();
  79. $adminRe = $adminDao->getInfoById($param['purchase_user_id']);
  80. if (!$adminRe['flag']) {
  81. return $adminRe;
  82. }
  83. $data = [
  84. "order_id" => $itemOrder['order_id'],
  85. "prod_type" => 'hotel',
  86. "order_detail_id" => $itemOrder['id'],
  87. "group_id" => $param['group_id'],
  88. "item_name" => $itemOrder['item_name'],
  89. "item_unit" => $itemOrder['item_unit'],
  90. "check_in_date" => $param['check_in_date'],
  91. "supplier_id" => $param['supplier_id'],
  92. "supplier_name" => $suplierRe['data']['supplier_name'],
  93. "purchase_user_id" => $param['purchase_user_id'],
  94. "purchase_user" => $adminRe['data']['nickname'],
  95. "del_flag"=>0
  96. ];
  97. $model = new Purchase();
  98. if (empty($param['purchase_id'])) {
  99. $id = $model->insertGetId($data);
  100. return Util::returnArrSu("", $id);
  101. }else {
  102. $model->save($data,["id"=>$param['purchase_id']]);
  103. return Util::returnArrSu("", $param['purchase_id']);
  104. }
  105. }catch (Exception $e){
  106. return Util::returnArrEr("新增采购单失败:".$e->getMessage());
  107. }
  108. }
  109. /**
  110. * 设置采购单 金额
  111. * @param $purchaseId
  112. * @return array
  113. */
  114. public function setPurchaseAmount(int $purchaseId){
  115. try{
  116. $purchasePrice = new PurchasePrice();
  117. $purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray();
  118. $cost = 0;
  119. $amount = 0;
  120. $cnt = 0;
  121. foreach ($purchasePriceList as $price) {
  122. $cost += $price['cost'] * $price["count"];
  123. $amount += $price['price'] * $price["count"];
  124. $cnt += $price['count'];
  125. }
  126. $purchase = new Purchase();
  127. $purchase->save(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt,"profit"=>$amount-$cost],["id"=>$purchaseId]);
  128. return Util::returnArrSu();
  129. }catch (Exception $e){
  130. return Util::returnArrEr("更新采购单金额失败:".$e->getMessage());
  131. }
  132. }
  133. /**
  134. * 删除记录
  135. * @param $order_id
  136. */
  137. public function delete($order_id){
  138. $model = new Purchase();
  139. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  140. }
  141. /**
  142. * 删除子订单
  143. * @param $subOrderId
  144. */
  145. public function deleteBySubOrderId($subOrderId) {
  146. $model = new Purchase();
  147. $model->save(["del_flag"=>1],["order_detail_id"=>$subOrderId]);
  148. }
  149. /**
  150. * 获取采购单列表
  151. * @param $orderId
  152. * @return array
  153. */
  154. public function getListByOrderId($orderId) {
  155. $model = new Purchase();
  156. try {
  157. $list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  158. if (null == $list) {
  159. return Util::returnArrSu("",[]);
  160. }
  161. return Util::returnArrSu("",$list);
  162. }catch (Exception $e) {
  163. return Util::returnArrEr("获取订单的采购单列表失败:".$e->getMessage());
  164. }
  165. }
  166. /**
  167. * 设置
  168. * @param $purchaseList
  169. * @param $purchasePriceList
  170. * @return array
  171. */
  172. public function setPurchaseShow($purchaseList,$purchasePriceList){
  173. $result = [];
  174. foreach ($purchaseList as $purchase) {
  175. $purchaseShow=[
  176. "purchase_id"=>$purchase['id'],
  177. "purchase_user_id"=>$purchase['purchase_user_id'],
  178. "purchase_user"=>$purchase['purchase_user'],
  179. "supplier_id"=>$purchase['supplier_id'],
  180. "supplier_name" =>$purchase['supplier_name'],
  181. "purchasePriceList"=>[]
  182. ];
  183. foreach ($purchasePriceList as $price) {
  184. if ($price['purchase_id'] == $purchase['id']) {
  185. $priceShow = [
  186. "id"=>$price['id'],
  187. "run_date"=>$price['run_date'],
  188. "count"=>$price['count'],
  189. "price"=>$price['price'],
  190. "cost"=>$price['cost']
  191. ];
  192. $purchaseShow["purchasePriceList"][]=$priceShow;
  193. }
  194. }
  195. $result[$purchase['order_detail_id']]= $purchaseShow;
  196. }
  197. return Util::returnArrSu("", $result);
  198. }
  199. }