MasterWorkerAgreeLogic.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. return [
  20. 'title' => ConfigService::get('master_agreement', $type . '_title', ''),
  21. 'content' => ConfigService::get('master_agreement', $type . '_content', ''),
  22. 'pdf'=>!empty($pdf)?'https://'.$_SERVER['SERVER_NAME'].'/'.$pdf:''
  23. ];
  24. }
  25. public static function getPolicyByType(string $type)
  26. {
  27. if($type == 'service'){
  28. return [
  29. 'title' => ConfigService::get('agreement', $type . '_title', ''),
  30. 'content' => ConfigService::get('agreement', $type . '_content', ''),
  31. ];
  32. }else{
  33. return [
  34. 'title' => ConfigService::get('master_agreement', $type . '_title', ''),
  35. 'content' => ConfigService::get('master_agreement', $type . '_content', ''),
  36. ];
  37. }
  38. }
  39. /**
  40. *
  41. * @param $params
  42. * @return bool|void
  43. */
  44. public static function sign($params)
  45. {
  46. try {
  47. //查询协议
  48. $agree = MasterWorkerAgree::where(['worker_id'=>$params['user_id'],'agree_type'=>'master_service_content'])->findOrEmpty();
  49. //保存签名
  50. if($agree->isEmpty()){
  51. $agree->code = generate_sn(MasterWorkerAgree::class, 'code');
  52. $agree->agree_type = 'master_service_content';
  53. $agree->worker_id = $params['user_id'];
  54. }
  55. $result = UploadService::base64Image(4, $params['sign']);
  56. $sign = $result['url'];
  57. $agree->sign = $sign;
  58. $agree->sign_status = 1;
  59. $agree->sign_time = time();
  60. $agree->audit_state = 0;
  61. $agree->save();
  62. \think\facade\Log::write('签署协议'.$agree->code);
  63. AddAgreementPdf::addPdf(['code'=>$agree->code,'url'=>'https://'.$_SERVER['SERVER_NAME'].'/index/agreement/index?code='.$agree->code]);
  64. //pdf队列发送
  65. // AddAgreementPdf::sendMq($agree->code,'https://'.$_SERVER['SERVER_NAME'].'/index/agreement/index?code='.$agree->code);
  66. return true;
  67. } catch (\Exception $e) {
  68. self::setError($e->getMessage());
  69. return false;
  70. }
  71. }
  72. }