UserShowTemplate.php 1.7 KB

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