Certificate.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\model;
  10. use app\common\model\Certificate as CertificateModel;
  11. /**
  12. * Class Certificate
  13. * 资质管理
  14. *
  15. * @Author: Yeshihao
  16. * @DateTime: 2024/11/26 14:01
  17. * @package app\store\model
  18. */
  19. class Certificate extends CertificateModel
  20. {
  21. public function getList()
  22. {
  23. $query = self::useGlobalScope(true);
  24. $query = $this->handlerSearch($query, request()->param()); //查询条件
  25. return $query->with(['file', 'category'])
  26. ->where('is_delete', '=', 0)
  27. ->order(['create_time' => 'desc'])
  28. ->paginate(15, false, [
  29. 'query' => request()->request()
  30. ]);
  31. }
  32. /**
  33. * [add]
  34. *
  35. * @Author: Yeshihao
  36. * @DateTime: 2024/11/26 14:55
  37. * @param $data
  38. * @return false|int
  39. */
  40. public function add($data)
  41. {
  42. if (empty($data['file_id'])) {
  43. $this->error = '请上传资质文件';
  44. return false;
  45. }
  46. if (empty($data['name'])) {
  47. $this->error = '请输入资质名称';
  48. return false;
  49. }
  50. if (empty($data['certificate_category_id'])) {
  51. $this->error = '请选择资质分类';
  52. return false;
  53. }
  54. //获取文件类型
  55. $file = UploadFile::detail($data['file_id']);
  56. $data['file_type'] = $file['file_type'];
  57. $data['wxapp_id'] = self::$wxapp_id;
  58. return $this->allowField(true)->save($data);
  59. }
  60. /**
  61. * 更新记录
  62. *
  63. * @param $data
  64. * @return bool|int
  65. */
  66. public function edit($data)
  67. {
  68. if (empty($data['file_id'])) {
  69. $this->error = '请上传资质文件';
  70. return false;
  71. }
  72. if (empty($data['name'])) {
  73. $this->error = '请输入资质名称';
  74. return false;
  75. }
  76. if (empty($data['certificate_category_id'])) {
  77. $this->error = '请选择资质分类';
  78. return false;
  79. }
  80. //获取文件类型
  81. $file = UploadFile::detail($data['file_id']);
  82. $data['file_type'] = $file['file_type'];
  83. return $this->allowField(true)->save($data) !== false;
  84. }
  85. /**
  86. * [getCertificateTotal]
  87. *
  88. * @Author: Yeshihao
  89. * @DateTime: 2024/11/26 14:31
  90. * @param array $where
  91. * @return int|string
  92. * @throws \think\Exception
  93. */
  94. public static function getCertificateTotal($where = [])
  95. {
  96. $model = new static;
  97. !empty($where) && $model->where($where);
  98. return $model->where('is_delete', '=', 0)->count();
  99. }
  100. }