StatOrderCountClass.php 1.0 KB

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