CertificateApply.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. $query = self::useGlobalScope(true);
  31. $query = $this->handlerSearch($query, request()->param()); //查询条件
  32. return $query->with(['applyUser'])
  33. ->where('is_delete', '=', 0)
  34. ->order(['create_time' => 'desc'])
  35. ->paginate(15, false, [
  36. 'query' => request()->request()
  37. ]);
  38. }
  39. /**
  40. * [add]
  41. * 新增申请
  42. *
  43. * @Author: Yeshihao
  44. * @DateTime: 2024/11/27 18:05
  45. * @param $data
  46. * @return false|int
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. public function add($data)
  52. {
  53. //判断是否有资质文件
  54. if (!isset($data['certificate_ids']) || empty($data['certificate_ids'])) {
  55. $this->error = '请选择资质文件';
  56. return false;
  57. }
  58. //获取资质文件信息
  59. $certificateList = Certificate::getCertificateList(['id' => ['in', $data['certificate_ids']]]);
  60. if ($certificateList->isEmpty()) {
  61. $this->error = '查无相关资质文件';
  62. return false;
  63. }
  64. // $result_data = [];
  65. // foreach ($certificateList as $certificate) {
  66. // $service = new WaterMarkBase($certificate['file']['file_path'], $data['watermark'], self::$wxapp_id, $certificate['file_type']);
  67. // $result = $service->waterMark();
  68. // }
  69. //获取文件类型
  70. $data['wxapp_id'] = self::$wxapp_id;
  71. $data['store_user_id'] = getStoreUserId();
  72. return $this->allowField(true)->save($data);
  73. }
  74. /**
  75. * [edit]
  76. *
  77. * @Author: Yeshihao
  78. * @DateTime: 2024/11/28 10:56
  79. * @param $data
  80. * @return false|int
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. */
  85. public function edit($data)
  86. {
  87. //申请拒绝
  88. if ($data['status'] == 30) {
  89. if (!isset($data['refuse_reason']) || empty($data['refuse_reason'])) {
  90. $this->error = '请填写拒绝原因';
  91. return false;
  92. }
  93. }
  94. if ($data['status'] == 20) {
  95. $result_data = [];
  96. //获取资质文件信息
  97. $certificateList = Certificate::getCertificateList(['id' => ['in', $this['certificate_ids']]]);
  98. if ($certificateList->isEmpty()) {
  99. $this->error = '查无相关资质文件';
  100. return false;
  101. }
  102. foreach ($certificateList as $certificate) {
  103. $service = new WaterMarkBase($certificate['file']['file_path'],
  104. $this['watermark'],
  105. self::$wxapp_id,
  106. $data['alpha'],
  107. $certificate['file_type'],
  108. '有效期至'.$this['indate'],
  109. $certificate['width'],
  110. $certificate['height']);
  111. $result = $service->waterMark();
  112. $result_data[] = [
  113. 'name' => $certificate['name'],
  114. 'file_path' => $result['file_path'],
  115. 'file_path_name' => $result['file_name'],
  116. ];
  117. }
  118. $data['result_data'] = $result_data;
  119. }
  120. //获取文件类型
  121. $data['apply_user_id'] = getStoreUserId();
  122. return $this->allowField(true)->save($data);
  123. }
  124. /**
  125. * [changeAlpha]
  126. * 修改水印透明度
  127. *
  128. * @Author: Yeshihao
  129. * @DateTime: 2024/12/2 16:38
  130. * @param $alpha
  131. * @return false|int
  132. * @throws \Mpdf\MpdfException
  133. * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
  134. * @throws \setasign\Fpdi\PdfParser\PdfParserException
  135. * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\ModelNotFoundException
  138. * @throws \think\exception\DbException
  139. */
  140. public function changeAlpha($alpha)
  141. {
  142. if ($this->status != 20) {
  143. $this->error = '该申请无法修改水印透明度';
  144. return false;
  145. }
  146. $result_data = [];
  147. //获取资质文件信息
  148. $certificateList = Certificate::getCertificateList(['id' => ['in', $this['certificate_ids']]]);
  149. if ($certificateList->isEmpty()) {
  150. $this->error = '查无相关资质文件';
  151. return false;
  152. }
  153. foreach ($certificateList as $certificate) {
  154. $service = new WaterMarkBase($certificate['file']['file_path'],
  155. $this['watermark'],
  156. self::$wxapp_id,
  157. $alpha,
  158. $certificate['file_type'],
  159. '有效期至'.$this['indate'],
  160. $certificate['width'],
  161. $certificate['height']);
  162. $result = $service->waterMark();
  163. $result_data[] = [
  164. 'name' => $certificate['name'],
  165. 'file_path' => $result['file_path'],
  166. 'file_path_name' => $result['file_name'],
  167. ];
  168. }
  169. $data['result_data'] = $result_data;
  170. $data['alpha'] = $alpha;
  171. return $this->allowField(true)->save($data);
  172. }
  173. }