Browse Source

1、分类排序;

Lawsun_M 1 year ago
parent
commit
d08fb91ffe

+ 79 - 42
app/controller/home/address.js

@@ -7,77 +7,111 @@ module.exports = class AddressController extends shopController {
     const that = this;
     return that.app.model.Address;
   }
+
   /**
-	 * [selectValidate 查询用户地址]
-	 * @return {[type]} [description]
-	 */
+   * [selectValidate 查询用户地址]
+   * @return {[type]} [description]
+   */
   get selectValidate() {
     const that = this;
     return {
-      is_use: that.ctx.rules.default(0).required().number(),
-      user_id: that.ctx.rules.default(that.service.shop.getWebUserId()).number(),
+      is_use: that.ctx.rules.default(0)
+        .required()
+        .number(),
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
     };
   }
 
   /**
-	 * [createValidate 添加收货地址]
-	 * @return {[type]} [description]
-	 */
+   * [createValidate 添加收货地址]
+   * @return {[type]} [description]
+   */
   get createValidate() {
     const that = this;
     return {
-      user_id: that.ctx.rules.default(that.service.shop.getWebUserId()).number(),
-      uname: that.ctx.rules.name('收货人姓名').required().notEmpty()
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
+      uname: that.ctx.rules.name('收货人姓名')
+        .required()
+        .notEmpty()
         .trim(),
-      mobile: that.ctx.rules.name('收货人电话').required().notEmpty()
+      mobile: that.ctx.rules.name('收货人电话')
+        .required()
+        .notEmpty()
         .trim()
         .phone(),
-      province_name: that.ctx.rules.name('所在省').required().notEmpty()
+      province_name: that.ctx.rules.name('所在省')
+        .required()
+        .notEmpty()
         .trim(),
-      province_id: that.ctx.rules.name('所在省ID').required().notEmpty()
+      province_id: that.ctx.rules.name('所在省ID')
+        .required()
+        .notEmpty()
         .number(),
-      city_id: that.ctx.rules.name('所在市ID').required().notEmpty()
+      city_id: that.ctx.rules.name('所在市ID')
+        .required()
+        .notEmpty()
         .number(),
-      city_name: that.ctx.rules.name('所在城市').required().notEmpty()
+      city_name: that.ctx.rules.name('所在城市')
+        .required()
+        .notEmpty()
         .trim(),
-      county_id: that.ctx.rules.name('所在区/县ID').required().notEmpty()
+      county_id: that.ctx.rules.name('所在区/县ID')
+        .required()
+        .notEmpty()
         .number(),
-      county_name: that.ctx.rules.name('所在区/县').required().notEmpty()
+      county_name: that.ctx.rules.name('所在区/县')
+        .required()
+        .notEmpty()
         .trim(),
-      address: that.ctx.rules.name('详细地址').required().notEmpty()
+      address: that.ctx.rules.name('详细地址')
+        .required()
+        .notEmpty()
         .trim(),
-      is_use: that.ctx.rules.default(0).number(),
-      create_time: that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s')).required(),
+      is_use: that.ctx.rules.default(0)
+        .number(),
+      create_time: that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s'))
+        .required(),
     };
   }
+
   /**
-	 * [updateValidate 更新收货地址]
-	 * @return {[type]} [description]
-	 */
+   * [updateValidate 更新收货地址]
+   * @return {[type]} [description]
+   */
   get updateValidate() {
     const that = this;
     return {
-      user_id: that.ctx.rules.default(that.service.shop.getWebUserId()).number(),
-      address_id: that.ctx.rules.name('收货地址ID').required().notEmpty()
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
+      address_id: that.ctx.rules.name('收货地址ID')
+        .required()
+        .notEmpty()
         .number(),
     };
   }
+
   /**
-	 * [deleteValidate 删除收货地址]
-	 * @return {[type]} [description]
-	 */
+   * [deleteValidate 删除收货地址]
+   * @return {[type]} [description]
+   */
   get deleteValidate() {
     const that = this;
     return {
-      user_id: that.ctx.rules.default(that.service.shop.getWebUserId()).number(),
-      address_id: that.ctx.rules.name('收货地址ID').required().notEmpty()
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
+      address_id: that.ctx.rules.name('收货地址ID')
+        .required()
+        .notEmpty()
         .number(),
     };
   }
+
   /**
-	 * [select 用户收货地址列表]
-	 * @return {[type]} [description]
-	 */
+   * [select 用户收货地址列表]
+   * @return {[type]} [description]
+   */
   async select() {
     const that = this;
     try {
@@ -92,10 +126,11 @@ module.exports = class AddressController extends shopController {
       return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', false, false));
     }
   }
+
   /**
-	 * [create 添加收货地址]
-	 * @return {[type]} [description]
-	 */
+   * [create 添加收货地址]
+   * @return {[type]} [description]
+   */
   async create() {
     const that = this;
     try {
@@ -107,10 +142,11 @@ module.exports = class AddressController extends shopController {
       return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
     }
   }
+
   /**
-	 * [update 更新收货地址]
-	 * @return {[type]} [description]
-	 */
+   * [update 更新收货地址]
+   * @return {[type]} [description]
+   */
   async update() {
     const that = this;
     try {
@@ -130,10 +166,11 @@ module.exports = class AddressController extends shopController {
       return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
     }
   }
+
   /**
-	 * [delete 删除收货地址]
-	 * @return {[type]} [description]
-	 */
+   * [delete 删除收货地址]
+   * @return {[type]} [description]
+   */
   async delete() {
     const that = this;
     try {

+ 1 - 1
app/controller/home/productCategory.js

@@ -77,7 +77,7 @@ module.exports = class ProductCategoryController extends shopController {
           ],
           attributes: [ 'category_id', [ 'category_name', 'text' ]],
           // 2023/9/15 关联查询排序
-          order: [[ 'category_id', 'asc' ], [ 'products', 'is_hot', 'desc' ], [ 'products', 'is_new', 'desc' ], [ 'products', 'sale_count', 'desc' ]],
+          order: [[ 'category_sort', 'asc' ], [ 'category_id', 'asc' ], [ 'products', 'is_hot', 'desc' ], [ 'products', 'is_new', 'desc' ], [ 'products', 'sale_count', 'desc' ]],
         };
         const selectBean = await that.app.comoBean.instance({}, opt);
         result = await that.service.manager.select(selectBean, that.useModel, '商品列表查看失败,请重试', false, true);

+ 19 - 19
app/models/mysql/product_category.js

@@ -7,58 +7,58 @@ module.exports = app => {
     category_id: {
       type: DataTypes.INTEGER(10).UNSIGNED,
       primaryKey: true,
-      autoIncrement: true
+      autoIncrement: true,
     },
     category_name: {
       type: DataTypes.STRING(255),
-      allowNull: true
+      allowNull: true,
     },
     pid: {
       type: DataTypes.INTEGER(10).UNSIGNED,
-      allowNull: true
+      allowNull: true,
     },
     category_image: {
       type: DataTypes.STRING(255),
-      allowNull: true
+      allowNull: true,
     },
     category_sort: {
       type: DataTypes.INTEGER(10).UNSIGNED,
-      allowNull: true
+      allowNull: true,
     },
     is_show: {
       type: DataTypes.INTEGER(1).UNSIGNED,
-      allowNull: true
+      allowNull: true,
     },
     is_nav: {
       type: DataTypes.INTEGER(1).UNSIGNED,
-      allowNull: true
+      allowNull: true,
     },
     category_attrs: {
       type: DataTypes.TEXT,
-      allowNull: true
+      allowNull: true,
     },
     admin_id: {
       type: DataTypes.INTEGER(10).UNSIGNED,
-      allowNull: true
+      allowNull: true,
     },
     update_time: {
-      type: DataTypes.TIME
+      type: DataTypes.TIME,
     },
     create_time: {
       type: DataTypes.DATE,
-      allowNull: true
-    }
+      allowNull: true,
+    },
   }, {
-    tableName: 'szj_product_category'
+    tableName: 'szj_product_category',
   });
 
   Model.associate = function() {
-    //关联管理员表
-    Model.belongsTo(app.model.AdminUser,{foreignKey:'admin_id',targetKey:'admin_id',as:'admin_user'});
-    //关联商品
-    Model.hasMany(app.model.Products,{foreignKey:'category_id',targetKey:'category_id',as:'products'});
-  }
-  //同步:没有就新建,有就不变
+    // 关联管理员表
+    Model.belongsTo(app.model.AdminUser, { foreignKey: 'admin_id', targetKey: 'admin_id', as: 'admin_user' });
+    // 关联商品
+    Model.hasMany(app.model.Products, { foreignKey: 'category_id', targetKey: 'category_id', as: 'products' });
+  };
+  // 同步:没有就新建,有就不变
   Model.sync();
   return Model;
 };