|
@@ -0,0 +1,102 @@
|
|
|
+<?php
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\cxinv\command;
|
|
|
+
|
|
|
+use app\cxinv\model\Assoc;use app\cxinv\model\QrdInfo;use app\cxinv\model\Trade;use app\cxinv\model\TradePool;use think\console\Command;
|
|
|
+use think\console\Input;
|
|
|
+use think\console\input\Argument;
|
|
|
+use think\console\input\Option;
|
|
|
+use think\console\Output;use think\facade\Cache;
|
|
|
+
|
|
|
+class CheckTrade extends Command
|
|
|
+{
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ // 指令配置
|
|
|
+ $this->setName('checktrade')
|
|
|
+ ->setDescription('the checktrade command');
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(Input $input, Output $output)
|
|
|
+ {
|
|
|
+ if(Cache::get('checkTradePlus')==1)return;
|
|
|
+ $list = $this->getTrade();
|
|
|
+ while ($list->valid()){
|
|
|
+ Cache::set('checkTradePlus',1,100);
|
|
|
+ $item = $list->current();
|
|
|
+ $this->checkTrade($item);
|
|
|
+ $list->next();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getTrade(){
|
|
|
+ $list = Trade::where([['status','=',1],["is_del","=",0],['updatetime','<=',date('Y-m-d H:i:s')]])->cursor();
|
|
|
+ foreach ($list as $item){
|
|
|
+ yield $item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function checkTrade($item){
|
|
|
+ if($item['customerNo'] == ''||$item['companyNo'] == ''){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $qrd = QrdInfo::where([['customerNo','=',$item['customerNo']],['companyNo','=',$item['companyNo']],['pay_status','=',1],['wpay_fee','=',$item['balance']]])->findOrEmpty();
|
|
|
+ if($qrd->isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QrdInfo::startTrans();
|
|
|
+ try{
|
|
|
+ $qrd->pay_status = 3;
|
|
|
+ $qrd->apay_fee = $item['balance'];
|
|
|
+ $qrd->wpay_fee = 0;
|
|
|
+ $result= $qrd->save();
|
|
|
+ if($result==false) throw new \Exception("订单{$qrd->sequenceNo}更新失败");
|
|
|
+ $tradup= Trade::where([['status','=',1],["is_del","=",0],["id","=",$item['id']]])->update(['status'=>3,"balance"=>0,"used_fee"=>$item['balance']]);
|
|
|
+ if($tradup==false) throw new \Exception("交易流水{$item['tradNo']}更新失败");
|
|
|
+ $this->makeAssoc($item,$qrd);
|
|
|
+ QrdInfo::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ QrdInfo::rollback();
|
|
|
+ echo $e->getMessage().PHP_EOL;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ echo "交易流水{$item['tradNo']}关联顶动感{$qrd->sequenceNo}更新成功".PHP_EOL;
|
|
|
+ }
|
|
|
+ public function makeAssoc($item,$qrd){
|
|
|
+ $TradeLog=[
|
|
|
+ 'logNo'=>makeNo("TRC"),
|
|
|
+ 'tradNo'=>$item['tradNo'],
|
|
|
+ 'platform_type'=>$qrd['platform_type']??0,
|
|
|
+ 'companyNo'=>$item['companyNo'],
|
|
|
+ 'customerNo'=>$item['customerNo'],
|
|
|
+ 'apply_id'=>0,
|
|
|
+ 'apply_name'=>'system',
|
|
|
+ 'trade_time'=>$item['trade_time'],
|
|
|
+ 'total_fee'=>$item['balance'],
|
|
|
+ 'status'=>2,
|
|
|
+ 'addtime'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updatetime'=>date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+ $result= TradePool::create($TradeLog);
|
|
|
+ if($result==false) throw new \Exception("交易流水关联记录{$TradeLog['logNo']}插入失败");
|
|
|
+ $Assoc=[
|
|
|
+ 'assocNo'=>makeNo('AS'),
|
|
|
+ 'apply_id'=>0,
|
|
|
+ 'apply_name'=>'system',
|
|
|
+ 'type'=>2,
|
|
|
+ 'orderCode'=>$qrd['sequenceNo'],
|
|
|
+ 'customerNo'=>$qrd['customerNo'],
|
|
|
+ 'viceCode'=>$TradeLog['logNo'],
|
|
|
+ 'order_total'=>$qrd['totalPrice'],
|
|
|
+ 'vice_total'=>$item['balance'],
|
|
|
+ 'cancel_fee'=>$item['balance'],
|
|
|
+ 'status'=>2,
|
|
|
+ 'addtime'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updatetime'=>date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+ $as= Assoc::create($Assoc);
|
|
|
+ if($as==false) throw new \Exception("订单关联记录{$Assoc['assocNo']}插入失败");
|
|
|
+ }
|
|
|
+}
|