| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/4/13 21:37
- */
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- class StatOutClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatOut';
- //更新当前商家的数据 linqh 2021.4.13
- // 当采购后台,将价格更新,若无则新增 ps 总支出金额暂不累计
- 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);
- }
- }
- }
|