| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use common\components\util;
- class StatPdSubMonthClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatPdSubMonth';
- //每月盘亏统计 ssh 20210827
- public static function replace($main, $shop, $amount, $date = null)
- {
- if ($date == null) {
- $time = date('Ym');
- $year = date('Y');
- $month = date('m');
- } else {
- $timestamp = strtotime($date);
- $time = date('Ym', $timestamp);
- $year = date('Y', $timestamp);
- $month = date('m', $timestamp);
- }
- $sjId = $shop->sjId;
- $shopId = $shop->id;
- $mainId = $main->id ?? 0;
- $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['shopId' => $shopId, 'mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->totalAmount = $main->totalPdSub;
- $unique->num += 1;
- $unique->save();
- }
- }
|