123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- package restcontroller.webmanage.saletool.award;
- import beans.datacontrllog.DataContrlLog;
- import beans.time.Time;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.data.*;
- import restcontroller.R;
- import restcontroller.webmanage.saletool.fad.FadHelper;
- import java.util.ArrayList;
- import java.util.Random;
- public class AwardItems extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public AwardItems(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "奖品项新增或编辑", apiversion = R.ID20240514131202.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sa_awardid = content.getLongValue("sa_awardid");
- Long sa_awarditemsid = content.getLongValue("sa_awarditemsid");
- if (sa_awarditemsid <= 0) {
- sa_awarditemsid = createTableID("sa_awarditems");
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_awarditems");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(sa_awarditemsid);
- insertSQL.setValue("sequence", content.getLongValue("sequence"));
- insertSQL.setValue("name", content.getStringValue("name"));
- insertSQL.setValue("price", content.getBigDecimalValue("price"));
- insertSQL.setValue("percentage", content.getBigDecimalValue("percentage"));
- insertSQL.setValue("type", content.getStringValue("type"));
- insertSQL.setValue("realcount", content.getLongValue("totalcount"));
- insertSQL.setValue("outcount", content.getLongValue("outcount"));
- insertSQL.setValue("totalcount", content.getLongValue("totalcount"));
- insertSQL.setValue("sa_awardid", sa_awardid);
- insertSQL.insert();
- DataContrlLog.createLog(this, "sa_award", sa_awardid, "新建", "新建奖项 " + content.getStringValue("name")).insert();
- } else {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_awarditems");
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_awarditemsid);
- updateSQL.setValue("sequence", content.getLongValue("sequence"));
- updateSQL.setValue("name", content.getStringValue("name"));
- updateSQL.setValue("price", content.getBigDecimalValue("price"));
- updateSQL.setValue("percentage", content.getBigDecimalValue("percentage"));
- updateSQL.setValue("type", content.getStringValue("type"));
- updateSQL.setValue("outcount", content.getLongValue("outcount"));
- updateSQL.setValue("totalcount", content.getLongValue("totalcount"));
- updateSQL.setValue("sa_awardid", sa_awardid);
- updateSQL.update();
- DataContrlLog.createLog(this, "sa_award", sa_awardid, "编辑", "编辑奖项 " + content.getStringValue("name")).insert();
- }
- Rows rows = dbConnect.runSqlQuery("SELECT * from sa_awarditems WHERE sa_awarditemsid=" + sa_awarditemsid + " and siteid='" + siteid + "'");
- return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString();
- }
- @API(title = "奖品项删除", apiversion = R.ID20240514131302.v1.class)
- public String delete() throws YosException {
- JSONArray sa_awarditemsids = content.getJSONArray("sa_awarditemsids");
- if (sa_awarditemsids.size() == 0) {
- return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
- }
- //操作记录
- for (Object object : sa_awarditemsids) {
- long sa_awarditemsid = Long.parseLong(object.toString());
- Row row = dbConnect.runSqlQuery(0, "SELECT * from sa_awarditems WHERE siteid='" + siteid + "' and sa_awarditemsid=" + sa_awarditemsid);
- DataContrlLog.createLog(this, "sa_award", row.getLong("sa_awardid"), "删除", "删除奖项 " + row.getString("name")).insert();
- }
- DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, "sa_awarditems");
- sqlFactory.setSiteid(siteid);
- sqlFactory.setWhere("sa_awarditemsid", sa_awarditemsids.toArray());
- sqlFactory.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "奖品项列表", apiversion = R.ID20240514131402.v1.class)
- public String list() 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_awarditems")
- .setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.inner, "sa_award", "t2", "t2.sa_awardid=t1.sa_awardid and t2.siteid=t1.siteid");
- querySQL.setSiteid(siteid);
- if (systemclient.equals("marketingtool")) {
- querySQL.setWhere("t2.isonsale", 1);
- }
- querySQL.setWhere("t1.sa_awardid", sa_awardid);
- querySQL.setWhere(where.toString());
- querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- RowsMap rowsMap = getAttachmentUrl("sa_awarditems", rows.toArrayList("sa_awarditemsid", new ArrayList<>()));
- for (Row row : rows) {
- row.put("attinfos", rowsMap.getOrDefault(row.getString("sa_awarditemsid"), new Rows()));
- }
- 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(" or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(" or t1.province like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(" or t1.city like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(" or t1.county like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(" or t1.address like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(" or t1.sharename like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("awardname") && !"".equals(whereObject.getString("awardname"))) {
- where.append(" and (");
- where.append("t1.awardname ='").append(whereObject.getString("awardname")).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");
- }
- if (max == 0) {
- return getErrReturnObject().setErrMsg("未中奖").toString();
- }
- 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;
- }
- @API(title = "我的中奖", apiversion = R.ID20240515140302.v1.class)
- public String myaward() throws YosException {
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_awardmx")
- .setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.inner, "sa_award", "t2", "t2.sa_awardid=t1.sa_awardid and t2.siteid=t1.siteid");
- querySQL.addQueryFields("addressdetail", "concat(province,city,county,address)");
- querySQL.addQueryFields("awardheadname", "t2.name");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("createuserid", userid);
- querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "更新中奖信息", apiversion = R.ID2024052910464202.v1.class)
- public String newApiMethod() throws YosException {
- long sa_awardmxid = content.getLong("sa_awardmxid");
- String name = content.getString("name");// 姓名
- String phonenumber = content.getString("phonenumber");// 手机号
- String address = content.getString("address");// 详细地址
- String city = content.getString("city");// 城市
- String county = content.getString("county");// 区县
- String province = content.getString("province");// 省份
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_awardmx");
- updateSQL.setValue("name", name);
- updateSQL.setValue("phonenumber", phonenumber);
- updateSQL.setValue("address", address);
- updateSQL.setValue("city", city);
- updateSQL.setValue("county", county);
- updateSQL.setValue("province", province);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sa_awardmxid);
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- }
|