71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\common\dao\store;
|
|
|
|
use app\common\dao\BaseDao;
|
|
use app\common\model\store\StoreActivityOrder;
|
|
|
|
class StoreActivityOrderDao extends BaseDao
|
|
{
|
|
|
|
protected function getModel(): string
|
|
{
|
|
return StoreActivityOrder::class;
|
|
}
|
|
|
|
/**
|
|
* 保存活动订单数据
|
|
* @param array $groupOrder 订单
|
|
* @param int $spreadId 推荐人id
|
|
* @param int $isFirstOrder 是否首单
|
|
* @param int $activityId 活动id
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
public function save(array $groupOrder, int $spreadId, int $isFirstOrder, int $activityId = 1)
|
|
{
|
|
$model = new StoreActivityOrder();
|
|
$model->activity_id = $activityId;
|
|
$model->user_id = $groupOrder['uid'];
|
|
$model->group_order_id = $groupOrder['group_order_id'];
|
|
$model->spread_id = $spreadId;
|
|
$model->total_amount = $groupOrder['pay_price'];
|
|
$model->is_first_order = $isFirstOrder;
|
|
if (!$model->save()) {
|
|
throw new \Exception('活动订单保存失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 活动订单撤销
|
|
* @param int $groupOrderId
|
|
* @return void
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function repeal(int $groupOrderId)
|
|
{
|
|
$model = StoreActivityOrder::where('group_order_id', $groupOrderId)->find();
|
|
$model->status = StoreActivityOrder::STATUS_INVALID;
|
|
if (!$model->save()) {
|
|
throw new \Exception('活动订单保存失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 活动订单批量撤销
|
|
* @param array $groupOrderIds
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
public function batchRepeal(array $groupOrderIds)
|
|
{
|
|
$count = StoreActivityOrder::whereIn('group_order_id', $groupOrderIds)->update(['status' => StoreActivityOrder::STATUS_INVALID]);
|
|
if ($count < count($groupOrderIds)) {
|
|
throw new \Exception('活动订单批量作废失败');
|
|
}
|
|
}
|
|
|
|
}
|