StatOutClass.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. //获取总和 shish 20210829
  13. public static function getSum($where)
  14. {
  15. return StatOut::find()->where($where)->sum('amount');
  16. }
  17. //更新当前商家的数据 linqh 2021.4.13
  18. // 当采购后台,将价格更新
  19. public static function updateOrInsert($shop, $amount)
  20. {
  21. $mainId = $shop->mainId ?? 0;
  22. $time = date('Ymd');
  23. $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
  24. if (empty($stat)) {
  25. $stat = self::add(['mainId' => $mainId, 'time' => $time], true);
  26. }
  27. $id = $stat->id;
  28. $unique = self::getLockById($id);
  29. if (empty($unique)) {
  30. util::fail('没有记录');
  31. }
  32. $currentAmount = bcadd($unique->amount, $amount, 2);
  33. $unique->amount = $currentAmount;
  34. $unique->totalAmount = $shop->totalExpend;
  35. $unique->save();
  36. //当月
  37. StatOutMonthClass::updateOrInsert($shop, $amount);
  38. }
  39. }