StatOrderMonthClass.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace bizHd\stat\classes;
  3. use bizHd\stat\models\StatOrderMonth;
  4. use Yii;
  5. use bizHd\base\classes\BaseClass;
  6. class StatOrderMonthClass extends BaseClass
  7. {
  8. public static $baseFile = '\bizHd\stat\models\StatOrderMonth';
  9. //月订单数增加 ssh 2020.5.25
  10. public static function addOrder($sjId, $asset, $month = null)
  11. {
  12. $month = isset($month) ? $month : date("Ym");
  13. $stat = self::getByCondition(['sjId' => $sjId, 'time' => $month], true);
  14. if (empty($stat)) {
  15. $stat = self::add(['sjId' => $sjId, 'time' => $month], true);
  16. }
  17. $stat->riseNum += 1;
  18. $stat->save();
  19. }
  20. //月订单+1
  21. public static function updateOrInsert($main, $shop)
  22. {
  23. $time = date('Ym');
  24. $mainId = $shop->mainId ?? 0;
  25. $where = ['mainId' => $mainId, 'time' => $time];
  26. $model = self::getByCondition($where, true);
  27. if (empty($model)) {
  28. $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrderNum], true);
  29. }
  30. $id = $model->id;
  31. //查id行级锁
  32. $stat = StatOrderMonthClass::getLockById($id);
  33. $stat->riseNum += 1;
  34. $stat->totalNum += 1;
  35. $stat->save();
  36. }
  37. }