Browse Source

1、待实现分佣根据订单状态提现;

Lawsun_M 11 months ago
parent
commit
dde9439c6b

+ 19 - 5
app/controller/home/RelInviter.js

@@ -15,8 +15,8 @@ module.exports = class RelInviterController extends Base {
     // const stateStr = that.app.szjcomo.base64_encode('http://test.enroll.sizhijie.com/#/shop/category?category_id=11');
     // const hh = that.app.szjcomo.base64_decode(stateStr);
 
-    const stateStr = that.app.szjcomo.base64_encode('http://ysjj.sizhijie.com/#/shop/officeHome');
-    console.log(stateStr);
+    // const stateStr = that.app.szjcomo.base64_encode('http://ysjj.sizhijie.com/#/shop/officeHome');
+    // console.log(stateStr);
 
     // https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7713e08a353ffcd7&redirect_uri=http%3A%2F%2Fysjj.sizhijie.com%2F%23%2Fshop%2Fwxauth&response_type=code&scope=snsapi_userinfo&state=aHR0cDovL3lzamouc2l6aGlqaWUuY29tLyMvc2hvcC9vZmZpY2VIb21l#wechat_redirect
 
@@ -32,6 +32,14 @@ module.exports = class RelInviterController extends Base {
     // 2023/3/5 餐币发放
     // const dispatchResult = that.service.diningCoin.orderDiningCoinDispatchAfterPay(362);
 
+    // const bodyData = {};
+    // const response = await that.app.curl('http://127.0.0.1:8105/oneshop/api/redEnvelopeProducts', {
+    //   method: 'GET', dataType: 'json', contentType: 'json', data: bodyData,
+    // });
+
+
+    // const response = await that.getCouldCashCommission(10);
+
     return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { commissionResult }, false));
   }
 
@@ -67,10 +75,16 @@ module.exports = class RelInviterController extends Base {
     const that = this;
     const seq = that.app.Sequelize;
     const selectBean = await that.app.comoBean.instance({}, {
-      where: { type: { [seq.Op.ne]: -1 } }, // type-1提现失败类型
-      attributes: [[ seq.fn('sum', seq.col('commission')), 'all_commission' ]],
+      where: { user_id: 10 }, // type-1提现失败类型
+      include: [ {
+        model: that.app.model.Orders,
+        where: { order_status: { [seq.Op.lte]: 2 } },
+        attributes: [ 'order_id', 'order_status', 'order_amount', ],
+        as: 'order'
+      } ],
+      // attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_cash' ] ],
     });
-    return await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
+    return await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, true);
   }
 
   async selectInfo(order_id) {

+ 2 - 1
app/controller/home/user.js

@@ -845,6 +845,7 @@ module.exports = class UserController extends shopController {
 
   /**
    * 获取用户可提现金额(求和)
+   * todo 判断订单状态 确认收货的订单才能提现
    * @return {Promise<void>}
    */
   async getCouldCashCommission(user_id = -1) {
@@ -879,6 +880,7 @@ module.exports = class UserController extends shopController {
 
   /**
    * 用户佣金提现
+   * TODO 提现条件 分佣对应订单状态 确认收货 方可提现
    * @return {Promise<void>}
    */
   async userCashOut() {
@@ -889,7 +891,6 @@ module.exports = class UserController extends shopController {
       const res = await that.getCouldCashCommission(data.user_id);
       if (data.cash_amount >= 0.1 && data.cash_amount <= res.all_commission_could_cash) {
         // 2023/1/31 发起提现
-        // todo : 用户分佣提现 1.扣取税费;2.用户分佣转通用电子餐费;
         const result = await that.service.wxPay.transfer(data);
         // 2023/1/31 提现状态
         if (result.status != 200) {

+ 2 - 1
app/models/mysql/users_commission_logs.js

@@ -65,7 +65,8 @@ module.exports = app => {
   });
 
   Model.associate = function() {
-
+    // 关联订单表
+    Model.belongsTo(app.model.Orders, { foreignKey: 'order_id', targetKey: 'order_id', as: 'order' });
   };
   // 同步:没有就新建,有就不变
   Model.sync();