|
- <?php
- /**
- * Created by PhpStorm.
- * User: nizongfeng
- * Date: 2021/10/27
- * Time: 11:26
- */
-
- namespace app\admin\service;
-
-
- use app\admin\command\Util;
- use app\admin\model\OrderHotel;
- use app\admin\model\OrderItem;
- use app\admin\model\OrderMain;
- use think\Exception;
-
- class OrderMainDao
- {
-
- /**
- * 添加、更新订单信息
- * @param $param
- * @return array
- */
- public function save($param) {
- try{
- $data = [
- "commissioner_id"=>$param['commissioner_id'],
- "commissioner"=>$param["commissioner"],
- "channel_id"=>$param["channel_id"],
- "channel_name"=>$param["channel_name"],
- "channel_order_no"=>$param["channel_order_no"],
- "user_name"=>$param["user_name"],
- "user_phone"=>$param["user_phone"],
- "order_memo"=>$param["order_memo"]
- ];
- $orderMain = new OrderMain();
- if (empty($param['id'])) {
- $id = $orderMain->insertGetId($data);
- return Util::returnArrSu($id);
- } else {
- $orderMain->save($data,['id'=>$param['id']]);
- return Util::returnArrSu($param['id']);
- }
- }catch (Exception $e){
- return Util::returnArrEr("更新主订单失败".$e->getMessage());
- }
-
- }
-
- /**
- * 设置主订单金额
- * @param int $orderId
- * @return array
- */
- public function setOrderAmount(int $orderId){
- try {
- $itemModel = new OrderItem();
- $hotelModel = new OrderHotel();
- $itemList = $itemModel->where(["order_id" => $orderId])->select();
- $hotelList = $hotelModel->where(["order_id" => $orderId])->select();
- $amount = 0;
- $cost = 0;
- foreach ($itemList as $item) {
- $amount += $item['total_price'];
- $cost += $item['total_cost'];
- }
- foreach ($hotelList as $hotel) {
- $amount += $hotel['total_price'];
- $cost += $hotel["total_cost"];
- }
- //更新金额
- OrderMain::update(["total_amount" => $amount, "cost_amount" => $cost])->where(["id" => $orderId]);
- return Util::returnArrSu();
- }catch (Exception $e){
- return Util::returnArrEr("更新主表订单金额失败".$orderId);
- }
- }
-
- /**
- * 根据ID获取详情
- * @param $id
- * @return array
- */
- public function getInfoById($id) {
- try {
- $orderMainModel = new OrderMain();
- $orderMain = $orderMainModel->where(["id" => $id])->find();
- if (null == $orderMain) {
- return Util::returnArrEr("订单查询失败".$id);
- }
- return Util::returnArrSu($orderMain);
- }catch (Exception $e) {
- return Util::returnArrEr("订单查询失败".$e->getMessage());
- }
- }
-
- /**
- * 子订单展示
- * @param $purchaseShow
- * @param $orderHotel
- * @param $orderItem
- * @return array
- */
- public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){
- $result = [];
- foreach ($orderItem as $item) {
- $item['prod_type'] = 'item';
- foreach ($purchaseShow as $key=> $purchase) {
- if ($item['id'] == $key) {
- array_merge($item,$purchase);
- }
- }
- $result[] = $item;
- }
- foreach ($orderHotel as $hotel) {
- $hotel['prod_type'] = 'hotel';
- foreach ($purchaseShow as $key=> $purchase) {
- if ($hotel['id'] == $key) {
- array_merge($hotel,$purchase);
- }
- }
- $result[] = $hotel;
- }
- return Util::returnArrSu($result);
- }
- }
|