InvoiceTicket.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\facade\Log;
  5. use think\Model;
  6. /**
  7. * @mixin \think\Model
  8. */
  9. class InvoiceTicket extends Model
  10. {
  11. public function getItemAttr($v){
  12. return json_decode($v,true);
  13. }
  14. public function setItemAttr($v){
  15. return json_encode($v,JSON_UNESCAPED_UNICODE);
  16. }
  17. public static function onAfterWrite(Model $model){
  18. Log::info('InvoiceInfo::OnAfterWrite'.json_encode($model->toArray()));
  19. if($model->status==1 && !empty($model['item'])){
  20. (new InvoiceItem)->saveAll(array_map(function ($item)use($model) {
  21. return [
  22. 'invoiceCode'=>$model->invNo,
  23. 'order_type'=>1,
  24. 'good_name'=>$item['XMMC'],
  25. 'unit'=>$item['DW'],
  26. 'num'=>$item['SPSL'],
  27. 'specinfo'=>$item['GGXH'],
  28. 'unit_price'=>$item['DJ'],
  29. 'amount'=>$item['JE'],
  30. 'tax_amount'=>$item['SE'],
  31. 'tax'=>$item['SL'],
  32. 'cat_code'=>$item['SPBM'],
  33. 'total_amount'=>bcadd($item['JE'],$item['SE'],2),
  34. 'balance_amount'=>bcadd($item['JE'],$item['SE'],2),
  35. ];
  36. },$model['item']));
  37. }
  38. }
  39. }