123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\model;
- use think\facade\Log;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class InvoiceTicket extends Model
- {
- public function getItemAttr($v){
- return json_decode($v,true);
- }
- public function setItemAttr($v){
- return json_encode($v,JSON_UNESCAPED_UNICODE);
- }
- public static function onAfterWrite(Model $model){
- Log::info('InvoiceInfo::OnAfterWrite'.json_encode($model->toArray()));
- if($model->status==1 && !empty($model['item'])){
- (new InvoiceItem)->saveAll(array_map(function ($item)use($model) {
- return [
- 'invoiceCode'=>$model->invNo,
- 'order_type'=>1,
- 'good_name'=>$item['XMMC'],
- 'unit'=>$item['DW'],
- 'num'=>$item['SPSL'],
- 'specinfo'=>$item['GGXH'],
- 'unit_price'=>$item['DJ'],
- 'amount'=>$item['JE'],
- 'tax_amount'=>$item['SE'],
- 'tax'=>$item['SL'],
- 'cat_code'=>$item['SPBM'],
- 'total_amount'=>bcadd($item['JE'],$item['SE'],2),
- 'balance_amount'=>bcadd($item['JE'],$item['SE'],2),
- ];
- },$model['item']));
- }
- }
- }
|