This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop/source/application/api/service/sharp/Order.php
2020-04-25 22:20:29 +08:00

38 lines
1.0 KiB
PHP

<?php
namespace app\api\service\sharp;
use app\api\service\Basics;
use app\api\model\Order as OrderModel;
use app\common\enum\order\Status as OrderStatusEnum;
use app\common\enum\order\OrderSource as OrderSourceEnum;
/**
* 整点秒杀订单服务类
* Class Order
* @package app\api\service\sharp
*/
class Order extends Basics
{
/**
* 获取某商品的购买件数
* @param $userId
* @param $goodsId
* @return float|int
*/
public static function getAlreadyBuyNum($userId, $goodsId)
{
$model = new OrderModel;
$totalNum = $model
->setBaseQuery('order', [
['order_goods', 'order_id'],
])
->where('order_goods.user_id', '=', $userId)
->where('order_goods.goods_id', '=', $goodsId)
->where('order.order_source', '=', OrderSourceEnum::SHARP)
->where('order.order_status', '<>', OrderStatusEnum::CANCELLED)
->where('order.is_delete', '=', 0)
->sum('order_goods.total_num');
return $totalNum;
}
}