IdentifyIdotModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * IdentifyIdotModel.php UTF-8
  4. * http://doc.huosdk.com/web/#/170?page_id=10981
  5. * 实名信息在线时长统计 idot:id_card_online_time
  6. *
  7. * @date : 2019/11/29 16:11
  8. *
  9. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  10. * @author : chenbingling <cbl@huosdk.com>
  11. * @version : HUOSDK 8.5
  12. */
  13. namespace huoIdentify\model;
  14. use huo\model\common\CommonModel;
  15. class IdentifyIdotModel extends CommonModel {
  16. protected $name = 'identify_idot';
  17. protected $pk = 'id';
  18. /* 开启自动写入时间戳字段 */
  19. protected $autoWriteTimestamp = true;
  20. /**
  21. * 添加数据
  22. *
  23. * @param array $data 需要添加的数据
  24. *
  25. * @return false|int 添加失败返回 false 添加成功 返回添加的ID
  26. */
  27. public function addData($data) {
  28. $_data = $data;
  29. $_id = parent::addData($_data);
  30. if (false === $_id) {
  31. return false;
  32. }
  33. return $_id;
  34. }
  35. /**
  36. * 通过ID获取信息
  37. *
  38. * @param int $id 主键ID
  39. *
  40. * @return array
  41. */
  42. public function getInfoById($id) {
  43. $_data = parent::getInfoById($id);
  44. if (empty($_data)) {
  45. return [];
  46. }
  47. return $_data;
  48. }
  49. /**
  50. * 更新单条数据
  51. *
  52. * @param array $data 数据
  53. * @param int $id ID
  54. *
  55. * @return bool
  56. */
  57. public function updateData($data, $id) {
  58. $_map[$this->pk] = $id;
  59. $_data = $data;
  60. $_rs = $this->allowField(true)->isUpdate(true)->save($_data, $_map);
  61. if (false === $_rs) {
  62. return false;
  63. }
  64. return true;
  65. }
  66. /**
  67. * 删除单条数据
  68. *
  69. * @param int $id ID
  70. * @param bool $is_complete 是否完成删除
  71. *
  72. * @return bool
  73. */
  74. public function deleteData($id, $is_complete = true) {
  75. return true;
  76. $_rs = parent::deleteData($id, $is_complete);
  77. if (false == $_rs) {
  78. return false;
  79. }
  80. return $_rs;
  81. }
  82. /**
  83. * 根据id_card获取数据
  84. *
  85. * @param string $id_card 证件号
  86. *
  87. * @return array
  88. */
  89. public function getInfoByIdCard($id_card) {
  90. $_map = [
  91. 'id_card' => $id_card
  92. ];
  93. $_info = $this->useGlobalScope(false)->where($_map)->find();
  94. if (false === $_info) {
  95. return [];
  96. }
  97. if (is_object($_info)) {
  98. return $_info->toArray();
  99. }
  100. return $_info;
  101. }
  102. /**
  103. * 根据id_card更新数据
  104. *
  105. * @param array $data 更新数据
  106. * @param string $id_card 证件号
  107. *
  108. * @return bool
  109. */
  110. public function updateByIdCard($data, $id_card) {
  111. $_map['id_card'] = $id_card;
  112. $_data = $data;
  113. $_model = new static();
  114. $_rs = $_model->allowField(true)->isUpdate(true)->save($_data, $_map);
  115. if (false === $_rs) {
  116. return false;
  117. }
  118. return true;
  119. }
  120. }