酒店预订平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

309 lignes
9.6 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. "purchase_user_id" => $param['purchase_user_id'],
  50. "purchase_user" => $param['purchase_user'],
  51. "supplier_id" => $param['supplier_id'],
  52. "supplier_name" => $param['supplier_name'],
  53. "del_flag"=>0
  54. ];
  55. $model = new OrderItem();
  56. if (empty($param['id'])) {
  57. $data["create_id"]= $param['create_id'];
  58. $data["group_id"]= $param['group_id'];
  59. $id = $model->insertGetId($data);
  60. return Util::returnArrSu("",$id);
  61. }else {
  62. $model->save($data,["id"=>$param['id']]);
  63. return Util::returnArrSu("",$param['id']);
  64. }
  65. }catch (Exception $e){
  66. return Util::returnArrEr("更新附加项目子订单失败:".$e->getMessage());
  67. }
  68. }
  69. /**
  70. * 获取附加项目信息
  71. * @param $id
  72. * @return array
  73. */
  74. public function getItemInfo($id)
  75. {
  76. try {
  77. $model = new CfItem();
  78. $result = $model->where(["id" => $id])->find();
  79. if ($result == null) {
  80. return Util::returnArrEr("获取附加项目信息失败:" . $id);
  81. }
  82. return Util::returnArrSu("",$result->toArray());
  83. } catch (Exception $e) {
  84. return Util::returnArrEr("获取附加项目信息失败:" . $id);
  85. }
  86. }
  87. /**
  88. * 设置子订单金额
  89. * @param int $subOrderId
  90. * @return array
  91. */
  92. public function setSubOrderAmount( int $subOrderId) {
  93. try{
  94. $purchaseModel = new Purchase();
  95. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0,"prod_type"=>"item"])->select()->toArray();
  96. $cost = 0;
  97. $amount = 0;
  98. $count = 0;
  99. foreach ($purchaseList as $purchase) {
  100. $cost += $purchase['total_cost'];
  101. $amount += $purchase['total_price'];
  102. $count += $purchase['count'];
  103. }
  104. //更新数据
  105. $oderItem = new OrderItem();
  106. $oderItem->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count,"profit"=>$amount-$cost],["id"=>$subOrderId]);
  107. return Util::returnArrSu();
  108. }catch (Exception $e){
  109. return Util::returnArrEr("更新附加项目订单子表金额失败:".$subOrderId);
  110. }
  111. }
  112. /**
  113. * 获取详情
  114. * @param $id
  115. * @return array
  116. */
  117. public function getInfoById($id) {
  118. try {
  119. $model = new OrderItem();
  120. $result = $model->where(["id" => $id])->find();
  121. if ($result == null) {
  122. return Util::returnArrEr("获取子订单信息失败:" . $id);
  123. }
  124. return Util::returnArrSu("", $result->toArray());
  125. } catch (Exception $e) {
  126. return Util::returnArrEr("获取子订单信息失败:" . $id);
  127. }
  128. }
  129. /**
  130. * 删除记录
  131. * @param $order_id
  132. */
  133. public function delete($order_id){
  134. $model = new OrderItem();
  135. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  136. }
  137. /**
  138. * 删除记录
  139. * @param $id
  140. */
  141. public function delById($id) {
  142. $model = new OrderItem();
  143. $model->save(["del_flag"=>1],["id"=>$id]);
  144. }
  145. /**
  146. * 获取附加项目子订单列表
  147. * @param $orderId
  148. * @return array
  149. */
  150. public function getListByOrderId($orderId){
  151. $subOrderModel = new OrderItem();
  152. try {
  153. $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  154. if (null == $subOrderList) {
  155. return Util::returnArrSu("",[]);
  156. }
  157. return Util::returnArrSu("", $subOrderList);
  158. }catch (Exception $e) {
  159. return Util::returnArrEr("获取附加项目订单列表异常".$e->getMessage());
  160. }
  161. }
  162. /**=====================================**/
  163. /**
  164. * 更新付款单下的状态
  165. * @param $paymentOrderId
  166. * @param $status
  167. * @return array
  168. */
  169. public function setPaymentOrderStatus($paymentOrderId, $status){
  170. try{
  171. $model = new OrderItem();
  172. $model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]);
  173. return Util::returnArrSu();
  174. }catch (Exception $e){
  175. return Util::returnArrEr("更新收款单下的附加项目订单状态失败".$e->getMessage());
  176. }
  177. }
  178. /**
  179. * 添加附加项目订单到付款单下
  180. * @param $paymentOrder
  181. * @param $orderIds
  182. * @return array
  183. */
  184. public function addSubOrderInPayment($paymentOrder,$orderIds){
  185. try{
  186. $data = [
  187. "payment_order_id"=>$paymentOrder['id'],
  188. "payment_order_status"=>$paymentOrder['status'],
  189. "payment_order_name"=>$paymentOrder['name']
  190. ];
  191. $model = new OrderItem();
  192. $model->save($data,["id"=>["in",$orderIds]]);
  193. return Util::returnArrSu();
  194. }catch (Exception $e){
  195. return Util::returnArrEr("添加附加项目订单到付款单下失败".$e->getMessage());
  196. }
  197. }
  198. /**
  199. * 将附加项目订单从付款单下移除
  200. * @param $orderIds
  201. * @return array
  202. */
  203. public function removeSubOrderFormPayment($orderIds){
  204. try{
  205. $data = [
  206. "payment_order_id"=>0,
  207. "payment_order_status"=>0,
  208. "payment_order_name"=>""
  209. ];
  210. $model = new OrderItem();
  211. $model->save($data,["id"=>["in",$orderIds]]);
  212. return Util::returnArrSu();
  213. }catch (Exception $e){
  214. return Util::returnArrEr("将附加项目订单从付款单下移除失败".$e->getMessage());
  215. }
  216. }
  217. /**
  218. * 删除采购单
  219. * @param $id
  220. * @return array
  221. */
  222. public function delPaymentOrder($id){
  223. try{
  224. $data = [
  225. "payment_order_id"=>0,
  226. "payment_order_status"=>0,
  227. "payment_order_name"=>""
  228. ];
  229. $model = new OrderItem();
  230. $model->save($data,["payment_order_id"=>$id]);
  231. return Util::returnArrSu();
  232. }catch (Exception $e){
  233. return Util::returnArrEr("将附加项目订单从付款单下移除失败".$e->getMessage());
  234. }
  235. }
  236. /**
  237. * 获取主订单ID
  238. * @param $payment_order_id
  239. * @return array
  240. */
  241. public function getOrderMainIdByPayment($payment_order_id){
  242. $subOrderModel = new OrderItem();
  243. try {
  244. $subOrderList = $subOrderModel->where(["payment_order_id" => $payment_order_id, "del_flag" => 0])->select()->toArray();
  245. if (null == $subOrderList) {
  246. return [];
  247. }
  248. $id = [];
  249. foreach ($subOrderList as $val){
  250. $id[] = $val['order_id'];
  251. }
  252. return array_unique($id);
  253. }catch (Exception $e) {
  254. return [];
  255. }
  256. }
  257. /**
  258. * 获取订单列表
  259. * @param $orderIds
  260. * @return array
  261. */
  262. public function getOrderListByOrderIds($orderIds){
  263. $subOrderModel = new OrderItem();
  264. try {
  265. $subOrderList = $subOrderModel->where(["order_id" => ["in",$orderIds], "del_flag" => 0])->order("id","DESC")->select()->toArray();
  266. if (null == $subOrderList) {
  267. return [];
  268. }
  269. return $subOrderList;
  270. }catch (Exception $e) {
  271. return [];
  272. }
  273. }
  274. public function updatePayOrderName($id, $name) {
  275. try{
  276. $data = [
  277. "payment_order_name"=>$name
  278. ];
  279. $model = new OrderItem();
  280. $model->save($data,["payment_order_id"=>$id]);
  281. return Util::returnArrSu();
  282. }catch (Exception $e){
  283. return Util::returnArrEr("同步名称到订单失败".$e->getMessage());
  284. }
  285. }
  286. }