12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\admin\model;
- use think\facade\Log;use think\model\concern\SoftDelete;
- class InvoiceItem extends \think\Model {
- use SoftDelete;
- protected $createTime="createTime";
- protected $updateTime="updateTime";
- protected $autoWriteTimestamp=true;
- protected $deleteTime="delete_time";
- public function OrderInfo(){
- return $this->hasMany(InvoiceOrder::class,"itemId","id");
- }
- public static function getNumAttr($val){
- return strval(floatval($val));
- }
- public static function setNumAttr($val){
- return floatval($val);
- }
- public static function onAfterUpdate($model){
- $code=$model->invoiceCode;
- $orderType=$model->order_type;
- $change = $model->getChangedData();
- Log::info("修改发票明细状态:".json_encode($change,JSON_UNESCAPED_UNICODE));
- Log::info("跟后数据:".json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
- if(in_array($change["status"],[0,1,2])){
- $num = self::where(['invoiceCode'=>$code,'order_type'=>$orderType,'status'=>0])->count();
- if($orderType==1){
- $info= InvoicePool::where(['invNo'=>$code,'is_del'=>0])->findOrEmpty();
- if(!$info->isEmpty()){
- if($num==0 && $info->status==10){
- $info->status=11;
- }
- if($num>0 && $info->status==11){
- $info->status=10;
- }
- $info->save();
- }
- }
- if($orderType==2){
- $info= PayInvoice::where(['hpNo'=>$code,'is_del'=>0])->findOrEmpty();
- if(!$info->isEmpty()){
- $pay = Pay::where(['payNo'=>$info->payNo,'is_del'=>0])->findOrEmpty();
- if(!$pay->isEmpty() && $pay->status==2){
- if($num==0 && $info->status==11){
- $info->status=12;
- }
- if($num>0 && $info->status==12){
- $info->status=11;
- }
- $info->save();
- }
- }
- }
- }
- }
- public static function rmInvoice($code,$orderType){
- $items = self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->select();
- if(!empty($items)){
- $orderItems=InvoiceOrder::whereIn('itemId',$items->column('id'))->select();
- if(!empty($orderItems)){
- InvoiceOrder::whereIn('itemId',$items->column('id'))->save(["status"=>3]);
- }
- self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->save(["status"=>3]);
- }
- }
- public static function CopyItem($invNo,$hpNo){
- $info = self::where(['invoiceCode'=>$invNo,'order_type'=>1])->select();
- if(!$info->isEmpty()){
- foreach($info as $item){
- $temp = $item->toArray();
- $temp['invoiceCode']=$hpNo;
- $temp['order_type']=2;
- unset($temp['id']);
- $up = self::create($temp);
- if($up->id>0){
- $orders = InvoiceOrder::where(['itemId'=>$item->id])->select();
- if(!$orders->isEmpty()){
- InvoiceOrder::create(array_map(function ($items)use ($up){
- $items['itemId']=$up->id;
- unset($items['id']);
- return $item;
- },$orders->toArray()));
- }
- }
- }
- }
- }
- }
|