160 lines
2.5 KiB
PHP
160 lines
2.5 KiB
PHP
<?php
|
|
namespace app\farm\model;
|
|
|
|
use app\BaseModel;
|
|
use think\facade\Db;
|
|
|
|
class Source extends BaseModel
|
|
{
|
|
//定义表名
|
|
protected $name = 'lbfarm_source';
|
|
|
|
|
|
protected $append = [
|
|
|
|
'stage'
|
|
|
|
];
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-12-14 17:23
|
|
* @功能说明:
|
|
*/
|
|
public function getStageAttr($value,$data){
|
|
|
|
if(!empty($data['id'])){
|
|
|
|
$source_text_model = new SourceText();
|
|
|
|
$list = $source_text_model->where(['source_id'=>$data['id']])->select()->toArray();
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:04
|
|
* @功能说明:添加
|
|
*/
|
|
public function dataAdd($data){
|
|
|
|
$data['create_time'] = time();
|
|
|
|
if(!empty($data['stage'])){
|
|
|
|
$stage= $data['stage'];
|
|
|
|
unset($data['stage']);
|
|
}
|
|
|
|
$res = $this->insert($data);
|
|
|
|
$id = $this->getLastInsID();
|
|
|
|
if(!empty($stage)){
|
|
|
|
$this->updateSome($id,$stage,$data['uniacid']);
|
|
}
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:05
|
|
* @功能说明:编辑
|
|
*/
|
|
public function dataUpdate($dis,$data){
|
|
|
|
if(!empty($data['stage'])){
|
|
|
|
$stage = $data['stage'];
|
|
|
|
unset($data['stage']);
|
|
}
|
|
|
|
$res = $this->where($dis)->update($data);
|
|
|
|
if(!empty($stage)){
|
|
|
|
$this->updateSome($dis['id'],$stage,$data['uniacid']);
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2021-12-14 17:14
|
|
* @功能说明:
|
|
*/
|
|
public function updateSome($id,$data,$uniacid){
|
|
|
|
$source_text_model = new SourceText();
|
|
|
|
$source_text_model->where(['source_id'=>$id])->delete();
|
|
|
|
if(!empty($data)){
|
|
|
|
foreach ($data as $v){
|
|
|
|
$v['uniacid'] = $uniacid;
|
|
|
|
$v['source_id'] = $id;
|
|
|
|
$source_text_model->insert($v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:06
|
|
* @功能说明:列表
|
|
*/
|
|
public function dataList($dis,$page){
|
|
|
|
$data = $this->where($dis)->order('id desc')->paginate($page)->toArray();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @author chenniang
|
|
* @DataTime: 2020-09-29 11:43
|
|
* @功能说明:
|
|
*/
|
|
public function dataInfo($dis){
|
|
|
|
$data = $this->where($dis)->find();
|
|
|
|
return !empty($data)?$data->toArray():[];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |