| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace bizHd\stat\classes;
- use bizHd\stat\models\StatIncomeMonth;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class StatIncomeMonthClass extends BaseClass
- {
- public static $baseFile = '\bizHd\stat\models\StatIncomeMonth';
- public static function updateOrInsert($main, $shop, $amount)
- {
- $time = date('Ym');
- $mainId = $shop->mainId ?? 0;
- $where = ['mainId' => $mainId, 'time' => $time,];
- $model = self::getByCondition($where, true);
- if (empty($model)) {
- $data = ['mainId' => $mainId, 'time' => $time, 'amount' => 0, 'totalAmount' => $main->totalIncome, 'createTime' => date('Y-m-d H:i:s')];
- $model = self::add($data, true);
- }
- $id = $model->id;
- //查id行级锁
- $stat = StatIncomeMonthClass::getLockById($id);
- $stat->amount = bcadd($amount, $stat->amount, 2);
- $stat->totalAmount = $main->totalIncome;
- $stat->save();
- }
- //查询当天收入金额
- public static function getAmountMonth($shopId)
- {
- $time = date('Ym');
- $res = self::getDetail($shopId, $time);
- return $res['amount'] ?? 0;
- }
- //查询某一个月的信息
- public static function getDetail($shopId, $time)
- {
- $where = [
- 'shopId' => $shopId,
- 'time' => $time,
- ];
- $model = self::getByCondition($where);
- return $model;
- }
- }
|