| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use biz\stat\models\StatStockOut;
- class StatStockOutClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatStockOut';
- //获取总和 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(['sjId' => $sjId, 'time' => $time, 'mainId' => $mainId], 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->totalStockOut;
- $unique->save();
- //当月
- StatStockOutMonthClass::replace($main, $shop, $amount);
- }
- //今天出库金额 ssh 20210526
- public static function getTodayAmount($shop)
- {
- if (empty($shop)) {
- return 0;
- }
- $today = date("Ymd");
- $shopId = $shop->id;
- $sjId = $shop->sjId;
- $out = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'time' => $today], true);
- return $out->amount ?? 0;
- }
- }
|