<?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>
 * 收益记录表 Table<ai_allwin_bank_bill>
 */
namespace app\allwin\model;
use think\Model;
use think\facade\Validate;

class BankBill extends Model{
    
    protected $pk     = 'id';
    protected $table  = 'ai_allwin_bank_bill';

    public function user(){
        return $this->hasOne('app\common\model\SystemUser','id','pay_uid');
    } 

    /**
     * 后台在使用
     * 收益记录
     */
    public static function bill($where){
        return self::where($where)->order('id desc')->paginate(20,false,['query'=>['uid' =>$where['user_id']]]);
    }
 

   /**
     * [log 增加财务日志]
     * @param  [array]  $param['miniapp_id = '1'',uid=>'1',store_id=>'1','pay_uid' => 0]
     * @return [boolean]          [增加成功ID]
     */
    public static function add(array $param,$message){
        $data['member_miniapp_id'] = intval($param['miniapp_id']);
        $data['user_id']           = intval($param['uid']);
        $data['store_id']          = intval($param['store_id']);
        $data['pay_uid']           = intval($param['pay_uid']);
        $data['money']             = money($param['money']);
        $data['message']           = $message;
        $data['update_time']       = time();
        return self::create($data);
    }
}