getFind(array($RPModel::MERCHANT_ID => $merchant_id), array($RPModel::SWITCH_TYPE, $RPModel::RECHARGE_SWITCH_TYPE, $RPModel::RENEW_RECHARGE_SWITCH_TYPE)); // 判断商户plus设置 $switch_type = $plus_set[$RPModel::SWITCH_TYPE] ?: 1; $recharge_switch_type = $plus_set[$RPModel::RECHARGE_SWITCH_TYPE] ?: 1; $renew_recharge_switch_type = $plus_set[$RPModel::RENEW_RECHARGE_SWITCH_TYPE] ?: 1; // 查询充值活动 $time = time(); $map = array( $this::MERCHANT_ID => $merchant_id, $this::STORE_ID => $store_id, $this::STATUS => 1, $this::STATE => 1, $this::SURPLUS => array(array('eq', '-1'), array('gt', 0), 'or'), $this::START_TIME => array(array('eq', ''), array('lt', $time), 'or'), $this::END_TIME => array(array('eq', ''), array('gt', $time), 'or'), ); // 判断线上线下 if ($type == 0) { // 线下 $map[$this::LINE_STATE] = 1; } else { // 线上 $map[$this::ONLINE_STATE] = 1; } // 判断会员类型 if ($vip_type == 1) { // 普通会员 $map[$this::SCENE_TYPE] = array('in', array(1, 2)); } else { // 过期,正常plus $map[$this::SCENE_TYPE] = array('in', array(1, 3)); } $field = array( $this::ID, $this::RECHARGE_MONEY, $this::GIVE_MONEY, $this::LIMIT_NUM, $this::ROLE_TYPE, $this::SCENE_TYPE, $this::TIME, $this::AGING_REPAY, $this::AGING_TIME, ); $recharge_list = $this->getSelect($map, $field); if (!$recharge_list) { // 暂无充值活动 return false; } // 处理数据,定义空数组 $vip_recharge_activity = array(); $plus_recharge_activity = array(); // 充值记录 $ROModel = D('RetailRechargeOrder'); $map2 = array( $ROModel::MERCHANT_ID => $merchant_id, $ROModel::STORE_ID => $store_id, $ROModel::VID => $vip_id, $ROModel::STATUS => 1, ); // 获取商户充值设置 $MerchantModel = new RetailMerchantModel(); $map = array( $MerchantModel::ID => $merchant_id, $MerchantModel::STATUS => 1 ); $field = array($MerchantModel::AGING_CYCLE, $MerchantModel::AGING_REPAY, $MerchantModel::AGING_TIME); $setting = $MerchantModel->getFind($map, $field); foreach ($recharge_list as &$val) { // 判断会员充值限制 if (intval($val[$this::LIMIT_NUM]) > 0) { $map3 = $map2; $map3[$ROModel::VIP_RECHARGE_ID] = $val[$this::ID]; $recharge_count = $ROModel->getCount($map3); // 大于充值限制 if (intval($recharge_count) >= intval($val[$this::LIMIT_NUM])) { continue; } } $val['aging_repay_name'] = $val['aging_repay'] == 1 ? '分期到账' : '直接到账'; $val['aging_cycle_name'] = $setting['aging_cycle'] == 0 ? '日' : '月'; $val['active_aging_time'] = $val['aging_time']; $val['aging_time'] = $setting['aging_time']; // 判断会员类型 switch ($vip_type) { case 1: // 普通会员 if ($val[$this::ROLE_TYPE] == 3 && $val[$this::SCENE_TYPE] == 1) { array_push($vip_recharge_activity, $val); continue; } else if ($val[$this::ROLE_TYPE] == 3 && $val[$this::SCENE_TYPE] == 2 && $switch_type == 2 && $recharge_switch_type == 2) { array_push($plus_recharge_activity, $val); continue; } else { continue; } break; case 2: // 过期plus if ($val[$this::ROLE_TYPE] == 3 && $val[$this::SCENE_TYPE] == 1) { array_push($vip_recharge_activity, $val); continue; } else if ($val[$this::ROLE_TYPE] == 2 && $val[$this::SCENE_TYPE] == 3 && $switch_type == 2 && $renew_recharge_switch_type == 2) { array_push($plus_recharge_activity, $val); continue; } else { continue; } break; case 3: // 正常plus if ($val[$this::ROLE_TYPE] == 2 && $val[$this::SCENE_TYPE] == 1) { array_push($vip_recharge_activity, $val); continue; } else if ($val[$this::ROLE_TYPE] == 2 && $val[$this::SCENE_TYPE] == 3 && $switch_type == 2 && $renew_recharge_switch_type == 2) { array_push($plus_recharge_activity, $val); continue; } else { continue; } break; default: continue; break; } } $res = array( 'vip_recharge_activity' => $vip_recharge_activity, 'plus_recharge_activity' => $plus_recharge_activity ); return $res; } /** * 获取最大赠送金额 * @param int $merchant_id 商户id * @param int $store_id 门店id * @param int $money 充值金额 * @param int $type 类型 0.线下 1.线上 * @param int $user_type 用户类型 2.plus会员 3.普通会员 * @return array|bool $res|false */ public function getMaxGiveMoney($merchant_id, $store_id, $money, $type, $user_type = 3) { if (!$merchant_id || !$store_id) { return false; } // 查询充值活动 $time = time(); $map = array( $this::MERCHANT_ID => $merchant_id, $this::STORE_ID => $store_id, $this::STATUS => 1, $this::STATE => 1, $this::RECHARGE_MONEY => array('elt', $money), $this::SURPLUS => array(array('eq', '-1'), array('gt', 0), 'or'), $this::START_TIME => array(array('eq', ''), array('lt', $time), 'or'), $this::END_TIME => array(array('eq', ''), array('gt', $time), 'or'), $this::ROLE_TYPE => $user_type, $this::SCENE_TYPE => 1, ); // 判断线上线下 if ($type == 0) { // 线下 $map[$this::LINE_STATE] = 1; } else { // 线上 $map[$this::ONLINE_STATE] = 1; } $field = array($this::ID, $this::RECHARGE_MONEY, $this::GIVE_MONEY, $this::SURPLUS, $this::LIMIT_NUM, $this::AGING_REPAY, $this::AGING_TIME); $recharge_act = $this->getOrderFind($map, $field, 'give_money desc'); return $recharge_act ? $recharge_act : 0; } /** * 验证会员充值档次是否能进行,并返回充值档次信息 * @param $vid 会员id * @param $recharge_id 充值档次id * @param $merchant_id 商户id * @param $type 验证类型 1线上 2线下 * @return bool */ public function checkRecharge_v1($vid, $recharge_id, $merchant_id, $type) { $time = time(); $map = array( $this::ID => $recharge_id, $this::STATUS => 1, $this::STATE => 1, $this::SURPLUS => array(array('eq', '-1'), array('gt', 0), 'or'), $this::START_TIME => array(array('eq', ''), array('lt', $time), 'or'), $this::END_TIME => array(array('eq', ''), array('gt', $time), 'or'), ); if ($type == 1) { $map[$this::ONLINE_STATE] = 1; } else { $map[$this::LINE_STATE] = 1; } $data = $this->getFind($map); // 判断活动 if (empty($data)) { return false; } // 判断会员限制数量 if (intval($data[$this::LIMIT_NUM]) > 0) { $RechargeOrderModel = D('RetailRechargeOrder'); $map = array( $RechargeOrderModel::VID => $vid, $RechargeOrderModel::MERCHANT_ID => $merchant_id, $RechargeOrderModel::STATUS => 1, $RechargeOrderModel::VIP_RECHARGE_ID => $recharge_id, ); $count = $RechargeOrderModel->getCount($map); if ($count >= intval($data[$this::LIMIT_NUM])) { return false; } } // 验证通过 return $data; } }