You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.1 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. class GoodsSearchword extends BaseModel
  4. {
  5. //用户消息
  6. protected $table = 'goods_searchword';
  7. public $timestamps = false;
  8. /**
  9. * 不能被批量赋值的属性
  10. *
  11. * @var array
  12. */
  13. protected $guarded = array();
  14. //获取列表
  15. public static function getList(array $param)
  16. {
  17. extract($param); //参数:limit,offset
  18. $limit = isset($limit) ? $limit : 10;
  19. $offset = isset($offset) ? $offset : 0;
  20. $model = new self;
  21. $where['status'] = 0;
  22. $model = $model->where($where);
  23. $res['count'] = $model->count();
  24. $res['list'] = array();
  25. if($res['count']>0)
  26. {
  27. $res['list'] = $model->skip($offset)->take($limit)->orderBy('click','desc')->orderBy('listorder','asc')->get();
  28. }
  29. else
  30. {
  31. return false;
  32. }
  33. return $res;
  34. }
  35. public static function getOne($where)
  36. {
  37. return self::where($where)->first();
  38. }
  39. public static function add(array $data)
  40. {
  41. //如果关键词存在,就增加点击量
  42. if(isset($data['name']))
  43. {
  44. if(self::getOne(array('name'=>$data['name'])))
  45. {
  46. \DB::table('goods_searchword')->where(array('name'=>$data['name']))->increment('click', 1);
  47. }
  48. else
  49. {
  50. if ($id = self::insertGetId($data))
  51. {
  52. return $id;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. return false;
  59. }
  60. return false;
  61. }
  62. public static function modify($where, array $data)
  63. {
  64. if (self::where($where)->update($data))
  65. {
  66. return true;
  67. }
  68. return false;
  69. }
  70. //删除一条记录
  71. public static function remove($id)
  72. {
  73. if (!self::whereIn('id', explode(',', $id))->delete())
  74. {
  75. return false;
  76. }
  77. return true;
  78. }
  79. }