Sellervideo.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Sellervideo extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervideo.lang.php');
  18. }
  19. public function index()
  20. {
  21. $goods_model = model('goods');
  22. $video_list = $goods_model->getGoodsVideoList(array(array('store_id', '=', session('store_id'))), '*', 'goodsvideo_id desc', 0, 16);
  23. foreach ($video_list as $key => $val) {
  24. $video_list[$key]['goodsvideo_url'] = goods_video($val['goodsvideo_name']);
  25. }
  26. View::assign('video_list', $video_list);
  27. View::assign('show_page', $goods_model->page_info->render());
  28. /* 设置卖家当前菜单 */
  29. $this->setSellerCurMenu('sellervideo');
  30. /* 设置卖家当前栏目 */
  31. $this->setSellerCurItem('index');
  32. return View::fetch($this->template_dir . 'index');
  33. }
  34. /**
  35. * 视频列表,外部调用
  36. */
  37. public function video_list()
  38. {
  39. $goods_model = model('goods');
  40. $video_list = $goods_model->getGoodsVideoList(array(array('store_id', '=', session('store_id'))), '*', 'goodsvideo_id desc', 0, 3);
  41. foreach ($video_list as $key => $val) {
  42. $video_list[$key]['goodsvideo_url'] = goods_video($val['goodsvideo_name']);
  43. }
  44. View::assign('video_list', $video_list);
  45. View::assign('show_page', $goods_model->page_info->render());
  46. echo View::fetch($this->template_dir . 'video_list');
  47. }
  48. /**
  49. * 视频删除
  50. */
  51. public function del_video()
  52. {
  53. $return_json = input('param.return_json'); //是否为json 返回
  54. $ids = input('param.id/a');
  55. if (empty($ids)) {
  56. $this->error(lang('param_error'));
  57. }
  58. $goods_model = model('goods');
  59. //删除视频
  60. $condition = array();
  61. $condition[] = array('goodsvideo_id', 'in', $ids);
  62. $condition[] = array('store_id', '=', session('store_id'));
  63. $return = $goods_model->delGoodsVideo($condition);
  64. if ($return) {
  65. if ($return_json) {
  66. ds_json_encode(10000, lang('ds_common_op_succ'));
  67. } else {
  68. $this->success(lang('ds_common_op_succ'));
  69. }
  70. } else {
  71. if ($return_json) {
  72. ds_json_encode(10000, lang('ds_common_op_fail'));
  73. } else {
  74. $this->error(lang('ds_common_op_fail'));
  75. }
  76. }
  77. }
  78. /**
  79. * 上传视频
  80. */
  81. public function video_upload()
  82. {
  83. $store_id = session('store_id');
  84. $save_name = $store_id . '_' . date('YmdHis') . rand(10000, 99999) . '.mp4';
  85. $file_name = input('post.name');
  86. $upload_path = ATTACH_GOODS . DIRECTORY_SEPARATOR . $store_id;
  87. $res = ds_upload_pic($upload_path, $file_name, $save_name, 'mp4');
  88. if ($res['code']) {
  89. $save_name = $res['data']['file_name'];
  90. $data = array();
  91. $data['url'] = goods_video($save_name);
  92. $data['name'] = $save_name;
  93. $goods_model = model('goods');
  94. $goods_model->addGoodsVideo(array(
  95. 'store_id' => $store_id,
  96. 'store_name' => session('store_name'),
  97. 'goodsvideo_name' => $save_name,
  98. 'goodsvideo_add_time' => TIMESTAMP
  99. ));
  100. // 整理为json格式
  101. $output = json_encode($data);
  102. echo $output;
  103. exit();
  104. } else {
  105. echo json_encode(array('error' => $res['msg']));
  106. exit();
  107. }
  108. }
  109. /**
  110. * 用户中心右边,小导航
  111. *
  112. * @param string $menu_type 导航类型
  113. * @param string $menu_key 当前导航的menu_key
  114. * @return
  115. */
  116. function getSellerItemList()
  117. {
  118. $item_list = array(
  119. array(
  120. 'name' => 'index',
  121. 'text' => lang('seller_goodsvideo'),
  122. 'url' => (string) url('Sellervideo/index'),
  123. )
  124. );
  125. return $item_list;
  126. }
  127. }