MasterWorkerAgreeLogic.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\workerapi\logic;
  3. use app\common\command\AddAgreementPdf;
  4. use app\common\logic\BaseLogic;
  5. use app\common\model\master_worker\MasterWorkerAgree;
  6. use app\common\service\ConfigService;
  7. use app\common\service\UploadService;
  8. use think\Exception;
  9. use think\facade\Db;
  10. use think\Log;
  11. class MasterWorkerAgreeLogic extends BaseLogic
  12. {
  13. public static function getAgreeByType($type,$userId)
  14. {
  15. //服务合作协议是否存在pdf
  16. if($type=='master_service'){
  17. $pdf = MasterWorkerAgree::where(['agree_type'=>'master_service_content','worker_id'=>$userId])->value('pdf_url');
  18. }
  19. if($type=='harmless'){
  20. $pdf = MasterWorkerAgree::where(['agree_type'=>'harmless_content','worker_id'=>$userId])->value('pdf_url');
  21. }
  22. if($type=='crime'){
  23. $pdf = MasterWorkerAgree::where(['agree_type'=>'crime_content','worker_id'=>$userId])->value('pdf_url');
  24. }
  25. return [
  26. 'title' => ConfigService::get('master_agreement', $type . '_title', ''),
  27. 'content' => ConfigService::get('master_agreement', $type . '_content', ''),
  28. 'pdf'=>!empty($pdf)?'https://'.$_SERVER['SERVER_NAME'].'/'.$pdf:''
  29. ];
  30. }
  31. public static function getPolicyByType(string $type)
  32. {
  33. if($type == 'service'){
  34. return [
  35. 'title' => ConfigService::get('agreement', $type . '_title', ''),
  36. 'content' => ConfigService::get('agreement', $type . '_content', ''),
  37. ];
  38. }else{
  39. return [
  40. 'title' => ConfigService::get('master_agreement', $type . '_title', ''),
  41. 'content' => ConfigService::get('master_agreement', $type . '_content', ''),
  42. ];
  43. }
  44. }
  45. /**
  46. *
  47. * @param $params
  48. * @return bool|void
  49. */
  50. public static function sign($params)
  51. {
  52. try {
  53. //查询协议
  54. // crime harmless master_service
  55. if(isset($params['agree_type']) && $params['agree_type']) {
  56. $agree_type = $params['agree_type'];
  57. $view_url = $agree_type;
  58. }else{
  59. $agree_type = 'master_service';
  60. $view_url = 'index';
  61. }
  62. $agree = MasterWorkerAgree::where(['worker_id'=>$params['user_id'],'agree_type'=>$agree_type.'_content'])->findOrEmpty();
  63. //保存签名
  64. if($agree->isEmpty()){
  65. $agree->code = generate_sn(MasterWorkerAgree::class, 'code');
  66. $agree->agree_type = $agree_type.'_content';
  67. $agree->worker_id = $params['user_id'];
  68. }
  69. $result = UploadService::base64Image(4, $params['sign']);
  70. $sign = $result['url'];
  71. $agree->sign = $sign;
  72. $agree->sign_status = 1;
  73. $agree->sign_time = time();
  74. $agree->audit_state = 0;
  75. $agree->save();
  76. \think\facade\Log::write('签署协议'.$agree->code);
  77. AddAgreementPdf::addPdf(['code'=>$agree->code,'url'=>'https://'.$_SERVER['SERVER_NAME'].'/index/agreement/'.$view_url.'?code='.$agree->code]);
  78. //pdf队列发送
  79. // AddAgreementPdf::sendMq($agree->code,'https://'.$_SERVER['SERVER_NAME'].'/index/agreement/index?code='.$agree->code);
  80. return true;
  81. } catch (\Exception $e) {
  82. self::setError($e->getMessage());
  83. return false;
  84. }
  85. }
  86. }