BaseBusiness.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = 'dbCalcServer';
  10. const CALC_DB_NAME = 'dbCalcServer';
  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. } else {
  26. //todo
  27. return false;
  28. }
  29. }
  30. /**
  31. * 从结算系统拉取周期信息并更新
  32. * @return int
  33. */
  34. public static function pullPeriodForUpdate($periodNum = 0): int
  35. {
  36. if (empty($periodNum) || !is_numeric($periodNum)) {
  37. return 0;
  38. }
  39. $db = self::CALC_DB_NAME;
  40. //同步字段去掉 IS_CALCULATED, 否则自动拉取的轮询间隔之间奖金计算完成后更新该字段则会认为已经拉取过奖金数据
  41. $period = \Yii::$app->$db->createCommand("SELECT
  42. PERIOD_NUM,
  43. IS_PERFED,
  44. IS_PERFING,
  45. IS_CALCING,
  46. PERF_PERCENT,
  47. CALC_PERCENT,
  48. PERF_STARTED_AT,
  49. PERFED_AT,
  50. CALCULATE_STARTED_AT,
  51. CALCULATED_AT
  52. FROM AR_PERIOD where PERIOD_NUM = $periodNum")->queryOne();
  53. return Period::updateAll($period, ['PERIOD_NUM' => $periodNum]);
  54. }
  55. public function getCalcPeriod()
  56. {
  57. $db = $this->_calc_db_name;
  58. return \Yii::$app->$db->createCommand("SELECT * FROM AR_PERIOD where PERIOD_NUM = $this->_periodNum")->queryOne();
  59. }
  60. public function getMonthsForQuarterly()
  61. {
  62. $startTime = strtotime(date('Y') . '0101');
  63. $calcMonth1 = date('Ym', strtotime('+' . ($this->_calcMonth - 1) . ' month', $startTime));
  64. $calcMonth2 = date('Ym', strtotime('+' . ($this->_calcMonth - 2) . ' month', $startTime));
  65. return [$calcMonth1, $calcMonth2];
  66. }
  67. }