TestModel.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. *
  4. *User:Administrator
  5. *Date:2021/10/11
  6. */
  7. namespace app\api\model;
  8. use think\Model;
  9. class TestModel extends Model
  10. {
  11. protected $table = 't_test_model';
  12. protected $pk = 'id';
  13. function testPesticides()
  14. {
  15. return $this->hasMany('TestPesticides', 'test_model_id', 'id');
  16. }
  17. function testProduct()
  18. {
  19. return $this->hasMany('TestProduct', 'test_model_id', 'id');
  20. }
  21. public function getProductInfo($model_id,$where=[])
  22. {
  23. $models = TestModel::find($model_id);
  24. $productInfo = $models->testProduct()->where($where)->select();
  25. return $productInfo;
  26. }
  27. public function getPesticidesInfo($model_id,$where='')
  28. {
  29. $models = TestModel::find($model_id, $where = '');
  30. $pesticides = $models->testPesticides()->where($where)->select();
  31. return $pesticides;
  32. }
  33. public function getListByUserId($uid,$pageNum=1,$pageSize=10,$where=[])
  34. {
  35. return $this->where('user_id','=',(int)$uid)->where($where)->page($pageNum,$pageSize)->select();
  36. }
  37. public function countListByUserId($uid, $where = [])
  38. {
  39. return $this->where('user_id','=',(int)$uid)->where($where)->count();
  40. }
  41. public function getModelInfoByModelID($model_id)
  42. {
  43. return $this->find($model_id);
  44. }
  45. public function updateModelInfoByModelID($model_id,$update_data)
  46. {
  47. return $this->find($model_id)->save($update_data);
  48. }
  49. public function createModelInfo($model_name,$type_id,$user_id)
  50. {
  51. return $this->insertGetId([
  52. 'name'=>$model_name,
  53. 'type_id'=>$type_id,
  54. 'user_id'=>$user_id
  55. ]);
  56. }
  57. public function getUserIdByModelID($model_id)
  58. {
  59. if (empty($model_id)) {
  60. return false;
  61. }
  62. return $this->where('id', '=', $model_id)->field('user_id')->find();
  63. }
  64. public function deleteModelInfoByID($model_id)
  65. {
  66. if (empty($model_id)) {
  67. return false;
  68. }
  69. return $this->where('id', '=', $model_id)->delete();
  70. }
  71. }