<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 公司和平台利润添加
 */
namespace app\allwin\model;
use think\Model;
use util\Util;

class Platform extends Model
{
    protected $pk = 'id';
    protected $table = 'ai_allwin_platform';

    /**
     * 运营公司
     * @param integer $miniapp_id
     * @param integer $money(元)
     * @return void
     */
    public function company(int $miniapp_id,float $money){
        $info = self::get(['member_miniapp_id' => $miniapp_id]);
        if(empty($info)){
            $data['member_miniapp_id'] = $miniapp_id;
            $data['company']           = floatval($money);
            return self::insert($data);
        }else{
            $info->company = floatval($info->company+$money);
            return $info->save();
        }
    }

    /**
     * 基金账户充值
     * @param integer $miniapp_id
     * @param integer $money(元)
     * @return void
     */
    public function platforms(int $miniapp_id,float $money){
        $info = self::get(['member_miniapp_id' => $miniapp_id]);
        if(empty($info)){
            $data['member_miniapp_id'] = $miniapp_id;
            $data['platform']          = floatval($money);
            return self::insert($data);
        }else{
            $info->platform = floatval($info->platform+$money);
            return $info->save();
        }
    }
}