query.tpl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {assign var="datetime" value=$file->GetFileCreateTime()}
  2. {assign var="namespace" value=$file->GetNamespace()}
  3. {assign var="classes" value=$file->GetClasses()}
  4. {assign var="uses" value=$file->GetUses()}
  5. <?php
  6. /**
  7. * Created by FFB.
  8. * Company: Shenzhen Zhixun Information Tec. Nanchang Com.
  9. * Copyright: ShenzhenZhixun
  10. * Email: eastbus@126.com
  11. * User: FFB
  12. * Date: {$datetime}
  13. * 文件不允许修改,自动生成
  14. */
  15. namespace {$namespace};
  16. {section name=index loop=$uses}
  17. use {{$uses[index]}};
  18. {/section}
  19. {section name=index loop=$classes}
  20. {assign var="className" value=$classes[index]->GetClassName()}
  21. {assign var="tableName" value=$classes[index]->GetTable()->GetName()}
  22. {assign var="tableNameHump" value=$classes[index]->GetTable()->GetNameForHump()}
  23. {assign var="attrs" value=$classes[index]->GetAttrs()}
  24. {assign var="extends" value=$classes[index]->GetExtends()}
  25. class {$className}{foreach item=e from=$extends key=i}{if $i == 0} extends {/if}{$e}{/foreach}{
  26. public function __construct($config = [])
  27. {
  28. parent::__construct({$tableNameHump}::class, $config);
  29. }
  30. /**
  31. * @param null $db
  32. * @return {$tableNameHump} | null | array
  33. */
  34. public function one($db = null)
  35. {
  36. return parent::one($db);
  37. }
  38. /**
  39. * @param null $db
  40. * @return array | {$tableNameHump}[]
  41. */
  42. public function all($db = null)
  43. {
  44. return parent::all($db);
  45. }
  46. public static function tableName()
  47. {
  48. return '{literal}{{{/literal}{{$tableName}}{literal}}}{/literal}';
  49. }
  50. {section name=index loop=$attrs}
  51. {assign var="fieldName" value=$attrs[index]->GetColumn()->GetName()}
  52. {assign var="fieldComment" value=$attrs[index]->GetColumn()->GetComment()}
  53. {assign var="attrName" value=$attrs[index]->GetName()}
  54. /**
  55. * ------------ 字段 {{$fieldName}}
  56. * ------------ 表字段注释: {{$fieldComment}}
  57. * 如果$val不是function,通过传入的值,直接组成['tableName' => $val]给到where方法
  58. * 如果是function,则闭包函数的类型为 function(string $tableName, ActiveQuery $activeQuery)
  59. * @param mixed | callable
  60. */
  61. public function filterBy{{$attrName}}($val): self
  62. {
  63. if(is_callable($val)){
  64. $val("{{$fieldName}}", $this);
  65. return $this;
  66. }
  67. $this->andWhere(["{{$fieldName}}" => $val]);
  68. return $this;
  69. }
  70. // ---------------------------------------------
  71. {/section}
  72. }
  73. {/section}