Caozuoguifan.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\api\controller\worker;
  3. use app\common\controller\Apiw;
  4. use think\Db;
  5. /**
  6. * 操作规范
  7. */
  8. class Caozuoguifan extends Apiw
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. public function index()
  13. {
  14. //所有分类
  15. $typelist = Db::name('caozuoguifan_type')
  16. ->where('company_id',$this->auth->company_id)
  17. ->order('id' , 'asc')
  18. ->select();
  19. //第一个分类的内容
  20. $list = [];
  21. if(!empty($typelist)){
  22. $list = Db::name('caozuoguifan')->field('content',true)
  23. ->where('company_id',$this->auth->company_id)
  24. ->where('type_id',$typelist[0]['id'])
  25. ->autopage()
  26. ->select();
  27. $list = list_domain_image($list,['image','videofile']);
  28. }
  29. $rs = [
  30. 'typelist' => $typelist,
  31. 'list' => $list,
  32. ];
  33. $this->success(1, $rs);
  34. }
  35. //操作规范
  36. public function lists(){
  37. $type_id = input('type_id',0);
  38. $list = Db::name('caozuoguifan')->field('content',true)
  39. ->where('company_id',$this->auth->company_id)
  40. ->where('type_id',$type_id)
  41. ->autopage()
  42. ->select();
  43. $list = list_domain_image($list,['image','videofile']);
  44. $this->success(1, $list);
  45. }
  46. //详情
  47. public function info(){
  48. $id = input('id',0);
  49. $info = Db::name('caozuoguifan')
  50. ->where('id',$id)
  51. ->find();
  52. $info = info_domain_image($info, ['image','videofile']);
  53. //收藏
  54. $info['is_collect'] = $this->is_collect($info['id'],$this->auth->id);
  55. $this->success(1, $info);
  56. }
  57. //收藏,取消收藏
  58. public function collect(){
  59. $where = [
  60. 'worker_id' => $this->auth->id,
  61. 'table' => 'caozuoguifan',
  62. 'table_id' => input('id',0),
  63. ];
  64. $check = Db::name('worker_collect')->where($where)->find();
  65. if($check){
  66. Db::name('worker_collect')->where($where)->delete();
  67. $this->success('已取消收藏');
  68. }else{
  69. Db::name('worker_collect')->insertGetId($where);
  70. $this->success('收藏成功');
  71. }
  72. }
  73. //动态是否收藏
  74. private function is_collect($id,$uid){
  75. $where = [
  76. 'worker_id' => $uid,
  77. 'table' => 'caozuoguifan',
  78. 'table_id' => $id,
  79. ];
  80. $check = Db::name('worker_collect')->where($where)->find();
  81. if($check){
  82. return 1;
  83. }else{
  84. return 0;
  85. }
  86. }
  87. }