MasterWorkerAgreeLogic.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. class MasterWorkerAgreeLogic extends BaseLogic
  11. {
  12. public static function getAgreeByType($type)
  13. {
  14. return [
  15. 'title' => ConfigService::get('master_agreement', $type . '_title', ''),
  16. 'content' => ConfigService::get('master_agreement', $type . '_content', ''),
  17. ];
  18. }
  19. /**
  20. *
  21. * @param $params
  22. * @return bool|void
  23. */
  24. public static function sign($params)
  25. {
  26. Db::startTrans();
  27. try {
  28. //查询协议
  29. $agree = MasterWorkerAgree::where(['code'=>$params['code']])->findOrEmpty();
  30. if($agree->isEmpty()){
  31. throw new Exception('协议不存在');
  32. }
  33. if($agree->sign_status==1){
  34. throw new Exception('请勿重复签名');
  35. }
  36. //保存签名
  37. $result = UploadService::base64Image(4, $params['sign']);
  38. $sign = $result['url'];
  39. $agree->sign = $sign;
  40. $agree->sign_status = 1;
  41. $agree->sign_time = time();
  42. $agree->save();
  43. //pdf队列发送
  44. AddAgreementPdf::sendMq($agree->code,'https://'.$_SERVER['SERVER_NAME'].'/index/agreement/index'.'?code='.$agree->code);
  45. Db::commit();
  46. return true;
  47. } catch (\Exception $e) {
  48. Db::rollback();
  49. self::setError($e->getMessage());
  50. return false;
  51. }
  52. }
  53. }