CertificateApply.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\CertificateApply as CertificateApplyModel;
  11. use app\common\service\watermark\WaterMarkBase;
  12. /**
  13. * 拼团商品分类模型
  14. * Class Category
  15. *
  16. * @package app\common\model
  17. */
  18. class CertificateApply extends CertificateApplyModel
  19. {
  20. /**
  21. * [getList]
  22. *
  23. * @Author: Yeshihao
  24. * @DateTime: 2024/11/27 11:12
  25. * @return \think\Paginator
  26. * @throws \think\exception\DbException
  27. */
  28. public function getList()
  29. {
  30. return $this->with(['applyUser'])
  31. ->where('is_delete', '=', 0)
  32. ->order(['create_time' => 'desc'])
  33. ->paginate(15, false, [
  34. 'query' => request()->request()
  35. ]);
  36. }
  37. /**
  38. * [add]
  39. * 新增申请
  40. *
  41. * @Author: Yeshihao
  42. * @DateTime: 2024/11/27 18:05
  43. * @param $data
  44. * @return false|int
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. * @throws \think\exception\DbException
  48. */
  49. public function add($data)
  50. {
  51. //判断是否有资质文件
  52. if (!isset($data['certificate_ids']) || empty($data['certificate_ids'])) {
  53. $this->error = '请选择资质文件';
  54. return false;
  55. }
  56. //获取资质文件信息
  57. $certificateList = Certificate::getCertificateList(['id' => ['in', $data['certificate_ids']]]);
  58. if ($certificateList->isEmpty()) {
  59. $this->error = '查无相关资质文件';
  60. return false;
  61. }
  62. // $result_data = [];
  63. // foreach ($certificateList as $certificate) {
  64. // $service = new WaterMarkBase($certificate['file']['file_path'], $data['watermark'], self::$wxapp_id, $certificate['file_type']);
  65. // $result = $service->waterMark();
  66. // }
  67. //获取文件类型
  68. $data['wxapp_id'] = self::$wxapp_id;
  69. $data['store_user_id'] = getStoreUserId();
  70. return $this->allowField(true)->save($data);
  71. }
  72. /**
  73. * [edit]
  74. *
  75. * @Author: Yeshihao
  76. * @DateTime: 2024/11/28 10:56
  77. * @param $data
  78. * @return false|int
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @throws \think\exception\DbException
  82. */
  83. public function edit($data)
  84. {
  85. //申请拒绝
  86. if ($data['status'] == 30) {
  87. if (!isset($data['refuse_reason']) || empty($data['refuse_reason'])) {
  88. $this->error = '请填写拒绝原因';
  89. return false;
  90. }
  91. }
  92. if ($data['status'] == 20) {
  93. $result_data = [];
  94. //获取资质文件信息
  95. $certificateList = Certificate::getCertificateList(['id' => ['in', $this['certificate_ids']]]);
  96. if ($certificateList->isEmpty()) {
  97. $this->error = '查无相关资质文件';
  98. return false;
  99. }
  100. foreach ($certificateList as $certificate) {
  101. $service = new WaterMarkBase($certificate['file']['file_path'], $this['watermark'], self::$wxapp_id, $certificate['file_type']);
  102. $filePath = $service->waterMark();
  103. $result_data[] = [
  104. 'name' => $certificate['name'],
  105. 'file_path' => $filePath,
  106. ];
  107. }
  108. $data['result_data'] = $result_data;
  109. }
  110. //获取文件类型
  111. $data['apply_user_id'] = getStoreUserId();
  112. return $this->allowField(true)->save($data);
  113. }
  114. }