| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\adopt\models\client;
- use app\librarys\YsOpen\YsClient;
- use app\plugins\adopt\models\AdoptGoodsDevice;
- use app\models\Goods;
- use app\models\GoodsCat;
- use app\plugins\adopt\models\AdoptCat;
- use app\plugins\adopt\models\AdoptSetting;
- use app\plugins\adopt\models\Monitor;
- use yii\base\Model;
- use yii\data\Pagination;
- class DeviceForm extends Model
- {
- public $cat_id;// 分类ID
- public $page;
- public $limit = 10;
- public $store_id;
- public $device_id;
- /**
- * 获取监控列表
- * @return array
- */
- public function search(){
- // 先获取所有的分类
- $catList = AdoptCat::find()->where([
- 'store_id' => $this->store_id,
- 'is_show'=> 1,
- 'is_delete' => 0
- ])->orderBy('sort DESC')->all();
- if($this->cat_id == 0){
- $goodsIdArray = Goods::find()->where([
- 'product_type' => Goods::GOODS_TYPE_ADOPT,
- 'status' => 1,
- 'is_delete' => 0,
- 'store_id' => $this->store_id
- ])->select('id')->orderBy('sort ASC')->column();
- }else{
- $goodsIdArray = GoodsCat::find()->where([
- 'is_delete' => 0,
- 'cat_id' => $this->cat_id,
- 'store_id' => $this->store_id
- ])->select('goods_id')->column();
- }
- // 获取设备ID列表
- $deviceId = AdoptGoodsDevice::find()->where(['in','goods_id',$goodsIdArray])->andWhere(['is_delete'=>0,'store_id'=>$this->store_id])->select(['device_id'])->column();
- $queryList = Monitor::find()->where(['in','id',$deviceId]);
- $count = $queryList->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit, 'page' => $this->page - 1]);
- $list = $queryList->orderBy('status DESC')->limit($pagination->limit)
- ->offset($pagination->offset)
- ->asArray()->all();
- foreach($list as &$item){
- if(empty($item['cover_pic'])){
- $item['cover_pic'] = \Yii::$app->request->hostInfo .'/web/v1/static/images/device.png';
- }
- }
- return ['code'=>0,'data'=>[
- 'cat_list' => $catList,
- 'list' => $list
- ]];
- }
- public function getPlayUrl(){
- if(!$this->device_id || $this->device_id == 'undefined'){
- return [
- 'code'=>1,
- 'msg'=>'请选择要播放的设备'
- ];
- }
- // 获取萤石配置
- $setting = AdoptSetting::findOne(['store_id'=>$this->store_id]);
- if(!$setting->ys_app_key || !$setting->ys_secret){
- return ['code'=>1,'msg'=>'未设置萤石信息'];
- }
- $ysOpen = new YsClient($setting->ys_app_key,$setting->ys_secret);
- $getAccessTokenResult = $ysOpen->getAccessToken();
- if(false == $getAccessTokenResult){
- return ['code'=>1,'msg'=>"萤石账号有误"];
- }
- $monitorInfo = Monitor::findOne($this->device_id);
- $source = $monitorInfo->serial;//.":1"
- $result = $ysOpen->getAddress($source);
- // if (!$result['data'][0]['hlsHd']) {
- // debug_log($result['data']);
- // return [
- // 'code'=>1,
- // 'msg'=>'获取播放地址失败'
- // ];
- // }
- if ($result['code'] != 200) {
- return [
- 'code'=>1,
- 'msg'=>'获取播放地址失败'
- ];
- }
- return ['code'=>0,'data'=>['url' => $result['data']['url'],'token' => $getAccessTokenResult]];
- }
- }
|