BaseClass.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace common\base\classes;
  3. use Yii;
  4. use \common\base\models\Base;
  5. class BaseClass
  6. {
  7. public static $baseFile;
  8. /**
  9. * @return Base
  10. */
  11. protected static function getModel()
  12. {
  13. return Yii::createObject(['class' => static::$baseFile]);
  14. }
  15. //查询全部 ssh 2019.11.27
  16. public static function getAllList($select, $where, $order = '', $with = '')
  17. {
  18. $model = self::getModel();
  19. $return = $model->getAllList($select, $where, $order, $with);
  20. return $return;
  21. }
  22. //分页查询 ssh 2019.9.21
  23. public static function getList($select, $where, $order = '', $with = '')
  24. {
  25. $get = Yii::$app->request->get();
  26. $page = isset($get['page']) ? $get['page'] : 1;
  27. Yii::$app->params['page'] = $page;
  28. $pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
  29. $model = self::getModel();
  30. $return = $model->getList($select, $where, $page, $pageSize, $order, $with);
  31. return $return;
  32. }
  33. //查询指定条数 ssh 2019.11.30
  34. public static function getLimitList($select, $where, $limit = 10, $order = '', $with = '')
  35. {
  36. $model = self::getModel();
  37. $return = $model->getLimitList($select, $where, $limit, $order, $with);
  38. return $return;
  39. }
  40. public static function add($data, $returnObject = false)
  41. {
  42. $model = self::getModel();
  43. return $model->add($data, $returnObject);
  44. }
  45. /**
  46. * 批量添加
  47. */
  48. public static function batchAdd($data)
  49. {
  50. $model = self::getModel();
  51. $model->batchAdd($data);
  52. }
  53. /**
  54. * 根据主键ID删除一条记录
  55. * @param $id
  56. * @return false|int the number of rows deleted, or `false` if the deletion is unsuccessful for some reason.
  57. * @throws \Throwable
  58. * @throws \yii\db\StaleObjectException
  59. */
  60. public static function deleteById($id)
  61. {
  62. $model = self::getModel();
  63. return $model->deleteById($id);
  64. }
  65. /**
  66. *根据条件删除一条或多条记录
  67. */
  68. public static function deleteByCondition($condition)
  69. {
  70. $model = self::getModel();
  71. $count = $model->deleteByCondition($condition);
  72. return $count;
  73. }
  74. //根据id批量删 ssh 2019.12.7
  75. public static function deleteByIds($ids)
  76. {
  77. $model = self::getModel();
  78. return $model->deleteByIds($ids);
  79. }
  80. /**
  81. * 根据主键ID更新一条记录
  82. */
  83. public static function updateById($id, $data)
  84. {
  85. $model = self::getModel();
  86. return $model->updateById($id, $data);
  87. }
  88. //根据多个主键id更新 ssh 2019.9.3
  89. public static function updateByIds($ids, $data)
  90. {
  91. $model = self::getModel();
  92. return $model->updateByIds($ids, $data);
  93. }
  94. /**
  95. * 根据条件更新一条或多条记录
  96. */
  97. public static function updateByCondition($condition, $data)
  98. {
  99. $model = self::getModel();
  100. $count = $model->updateByCondition($condition, $data);
  101. return $count;
  102. }
  103. /**
  104. * 根据主键ID查出一条记录
  105. */
  106. public static function getById($id, $returnObject = false, $field = '*')
  107. {
  108. $model = self::getModel();
  109. return $model->getById($id, $returnObject, $field);
  110. }
  111. //随机取一个 ssh 2020.2.10
  112. public static function getOne($returnObject = false, $order = false, $field = '*')
  113. {
  114. $model = self::getModel();
  115. return $model->getOne($returnObject, $order, $field);
  116. }
  117. /**
  118. *根据条件查出一条记录
  119. */
  120. public static function getByCondition($condition, $returnObject = false, $order = false, $field = '*')
  121. {
  122. $model = self::getModel();
  123. return $model->getByCondition($condition, $returnObject, $order, $field);
  124. }
  125. //是否存在 ssh 2019.8.30
  126. public static function exists($condition)
  127. {
  128. $model = self::getModel();
  129. return $model->exists($condition);
  130. }
  131. /**
  132. *根据条件查出多条记录
  133. */
  134. public static function getAllByCondition($condition, $order = null, $field = '*', $indexBy = null, $returnObject = false)
  135. {
  136. $model = self::getModel();
  137. return $model->getAllByCondition($condition, $order, $field, $indexBy, $returnObject);
  138. }
  139. /**
  140. * 根据多个主键ID查询多条记录
  141. */
  142. public static function getByIds($ids, $order = null, $indexBy = null, $field = '*')
  143. {
  144. $model = self::getModel();
  145. return $model->getByIds($ids, $order, $indexBy, $field);
  146. }
  147. /**
  148. *根据条件查出数量
  149. */
  150. public static function getCount($condition)
  151. {
  152. $model = self::getModel();
  153. return $model->getCount($condition);
  154. }
  155. //计数器+1-1 shizq 2019-12-05
  156. public static function counters($counters, $condition, $params = [])
  157. {
  158. $model = self::getModel();
  159. return $model->counters($counters, $condition, $params);
  160. }
  161. //根据主键获取被销的信息 ssh 2021.5.18
  162. public static function getLockById($id, $field = '*')
  163. {
  164. $model = self::getModel();
  165. return $model->getLockById($id, $field);
  166. }
  167. //求和
  168. public static function sum($condition, $field)
  169. {
  170. $model = self::getModel();
  171. return $model->sum($condition, $field);
  172. }
  173. }