Activity.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 数据层模型
  13. */
  14. class Activity extends BaseModel
  15. {
  16. public $page_info;
  17. /**
  18. * 活动列表
  19. * @author csdeshang
  20. * @param type $condition 查询条件
  21. * @param type $pagesize 分页页数
  22. * @param type $order 排序
  23. * @return type
  24. */
  25. public function getActivityList($condition, $pagesize = '', $order = 'activity_sort asc')
  26. {
  27. if ($pagesize) {
  28. $res = Db::name('activity')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  29. $this->page_info = $res;
  30. return $res->items();
  31. } else {
  32. return Db::name('activity')->where($condition)->order($order)->select()->toArray();
  33. }
  34. }
  35. /**
  36. * 添加活动
  37. * @author csdeshang
  38. * @param type $data 查询数据
  39. * @return array 一维数组
  40. */
  41. public function addActivity($data)
  42. {
  43. return Db::name('activity')->insertGetId($data);
  44. }
  45. /**
  46. * 更新活动
  47. * @author csdeshang
  48. * @param type $data 活动数据
  49. * @param type $id 活动id
  50. * @return type
  51. */
  52. public function editActivity($data, $id)
  53. {
  54. return Db::name('activity')->where("activity_id='$id' ")->update($data);
  55. }
  56. /**
  57. * 删除活动
  58. * @author csdeshang
  59. * @param type $condition 删除条件
  60. * @return type
  61. */
  62. public function delActivity($condition)
  63. {
  64. return Db::name('activity')->where($condition)->delete();
  65. }
  66. /**
  67. * 根据id查询一条活动
  68. * @author csdeshang
  69. * @param int $id 活动id
  70. * @return array 一维数组
  71. */
  72. public function getOneActivityById($id)
  73. {
  74. return Db::name('activity')->where('activity_id', $id)->find();
  75. }
  76. }