package com.ssj.dao.weixin.order.dao;

import com.ssj.bean.weixin.order.domain.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


@Repository
public interface OrderDao extends JpaRepository<Order, String> {

	 @Query(nativeQuery = true, value = "update tb_orders set transaction_id = ?2 , pay_time =now() , update_time =now() , order_status =?3 where order_no = ?1  ")
  	 @Modifying
	 public void updateOrderStatus(String orderNo,String transactionId,Integer orderStatus);
	 
	 
	@Query(nativeQuery = true, value = "update tb_orders set is_closed = 1 , update_time =now() ,close_time =now() where order_no = ?1 and order_status =1   ")
	@Modifying
	public void updateOrderClosed(String orderNo);
	
	@Query(nativeQuery = true, value = "update tb_orders set  update_time =now() , order_status =4 where order_no = ?1   ")
	@Modifying
	public void updateOrderRefunds(String orderNo);

	@Query(nativeQuery = true, value = " SELECT * from tb_orders where order_type='7' and order_status='1' and user_id=?1   ")
	public Order findUserDepositOrder(String userId);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_orders where order_status=?2 and order_no=?1   ")
	public Order findOrderByOrderNo(String orderNo,String status);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_orders where   order_no=?1   ")
	public Order findOrderNo(String orderNo);
	
	
}
