WechatQrcodeDao.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\wechat;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\wechat\WechatQrcode;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. use think\Model;
  19. /**
  20. * Class WechatQrcodeDao
  21. * @package app\common\dao\wechat
  22. * @author xaboy
  23. * @day 2020-04-28
  24. */
  25. class WechatQrcodeDao extends BaseDao
  26. {
  27. /**
  28. * @return BaseModel
  29. * @author xaboy
  30. * @day 2020-03-30
  31. */
  32. protected function getModel(): string
  33. {
  34. return WechatQrcode::class;
  35. }
  36. /**
  37. * 通过二维码票号查询微信二维码信息。
  38. *
  39. * 本函数旨在通过微信二维码的票号,从数据库中检索对应的二维码信息。
  40. * 这对于需要根据二维码票号进行特定操作的场景非常有用,比如验证入场券的有效性。
  41. *
  42. * @param string $ticket 二维码票号,用于查询数据库。
  43. * @return array|false 返回匹配的二维码信息数组,如果未找到则返回false。
  44. */
  45. public function ticketByQrcode($ticket)
  46. {
  47. // 使用WechatQrcode类的数据库访问对象,根据ticket查询数据库,返回找到的第一条记录。
  48. return WechatQrcode::getDB()->where('ticket', $ticket)->find();
  49. }
  50. /**
  51. * 获取永久二维码信息
  52. *
  53. * 本函数用于查询微信公众号永久二维码的相关信息。通过传入类型和标识符,定位到特定的二维码记录。
  54. * 永久二维码的特点是其有效期为0,意味着一旦生成,将一直有效。
  55. *
  56. * @param string $type 二维码类型标识,用于区分不同类型的二维码。
  57. * @param int $id 与二维码相关联的标识符,用于唯一标识某个特定的二维码。
  58. * @return object 返回符合查询条件的二维码信息对象,如果未找到则返回null。
  59. */
  60. public function getForeverQrcode($type, $id)
  61. {
  62. // 构建查询条件,查询third_id为$id,third_type为$type,且expire_seconds为0(表示永久有效)的二维码记录
  63. return WechatQrcode::getDB()->where('third_id', $id)->where('third_type', $type)->where('expire_seconds', 0)->find();
  64. }
  65. /**
  66. * 根据类型和ID获取临时二维码信息
  67. *
  68. * 本函数用于从数据库中检索指定类型和ID对应的临时二维码信息。
  69. * 临时二维码是具有过期时间的,本函数只会返回未过期的二维码记录。
  70. *
  71. * @param string $type 二维码类型标识
  72. * @param int $id 与二维码相关的ID,用于标识特定的二维码
  73. * @return object|null 返回符合查询条件的临时二维码对象,如果未找到则返回null
  74. */
  75. public function getTemporaryQrcode($type, $id)
  76. {
  77. // 通过WechatQrcode的数据库访问对象执行查询
  78. // 查询条件为third_id为$id,third_type为$type,且expire_seconds大于0(表示未过期)
  79. return WechatQrcode::getDB()->where('third_id', $id)->where('third_type', $type)->where('expire_seconds', '>', 0)->find();
  80. }
  81. }