123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace catchAdmin\api\controller;
- use catchAdmin\hydraulic\model\maintenancemapper;
- use catchAdmin\hydraulic\model\Wrench as ModelWrench;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use PhpParser\Node\Expr\FuncCall;
- use think\facade\Db;
- use Wrench;
- class Tool extends Base
- {
- /**
- * @Descripttion: 下发设备 携带的参数 imei号 版本号
- * @name: likang
- * @return {*}
- */
- public function Issued()
- {
- //校验imei是否存在
- if (!isset($_GET['imei']) || $_GET['imei'] == '') {
- json_fail('缺少设备IMEI号参数');
- }
- $Imei = $_GET['imei'];
- if (!isset($_GET['version']) || $_GET['version'] == '') {
- json_fail('缺少版本号参数', '', $Imei);
- }
- $version = $_GET['version'];
- return $this->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);
- }
- }
|