StatOutClass.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/4/13 21:37
  5. */
  6. namespace biz\stat\classes;
  7. use biz\base\classes\BaseClass;
  8. use common\components\util;
  9. class StatOutClass extends BaseClass
  10. {
  11. public static $baseFile = '\biz\stat\models\StatOut';
  12. //获取总和 ssh 20210829
  13. public static function getSum($where)
  14. {
  15. return StatOut::find()->where($where)->sum('amount');
  16. }
  17. //更新当前商家的数据 lqh 2021.4.13
  18. // 当采购后台,将价格更新
  19. public static function updateOrInsert($main, $shop, $amount)
  20. {
  21. $mainId = $main->id ?? 0;
  22. $sjId = $shop->sjId ?? 0;
  23. $time = date('Ymd');
  24. $stat = self::getByCondition(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
  25. if (empty($stat)) {
  26. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
  27. }
  28. $id = $stat->id;
  29. $unique = self::getLockById($id);
  30. if (empty($unique)) {
  31. util::fail('没有记录');
  32. }
  33. $currentAmount = bcadd($unique->amount, $amount, 2);
  34. $unique->amount = $currentAmount;
  35. $unique->totalAmount = $main->totalExpend;
  36. $unique->save();
  37. //当月
  38. StatOutMonthClass::updateOrInsert($main, $amount);
  39. }
  40. }