1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace app\cxinv\model;
- use think\facade\Log;use think\Model;
- use think\model\concern\SoftDelete;
- class PaymentOrder extends Base{
- use SoftDelete;
- protected $createTime='createTime';
- protected $updateTime='updateTime';
- protected $deleteTime='delete_time';
- protected $schema=[
- 'id'=>'int',
- 'dzNo'=>'string',
- 'cgdNo'=>'string',
- 'rela_fee'=>'decimal',
- 'status'=>'tinyint',
- 'createTime'=>'datetime',
- 'updateTime'=>'datetime',
- 'delete_time'=>'datetime'
- ];
- //状态 0 关联中 1 已付款 2 解除付款 3 取消付款',
- public static function onAfterWrite(Model $model) : void{
- $cgdNo = $model->cgdNo;
- $status = $model->status;
- Log::info("PaymentOrder::onAfterWrite:".$model->cgdNo."-".$model->status);
- $cgdinfo = CgdInfo::where(["sequenceNo"=>$cgdNo,"is_del"=>0,"status"=>1])->findOrEmpty();
- if($cgdinfo->isEmpty()) return;
- switch ($status){
- case 0:
- $cgdinfo->wpay_fee= $cgdinfo->wpay_fee-$model->rela_fee;
- $cgdinfo->pay_status= 2;
- break;
- case 1:
- $cgdinfo->apay_fee= $cgdinfo->apay_fee+$model->rela_fee;
- $cgdinfo->pay_status= $cgdinfo->wpay_fee==0 && $cgdinfo->apay_fee==$cgdinfo->totalPrice-$cgdinfo->pay_tag_fee?3:2;
- break;
- case 2:
- $cgdinfo->apay_fee= $cgdinfo->apay_fee-$model->rela_fee;
- $cgdinfo->wpay_fee= $cgdinfo->wpay_fee+$model->rela_fee;
- $cgdinfo->pay_status= $cgdinfo->apay_fee==0 && $cgdinfo->wpay_fee==$cgdinfo->totalPrice-$cgdinfo->pay_tag_fee?1:2;
- break;
- case 3:
- $cgdinfo->wpay_fee= $cgdinfo->wpay_fee+$model->rela_fee;
- $cgdinfo->pay_status= $cgdinfo->apay_fee==0 && $cgdinfo->wpay_fee==$cgdinfo->totalPrice-$cgdinfo->pay_tag_fee?1:2;
- break;
- default:
- return;
- }
- $cgdinfo->save();
- Log::info("PaymentOrder::onAfterWrite-update:".self::getLastSql());
- }
- //状态 0 关联中 1 已付款 2 解除付款 3 取消付款',
- public static function checkOrder($dzNo,$status){
- $list = self::where(['dzNo'=>$dzNo,'status'=>$status==2?1:0])->field("id,cgdNo,status,rela_fee")->select();
- Log::info("PaymentOrder::checkOrder:dzNo-{$dzNo},status-{$status}");
- if($list->isEmpty()) return;
- Log::info(array_map(function($item)use($status){
- return [
- 'id'=>$item['id'],
- 'cgdNo'=>$item['cgdNo'],
- 'rela_fee'=>$item['rela_fee'],
- 'status'=>$status
- ];
- },$list->toArray()));
- (new PaymentOrder)->saveAll(array_map(function($item)use($status){
- return [
- 'id'=>$item['id'],
- 'cgdNo'=>$item['cgdNo'],
- 'rela_fee'=>$item['rela_fee'],
- 'status'=>$status
- ];
- },$list->toArray()));
- Log::info("PaymentOrder::checkOrder-update:".self::getLastSql());
- }
- }
|