BestbaoAsk.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 知识库
  7. */
  8. namespace app\bestbao\model;
  9. use think\Model;
  10. class BestbaoAsk extends Model{
  11. //栏目名称
  12. public function category(){
  13. return $this->hasOne('BestbaoAskCategory','id','category_id');
  14. }
  15. //搜索
  16. public function searchTitleAttr($query, $value, $data){
  17. if(!empty($value)){
  18. $query->where('title','like', $value .'%');
  19. }
  20. }
  21. //添加或编辑
  22. public static function edit($param){
  23. $data['title'] = $param['title'];
  24. $data['content'] = $param['content'];
  25. $data['img'] = $param['img'];
  26. $data['imgs'] = json_encode($param['imgs']);
  27. $data['answer'] = $param['answer'];
  28. $data['reimg'] = json_encode($param['reimg']);
  29. $data['price'] = $param['price'];
  30. $data['update_time'] = time();
  31. if(isset($param['id'])){
  32. return self::update($data,['id'=>(int)$param['id']]);
  33. }else{
  34. $data['create_time'] = time();
  35. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  36. return self::insert($data);
  37. }
  38. }
  39. //推荐
  40. public static function ad(int $id){
  41. $result = self::where(['id' => $id])->find();
  42. $data['is_ad'] = $result['is_ad'] ? 0 : 1;
  43. return self::where('id',$id)->update($data);
  44. }
  45. //置顶
  46. public static function top(int $id){
  47. $result = self::where(['id' => $id])->find();
  48. $data['is_top'] = $result['is_top'] ? 0 : 1;
  49. return self::where('id',$id)->update($data);
  50. }
  51. }