• mysql,既可以自己的字段相乘,也可以乘固定的字段


    /**
     * 更新昨日收益,流量主,业务员都更新
     */
    public function updateYesterdayEarnings()
    {
        $yestoday = strtotime('-1 day', strtotime(date('Y-m-d')));
        $wx_user = M('wx_user');
        $day_earnings_log = M('day_earnings_log');
    
        // 流量主
        $day_earnings_log_list = $day_earnings_log->where(['date' => $yestoday, 'is_close' => 1])->getField('wx_uid,`count` * `close_complete_earnings` as earnings');
        $wx_user_list = $wx_user->where(['identity' => 0])->select();
        $count = 0;
        foreach ($wx_user_list as $k => $v) {
            if (!array_key_exists($v['id'], $day_earnings_log_list)) {
                $yesterday_earnings = 0;
            } else {
                $yesterday_earnings = $day_earnings_log_list[$v['id']];
            }
    
            $flag = $wx_user->where(['id' => $v['id']])->save(['yesterday_earnings' => $yesterday_earnings]);
            if ($flag !== false) {
                $count++;
            }
        }
        echo "本次更新了" . $count . "个流量主昨日收益" . date('Y-m-d H:i') . PHP_EOL;
    
    
        $salesman_user_list = $wx_user->where(['identity' => ['neq', 0]])->select();
        $salesman_count = 0;
        foreach ($salesman_user_list as $sk => $sv) {
            $yesterday_earnings = $day_earnings_log->where(['salesman_wx_uid' => $sv['id'], 'date' => $yestoday, 'is_salesman_close' => 1])->sum('`count` * `close_salesman_complete_earnings`');
    
            $flag = $wx_user->where(['id' => $sv['id']])->save(['yesterday_earnings' => $yesterday_earnings]);
            if ($flag !== false) {
                $salesman_count++;
            }
        }
        echo "本次更新了" . $salesman_count . "个业务员昨日收益" . date('Y-m-d H:i') . PHP_EOL;
    }
    
    
    /**
     * 更新今日预估收益,流量主,业务员都更新
     */
    public function updateTodayEarnings()
    {
        $today = strtotime(date('Y-m-d'));
        $wx_user = M('wx_user');
        $day_earnings_log = M('day_earnings_log');
    
        $day_complete_earnings = M('day_complete_earnings');
        $day_complete_earnings_info = $day_complete_earnings->where(['date' => strtotime(date('Y-m-d'))])->find();
        $today_complete_earnings = $day_complete_earnings_info['complete_earnings'];
    
        // 流量主
        $day_earnings_log_list = $day_earnings_log->where(['date' => $today])->getField("wx_uid,`count` * $today_complete_earnings as earnings");
        $wx_user_list = $wx_user->where(['identity' => 0])->select();
        $count = 0;
        foreach ($wx_user_list as $k => $v) {
            if (!array_key_exists($v['id'], $day_earnings_log_list)) {
                $today_earnings = 0;
            } else {
                $today_earnings = $day_earnings_log_list[$v['id']];
            }
    
            $flag = $wx_user->where(['id' => $v['id']])->save(['today_estimate_earnings' => $today_earnings]);
            if ($flag !== false) {
                $count++;
            }
        }
        echo "本次更新了" . $count . "个流量主今日预估收益" . date('Y-m-d H:i') . PHP_EOL;
    
    
        $salesman_user_list = $wx_user->where(['identity' => ['neq', 0]])->select();
        $salesman_count = 0;
        foreach ($salesman_user_list as $sk => $sv) {
            $salesman_complete_earnings = $sv['salesman_complete_earnings'];
            $today_earnings = $day_earnings_log->where(['salesman_wx_uid' => $sv['id'], 'date' => $today])->sum("`count` * $salesman_complete_earnings");
    
            $flag = $wx_user->where(['id' => $sv['id']])->save(['today_estimate_earnings' => $today_earnings]);
            if ($flag !== false) {
                $salesman_count++;
            }
        }
        echo "本次更新了" . $salesman_count . "个业务员今日预估收益" . date('Y-m-d H:i') . PHP_EOL;
    }
    
  • 相关阅读:
    移动传感器扫描覆盖
    最小生成树
    什么是壳 脱壳篇01
    最小生成树
    最小生成树
    最小生成树
    最小生成树
    最小生成树
    普里姆算法
    普里姆算法
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/13497664.html
Copyright © 2020-2023  润新知