|
@@ -0,0 +1,159 @@
|
|
|
+package restcontroller.webmanage.saletool.award;
|
|
|
+
|
|
|
+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 io.swagger.annotations.Api;
|
|
|
+import restcontroller.R;
|
|
|
+import restcontroller.webmanage.saletool.fad.FadHelper;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+public class Award extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public Award(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "抽奖管理新增或编辑", apiversion = R.ID20240514101402.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ Long sa_awardid = content.getLongValue("sa_awardid");
|
|
|
+ int isonsale = content.getIntValue("isonsale");
|
|
|
+
|
|
|
+ if (sa_awardid <= 0) {
|
|
|
+ sa_awardid = createTableID("sa_award");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_award");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_awardid);
|
|
|
+ insertSQL.setValue("name", content.getStringValue("name"));
|
|
|
+ insertSQL.setValue("begdate", content.getStringValue("begdate", false, "null"));
|
|
|
+ insertSQL.setValue("enddate", content.getStringValue("enddate", false, "null"));
|
|
|
+ insertSQL.insert();
|
|
|
+ content.put("sa_awardid", sa_awardid);
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_award");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_awardid);
|
|
|
+ updateSQL.setValue("name", content.getStringValue("name"));
|
|
|
+ updateSQL.setValue("begdate", content.getStringValue("begdate", false, "null"));
|
|
|
+ updateSQL.setValue("enddate", content.getStringValue("enddate", false, "null"));
|
|
|
+ updateSQL.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_award");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_awardid", sa_awardid);
|
|
|
+ updateSQL.setValue("isonsale", isonsale);
|
|
|
+ updateSQL.setValue("onsaledate", isonsale == 1 ? Time.getDateTime_Str() : "null");
|
|
|
+ updateSQL.setValue("onsaleby", isonsale == 1 ? username : "null");
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+
|
|
|
+ return detail();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "抽奖管理详情", apiversion = R.ID20240514101502.v1.class)
|
|
|
+ public String detail() throws YosException {
|
|
|
+ Long sa_awardid = content.getLongValue("sa_awardid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_award").setTableAlias("t1");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setUniqueid(sa_awardid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(detailRow).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "抽奖管理删除", apiversion = R.ID20240514101602.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+ JSONArray sa_awardids = content.getJSONArray("sa_awardids");
|
|
|
+ if (sa_awardids.size() == 0) {
|
|
|
+ return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_awardmx");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sa_awardid", sa_awardids.toArray());
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前活动已有中奖数据,不可删除").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, "sa_award");
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setWhere("sa_awardid", sa_awardids.toArray());
|
|
|
+ sqlFactory.delete();
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "抽奖管理上下架", apiversion = R.ID20240514101702.v1.class)
|
|
|
+ public String isonsale() throws YosException {
|
|
|
+ JSONArray sa_awardids = content.getJSONArray("sa_awardids");
|
|
|
+ int isonsale = content.getIntValue("isonsale");
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_award");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setWhere("sa_awardid", sa_awardids);
|
|
|
+ updateSQL.setValue("isonsale", isonsale);
|
|
|
+ updateSQL.setValue("onsaledate", isonsale == 0 ? "null" : Time.getDateTime_Str());
|
|
|
+ updateSQL.setValue("onsaleby", isonsale == 0 ? "null" : username);
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "抽奖管理列表", apiversion = R.ID20240514101802.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("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.isonsale ='").append(whereObject.getString("isonsale")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_award")
|
|
|
+ .setTableAlias("t1");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("shareurl", FadHelper.getAppletUrl(this, "AwardShareUrl", "奖品可分享小程序链接") + row.getString("sa_awardid"));
|
|
|
+ row.put("noshareurl", FadHelper.getAppletUrl(this, "AwardNoShareUrl", "奖品不可分享小程序链接") + row.getString("sa_awardid"));
|
|
|
+
|
|
|
+ row.putIfAbsent("onsaledate", "");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+}
|