|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /**
- * Created by PhpStorm.
- * User: nizongfeng
- * Date: 2021/10/27
- * Time: 13:36
- */
-
- namespace app\admin\service;
-
-
- use app\admin\command\Util;
- use app\admin\model\CfItem;
- use app\admin\model\OrderHotel;
- use app\admin\model\OrderItem;
- use app\admin\model\Purchase;
- use think\Exception;
-
- class OrderItemDao
- {
-
-
- /**
- * 新增、更新记录
- * @param $param
- * @param $orderId
- * @return array|string
- */
- public function modify($param, $orderId)
- {
- $itemInfo = $this->getItemInfo($param['item_id']);
- if (!$itemInfo['flag']){
- return $itemInfo;
- }
- try{
- //设置入参
- $data = [
- "order_id" => $orderId,
- //附加项目
- "item_id"=>$itemInfo['data']['id'],
- "item_type"=>$itemInfo['data']['item_type'],
- "item_name"=>$itemInfo['data']['item_name'],
- "item_memo"=>$itemInfo['data']['item_memo'],
- "item_unit"=>$itemInfo['data']['item_unit'],
- "area_name" => $itemInfo['data']['area_name'],
- "province_name" => $itemInfo['data']['province_name'],
- "city_name" => $itemInfo['data']['city_name'],
- "detail_address" => $itemInfo['data']['detail_address'],
- //其他
- "check_in_date" => $param['check_in_date'],
- "confirm_status" => $param['confirm_status'],
- "confirm_no" => $param['confirm_no'],
- "customer_name" => $param['customer_name'],
- "customer_comments" => empty($param['customer_comments'])?"":$param['customer_comments'],
- "trade_order_number" => $param['trade_order_number'],
- "del_flag"=>0
- ];
- $orderHotelModel = new OrderHotel();
- if (empty($param['id'])) {
- $id = $orderHotelModel->insertGetId($data);
- return Util::returnArrSu("",$id);
- }else {
- $orderHotelModel->save($data,["id"=>$param['id']]);
- return Util::returnArrSu("",$param['id']);
- }
- }catch (Exception $e){
- return Util::returnArrEr("更新附加项目子订单失败:".$e->getMessage());
- }
-
- }
-
- /**
- * 获取附加项目信息
- * @param $id
- * @return array
- */
- public function getItemInfo($id)
- {
- try {
- $model = new CfItem();
- $result = $model->where(["id" => $id])->find()->toArray();
- if ($result == null) {
- return Util::returnArrEr("获取附加项目信息失败:" . $id);
- }
- return Util::returnArrSu("",$result);
- } catch (Exception $e) {
- return Util::returnArrEr("获取附加项目信息失败:" . $id);
- }
- }
-
- /**
- * 设置子订单金额
- * @param int $subOrderId
- * @return array
- */
- public function setSubOrderAmount( int $subOrderId) {
- try{
- $purchaseModel = new Purchase();
- $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select();
- $cost = 0;
- $amount = 0;
- $count = 0;
- foreach ($purchaseList as $purchase) {
- $cost += $purchase['total_cost'];
- $amount += $purchase['total_price'];
- $count += $purchase['count'];
- }
- //更新数据
- $oderItem = new OrderItem();
- $oderItem->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count,"profit"=>$amount-$cost])->where(["id"=>$subOrderId]);
- return Util::returnArrSu();
- }catch (Exception $e){
- return Util::returnArrEr("更新附加项目订单子表金额失败:".$subOrderId);
- }
-
- }
-
- /**
- * 获取详情
- * @param $id
- * @return array
- */
- public function getInfoById($id) {
- try {
- $model = new OrderItem();
- $result = $model->where(["id" => $id])->find()->toArray();
- if ($result == null) {
- return Util::returnArrEr("获取子订单信息失败:" . $id);
- }
- return Util::returnArrSu("", $result);
- } catch (Exception $e) {
- return Util::returnArrEr("获取子订单信息失败:" . $id);
- }
- }
-
- /**
- * 删除记录
- * @param $order_id
- */
- public function delete($order_id){
- $model = new OrderItem();
- $model->save(["del_flag"=>1],["order_id"=>$order_id]);
- }
-
- /**
- * 删除记录
- * @param $id
- */
- public function delById($id) {
- $model = new OrderItem();
- $model->save(["del_flag"=>1],["id"=>$id]);
- }
-
- /**
- * 获取附加项目子订单列表
- * @param $orderId
- * @return array
- */
- public function getListByOrderId($orderId){
- $subOrderModel = new OrderItem();
- try {
- $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select();
- if (null == $subOrderList) {
- return Util::returnArrSu("",[]);
- }
- return Util::returnArrSu("", $subOrderList);
- }catch (Exception $e) {
- return Util::returnArrEr("获取附加项目订单列表异常".$e->getMessage());
- }
- }
-
-
- }
|