<?php
|
|
namespace app\api\model\plus\groupbuy;
|
|
use app\common\model\plus\groupbuy\Bill as BillModel;
|
|
/**
|
* 团购订单模型(API端)
|
*/
|
class Bill extends BillModel
|
{
|
/**
|
* 获取正在进行中的团购订单
|
*/
|
public function getBill($groupbuy_product_id, $groupbuy_active_id, $groupbuy_num)
|
{
|
$filter = [
|
'groupbuy_product_id' => $groupbuy_product_id,
|
'groupbuy_active_id' => $groupbuy_active_id,
|
'status' => 10
|
];
|
$res = $this->with(['user','billUser'])
|
->where($filter)
|
->order(['create_time' => 'desc'])
|
->select();
|
foreach ($res as $key => $val) {
|
$res[$key]['dif_people'] = $groupbuy_num - $val['actual_people'];
|
}
|
return $res;
|
}
|
|
/**
|
* 获取用户参与的团购订单
|
*/
|
public function getUserBills($user_id, $groupbuy_product_id = null)
|
{
|
$model = $this->with(['active', 'user', 'billUser.user'])
|
->where('creator_id', '=', $user_id)
|
->whereOrExists(function ($query) use ($user_id) {
|
$query->table('groupbuy_bill_user gb_user')
|
->where('gb_user.groupbuy_bill_id', '=', 'groupbuy_bill.groupbuy_bill_id')
|
->where('gb_user.user_id', '=', $user_id);
|
});
|
|
if ($groupbuy_product_id) {
|
$model = $model->where('groupbuy_product_id', '=', $groupbuy_product_id);
|
}
|
|
return $model->order(['create_time' => 'desc'])->select();
|
}
|
}
|