Kirin пре 3 година
родитељ
комит
f60e352e33

+ 38 - 0
app/models/store/StoreOrder.php

@@ -9,6 +9,7 @@ namespace app\models\store;
 
 use app\admin\model\system\ShippingTemplatesFree;
 use app\admin\model\system\ShippingTemplatesRegion;
+use app\models\system\MonthAwardLog;
 use app\models\tree\TreeRecommend;
 use crmeb\basic\BaseModel;
 use think\db\exception\DataNotFoundException;
@@ -2326,4 +2327,41 @@ class StoreOrder extends BaseModel
         return compact('list', 'count');
     }
 
+    public static function monthAward()
+    {
+        if (MonthAwardLog::whereTime('day', 'month')->find()) {
+            return true;
+        }
+        $uids = TreeRecommend::where('get', 0)
+            ->whereTime('add_time', 'last month')
+            ->column('uid');
+        $month_award_ratio = sys_config('month_award_ratio', 0);
+        $orders = self::where('status', '>=', 2)
+            ->where('paid', 1)
+            ->where('is_del', 0)
+            ->where('combination_id', 0)
+            ->where('seckill_id', 0)
+            ->where('bargain_id', 0)
+            ->where('shipping_type', 1)
+            ->where('is_system_del', 0)
+            ->whereTime('pay_time', 'last month')
+            ->where('refund_status', 0)
+            ->sum('pay_price');
+        $brokerage_ratio = bcdiv($month_award_ratio, 100, 3);
+        $brokerage = bcmul($brokerage_ratio, $orders, 3);
+        $brokerage = bcdiv($brokerage, count($uids), 2);
+        if ($brokerage <= 0) return true;
+        try {
+            $res = true;
+            foreach ($uids as $v) {
+                $user = User::get($v);
+                $res = $res && UserBill::income('商城业绩分红', $v, 'now_money', 'brokerage', $brokerage, 0, bcadd($user['brokerage_price'], $brokerage, 2), '获得本月商城业绩奖励。');
+                $res = $res && User::where('uid', $v)->inc('brokerage_price', $brokerage)->update();
+            }
+            return $res && MonthAwardLog::create(['day' => time()]);
+        } catch (\Exception $e) {
+            return self::setErrorInfo($e->getMessage());
+        }
+    }
+
 }

+ 30 - 0
app/models/system/MonthAwardLog.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace app\models\system;
+
+
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+/**
+ * TODO 文章Model
+ * Class Article
+ * @package app\models\article
+ */
+class MonthAwardLog extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'month_award_log';
+
+    use ModelTrait;
+
+}

+ 7 - 0
crmeb/subscribes/TaskSubscribe.php

@@ -75,6 +75,13 @@ class TaskSubscribe
         } catch (\Exception $e) {
             Db::rollback();
         }
+        try {
+            Db::startTrans();
+            StoreOrder::monthAward();//拼团到期修改状态
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+        }
     }
 
     /**