|
|
@@ -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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|