StatWorkCountClass.php 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\stat\models\StatWorkCount;
  4. use bizHd\base\classes\BaseClass;
  5. class StatWorkCountClass extends BaseClass
  6. {
  7. public static $baseFile = '\biz\stat\models\StatWorkCount';
  8. //每天订单
  9. public static function addOrder($main)
  10. {
  11. $time = date('Ymd');
  12. $mainId = $main->id ?? 0;
  13. $where = [
  14. 'mainId' => $mainId,
  15. 'time' => $time,
  16. ];
  17. $model = self::getByCondition($where, true);
  18. if (empty($model)) {
  19. $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrder], true);
  20. }
  21. $id = $model->id;
  22. //查id行级锁
  23. $stat = StatWorkCount::findBySql('select * from ' . StatWorkCount::tableName() . ' where id = :id for update', ['id' => $id])->one();
  24. $stat->riseNum += 1;
  25. $stat->totalNum += 1;
  26. $stat->save();
  27. return $stat->riseNum;
  28. }
  29. }