BaseClass.php 4.3 KB

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