| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace bizHd\stat\classes;
- use bizHd\stat\models\StatOrder;
- use bizHd\base\classes\BaseClass;
- class StatOrderClass extends BaseClass
- {
- public static $baseFile = '\bizHd\stat\models\StatOrder';
- //今日订单+1
- public static function updateOrInsert($main, $shop)
- {
- $time = date('Ymd');
- $mainId = $shop->mainId ?? 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->totalOrderNum], true);
- }
- $id = $model->id;
- //查id行级锁
- $stat = StatOrderClass::getLockById($id);
- $stat->riseNum += 1;
- $stat->totalNum += 1;
- $stat->save();
- //本月订单+1
- StatOrderMonthClass::updateOrInsert($main, $shop);
- }
- public static function getRiseNumToday($shopId)
- {
- $time = date('Ymd');
- $res = self::getDetail($shopId, $time);
- return $res['riseNum'] ?? 0;
- }
- //yesterday
- public static function getRiseNumYesterday($shopId)
- {
- $time = date('Ymd', strtotime("-1 days"));
- $res = self::getDetail($shopId, $time);
- return $res['riseNum'] ?? 0;
- }
- public static function getDetail($shopId, $time)
- {
- $where = [
- 'shopId' => $shopId,
- 'time' => $time,
- ];
- $model = self::getByCondition($where);
- return $model;
- }
- //近7天
- public static function getRiseNumWeek($shopId)
- {
- $end = date('Ymd');
- $start = date('Ymd', strtotime("-6 days"));
- return self::getRiseNumByTime($shopId, $start, $end);
- }
- //近30天
- public static function getRiseNumThirty($shopId)
- {
- $end = date('Ymd');
- $start = date('Ymd', strtotime("-29 days"));
- return self::getRiseNumByTime($shopId, $start, $end);
- }
- public static function getRiseNumByTime($shopId, $start, $end)
- {
- $where = [];
- $where['shopId'] = $shopId;
- $where['time'] = ['between', [$start, $end]];
- $res = self::getAllByCondition($where, null, "riseNum");
- $riseNum = 0;
- if ($res) {
- foreach ($res as $v) {
- $riseNum = bcadd($riseNum, $v['riseNum'], 0);
- }
- }
- return $riseNum;
- }
- }
|