Example #1
0
 /**
  * 我的优惠券
  */
 public function action_coupons()
 {
     $coupons = \Model_PeopleCoupon::query()->related('coupon')->where(['user_id' => $this->user->id, 'status' => 'NONE'])->where('coupon.start', '<', time())->where('coupon.end', '>', time())->where('coupon.quota', '>=', \Input::post('fee'))->where('coupon.not_allowed_date', 'NOT IN', [date('w'), date('Y-m-d')])->get();
     //限制门类并转数组
     $items = [];
     foreach ($coupons as $coupon) {
         foreach (\Input::post('category_ids') as $item) {
             if ($coupon->coupon->allowed_categories == '' || in_array($item, explode(',', $coupon->coupon->allowed_categories))) {
                 array_push($items, $coupon->to_array());
                 break;
             }
         }
     }
     return $this->response(['status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => $items], 200);
 }
Example #2
0
 /**
  * 检测sn码
  */
 public function action_check_sn()
 {
     $coupon = \Model_PeopleCoupon::query()->related('coupon')->where(['user_id' => 0, 'sn' => \Input::post('no', '')])->get_one();
     if (!$coupon) {
         return $this->response(['status' => 'err', 'msg' => '未找到优惠券', 'errcode' => 10], 200);
     }
     $not_allowed_date = explode(',', $coupon->coupon->not_allowed_date);
     if ($coupon->status != 'NONE') {
         return $this->response(['status' => 'err', 'msg' => '优惠码已使用', 'errcode' => 10], 200);
     } else {
         if ($coupon->pwd != \Input::post('pwd', '')) {
             return $this->response(['status' => 'err', 'msg' => '验证码错误', 'errcode' => 10], 200);
         } else {
             if ($coupon->coupon->start && $coupon->coupon->start > time() || $coupon->coupon->end && $coupon->coupon->end < time() || in_array(date('w'), $not_allowed_date) || in_array(date('Y-m-d'), $not_allowed_date)) {
                 return $this->response(['status' => 'err', 'msg' => '优惠不在可用时间段', 'errcode' => 10], 200);
             } else {
                 if ($coupon->coupon->allowed_categories && !in_array(\Input::post('category', ''), explode(',', $coupon->coupon->allowed_categories))) {
                     return $this->response(['status' => 'err', 'msg' => '优惠码不适用该订单', 'errcode' => 10], 200);
                 }
             }
         }
     }
     return $this->response(['status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => $coupon], 200);
 }