WebAftermarket.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace addons\qingdongams\controller;
  3. use addons\qingdongams\model\Aftermarket as AftermarketModel;
  4. use addons\qingdongams\model\AftermarketType;
  5. use addons\qingdongams\model\Comment;
  6. use addons\qingdongams\model\AdminConfig;
  7. /**
  8. * 知识库
  9. */
  10. class WebAftermarket extends WebIndexApi
  11. {
  12. protected $noNeedLogin = ['user_config'];
  13. protected $noNeedRight = [];
  14. /**
  15. * @var \addons\qingdongams\model\Aftermarket
  16. */
  17. protected $model;
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. $this->model = new AftermarketModel();
  22. }
  23. // 获取分类
  24. public function typeList(){
  25. $pid = input('pid',0);
  26. $where['pid'] = $pid;
  27. $model = new AftermarketType();
  28. $list = collection($model->order('id desc')->where($where)->field('id,name,pid')->select())->toArray();
  29. $this->success('',$list);
  30. }
  31. //文章列表
  32. public function articleList()
  33. {
  34. $limit = input("limit/d", 10);
  35. $params = $this->request->post();
  36. $where = [];
  37. if(isset($params['type_ids']) && $params['type_ids']){
  38. $where['type_ids'] = ['like','%,'.$params['type_ids'].',%'];
  39. }
  40. if(isset($params['name']) && $params['name']){
  41. $where['title'] = ['like','%'.$params['name'].'%'];
  42. }
  43. $comments = $this->model->where($where)->paginate($limit);
  44. $this->success('请求成功', $comments);
  45. }
  46. public function detailArt(){
  47. $id = input('id');
  48. if(!$id){
  49. $this->error('文章id呢?');
  50. }
  51. $id = input("id");
  52. if(!isset($id) || !$id){
  53. $this->error('参数缺失');
  54. }
  55. // 文章详情
  56. $detail = AftermarketModel::where('id',$id)->field('id,create_staff_id,product_ids,type_ids,title,content,img,desc,method,click_number,comment_num,createtime')->find();
  57. // 详情
  58. $comments = Comment::where([
  59. 'relation_type' => 'article',
  60. 'relation_id' => $id,
  61. 'status' => 1
  62. ])->field('id,staff_id,content,createtime')->with(['staff'])->select();
  63. $detail['comment'] = $comments;
  64. $this->success('请求成功', $detail);
  65. }
  66. /**
  67. * 文章浏览次数
  68. * @throws \think\Exception
  69. */
  70. public function viewArticle(){
  71. $id = input('id');
  72. if(!$id){
  73. $this->error('文章id呢?');
  74. }
  75. $articleModel = new AftermarketModel();
  76. $row = $articleModel->get($id);
  77. if(!$row){
  78. $this->error('文章不存在');
  79. }
  80. if($articleModel->where(['id'=>$id])->setInc('click_number')){
  81. $this->success('成功');
  82. }else{
  83. $this->error('失败');
  84. }
  85. }
  86. //客户端配置
  87. public function user_config(){
  88. $data = AdminConfig::where(array('type'=>'user'))->column('field,value');
  89. $data['user_name'] = $data['user_name'] ??'';
  90. $data['user_phone'] = $data['user_phone']??'';
  91. $data['user_email'] = $data['user_email'] ?? '';
  92. $data['user_logo'] = isset($data['user_logo'])? cdnurl($data['user_logo'],true) : '';
  93. $data['user_address'] = $data['user_address'] ?? '';
  94. $data['user_lat'] = $data['user_lat'] ?? '';
  95. $data['user_lag'] = $data['user_lag'] ??'';
  96. $this->success('',$data);
  97. }
  98. }