Tool.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace catchAdmin\api\controller;
  3. use catchAdmin\hydraulic\model\maintenancemapper;
  4. use catchAdmin\hydraulic\model\Wrench as ModelWrench;
  5. use catcher\base\CatchRequest as Request;
  6. use catcher\CatchResponse;
  7. use catcher\base\CatchController;
  8. use PhpParser\Node\Expr\FuncCall;
  9. use think\facade\Db;
  10. use Wrench;
  11. class Tool extends Base
  12. {
  13. /**
  14. * @Descripttion: 下发设备 携带的参数 imei号 版本号
  15. * @name: likang
  16. * @return {*}
  17. */
  18. public function Issued()
  19. {
  20. //校验imei是否存在
  21. if (!isset($_GET['imei']) || $_GET['imei'] == '') {
  22. json_fail('缺少设备IMEI号参数');
  23. }
  24. $Imei = $_GET['imei'];
  25. if (!isset($_GET['version']) || $_GET['version'] == '') {
  26. json_fail('缺少版本号参数', '', $Imei);
  27. }
  28. $version = $_GET['version'];
  29. return $this->DataIssued($Imei, $version);
  30. }
  31. //收到的数据
  32. public function receive()
  33. {
  34. //校验imei是否存在
  35. $where = [];
  36. if (!isset($_POST['imei']) || $_POST['imei'] == '') {
  37. json_fail('缺少设备IMEI号参数');
  38. }
  39. $Imei = $_POST['imei'];
  40. if (!isset($_POST['version']) || $_POST['version'] == '') {
  41. json_fail('缺少版本号参数', '', $Imei);
  42. }
  43. $version = $_POST['version'];
  44. if (!isset($_POST['Succ']) || $_POST['Succ'] == '') {
  45. json_fail('缺少返回结果', '', $Imei);
  46. }
  47. $Succ = $_POST['Succ'];
  48. if (!isset($_POST['Extra'])) {
  49. json_fail('缺少回复内容参数', '', $Imei);
  50. }
  51. $Extra = $_POST['Extra'];
  52. $where[] = ['PublishVersion', '=', $version];
  53. $where[] = ['Imei', '=', $Imei];
  54. $ack = Db::name("publish_ack")->where($where)->find();
  55. if (!$ack) {
  56. json_fail('没有找到下发记录', '', $Imei);
  57. }
  58. $data = [
  59. 'Succ' => $Succ,
  60. 'AckTime' => msectime(),
  61. 'Extra' => $Extra
  62. ];
  63. Db::name("publish_ack")->where($where)->update($data);
  64. return $this->DataIssued($Imei, $version);
  65. }
  66. /**
  67. * @Descripttion: 数据处理
  68. * @name: likang
  69. * @return {*}
  70. */
  71. private function DataIssued($Imei, $version)
  72. {
  73. $where1 = [
  74. // ['Imei', '<>', $Imei],
  75. ['Version', '>', $version]
  76. ];
  77. $where2 = [
  78. ['Imei', '=', $Imei],
  79. ['ContentType', '=', 'File'],
  80. ['Version', '>', $version]
  81. ];
  82. $list = Db::name('publish')
  83. ->whereOr([$where1, $where2])
  84. //->where($where1)
  85. ->order('Version asc')->limit(5)->select();
  86. foreach ($list as $key => $value) {
  87. $da = json_decode($value['Content'], true);
  88. $da['id'] = strval($da['id']);
  89. $content[] = [
  90. 'OpType' => $value['Type'],
  91. 'CntType' => $value['ContentType'],
  92. 'CntVersion' => strval($value['Version']),
  93. 'id' => strval($value['ContentId']),
  94. 'Content' => $da
  95. ];
  96. $CntVersion = strval($value['Version']);
  97. }
  98. //保存下发的记录
  99. $ack = [
  100. 'PublishVersion' => $CntVersion,
  101. 'PublishContent' => json_encode($content),
  102. 'Imei' => $Imei,
  103. 'AddTime' => msectime()
  104. ];
  105. Db::name('publish_ack')->save($ack);
  106. return json_success('获取成功', $content, $Imei);
  107. }
  108. }