LiveAnchor.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\marketing\live;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\live\LiveAnchorServices;
  14. use think\facade\App;
  15. /**
  16. * 直播间主播
  17. * Class LiveAnchor
  18. * @package app\controller\admin\store
  19. */
  20. class LiveAnchor extends AuthController
  21. {
  22. /**
  23. * LiveAnchor constructor.
  24. * @param App $app
  25. * @param LiveAnchorServices $services
  26. */
  27. public function __construct(App $app, LiveAnchorServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 列表
  34. * @return mixed
  35. */
  36. public function list()
  37. {
  38. $where = $this->request->postMore([
  39. ['kerword', ''],
  40. ]);
  41. return $this->success($this->services->getList($where));
  42. }
  43. /**
  44. * 添加修改表单
  45. * @return mixed
  46. * @throws \FormBuilder\Exception\FormBuilderException
  47. */
  48. public function add()
  49. {
  50. [$id] = $this->request->getMore([
  51. ['id', 0],
  52. ], true);
  53. return $this->success($this->services->add((int)$id));
  54. }
  55. /**
  56. * 保存标签表单数据
  57. * @param int $id
  58. * @return mixed
  59. */
  60. public function save()
  61. {
  62. $data = $this->request->postMore([
  63. ['id', 0],
  64. ['name', ''],
  65. ['wechat', ''],
  66. ['phone', ''],
  67. ['cover_img', '']
  68. ]);
  69. if (!$data['name'] = trim($data['name'])) return $this->fail('名称不能为空!');
  70. if (!$data['wechat'] = trim($data['wechat'])) return $this->fail('微信号不能为空!');
  71. if (!$data['phone'] = trim($data['phone'])) return $this->fail('手机号不能为空!');
  72. if (!check_phone($data['phone'])) return app('json')->fail('请输入正确手机号');
  73. if (!$data['cover_img'] = trim($data['cover_img'])) return $this->fail('请选择主播图像');
  74. $res = $this->services->save((int)$data['id'], $data);
  75. if ($res === true) {
  76. return $this->success('保存成功', ['auth' => false]);
  77. }
  78. return $this->success('请先去小程序认证主播', $res);
  79. }
  80. /**
  81. * 删除
  82. * @param $id
  83. * @throws \Exception
  84. */
  85. public function delete()
  86. {
  87. [$id] = $this->request->getMore([
  88. ['id', 0],
  89. ], true);
  90. if (!$id) return $this->fail('数据不存在');
  91. $this->services->delAnchor((int)$id);
  92. return $this->success('刪除成功!');
  93. }
  94. /**
  95. * 设置会员等级显示|隐藏
  96. *
  97. * @return json
  98. */
  99. public function setShow($id = '', $is_show = '')
  100. {
  101. if ($is_show == '' || $id == '') return $this->fail('缺少参数');
  102. return $this->success($this->services->setShow((int)$id, (int)$is_show));
  103. }
  104. /**
  105. * 同步主播
  106. * @return mixed
  107. */
  108. public function syncAnchor()
  109. {
  110. $this->services->syncAnchor();
  111. return app('json')->success('同步成功');
  112. }
  113. }