feat : coupon template
This commit is contained in:
21
app/Service/Admin/Coupon/DispenseAddService.php
Normal file
21
app/Service/Admin/Coupon/DispenseAddService.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Coupon;
|
||||
|
||||
use App\Service\Admin\BaseService;
|
||||
|
||||
class DispenseAddService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
//todo Write logic
|
||||
}
|
||||
}
|
||||
153
app/Service/Admin/Coupon/DispenseConfirmService.php
Normal file
153
app/Service/Admin/Coupon/DispenseConfirmService.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Coupon;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\CouponDispenseLog;
|
||||
use App\Model\Cycle;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderGood;
|
||||
use App\Model\Site;
|
||||
use App\Model\Sku;
|
||||
use App\Model\User;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Admin\CouponDispenseTrait;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DispenseConfirmService extends BaseService
|
||||
{
|
||||
use CouponDispenseTrait;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @var Sku
|
||||
*/
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
/**
|
||||
* @var OrderGood
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderGood $orderGoodModel;
|
||||
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected Site $siteModel;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
#[Inject]
|
||||
protected User $userModel;
|
||||
|
||||
/**
|
||||
* @var CouponDispenseLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected CouponDispenseLog $couponDispenseLogModel;
|
||||
|
||||
/**
|
||||
* @var Cycle
|
||||
*/
|
||||
#[Inject]
|
||||
protected Cycle $cycleModel;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $res;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private int $cycleId;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $appointValue;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private int $groupType;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
try {
|
||||
$this->res = [];
|
||||
|
||||
if (empty($this->request->input('appoint_value'))) throw new Exception('请选择指定值');
|
||||
|
||||
match ($this->groupType = (int)$this->request->input('appoint_group',CouponCode::DISPENSE_APPOINT_GROUP_ALL_PEOPLE))
|
||||
{
|
||||
CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_USERS => $this->handleDesignatedUsers(),
|
||||
CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_SITES => $this->handleDesignatedSites(),
|
||||
CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_GOODS => $this->handleDesignatedGoods(),
|
||||
CouponCode::DISPENSE_APPOINT_GROUP_DESIGNATED_SITES_AND_GOODS => $this->handleDesignatedSitesAndGoods(),
|
||||
default => throw new Exception('不需要渲染用户数据')
|
||||
};
|
||||
|
||||
return $this->return->success('success',['list' => $this->res]);
|
||||
}catch (Exception $e) {
|
||||
throw new ErrException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function handleDesignatedUsers()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function handleDesignatedSitesAndGoods()
|
||||
{
|
||||
$this->getValueAndCheckDate();
|
||||
|
||||
$this->checkSite();
|
||||
|
||||
$this->checkSku();
|
||||
|
||||
$this->getUserData();
|
||||
}
|
||||
|
||||
private function handleDesignatedSites()
|
||||
{
|
||||
$this->getValueAndCheckDate();
|
||||
|
||||
$this->checkSite();
|
||||
|
||||
$this->getUserData();
|
||||
}
|
||||
|
||||
private function handleDesignatedGoods()
|
||||
{
|
||||
$this->getValueAndCheckDate();
|
||||
|
||||
$this->checkSku();
|
||||
|
||||
$this->getUserData();
|
||||
}
|
||||
|
||||
}
|
||||
21
app/Service/Admin/Coupon/DispenseService.php
Normal file
21
app/Service/Admin/Coupon/DispenseService.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Coupon;
|
||||
|
||||
use App\Service\Admin\BaseService;
|
||||
|
||||
class DispenseService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
//todo Write logic
|
||||
}
|
||||
}
|
||||
118
app/Service/Admin/Coupon/TemplateService.php
Normal file
118
app/Service/Admin/Coupon/TemplateService.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Coupon;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\CouponTemplate;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class TemplateService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var CouponTemplate
|
||||
*/
|
||||
#[Inject]
|
||||
protected CouponTemplate $couponTemplateModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
|
||||
$list = $this
|
||||
->couponTemplateModel
|
||||
->when($searchName = $this->request->input('query_name'), function ($query) use ($searchName) {
|
||||
$query->where('name', 'like', "$searchName%");
|
||||
})
|
||||
->when($status = $this->request->input('query_status'), function ($query) use ($status) {
|
||||
$query->where('id', $status);
|
||||
})
|
||||
->paginate($limit,['chinese_name','id','mobile','status'])->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ErrException
|
||||
*/
|
||||
public function add(): array
|
||||
{
|
||||
$insertModel = new CouponTemplate();
|
||||
|
||||
$insertModel->name = $this->request->input('name');
|
||||
$insertModel->coupon_type = $this->request->input('coupon_type');
|
||||
$insertModel->amount = $this->request->input('amount','0.00');
|
||||
$insertModel->ratio = $this->request->input('ratio','0.00');
|
||||
$insertModel->is_admin_edit = CouponCode::IS_ADMIN_EDIT;
|
||||
$insertModel->status = CouponCode::COUPON_TEMPLATE_STATUS_NORMAL;
|
||||
|
||||
if (!$insertModel->save()) throw new ErrException('保存优惠券模板失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ErrException
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->couponTemplateModel->getInfoById($id);
|
||||
if (!$info) throw new ErrException('优惠券模板不存在');
|
||||
|
||||
if ($info->is_admin_edit != CouponCode::IS_ADMIN_EDIT) throw new ErrException('该优惠券模板不允许修改,请联系运维或者后端工程师在不影响程序的情况下进行修改');
|
||||
|
||||
$info->name = $this->request->input('name');
|
||||
$info->coupon_type = $this->request->input('coupon_type');
|
||||
$info->amount = $this->request->input('amount','0.00');
|
||||
$info->ratio = $this->request->input('ratio','0.00');
|
||||
|
||||
if (!$info->save()) throw new ErrException('保存优惠券模板失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function changeStatus(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->couponTemplateModel->getInfoById($id);
|
||||
if (!$info) throw new ErrException('优惠券模板不存在');
|
||||
|
||||
$info->status = $info->status == CouponCode::COUPON_TEMPLATE_STATUS_NORMAL ? CouponCode::COUPON_TEMPLATE_STATUS_ENABLE : CouponCode::COUPON_TEMPLATE_STATUS_NORMAL;
|
||||
|
||||
if (!$info->save()) throw new ErrException('保存优惠券模板失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function info(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->couponTemplateModel->getInfoById($id);
|
||||
|
||||
return $this->return->success('success',$info->toArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user