|
|
@@ -57,22 +57,45 @@ class UserCouponLogic extends BaseLogic
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 我的优惠卷列表
|
|
|
* @param $params
|
|
|
* @return array|false
|
|
|
- */
|
|
|
- public static function categoryCouponList($params)
|
|
|
+ */
|
|
|
+ public static function userCouponList($params)
|
|
|
{
|
|
|
try{
|
|
|
- $data = CouponRules::whereIn('id',CouponCategory::where('goods_category_id',$params['goods_category_id'])->group('coupon_id')->column('coupon_id'))
|
|
|
- ->where(['coupon_type'=>1])
|
|
|
- ->field(['id', 'amount', 'coupon_type','amount_require', 'begin_use', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count'])
|
|
|
+ $where = [];
|
|
|
+ if(isset($params['voucher_status']) && is_array($params['voucher_status'])){
|
|
|
+ $where[] = ['voucher_status','IN',$params['voucher_status']];
|
|
|
+ }
|
|
|
+ $where[] = ['user_id','=',$params['user_id']];
|
|
|
+
|
|
|
+ $data = UserCoupon::with(['couponRules'=>function(Query $query){
|
|
|
+ $query->withoutField(['voucher_status','voucher_count']);
|
|
|
+ $query->with(['couponWithCategory'=>function(Query $query){
|
|
|
+ $query->field('id,name');
|
|
|
+ }]);
|
|
|
+ }])
|
|
|
+ ->where($where)
|
|
|
+ ->field(['id', 'user_id', 'coupon_id', 'voucher_status','voucher_count'])
|
|
|
->order(['id' => 'desc'])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
+ $couponIds = [];
|
|
|
foreach($data as $k => $v){
|
|
|
- $v['begin_use'] = $v['begin_use'] ? date('Y-m-d H:i:s',$v['begin_use']) :null;
|
|
|
- $v['expire_time'] = $v['begin_use'] ?date('Y-m-d H:i:s',$v['expire_time']) :null;
|
|
|
- $data[$k] = $v;
|
|
|
+ if($v['couponRules']){
|
|
|
+ if($v['voucher_status'] !=2 &&($v['couponRules']['begin_use'] <time() || $data['couponRules']['expire_time'] > time())){
|
|
|
+ $couponIds[] = $v['coupon_id'];
|
|
|
+ $v['voucher_status'] = 2;
|
|
|
+ }
|
|
|
+ $v['couponRules']['begin_use'] = date("Y-m-d H:i:s",$v['couponRules']['begin_use'] );
|
|
|
+ $v['couponRules']['expire_time'] = date("Y-m-d H:i:s",$v['couponRules']['expire_time'] );
|
|
|
+ $v['couponRules']['goods_category_ids'] = array_column($v['couponRules']['couponWithCategory'],'id');
|
|
|
+ $data[$k] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!empty($couponIds)){
|
|
|
+ UserCoupon::whereIn('coupon_id',$couponIds)->update(['voucher_status'=>2]);
|
|
|
}
|
|
|
return $data;
|
|
|
}catch(\Exception $e){
|
|
|
@@ -81,4 +104,26 @@ class UserCouponLogic extends BaseLogic
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品分类优惠卷领取
|
|
|
+ * @param $params
|
|
|
+ * @return array|false
|
|
|
+ */
|
|
|
+ public static function categoryCouponList($params)
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ $data = CouponRules::with(['couponWithCategory'=>function(Query $query) use($params){
|
|
|
+ $query->where('goods_category_id',$params['goods_category_id']);
|
|
|
+ }])->field(['id', 'amount', 'coupon_type','amount_require', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_count'])
|
|
|
+ ->order(['id' => 'desc'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ return $data;
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|