setter
parent
c10d9576f5
commit
4ced1bd6ea
|
@ -3,6 +3,7 @@ namespace app\controller\api;
|
|||
|
||||
use app\exception\RepositoryException;
|
||||
use app\model\CouponMain;
|
||||
use app\model\Score;
|
||||
use app\repository\AccountRepository;
|
||||
use app\repository\CouponRepository;
|
||||
use think\Exception;
|
||||
|
@ -25,7 +26,7 @@ class Coupon extends Base
|
|||
*
|
||||
* type in ['', 'notUsed', 'normal', 'used']
|
||||
*/
|
||||
public function getMyCouponList()
|
||||
public function getCouponList()
|
||||
{
|
||||
$page = $this->request->param('page/d', 1);
|
||||
$size = $this->request->param('size/d', 10);
|
||||
|
@ -39,10 +40,23 @@ class Coupon extends Base
|
|||
try {
|
||||
$whereMap = [];
|
||||
$sortOrder = ['received_time' => 'desc'];
|
||||
$fields = ['*', '(end_time > NOW()) as sort_weight'];
|
||||
$fields = [
|
||||
'id',
|
||||
'is_verificated as isVerificated',
|
||||
'money',
|
||||
'name as couponName',
|
||||
'business_code as businessCode',
|
||||
'end_time as endTime',
|
||||
'consumer_name as consumerName',
|
||||
'verificate_time as verificateTime',
|
||||
'(end_time > NOW()) as sort_weight'];
|
||||
|
||||
$whereMap[] = ['consumer_code', '=', $accountCode];
|
||||
switch ($type) {
|
||||
case 'all':
|
||||
// 全部持有优惠券
|
||||
$sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc'];
|
||||
break;
|
||||
case 'notUsed':
|
||||
// 未使用(包含已过期)
|
||||
$whereMap[] = ['is_verificated', '=', self::BOOL_FALSE];
|
||||
|
@ -52,19 +66,35 @@ class Coupon extends Base
|
|||
// 未使用且未过期
|
||||
$whereMap[] = ['is_verificated', '=', self::BOOL_FALSE];
|
||||
$whereMap[] = ['end_time', '< TIME', date('Y-m-d H:i:s')];
|
||||
$fields = [];
|
||||
break;
|
||||
case 'used':
|
||||
// 已使用
|
||||
$whereMap[] = ['is_verificated', '=', self::BOOL_TRUE];
|
||||
$sortOrder = ['verificate_time' => 'desc'];
|
||||
$fields = [];
|
||||
break;
|
||||
}
|
||||
|
||||
$res = CouponRepository::getInstance()->findList($whereMap, $fields, $page, $size, null, $sortOrder);
|
||||
$res['list'] = multiTwoArrayKeysExcludeFilter($res['list']->toArray(), ['sort_weight']);
|
||||
$res = CouponRepository::getInstance()->findList($whereMap, $fields, $page, $size,function ($q){
|
||||
return $q->with(["couponMain","scoreModel"]);
|
||||
}, $sortOrder);
|
||||
|
||||
$res['list'] ->each(function ($item){
|
||||
//重置优惠券名称
|
||||
if(isset($item->couponMain) && $item->couponMain){
|
||||
$item->couponName = $item->couponMain->name;
|
||||
}
|
||||
//是否已经打分过了
|
||||
if(isset($item->scoreModel) && $item->scoreModel){
|
||||
$item->scored = true;
|
||||
$item->score = $item->scoreModel->score;
|
||||
}else{
|
||||
$item->scored = false;
|
||||
$item->score = Score::COMMON_OFF;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$res['list'] = multiTwoArrayKeysExcludeFilter($res['list']->toArray(), ['sort_weight']);
|
||||
return $this->json(0, 'success', $res);
|
||||
} catch (RepositoryException | \Exception $e) {
|
||||
return $this->json(5001, '优惠卷查询失败!');
|
||||
|
|
|
@ -37,4 +37,8 @@ class Coupon extends Base
|
|||
{
|
||||
return $this->hasOne(CouponMain::class, 'id', 'coupon_id');
|
||||
}
|
||||
public function scoreModel()
|
||||
{
|
||||
return $this->hasOne(Score::class, 'coupon_id', 'id');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace app\model;
|
||||
/**
|
||||
* 优惠券使用后商家打分
|
||||
* Class Score
|
||||
* @package app\model
|
||||
*/
|
||||
class Score extends Base
|
||||
{
|
||||
|
||||
}
|
|
@ -146,11 +146,11 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||
<fieldset class="layui-elem-field layui-field-title site-title layui-hide">
|
||||
<legend><a >处罚规则</a></legend>
|
||||
</fieldset>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-form-item layui-hide">
|
||||
<label class="layui-form-label">处罚规则</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="item[using_rule]" cols="30" rows="10"></textarea>
|
||||
|
|
|
@ -147,12 +147,12 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||
<fieldset class="layui-elem-field layui-field-title site-title layui-hide">
|
||||
<legend><a >处罚规则</a></legend>
|
||||
</fieldset>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-form-item layui-hide">
|
||||
<label class="layui-form-label">处罚规则</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="item[using_rule]" cols="30" rows="10">{$item['using_rule']}</textarea>
|
||||
|
|
Loading…
Reference in New Issue