CertificateApply.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. $data['order_no'] = getOrderNo('CA');
  75. //获取文件类型
  76. $data['wxapp_id'] = self::$wxapp_id;
  77. $data['store_user_id'] = getStoreUserId();
  78. return $this->allowField(true)->save($data);
  79. }
  80. /**
  81. * [edit]
  82. *
  83. * @Author: Yeshihao
  84. * @DateTime: 2024/11/28 10:56
  85. * @param $data
  86. * @return false|int
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @throws \think\exception\DbException
  90. */
  91. public function edit($data)
  92. {
  93. //申请拒绝
  94. if ($data['status'] == 30) {
  95. if (!isset($data['refuse_reason']) || empty($data['refuse_reason'])) {
  96. $this->error = '请填写拒绝原因';
  97. return false;
  98. }
  99. }
  100. if ($data['status'] == 20) {
  101. $result_data = [];
  102. //获取资质文件信息
  103. $certificateList = Certificate::getCertificateList(['id' => ['in', $this['certificate_ids']]]);
  104. if ($certificateList->isEmpty()) {
  105. $this->error = '查无相关资质文件';
  106. return false;
  107. }
  108. foreach ($certificateList as $certificate) {
  109. $water = $this->watermark ?: '审批号:'.$this->order_no;
  110. $water2 = '';
  111. if ($this['indate']) {
  112. $water2 = $data['use_data'] ? '有效期至'.$this['indate'] : '';
  113. }
  114. $service = new WaterMarkBase($certificate['file']['file_path'],
  115. $water,
  116. self::$wxapp_id,
  117. $data['alpha'],
  118. $certificate['file_type'],
  119. $water2,
  120. $certificate['width'],
  121. $certificate['height']);
  122. $result = $service->waterMark();
  123. $result_data[] = [
  124. 'name' => $certificate['name'],
  125. 'file_path' => $result['file_path'],
  126. 'file_path_name' => $result['file_name'],
  127. ];
  128. }
  129. $data['result_data'] = $result_data;
  130. }
  131. //发送失败通知给客服
  132. $robot = new BaseRobot($this->wxapp_id);
  133. if ($data['status'] == 20) {
  134. $robot->sendMessage("资质申请:【{$this->project}】,审核成功。", RobotSence::WATERMARK_APPLY, [$this->storeUser->phone]);
  135. }
  136. if ($data['status'] == 30) {
  137. $robot->sendMessage("资质申请:【{$this->project}】,审核失败,失败原因:{$data['refuse_reason']}。", RobotSence::WATERMARK_APPLY, [$this->storeUser->phone]);
  138. }
  139. //获取文件类型
  140. $data['apply_user_id'] = getStoreUserId();
  141. return $this->allowField(true)->save($data);
  142. }
  143. /**
  144. * [changeAlpha]
  145. * 修改水印透明度
  146. *
  147. * @Author: Yeshihao
  148. * @DateTime: 2024/12/2 16:38
  149. * @param $alpha
  150. * @return false|int
  151. * @throws \Mpdf\MpdfException
  152. * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
  153. * @throws \setasign\Fpdi\PdfParser\PdfParserException
  154. * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
  155. * @throws \think\db\exception\DataNotFoundException
  156. * @throws \think\db\exception\ModelNotFoundException
  157. * @throws \think\exception\DbException
  158. */
  159. public function changeAlpha($alpha)
  160. {
  161. if ($this->status != 20) {
  162. $this->error = '该申请无法修改水印透明度';
  163. return false;
  164. }
  165. $result_data = [];
  166. //获取资质文件信息
  167. $certificateList = Certificate::getCertificateList(['id' => ['in', $this['certificate_ids']]]);
  168. if ($certificateList->isEmpty()) {
  169. $this->error = '查无相关资质文件';
  170. return false;
  171. }
  172. foreach ($certificateList as $certificate) {
  173. $water = $this->watermark ?: '审批号:'.$this->order_no;
  174. $water2 = '';
  175. if ($this['indate']) {
  176. $water2 = $this->use_date ? '有效期至'.$this->indate : '';
  177. }
  178. $service = new WaterMarkBase($certificate['file']['file_path'],
  179. $water,
  180. self::$wxapp_id,
  181. $alpha,
  182. $certificate['file_type'],
  183. $water2,
  184. $certificate['width'],
  185. $certificate['height']);
  186. $result = $service->waterMark();
  187. $result_data[] = [
  188. 'name' => $certificate['name'],
  189. 'file_path' => $result['file_path'],
  190. 'file_path_name' => $result['file_name'],
  191. ];
  192. }
  193. $data['result_data'] = $result_data;
  194. $data['alpha'] = $alpha;
  195. return $this->allowField(true)->save($data);
  196. }
  197. }