DataIssued($Imei, $version); } //收到的数据 public function receive() { //校验imei是否存在 $where = []; if (!isset($_POST['imei']) || $_POST['imei'] == '') { json_fail('缺少设备IMEI号参数'); } $Imei = $_POST['imei']; if (!isset($_POST['version']) || $_POST['version'] == '') { json_fail('缺少版本号参数', '', $Imei); } $version = $_POST['version']; if (!isset($_POST['Succ']) || $_POST['Succ'] == '') { json_fail('缺少返回结果', '', $Imei); } $Succ = $_POST['Succ']; if (!isset($_POST['Extra'])) { json_fail('缺少回复内容参数', '', $Imei); } $Extra = $_POST['Extra']; $where[] = ['PublishVersion', '=', $version]; $where[] = ['Imei', '=', $Imei]; $ack = Db::name("publish_ack")->where($where)->find(); if (!$ack) { json_fail('没有找到下发记录', '', $Imei); } $data = [ 'Succ' => $Succ, 'AckTime' => msectime(), 'Extra' => $Extra ]; Db::name("publish_ack")->where($where)->update($data); return $this->DataIssued($Imei, $version); } /** * @Descripttion: 数据处理 * @name: likang * @return {*} */ private function DataIssued($Imei, $version) { $where1 = [ // ['Imei', '<>', $Imei], ['Version', '>', $version] ]; $where2 = [ ['Imei', '=', $Imei], ['ContentType', '=', 'File'], ['Version', '>', $version] ]; $list = Db::name('publish') ->whereOr([$where1, $where2]) //->where($where1) ->order('Version asc')->limit(5)->select(); foreach ($list as $key => $value) { $da = json_decode($value['Content'], true); $da['id'] = strval($da['id']); $content[] = [ 'OpType' => $value['Type'], 'CntType' => $value['ContentType'], 'CntVersion' => strval($value['Version']), 'id' => strval($value['ContentId']), 'Content' => $da ]; $CntVersion = strval($value['Version']); } //保存下发的记录 $ack = [ 'PublishVersion' => $CntVersion, 'PublishContent' => json_encode($content), 'Imei' => $Imei, 'AddTime' => msectime() ]; Db::name('publish_ack')->save($ack); return json_success('获取成功', $content, $Imei); } }