| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/4/13 21:37
- */
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use common\components\util;
- class StatOutClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatOut';
- //获取总和 ssh 20210829
- public static function getSum($where)
- {
- return StatOut::find()->where($where)->sum('amount');
- }
- //更新当前商家的数据 lqh 2021.4.13
- // 当采购后台,将价格更新
- public static function updateOrInsert($main, $shop, $amount)
- {
- $mainId = $main->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $time = date('Ymd');
- $stat = self::getByCondition(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- if (empty($unique)) {
- util::fail('没有记录');
- }
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->totalAmount = $main->totalExpend;
- $unique->save();
- //当月
- StatOutMonthClass::updateOrInsert($main, $amount);
- }
- }
|