Browse Source
Merge branch 'coupon_rebate' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into coupon_rebate
Merge branch 'coupon_rebate' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into coupon_rebate
# Conflicts: # app/Controller/CouponRebateController.php # app/Service/CouponRebateService.php # app/Service/CouponRebateServiceInterface.php # config/routes.phpmaster
11 changed files with 480 additions and 152 deletions
-
15app/Constants/SsdbKeysPrefix.php
-
79app/Controller/CouponController.php
-
22app/Controller/CouponRebateController.php
-
45app/Request/CouponGetListRequest.php
-
6app/Request/CouponRebateReceiveRequest.php
-
48app/Request/CouponRebateTieRequest.php
-
250app/Service/CouponRebateService.php
-
4app/Service/CouponRebateServiceInterface.php
-
141app/Service/CouponService.php
-
18app/Service/CouponServiceInterface.php
-
4config/routes.php
@ -0,0 +1,45 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace App\Request; |
||||
|
|
||||
|
use Hyperf\Validation\Request\FormRequest; |
||||
|
|
||||
|
class CouponGetListRequest extends FormRequest |
||||
|
{ |
||||
|
/** |
||||
|
* Determine if the user is authorized to make this request. |
||||
|
*/ |
||||
|
public function authorize(): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the validation rules that apply to the request. |
||||
|
*/ |
||||
|
public function rules(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'user_id' => 'required|nonempty|integer|exists_enable:ims_cjdc_user,id', |
||||
|
'receive_type' => 'required|nonempty|integer' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function messages(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'user_id.*' => ':attribute信息不正确', |
||||
|
'receive_type.*' => ':attribute必须' |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributes(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'user_id' => '用户ID', |
||||
|
'receive_type' => '领取方式' |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace App\Request; |
||||
|
|
||||
|
use Hyperf\Validation\Request\FormRequest; |
||||
|
|
||||
|
class CouponRebateTieRequest extends FormRequest |
||||
|
{ |
||||
|
/** |
||||
|
* Determine if the user is authorized to make this request. |
||||
|
*/ |
||||
|
public function authorize(): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the validation rules that apply to the request. |
||||
|
*/ |
||||
|
public function rules(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'coupon_activity' => 'required|nonempty', |
||||
|
'coupon_forward_ids' => 'required|nonempty', |
||||
|
'coupon_repay_id' => 'required|nonempty', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function messages(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'coupon_activity.*' => ':attribute必须', |
||||
|
'coupon_forward_ids.*' => ':attribute必须', |
||||
|
'coupon_repay_id.*' => ':attribute必须', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributes(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'coupon_activity' => '优惠券活动', |
||||
|
'coupon_forward_ids' => '领取类型优惠券', |
||||
|
'coupon_repay_id' => '返还类型优惠券', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,141 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service; |
||||
|
|
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
use Hyperf\DbConnection\Db; |
||||
|
use App\Model\CouponUserRecType; |
||||
|
use App\Model\Coupon; |
||||
|
use App\Model\CouponRec; |
||||
|
use Hyperf\Utils\ApplicationContext; |
||||
|
use App\TaskWorker\SSDBTask; |
||||
|
use App\Constants\SsdbKeysPrefix; |
||||
|
use App\Constants\LogLabel; |
||||
|
use App\Commons\Log; |
||||
|
use Exception; |
||||
|
|
||||
|
class CouponService implements CouponServiceInterface |
||||
|
{ |
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var Log |
||||
|
*/ |
||||
|
protected $log; |
||||
|
|
||||
|
/** |
||||
|
* 获取用户可领取优惠卷接口 |
||||
|
*/ |
||||
|
public function getSystemCouponUserList($userId,$receiveType) |
||||
|
{ |
||||
|
$activityType = 2;/* 优惠券活动标志 2 */ |
||||
|
$result = [ |
||||
|
'active_type' => 1, |
||||
|
'not_receive' => [], |
||||
|
'jump_data' => [ |
||||
|
'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, |
||||
|
'src' => "/zh_cjdianc/pages/couponrebate/index?activity_type=".$activityType, |
||||
|
'coupons' => [] |
||||
|
] |
||||
|
]; |
||||
|
$nowTime = time(); |
||||
|
$c_ids = []; |
||||
|
$result['active_type'] = 1; |
||||
|
// 渠道开启,查询该渠道可以领取的优惠券ID
|
||||
|
// 渠道未开启,查询所有优惠券
|
||||
|
if (env('SUB_CHANNEL') == 1) { |
||||
|
$c_ids = CouponUserRecType::where('receive_type', $receiveType)->pluck('system_coupon_user_id'); |
||||
|
} else { |
||||
|
$c_ids = Coupon::pluck('id'); |
||||
|
} |
||||
|
|
||||
|
$couponReceive = CouponRec::where('user_id',$userId); |
||||
|
|
||||
|
// 渠道开启,查询该用户在此渠道领过的优惠券ID
|
||||
|
if (env('SUB_CHANNEL') == 1) { |
||||
|
$couponReceive->where('receive_type', $receiveType); |
||||
|
} |
||||
|
$cr_ids = $couponReceive->pluck('system_coupon_user_id'); |
||||
|
|
||||
|
// 可领取的券ID
|
||||
|
$c_ids = $c_ids->toArray(); |
||||
|
// 已经领取的券ID
|
||||
|
$cr_ids = $cr_ids->toArray(); |
||||
|
|
||||
|
// 当前用户可领的优惠券ID
|
||||
|
$couponIds = array_diff($c_ids, $cr_ids); |
||||
|
|
||||
|
// 获取领取型优惠券
|
||||
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
||||
|
$couponRebateIds = $ssdb->exec('hgetall',SsdbKeysPrefix::COUPON_REBATE_FORWARD.$activityType); |
||||
|
// $result['active_type'] = $couponRebateIds;
|
||||
|
// return $result;
|
||||
|
$couponIds = ($couponRebateIds === false || empty($couponRebateIds)) ? $couponIds : array_merge($couponIds,$couponRebateIds) ; |
||||
|
|
||||
|
$whereC = [ |
||||
|
['u.end_time','>',$nowTime], |
||||
|
['u.start_time','<=',$nowTime], |
||||
|
['u.status','=',1] |
||||
|
]; |
||||
|
|
||||
|
if (env('SUB_CHANNEL') == 1) { |
||||
|
array_push($whereC, ['type.receive_type','=', $receiveType]); |
||||
|
} |
||||
|
|
||||
|
$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) |
||||
|
->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){ |
||||
|
$result['not_receive'] = $v; |
||||
|
}else if($v['active_type'] == 2){ |
||||
|
$result['jump_data']['coupons'][] = $v; |
||||
|
} |
||||
|
if($v->discount_type == 2){ |
||||
|
$v->discounts = floatval($v->discounts); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$result['active_type'] = count($result['jump_data']['coupons']) > 0 ? 2 : $result['active_type'] ; |
||||
|
|
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
//统计用户
|
||||
|
public function userCouponAccount() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 用户领取优惠卷 |
||||
|
*/ |
||||
|
public function userReceiveCoupon() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取用户已经领取的优惠卷列表 |
||||
|
*/ |
||||
|
public function getUserReceiveCouponList() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取用户当前订单可用的优惠券列表 |
||||
|
* 按分类(1订单 等优惠)分组返回 |
||||
|
*/ |
||||
|
public function getUserAvailableCoupons() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service; |
||||
|
|
||||
|
interface CouponServiceInterface |
||||
|
{ |
||||
|
|
||||
|
public function getSystemCouponUserList($userId,$receiveType); |
||||
|
|
||||
|
public function userCouponAccount(); |
||||
|
|
||||
|
public function userReceiveCoupon(); |
||||
|
|
||||
|
public function getUserReceiveCouponList(); |
||||
|
|
||||
|
public function getUserAvailableCoupons(); |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue