123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\model;
- use think\facade\Log;use think\Model;
- /**
- * @mixin \think\Model
- */
- class InvoiceInfo extends Model
- {
- protected $updateTime="updatetime";
- public function getItemListAttr($value){
- return json_decode($value,true);
- }
- public function setItemListAttr($value){
- return json_encode($value,JSON_UNESCAPED_UNICODE);
- }
- public static function onAfterWrite(Model $model){
- log::info("InvoiceInfo::OnAfterWrite".json_encode($model->toArray()));
- $pay = Pay::where(["payNo"=>$model->payNo])->findOrEmpty();
- if(!$pay->isEmpty() && $pay->is_comon!=1){
- if($model->status==1 && !empty($model->item_list)){
- (new InvoiceItem)->saveAll(array_map(function ($item)use($model) {
- return [
- 'invoiceCode'=>$model->hpNo,
- 'order_type'=>2,
- 'good_name'=>$item['name'],
- 'unit'=>$item['unit'],
- 'num'=>$item['quantity'],
- 'unit_price'=>$item['unit_price'],
- 'amount'=>$item['amount'],
- 'tax_amount'=>$item['tax'],
- 'tax'=>$item['tax_rate'],
- 'cat_code'=>$item['license_plate_number'],
- 'total_amount'=>bcadd($item['amount'],$item['tax'],2),
- 'balance_amount'=>bcadd($item['amount'],$item['tax'],2),
- ];
- },$model->item_list));
- }
- }
- }
- }
|