MiniNoticeTemplate.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2020/6/5
  6. * Time: 17:48
  7. */
  8. namespace app\common\services\notice\share;
  9. use app\common\models\MiniTemplateCorresponding;
  10. use app\common\models\notice\MinAppTemplateMessage;
  11. Trait MiniNoticeTemplate
  12. {
  13. public $temp_id = 0;
  14. public $temp_open = 0;
  15. public $temp_title = "";
  16. public function getTemplate($name)
  17. {
  18. $corres_id = MiniTemplateCorresponding::uniacid()->where("template_name",$name)->value("template_id");
  19. $temp = MinAppTemplateMessage::select('template_id','is_open','title')->where('template_id',$corres_id)->where("small_type",1)->where('is_default',1)->first();
  20. $this->temp_id = empty($temp['template_id']) ? 0 : $temp['template_id'];
  21. $this->temp_open = empty($temp['is_open']) ? 0 : $temp['is_open'];
  22. $this->temp_title = empty($temp['title']) ? "" : $temp['title'].'-';
  23. }
  24. public function checkDataLength($str,$length)
  25. {
  26. if (mb_strlen($str,'utf8') > $length) {
  27. return mb_substr($str,0,$length,'utf8');
  28. }
  29. return $str;
  30. }
  31. }