FinancialPaymentRecordsLogic.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\financial;
  15. use app\common\model\financial\FinancialPaymentRecords;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\financial\MasterSettlementDetails;
  18. use app\common\model\master_worker\EngineerSettlement;
  19. use think\facade\Db;
  20. /**
  21. * FinancialPaymentRecords逻辑
  22. * Class FinancialPaymentRecordsLogic
  23. * @package app\adminapi\logic
  24. */
  25. class FinancialPaymentRecordsLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 添加
  29. * @param array $params
  30. * @return bool
  31. * @author likeadmin
  32. * @date 2024/12/02 11:55
  33. */
  34. public static function add(array $params): bool
  35. {
  36. Db::startTrans();
  37. try {
  38. FinancialPaymentRecords::create([
  39. 'export_conditions' => $params['export_conditions'],
  40. 'batch_number' => $params['batch_number'],
  41. 'upload_status' => $params['upload_status'],
  42. 'payment_status' => $params['payment_status'],
  43. ]);
  44. Db::commit();
  45. return true;
  46. } catch (\Exception $e) {
  47. Db::rollback();
  48. self::setError($e->getMessage());
  49. return false;
  50. }
  51. }
  52. /**
  53. * @notes 编辑
  54. * @param array $params
  55. * @return bool
  56. * @author likeadmin
  57. * @date 2024/12/02 11:55
  58. */
  59. public static function edit(array $params): bool
  60. {
  61. Db::startTrans();
  62. try {
  63. FinancialPaymentRecords::where('id', $params['id'])->update([
  64. 'export_conditions' => $params['export_conditions'],
  65. 'batch_number' => $params['batch_number'],
  66. 'upload_status' => $params['upload_status'],
  67. 'payment_status' => $params['payment_status'],
  68. ]);
  69. Db::commit();
  70. return true;
  71. } catch (\Exception $e) {
  72. Db::rollback();
  73. self::setError($e->getMessage());
  74. return false;
  75. }
  76. }
  77. /**
  78. * @notes 取消
  79. * @param array $params
  80. * @return bool
  81. * @author likeadmin
  82. * @date 2024/12/02 11:55
  83. */
  84. public static function delete(array $params): bool
  85. {
  86. Db::startTrans();
  87. try {
  88. $recordInfo = FinancialPaymentRecords::findOrEmpty($params['id'])->toArray();
  89. if($recordInfo){
  90. if((int)$recordInfo['upload_status'] !== 1){
  91. throw new \Exception('非待上传,不能取消');
  92. }
  93. MasterSettlementDetails::where('batch_number',$recordInfo['batch_number'])->where('status','<',3)->update(['status'=>1,'batch_number'=>'']);
  94. EngineerSettlement::destroy(['batch_number'=>$recordInfo['batch_number'],'is_deduction'=>['neq',1]]);
  95. FinancialPaymentRecords::update(['payment_status'=>2],['id'=>$params['id']]);
  96. }else{
  97. throw new \Exception('记录不存在');
  98. }
  99. Db::commit();
  100. return true;
  101. } catch (\Exception $e) {
  102. Db::rollback();
  103. self::setError($e->getMessage());
  104. return false;
  105. }
  106. }
  107. /**
  108. * @notes 获取详情
  109. * @param $params
  110. * @return array
  111. * @author likeadmin
  112. * @date 2024/12/02 11:55
  113. */
  114. public static function detail($params): array
  115. {
  116. return FinancialPaymentRecords::findOrEmpty($params['id'])->toArray();
  117. }
  118. }