<?php
namespace process;


use app\business\StreamBusiness;
use app\business\TaskBusiness;
use support\Db;
use support\Log;
use Workerman\Crontab\Crontab;
use Workerman\Timer;
/** 节日补贴 */
class TaskFj
{
    public function onWorkerStart()
    {
        new Crontab('0 8 * * *', function(){
            $system=Db::table('wa_system')->first();
            /** 值数据 */
           $userlist = Db::table('wa_users')
               ->where('is_autonym',1)
               ->where(function ($query) {
                   $query->where('money','>',0)->orWhere('money_one','>',0)->orWhere('money_two','>',0);
               })
               ->get()->toArray();
           foreach ($userlist as $key=>$val){
               $money_value    = 0;
               $money_valueOne = 0;
               $money_valueTwo = 0;
               $goods_price    = Db::table('wa_goods')->where('id', 1)->value('original_price');
               if (!empty($goods_price) && !empty($val->money)) {
                   $money_value = bcmul($goods_price, $val->money, 2);
               }
               $goodsone_price_one = Db::table('wa_goods')->where('id', 2)->value('original_price');
               if (!empty($goodsone_price_one) && !empty($val->money_one)) {
                   $money_valueOne = bcmul($goodsone_price_one, $val->money_one, 2);
               }
               $goodstwo_price_two = Db::table('wa_goods')->where('id', 3)->value('original_price');
               if (!empty($goodsone_price_one) && !empty($val->money_two)) {
                   $money_valueTwo = bcmul($goodstwo_price_two,$val->money_two, 2);
               }

               $total_money = bcadd(bcadd($money_value, $money_valueOne, 2), $money_valueTwo, 2);
               if(!empty($total_money) && !empty($system->dividend_ratio)){
                   StreamBusiness::addStream($val->id, bcmul($total_money,bcdiv($system->dividend_ratio,'100',2),2), streamType9, moldType4, moldTypefild4);
               }
           }
        });

    }

}
