SharePosters.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\controller\admin\share;
  3. use crmeb\basic\BaseController;
  4. use think\facade\Db;
  5. class SharePosters extends BaseController
  6. {
  7. public function lst(){
  8. [$page, $limit] = $this->getPage();
  9. $where = $this->request->params(['classify']);
  10. $query=Db::name('share_posters')
  11. -> alias("sp")
  12. -> join("share_posters_classify spc","sp.classify = spc.id","left")
  13. -> where('sp.mer_id',0)
  14. -> when(!empty($where['classify']),function ($query) use ($where){
  15. $query -> where("sp.classify",$where['classify']);
  16. })->field("sp.sort,sp.name,spc.name as classify_name,sp.time,sp.type,sp.status,sp.id");
  17. $count = $query -> count();
  18. $list = $query ->order("sp.sort desc,sp.id desc")->page($page,$limit)->select()->toArray();
  19. return app('json')->success(compact("list","count"));
  20. }
  21. public function classify_list(){
  22. $list = Db::name("share_posters_classify") ->where('mer_id',0)->where('is_del',0)->order("sort desc,id asc")-> select() -> toArray();
  23. return app("json") -> success($list);
  24. }
  25. public function classify_del(){
  26. $id=$this->request->params(['id']);
  27. Db::name('share_posters_classify')->where('mer_id',0)->where('id',$id['id'])->update(['is_del'=>1]);
  28. return app("json") -> success('删除成功');
  29. }
  30. public function del(){
  31. $id=$this->request->params(['id']);
  32. Db::name('share_posters')->where('id',$id['id'])->delete();
  33. return app("json") -> success('删除成功');
  34. }
  35. public function get_one(){
  36. $id=$this->request->params(['id']);
  37. if(empty($id['id'])){
  38. return app('json')->fail('id不存在');
  39. }
  40. $data=Db::name('share_posters')->where('id',$id['id'])->find();
  41. return app("json") -> success($data);
  42. }
  43. public function save_share(){
  44. $data = $this -> request -> params([
  45. 'name',
  46. 'image',
  47. 'classify',
  48. 'qr_coordinate',
  49. 'head_coordinate',
  50. 'nickname_coordinate',
  51. 'head_size',
  52. 'qr_size',
  53. 'nickname_size',
  54. 'image_fake',
  55. 'type',
  56. 'status',
  57. 'sort',
  58. 'id'
  59. ]);
  60. $id = $data['id'] ?? 0;
  61. unset($data['id']);
  62. if ($id == 0){
  63. //新增
  64. $res = Db::name("share_posters") -> insert($data);
  65. }else{
  66. //
  67. $res = Db::name("share_posters") -> where("id",$id) -> update($data);
  68. return app("json") -> success("成功");
  69. }
  70. if ($res)return app("json") -> success("成功");
  71. return app("json") -> fail('出错');
  72. }
  73. public function save_share_classify(){
  74. $data = $this -> request -> params([
  75. 'name',
  76. 'sort',
  77. "id"
  78. ]);
  79. $id = $data['id'] ?? 0;
  80. unset($data['id']);
  81. if ($id == 0 ){
  82. $res = Db::name("share_posters_classify") -> insert($data);
  83. }else{
  84. $res = Db::name("share_posters_classify") -> where("id",$id) -> update($data);
  85. return app("json") -> success("成功");
  86. }
  87. if ($res)return app("json") -> success("成功");
  88. return app("json") -> fail('出错');
  89. }
  90. }