MiniTemplate.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\api\model\service;
  3. use think\Model;
  4. class MiniTemplate extends Model
  5. {
  6. // 表名
  7. protected $name = 'service_mini_template';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. public static function getTemplateConfig($attr)
  14. {
  15. return json_decode(self::where(['state'=>1])->value($attr),true);
  16. }
  17. public static function spellParams($params)
  18. {
  19. //9个模板 type 1接单通知用户2用户端订单通知3用户售后服务通知4投诉处理通知用户5服务者订单通知6服务者售后服务通知7商户订单通知8商户售后服务通知9商户订单完成通知
  20. $templateConfig = self::getTemplateConfig($params['templateAttr']);
  21. if(!$templateConfig)
  22. {
  23. return false;
  24. }
  25. unset($templateConfig['template_id']);
  26. $valueList = array_values($templateConfig);
  27. $keyList = array_keys($templateConfig);
  28. $data = [];
  29. foreach ($valueList as $key=>$value)
  30. {
  31. $length = self::getStrCount($value);
  32. if(in_array($keyList[$key],['url','urlParams'])){
  33. continue;
  34. }elseif($keyList[$key] == 'time')
  35. {
  36. $data[$value]['value'] = date("Y-m-d H:i",$params[$keyList[$key]]);
  37. }elseif ($keyList[$key] == 'name') {
  38. $data[$value]['value'] = substr($params[$keyList[$key]],0,$length);
  39. }elseif($keyList[$key] == 'note'){
  40. $data[$value]['value'] = $params[$keyList[$key]]?substr($params[$keyList[$key]],0,$length):'有问题请联系客服';
  41. }else{
  42. $data[$value]['value'] = substr($params[$keyList[$key]],0,$length);
  43. }
  44. }
  45. return $data;
  46. }
  47. public static function getStrCount($strType)
  48. {
  49. switch ($strType)
  50. {
  51. case strpos($strType, 'ame'):
  52. case strpos($strType,'hing'):
  53. $count = 18;
  54. break;
  55. case strpos($strType, 'etter'):
  56. case strpos($strType, 'haracter string'):
  57. case strpos($strType,'umber'):
  58. $count = 30;
  59. break;
  60. case strpos($strType,'hrase'):
  61. $count = 15;
  62. break;
  63. default :
  64. $count = 15;
  65. }
  66. return $count;
  67. }
  68. }