TakeCashQueryCommand.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\common\command;
  3. use app\common\model\MoneyLog;
  4. use app\common\model\TakeCash;
  5. use app\common\model\User;
  6. use app\service\WechatTransferSvc;
  7. use think\console\Command;
  8. use think\console\Input;
  9. use think\console\Output;
  10. use think\Db;
  11. use think\Log;
  12. class TakeCashQueryCommand extends Command{
  13. protected function configure()
  14. {
  15. $this->setName('tk:query')->setDescription('提现确认');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $cashes=TakeCash::where('check_status',0)
  20. ->where('status',TakeCash::STATUS_PASS)
  21. ->limit(10)
  22. ->select();
  23. $class=new WechatTransferSvc();
  24. foreach ($cashes as $cash){
  25. Db::startTrans();
  26. try {
  27. list($succ,$data)=$class->checkDetail($cash['order_no'],$cash['detail_no']);
  28. user_log('/tkquery',['cash'=>$cash['id'],'data'=>$data]);
  29. if(in_array($data['detail_status'],['SUCCESS','PROCESSING'])){
  30. $cash['check_status']=$data['detail_status']=='SUCCESS'?1:2;
  31. if($cash['check_status']==2) {
  32. $cash['check_data'] = $data['fail_reason'] ?? json_encode($data, 256);
  33. }
  34. if($cash['check_status']==2){
  35. User::money($this['amount'],$cash['user_id'],MoneyLog::TYPE_TAKECASH_REJECT,'提现打款失败');
  36. }
  37. $cash->save();
  38. }
  39. Db::commit();
  40. }catch (\Exception $e){
  41. Db::rollback();
  42. }
  43. }
  44. }
  45. }