Model.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace crmeb\services\crud;
  14. /**
  15. * Class Model
  16. * @author 等风来
  17. * @email 136327134@qq.com
  18. * @date 2023/3/13
  19. * @package crmeb\command\crud
  20. */
  21. class Model extends Make
  22. {
  23. /**
  24. * 当前命令名称
  25. * @var string
  26. */
  27. protected $name = "model";
  28. /**
  29. * @return string
  30. * @author 等风来
  31. * @email 136327134@qq.com
  32. * @date 2023/4/4
  33. */
  34. protected function setBaseDir(): string
  35. {
  36. return 'app' . DS . 'model' . DS . 'crud';
  37. }
  38. /**
  39. * @param string $name
  40. * @param array $options
  41. * @return Model
  42. * @author 等风来
  43. * @email 136327134@qq.com
  44. * @date 2023/4/12
  45. */
  46. public function handle(string $name, array $options = [])
  47. {
  48. $this->value['key'] = $options['key'] ?? 'id';
  49. if (isset($options['softDelete']) && $options['softDelete']) {
  50. $this->value['use-php'] = "use think\model\concern\SoftDelete;\n";
  51. $this->value['content-php'] = $this->tab() . "use SoftDelete;\n";
  52. }
  53. $this->value['modelName'] = $options['modelName'] ?? $name;
  54. return parent::handle($name, $options);
  55. }
  56. /**
  57. * @param string $path
  58. * @param string $name
  59. * @return string
  60. * @author 等风来
  61. * @email 136327134@qq.com
  62. * @date 2023/4/12
  63. */
  64. protected function getFilePathName(string $path, string $name): string
  65. {
  66. $path = ltrim(str_replace('\\', '/', $path), '/');
  67. return $this->getBasePath($path) . $name . '.' . $this->fileMime;
  68. }
  69. /**
  70. * 模板文件
  71. * @param string $type
  72. * @return string
  73. * @author 等风来
  74. * @email 136327134@qq.com
  75. * @date 2023/3/13
  76. */
  77. protected function getStub(string $type = '')
  78. {
  79. return __DIR__ . DS . 'stubs' . DS . 'model' . DS . 'crudModel.stub';
  80. }
  81. }