LiveApply.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. /**
  3. * 商品管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. use TencentCloud\Common\Credential;
  10. use TencentCloud\Common\Profile\ClientProfile;
  11. use TencentCloud\Common\Profile\HttpProfile;
  12. use TencentCloud\Common\Exception\TencentCloudSDKException;
  13. use TencentCloud\Live\V20180801\LiveClient;
  14. use TencentCloud\Live\V20180801\Models\DropLiveStreamRequest;
  15. use TencentCloud\Live\V20180801\Models\DescribeLiveStreamStateRequest;
  16. use AlibabaCloud\Client\AlibabaCloud;
  17. /**
  18. * ============================================================================
  19. * DSKMS多用户商城
  20. * ============================================================================
  21. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  22. * 网站地址: https://www.valimart.net/
  23. * ----------------------------------------------------------------------------
  24. *
  25. * ============================================================================
  26. * 控制器
  27. */
  28. class LiveApply extends AdminControl {
  29. public function initialize() {
  30. parent::initialize();
  31. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/live_apply.lang.php');
  32. }
  33. /**
  34. * 商品管理
  35. */
  36. public function index() {
  37. /**
  38. * 查询条件
  39. */
  40. $condition = array();
  41. $store_model = model('store');
  42. if (config('ds_config.live_type') == 1) {
  43. $minipro_live_model = model('minipro_live');
  44. $minipro_live_list = $minipro_live_model->getMiniproLiveList($condition);
  45. $store_list = array();
  46. foreach ($minipro_live_list as $key => $val) {
  47. $minipro_live_list[$key]['minipro_live_image_url'] = ds_get_pic( ATTACH_MINIPRO_LIVE , $val['minipro_live_image']);
  48. if (!isset($store_list[$val['store_id']])) {
  49. $store_list[$val['store_id']] = $store_model->getStoreInfo(array('store_id' => $val['store_id']));
  50. }
  51. $minipro_live_list[$key]['store_name'] = $store_list[$val['store_id']]['store_name'] ? $store_list[$val['store_id']]['store_name'] : '';
  52. }
  53. View::assign('minipro_live_list', $minipro_live_list);
  54. View::assign('show_page', $minipro_live_model->page_info->render());
  55. } else {
  56. $live_apply_model = model('live_apply');
  57. $live_apply_state = input('param.live_apply_state');
  58. if (in_array($live_apply_state, array('0', '1', '2'))) {
  59. $condition[] = array('live_apply_state', '=', $live_apply_state);
  60. }
  61. $live_apply_list = $live_apply_model->getLiveApplyList($condition, '*', 10, 'live_apply_state asc,live_apply_id desc');
  62. $store_list = array();
  63. foreach ($live_apply_list as $key => $val) {
  64. if ($val['live_apply_cover_video']) {
  65. $live_apply_list[$key]['live_apply_cover_video_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'] , $val['live_apply_cover_video']);
  66. } elseif ($val['live_apply_cover_image']) {
  67. $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'] , $val['live_apply_cover_image']);
  68. } else {
  69. $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  70. }
  71. $live_apply_list[$key]['live_apply_user_name'] = '';
  72. switch ($val['live_apply_user_type']) {
  73. case 2:
  74. if (!isset($store_list[$val['live_apply_user_id']])) {
  75. $store_list[$val['live_apply_user_id']] = $store_model->getStoreInfo(array('store_id' => $val['live_apply_user_id']));
  76. }
  77. $live_apply_list[$key]['live_apply_user_name'] = $store_list[$val['live_apply_user_id']]['store_name'] ? $store_list[$val['live_apply_user_id']]['store_name'] : '';
  78. break;
  79. }
  80. }
  81. View::assign('live_apply_list', $live_apply_list);
  82. View::assign('show_page', $live_apply_model->page_info->render());
  83. }
  84. View::assign('search', $condition);
  85. $this->setAdminCurItem('index');
  86. return View::fetch();
  87. }
  88. /**
  89. * 删除商品
  90. */
  91. public function del() {
  92. $live_apply_id = input('param.live_apply_id');
  93. $live_apply_id_array = ds_delete_param($live_apply_id);
  94. if ($live_apply_id_array == FALSE) {
  95. ds_json_encode('10001', lang('ds_common_op_fail'));
  96. }
  97. $condition = array();
  98. $condition[] = array('live_apply_id', 'in', $live_apply_id_array);
  99. model('live_apply')->delLiveApply($condition);
  100. $this->log(lang('ds_del') . lang('live_apply') . ' ID:' . implode('、', $live_apply_id_array), 1);
  101. ds_json_encode('10000', lang('ds_common_op_succ'));
  102. }
  103. /**
  104. * 审核商品
  105. */
  106. public function view() {
  107. if (config('ds_config.live_type') == 1) {
  108. $minipro_live_id = input('param.minipro_live_id');
  109. $minipro_live_model = model('minipro_live');
  110. $minipro_live_info = $minipro_live_model->getMiniproLiveInfo(array(array('minipro_live_id', '=', $minipro_live_id)));
  111. if (!$minipro_live_info) {
  112. $this->error(lang('live_not_exist'));
  113. }
  114. $minipro_live_info['minipro_live_image_url'] = ds_get_pic( ATTACH_MINIPRO_LIVE , $minipro_live_info['minipro_live_image']);
  115. $minipro_live_room_goods_model = model('minipro_live_room_goods');
  116. $goods_list = $minipro_live_room_goods_model->getMiniproLiveRoomGoodsList(array(array('minipro_live_id', '=', $minipro_live_id)));
  117. foreach ($goods_list as $k => $v) {
  118. $goods_list[$k]['goods_image'] = goods_cthumb($v['goods_image']);
  119. }
  120. $minipro_live_info['goods_list'] = $goods_list;
  121. View::assign('live_apply_info', $minipro_live_info);
  122. echo View::fetch('view');
  123. } else {
  124. $live_apply_id = input('param.live_apply_id');
  125. $live_apply_model = model('live_apply');
  126. $live_apply_info = $live_apply_model->getLiveApplyInfo(array('live_apply_id' => $live_apply_id));
  127. if (!$live_apply_info) {
  128. $this->error(lang('live_not_exist'));
  129. }
  130. if (request()->isPost()) {
  131. $live_apply_model = model('live_apply');
  132. $data = array(
  133. 'live_apply_end_time' => strtotime(input('param.live_apply_end_time')),
  134. 'live_apply_video' => input('param.live_apply_video'),
  135. );
  136. if (!$data['live_apply_end_time']) {
  137. $this->error(lang('live_apply_end_time_empty'));
  138. }
  139. if ($live_apply_info['live_apply_state'] == 0) {
  140. if (intval(input('param.verify_state')) == 0) {
  141. $state = 2;
  142. $remark = input('param.verify_reason');
  143. if ($remark) {
  144. $store_ids = Db::name('live_apply')->where(array('live_apply_user_type' => 2, 'live_apply_id' => $live_apply_id))->column('live_apply_user_id');
  145. if ($store_ids) {
  146. $store_model = model('store');
  147. $store_list = $store_model->getStoreList(array(array('store_id', 'in', $store_ids)));
  148. if ($store_list) {
  149. foreach ($store_list as $store) {
  150. $param = array();
  151. $param['code'] = 'live_apply_verify';
  152. $param['store_id'] = $store['store_id'];
  153. $param['ali_param'] = array(
  154. 'remark' => $remark,
  155. 'live_apply_id' => $live_apply_id
  156. );
  157. $param['ten_param'] = array(
  158. $remark,
  159. $live_apply_id
  160. );
  161. $param['param'] = $param['ali_param'];
  162. $param['weixin_param'] = array(
  163. 'url' => config('ds_config.h5_store_site_url') . '/pages/seller/live_apply/LiveApplyList',
  164. 'data' => array(
  165. "keyword1" => array(
  166. "value" => $live_apply_info['live_apply_remark'],
  167. "color" => "#333"
  168. ),
  169. "keyword2" => array(
  170. "value" => $remark,
  171. "color" => "#333"
  172. )
  173. ),
  174. );
  175. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendStoremsg','cron_value'=>serialize($param)));
  176. }
  177. }
  178. }
  179. }
  180. } else {
  181. $state = 1;
  182. //生成小程序码
  183. $wechat_model = model('wechat');
  184. $wechat_model->getOneWxconfig();
  185. $a = $wechat_model->getMiniProCode($live_apply_id, 'pages/seller/live_apply/LiveApplyDetail');
  186. if (@imagecreatefromstring($a) == false) {
  187. $a = json_decode($a);
  188. $this->error(lang('live_minipro_code_fail') . lang('ds_colon') . $a->errmsg);
  189. } else {
  190. if (is_dir(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY) || (!is_dir(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY) && mkdir(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY, 0755, true))) {
  191. file_put_contents(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_LIVE_APPLY . DIRECTORY_SEPARATOR . $live_apply_id . '.png', $a);
  192. } else {
  193. $this->error(lang('live_minipro_code_fail') . lang('ds_colon') . lang('directory_no_right'));
  194. }
  195. }
  196. }
  197. $data['live_apply_state'] = $state;
  198. }
  199. $live_apply_model->editLiveApply($data, array('live_apply_id' => $live_apply_id));
  200. $this->log(lang('ds_verify') . lang('live_apply') . ' ID:' . $live_apply_id, 1);
  201. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  202. } else {
  203. //判断当前流状态
  204. $live_apply_info['active'] = false;
  205. if ($live_apply_info['live_apply_state'] == 1 && $live_apply_info['live_apply_end_time'] > TIMESTAMP) {
  206. if (config('ds_config.video_type') == 'aliyun') {
  207. if (!config('ds_config.aliyun_live_push_domain')) {
  208. ds_json_encode(10001, lang('aliyun_live_push_domain_empty'));
  209. }
  210. if (!config('ds_config.aliyun_live_push_key')) {
  211. ds_json_encode(10001, lang('aliyun_live_push_key_empty'));
  212. }
  213. if (!config('ds_config.aliyun_live_play_domain')) {
  214. ds_json_encode(10001, lang('aliyun_live_play_domain_empty'));
  215. }
  216. if (!config('ds_config.aliyun_live_play_key')) {
  217. ds_json_encode(10001, lang('aliyun_live_play_key_empty'));
  218. }
  219. $regionId = 'cn-shanghai';
  220. AlibabaCloud::accessKeyClient(config('ds_config.aliyun_access_key_id'), config('ds_config.aliyun_access_key_secret'))
  221. ->regionId($regionId)
  222. ->asDefaultClient();
  223. try {
  224. $result = AlibabaCloud::rpc()
  225. ->product('live')
  226. // ->scheme('https') // https | http
  227. ->version('2016-11-01')
  228. ->action('DescribeLiveStreamsOnlineList')
  229. ->method('POST')
  230. ->host('live.aliyuncs.com')
  231. ->options([
  232. 'query' => [
  233. 'RegionId' => $regionId,
  234. 'DomainName' => config('ds_config.aliyun_live_push_domain'),
  235. 'AppName' => "live",
  236. 'StreamName' => 'live_apply_' . $live_apply_info['live_apply_id'],
  237. 'PageSize' => "1",
  238. 'PageNum' => "1",
  239. 'QueryType' => "strict",
  240. ],
  241. ])
  242. ->request();
  243. if ($result->TotalNum) {
  244. $live_apply_info['active'] = true;
  245. //生成播放地址
  246. $live_apply_info['live_apply_play_url'] = model('live_apply')->getPlayUrl('live_apply_' . $live_apply_info['live_apply_id'], $live_apply_info['live_apply_end_time']);
  247. }
  248. } catch (\Exception $e) {
  249. }
  250. } else {
  251. if (!config('ds_config.live_push_domain')) {
  252. $this->error(lang('live_push_domain_empty'));
  253. }
  254. if (!config('ds_config.live_push_key')) {
  255. $this->error(lang('live_push_key_empty'));
  256. }
  257. if (!config('ds_config.live_play_domain')) {
  258. $this->error(lang('live_play_domain_empty'));
  259. }
  260. try {
  261. $cred = new Credential(config('ds_config.vod_tencent_secret_id'), config('ds_config.vod_tencent_secret_key'));
  262. $httpProfile = new HttpProfile();
  263. $httpProfile->setEndpoint("live.tencentcloudapi.com");
  264. $clientProfile = new ClientProfile();
  265. $clientProfile->setHttpProfile($httpProfile);
  266. $client = new LiveClient($cred, "", $clientProfile);
  267. $req = new DescribeLiveStreamStateRequest();
  268. $params = '{"AppName":"live","DomainName":"' . config('ds_config.live_push_domain') . '","StreamName":"' . 'live_apply_' . $live_apply_info['live_apply_id'] . '"}';
  269. $req->fromJsonString($params);
  270. $resp = $client->DescribeLiveStreamState($req);
  271. } catch (TencentCloudSDKException $e) {
  272. $this->error($e->getMessage());
  273. }
  274. if ($resp->StreamState == 'active') {
  275. $live_apply_info['active'] = true;
  276. //生成播放地址
  277. $live_apply_info['live_apply_play_url'] = model('live_apply')->getPlayUrl('live_apply_' . $live_apply_info['live_apply_id'], $live_apply_info['live_apply_end_time']);
  278. }
  279. }
  280. }
  281. if ($live_apply_info['live_apply_cover_video']) {
  282. $live_apply_info['live_apply_cover_video_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $live_apply_info['live_apply_user_id'] , $live_apply_info['live_apply_cover_video']);
  283. } elseif ($live_apply_info['live_apply_cover_image']) {
  284. $live_apply_info['live_apply_cover_image_url'] = ds_get_pic( ATTACH_LIVE_APPLY . '/' . $live_apply_info['live_apply_user_id'] , $live_apply_info['live_apply_cover_image']);
  285. } else {
  286. $live_apply_info['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  287. }
  288. $goods_commonid = Db::name('live_apply_goods')->where('live_apply_id', $live_apply_info['live_apply_id'])->column('goods_commonid');
  289. $goods_model = model('goods');
  290. if (!empty($goods_commonid)) {
  291. $goods_list = $goods_model->getGoodsUnionList(array(array('goodscommon.goods_commonid', 'in', $goods_commonid)), 'goods_id,goodscommon.goods_name,goodscommon.goods_image,goodscommon.goods_price');
  292. foreach ($goods_list as $k => $v) {
  293. $goods_list[$k]['goods_image'] = goods_cthumb($v['goods_image']);
  294. }
  295. $live_apply_info['goods_list'] = $goods_list;
  296. } else {
  297. $live_apply_info['goods_list'] = array();
  298. }
  299. View::assign('live_apply_info', $live_apply_info);
  300. echo View::fetch('view');
  301. }
  302. }
  303. }
  304. public function close() {
  305. $live_apply_id = input('param.live_apply_id');
  306. $live_apply_model = model('live_apply');
  307. $live_apply = $live_apply_model->getLiveApplyInfo(array('live_apply_id' => $live_apply_id));
  308. if (!$live_apply) {
  309. ds_json_encode(10001, lang('live_not_exist'));
  310. }
  311. if (config('ds_config.video_type') == 'aliyun') {
  312. $regionId = 'cn-shanghai';
  313. AlibabaCloud::accessKeyClient(config('ds_config.aliyun_access_key_id'), config('ds_config.aliyun_access_key_secret'))
  314. ->regionId($regionId)
  315. ->asDefaultClient();
  316. try {
  317. $result = AlibabaCloud::rpc()
  318. ->product('live')
  319. // ->scheme('https') // https | http
  320. ->version('2016-11-01')
  321. ->action('ForbidLiveStream')
  322. ->method('POST')
  323. ->host('live.aliyuncs.com')
  324. ->options([
  325. 'query' => [
  326. 'RegionId' => $regionId,
  327. 'AppName' => "live",
  328. 'StreamName' => 'live_apply_' . $live_apply['live_apply_id'],
  329. 'LiveStreamType' => "publisher",
  330. 'DomainName' => config('ds_config.aliyun_live_push_domain'),
  331. ],
  332. ])
  333. ->request();
  334. } catch (\Exception $e) {
  335. ds_json_encode(10001, $e->getMessage());
  336. }
  337. } else {
  338. try {
  339. $cred = new Credential(config('ds_config.vod_tencent_secret_id'), config('ds_config.vod_tencent_secret_key'));
  340. $httpProfile = new HttpProfile();
  341. $httpProfile->setEndpoint("live.tencentcloudapi.com");
  342. $clientProfile = new ClientProfile();
  343. $clientProfile->setHttpProfile($httpProfile);
  344. $client = new LiveClient($cred, "", $clientProfile);
  345. $req = new DropLiveStreamRequest();
  346. $params = '{"AppName":"live","DomainName":"' . config('ds_config.live_push_domain') . '","StreamName":"' . 'live_apply_' . $live_apply['live_apply_id'] . '"}';
  347. $req->fromJsonString($params);
  348. $resp = $client->DropLiveStream($req);
  349. } catch (TencentCloudSDKException $e) {
  350. ds_json_encode(10001, $e->getMessage());
  351. }
  352. }
  353. $this->log(lang('live_cut_off') . ' ID:' . $live_apply_id, 1);
  354. ds_json_encode(10000, lang('ds_common_op_succ'));
  355. }
  356. /**
  357. * 获取卖家栏目列表,针对控制器下的栏目
  358. */
  359. protected function getAdminItemList() {
  360. $menu_array = array(
  361. array(
  362. 'name' => 'index',
  363. 'text' => lang('ds_list'),
  364. 'url' => url('LiveApply/index')
  365. ),
  366. );
  367. return $menu_array;
  368. }
  369. }
  370. ?>