Boss.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace app\adminall\controller;
  3. use think\facade\View;
  4. use think\facade\Request;
  5. use app\logics\Activity as Logic;
  6. use app\model\Activity as ModelActivity;
  7. use app\model\ActivityCustomerExportLog;
  8. use app\model\Footprints;
  9. use think\facade\Db;
  10. use app\model\Employee;
  11. use app\model\Customer;
  12. use app\model\Org;
  13. use app\model\Permission;
  14. use app\model\Grant;
  15. use app\model\CustomerVisitLog;
  16. use app\model\Broadcast;
  17. use app\model\Lecturer;
  18. class Boss
  19. {
  20. private $root_id = 0;//总后台店面id默认0
  21. private $employee_id = 0;
  22. /**
  23. * 列表
  24. */
  25. public function list()
  26. {
  27. if (!Request::isAjax()) {
  28. $eid = ModelActivity::where([['del', '=', 0], ['root_id', '=', $this->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
  29. $where = [
  30. ['del', '=', 0],
  31. ['root_id', '=', $this->root_id]
  32. ];
  33. // 运营人员列表
  34. $employee = Lecturer::where($where)->column('id,name');
  35. View::assign('employee', $employee);
  36. return View::fetch();
  37. }
  38. $param = Request::only(['page', 'limit', 'keyword', 'date', 'employee_id']);
  39. $where = [
  40. ['del', '=', 0],
  41. ['root_id', '=', $this->root_id]
  42. ];
  43. if (!empty($param['date'])) {
  44. $dates = explode(' - ', $param['date']);
  45. $where[] = ['start_date', '>=', strtotime($dates[0])];
  46. $where[] = ['start_date', '<=', strtotime($dates[1])];
  47. }
  48. if (!empty($param['keyword'])) {
  49. $where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
  50. }
  51. if (!empty($param['employee_id'])) {
  52. $where[] = ['lecturer_id', '=', $param['employee_id']];
  53. }
  54. $list = Broadcast::with(['lecturer'=>function($query){
  55. $query->bind(['lecturer_name'=>'name']);
  56. }])->where($where)->page($param['page'], $param['limit'])->field('*')->order('addtime desc')->select()->toArray();
  57. $aids = [];
  58. foreach ($list as &$val) {
  59. $val['start_date'] = str_replace('-','/',$val['start_date']);
  60. $val['end_date'] = str_replace('-','/',$val['end_date']);
  61. $val['time'] = $val['start_date'].'-'.$val['end_date'];
  62. $val['type'] = $val['broadcast_type']==1 ? '威哥直播' : '直播';
  63. $val['broadcast_platform'] = $val['broadcast_platform']==1 ? '其他平台' : 'boos直播';
  64. }
  65. $count = Broadcast::where($where)->count();
  66. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  67. }
  68. /**
  69. * 添加视图
  70. */
  71. public function add()
  72. {
  73. //讲师列表
  74. $employee = Lecturer::where([['del','=',0],['root_id','=',0]])->column('name,id');
  75. View::assign('employee', $employee);
  76. return View::fetch();
  77. }
  78. /**
  79. * 删除直播
  80. */
  81. public function del()
  82. {
  83. $id = input('id',0);
  84. Broadcast::where([['id','=',$id],['root_id','=',0]])->update(['del'=>1]);
  85. return json(['code' => 0, 'msg' => '删除成功']);
  86. }
  87. /**
  88. * 添加直播
  89. */
  90. public function addActivity()
  91. {
  92. $data = Request::only(['name','lecturer_id','start_date','broadcast_type','broadcast_platform','broadcast_url','broadcast_cover']);
  93. $date = explode(' - ',$data['start_date']);
  94. $data['start_date'] = strtotime($date[0]);
  95. $data['end_date'] = strtotime($date[1]);
  96. $data['root_id'] = $this->root_id;
  97. $data['addtime'] = time();
  98. if ($data['start_date'] > $data['end_date']) return json(['code' => 1, 'msg' => '开始日期需在结束日期之前']);
  99. Broadcast::insert($data);
  100. return json(['code' => 0, 'msg' => '添加成功']);
  101. }
  102. /**
  103. * 修改视图
  104. */
  105. public function edit($id)
  106. {
  107. $where = [
  108. ['root_id','=',0],
  109. ['id','=',$id]
  110. ];
  111. $data = Broadcast::where($where)->findOrEmpty();
  112. View::assign('data', $data);
  113. //讲师列表
  114. $employee = Lecturer::where([['del','=',0],['root_id','=',0]])->column('name,id');
  115. View::assign('employee', $employee);
  116. return View::fetch();
  117. }
  118. /**
  119. * 编辑直播
  120. */
  121. public function editActivity()
  122. {
  123. $data = Request::only(['name','lecturer_id','start_date','broadcast_type','broadcast_platform','broadcast_url','broadcast_cover']);
  124. $id = input('id',0);
  125. $info = Broadcast::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
  126. $date = explode(' - ',$data['start_date']);
  127. $data['start_date'] = strtotime($date[0]);
  128. $data['end_date'] = strtotime($date[1]);
  129. foreach ($data as $key => $value) {
  130. $info->$key = $value;
  131. }
  132. $info->save();
  133. return json(['code' => 0, 'msg' => '添加成功']);
  134. }
  135. /**
  136. * 直播回访
  137. */
  138. public function playback()
  139. {
  140. $id = input('id',0);
  141. $data = Broadcast::where([['root_id','=',0],['id','=',$id]])->field('id,playback_cover,playback_url')->findOrEmpty();
  142. View::assign('data', $data);
  143. return View::fetch();
  144. }
  145. /**
  146. * 直播回访
  147. */
  148. public function savePlayback()
  149. {
  150. $data = Request::only(['playback_cover'=>'','playback_url'=>'']);
  151. $id = input('id',0);
  152. $info = Broadcast::where([['root_id','=',0],['id','=',$id]])->field('id,playback_cover,playback_url')->findOrEmpty();
  153. foreach ($data as $key => $value) {
  154. $info->$key = $value;
  155. }
  156. $info->save();
  157. return json(['code' => 0, 'msg' => '保存成功','data'=>'保存成功']);
  158. }
  159. }