<?php

namespace app\common\model\project;

use app\common\model\project\ProjectDonationOrder;
use liuniu\BaseModel;
use think\Model;


class ProjectDonationRocord extends BaseModel
{

    

    

    // 表名
    protected $name = 'project_donation_rocord';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'add_time_text'
    ];
    

    



    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
    public static function bill($cid=0,$type,$admin_id=0,$project_id=0,$order_id=0,$remark='')
    {
        $add_time = time();
        return self::create(compact('type', 'admin_id', 'order_id', 'remark', 'type', 'add_time','project_id','cid'));
    }
    public static function getbill($project_id,$type,$page=1,$limit=20,$cid=0)
    {
        $model = new self;
        if ($cid>0) $model = $model->where('cid',$cid);
        $where['project_id'] = $project_id;
        $where['type'] = $type;
        $model = $model->where($where);
        $count = $model->count();
        $data = $model->page($page,$limit)->select()->toarray();
        foreach ($data as &$v)
        {
            $v['name'] = ProjectDonationOrder::where('id',$v['order_id'])->value('name');
        }
        return compact('count','data');
    }

}
