我收到這個錯誤表單 helper.php。我需要產品的銷售價格。但我得到了這個錯誤。當我得到這個錯誤時我不明白。
助手.php
public static function getSalesPriceUsingProductIDCode($id, $customerId)
{
$data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
->select('product_id', 'sales_price')
->first()->sales_price;
return $data;
}
orderSheetExport.php
if(isset($results[$product->id]))
{
if (Helper::getSalesPriceUsingProductIDCode($product->id,$results['customer_id'])==0)
{
$excel_dynamic_data_values[$index][] = $product->whole_sale_price * $results[$product->id];
$productArray[$rsm_id][$product->id] = $results[$product->id] * $product->whole_sale_price;
$singleProductArray[$rsm_id][$product->id] = $productArray[$rsm_id][$product->id];
}else
{
$excel_dynamic_data_values[$index][] = Helper::getSalesPriceUsingProductIDCode($product->id,$results['customer_id']) * $results[$product->id];
$productArray[$rsm_id][$product->id] = $results[$product->id] * Helper::getSalesPriceUsingProductIDCode( $product->id,$results['customer_id']);
$singleProductArray[$rsm_id][$product->id] = $productArray[$rsm_id][$product->id];
}
}
uj5u.com熱心網友回復:
如果你只需要 sales_price 使用value功能
public static function getSalesPriceUsingProductIDCode($id, $customerId)
{
$data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
->select('product_id', 'sales_price')
->value('sales_price');
return $data;
}
請在Laravel 查詢中參考 value()
uj5u.com熱心網友回復:
我解決了這個問題。我也明白為什么我會收到這個錯誤。當我在回圈中使用這個輔助函式時。它得到一些不是任何銷售價格資料的值。所以它雖然這個錯誤。所以,我寫了 if else 條件。
助手.php
public static function getSalesPriceUsingProductIDCode($id, $customerId)
{
$data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
->select('product_id', 'sales_price')
->first();
if ($data) {
$data = $data->sales_price;
} else {
$data = 0;
}
return $data;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/521868.html
標籤:php拉拉维尔帮手
上一篇:CSS 漸變鋸齒消失術
下一篇:瀏覽器本地存盤
