Browse Source

优惠券返券活动--修改获取接口-查询条数不限制和其他优化

master
liangyuyan 5 years ago
parent
commit
232b3c4883
  1. 1
      .gitignore
  2. 4
      app/Controller/CouponController.php
  3. 11
      app/Controller/CouponRebateController.php
  4. 27
      app/Service/CouponService.php
  5. 1
      config/autoload/dependencies.php

1
.gitignore

@ -12,3 +12,4 @@ vendor/
*.lock
.phpunit*
/watch
.vscode/

4
app/Controller/CouponController.php

@ -20,13 +20,13 @@ use Hyperf\DbConnection\Db;
use Hyperf\Redis\Redis;
use Hyperf\Utils\ApplicationContext;
use App\Request\CouponGetListRequest;
use App\Service\CouponService;
use App\Service\CouponServiceInterface;
class CouponController extends BaseController
{
/**
* @Inject
* @var CouponService
* @var CouponServiceInterface
*/
protected $couponService;

11
app/Controller/CouponRebateController.php

@ -11,24 +11,17 @@ declare(strict_types=1);
*/
namespace App\Controller;
use Hyperf\DbConnection\Db;
use Hyperf\Redis\Redis;
use Hyperf\Utils\ApplicationContext;
use App\Service\CouponRebateServiceInterface;
use http\Client\Curl\User;
use Hyperf\Di\Annotation\Inject;
use App\Model\Coupon;
use App\Model\CouponUserRecType;
use App\Model\CouponRec;
use App\Request\CouponRebateReceiveRequest;
use App\Service\CouponRebateService;
use App\Request\CouponRebateTieRequest;
class CouponRebateController extends BaseController
{
/**
* @Inject
* @var CouponRebateService
* @var CouponRebateServiceInterface
*/
protected $CouponRebateService;

27
app/Service/CouponService.php

@ -13,6 +13,7 @@ use App\Constants\SsdbKeysPrefix;
use App\Constants\LogLabel;
use App\Commons\Log;
use Exception;
use App\Service\CommonService;
class CouponService implements CouponServiceInterface
{
@ -22,6 +23,12 @@ class CouponService implements CouponServiceInterface
*/
protected $log;
/**
* @Inject
* @var CommonService
*/
protected $commonService;
/**
* 获取用户可领取优惠卷接口
*/
@ -45,13 +52,17 @@ class CouponService implements CouponServiceInterface
];
$nowTime = time();
$c_ids = [];
$whereC = [
['end_time','>',$nowTime],
['start_time','<=',$nowTime],
['status','=',1]
];
// 渠道开启,查询该渠道可以领取的优惠券ID
// 渠道未开启,查询所有优惠券
if (env('SUB_CHANNEL') == 1) {
$c_ids = CouponUserRecType::where('receive_type', $receiveType)->pluck('system_coupon_user_id');
$c_ids = CouponUserRecType::where('receive_type', $receiveType)->where($whereC)->pluck('system_coupon_user_id');
} else {
$c_ids = Coupon::pluck('id');
$c_ids = Coupon::where($whereC)->pluck('id');
}
$couponReceive = CouponRec::where('user_id',$userId);
@ -71,13 +82,17 @@ class CouponService implements CouponServiceInterface
$couponIds = array_diff($c_ids, $cr_ids);
// 转发型优惠券
$couponReceiveIds = $couponActivity === false ? [] : explode(',',$couponActivity['forward']);
$couponReceiveIds = ($couponActivity === false || $this->commonService->empty($couponActivity['forward']) )? [] : explode(',',$couponActivity['forward']);
// 所有优惠券
$couponIds = array_merge($couponIds,$couponReceiveIds);
$whereC = [
['u.end_time','>',$nowTime],
['u.start_time','<=',$nowTime],
['u.status','=',1]
];
// 查询领取型1 和 转发型2
$whereActiveType = [1,2];
if (env('SUB_CHANNEL') == 1) {
array_push($whereC, ['type.receive_type','=', $receiveType]);
@ -86,16 +101,16 @@ class CouponService implements CouponServiceInterface
$coupons = Db::table('ims_system_coupon_user as u')
->join('ims_system_coupon_user_receivetype as type', 'u.id', '=', 'type.system_coupon_user_id')
->whereIn('u.id', $couponIds)
->whereIn('u.active_type', $whereActiveType)
->where($whereC)
->whereRaw('u.inventory_use < u.inventory and u.inventory-u.inventory_use >= type.one_receive_number')
->select('u.*','type.one_receive_number')
->orderBy('u.weigh','desc')
->limit(4)
->get();
foreach ($coupons as $k => &$v){
if($v->active_type == 1){
if($v->active_type == 1 && count($result['not_receive']) < 4){
$result['not_receive'][] = $v;
}else if($v->active_type == 2 && in_array($v->id,$couponReceiveIds)){
$result['jump_data']['coupons'][] = $v->id;

1
config/autoload/dependencies.php

@ -17,4 +17,5 @@ return [
\App\Commons\Log::class => \App\Commons\Log::class,
\App\Service\CouponRebateServiceInterface::class => \App\Service\CouponRebateService::class,
\App\Service\UserServiceInterface::class => \App\Service\UserService::class,
\App\Service\CouponServiceInterface::class => \App\Service\CouponService::class,
];
Loading…
Cancel
Save