BaseBusiness.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace common\helpers\bonus\Calc;
  3. use common\models\Period;
  4. use common\traits\ResponseTrait;
  5. class BaseBusiness
  6. {
  7. use ResponseTrait;
  8. protected $_periodNum = 0;
  9. protected $_calc_db_name = 'dbCalc';
  10. const CALC_DB_NAME = 'dbCalc';
  11. protected $_limit = 10000;
  12. //最小生成自动合格订单的业绩
  13. public static $automaticEntitlementPerf = 30;
  14. public function __construct($periodNum)
  15. {
  16. if (is_numeric($periodNum)) {
  17. $this->_periodNum = $periodNum;
  18. $periodObj = Period::instance();
  19. // $periodDataArr = $periodObj->setPeriodNum($periodNum);
  20. // $this->_periodId = $periodDataArr['ID'];
  21. $this->_isCalcMonth = $periodObj->isCalcMonth($periodNum);
  22. $this->_calcYear = $periodObj->getYear($periodNum);
  23. $this->_calcMonth = $periodObj->getMonth($periodNum);
  24. $this->_calcYearMonth = $periodObj->getYearMonth($periodNum);
  25. $this->_periodId = $periodObj->getPeriodIdByNumber($periodNum);
  26. } else {
  27. //todo
  28. return false;
  29. }
  30. }
  31. /**
  32. * 从结算系统拉取周期信息并更新
  33. * @return int
  34. */
  35. public static function pullPeriodForUpdate($periodNum = 0): int
  36. {
  37. if (empty($periodNum) || !is_numeric($periodNum)) {
  38. return 0;
  39. }
  40. $db = self::CALC_DB_NAME;
  41. //同步字段去掉 IS_CALCULATED, 否则自动拉取的轮询间隔之间奖金计算完成后更新该字段则会认为已经拉取过奖金数据
  42. $period = \Yii::$app->$db->createCommand("SELECT
  43. PERIOD_NUM,
  44. IS_PERFED,
  45. IS_PERFING,
  46. IS_CALCING,
  47. PERF_PERCENT,
  48. CALC_PERCENT,
  49. PERF_STARTED_AT,
  50. PERFED_AT,
  51. CALCULATE_STARTED_AT,
  52. CALCULATED_AT
  53. FROM AR_PERIOD where PERIOD_NUM = $periodNum")->queryOne();
  54. return Period::updateAll($period, ['PERIOD_NUM' => $periodNum]);
  55. }
  56. public function getCalcPeriod()
  57. {
  58. $db = $this->_calc_db_name;
  59. return \Yii::$app->$db->createCommand("SELECT * FROM AR_PERIOD where PERIOD_NUM = $this->_periodNum")->queryOne();
  60. }
  61. public function getMonthsForQuarterly()
  62. {
  63. $startTime = strtotime(date('Y') . '0101');
  64. $calcMonth1 = date('Ym', strtotime('+' . ($this->_calcMonth - 1) . ' month', $startTime));
  65. $calcMonth2 = date('Ym', strtotime('+' . ($this->_calcMonth - 2) . ' month', $startTime));
  66. return [$calcMonth1, $calcMonth2];
  67. }
  68. }