master
wangxinglong 2021-12-08 18:15:47 +08:00
parent c10d9576f5
commit 4ced1bd6ea
5 changed files with 56 additions and 10 deletions

View File

@ -3,6 +3,7 @@ namespace app\controller\api;
use app\exception\RepositoryException; use app\exception\RepositoryException;
use app\model\CouponMain; use app\model\CouponMain;
use app\model\Score;
use app\repository\AccountRepository; use app\repository\AccountRepository;
use app\repository\CouponRepository; use app\repository\CouponRepository;
use think\Exception; use think\Exception;
@ -25,7 +26,7 @@ class Coupon extends Base
* *
* type in ['', 'notUsed', 'normal', 'used'] * type in ['', 'notUsed', 'normal', 'used']
*/ */
public function getMyCouponList() public function getCouponList()
{ {
$page = $this->request->param('page/d', 1); $page = $this->request->param('page/d', 1);
$size = $this->request->param('size/d', 10); $size = $this->request->param('size/d', 10);
@ -39,10 +40,23 @@ class Coupon extends Base
try { try {
$whereMap = []; $whereMap = [];
$sortOrder = ['received_time' => 'desc']; $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]; $whereMap[] = ['consumer_code', '=', $accountCode];
switch ($type) { switch ($type) {
case 'all':
// 全部持有优惠券
$sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc'];
break;
case 'notUsed': case 'notUsed':
// 未使用(包含已过期) // 未使用(包含已过期)
$whereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; $whereMap[] = ['is_verificated', '=', self::BOOL_FALSE];
@ -52,19 +66,35 @@ class Coupon extends Base
// 未使用且未过期 // 未使用且未过期
$whereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; $whereMap[] = ['is_verificated', '=', self::BOOL_FALSE];
$whereMap[] = ['end_time', '< TIME', date('Y-m-d H:i:s')]; $whereMap[] = ['end_time', '< TIME', date('Y-m-d H:i:s')];
$fields = [];
break; break;
case 'used': case 'used':
// 已使用 // 已使用
$whereMap[] = ['is_verificated', '=', self::BOOL_TRUE]; $whereMap[] = ['is_verificated', '=', self::BOOL_TRUE];
$sortOrder = ['verificate_time' => 'desc']; $sortOrder = ['verificate_time' => 'desc'];
$fields = [];
break; break;
} }
$res = CouponRepository::getInstance()->findList($whereMap, $fields, $page, $size, null, $sortOrder); $res = CouponRepository::getInstance()->findList($whereMap, $fields, $page, $size,function ($q){
$res['list'] = multiTwoArrayKeysExcludeFilter($res['list']->toArray(), ['sort_weight']); 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); return $this->json(0, 'success', $res);
} catch (RepositoryException | \Exception $e) { } catch (RepositoryException | \Exception $e) {
return $this->json(5001, '优惠卷查询失败!'); return $this->json(5001, '优惠卷查询失败!');

View File

@ -37,4 +37,8 @@ class Coupon extends Base
{ {
return $this->hasOne(CouponMain::class, 'id', 'coupon_id'); return $this->hasOne(CouponMain::class, 'id', 'coupon_id');
} }
public function scoreModel()
{
return $this->hasOne(Score::class, 'coupon_id', 'id');
}
} }

12
app/model/Score.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace app\model;
/**
* 优惠券使用后商家打分
* Class Score
* @package app\model
*/
class Score extends Base
{
}

View File

@ -146,11 +146,11 @@
</div> </div>
</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> <legend><a >处罚规则</a></legend>
</fieldset> </fieldset>
<div class="layui-form-item"> <div class="layui-form-item layui-hide">
<label class="layui-form-label">处罚规则</label> <label class="layui-form-label">处罚规则</label>
<div class="layui-input-block"> <div class="layui-input-block">
<textarea name="item[using_rule]" cols="30" rows="10"></textarea> <textarea name="item[using_rule]" cols="30" rows="10"></textarea>

View File

@ -147,12 +147,12 @@
</div> </div>
</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> <legend><a >处罚规则</a></legend>
</fieldset> </fieldset>
<div class="layui-form-item"> <div class="layui-form-item layui-hide">
<label class="layui-form-label">处罚规则</label> <label class="layui-form-label">处罚规则</label>
<div class="layui-input-block"> <div class="layui-input-block">
<textarea name="item[using_rule]" cols="30" rows="10">{$item['using_rule']}</textarea> <textarea name="item[using_rule]" cols="30" rows="10">{$item['using_rule']}</textarea>