|
@@ -10,6 +10,8 @@ import common.data.*;
|
|
|
import restcontroller.R;
|
|
|
import restcontroller.webmanage.saletool.fad.FadHelper;
|
|
|
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
public class AwardItems extends Controller {
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -78,7 +80,7 @@ public class AwardItems extends Controller {
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
- @API(title = "奖品项新增或编辑", apiversion = R.ID20240514131402.v1.class)
|
|
|
+ @API(title = "奖品项列表", apiversion = R.ID20240514131402.v1.class)
|
|
|
public String list() throws YosException {
|
|
|
|
|
|
/*
|
|
@@ -115,4 +117,111 @@ public class AwardItems extends Controller {
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "中奖明细列表", apiversion = R.ID20240514133902.v1.class)
|
|
|
+ public String awardmxlist() throws YosException {
|
|
|
+
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Long sa_awardid = content.getLongValue("sa_awardid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_awardmx")
|
|
|
+ .setTableAlias("t1");
|
|
|
+ querySQL.addQueryFields("addressdetail", "concat(province,city,county,address)");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setWhere("sa_awardid", sa_awardid);
|
|
|
+ querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "中奖", apiversion = R.ID20240514134002.v1.class)
|
|
|
+ public String awardmx() throws YosException {
|
|
|
+
|
|
|
+
|
|
|
+ Long sa_awardid = content.getLongValue("sa_awardid");
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_awarditems WHERE sa_awardid=" + sa_awardid + " and outcount>0 and siteid='" + siteid + "'");
|
|
|
+ int max = 0;
|
|
|
+ int firstnumber = 0;
|
|
|
+ for (Row row : rows) {
|
|
|
+ max = max + row.getInteger("outcount");
|
|
|
+ row.put("min", firstnumber + 1);
|
|
|
+ row.put("max", firstnumber + row.getInteger("outcount"));
|
|
|
+ firstnumber = firstnumber + row.getInteger("outcount");
|
|
|
+ }
|
|
|
+
|
|
|
+ int number = getNumber(1, max);
|
|
|
+ Long sa_awarditemsid = 0L;
|
|
|
+ for (Row row : rows) {
|
|
|
+ if (row.getLong("min") <= number && row.getLong("max") >= number) {
|
|
|
+ sa_awarditemsid = row.getLong("sa_awarditemsid");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Rows awarditemsRows = dbConnect.runSqlQuery("SELECT * from sa_awarditems WHERE sa_awarditemsid=" + sa_awarditemsid + " and siteid='" + siteid + "'");
|
|
|
+ if (awarditemsRows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("奖项不存在").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ Long count = 0L;
|
|
|
+ rows = dbConnect.runSqlQuery("SELECT count(0) count from sa_awardmx WHERE sa_awarditemsid=" + sa_awarditemsid + " and siteid='" + siteid + "'");
|
|
|
+ count = rows.get(0).getLong("count");
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate("UPDATE sa_awarditems SET outcount=totalcount-" + count + ",realcount=totalcount-" + count + " WHERE sa_awarditemsid=" + sa_awarditemsid + " and siteid='" + siteid + "'");
|
|
|
+
|
|
|
+
|
|
|
+ Long shareuserid = content.getLongValue("shareuserid");
|
|
|
+
|
|
|
+ Long sa_awardmxid = createTableID("sa_awardmx");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_awardmx");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_awardmxid);
|
|
|
+ insertSQL.setValue("sa_awardid", sa_awardid);
|
|
|
+ insertSQL.setValue("awardname", awarditemsRows.get(0).getString("name"));
|
|
|
+ insertSQL.setValue("price", awarditemsRows.get(0).getBigDecimal("price"));
|
|
|
+ insertSQL.setValue("type", awarditemsRows.get(0).getString("type"));
|
|
|
+ insertSQL.setValue("sharename", getUser(shareuserid).getString("name"));
|
|
|
+ insertSQL.setValue("shareuserid", shareuserid);
|
|
|
+ insertSQL.setValue("sa_awarditemsid", sa_awarditemsid);
|
|
|
+ insertSQL.setValue("name", content.getStringValue("name"));
|
|
|
+ insertSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
|
|
|
+ insertSQL.setValue("province", content.getStringValue("province"));
|
|
|
+ insertSQL.setValue("city", content.getStringValue("city"));
|
|
|
+ insertSQL.setValue("county", content.getStringValue("county"));
|
|
|
+ insertSQL.setValue("address", content.getStringValue("address"));
|
|
|
+ insertSQL.insert();
|
|
|
+
|
|
|
+ Rows mxRows = dbConnect.runSqlQuery("SELECT * from sa_awardmx WHERE sa_awardmxid=" + sa_awardmxid + " and siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(mxRows.get(0)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int getNumber(int min, int max) {
|
|
|
+ Random rand = new Random();
|
|
|
+ return rand.nextInt(max - min + 1) + min;
|
|
|
+ }
|
|
|
+
|
|
|
}
|