hasMany('TestPesticides', 'test_model_id', 'id'); } function testProduct() { return $this->hasMany('TestProduct', 'test_model_id', 'id'); } public function getProductInfo($model_id,$where=[]) { $models = TestModel::find($model_id); $productInfo = $models->testProduct()->where($where)->select(); return $productInfo; } public function getPesticidesInfo($model_id,$where='') { $models = TestModel::find($model_id, $where = ''); $pesticides = $models->testPesticides()->where($where)->select(); return $pesticides; } public function getListByUserId($uid,$pageNum=1,$pageSize=10,$where=[]) { return $this->where('user_id','=',(int)$uid)->where($where)->page($pageNum,$pageSize)->select(); } public function countListByUserId($uid, $where = []) { return $this->where('user_id','=',(int)$uid)->where($where)->count(); } public function getModelInfoByModelID($model_id) { return $this->find($model_id); } public function updateModelInfoByModelID($model_id,$update_data) { return $this->find($model_id)->save($update_data); } public function createModelInfo($model_name,$type_id,$user_id) { return $this->insertGetId([ 'name'=>$model_name, 'type_id'=>$type_id, 'user_id'=>$user_id ]); } public function getUserIdByModelID($model_id) { if (empty($model_id)) { return false; } return $this->where('id', '=', $model_id)->field('user_id')->find(); } public function deleteModelInfoByID($model_id) { if (empty($model_id)) { return false; } return $this->where('id', '=', $model_id)->delete(); } }