RoutineQrcodeDao.php 3.0 KB

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