|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
namespace app\models\user;
|
|
|
|
|
|
+use app\admin\model\user\UserBonus;
|
|
|
use app\models\store\StoreOrder;
|
|
|
use app\models\store\StoreProduct;
|
|
|
use crmeb\services\SystemConfigService;
|
|
@@ -747,7 +748,7 @@ class User extends BaseModel
|
|
|
*/
|
|
|
public static function bonus()
|
|
|
{
|
|
|
- if (!Push::where('add_time', strtotime('today'))->find()) {
|
|
|
+ if (!Push::where('add_time', strtotime('today'))->where('type', 0)->find()) {
|
|
|
$user = User::select();
|
|
|
foreach ($user as $item) {
|
|
|
$start_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
|
|
@@ -845,7 +846,48 @@ class User extends BaseModel
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Push::create(['add_time' => strtotime('today')]); //存入数据库信息
|
|
|
+ Push::create(['add_time' => strtotime('today'), 'type' => 0]); //存入数据库信息
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 积分分红
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public static function in_bonus()
|
|
|
+ {
|
|
|
+ if (!Push::where('add_time', strtotime('today'))->where('type', 1)->find()) {
|
|
|
+ $price = StoreOrder::whereBetweenTime('add_time', strtotime('yesterday'), strtotime('today'))->where('paid', 1)->sum('pay_price');
|
|
|
+ $price = $price * 0.1;// 百分之十的分红
|
|
|
+ $count = UserBonus::where('status', 0)->sum('integral')/10000;//分红多少份
|
|
|
+ if ($count > 0){
|
|
|
+ $bonus = UserBonus::where('status', 0)->select();
|
|
|
+ $copy = round($price/$count, 2);
|
|
|
+ foreach ($bonus as $item)
|
|
|
+ {
|
|
|
+ $jl = $copy * $item['integral']/10000;
|
|
|
+ $mark = '';
|
|
|
+ $fa = 0;
|
|
|
+ if ($item['price']+$jl > $item['integral']){
|
|
|
+ $jl = $item['integral'] - $item['price'];
|
|
|
+ $mark = '发放完';
|
|
|
+ $fa = 1;
|
|
|
+ }
|
|
|
+ if ($fa == 1){
|
|
|
+ UserBonus::where('id', $item['id'])->update(['status'=> 1]);
|
|
|
+ UserBonus::where('id', $item['id'])->inc('price', $jl)->update();
|
|
|
+ }else{
|
|
|
+ UserBonus::where('id', $item['id'])->inc('price', $jl)->update();
|
|
|
+ }
|
|
|
+
|
|
|
+ User::where('uid', $item['uid'])->inc('brokerage_price', $jl)->update();
|
|
|
+ UserBill::income('佣金', $item['uid'], 'now_money', 'brokerage', $jl, '', User::where('uid', $item['uid'])->value('brokerage_price'), '分红'.($item['integral']/10000).'份佣金'.$mark);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Push::create(['add_time' => strtotime('today'), 'type' => 1]); //存入数据库信息
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|