本文整理匯總了PHP中common\models\Order::tableName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Order::tableName方法的具體用法?PHP Order::tableName怎麽用?PHP Order::tableName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類common\models\Order
的用法示例。
在下文中一共展示了Order::tableName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getOrderGoodsCount
/**
* 獲取用戶某個時間段購買某個商品的數量
*
* @param string $goodsId
* @param string $timeStart
* @param string $timeEnd
* @return integer
*/
public function getOrderGoodsCount($goodsId, $timeStart = null, $timeEnd = null)
{
$sql = 'SELECT sum(t0.count) FROM ' . OrderGoods::tableName() . ' AS t0 LEFT JOIN ' . Order::tableName() . ' AS t1 ON t0.order_id = t1.id WHERE t1.user_id=:user_id AND t0.goods_id=:goods_id';
$params = [':user_id' => $this->id, ':goods_id' => $goodsId];
if ($timeStart !== null) {
$sql .= ' AND t1.created_at >= :time_start';
$params[':time_start'] = $timeStart;
}
if ($timeEnd !== null) {
$sql .= ' AND t1.created_at < :time_end';
$params[':time_end'] = $timeEnd;
}
$count = Yii::$app->db->createCommand($sql, $params)->queryScalar();
return (int) $count;
}