123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- package com.mall.model.product;
- import com.jfinal.plugin.activerecord.Db;
- import com.jfinal.plugin.activerecord.Model;
- import com.jfinal.plugin.activerecord.Page;
- import com.jfinal.plugin.activerecord.Record;
- import com.mall.util.DateUtil;
- import com.mall.util.Utility;
- import org.apache.commons.lang.ObjectUtils;
- import org.apache.commons.lang.StringUtils;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- @SuppressWarnings("serial")
- public class Product extends Model<Product>
- {
- public static final Product dao = new Product();
-
- /**
- *
- * @Description 查询
- * @author zhengwei
- * @date 2017年8月25日 下午3:27:34
- * @param pageNumber
- * @param pageSize
- * @return Page<Product>
- */
- public Page<Product> query(Integer merchantId, Map<String,Object> params, int pageNumber, int pageSize){
- StringBuffer sql = new StringBuffer();
- StringBuffer select = new StringBuffer();
- List<String> param=new ArrayList<String>();
- select.append(" select t.*");
- sql.append(" from product t where 1=1 ");
- if(Utility.isNotEmpty(params.get("productName"))){
- sql.append(" and product_name like ?");
- param.add("%"+ObjectUtils.toString(params.get("productName"))+"%");
- }
- if(Utility.isNotEmpty(params.get("merchantName"))){
- sql.append(" and merchant_name like ?");
- param.add("%"+ObjectUtils.toString(params.get("merchantName"))+"%");
- }
- if(Utility.isNotEmpty(params.get("productType"))){
- sql.append(" and product_type = ?");
- param.add(ObjectUtils.toString(params.get("productType")));
- }
- if(Utility.isNotEmpty(params.get("productOwner"))){
- sql.append(" and product_owner = ?");
- param.add(ObjectUtils.toString(params.get("productOwner")));
- }
- if(merchantId!=null) {
- sql.append(" and merchant_id = ?");
- param.add(""+merchantId+"");
- }
- sql.append(" order by create_time desc");
- if(param.isEmpty()){
- return paginate(pageNumber, pageSize, select.toString(), sql.toString());
- }else{
- return paginate(pageNumber, pageSize, select.toString(), sql.toString(),param.toArray());
- }
- }
-
- /**
- *
- * @Description 查询
- * @author zhengwei
- * @date 2017年8月25日 下午3:27:34
- * @param pageNumber
- * @param pageSize
- * @return Page<Product>
- */
- public Page<Product> getList(String type, int pageNumber, int pageSize){
- StringBuffer sql = new StringBuffer();
- StringBuffer select = new StringBuffer();
- select.append(" select t.id ,t.merchant_name,t.product_name,t.product_price,t.product_old_price,t.product_num,");
- select.append(" t.product_main_img,t.visit_num,t.end_time,t.use_time,t.order_hour,t.time_status,t.share_price");
- sql.append(" from product t where product_type='10' and product_owner='10' and t.status='1' ");
- sql.append(" and t.start_time<'"+DateUtil.formatDateTime(new Date())+"'");
- if(StringUtils.isNotEmpty(type)){
- sql.append(" and t.merchant_id in (select id from merchant where merchant_category="+type+")");
- }
- sql.append(" order by t.time_status, t.is_hot desc, t.sort desc");
- return paginate(pageNumber, pageSize, select.toString(), sql.toString());
- }
- /**
- *
- * @Description 查询
- * @author zhengwei
- * @date 2017年8月25日 下午3:27:34
- * @param pageNumber
- * @param pageSize
- * @return Page<Product>
- */
- public Page<Product> getCutList(String type, int pageNumber, int pageSize){
- StringBuffer sql = new StringBuffer();
- StringBuffer select = new StringBuffer();
- select.append(" select t.id ,t.merchant_name,t.product_name,t.product_price,t.product_old_price,t.product_num,");
- select.append(" t.product_main_img,t.visit_num,t.end_time,t.use_time,t.order_hour,t.time_status,t.share_price");
- sql.append(" from product t where product_type='20' and t.status='1' ");
- sql.append(" and t.start_time<'"+DateUtil.formatDateTime(new Date())+"'");
- // if("0".equals(type)){
- // sql.append(" and t.use_time>'"+DateUtil.formatDateTime(new Date())+"'");
- // }else {
- // sql.append(" and t.use_time<'"+DateUtil.formatDateTime(new Date())+"'");
- // }
- sql.append(" order by t.time_status , t.is_hot desc, t.sort desc");
- return paginate(pageNumber, pageSize, select.toString(), sql.toString());
- }
- /**
- *
- * @Description 查询
- * @author zhengwei
- * @date 2017年8月25日 下午3:27:34
- * @return Page<Product>
- */
- public List<Product> getAll(String type){
- StringBuffer sql = new StringBuffer();
- sql.append(" select t.id ,t.merchant_name,t.product_name,t.product_price,t.product_old_price,t.product_num,");
- sql.append(" t.product_main_img,t.visit_num,t.end_time,t.use_time,t.order_hour,t.time_status,t.product_img_1");
- sql.append(" from product t where t.status='1' ");
- sql.append(" and t.start_time<'"+DateUtil.formatDateTime(new Date())+"'");
- if(StringUtils.isNotEmpty(type)) {
- if("0".equals(type)){
- sql.append(" and t.use_time>'"+DateUtil.formatDateTime(new Date())+"'");
- }else {
- sql.append(" and t.use_time<'"+DateUtil.formatDateTime(new Date())+"'");
- }
- }
- sql.append(" order by t.time_status , t.is_hot desc, t.sort desc");
- return find(sql.toString());
- }
-
- /**
- *
- * @Description: 批量删除
- * @author zhengwei
- * @date 2016年8月10日 下午10:33:53
- * @return void
- */
- public void deleteAll(Object[][] paras){
- Db.batch("delete from product where id = ?", paras,1000);
- }
-
- /**
- *
- * @Description: 修改状态
- * @author zhengwei
- * @date 2016年8月10日 下午10:33:53
- * @return void
- */
- public void updateStatus(Object[][] paras){
- Db.batch("update product set status=? where id = ?", paras,1000);
- }
-
- /**
- *
- * @Description 根据分类获取
- * @author zhengwei
- * @date 2017年8月30日 下午3:36:28
- * @return List<Record>
- */
- public List<Record> getByCategory(int categoryId){
- return Db.find("select t.*,"
- + " (select ifnull(sum(product_qty),0) from user_order_detail where product_id=t.id) sale_num"
- + " from product t"
- + " where t.status='1' and t.product_category=? order by is_hot desc,t.create_time desc ",categoryId);
- }
-
- /**
- *
- * @Description 根据ID获取
- * @author zhengwei
- * @date 2017年8月31日 上午12:15:06
- * @param id
- * @return Product
- */
- public Product getById(int id){
- return findFirst("select t.*,"
- + " (select ifnull(sum(a.product_qty),0) from user_order a,user_order_detail b where "
- + " a.id =b.order_id and b.product_id = t.id and (order_status='20' or order_status='30'))sale_num"
- + " from product t"
- + " where t.id=?",id);
- }
-
- public List<Product> getByMerchant(int merchantId, String isShop){
- if("1".equals(isShop)){
- return find("select t.*"
- + " from product t"
- + " where t.merchant_id=? and t.product_owner='20' and t.time_status in ('0','1','2') order by t.time_status",merchantId);
- }else{
- return find("select t.*"
- + " from product t"
- + " where t.merchant_id=? and t.product_owner='10' order by t.time_status limit 5",merchantId);
- }
- }
- public int getMaxSort() {
- Record record = Db.findFirst("select max(sort) sort from product");
- if(record.get("sort")!=null) {
- return record.getInt("sort")+1;
- }else {
- return 1;
- }
- }
-
- public List<Product> getForTask(){
- return find("select t.*,"
- + " (select ifnull(sum(a.product_qty),0) from user_order a,user_order_detail b where "
- + " a.id =b.order_id and b.product_id = t.id and (order_status='20' or order_status='30'))sale_num"
- + " from product t");
- }
- }
|