Last active
July 2, 2019 05:51
-
-
Save GimmyHchs/77633d99b9e6fc8a3f5a4dbb887d3f50 to your computer and use it in GitHub Desktop.
Laravel ORM gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 取得含有費用調整order集合. | |
* | |
* @param string $orderNo | |
* | |
* @return AdjustmentOrderCollection | |
*/ | |
public function fetchOrders($orderNo = null) | |
{ | |
$adjustmentRecords = OrderExtra::with('orderHead') | |
->where('add_type', OrderExtra::TYPE_RETURN_DISCOUNT) | |
->orderBy('u_date', 'desc') | |
->orderBy('u_time', 'desc') | |
->take(5); | |
if ($orderNo) { | |
$adjustmentRecords->where('o_no', $orderNo); | |
} | |
$adjustmentOrders = $adjustmentRecords->get()->map(function ($record) { | |
return $record->orderHead; | |
}); | |
$adjustmentOrders->load([ | |
'room.bnb:id,l_id,landlord_name', // bnb資訊 | |
'cancelReason:o_no,c_date', // 取消資訊 | |
'room.bnb.host.useUsd', // 主人定價幣別 | |
'room:id,ld_id,h_name', // room資訊 | |
'member:id,u_name,u_lname', // member資訊 | |
'orderSumOriginal:o_no,sumE,sumG', // sumE:原訂單金額, sumG:原幣主人實際應收金額 | |
'orderExtras' => function ($query) { | |
$query->whereIn('add_type', [ | |
OrderExtra::TYPE_RETURN_DISCOUNT, // 調整金額 | |
OrderExtra::TYPE_CANCEL_RETENTION_RATIO, // 保留比例 | |
]); | |
}, | |
]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function checktTempOrderNoneTaiwanInTwoDays(string $orderId) | |
{ | |
$orders = $this->tempOrderHeadModel->load([ | |
'member:id,u_country', | |
'bnb:id,u_country' | |
])->where('o_no', $orderId) | |
->whereHas('member', function ($query) { | |
$query->where('u_country', '!=', CountryHelper::TW); | |
})->orWhereHas('bnb', function ($query) { | |
$query->where('u_country', '!=', CountryHelper::TW); | |
} | |
->toSql(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment