CertificateApply.php 6.1 KB

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