Certificate.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. return $this->with(['file', 'category'])
  24. ->where('is_delete', '=', 0)
  25. ->order(['create_time' => 'desc'])
  26. ->paginate(15, false, [
  27. 'query' => request()->request()
  28. ]);
  29. }
  30. /**
  31. * [add]
  32. *
  33. * @Author: Yeshihao
  34. * @DateTime: 2024/11/26 14:55
  35. * @param $data
  36. * @return false|int
  37. */
  38. public function add($data)
  39. {
  40. if (empty($data['file_id'])) {
  41. $this->error = '请上传资质文件';
  42. return false;
  43. }
  44. if (empty($data['name'])) {
  45. $this->error = '请输入资质名称';
  46. return false;
  47. }
  48. //获取文件类型
  49. $file = UploadFile::detail($data['file_id']);
  50. $data['file_type'] = $file['file_type'];
  51. $data['wxapp_id'] = self::$wxapp_id;
  52. return $this->allowField(true)->save($data);
  53. }
  54. /**
  55. * 更新记录
  56. *
  57. * @param $data
  58. * @return bool|int
  59. */
  60. public function edit($data)
  61. {
  62. if (empty($data['file_id'])) {
  63. $this->error = '请上传资质文件';
  64. return false;
  65. }
  66. if (empty($data['name'])) {
  67. $this->error = '请输入资质名称';
  68. return false;
  69. }
  70. return $this->allowField(true)->save($data) !== false;
  71. }
  72. /**
  73. * [getCertificateTotal]
  74. *
  75. * @Author: Yeshihao
  76. * @DateTime: 2024/11/26 14:31
  77. * @param array $where
  78. * @return int|string
  79. * @throws \think\Exception
  80. */
  81. public static function getCertificateTotal($where = [])
  82. {
  83. $model = new static;
  84. !empty($where) && $model->where($where);
  85. return $model->where('is_delete', '=', 0)->count();
  86. }
  87. }