BaseClass.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace biz\base\classes;
  3. use Yii;
  4. class BaseClass
  5. {
  6. public static $baseFile;
  7. //查询全部 shish 2019.11.27
  8. public static function getAllList($select, $where, $order = '', $with = '')
  9. {
  10. $model = Yii::createObject(['class' => static::$baseFile]);
  11. $return = $model->getAllList($select, $where, $order, $with);
  12. return $return;
  13. }
  14. //分页查询 shish 2019.9.21
  15. public static function getList($select, $where, $order = '', $with = '')
  16. {
  17. $get = Yii::$app->request->get();
  18. $page = isset($get['page']) ? $get['page'] : 1;
  19. Yii::$app->params['page'] = $page;
  20. //pageSize 已经在common/params.php定义
  21. $pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
  22. $model = Yii::createObject(['class' => static::$baseFile]);
  23. $return = $model->getList($select, $where, $page, $pageSize, $order, $with);
  24. return $return;
  25. }
  26. //查询指定条数 shish 2019.11.30
  27. public static function getLimitList($select, $where, $limit = 10, $order = '', $with = '')
  28. {
  29. $model = Yii::createObject(['class' => static::$baseFile]);
  30. $return = $model->getLimitList($select, $where, $limit, $order, $with);
  31. return $return;
  32. }
  33. public static function add($data, $returnObject = false)
  34. {
  35. $model = Yii::createObject(['class' => static::$baseFile]);
  36. return $model->add($data, $returnObject);
  37. }
  38. /**
  39. * 批量添加
  40. */
  41. public static function batchAdd($data)
  42. {
  43. $model = Yii::createObject(['class' => static::$baseFile]);
  44. $model->batchAdd($data);
  45. }
  46. /**
  47. * 根据主键ID删除一条记录
  48. */
  49. public static function deleteById($id)
  50. {
  51. $model = Yii::createObject(['class' => static::$baseFile]);
  52. return $model->deleteById($id);
  53. }
  54. /**
  55. *根据条件删除一条或多条记录
  56. */
  57. public static function deleteByCondition($condition)
  58. {
  59. $model = Yii::createObject(['class' => static::$baseFile]);
  60. $count = $model->deleteByCondition($condition);
  61. return $count;
  62. }
  63. //根据id批量删 shish 2019.12.7
  64. public static function deleteByIds($ids)
  65. {
  66. $model = Yii::createObject(['class' => static::$baseFile]);
  67. return $model->deleteByIds($ids);
  68. }
  69. /**
  70. * 根据主键ID更新一条记录
  71. */
  72. public static function updateById($id, $data)
  73. {
  74. $model = Yii::createObject(['class' => static::$baseFile]);
  75. return $model->updateById($id, $data);
  76. }
  77. //根据多个主键id更新 shish 2019.9.3
  78. public static function updateByIds($ids, $data)
  79. {
  80. $model = Yii::createObject(['class' => static::$baseFile]);
  81. return $model->updateByIds($ids, $data);
  82. }
  83. /**
  84. * 根据条件更新一条或多条记录
  85. */
  86. public static function updateByCondition($condition, $data)
  87. {
  88. $model = Yii::createObject(['class' => static::$baseFile]);
  89. $count = $model->updateByCondition($condition, $data);
  90. return $count;
  91. }
  92. /**
  93. * 根据主键ID查出一条记录
  94. */
  95. public static function getById($id, $returnObject = false)
  96. {
  97. $model = Yii::createObject(['class' => static::$baseFile]);
  98. return $model->getById($id, $returnObject);
  99. }
  100. /**
  101. *根据条件查出一条记录
  102. */
  103. public static function getByCondition($condition, $returnObject = false, $order = false)
  104. {
  105. $model = Yii::createObject(['class' => static::$baseFile]);
  106. return $model->getByCondition($condition, $returnObject, $order);
  107. }
  108. //是否存在 shish 2019.8.30
  109. public static function exists($condition)
  110. {
  111. $model = Yii::createObject(['class' => static::$baseFile]);
  112. return $model->exists($condition);
  113. }
  114. /**
  115. *根据条件查出多条记录
  116. */
  117. public static function getAllByCondition($condition, $order = null, $field, $indexBy = null)
  118. {
  119. $model = Yii::createObject(['class' => static::$baseFile]);
  120. return $model->getAllByCondition($condition, $order, $field, $indexBy);
  121. }
  122. /**
  123. * 根据多个主键ID查询多条记录
  124. */
  125. public static function getByIds($ids, $order = null, $indexBy = null)
  126. {
  127. $model = Yii::createObject(['class' => static::$baseFile]);
  128. return $model->getByIds($ids, $order, $indexBy);
  129. }
  130. /**
  131. *根据条件查出数量
  132. */
  133. public static function getCount($condition)
  134. {
  135. $model = Yii::createObject(['class' => static::$baseFile]);
  136. return $model->getCount($condition);
  137. }
  138. }