whereIn('id', $orderIds) ->where('enable', 1)->get()->keyBy('id')->toArray(); $ECommerceColmus = 'actual_consumption'; if(1 == $isDiscount) { $ECommerceColmus = 'discount_amount'; } switch($type){ case 3: $colums = $ECommerceColmus; break; default: $colums = 'total_amount'; break; } $salerStatementsDetailsList = SalerStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount') ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id') ->get()->keyBy('order_id')->toArray(); $ECommerceStatementsDetailsList = ECommerceStatementsDetail::selectRaw('order_id, sum('.$ECommerceColmus.') as total_amount') ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id') ->get()->keyBy('order_id')->toArray(); $GameStatementsDetailsList = GameStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount') ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id') ->get()->keyBy('order_id')->toArray(); $CPAStatementsDetailsList = CPAStatementsDetail::selectRaw('order_id, sum(total_amount) as total_amount') ->whereIn('order_id', $orderIds)->where('enable', 1)->groupBy('order_id') ->get()->keyBy('order_id')->toArray(); foreach ($orderData as $order) { $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null; $salerStatementsDetailInfo = isset($salerStatementsDetailsList[$order['order_id']]) ? $salerStatementsDetailsList[$order['order_id']] : 0; $ECommerceStatementsDetailInfo = isset($ECommerceStatementsDetailsList[$order['order_id']]) ? $ECommerceStatementsDetailsList[$order['order_id']] : 0; $CPAStatementsDetailInfo = isset($CPAStatementsDetailsList[$order['order_id']]) ? $CPAStatementsDetailsList[$order['order_id']] : 0; $GameStatementsDetailInfo = isset($GameStatementsDetailsList[$order['order_id']]) ? $GameStatementsDetailsList[$order['order_id']] : 0; if (empty($orderInfo) || ($orderInfo['final_amount'] < ( $order[$colums] + $salerStatementsDetailInfo['total_amount'] + $ECommerceStatementsDetailInfo['total_amount'] + $CPAStatementsDetailInfo['total_amount'] + $GameStatementsDetailInfo['total_amount'] ))) { return false; } } return true; } /* * 状态机 */ public static function getStatementsEnableStatus($statementsData, $user) { if ($user->role_id == 15) { return [2,3]; } else if (in_array($user->role_id,[10, 17, 21])) { return [4,5]; } else { return []; } } public static function chargeSalerAmountSecond($orderData, $isDiscount, $type) { $orderIds = array_column($orderData, 'order_id'); $orderList = Order::query() ->select('final_amount','id') ->whereIn('id', $orderIds) ->where('enable', 1) ->get() ->keyBy('id') ->toArray(); foreach ($orderData as $order) { $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null; $orderInfo['final_amount'] = $orderInfo['final_amount'] === null ? 0 : $orderInfo['final_amount']; if (empty($orderInfo) || ($orderInfo['final_amount'] != $order['total_amount'] )) { return false; } } return true; } public static function chargeSalerAmountThird($orderData, $statementsId) { $orderIds = array_column($orderData, 'order_id'); $orderList = Order::query() ->select('final_amount','id') ->whereIn('id', $orderIds) ->where('enable', 1) ->get(); if (empty($orderList)) { $orderList = []; } else { $orderList = $orderList->toArray(); $orderList = array_column($orderList, null, 'id'); } if (0 != $statementsId) { $pddStatements = PddStatementsDetail::query() ->selectRaw('order_id, sum(total_amount) as total_amount') ->whereIn('order_id', $orderIds) ->where('statements_id', '!=', $statementsId) ->where('enable', 1) ->groupBy('order_id') ->get(); if (empty($pddStatements)) { $pddStatements = []; } else { $pddStatements = $pddStatements->toArray(); $pddStatements = array_column($pddStatements, null, 'order_id'); } } else { $pddStatements = []; } foreach ($orderData as $order) { $orderInfo = isset($orderList[$order['order_id']]) ? $orderList[$order['order_id']] : null; $pddStatementsInfo = isset($pddStatements[$order['order_id']]) ? $pddStatements[$order['order_id']] : null; $orderInfo['final_amount'] = $orderInfo['final_amount'] === null ? 0 : $orderInfo['final_amount']; if (empty($orderInfo) || ($orderInfo['final_amount'] < ($order['total_amount'] + $pddStatementsInfo['total_amount']))) { return false; } } return true; } public static function getStatementsInfo($statementsId, $columns) { $statementsModel = self::query()->where('id', $statementsId); if(!empty($columns)) { $statementsModel->select($columns); } return $statementsModel->first(); } public static function getListBySearch($search) { $statementsModel = self::query()->where('enable'); if(isset($serach['statements_list']) && !empty($search['statements_list'])) $statementsModel->whereIn('id', $search['statements_list']); return $statementsModel->get(); } }