Activity.php 2.0 KB

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