12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2021/4/15
- * Time: 13:57
- */
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class GameStatementsDetail extends Model
- {
- protected $table = 'game_statements_detail';
- public $timestamps = false;
- public static function calculateSubtotal($orderList)
- {
- $monthData = [];
- $total = [];
- foreach($orderList as $order) {
- $order['actual_consumption'] = isset($order['actual_consumption']) ? $order['actual_consumption'] : 0;
- $order['discount_amount'] = isset($order['discount_amount']) ? $order['discount_amount'] : 0;
- $order['link_fee'] = isset($order['link_fee']) ? $order['link_fee'] : 0;
- $order['top_fee'] = isset($order['top_fee']) ? $order['top_fee'] : 0;
- $order['flow_boost_back_point'] = isset($order['flow_boost_back_point']) ? $order['flow_boost_back_point'] : 0;
- $order['total_amount'] = isset($order['total_amount']) ? $order['total_amount'] : 0;
- $order['discount_rate'] = isset($order['discount_rate']) ? $order['discount_rate'] :
- ($order['actual_consumption'] > 0 ? round($order['discount_amount'] / $order['actual_consumption'], 4) : 0);
- $total['actual_consumption'] = isset($total['actual_consumption']) ? $total['actual_consumption'] + $order['actual_consumption'] : $order['actual_consumption'];
- $total['discount_amount'] = isset($total['discount_amount']) ? $total['discount_amount'] + $order['discount_amount'] : $order['discount_amount'];
- $total['link_fee'] = isset($total['link_fee']) ? $total['link_fee'] + $order['link_fee'] : $order['link_fee'];
- $total['top_fee'] = isset($total['top_fee']) ? $total['top_fee'] + $order['top_fee'] : $order['top_fee'];
- $total['flow_boost_back_point'] = isset($total['flow_boost_back_point']) ? $total['flow_boost_back_point'] + $order['flow_boost_back_point'] : $order['flow_boost_back_point'];
- $total['total_amount'] = isset($total['total_amount']) ? $total['total_amount'] + $order['total_amount'] : $order['total_amount'];
- $key = $order['sort_month'].'@'.$order['proejct_name'];
- if (isset($monthData[$key])) {
- if($monthData[$key]['sort_month_format'] == $order['sort_month']) {
- $monthData[$key]['actual_consumption'] += $order['actual_consumption'];
- $monthData[$key]['discount_amount'] += $order['discount_amount'];
- $monthData[$key]['link_fee'] += $order['link_fee'];
- $monthData[$key]['top_fee'] += $order['top_fee'];
- $monthData[$key]['flow_boost_back_point'] += $order['flow_boost_back_point'];
- $monthData[$key]['total_amount'] += $order['total_amount'];
- }
- } else {
- $monthData[$key]['actual_consumption'] = $order['actual_consumption'];
- $monthData[$key]['discount_amount'] = $order['discount_amount'];
- $monthData[$key]['link_fee'] = $order['link_fee'];
- $monthData[$key]['top_fee'] = $order['top_fee'];
- $monthData[$key]['flow_boost_back_point'] = $order['flow_boost_back_point'];
- $monthData[$key]['total_amount'] = $order['total_amount'];
- $monthData[$key]['sort_month'] = date('Y年m月', strtotime($order['sort_month']));
- $monthData[$key]['sort_month_format'] = $order['sort_month'];
- }
- // 将当月数据写入
- $order['sort_month'] = date('Y年m月', strtotime($order['sort_month']));
- $order['month'] = date('Y年m月', strtotime($order['month']));
- $order['order_original_month'] = !empty($order['order_original_month']) ? date('Y年m月', strtotime($order['order_original_month'])) : '';
- $monthData[$key]['row'][] = $order;
- }
- ksort($monthData);
- return ['list' => array_values($monthData), 'total' => $total];
- }
- }
|