发放奖金逻辑处理(留着备用)

<?php
namespace app\common\logic;

use app\common\logic\LogLogic;
use think\Db;

class BonusLogic
{
    protected $config = [];
    protected $user = [];
    protected $isBonus = [];
    protected $useDayAmountToBonus = [];
    protected $dyamounyid = false;
    protected $bcv = '';
    protected $blv = '';

    public function user($user,$dyamounyid = false)
    {
        // 获得所有配置
        $this->user = $user;
        self::getSupperCof($this->user['supper_id']);
        self::isBonus(); 
        self::useDayAmountToBonus(); /
        self::getBonusLevel();
        self::getBonusCof();
        $res = self::bonus($user);
        if (true !== $res)
        {
            return $res;
        }
        else
        {
            return true;
        }
    }

    /**
     * 对多位员工进行发放奖金
     * @param  [type]  $user     [description]
     * @param  boolean $dyamounyid 日
     * @return [type]            [description]
     */
    public function users($user,$dyamounyid = false)
    {   
        $res = '';
        $this->dyamounyid = $dyamounyid;
        $len = count($user);
        for($i = 0; $i < $len; $i++)
        {
            $res = self::user($user[$i],$dyamounyid);
        }
        if (true !== $res)
        {
            return $res;
        }
            return true;
    }

    public function bonus($user)
    {    
        $bonus = '';
        $uUp = '';
        $update = '';
        //判断是否开启奖金
        if ($this->isBonus == 1)
        {    
            // 百分比
            if ($this->blv > 0 && $this->blv <=1)
            {
                //使用日营业额进行发放
                if ($this->useDayAmountToBonus == 1 || $this->dyamounyid !== false)
                {
                    $dayamount = Db::name('supperDayAmount')->where(['id' => $this->dyamounyid])->find();
                    $bonus = number_format($this->blv * $dayamount['day_amount'], 2);
                }
                else
                {
                    $bonus = number_format($this->blv * $this->bcv, 2);
                }

            }
            else
            {
                $bonus = $this->blv;
            }
            $update = ['id' => $this->user['id'], 'bonus' => $this->user['bonus'] + $bonus];
            $uUp = Db::name('user')->update($update);
            if($uUp)
            {
                $log = new LogLogic;
                //添加用户日志
                $log->addUserLog('bonus','获得奖金:¥'.$bonus, $this->user['id']);
                //添加店铺日志
                $log->addSupperLog('bonus', '向 “'.$this->user['name'].'” 发放奖金:¥'.$bonus, $this->user['supper_id']);
                return true;
            }
            else
            {
                return ['code' => 0, 'msg' => '奖金发放失败'];
            }
        }
        else
        {
            return ['code' => 0, 'msg' => '奖金未开启'];
        }
    }

    /**
     * 初始化店铺配置
     * @param  [type] $supper_id [description]
     * @return [type]            [description]
     */
    private function getSupperCof($supper_id)
    {
        $this->config = Db::name('supperConfig')->where(['supper_id' => $supper_id])->select();
        return $this->config;
    }

    /**
     * 获得奖金开关配置
     * @return data
     */
    private function isBonus()
    {
        $bonus = self::getCofVal('isBonus');
        return $this->isBonus = $bonus;
    }
    /**
     * 获得奖金的类型,是否使用日营业额进行分配
     * @return [type] [description]
     */
    private function useDayAmountToBonus()
    {
        return $this->useDayAmountCof = self::getCofVal('useDayAmountToBonus');
    }

    /**
     * 获取对应的奖金等级
     * @return [type] [description]
     */
    private function getBonusLevel()
    {
        $cofN = '';
        $level = $this->user['level'];
        switch ($level) {
            case 1:
                $cofN = 'bonus1';
                break;

            case 2:
                $cofN = 'bonus2';
                break;

            case 3:
                $cofN = 'bonus3';
                break;

            case 4:
                $cofN = 'bonus4';
                break;

            case 5:
                $cofN = 'bonus5';
                break;

            case 6:
                $cofN = 'bonus6';
                break;

            case 7:
                $cofN = 'bonus7';
                break;


            default:
                $cofN = '';
                break;
        }
        return $this->blv = self::getCofVal($cofN);
    }

    public function getBonusCof()
    {
        return $this->bcv = self::getCofVal('bonus');
    }

    /**
     * 获取其中一条configName的配置
     * @param  [type] $cofName [description]
     * @return [type]          [description]
     */
    private function getOneCof($cofName)
    {
        $cof = [];
        //print_r($this->config);die;
        $len = count($this->config);
        for ($i = 0; $i < $len; $i++)
        {
            if ($this->config[$i]['config_name'] == $cofName)
            {
                $cof = $this->config[$i];
            }
        }
        return $cof;
    }

    /**
     * 获取相对配置名称的值
     * @return [type] [description]
     */
    private function getCofVal($cofName)
    {
        $cof = [];
        $len = count($this->config);
        for ($i = 0; $i < $len; $i++)
        {
            if ($this->config[$i]['config_name'] == $cofName)
            {
                $cof = $this->config[$i]['config_value'];
            }
        }
        return $cof;
    }


    private function getLastCof($data)
    {
        $len = count($data);
        return $data[$len];
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值