Browse Source

红包下单获取数量接口

master
Mike 6 years ago
parent
commit
4fd4e9f23a
  1. 85
      app/Controller/CouponController.php
  2. 2
      config/routes.php

85
app/Controller/CouponController.php

@ -163,6 +163,91 @@ class CouponController extends BaseController
$type = $this->request->input('type',1);
# 店铺类型id
$storetypeId = $this->request->input('storetype_id',0);
// 获取用户优惠券
$currentTime = time();
$data = Db::table('ims_system_coupon_user_receive as receive')
->leftJoin('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id')
->where(['receive.user_id' => $userId])
->where(['receive.user_id' => $userId])
->whereIn('coupon.type', [1,$type])
->whereIn('receive.status', [0,1])
->where('receive.number_remain', '>', 0)
->where('coupon.full_amount', '<=', $orderAmount)
->where('coupon.usable_start_time', '<=', $currentTime)
->where('coupon.usable_end_time', '>=', $currentTime)
->where('coupon.usable_number', '<=', Db::raw('receive.number_remain'))
->where('coupon.market_id', 'in', [0,$marketId])
->where(function ($query) use ($storetypeId) {
$query->whereOr(
[
[
['coupon.type', 'in', [1,2]],
['coupon.storetype_id', '=', 0]
],
[
['coupon.type', 'in', [1,3]],
['coupon.storetype_id', '=', $storetypeId]
]
]
);
})
->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC')
->get();
//var_dump($d);
return $this->success($data);
// $coupons = CouponRec::alias('receive')
// ->field([
// 'receive.id receive_id',
// 'receive.user_id',
// 'receive.number_remain',
// 'coupon.id',
// 'coupon.title',
// 'coupon.full_amount',
// 'coupon.discounts',
// 'coupon.usable_start_time',
// 'coupon.usable_end_time',
// 'coupon.discount_type'
// ])
// ->withAttr('usable_start_time', function ($value){
// return $value ? date('Y-m-d H:i:s', $value) : '';
// })
// ->withAttr('usable_end_time', function ($value){
// return $value ? date('Y-m-d H:i:s', $value) : '';
// })
// ->join(Coupon::getTable() . ' coupon ', 'coupon.id=receive.system_coupon_user_id')
// ->where(['receive.user_id' => $userId])
// ->whereIn('coupon.type', [1,$type])
// ->whereIn('receive.status', [0,1])
// ->where('receive.number_remain', '>', 0)
// ->where('coupon.full_amount', '<=', $orderAmount)
// ->where('coupon.usable_start_time', '<=', $currentTime)
// ->where('coupon.usable_end_time', '>=', $currentTime)
// ->where('coupon.usable_number', '<=', Db::raw('receive.number_remain'))
// ->where('coupon.market_id', 'in', [0,$marketId])
// ->where(function ($query) use ($storetypeId) {
// $query->whereOr(
// [
// [
// ['coupon.type', 'in', [1,2]],
// ['coupon.storetype_id', '=', 0]
// ],
// [
// ['coupon.type', 'in', [1,3]],
// ['coupon.storetype_id', '=', $storetypeId]
// ]
// ]
// );
// })
// ->order('coupon.discounts DESC, coupon.full_amount DESC')
// ->select()
// ->toArray();
// var_dump($coupons);
}
}

2
config/routes.php

@ -19,4 +19,6 @@ Router::addGroup('/v1/',function (){
Router::post('CouponUser/userCouponAccount', 'App\Controller\CouponController@userCouponAccount');
Router::post('CouponUserReceive/getUserReceiveCouponList', 'App\Controller\CouponController@getUserReceiveCouponList');
Router::post('CouponUserReceive/userReceiveCoupon', 'App\Controller\CouponController@userReceiveCoupon');
Router::post('CouponUserReceive/getUserAvailableCoupons', 'App\Controller\CouponController@getUserAvailableCoupons');
});
Loading…
Cancel
Save