PaymentOrder.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\cxinv\model;
  3. use think\facade\Log;use think\Model;
  4. use think\model\concern\SoftDelete;
  5. class PaymentOrder extends Base{
  6. use SoftDelete;
  7. protected $createTime='createTime';
  8. protected $updateTime='updateTime';
  9. protected $deleteTime='delete_time';
  10. protected $schema=[
  11. 'id'=>'int',
  12. 'dzNo'=>'string',
  13. 'cgdNo'=>'string',
  14. 'rela_fee'=>'decimal',
  15. 'status'=>'tinyint',
  16. 'createTime'=>'datetime',
  17. 'updateTime'=>'datetime',
  18. 'delete_time'=>'datetime'
  19. ];
  20. //状态 0 关联中 1 已付款 2 解除付款 3 取消付款',
  21. public static function onAfterWrite(Model $model) : void{
  22. $cgdNo = $model->cgdNo;
  23. $status = $model->status;
  24. Log::info("PaymentOrder::onAfterWrite:".$model->cgdNo."-".$model->status);
  25. $cgdinfo = CgdInfo::where(["sequenceNo"=>$cgdNo,"is_del"=>0,"status"=>1])->findOrEmpty();
  26. if($cgdinfo->isEmpty()) return;
  27. switch ($status){
  28. case 0:
  29. $cgdinfo->wpay_fee= $cgdinfo->wpay_fee-$model->rela_fee;
  30. $cgdinfo->pay_status= 2;
  31. break;
  32. case 1:
  33. $cgdinfo->apay_fee= $cgdinfo->apay_fee+$model->rela_fee;
  34. $cgdinfo->pay_status= $cgdinfo->wpay_fee==0 && $cgdinfo->apay_fee==$cgdinfo->totalPrice-$cgdinfo->pay_tag_fee?3:2;
  35. break;
  36. case 2:
  37. $cgdinfo->apay_fee= $cgdinfo->apay_fee-$model->rela_fee;
  38. $cgdinfo->wpay_fee= $cgdinfo->wpay_fee+$model->rela_fee;
  39. $cgdinfo->pay_status= $cgdinfo->apay_fee==0 && $cgdinfo->wpay_fee==$cgdinfo->totalPrice-$cgdinfo->pay_tag_fee?1:2;
  40. break;
  41. case 3:
  42. $cgdinfo->wpay_fee= $cgdinfo->wpay_fee+$model->rela_fee;
  43. $cgdinfo->pay_status= $cgdinfo->apay_fee==0 && $cgdinfo->wpay_fee==$cgdinfo->totalPrice-$cgdinfo->pay_tag_fee?1:2;
  44. break;
  45. default:
  46. return;
  47. }
  48. $cgdinfo->save();
  49. Log::info("PaymentOrder::onAfterWrite-update:".self::getLastSql());
  50. }
  51. //状态 0 关联中 1 已付款 2 解除付款 3 取消付款',
  52. public static function checkOrder($dzNo,$status){
  53. $list = self::where(['dzNo'=>$dzNo,'status'=>$status==2?1:0])->field("id,cgdNo,status,rela_fee")->select();
  54. Log::info("PaymentOrder::checkOrder:dzNo-{$dzNo},status-{$status}");
  55. if($list->isEmpty()) return;
  56. Log::info(array_map(function($item)use($status){
  57. return [
  58. 'id'=>$item['id'],
  59. 'cgdNo'=>$item['cgdNo'],
  60. 'rela_fee'=>$item['rela_fee'],
  61. 'status'=>$status
  62. ];
  63. },$list->toArray()));
  64. (new PaymentOrder)->saveAll(array_map(function($item)use($status){
  65. return [
  66. 'id'=>$item['id'],
  67. 'cgdNo'=>$item['cgdNo'],
  68. 'rela_fee'=>$item['rela_fee'],
  69. 'status'=>$status
  70. ];
  71. },$list->toArray()));
  72. Log::info("PaymentOrder::checkOrder-update:".self::getLastSql());
  73. }
  74. }