licailing hace 5 años
padre
commit
b1d5e800ff

+ 65 - 0
src/main/java/com/izouma/dingdong/dto/MerchantDTO.java

@@ -4,6 +4,7 @@ import com.izouma.dingdong.annotations.Searchable;
 import com.izouma.dingdong.domain.Verified;
 import com.izouma.dingdong.domain.backstage.Category;
 import com.izouma.dingdong.domain.backstage.MerchantNature;
+import com.izouma.dingdong.domain.merchant.FullReduction;
 import com.izouma.dingdong.domain.merchant.Merchant;
 import com.izouma.dingdong.domain.merchant.MerchantSettings;
 import com.izouma.dingdong.enums.ApplyStatus;
@@ -15,10 +16,12 @@ import lombok.NoArgsConstructor;
 import org.hibernate.annotations.BatchSize;
 
 import javax.persistence.*;
+import javax.validation.constraints.Size;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
+import java.util.List;
 import java.util.Set;
 
 @Data
@@ -60,8 +63,53 @@ public class MerchantDTO implements Serializable {
         isOpening = merchantSettings.getIsOpening();
         automaticOrder = merchantSettings.getAutomaticOrder();
         doorHeadImg = merchantSettings.getDoorHeadImg();
+        promo = merchant.getPromo();
+        buyAlliance = merchantSettings.getBuyAlliance();
+        monthSales = merchant.getMonthSales();
     }
 
+    //包含距离
+    public MerchantDTO(Merchant merchant, MerchantSettings merchantSettings, Double distance) {
+        address = merchant.getAddress();
+        aliAccount = merchant.getAliAccount();
+        aliName = merchant.getAliName();
+        blacklist = merchant.getBlacklist();
+        merchantNatureId = merchantSettings.getMerchantNatureId();
+        category = merchantSettings.getCategory();
+        enabled = merchant.getEnabled();
+        endTime = merchantSettings.getEndTime();
+        firstOrder = merchantSettings.getFirstOrder();
+        mid = merchant.getId();
+        img = merchantSettings.getImg();
+        introduction = merchantSettings.getIntroduction();
+        name = merchant.getName();
+        /*    newUser = merchantSettings.getNewUser();*/
+        phone = merchant.getPhone();
+        qualification = merchantSettings.getQualification();
+        showName = merchant.getShowName();
+        startTime = merchantSettings.getStartTime();
+        //tag = merchantSettings.getTag();
+        isPass = merchant.getIsPass();
+        status = merchant.getStatus();
+        establishTime = merchant.getEstablishTime();
+        week = merchantSettings.getWeek();
+        banner = merchantSettings.getBanner();
+        logo = merchant.getLogo();
+        proclamation = merchantSettings.getProclamation();
+        userId = merchant.getUserId();
+        merchantNature = merchantSettings.getMerchantNature();
+        startingAmount = merchantSettings.getStartingAmount();
+        preparationTime = merchantSettings.getPreparationTime();
+        isOpening = merchantSettings.getIsOpening();
+        automaticOrder = merchantSettings.getAutomaticOrder();
+        doorHeadImg = merchantSettings.getDoorHeadImg();
+        promo = merchant.getPromo();
+        buyAlliance = merchantSettings.getBuyAlliance();
+        monthSales = merchant.getMonthSales();
+        this.distance = distance;
+
+
+    }
 
     private Long mid;
 
@@ -179,4 +227,21 @@ public class MerchantDTO implements Serializable {
 
     @ApiModelProperty(value = "门头图片")
     private String doorHeadImg;
+
+    @Size(max = 15)
+    @Column(length = 15)
+    @ApiModelProperty(value = "推广语", name = "promo")
+    private String promo;
+
+    @ApiModelProperty(value = "购买口碑联盟", name = "buyAlliance")
+    private Boolean buyAlliance = false;
+
+    @ApiModelProperty(value = "月销", name = "monthSales")
+    private Integer monthSales = 0;
+
+    @ApiModelProperty(value = "距离")
+    private Double distance;
+
+    @ApiModelProperty(value = "满减")
+    private List<FullReduction> fullReductions;
 }

+ 9 - 5
src/main/java/com/izouma/dingdong/service/merchant/GoodsService.java

@@ -258,12 +258,18 @@ public class GoodsService {
 
         //用户3km以内的商品 3km以内的商户
         Set<Merchant> merchantSet = new HashSet<>(merchantRepo.findAll());
-        List<Merchant> merchantList = merchantService.distanceSorting(merchantSet, longitude, latitude, range);
+        //List<Merchant> merchantList = merchantService.distanceSorting(merchantSet, longitude, latitude, range);
 
-        List<Goods> goodsList = goodsRepo.findAll();
+        Map<Merchant, Double> map = merchantService.distanceSorting(merchantSet, longitude, latitude, range);
+
+        List<Goods> goodsList = new ArrayList<>();
+        for (Map.Entry<Merchant, Double> m : map.entrySet()) {
+            goodsList.addAll(goodsRepo.findAllByMerchantId(m.getKey().getId()));
+        }
+       // List<Goods> goodsList = goodsRepo.findAll();
 
-        List<Goods> all = new ArrayList<>();
 
+        List<Goods> all = new ArrayList<>();
         //(1000-距离)/1000*0.5 + 月销/10000*0.5 (月销大于10000按照10000计算)
         switch (type) {
             case PRAISE_FOOD:
@@ -274,9 +280,7 @@ public class GoodsService {
             case SIGNBOARD_FOOD:
                 all.addAll(goodsList.stream().filter(Goods::getPraise).collect(Collectors.toList()));
         }
-        for (Goods a : all) {
 
-        }
         return all;
     }
 

+ 49 - 25
src/main/java/com/izouma/dingdong/service/merchant/MerchantService.java

@@ -266,16 +266,27 @@ public class MerchantService {
 
 //        Specification<Merchant> specification = toSpecification(pageQuery, Merchant.class);
 
-        List<Merchant> merchantList = merchantRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> criteriaQuery.where(
-                criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
-        ));
+        List<Merchant> merchantList = merchantRepo.findAll((root, criteriaQuery, criteriaBuilder) ->
+                        criteriaQuery.where(
+                                criteriaBuilder.and(
+                                        criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")),
+                                criteriaBuilder.equal(root.get("status"), ApplyStatus.PASS)).getRestriction()
+                //criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
+        );
+
+        List<Goods> goods = goodsRepo.findAll((root, criteriaQuery, criteriaBuilder) ->
+                criteriaQuery.where(
+                        criteriaBuilder.and(
+                                criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")),
+                        criteriaBuilder.equal(root.get("status"), ApplyStatus.PASS)).getRestriction()
+        );
 
-        List<Goods> goods = goodsRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> criteriaQuery.where(
-                criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
-        ));
         Set<Merchant> merchants = new HashSet<>(merchantList);
         goods.forEach(g -> {
-            merchants.add(merchantRepo.findById(g.getMerchantId()).orElse(null));
+            Merchant merchant = merchantRepo.findById(g.getMerchantId()).orElse(null);
+            if (ObjectUtil.isNotNull(merchant) && ApplyStatus.PASS.equals(merchant.getStatus())) {
+                merchants.add(merchant);
+            }
         });
 
 /*        //所有商家要按距离排序规则
@@ -297,7 +308,9 @@ public class MerchantService {
         }*/
 
         //距离排序
-        List<Merchant> mers = this.distanceSorting(merchants, longitude, latitude, null);
+        //List<Merchant> mers = this.distanceSorting(merchants, longitude, latitude, null);
+
+        Map<Merchant, Double> mers = this.distanceSorting(merchants, longitude, latitude, null);
 
         if (popularTag == null) {
             popularTag = pageQuery.getSearch();
@@ -305,41 +318,47 @@ public class MerchantService {
 
         //转DTO
         List<MerchantDTO> merchantDTOS = CollUtil.newArrayList();
-        for (Merchant m : mers) {
-            MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getId()).orElseThrow(new BusinessException("商户不存在"));
+
+        for (Map.Entry<Merchant, Double> m : mers.entrySet()) {
+
+            //  }
+            // for (Merchant m : mers) {
+            MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getKey().getId()).orElseThrow(new BusinessException("商户不存在"));
             if (StrUtil.isNotBlank(popularTag)) {
+                MerchantDTO merchantDTO = new MerchantDTO(m.getKey(), settings, m.getValue());
+                merchantDTO.setFullReductions(fullReductionRepo.findAllByMerchantId(merchantDTO.getMid()));
                 switch (popularTag) {
                     case "首单立减":
                         if ((settings.getFirstOrder() != null ? settings.getFirstOrder().compareTo(BigDecimal.ZERO) : 0) > 0) {
-                            merchantDTOS.add(new MerchantDTO(m, settings));
+                            merchantDTOS.add(merchantDTO);
                         }
                         break;
                     case "满减优惠":
-                        if (CollUtil.isNotEmpty(fullReductionRepo.findAllByMerchantId(m.getId()))) {
-                            merchantDTOS.add(new MerchantDTO(m, settings));
+                        if (CollUtil.isNotEmpty(fullReductionRepo.findAllByMerchantId(m.getKey().getId()))) {
+                            merchantDTOS.add(merchantDTO);
                         }
                         break;
                     case "折扣商家":
-                        if (StrUtil.isNotEmpty(merchantClassificationRepo.findByMerchantIdAndType(m.getId(), 2).getGoodsIds())) {
-                            merchantDTOS.add(new MerchantDTO(m, settings));
+                        if (StrUtil.isNotEmpty(merchantClassificationRepo.findByMerchantIdAndType(m.getKey().getId(), 2).getGoodsIds())) {
+                            merchantDTOS.add(merchantDTO);
                         }
                         break;
                     case "下单返红包":
-                        if (CollUtil.isNotEmpty(couponRepo.findAllByMerchantIdAndEnabledTrue(m.getId()))) {
-                            merchantDTOS.add(new MerchantDTO(m, settings));
+                        if (CollUtil.isNotEmpty(couponRepo.findAllByMerchantIdAndEnabledTrue(m.getKey().getId()))) {
+                            merchantDTOS.add(merchantDTO);
                         }
                         break;
                     case "可用红包":
                         List<UserCoupon> coupons = userCouponRepo.findAllByUserIdAndIsUsedFalse(userId);
                         List<UserCoupon> collect = coupons.stream().filter(c ->
-                                !c.getCoupon().getEndDate().isBefore(LocalDate.now()) && (c.getCoupon().getMerchantId() == null || c.getCoupon().getMerchantId().equals(m.getId()))
+                                !c.getCoupon().getEndDate().isBefore(LocalDate.now()) && (c.getCoupon().getMerchantId() == null || c.getCoupon().getMerchantId().equals(m.getKey().getId()))
                         ).collect(Collectors.toList());
                         if (CollUtil.isNotEmpty(collect)) {
-                            merchantDTOS.add(new MerchantDTO(m, settings));
+                            merchantDTOS.add(merchantDTO);
                         }
                         break;
                     default:
-                        merchantDTOS.add(new MerchantDTO(m, settings));
+                        merchantDTOS.add(merchantDTO);
                         break;
                 }
             }
@@ -389,14 +408,14 @@ public class MerchantService {
     /*
     距离排序,如果有范围,范围内进行排序
      */
-    public List<Merchant> distanceSorting(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
+    public Map<Merchant, Double> distanceSorting(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
         //List<Merchant> merchants = merchantRepo.findAll();
 
         //所有商家要按距离排序规则
         Map<Merchant, Double> map = new HashMap<>();
         //算距离
         for (Merchant m : merchants) {
-            if (m.getLatitude() != null && m.getLongitude() != null) {
+            if (ObjectUtil.isNotNull(m.getLatitude()) && ObjectUtil.isNotNull(m.getLongitude())) {
                 Double distance = MapUtils.distance(m.getLongitude(), m.getLatitude(), longitude, latitude);
                 if (range != null) {
                     if (distance < range) {
@@ -411,12 +430,17 @@ public class MerchantService {
         //排序
         List<Map.Entry<Merchant, Double>> list = new ArrayList<>(map.entrySet());
         list.sort(Comparator.comparing(Map.Entry<Merchant, Double>::getValue));
-        List<Merchant> mers = new ArrayList<>();
+
+
+        //List<Merchant> mers = new ArrayList<>();
+
+        Map<Merchant, Double> map1 = new HashMap<>();
         for (Map.Entry<Merchant, Double> m : list) {
-            mers.add(m.getKey());
+            //mers.add(m.getKey());
+            map1.put(m.getKey(), m.getValue());
         }
 
-        return mers;
+        return map1;
     }
 
 }

+ 38 - 0
src/main/java/com/izouma/dingdong/service/merchant/MerchantSettingsService.java

@@ -23,6 +23,7 @@ import com.izouma.dingdong.repo.backstage.CategoryRepo;
 import com.izouma.dingdong.repo.backstage.PromoteRepo;
 import com.izouma.dingdong.repo.backstage.TimeTagRepo;
 import com.izouma.dingdong.repo.merchant.*;
+import com.izouma.dingdong.service.backstage.CategoryService;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
@@ -46,6 +47,7 @@ public class MerchantSettingsService {
     private MoneyRecordRepo moneyRecordRepo;
     private BannerRepo bannerRepo;
     private CategoryRepo categoryRepo;
+    private CategoryService categoryService;
     private PromoteRepo promoteRepo;
     private GoodsRepo goodsRepo;
     private AppraisalRepo appraisalRepo;
@@ -221,4 +223,40 @@ public class MerchantSettingsService {
 
     }
 
+    //商家推广语
+    public void merPromo() {
+        List<Category> byParent = categoryRepo.findAllByParent(1L);
+        byParent.forEach(this::accept);
+    }
+
+
+    private void accept(Category c) {
+        List<MerchantDTO> list = categoryService.categoryMer(c.getId());
+        List<Merchant> merchants = new ArrayList<>();
+        list.sort((a, b) -> b.getMonthSales().compareTo(a.getMonthSales()));
+
+        for (int i = 0; i < 5; i++) {
+            Merchant merchant = merchantRepo.findById(list.get(i).getMid()).orElseThrow(new BusinessException("无商家"));
+            String name;
+            switch (i) {
+                case 0:
+                    name = "商家月销售冠军";
+                    break;
+                case 1:
+                    name = "商家月销售亚军";
+                    break;
+                case 2:
+                    name = "商家月销售季军";
+                    break;
+                case 3:
+                    name = "商家月销售第四名";
+                    break;
+                default:
+                    name = "商家月销售第五名";
+            }
+            merchant.setPromo(c.getName() + name);
+            merchants.add(merchant);
+        }
+        merchantRepo.saveAll(merchants);
+    }
 }

+ 1 - 0
src/main/java/com/izouma/dingdong/web/merchant/GoodsController.java

@@ -53,6 +53,7 @@ public class GoodsController extends BaseController {
     }
 
 
+    //后台商品列表
     //@PreAuthorize("hasRole('ADMIN')")
     @GetMapping("/all")
     public Page<Goods> all(PageQuery pageQuery) {

+ 28 - 13
src/main/vue/src/views/merchant/GoodsList.vue

@@ -9,9 +9,18 @@
             <el-button @click="addRow" type="primary" icon="el-icon-plus"
                        class="filter-item">添加
             </el-button>
-<!--            <el-button @click="download" type="primary" icon="el-icon-download"
-                       :loading="downloading" class="filter-item">导出EXCEL
-            </el-button>-->
+            <!--            <el-button @click="download" type="primary" icon="el-icon-download"
+                                   :loading="downloading" class="filter-item">导出EXCEL
+                        </el-button>-->
+            <el-select v-model="status" class="filter-item" placeholder="筛选状态" clearable filterable
+                       @change="getData">
+                <el-option
+                        v-for="item in statusOptions"
+                        :label="item.label"
+                        :value="item.value"
+                        :key="item.value"
+                />
+            </el-select>
         </div>
         <el-table :data="tableData" row-key="id" ref="table"
                   header-row-class-name="table-header-row"
@@ -91,7 +100,7 @@
                     fixed="right"
                     min-width="350">
                 <template slot-scope="{row}">
-                   <!-- <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>-->
+                    <!-- <el-button @click="editRow(row)" type="primary" size="mini" plain>编辑</el-button>-->
                     <el-button @click="take(row)" type="warning" size="mini" plain v-if="row.status === 'PASS'">
                         {{row.takeOff?'上架':'下架'}}
                     </el-button>
@@ -119,14 +128,14 @@
             </el-table-column>
         </el-table>
         <div class="pagination-wrapper">
-        <!--    <div class="multiple-mode-wrapper">
-                <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)">批量编辑</el-button>
-                <el-button-group v-else>
-                    <el-button @click="operation1">批量操作1</el-button>
-                    <el-button @click="operation2">批量操作2</el-button>
-                    <el-button @click="toggleMultipleMode(false)">取消</el-button>
-                </el-button-group>
-            </div>-->
+            <!--    <div class="multiple-mode-wrapper">
+                    <el-button v-if="!multipleMode" @click="toggleMultipleMode(true)">批量编辑</el-button>
+                    <el-button-group v-else>
+                        <el-button @click="operation1">批量操作1</el-button>
+                        <el-button @click="operation2">批量操作2</el-button>
+                        <el-button @click="toggleMultipleMode(false)">取消</el-button>
+                    </el-button-group>
+                </div>-->
             <el-pagination background @size-change="onSizeChange"
                            @current-change="onCurrentChange" :current-page="page"
                            :page-sizes="[10, 20, 30, 40, 50]" :page-size="pageSize"
@@ -156,6 +165,7 @@
                 statusOptions: [{"label": "待处理", "value": "PENDING"}, {
                     "label": "成功", "value": "PASS"
                 }, {"label": "失败", "value": "DENY"}],
+                status: '',
 
             }
         },
@@ -180,9 +190,14 @@
                 return '';
             },
             beforeGetData() {
+                let data = {}
                 if (this.search) {
-                    return {search: this.search};
+                    data.search = this.search;
                 }
+                if (this.status) {
+                    data.query.status = this.status;
+                }
+                return data;
             },
             toggleMultipleMode(multipleMode) {
                 this.multipleMode = multipleMode;

+ 12 - 2
src/main/vue/src/views/merchant/MerchantList.vue

@@ -14,7 +14,15 @@
             </el-button>
 
             <!--            <el-button >新店</el-button>-->
-
+            <el-select v-model="status" class="filter-item" placeholder="筛选状态" clearable filterable
+                       @change="getData">
+                <el-option
+                        v-for="item in statusOptions"
+                        :label="item.label"
+                        :value="item.value"
+                        :key="item.value"
+                />
+            </el-select>
             <el-date-picker
                     v-model="dateRange"
                     type="daterange"
@@ -360,7 +368,9 @@
                 if (this.dateRange && this.dateRange.length > 0) {
                     data.query.establishTime = this.dateRange[0] + ',' + this.dateRange[1];
                 }
-
+                if (this.status) {
+                    data.query.status = this.status;
+                }
                 return data;
                 /*                if (this.search) {
                                     return {search: this.search};

+ 13 - 9
src/test/java/com/izouma/dingdong/service/MerchantServiceTest.java

@@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @RunWith(SpringRunner.class)
@@ -108,9 +109,11 @@ public class MerchantServiceTest {
         PageQuery pageQuery = new PageQuery();
         pageQuery.setPage(0);
         pageQuery.setSize(50);
-        pageQuery.setSearch("走马");
+        pageQuery.setSearch("");
         pageQuery.setSort("");
-        System.out.println(merchantService.showAll(pageQuery, 118.738275, 31.991961, null, 82L).size());
+        List<MerchantDTO> list = merchantService.showAll(pageQuery, 118.738275, 31.991961, "满减优惠", 82L);
+
+        System.out.println(list.get(0).getFullReductions());
     }
 
 /*    @Test
@@ -130,12 +133,13 @@ public class MerchantServiceTest {
     @Test
     public void testIndex(){
         Map<String, Object> index = merchantSettingsService.index(118.00, 31.0);
-        System.out.println(index.get("banner"));
-        System.out.println(index.get("categories"));
-        System.out.println(index.get("timeTag"));
-        System.out.println(index.get("promote1"));
-        System.out.println(index.get("promote2"));
-        System.out.println(index.get("newMerchants"));
-
+//        System.out.println(index.get("banner"));
+//        System.out.println(index.get("categories"));
+//        System.out.println(index.get("timeTag"));
+//        System.out.println(index.get("promote1"));
+//        System.out.println(index.get("promote2"));
+//        System.out.println(index.get("newMerchants"));
+
+        System.out.println(index);
     }
 }