Example #1
0
 /**
  * sendGift
  * 发送礼物
  * 
  * @param array $toUid  接收礼品人的ID(可以多个,以,分隔)
  * @param $fromUid  送礼者ID
  * @param $sendInfo  附加信息和发送方式
  * @param $giftInfo  礼品信息
  */
 public function sendGift($toUid, $fromUid, array $sendInfo, array $giftInfo)
 {
     //判断参数是否合法.不合法返回false
     if (!is_numeric($fromUid)) {
         return '非法操作!';
     }
     $toUser = explode(',', $toUid);
     $userNum = count($toUser);
     //判断是否是自己给自己送礼物
     if (in_array($fromUid, $toUser)) {
         return '不能给自己送礼物!';
     }
     // //判断是否有足够的礼物数
     if ($this->gift->assertNumAreEmpty($giftInfo['id'], $userNum)) {
         return '礼物库存不足,发送礼品失败!';
     }
     //扣除相应积分
     $giftPrice = intval($giftInfo['price']);
     $prices = $userNum * $giftPrice;
     $moneyType = gift_getConfig('credit');
     //积分操作
     $setCredit = model('Credit');
     //检测积分是否足够
     $userCredit = $setCredit->getUserCredit($fromUid);
     // 测试时注释以下代码(积分不够)
     if ($userCredit['credit'][$moneyType]['value'] < $prices) {
         return $userCredit['credit'][$moneyType]['alias'] . '不足,不能赠送~~';
     }
     $setCredit->setUserCredit($fromUid, array($moneyType => $prices), -1);
     $map['giftPrice'] = $giftPrice;
     $map['giftImg'] = t($giftInfo['img']);
     $map['sendInfo'] = t($sendInfo['sendInfo']);
     $map['sendWay'] = intval($sendInfo['sendWay']);
     $map['fromUserId'] = intval($fromUid);
     $map['cTime'] = time();
     $res = $this->__insertData($toUser, $map);
     //如果入库过程成功.则做相应的处理
     if ($res) {
         //礼物数减
         $this->gift->setDec('num', 'id=' . $giftInfo['id'], $userNum);
         //给接收人发送通知
         $this->__doNotify($toUser, $sendInfo, $giftInfo, $fromUid, $appId);
         return true;
     } else {
         return '发送礼品失败!';
     }
 }
Example #2
0
 /**
  * 礼物兑换积分 --using
  * 
  * @param integer $gift_id
  *        	礼物ID
  * @return 状态+提示
  */
 public function exchange()
 {
     $giftId = intval($this->data['gift_id']);
     // $giftNum = $this->data['gift_num'] ? intval($this->data['gift_num']) : 1;
     $map['id'] = $giftId;
     $map['toUserId'] = $this->mid;
     $map['status'] = 1;
     $exchange = D('UserGift', 'gift')->where($map)->find();
     if (!$exchange) {
         return array('status' => 0, 'msg' => '您没有该礼物');
     }
     // 		if ($exchange ['giftNum'] < $giftNum) {
     // 			return array (
     // 					'status' => 0,
     // 					'msg' => '该礼物数量不够'
     // 			);
     // 		}
     $add = $exchange['giftPrice'] / 5 * 4;
     $add = $add ? round($add) : 0;
     // 		dump($add);exit;
     // 积分操作
     $setCredit = model('Credit');
     $moneyType = gift_getConfig('credit');
     $des['content'] = "用礼物兑换了" . $add . "积分";
     $re = $setCredit->setUserCredit($this->mid, array('name' => 'gift_exchange', $moneyType => $add), 1, $des);
     if ($re) {
         D('UserGift', 'gift')->where($map)->setField('status', 0);
         return array('status' => 1, 'msg' => '兑换成功');
     } else {
         return array('status' => 0, 'msg' => '兑换失败');
     }
 }
Example #3
0
 /**
  * 送出的礼物
  *
  */
 function sendbox()
 {
     //获取送出的礼物列表
     $gift = $this->user_gift->sendList($this->mid);
     //判断是否有公开赠送信息,用于发微薄
     $tpldata = unserialize($_SESSION['gift_send_weibo']);
     if (isset($_SESSION['gift_send_weibo']) && !empty($_SESSION['gift_send_weibo'])) {
         $tpldata = unserialize($_SESSION['gift_send_weibo']);
         $str = '我在礼物中心赠送了礼物‘' . $tpldata['title'] . '’给' . $tpldata['user'] . ' ,赶快来参与送礼';
         $this->assign('tpl_data', $str);
         unset($_SESSION['gift_send_weibo']);
     }
     $type = gift_getConfig('credit');
     // 积分  经验
     $map['name'] = array('LIKE', $type);
     $name = M('credit_type')->where($map)->getField('alias');
     $this->assign('type', $name);
     $fromUids = getSubByKey($gift['data'], 'fromUserId');
     $toUids = getSubByKey($gift['data'], 'toUserId');
     $uids = array_unique(array_merge($fromUids, $toUids));
     $this->assign('user_info', model('User')->getUserInfoByUids($uids));
     $this->assign('gifts', $gift);
     $this->setTitle("送出的{$this->app_alias}");
     $this->display();
 }