FilmScreen.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 电影场次管理
  7. * Class FilmList
  8. * @package app\store\controller
  9. */
  10. class FilmScreen extends Controller
  11. {
  12. protected $table = 'FilmInfo';
  13. /**
  14. * 电影场次列表
  15. * @auth true
  16. * @menu true
  17. */
  18. public function index(){
  19. $this->title = '电影场次';
  20. $f_id = input('f_id');
  21. $this->film = Db::table('film_list')->find($f_id);
  22. $query = $this->_query($this->table)->where(['f_id'=>$f_id]);
  23. $query->order('day_time desc ,point_time desc,id desc')->page();
  24. }
  25. /**
  26. * 数据列表处理
  27. * @auth true
  28. * @menu true
  29. * @param array $data
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. protected function _index_page_filter(&$data)
  35. {
  36. foreach ($data as &$vo) {
  37. $vo['show_time'] = $vo['day_time'].' ' . $vo['point_time'];
  38. $vo['sell_rate'] = bcdiv( $vo['num'] - $vo['surplus_num'],$vo['num'] ? : 1,4) * 100 . '%';
  39. $sell_num = Db::table('ticket_order')
  40. ->field('total_num,children_num')
  41. ->where(['f_id'=>$vo['id'],'pay_state'=>1])
  42. ->select();
  43. $children_num = empty($sell_num) ? 0: array_sum(array_column($sell_num,'children_num'));
  44. $total = empty($sell_num) ? 0: array_sum(array_column($sell_num,'total_num'));
  45. $adu_num = $total - $children_num;
  46. $vo['s_num'] = $total;
  47. $vo['adu_rate'] = empty($sell_num)? '0%' :bcdiv($adu_num,$vo['num'],4)*100 . '%';
  48. $vo['children_rate'] = empty($sell_num)? '0%':bcdiv($children_num,$vo['num'],4) * 100 . '%';
  49. }
  50. }
  51. /**
  52. * 添加场次
  53. * @auth true
  54. * @menu true
  55. * @throws \think\Exception
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @throws \think\exception\DbException
  59. * @throws \think\exception\PDOException
  60. */
  61. public function add()
  62. {
  63. $this->title = '添加场次';
  64. $f_id = input('f_id');
  65. $this->film_detail = Db::table('film_list')->find($f_id);
  66. $this->_form($this->table, 'form');
  67. }
  68. /**
  69. * 编辑场次
  70. * @auth true
  71. * @menu true
  72. * @throws \think\Exception
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. * @throws \think\exception\PDOException
  77. */
  78. public function edit()
  79. {
  80. $this->title = '编辑场次';
  81. $f_id = input('f_id');
  82. $this->film_detail = Db::table('film_list')->find($f_id);
  83. $this->_form($this->table, 'form');
  84. }
  85. /**
  86. * 取消场次
  87. * @auth true
  88. * @menu true
  89. * @throws \think\Exception
  90. * @throws \think\exception\PDOException
  91. */
  92. public function cancel()
  93. {
  94. $this->_save($this->table, ['status' => '0']);
  95. }
  96. /**
  97. * 上映场次
  98. * @auth true
  99. * @menu true
  100. * @throws \think\Exception
  101. * @throws \think\exception\PDOException
  102. */
  103. public function up()
  104. {
  105. $this->_save($this->table, ['status' => '1']);
  106. }
  107. /**
  108. * 表单数据处理
  109. * @auth true
  110. * @menu true
  111. * @param array $data
  112. */
  113. protected function _form_filter(&$data)
  114. {
  115. if ($this->request->isPost()) {
  116. $f_id = input('f_id');
  117. $show_time = strtotime( input('show_time'));
  118. $data['day_time'] = date("Y-m-d",$show_time);
  119. $data['point_time'] = date("H:i",$show_time);
  120. $data['surplus_num'] = input('num');
  121. $sel_id = isset($data['id']) ? $data['id'] : 0;
  122. $check = Db::table('film_info')
  123. ->where(['f_id'=>$f_id,'day_time' =>$data['day_time'],'point_time'=>$data['point_time'] ])
  124. ->where('id !='.$sel_id)
  125. ->count();
  126. if($check) $this->error('该电影在此时间段已有场次');
  127. }
  128. }
  129. function copy_screen()
  130. {
  131. $ids = input('ids');// 所选择的id
  132. $limit_date =date("Y-m-d", strtotime('-1 day'));// 昨天日期
  133. $sel_screen = Db::table('film_info')
  134. ->where(['id'=>$ids])
  135. ->where('day_time','>= time',$limit_date)
  136. ->select();
  137. $copy_num= 0;
  138. foreach ($sel_screen as $sv)
  139. {
  140. $check = Db::table('film_info')
  141. ->where(['f_id'=>$sv['f_id'],'point_time'=>$sv['point_time'],'day_time'=>date("Y-m-d",strtotime($sv['day_time']) + 86400)])
  142. ->value('id');
  143. if($check) continue;
  144. $copy_data = [
  145. 'f_id'=>$sv['f_id'],
  146. 'status'=>$sv['status'],
  147. 'create_at'=>date('Y-m-d H:i:s'),
  148. 's_price'=>$sv['s_price'],
  149. 'sort'=>$sv['sort'],
  150. 'num'=>$sv['num'],
  151. 'surplus_num'=>$sv['surplus_num'],
  152. 'point_time'=>$sv['point_time'],
  153. 'day_time'=>date("Y-m-d",strtotime($sv['day_time']) + 86400),
  154. 'show_time'=>date("Y-m-d H:i:s",strtotime($sv['show_time'])+86400),
  155. ];
  156. $copy_num++;
  157. }
  158. }
  159. }