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

290 lines
8.8 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 13:36
  7. */
  8. namespace app\admin\dao;
  9. use app\admin\command\Util;
  10. use app\admin\model\CfItem;
  11. use app\admin\model\OrderItem;
  12. use app\admin\model\Purchase;
  13. use think\Exception;
  14. class OrderItemDao
  15. {
  16. /**
  17. * 新增、更新记录
  18. * @param $param
  19. * @param $orderId
  20. * @return array|string
  21. */
  22. public function modify($param, $orderId)
  23. {
  24. $itemInfo = $this->getItemInfo($param['item_id']);
  25. if (!$itemInfo['flag']){
  26. return $itemInfo;
  27. }
  28. try{
  29. //设置入参
  30. $data = [
  31. "order_id" => $orderId,
  32. //附加项目
  33. "item_id"=>$itemInfo['data']['id'],
  34. "item_type"=>$itemInfo['data']['item_type'],
  35. "item_name"=>$itemInfo['data']['item_name'],
  36. "item_memo"=>$itemInfo['data']['item_memo'],
  37. "item_unit"=>$itemInfo['data']['item_unit'],
  38. "area_name" => $itemInfo['data']['area_name'],
  39. "province_name" => $itemInfo['data']['province_name'],
  40. "city_name" => $itemInfo['data']['city_name'],
  41. "detail_address" => $itemInfo['data']['detail_address'],
  42. //其他
  43. "check_in_date" => $param['check_in_date'],
  44. "confirm_status" => $param['confirm_status'],
  45. "confirm_no" => $param['confirm_no'],
  46. "customer_name" => $param['customer_name'],
  47. "customer_comments" => empty($param['customer_comments'])?"":$param['customer_comments'],
  48. "trade_order_number" => $param['trade_order_number'],
  49. "del_flag"=>0
  50. ];
  51. $model = new OrderItem();
  52. if (empty($param['id'])) {
  53. $id = $model->insertGetId($data);
  54. return Util::returnArrSu("",$id);
  55. }else {
  56. $model->save($data,["id"=>$param['id']]);
  57. return Util::returnArrSu("",$param['id']);
  58. }
  59. }catch (Exception $e){
  60. return Util::returnArrEr("更新附加项目子订单失败:".$e->getMessage());
  61. }
  62. }
  63. /**
  64. * 获取附加项目信息
  65. * @param $id
  66. * @return array
  67. */
  68. public function getItemInfo($id)
  69. {
  70. try {
  71. $model = new CfItem();
  72. $result = $model->where(["id" => $id])->find();
  73. if ($result == null) {
  74. return Util::returnArrEr("获取附加项目信息失败:" . $id);
  75. }
  76. return Util::returnArrSu("",$result->toArray());
  77. } catch (Exception $e) {
  78. return Util::returnArrEr("获取附加项目信息失败:" . $id);
  79. }
  80. }
  81. /**
  82. * 设置子订单金额
  83. * @param int $subOrderId
  84. * @return array
  85. */
  86. public function setSubOrderAmount( int $subOrderId) {
  87. try{
  88. $purchaseModel = new Purchase();
  89. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select()->toArray();
  90. $cost = 0;
  91. $amount = 0;
  92. $count = 0;
  93. foreach ($purchaseList as $purchase) {
  94. $cost += $purchase['total_cost'];
  95. $amount += $purchase['total_price'];
  96. $count += $purchase['count'];
  97. }
  98. //更新数据
  99. $oderItem = new OrderItem();
  100. $oderItem->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count,"profit"=>$amount-$cost],["id"=>$subOrderId]);
  101. return Util::returnArrSu();
  102. }catch (Exception $e){
  103. return Util::returnArrEr("更新附加项目订单子表金额失败:".$subOrderId);
  104. }
  105. }
  106. /**
  107. * 获取详情
  108. * @param $id
  109. * @return array
  110. */
  111. public function getInfoById($id) {
  112. try {
  113. $model = new OrderItem();
  114. $result = $model->where(["id" => $id])->find();
  115. if ($result == null) {
  116. return Util::returnArrEr("获取子订单信息失败:" . $id);
  117. }
  118. return Util::returnArrSu("", $result->toArray());
  119. } catch (Exception $e) {
  120. return Util::returnArrEr("获取子订单信息失败:" . $id);
  121. }
  122. }
  123. /**
  124. * 删除记录
  125. * @param $order_id
  126. */
  127. public function delete($order_id){
  128. $model = new OrderItem();
  129. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  130. }
  131. /**
  132. * 删除记录
  133. * @param $id
  134. */
  135. public function delById($id) {
  136. $model = new OrderItem();
  137. $model->save(["del_flag"=>1],["id"=>$id]);
  138. }
  139. /**
  140. * 获取附加项目子订单列表
  141. * @param $orderId
  142. * @return array
  143. */
  144. public function getListByOrderId($orderId){
  145. $subOrderModel = new OrderItem();
  146. try {
  147. $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  148. if (null == $subOrderList) {
  149. return Util::returnArrSu("",[]);
  150. }
  151. return Util::returnArrSu("", $subOrderList);
  152. }catch (Exception $e) {
  153. return Util::returnArrEr("获取附加项目订单列表异常".$e->getMessage());
  154. }
  155. }
  156. /**=====================================**/
  157. /**
  158. * 更新付款单下的状态
  159. * @param $paymentOrderId
  160. * @param $status
  161. * @return array
  162. */
  163. public function setPaymentOrderStatus($paymentOrderId, $status){
  164. try{
  165. $model = new OrderItem();
  166. $model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]);
  167. return Util::returnArrSu();
  168. }catch (Exception $e){
  169. return Util::returnArrEr("更新收款单下的附加项目订单状态失败".$e->getMessage());
  170. }
  171. }
  172. /**
  173. * 添加附加项目订单到付款单下
  174. * @param $paymentOrder
  175. * @param $orderIds
  176. * @return array
  177. */
  178. public function addSubOrderInPayment($paymentOrder,$orderIds){
  179. try{
  180. $data = [
  181. "payment_order_id"=>$paymentOrder['id'],
  182. "payment_order_status"=>$paymentOrder['status'],
  183. "payment_order_name"=>$paymentOrder['name']
  184. ];
  185. $model = new OrderItem();
  186. $model->save($data,["id"=>["in",$orderIds]]);
  187. return Util::returnArrSu();
  188. }catch (Exception $e){
  189. return Util::returnArrEr("添加附加项目订单到付款单下失败".$e->getMessage());
  190. }
  191. }
  192. /**
  193. * 将附加项目订单从付款单下移除
  194. * @param $orderIds
  195. * @return array
  196. */
  197. public function removeSubOrderFormPayment($orderIds){
  198. try{
  199. $data = [
  200. "payment_order_id"=>0,
  201. "payment_order_status"=>0,
  202. "payment_order_name"=>""
  203. ];
  204. $model = new OrderItem();
  205. $model->save($data,["id"=>["in",$orderIds]]);
  206. return Util::returnArrSu();
  207. }catch (Exception $e){
  208. return Util::returnArrEr("将附加项目订单从付款单下移除失败".$e->getMessage());
  209. }
  210. }
  211. /**
  212. * 删除采购单
  213. * @param $id
  214. * @return array
  215. */
  216. public function delPaymentOrder($id){
  217. try{
  218. $data = [
  219. "payment_order_id"=>0,
  220. "payment_order_status"=>0,
  221. "payment_order_name"=>""
  222. ];
  223. $model = new OrderItem();
  224. $model->save($data,["payment_order_id"=>$id]);
  225. return Util::returnArrSu();
  226. }catch (Exception $e){
  227. return Util::returnArrEr("将附加项目订单从付款单下移除失败".$e->getMessage());
  228. }
  229. }
  230. /**
  231. * 获取主订单ID
  232. * @param $payment_order_id
  233. * @return array
  234. */
  235. public function getOrderMainIdByPayment($payment_order_id){
  236. $subOrderModel = new OrderItem();
  237. try {
  238. $subOrderList = $subOrderModel->where(["payment_order_id" => $payment_order_id, "del_flag" => 0])->select()->toArray();
  239. if (null == $subOrderList) {
  240. return [];
  241. }
  242. $id = [];
  243. foreach ($subOrderList as $val){
  244. $id[] = $val['order_id'];
  245. }
  246. return array_unique($id);
  247. }catch (Exception $e) {
  248. return [];
  249. }
  250. }
  251. /**
  252. * 获取订单列表
  253. * @param $orderIds
  254. * @return array
  255. */
  256. public function getOrderListByOrderIds($orderIds){
  257. $subOrderModel = new OrderItem();
  258. try {
  259. $subOrderList = $subOrderModel->where(["order_id" => ["in",$orderIds], "del_flag" => 0])->select()->toArray();
  260. if (null == $subOrderList) {
  261. return [];
  262. }
  263. return $subOrderList;
  264. }catch (Exception $e) {
  265. return [];
  266. }
  267. }
  268. }