CertificateApply.php 5.5 KB

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