RoutineQrcode.php 3.0 KB

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