/** * 当银联通知票券承兑 * * @param unknown_type $uid * @param unknown_type $unionUid * @param unknown_type $unionCouponId */ public function accept_coupon($uid, $unionCouponId) { $CI =& get_instance(); // 改变downloadedcoupon中的记录,吧unused变成used //先获得couponId $query = $CI->db->query("select id from coupon where unionCouponId='{$unionCouponId}' limit 1"); $results = $query->result_array(); $couponId = $results[0]['id']; if (empty($couponId)) { // 如果没有从unionCouponId获得couponId, 就log error log_message("error", "Kqlibrary.accept_coupon: Empty couponId -- uid # {$uid}, unionCouponId # {$unionCouponId}"); return; } // echo 'couponId'.$couponId; // echo 'uid'.$uid; //改变downloadedcoupon中的记录,吧unused变成used $CI->db->query("update downloadedcoupon \nset status='used'\nwhere status='unused'\nand couponId={$couponId}\nand uid={$uid}\nlimit 1"); if (!$this->coupon->increment_acount($couponId)) { // echo 'increment error'; } else { // echo 'increment sucess'; } // echo 'after increment acount'; //发送通知: 如果是安卓就push,如果是ios就发短信 // $umengpush = new UmengPush(); // $completeTitle = $this->coupon->get_complete_title($couponId); // $title = '快券承兑完成'; // $text = "您的".$completeTitle."快券已使用,更多优惠在等着你哦!"; // // $umengpush->send_customized_notification($uid,$title, $text); // -- 发送通知 $user = $this->user->get($uid); $completeTitle = $this->coupon->get_complete_title($couponId); $mobile = $user['username']; $device = $user['device']; if ($device == 'iOS') { // echo 'iOS'; $sms = new Kqsms(); $response = $sms->send_coupon_accepted_sms($mobile, $completeTitle); log_message('error', 'iOS SMS CouponAccepted #' . $response . ', mobile # ' . $mobile); // echo $response; } else { // echo 'Android'; $umengpush = new UmengPush(); $title = '优惠券承兑完成'; $text = "您的" . $completeTitle . "快券已使用,更多优惠在等着你哦!"; $umengpush->send_customized_notification($uid, $title, $text); } // End of 发送通知 }
function test_acoupon_increment() { echo $this->coupon->increment_acount(36); }