ChartData.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/6/12
  6. * Time: 下午2:11
  7. */
  8. namespace common\helpers;
  9. use common\models\CalcBonus;
  10. use common\models\Period;
  11. use yii\base\BaseObject;
  12. use yii\base\StaticInstanceTrait;
  13. class ChartData extends BaseObject
  14. {
  15. use StaticInstanceTrait;
  16. public function userBonusData($userId){
  17. $period = Period::instance();
  18. $calcMonth = $period->getNowYearMonth();
  19. $formatCalcMonth = substr($calcMonth, 0, 4).'-'.substr($calcMonth, 4, 2).'-01';
  20. $calcMonths = [
  21. [
  22. 'month' => $calcMonth,
  23. ],
  24. [
  25. 'month' => Date::lastNumMonth(1, strtotime($formatCalcMonth), 'Ym'),
  26. ],
  27. [
  28. 'month' => Date::lastNumMonth(2, strtotime($formatCalcMonth), 'Ym'),
  29. ],
  30. [
  31. 'month' => Date::lastNumMonth(3, strtotime($formatCalcMonth), 'Ym'),
  32. ],
  33. [
  34. 'month' => Date::lastNumMonth(4, strtotime($formatCalcMonth), 'Ym'),
  35. ],
  36. ];
  37. foreach($calcMonths as $key => $value){
  38. $calcMonths[$key] = array_merge($calcMonths[$key], $this->_userMonthBonus($value['month'], $userId));
  39. }
  40. return array_reverse($calcMonths);
  41. }
  42. private function _userMonthBonus($calcMonth, $userId){
  43. $bonus = CalcBonus::findUseSlaves()->yearMonth($calcMonth)->select('BONUS_QY, BONUS_YC, BONUS_FX, BONUS_LS, BONUS_CF, BONUS_LX, BONUS_FL, BONUS_BT, BONUS_FW')->where('CALC_MONTH=:CALC_MONTH AND IS_SENT=1 AND USER_ID=:USER_ID', [':CALC_MONTH'=>$calcMonth, ':USER_ID'=>$userId])->asArray()->one();
  44. if($bonus){
  45. return [
  46. 'BONUS_QY' => $bonus['BONUS_QY'],
  47. 'BONUS_YC' => $bonus['BONUS_YC'],
  48. 'BONUS_FX' => $bonus['BONUS_FX'],
  49. 'BONUS_LS' => $bonus['BONUS_LS'],
  50. 'BONUS_CF' => $bonus['BONUS_CF'],
  51. 'BONUS_LX' => $bonus['BONUS_LX'],
  52. 'BONUS_FL' => $bonus['BONUS_FL'],
  53. 'BONUS_BT' => $bonus['BONUS_BT'],
  54. 'BONUS_FW' => $bonus['BONUS_FW'],
  55. ];
  56. } else {
  57. return [
  58. 'BONUS_QY' => 0,
  59. 'BONUS_YC' => 0,
  60. 'BONUS_FX' => 0,
  61. 'BONUS_LS' => 0,
  62. 'BONUS_CF' => 0,
  63. 'BONUS_LX' => 0,
  64. 'BONUS_FL' => 0,
  65. 'BONUS_BT' => 0,
  66. 'BONUS_FW' => 0,
  67. ];
  68. }
  69. }
  70. }