Banner.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 轮播图管理
  7. */
  8. class Banner extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //某门店的轮播图
  13. public function banner_list(){
  14. $where = [
  15. 'company_id' => $this->auth->company_id,
  16. 'position' => 0, //首页
  17. ];
  18. $index = Db::name('banner')->where($where)->order('weigh asc,id asc')->select();
  19. $index = list_domain_image($index,['image']);
  20. $where = [
  21. 'company_id' => $this->auth->company_id,
  22. 'position' => 1, //门店印象
  23. ];
  24. $store = Db::name('banner')->where($where)->order('weigh asc,id asc')->autopage()->select();
  25. $store = list_domain_image($store,['image']);
  26. $rs = [
  27. 'index' => $index,
  28. 'store' => $store,
  29. ];
  30. $this->success(1,$rs);
  31. }
  32. //设置轮播图
  33. public function edit(){
  34. $index = input('index','');
  35. $store = input('store','');
  36. $where = [
  37. 'company_id' => $this->auth->company_id,
  38. 'position' => 0, //首页
  39. ];
  40. Db::name('banner')->where('company_id',$this->auth->company_id)->delete();
  41. $data = [];
  42. if(!empty($index)){
  43. $index = explode(',',$index);
  44. foreach($index as $key => $val){
  45. $data[] = [
  46. 'company_id' => $this->auth->company_id,
  47. 'image' => $val,
  48. 'position' => 0,
  49. 'status' => 1,
  50. 'createtime' => time(),
  51. 'updatetime' => time(),
  52. ];
  53. }
  54. }
  55. if(!empty($store)){
  56. $store = explode(',',$store);
  57. foreach($store as $key => $val){
  58. $data[] = [
  59. 'company_id' => $this->auth->company_id,
  60. 'image' => $val,
  61. 'position' => 1,
  62. 'status' => 1,
  63. 'createtime' => time(),
  64. 'updatetime' => time(),
  65. ];
  66. }
  67. }
  68. if(!empty($data)){
  69. Db::name('banner')->insertAll($data);
  70. }
  71. $this->success();
  72. }
  73. }