123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php
- 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 {
-
- 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);
- }
-
- 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_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;
- }
-
- 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);
- }
-
- return IntegralStatus::NO_ERROR;
- }
-
- 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) {
-
- $_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;
- }
- }
- }
|