RoutineQrcode.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\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. $row = self::where('third_id', $thirdId)->where('third_type', $thirdType)->find();
  41. if ($row) {
  42. return $row;
  43. }
  44. return self::setRoutineQrcodeForever($thirdId, $thirdType, $page, $qrCodeLink);
  45. }
  46. /**
  47. * 添加二维码记录
  48. * @param string $thirdType
  49. * @param int $thirdId
  50. * @return object
  51. */
  52. public static function setRoutineQrcodeForever($thirdId = 0, $thirdType = 'spread', $page = '', $qrCodeLink = '')
  53. {
  54. $data['third_type'] = $thirdType;
  55. $data['third_id'] = $thirdId;
  56. $data['status'] = 1;
  57. $data['add_time'] = time();
  58. $data['page'] = $page;
  59. $data['url_time'] = '';
  60. $data['qrcode_url'] = $qrCodeLink;
  61. return self::create($data);
  62. }
  63. /**
  64. * 修改二维码地址
  65. * @param int $id
  66. * @param array $data
  67. * @return bool
  68. */
  69. public static function setRoutineQrcodeFind($id = 0, $data = array())
  70. {
  71. if (!$id) return false;
  72. $count = self::getRoutineQrcodeFind($id);
  73. if (!$count) return false;
  74. return self::edit($data, $id, 'id');
  75. }
  76. /**
  77. * 获取二维码是否存在
  78. * @param int $id
  79. * @return int|string
  80. */
  81. public static function getRoutineQrcodeFind($id = 0)
  82. {
  83. if (!$id) return 0;
  84. return self::where('id', $id)->count();
  85. }
  86. /**
  87. * 获取小程序二维码信息
  88. * @param int $id
  89. * @param string $field
  90. * @return array|bool|false|\PDOStatement|string|\think\Model
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. * @throws \think\exception\DbException
  94. */
  95. public static function getRoutineQrcodeFindType($id = 0, $field = 'third_type,third_id,page')
  96. {
  97. if (!$id) return false;
  98. $count = self::getRoutineQrcodeFind($id);
  99. if (!$count) return false;
  100. return self::where('id', $id)->where('status', 1)->field($field)->find();
  101. }
  102. }