RoutineQrcode.php 3.0 KB

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