| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use biz\stat\models\StatStockIn;
- class StatStockInClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatStockIn';
- //获取总和 ssh 20210829
- public static function getSum($where)
- {
- $amount = self::sum($where, 'amount');
- return empty($amount) ? 0 : $amount;
- }
- //入库添加或更新 ssh 20210526
- public static function replace($main, $shop, $amount)
- {
- $sjId = $shop->sjId;
- $mainId = $main->id ?? 0;
- $time = date('Ymd');
- $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, '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->totalStockIn;
- $unique->save();
- //当月
- StatStockInMonthClass::replace($main, $shop, $amount);
- }
- }
|