123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php
- /**
- * MemIntegral.php UTF-8
- * 玩家积分
- *
- * @date : 2018/5/5 14:00
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\integral;
- use huo\controller\agent\AgentWallet;
- use huo\controller\common\Base;
- use huo\controller\common\CommonFunc;
- use huo\controller\game\GameCache;
- use huo\controller\member\MemCache;
- use huo\logic\shop\ItgLogic;
- use huo\model\agent\AgentOrderModel;
- use huo\model\integral\MemItgLogModel;
- use huo\model\user\UserModel;
- use huolib\constant\IaConst;
- use huolib\constant\MemItgConst;
- use huolib\constant\SettleConst;
- use huolib\constant\WalletConst;
- use huolib\status\CommonStatus;
- use huolib\status\IntegralStatus;
- use huolib\status\SettleStatus;
- use huolib\tool\StrUtils;
- use huomp\controller\member\MemberOut;
- use huoMpMsg\controller\OaOut;
- use think\Log;
- class MemIntegral extends Base {
- /**
- * 获取玩家积分列表
- *
- *
- * @param array $where
- * @param string $page
- * @param int $mem_id
- *
- * @return array
- */
- public function getItgList($where = [], $page = '1,10', $mem_id) {
- $_order = '-create_time';
- $where['mem_id'] = $mem_id;
- $_data = (new ItgLogic())->getItgList($where, $page, $_order);
- return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
- }
- /**
- * 设置玩家积分
- *
- * @param int $mem_id 玩家ID
- * @param int $integral 获得的积分
- * @param int $type 积分变化类型
- * @param int $ia_id 积分活动ID
- * @param int $sub_ia_id 子活动ID
- * @param string $link_table 关联的表
- * @param int $link_id 关联表ID
- * @param int $app_id 盒子ID
- *
- * @param string $ia_name 活动名称,当不是积分任务中的任务改变积分时必传
- *
- * @return int
- */
- public function setMemItg(
- $mem_id, $integral, $type, $ia_id = 0, $sub_ia_id = 0, $link_table = '', $link_id = 0, $ia_name = '',
- $app_id = 0
- ) {
- if ($integral < 0) {
- return IntegralStatus::ITG_MEM_TYPE_ERROR;
- }
- $_mc_class = MemCache::ins();
- $_me_data = $_mc_class->getMeInfoById($mem_id);
- if (empty($_me_data)) {
- return IntegralStatus::ITG_MEM_NOT_EXISTS;
- }
- $_itg = $integral;
- switch ($type) {
- case MemItgConst::MEM_ITG_ADD:
- case MemItgConst::MEM_ITG_OFFICE_GIVE:
- $_me_data['integral_total'] += $integral;
- $_me_data['my_integral'] += $integral;
- break;
- case MemItgConst::MEM_ITG_DEDUCT:
- case MemItgConst::MEM_ITG_OFFICE_DEDUCT:
- if ($integral > $_me_data['my_integral']) {
- /* 玩家积分不足 */
- return IntegralStatus::ITG_NOT_ENOUGH;
- }
- $_me_data['my_integral'] -= $integral;
- $_itg = 0 - $integral;
- break;
- default:
- return IntegralStatus::ITG_MEM_TYPE_ERROR;
- }
- $_rs = $_mc_class->updateMeCache($mem_id, $_me_data);
- if (false == $_rs) {
- return IntegralStatus::INNER_ERROR;
- }
- $_ia_data = IaCache::ins()->getIa($ia_id);
- /* 插入积分Log */
- $_log_data['mem_id'] = $mem_id;
- $_log_data['itg_type'] = $type;
- $_log_data['integral_total'] = $_me_data['integral_total'];
- $_log_data['my_integral'] = $_me_data['my_integral'];
- $_log_data['integral'] = $integral;
- $_log_data['ia_id'] = $ia_id;
- $_log_data['ia_name'] = empty($ia_name) ? $_ia_data['ia_name'] : $ia_name;
- $_log_data['sub_ia_id'] = $sub_ia_id;
- $_log_data['link_table'] = $link_table;
- $_log_data['link_id'] = $link_id;
- $_log_data['app_id'] = $app_id;
- if (IaConst::IA_PLAY_3 == $ia_id) {
- $_play_data = (new MemberOut())->getPlayCnt($mem_id);
- $_pay_cnt = empty($_play_data['cnt']) ? 1 : $_play_data['cnt'] + 1;
- $_log_data['ia_name'] .= $_pay_cnt;
- }
- $_rs = (new MemItgLogModel())->addMemIaLog($_log_data);
- if (false == $_rs) {
- return IntegralStatus::ITG_IA_FAIL;
- }
- if (!empty($ia_id)) {
- $_rs = MemIaCache::ins()->updateMemIa($ia_id, $mem_id, $_itg);
- if (false == $_rs) {
- return IntegralStatus::ITG_IA_FAIL;
- }
- }
- return IntegralStatus::NO_ERROR;
- }
- /**
- * 增加玩家积分
- *
- * @param int $mem_id 玩家ID
- * @param int $integral 获得的积分
- * @param int $ia_id 积分活动ID
- * @param int $sub_ia_id 子活动ID
- * @param string $link_table 关联的表
- * @param int $link_id 关联表ID
- * @param string $ia_name 活动名称,当不是积分任务中的任务改变积分时必传
- * @param int $app_id 应用ID 添加到哪个盒子
- * @param bool $is_rp 是否转红包
- *
- * @return int
- */
- public function addMemItg(
- $mem_id, $integral, $ia_id = 0, $sub_ia_id = 0, $link_table = '', $link_id = 0, $ia_name = '',
- $app_id = 0, $is_rp = false
- ) {
- $_rs = $this->setMemItg(
- $mem_id, $integral, MemItgConst::MEM_ITG_ADD, $ia_id, $sub_ia_id, $link_table, $link_id, $ia_name, $app_id
- );
- if (IntegralStatus::NO_ERROR != $_rs) {
- return $_rs;
- }
- $_is_rp_box = GameCache::ins()->isRpBox($app_id);
- if ($_is_rp_box != true && $is_rp == true) {
- $_is_rp_box = true;
- }
- if (true == $_is_rp_box) {
- /* 红包盒子 直接转换所有积分为红包 */
- $_ia_data = IaCache::ins()->getIa($ia_id);
- $ia_name = empty($ia_name) ? $_ia_data['ia_name'] : $ia_name;
- $this->setMemItg(
- $mem_id, $integral, MemItgConst::MEM_ITG_DEDUCT, $ia_id, $sub_ia_id, $link_table, $link_id,
- $ia_name.'--转换红包'
- );
- return $this->addWalletByItg($mem_id, $integral, $app_id, $ia_name);
- }
- // (new OaOut())->sendGoldChangeMsg($mem_id, $app_id, $integral);
- return IntegralStatus::NO_ERROR;
- }
- /**
- * 通过积分转化为钱包余额
- *
- * @param int $mem_id 玩家ID
- * @param int $integral 获得的积分
- * @param int $app_id 应用ID 添加到哪个盒子
- * @param string $remark 备注信息
- *
- * @return int
- */
- public function addWalletByItg($mem_id, $integral, $app_id = 0, $remark = '') {
- /* 红包版本直接转化为红包余额 */
- $_agent_id = (new UserModel())->getIdByMemId($mem_id);
- if (!empty($_agent_id)) {
- $_gold_rmb_rate = CommonFunc::getGoldRmbRate();
- $_amount = StrUtils::formatNumber($integral / $_gold_rmb_rate);
- $_rs = (new AgentWallet())->updateWallet($_agent_id, $_amount, SettleConst::SETTLE_WALLET_ADD);
- if (SettleStatus::NO_ERROR == $_rs) {
- /* 添加到agentOrder 渠道余额记录*/
- $_agent_id = (new UserModel())->getIdByMemId($mem_id);
- $_ao_data = [
- 'order_id' => StrUtils::genOrderId(
- $_agent_id, $_agent_id, $mem_id, WalletConst::WALLET_ORDER_PREFIX_MP
- ),
- 'agent_id' => $_agent_id,
- 'agent_gain' => $_amount,
- 'status' => 2,//成功
- 'remark' => $remark
- ];
- (new AgentOrderModel())->createOrder($_ao_data);
- (new OaOut())->sendMoneyChangeMsg($mem_id, $app_id, $_amount);
- }
- return $_rs;
- } else {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&mem_id=".$mem_id."&integral=".$integral,
- LOG::ERROR
- );
- return IntegralStatus::NO_ERROR;
- }
- }
- }
|