Cang.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * 持仓到期自动结算
  4. * User: qissen
  5. * Date: 2017/11/26
  6. * Time: 11:26a
  7. */
  8. namespace app\crontab\command;
  9. use app\core\model\Cang as Model;
  10. use app\core\model\CangRepay;
  11. use think\console\Command;
  12. use think\console\Input;
  13. use think\console\Output;
  14. use think\Log;
  15. use tool\Common;
  16. class Cang extends Command
  17. {
  18. protected function configure()
  19. {
  20. $this->setName('Cang')->setDescription('Cang开始');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. //在这里我们进行结算
  25. Log::info('Cang:'.Common::timetodate(THINK_START_TIME));
  26. $this->setStatusInterest();
  27. $this->setStatusRepayIng();
  28. $output->writeln("Cang开始");
  29. }
  30. /**
  31. * 设置持仓状态:持有状态->计息状态
  32. */
  33. private function setStatusInterest() {
  34. Model::where([
  35. 'interestBeginTime'=>['lt', THINK_START_TIME],
  36. 'status'=>Model::STATUS_PAY
  37. ])->chunk(100, function($list) {
  38. foreach ($list as $item) {
  39. $item->status = Model::STATUS_INTEREST;
  40. $item->save();
  41. }
  42. });
  43. }
  44. /**
  45. * 设置持仓状态:计息状态->回款中
  46. */
  47. private function setStatusRepayIng() {
  48. //兼容老佳乾,老佳乾客户全部转移后,可注释
  49. Model::where([
  50. 'interestEndTime'=>['lt', THINK_START_TIME],
  51. 'alias'=>'',
  52. 'status'=>Model::STATUS_INTEREST
  53. ])->chunk(100, function($list) {
  54. foreach ($list as $item) {
  55. $item->status = Model::STATUS_REPAY;
  56. $item->save();
  57. }
  58. });
  59. //end
  60. Model::where([
  61. 'interestEndTime'=>['lt', THINK_START_TIME - 86400],
  62. 'alias'=>['neq', ''],
  63. 'status'=>Model::STATUS_INTEREST
  64. ])->chunk(100, function($list) {
  65. foreach ($list as $item) {
  66. $item->status = Model::STATUS_REPAY;
  67. $item->save();
  68. }
  69. });
  70. }
  71. }