|
|
@@ -7,7 +7,46 @@ use bizHd\base\classes\BaseClass;
|
|
|
|
|
|
class StatIncomeClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
public static $baseFile = '\bizHd\stat\models\StatIncome';
|
|
|
|
|
|
-}
|
|
|
+ //更新当前商家的数据 linqh 2021.4.15
|
|
|
+ // 收入更新,若无则新增
|
|
|
+ public static function updateOrInsert($sjId,$shopId,$amount)
|
|
|
+ {
|
|
|
+ $time = date('Ymd');
|
|
|
+ $where = [
|
|
|
+ 'merchantId'=>$sjId,
|
|
|
+ 'shopId'=>$shopId,
|
|
|
+ 'time'=>$time,
|
|
|
+ ];
|
|
|
+ $model = self::getByCondition($where);
|
|
|
+ if($model){
|
|
|
+ $id = $model['id'];
|
|
|
+ //累加金额 amount
|
|
|
+ $newAmount = bcadd($amount,$model['amount'],2);
|
|
|
+ $totalAmount = bcadd($amount,$model['totalAmount'],2);
|
|
|
+ self::updateById($id,['amount'=>$newAmount,'totalAmount'=>$totalAmount]);
|
|
|
+ }else{
|
|
|
+ //insert
|
|
|
+ $data = $where;
|
|
|
+ $data['amount'] = $amount;
|
|
|
+ //totalAmount = 前一天的 totalAmount
|
|
|
+ $totalAmount = 0;
|
|
|
+ $lastDate = date('Ymd',strtotime("-1 day"));
|
|
|
+ $lastWhere = [
|
|
|
+ 'merchantId'=>$sjId,
|
|
|
+ 'shopId'=>$shopId,
|
|
|
+ 'time'=>$lastDate,
|
|
|
+ ];
|
|
|
+ $lastModel = self::getByCondition($lastWhere);
|
|
|
+ if($lastModel){
|
|
|
+ $totalAmount = $lastModel['totalAmount'];
|
|
|
+ }
|
|
|
+ $data['totalAmount'] = bcadd($amount,$totalAmount,2);
|
|
|
+ $data['createTime'] = date('Y-m-d H:i:s');
|
|
|
+ self::add($data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|