12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\cxinv\model;
- use think\facade\Log;
- use think\model\concern\SoftDelete;
- class InvoiceItem extends Base{
- 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")->whereIn('status', [1, 2]);
- }
- 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(isset($change['status'])&&in_array($change["status"],[0,1,2])){
- Log::info('跟后数据:'.json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
- $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= Invoice::where(['InvCode'=>$code,"status"=>1])->findOrEmpty();
- Log::info('跟后数据:'.json_encode( $info->toArray(),JSON_UNESCAPED_UNICODE));
- if(!$info->isEmpty()){
- if ($num==0){
- $info->status=2;
- $info->save();
- }
- }
- }
- }
- }
- public static function rmInvoice($code,$orderType=2){
- $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,"status"=>[1,2]])->select();
- if(!$orders->isEmpty()){
- InvoiceOrder::create(array_map(function ($items)use ($up){
- $items['itemId']=$up->id;
- unset($items['id']);
- return $items;
- },$orders->toArray()));
- }
- }
- }
- }
- }
- }
|