RoutineQrcode.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\routine\model\routine;
  3. use basic\ModelBasic;
  4. use traits\ModelTrait;
  5. /**
  6. * 小程序二维码Model
  7. * Class RoutineQrcode
  8. * @package app\routine\model\routine
  9. */
  10. class RoutineQrcode extends ModelBasic {
  11. use ModelTrait;
  12. /**
  13. * 添加二维码记录
  14. * @param string $thirdType
  15. * @param int $thirdId
  16. * @return object
  17. */
  18. public static function setRoutineQrCodeForever($thirdId = 0,$thirdType = 'spread',$page = '',$imgUrl = ''){
  19. $data['third_type'] = $thirdType;
  20. $data['third_id'] = $thirdId;
  21. $data['status'] = 1;
  22. $data['add_time'] = time();
  23. $data['page'] = $page;
  24. $data['url_time'] = '';
  25. $data['qrcode_url'] = $imgUrl;
  26. return self::set($data);
  27. }
  28. /**
  29. * 修改二维码地址
  30. * @param int $id
  31. * @param array $data
  32. * @return bool
  33. */
  34. public static function setRoutineQrcodeFind($id = 0,$data = array()){
  35. if(!$id) return false;
  36. $count = self::getRoutineQrcodeFind($id);
  37. if(!$count) return false;
  38. return self::edit($data,$id,'id');
  39. }
  40. /**
  41. * 获取二维码是否存在
  42. * @param int $id
  43. * @return int|string
  44. */
  45. public static function getRoutineQrcodeFind($id = 0){
  46. if(!$id) return 0;
  47. return self::where('id',$id)->count();
  48. }
  49. /**
  50. * 获取小程序二维码信息
  51. * @param int $id
  52. * @param string $field
  53. * @return array|bool|false|\PDOStatement|string|\think\Model
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. * @throws \think\exception\DbException
  57. */
  58. public static function getRoutineQrcodeFindType($id = 0,$field = 'third_type,third_id,page'){
  59. if(!$id) return false;
  60. $count = self::getRoutineQrcodeFind($id);
  61. if(!$count) return false;
  62. return self::where('id',$id)->where('status',1)->field($field)->find();
  63. }
  64. /**
  65. * TODO 根据用户编号和二维码类型查看分销二维码是否存在
  66. * @param int $thirdId
  67. * @param string $thirdType
  68. * @return int|string
  69. * @throws \think\Exception
  70. */
  71. public static function getRoutineQrCodeCount($thirdId = 0,$thirdType = 'spread'){
  72. return self::where('third_id',$thirdId)->where('third_type',$thirdType)->count();
  73. }
  74. /**
  75. * TODO 根据用户编号和二维码类型获取分销二维码
  76. * @param int $thirdId
  77. * @param string $thirdType
  78. * @return bool|mixed|object
  79. * @throws \think\Exception
  80. */
  81. public static function getRoutineQrCode($thirdId = 0,$thirdType = 'spread',$page = '',$imgUrl = ''){
  82. if(!$thirdId) return false;
  83. $count = self::getRoutineQrCodeCount($thirdId,$thirdType);
  84. if($count) return self::where('third_id',$thirdId)->where('third_type',$thirdType)->find();
  85. else return self::setRoutineQrCodeForever($thirdId,$thirdType,$page,$imgUrl);
  86. }
  87. }