DoWithdraw.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Created by: PhpStorm
  4. * User: lytian
  5. * Date: 2020/3/11
  6. * Time: 19:02
  7. */
  8. namespace app\admin\command;
  9. use app\common\model\User;
  10. use think\console\Command;
  11. use think\console\Input;
  12. use think\console\Output;
  13. use think\Request;
  14. class DoWithdraw extends Command
  15. {
  16. /**
  17. * @var User
  18. */
  19. private $model = null;
  20. private $redis = null;
  21. protected function configure()
  22. {
  23. $this->setName('DoWithdraw')
  24. ->setDescription('提现');
  25. }
  26. protected function execute(Input $input, Output $output)
  27. {
  28. Request::instance()->module('admin'); //cli模式下无法获取到当前的项目模块,手动指定一下
  29. die;
  30. $channel_ids = [17278, 17279, 17281, 17282, 17283, 17284, 17285, 17286, 17287, 17288, 18545, 18546, 18547];
  31. foreach ($channel_ids as $channel_id) {
  32. $admin_money = model("AdminMoney")->where("admin_id", 'eq', $channel_id)->find();
  33. if (empty($admin_money)) {
  34. echo "渠道商{$channel_id} 没有汇总 因此跳过";
  35. continue;
  36. }
  37. $total_collect = model("OrdersCollect")->sumCollect($channel_id, 1, 3, '20181001', '20200229');
  38. $channelTotalSplitMoney = $total_collect['split_money'] ?? 0;
  39. $no_cash_money = ($total_collect['recharge_money_benefit'] ?? 0) - $admin_money['cash_money'] - $admin_money['count_cash_money'] - $channelTotalSplitMoney;
  40. $no_cash_money = (string)sprintf("%.2f", $no_cash_money);
  41. if ($no_cash_money < 10) {
  42. //直接跳过 记录日志
  43. echo "渠道商{$channel_id} 可提现金额小于10元 因此跳过";
  44. echo "可提现金额小于10元 因此跳过";
  45. continue;
  46. }
  47. $save['etime'] = '20200229';
  48. $stime = model('withdraw')->where('admin_id', $channel_id)->field('etime')->order('id desc')->find();
  49. if (empty($stime['etime'])) {
  50. $save['stime'] = null;
  51. } else {
  52. $save['stime'] = date('Ymd', strtotime($stime['etime']) + 3600 * 24);
  53. }
  54. $save['admin_id'] = $channel_id;
  55. $save['money'] = $no_cash_money;//含手续费
  56. $save['state'] = 1;
  57. $save['createtime'] = time();
  58. $save['updatetime'] = time();
  59. var_dump($save);die;
  60. if (model('withdraw')->insertGetId($save)) {
  61. model('AdminMoney')->where('admin_id', $channel_id)->setInc('cash_money', $no_cash_money);
  62. echo "提现成功";
  63. }
  64. }
  65. }
  66. }