/**
  * 用户去向 add
  */
 public function add($user_id = NULL, $shop_id = NULL)
 {
     if (IS_POST) {
         /* 定义变量 */
         $model = D(CONTROLLER_NAME);
         $result = $model->do_add();
         /* 返回信息 */
         if ($result) {
             /* 关注的人收到通知 */
             // 获取关注你的人
             $where_attention['user_attention.to_user_id'] = array('EQ', $user_id);
             $where_attention['user.push_id'] = array('NEQ', '');
             $where_attention['user.status'] = array('EQ', 1);
             $where_attention['user.display'] = array('EQ', 1);
             $where_attention['user.trace_notify'] = array('EQ', 1);
             $attention_user_id = M('UserAttention')->alias('user_attention')->field('user.push_id')->where($where_attention)->join('__USER__ user on user_attention.user_id = user.id')->select();
             if ($attention_user_id) {
                 // 获取去向资料
                 $data_shop_user_went = get_shop_user_went($user_id, $shop_id);
                 if ($data_shop_user_went) {
                     foreach ($attention_user_id as $k => $v) {
                         $push_id[] = $v['push_id'];
                     }
                     $push_id = array_filter(array_unique(array_slice($push_id, 0, 1000)));
                     $this->push_one($push_id, $data_shop_user_went);
                 }
             }
             $this->ajaxReturn(array('RESPONSE_STATUS' => 100, 'Tips' => L('YZ_return_success')));
         } else {
             $this->return_post($model);
         }
     }
     $this->ajaxReturn(array('RESPONSE_STATUS' => 500, 'Tips' => L('YZ_return_failure')));
 }
 /**
  * 优惠劵购买 buy
  */
 public function buy($user_id = NULL, $shop_id = NULL)
 {
     if (IS_POST) {
         /* 定义变量 */
         $model = D('PayOrder');
         $result = $model->do_add();
         /* 返回信息 */
         if ($result) {
             header('Content-Type:application/json; charset=utf-8');
             echo json_encode(array('RESPONSE_STATUS' => 100, 'Tips' => L('YZ_return_success')));
             /* 插入想去 */
             $result_shop_user_went = D('ShopUserWent')->do_add_buy($shop_id, $user_id, $result);
             if ($result_shop_user_went) {
                 /* 关注的人收到通知 */
                 // 获取关注你的人
                 $where_attention['user_attention.to_user_id'] = array('EQ', $user_id);
                 $where_attention['user.push_id'] = array('NEQ', '');
                 $where_attention['user.status'] = array('EQ', 1);
                 $where_attention['user.display'] = array('EQ', 1);
                 $where_attention['user.trace_notify'] = array('EQ', 1);
                 $attention_user_id = M('UserAttention')->alias('user_attention')->field('user.push_id')->where($where_attention)->join('__USER__ user on user_attention.user_id = user.id')->select();
                 // 获取去向资料
                 $data_shop_user_went = get_shop_user_went($user_id, $shop_id);
                 if ($data_shop_user_went) {
                     foreach ($attention_user_id as $k => $v) {
                         $push_id[] = $v['push_id'];
                     }
                     $push_id = array_filter(array_unique(array_slice($push_id, 0, 1000)));
                     $this->push_one($push_id, $data_shop_user_went);
                 }
             }
         } else {
             $this->return_post($model);
         }
     }
     $this->ajaxReturn(array('RESPONSE_STATUS' => 500, 'Tips' => L('YZ_return_failure')));
 }
 public function do_consume()
 {
     $name = CONTROLLER_NAME;
     $model = D($name);
     $result = $model->do_consume();
     /* 返回信息 */
     if ($result) {
         /* ShopUserWent 添加去向 */
         $where['trade_no'] = array('EQ', I('post.verify'));
         $where['trade_state'] = array('EQ', 1);
         $where['shop_account_id'] = array('EQ', UID);
         $where['display'] = array('EQ', 1);
         $shopUserWent = $model->field('id,user_id,shop_id,shop_coupon_info')->where($where)->find();
         $shopUserWentInfo = json_decode($shopUserWent['shop_coupon_info'], true);
         $content = '使用了"' . $shopUserWentInfo['title'] . '"';
         $dataUserWent['shop_id'] = $shopUserWent['shop_id'];
         $dataUserWent['user_id'] = $shopUserWent['user_id'];
         $dataUserWent['content'] = $content;
         $dataUserWent['pay_order_id'] = $shopUserWent['id'];
         $dataUserWent['create_time'] = NOW_TIME;
         M('ShopUserWent')->add($dataUserWent);
         /* 关注的人收到通知 */
         // 获取关注你的人
         $where_attention['user_attention.to_user_id'] = array('EQ', $shopUserWent['user_id']);
         $where_attention['user.push_id'] = array('NEQ', '');
         $where_attention['user.status'] = array('EQ', 1);
         $where_attention['user.display'] = array('EQ', 1);
         $where_attention['user.trace_notify'] = array('EQ', 1);
         $attention_user_id = M('UserAttention')->alias('user_attention')->field('user.push_id')->where($where_attention)->join('__USER__ user on user_attention.user_id = user.id')->select();
         // 获取去向资料
         $data_shop_user_went = get_shop_user_went($shopUserWent['user_id'], $shopUserWent['shop_id']);
         if ($data_shop_user_went) {
             foreach ($attention_user_id as $k => $v) {
                 $push_id[] = $v['push_id'];
             }
             $push_id = array_filter(array_unique(array_slice($push_id, 0, 1000)));
             R('Api/Api/push_one', array($push_id, $data_shop_user_went));
         }
         $this->ajaxReturn(array('msg' => L('YZ_operation_success'), 'result' => 1, 'href' => U('consume')));
     } else {
         $result = $model->getError();
         if (is_array($result) && count($result)) {
             /* 验证错误 */
             $errorMsg = validate_error($result);
             $this->ajaxReturn(array('formError' => $errorMsg, 'result' => -1));
         }
         /* 数据库操作错误 */
         $this->ajaxReturn(array('msg' => L('YZ_operation_fail'), 'result' => 1));
     }
 }