1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?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==2 && $num==0){
- $info= PayInvoice::where(['hpNo'=>$code,"status"=>11])->findOrEmpty();
- Log::info('跟后数据:'.json_encode( $info->toArray(),JSON_UNESCAPED_UNICODE));
- if(!$info->isEmpty()){
- $info->status=12;
- $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 refund($invNo){
- $info = self::where(['invoiceCode'=>$invNo,'order_type'=>2])->select();
- if(!$info->isEmpty()){
- $orderItems=InvoiceOrder::whereIn('itemId',$info->column('id'))->where(["status"=>[1,2]])->select();
- if(!$orderItems->isEmpty()){
- InvoiceOrder::whereIn('itemId',$info->column('id'))->where(['status'=>[1,2]])->save(["status"=>4]);
- }
- self::where(['invoiceCode'=>$invNo,'order_type'=>2])->save(["status"=>3]);
- }
- }
- }
|