CertificateApply.php 5.6 KB

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