|
|
@@ -26,7 +26,7 @@ class StatIncomeClass extends BaseClass
|
|
|
$model = self::getByCondition($where, true);
|
|
|
if (empty($model)) {
|
|
|
$data = [
|
|
|
- 'shopId'=>$shopId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
'time' => $time,
|
|
|
'amount' => 0,
|
|
|
'totalAmount' => $shop->totalIncome,
|
|
|
@@ -36,7 +36,7 @@ class StatIncomeClass extends BaseClass
|
|
|
}
|
|
|
$id = $model->id;
|
|
|
//查id行级锁
|
|
|
- $stat = StatIncome::findBySql('select * from ' . StatIncome::tableName() . ' where id = :id for update', ['id' => $id])->one();
|
|
|
+ $stat = StatIncomeClass::getLockById($id);
|
|
|
$stat->amount = bcadd($amount, $stat->amount, 2);
|
|
|
$stat->totalAmount = bcadd($amount, $shop->totalIncome, 2);
|
|
|
$stat->save();
|
|
|
@@ -48,16 +48,16 @@ class StatIncomeClass extends BaseClass
|
|
|
public static function getAmountToday($shopId)
|
|
|
{
|
|
|
$time = date('Ymd');
|
|
|
- $res = self::getDetail($shopId,$time);
|
|
|
- return $res['amount']??0;
|
|
|
+ $res = self::getDetail($shopId, $time);
|
|
|
+ return $res['amount'] ?? 0;
|
|
|
}
|
|
|
|
|
|
//yesterday
|
|
|
public static function getAmountYesterday($shopId)
|
|
|
{
|
|
|
- $time = date('Ymd',strtotime("-1 days"));
|
|
|
- $res = self::getDetail($shopId,$time);
|
|
|
- return $res['amount']??0;
|
|
|
+ $time = date('Ymd', strtotime("-1 days"));
|
|
|
+ $res = self::getDetail($shopId, $time);
|
|
|
+ return $res['amount'] ?? 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -65,8 +65,8 @@ class StatIncomeClass extends BaseClass
|
|
|
public static function getAmountWeek($shopId)
|
|
|
{
|
|
|
$end = date('Ymd');
|
|
|
- $start = date('Ymd',strtotime("-7 days"));
|
|
|
- return self::getAmountByTime($shopId,$start,$end);
|
|
|
+ $start = date('Ymd', strtotime("-7 days"));
|
|
|
+ return self::getAmountByTime($shopId, $start, $end);
|
|
|
}
|
|
|
|
|
|
//30天输入金额
|
|
|
@@ -74,13 +74,13 @@ class StatIncomeClass extends BaseClass
|
|
|
{
|
|
|
|
|
|
$end = date('Ymd');
|
|
|
- $start = date('Ymd',strtotime("-30 days"));
|
|
|
- return self::getAmountByTime($shopId,$start,$end);
|
|
|
+ $start = date('Ymd', strtotime("-30 days"));
|
|
|
+ return self::getAmountByTime($shopId, $start, $end);
|
|
|
}
|
|
|
|
|
|
|
|
|
//查询某一天的信息
|
|
|
- public static function getDetail($shopId,$time)
|
|
|
+ public static function getDetail($shopId, $time)
|
|
|
{
|
|
|
$where = [
|
|
|
'shopId' => $shopId,
|
|
|
@@ -90,16 +90,16 @@ class StatIncomeClass extends BaseClass
|
|
|
return $model;
|
|
|
}
|
|
|
|
|
|
- public static function getAmountByTime($shopId,$start,$end)
|
|
|
+ public static function getAmountByTime($shopId, $start, $end)
|
|
|
{
|
|
|
$where = [];
|
|
|
$where['shopId'] = $shopId;
|
|
|
$where['time'] = ['between', [$start, $end]];
|
|
|
- $res = self::getAllByCondition($where,null,"amount");
|
|
|
+ $res = self::getAllByCondition($where, null, "amount");
|
|
|
$amount = 0;
|
|
|
- if($res){
|
|
|
- foreach ($res as $v){
|
|
|
- $amount = bcadd($amount,$v['amount'],2);
|
|
|
+ if ($res) {
|
|
|
+ foreach ($res as $v) {
|
|
|
+ $amount = bcadd($amount, $v['amount'], 2);
|
|
|
}
|
|
|
}
|
|
|
return $amount;
|