InvoiceInfo.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\facade\Log;use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class InvoiceInfo extends Model
  9. {
  10. protected $updateTime="updatetime";
  11. public function getItemListAttr($value){
  12. return json_decode($value,true);
  13. }
  14. public function setItemListAttr($value){
  15. return json_encode($value,JSON_UNESCAPED_UNICODE);
  16. }
  17. public static function onAfterWrite(Model $model){
  18. log::info("InvoiceInfo::OnAfterWrite".json_encode($model->toArray()));
  19. $pay = Pay::where(["payNo"=>$model->payNo])->findOrEmpty();
  20. if(!$pay->isEmpty() && $pay->is_comon!=1){
  21. if($model->status==1 && !empty($model->item_list)){
  22. (new InvoiceItem)->saveAll(array_map(function ($item)use($model) {
  23. return [
  24. 'invoiceCode'=>$model->hpNo,
  25. 'order_type'=>2,
  26. 'good_name'=>$item['name'],
  27. 'unit'=>$item['unit'],
  28. 'num'=>$item['quantity'],
  29. 'unit_price'=>$item['unit_price'],
  30. 'amount'=>$item['amount'],
  31. 'tax_amount'=>$item['tax'],
  32. 'tax'=>$item['tax_rate'],
  33. 'cat_code'=>$item['license_plate_number'],
  34. 'total_amount'=>bcadd($item['amount'],$item['tax'],2),
  35. 'balance_amount'=>bcadd($item['amount'],$item['tax'],2),
  36. ];
  37. },$model->item_list));
  38. }
  39. }
  40. }
  41. }