123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- class Video extends Backend
- {
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Video;
- $this->view->assign("isPayList", $this->model->getIsPayList());
- $this->view->assign("statusList", $this->model->getStatusList());
- }
-
-
- public function index()
- {
-
- $this->relationSearch = true;
-
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
-
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with(['type'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
-
- $row->getRelation('type')->visible(['type','name']);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
-
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- $params = $this->preExcludeFields($params);
- if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- $result = false;
- Db::startTrans();
- try {
-
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
- $this->model->validateFailException(true)->validate($validate);
- }
- $result = $this->model->allowField(true)->save($params);
- $id = $this->model->id;
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
-
- $cspid = config('cspid');
- $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
- $videofile = $params['videofile'];
- $videofile = explode('/', $videofile);
- $video_url = $videofile[4];
- $data = [
- 'cpAlbumId' => $id,
- 'albumName' => $params['title'],
- 'tvSets' => 1,
- 'updateToSet' => 1,
- 'isPurchase' => $params['is_pay'],
- 'isEffective' => $params['status'],
- 'isOnline' => $params['status'],
- 'albumTypes' => '健康',
- 'picBox' => config('upload.cdnurl') . $params['image'],
- 'albumUpdateTime' => date('YmdHis', time()),
- 'albumCreateTime' => date('YmdHis', time()),
- 'tvlist' => [
- [
- 'cpAlbumId' => $id,
- 'cpTvId' => $id,
- 'tvName' => $params['title'],
- 'tvIsEffective' => $params['status'],
- 'tvIsOnline' => $params['status'],
- 'isPurchase' => $params['is_pay'],
- 'playOrder' => 1,
- 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$video_url
- ]
- ]
- ];
- $data = json_encode($data, 320);
- $header = [
- 'Content-Type: application/json'
- ];
- $rs = httpRequest($url, 'POST', $data, $header);
- if ($rs) {
- $rs = json_decode($rs, true);
- if ($rs['code'] == 'A000000') {
- Db::name('video')->where(['id' => $id])->setField('inject_status', 1);
- }
- }
- $this->success();
- } else {
- $this->error(__('No rows were inserted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- return $this->view->fetch();
- }
-
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- $params = $this->preExcludeFields($params);
- $result = false;
- Db::startTrans();
- try {
-
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException(true)->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
-
- $cspid = config('cspid');
- $url = 'http://jscp.agency.gitv.tv/epgDataSync/v1/' . $cspid . '/';
- $videofile = $params['videofile'];
- $videofile = explode('/', $videofile);
- $video_url = $videofile[4];
- $data = [
- 'cpAlbumId' => $ids,
- 'albumName' => $params['title'],
- 'tvSets' => 1,
- 'updateToSet' => 1,
- 'isPurchase' => $params['is_pay'],
- 'isEffective' => $params['status'],
- 'isOnline' => $params['status'],
- 'albumTypes' => '健康',
- 'picBox' => config('upload.cdnurl') . $params['image'],
- 'albumUpdateTime' => date('YmdHis', time()),
- 'tvlist' => [
- [
- 'cpAlbumId' => $ids,
- 'cpTvId' => $ids,
- 'tvName' => $params['title'],
- 'tvIsEffective' => $params['status'],
- 'tvIsOnline' => $params['status'],
- 'isPurchase' => $params['is_pay'],
- 'playOrder' => 1,
- 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$video_url
- ]
- ]
- ];
- $data = json_encode($data, 320);
- $header = [
- 'Content-Type: application/json'
- ];
- $rs = httpRequest($url, 'POST', $data, $header);
- if ($rs) {
- $rs = json_decode($rs, true);
- if ($rs['code'] == 'A000000') {
- Db::name('video')->where(['id' => $ids])->setField('inject_status', 1);
- }
- }
- $this->success();
- } else {
- $this->error(__('No rows were updated'));
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
-
- public function del($ids = "")
- {
- if (!$this->request->isPost()) {
- $this->error(__("Invalid parameters"));
- }
- $ids = $ids ? $ids : $this->request->post("ids");
- $params = Db::name('video')->find($ids);
- if (!$params) {
- $this->success();
- }
- Db::startTrans();
- $rt = Db::name('video')->delete($ids);
- if (!$rt) {
- Db::rollback();
- $this->error('删除失败');
- }
-
- $cspid = config('cspid');
- $url = 'http://jscp.agency.gitv.tv/epgDeleteSync/v1/' . $cspid . '/';
- $data = [
- 'cpAlbumId' => $ids,
- 'albumName' => $params['title'],
- 'tvSets' => 1,
- 'updateToSet' => 1,
- 'isPurchase' => $params['is_pay'],
- 'isEffective' => 0,
- 'isOnline' => 2,
- 'albumTypes' => '健康',
- 'picBox' => config('upload.cdnurl') . $params['image'],
- 'albumUpdateTime' => date('YmdHis', time()),
- 'tvlist' => [
- [
- 'cpAlbumId' => $ids,
- 'cpTvId' => $ids,
- 'tvName' => $params['title'],
- 'tvIsEffective' => 0,
- 'tvIsOnline' => 2,
- 'isPurchase' => $params['is_pay'],
- 'playOrder' => 1,
- 'tvUrl' => 'ftp://'.config('ftp_user').':'.config('ftp_pwd').'@'.config('ftp_ip').':'.config('ftp_port').'/'.$params['title'].'.mp4'
- ]
- ]
- ];
- $data = json_encode($data, 320);
- $header = [
- 'Content-Type: application/json'
- ];
- $rs = httpRequest($url, 'POST', $data, $header);
- if (!$rs) {
- Db::rollback();
- $this->error('删除失败');
- }
- $rs = json_decode($rs, true);
- if ($rs['code'] != 'A000000') {
- Db::rollback();
- $this->error('删除失败');
- }
- Db::commit();
- $this->success();
- }
- }
|