UserShowTemplate.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class UserShowTemplate extends Model
  9. {
  10. /**
  11. * 用户绑定名片模板
  12. * @param type $id
  13. * @param type $uid
  14. */
  15. public function userBindTemp($id,$uid){
  16. $count = $this->where("uid",$uid)->where("show_template_id",$id)->count();
  17. if($count<=0){
  18. $ocount = $this->where("uid",$uid)->where("is_default",1)->count();
  19. $r = $this->insert([
  20. "uid" => $uid,
  21. "show_template_id" => $id,
  22. "start_time" => time(),
  23. "end_time" => time()+100*365*24*60*60,//100年
  24. "is_default" => $ocount>0 ? 0 : 1,
  25. ]);
  26. }
  27. return true;
  28. }
  29. /**
  30. * 设置初始化模板
  31. * @param type $uid
  32. */
  33. public function userBindTempInit($uid){
  34. $count = $this->where("uid",$uid)->where("is_init",1)->count();
  35. if($count<=0){
  36. $initTemp = $this->where("is_init",1)->find();
  37. if(!empty($initTemp)){
  38. $ocount = $this->where("uid",$uid)->where("is_default",1)->count();
  39. $r = $this->insert([
  40. "uid" => $uid,
  41. "show_template_id" => $initTemp->id,
  42. "start_time" => time(),
  43. "end_time" => time()+1000*365*24*60*60,//100年
  44. "is_default" => $ocount>0 ? 0 : 1,
  45. "is_init" => 1,
  46. ]);
  47. }
  48. }
  49. }
  50. }