1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- *
- *User:Administrator
- *Date:2021/10/11
- */
- namespace app\api\model;
- use think\Model;
- class TestModel extends Model
- {
- protected $table = 't_test_model';
- protected $pk = 'id';
- function testPesticides()
- {
- return $this->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();
- }
- }
|