RuleStatService.php 803 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace addons\Wechat\services;
  3. use common\components\Service;
  4. use addons\Wechat\common\models\RuleStat;
  5. /**
  6. * Class RuleStatService
  7. * @package addons\Wechat\services
  8. * @author jianyan74 <751393839@qq.com>
  9. */
  10. class RuleStatService extends Service
  11. {
  12. /**
  13. * 插入今日规则统计
  14. *
  15. * @param $rule_id
  16. */
  17. public function set($rule_id)
  18. {
  19. $ruleStat = RuleStat::find()
  20. ->where(['rule_id' => $rule_id, 'created_at' => strtotime(date('Y-m-d'))])
  21. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  22. ->one();
  23. if ($ruleStat) {
  24. $ruleStat->hit += 1;
  25. } else {
  26. $ruleStat = new RuleStat();
  27. $ruleStat->rule_id = $rule_id;
  28. }
  29. $ruleStat->save();
  30. }
  31. }
粤ICP备19079148号