Commit bca278e3 authored by hujun's avatar hujun

download

parent 4e9d3f1f
...@@ -179,4 +179,15 @@ class AliYunSecretReport extends BaseModel ...@@ -179,4 +179,15 @@ class AliYunSecretReport extends BaseModel
->where($where) ->where($where)
->find(); ->find();
} }
/**
* @param $data
* @param $where
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function updateData($data, $where) {
return $this->where($where)->update($data);
}
} }
\ No newline at end of file
...@@ -28,11 +28,28 @@ class AliyunVoiceDown extends BaseModel ...@@ -28,11 +28,28 @@ class AliyunVoiceDown extends BaseModel
/** /**
* @param $data * @param $data
* @param $where
* @return int|string * @return int|string
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function updateData($data) { public function updateData($data, $where) {
return $this->db_->update($data); return $this->db_->where($where)->update($data);
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListAll($field, $where = [])
{
$where['is_del'] = 0;
return $this->field($field)
->where($where)
->select();
} }
} }
\ No newline at end of file
...@@ -733,28 +733,66 @@ class PrivacyNumber ...@@ -733,28 +733,66 @@ class PrivacyNumber
/** /**
* 更新已下载 * 更新已下载
*
* @return int|Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\View|\think\response\Xml
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/ */
public function updateDownVoiceId() { public function updateDownVoiceId()
{
$params = Request::instance()->param(); $params = Request::instance()->param();
if (!in_array($params['source'], [1,2])) { if (!in_array($params['source'], [1, 2])) {
return Response::create(['code'=>101, 'msg'=>'参数错误'], 'json'); return Response::create(['code' => 101, 'msg' => '参数错误'], 'json');
}
if (empty($params['params'])) {
return Response::create(['code' => 101, 'msg' => '参数错误'], 'json');
}
$data_array = json_decode($params['params'], true);
$num = count($data_array);
$limit_num = round($num / 10);
$count = 0;
$update_id_array = [];
$update_data['is_down'] = $save_data['record_down'] = $params['source'];
for ($i = 0; $i < $num; $i++) {
$tmp_id_array[] = $data_array[$i]['id'];
$voice_file[$data_array[$i]['id']] = $data_array[$i]['voice_file']; //组装文件路径
if ($count == $limit_num) {
$voice_data = $this->m_down->getListAll('id,call_id,call_time,voice_file,type', ['id' => ['in', $tmp_id_array]]);
if (empty($voice_data)) {
continue;
}
foreach ($voice_data as $k => $v) {
$update_id_array[$k] = $v['id'];
$where['call_id'] = $v['call_id'];
if ($v['type'] == 1) {
$where['call_time'] = $v['call_time']; //阿里云录音
} }
$id_array = explode(',', $params['id']); if ($params['source'] == 1) {
$update_data['is_down'] = $params['source']; $save_data['voice_file'] = $update_data['voice_file'] = $voice_file[$v['id']];
foreach ($id_array as $k=>$v) { }
$update_data['id'] = $v; $this->m_secret_report->updateData($save_data, $where);
$this->m_down->updateData($update_data); $this->m_down->updateData($update_data, ['id' => $v['id']]); //更新下载状态
} }
$tmp_id_array = $update_id_array = [];
$count = 0;
}
$count++;
}
return $num;
} }
/** /**
* getDownVoiceParams -> downVoiceByParams -> updateDownVoiceId * getDownVoiceParams -> downVoiceByParams -> updateDownVoiceId
* 获取下载参数->开始下载->更新数据库已下载 * 获取下载参数->开始下载->更新数据库已下载
* *
* @return Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\View|\think\response\Xml|void * @return Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\View|\think\response\Xml
* @throws \think\Exception
* @throws \think\exception\PDOException
*/ */
public function downVoiceByParams() public function downVoiceByParams()
{ {
...@@ -765,6 +803,7 @@ class PrivacyNumber ...@@ -765,6 +803,7 @@ class PrivacyNumber
} }
$base_url = 'https://api.tonglianjituan.com/task/'; $base_url = 'https://api.tonglianjituan.com/task/';
// $base_url = 'https://pre2.tonglianjituan.com/task/';
$url = $base_url .'getDownVoiceParams?source='.$params['source']; $url = $base_url .'getDownVoiceParams?source='.$params['source'];
$get_params = curl_get($url); $get_params = curl_get($url);
$data = json_decode($get_params,true); $data = json_decode($get_params,true);
...@@ -772,7 +811,7 @@ class PrivacyNumber ...@@ -772,7 +811,7 @@ class PrivacyNumber
return Response::create(['code'=>101, 'msg'=>'获取数据错误'], 'json'); return Response::create(['code'=>101, 'msg'=>'获取数据错误'], 'json');
} }
$save_path = ''; $save_path = '';
$update_id = []; $update_data = [];
foreach ($data['data'] as $k => $v) { foreach ($data['data'] as $k => $v) {
$create_time = date('Y-m-d', strtotime($v['call_time'])); $create_time = date('Y-m-d', strtotime($v['call_time']));
switch ($v['type']) { switch ($v['type']) {
...@@ -811,16 +850,21 @@ class PrivacyNumber ...@@ -811,16 +850,21 @@ class PrivacyNumber
} }
if (file_exists(PHONE_VOICE.'/'.$save_path)) { if (file_exists(PHONE_VOICE.'/'.$save_path)) {
$update_id[] = $v['id']; $update_data[] = [
$this->m_down->updateData(['id'=>$v['id'], 'voice_file'=>$save_path]); 'id'=>$v['id'],
'voice_file'=>$save_path
];
} }
} }
$result = 0;
if ($update_data) {
$update_data = json_encode($update_data);
//更新下载 //更新下载
$id_string = implode(',', $update_id); $url = $base_url .'updateDownVoiceId';
$url = $base_url .'updateDownVoiceId?id='.$id_string.'&source='.$params['source']; $result = curl_post($url, ['params'=>$update_data, 'source'=>$params['source']], 10);
curl_post($url, ['id'=>$id_string, 'source'=>$params['source']], 30000); }
return ; return Response::create(['code'=>200, 'msg'=>'修改数量'.$result], 'json');
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment