123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\cxinv\model;
- use think\facade\Log;
- use think\Model;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 $model){
- $code=$model->invoiceCode;
- $orderType=$model->order_type;
- $change = $model->getChangedData();
- Log::info("InvoiceItem修改发票明细:onAfterUpdate:".json_encode($change,JSON_UNESCAPED_UNICODE));
- Log::info("InvoiceItem数据:onAfterUpdate:".json_encode($model->toArray(),JSON_UNESCAPED_UNICODE));
- if(isset($change['status'])&&in_array($change["status"],[0,1,2])){
- Log::info('InvoiceItem数据:onAfterUpdate:'.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('InvoiceItem数据:onAfterUpdate:'.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)){
- foreach ($orderItems as $key=>$val){
- $val->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();
- Log::info("退票申请:".json_encode($info->toArray(),JSON_UNESCAPED_UNICODE));
- if(!$info->isEmpty()){
- $orderItems=InvoiceOrder::whereIn('itemId',$info->column('id'))->where(["status"=>[1,2]])->select();
- Log::info("退票申请:".json_encode($orderItems->toArray(),JSON_UNESCAPED_UNICODE));
- if(!$orderItems->isEmpty()){
- foreach ($orderItems as $key=>$val){
- $val->save(["status"=>4]);
- }
- Log::info("caigou:".InvoiceOrder::getLastSql());
- }
- self::where(['invoiceCode'=>$invNo,'order_type'=>2])->save(["status"=>3]);
- }
- }
- }
|