RoutineQrcodeDao.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\common\dao\wechat;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\wechat\RoutineQrcode;
  6. class RoutineQrcodeDao extends BaseDao
  7. {
  8. protected function getModel(): string
  9. {
  10. return RoutineQrcode::class;
  11. }
  12. /**
  13. * TODO 添加二维码 存在直接获取
  14. * @param int $thirdId
  15. * @param string $thirdType
  16. * @param string $page
  17. * @param string $qrCodeLink
  18. * @return array|false|object|\PDOStatement|string|\think\Model
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\DbException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. */
  23. public function routineQrCodeForever($thirdId = 0, $thirdType = 'spread', $page = '', $qrCodeLink = '')
  24. {
  25. $count = RoutineQrcode::where('third_id', $thirdId)->where('third_type', $thirdType)->count();
  26. if ($count) return RoutineQrcode::where('third_id', $thirdId)->where('third_type', $thirdType)->field('routine_qrcode_id')->find();
  27. return $this->setRoutineQrcodeForever($thirdId, $thirdType, $page, $qrCodeLink);
  28. }
  29. /**
  30. * 添加二维码记录
  31. * @param int $thirdId
  32. * @param string $thirdType
  33. * @param string $page
  34. * @param string $qrCodeLink
  35. * @return object
  36. */
  37. public static function setRoutineQrcodeForever($thirdId = 0, $thirdType = 'spread', $page = '', $qrCodeLink = '')
  38. {
  39. $data['third_type'] = $thirdType;
  40. $data['third_id'] = $thirdId;
  41. $data['status'] = 1;
  42. $data['add_time'] = time();
  43. $data['page'] = $page;
  44. $data['qrcode_url'] = $qrCodeLink;
  45. return RoutineQrcode::create($data);
  46. }
  47. /**
  48. * 修改二维码地址
  49. * @param int $id
  50. * @param array $data
  51. * @return bool
  52. * @throws \think\db\exception\DbException
  53. */
  54. public function setRoutineQrcodeFind($id = 0, $data = array())
  55. {
  56. if (!$id) return false;
  57. $count = $this->getRoutineQrcodeFind($id);
  58. if (!$count) return false;
  59. return $this->update($id, $data);
  60. }
  61. /**
  62. * 获取二维码是否存在
  63. * @param int $id
  64. * @return int|string
  65. */
  66. public function getRoutineQrcodeFind($id = 0)
  67. {
  68. if (!$id) return 0;
  69. return RoutineQrcode::where('routine_qrcode_id', $id)->count();
  70. }
  71. /**
  72. * 获取小程序二维码信息
  73. * @param int $id
  74. * @param string $field
  75. * @return array|bool|false|\PDOStatement|string|\think\Model
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function getRoutineQrcodeFindType($id = 0, $field = 'third_type,third_id,page')
  81. {
  82. if (!$id) return false;
  83. $count = $this->getRoutineQrcodeFind($id);
  84. if (!$count) return false;
  85. return RoutineQrcode::where('routine_qrcode_id', $id)->where('status', 1)->field($field)->find();
  86. }
  87. }