RoutineQrcodeDao.php 3.6 KB

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