Banner.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class Banner extends Api
  6. {
  7. protected $noNeedLogin = ['getList'];
  8. protected $noNeedRight = '*';
  9. protected $model = null;
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->model = Db::name('platform_banner');
  14. }
  15. /**
  16. * 列表
  17. * @return void
  18. */
  19. public function getList()
  20. {
  21. try {
  22. $position = $this->request->param('position',0);//位置:0=首页,1=门店印象
  23. $field = 'id,title,image,url';
  24. $where['status'] = 1;
  25. $where['position'] = $position;
  26. $result = $this->model->field($field)->where($where)->order('weigh asc')->select();
  27. if (!empty($result)) {
  28. foreach ($result as $key => &$value) {
  29. !empty($value['image']) && $value['image'] = cdnurl($value['image']);
  30. }
  31. }
  32. $this->success('获取成功',$result);
  33. } catch (Exception $e) {
  34. $this->error($e->getMessage());
  35. }
  36. }
  37. /**
  38. * 门店列表
  39. * @return void
  40. */
  41. public function getCompanyList()
  42. {
  43. try {
  44. $companyId = $this->request->param('company_id',0);
  45. $companyId = !empty($companyId) ? $companyId : $this->auth->company_id;
  46. $field = 'id,title,image,url';
  47. $where['status'] = 1;
  48. $where['company_id'] = $companyId;
  49. $result = Db::name('banner')->field($field)->where($where)->order('weigh asc')->select();
  50. if (!empty($result)) {
  51. $result = list_domain_image($result, ['image']);
  52. }
  53. $this->success('获取成功',$result);
  54. } catch (Exception $e) {
  55. $this->error($e->getMessage());
  56. }
  57. }
  58. }