| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace biz\stat\classes;
- use biz\stat\models\StatWorkCount;
- use bizHd\base\classes\BaseClass;
- class StatWorkCountClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatWorkCount';
- //每天订单
- public static function addOrder($main)
- {
- $time = date('Ymd');
- $mainId = $main->id ?? 0;
- $where = [
- 'mainId' => $mainId,
- 'time' => $time,
- ];
- $model = self::getByCondition($where, true);
- if (empty($model)) {
- $model = self::add(['mainId' => $mainId, 'time' => $time, 'riseNum' => 0, 'totalNum' => $main->totalOrder], true);
- }
- $id = $model->id;
- //查id行级锁
- $stat = StatWorkCount::findBySql('select * from ' . StatWorkCount::tableName() . ' where id = :id for update', ['id' => $id])->one();
- $stat->riseNum += 1;
- $stat->totalNum += 1;
- $stat->save();
- return $stat->riseNum;
- }
- }
|