request; if ($request->isPost) { $user_info = BusinessBonusUser::getInfo($this->mall_id, $this->user); $config = Yii::$app->services->setting->addons->get($this->mall_id, BusinessBonusEnums::ADDONS_NAME, 'basic'); // 结算周期 $settle_circle = $config['settle_circle'] ?? BusinessBonusEnums::SETTLE_CIRCLE_DAY; // 今天 $today_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('today'), strtotime('tomorrow') - 1); if ($settle_circle == BusinessBonusEnums::SETTLE_CIRCLE_DAY) { // 一天 // 昨天、前天 $current_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('yesterday'), strtotime('today') - 1); $pre_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('yesterday -1 day'), strtotime('yesterday') - 1); $bonus_count = [ ['title' => '今天', 'value' => $today_count], ['title' => '昨天', 'value' => $current_count], ['title' => '前天', 'value' => $pre_count] ]; } else if ($settle_circle == BusinessBonusEnums::SETTLE_CIRCLE_WEEK) { // 一周 // 本周、上周 $current_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('Monday this week'), time()); $pre_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('Monday last week'), strtotime('Monday this week') - 1); $bonus_count = [ ['title' => '今天', 'value' => $today_count], ['title' => '本周', 'value' => $current_count], ['title' => '上周', 'value' => $pre_count] ]; } else { // 一个月 // 本月、上月 $current_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('midnight first day of this month'), time()); $pre_count = BusinessBonusReward::getCustomStatistic($this->mall_id, $this->user_id, strtotime('midnight first day of last month'), strtotime('midnight first day of this month') - 1); $bonus_count = [ ['title' => '今天', 'value' => $today_count], ['title' => '本月', 'value' => $current_count], ['title' => '上月', 'value' => $pre_count] ]; } $user_info['bonus_count'] = $bonus_count; return $this->success('招商员信息', $user_info); } } /** * 获取申请页面的数据 */ public function actionApplyInfo() { $request = Yii::$app->request; if ($request->isPost) { // 初级招商员的福利介绍 $business_bonus_level = BusinessBonusEnums::FIRST_BUSINESS_LEVEL; $benefit_intro = BusinessBonusLevelInfo::getBenefitIntro($this->mall_id, $business_bonus_level); $level_info = BusinessBonusLevel::getOne([ ['=', 'mall_id', $this->mall_id], ['=', 'level', $business_bonus_level], ['>=', 'status', StatusEnum::DISABLED] ], true); $is_apply = BusinessBonusUpgradeApply::getOne([ ['=', 'mall_id', $this->mall_id], ['=', 'user_id', $this->user_id], ['=', 'status', StatusEnum::ENABLED], ], true, '', 'id desc'); $is_applying = 0; if ($is_apply && $is_apply['audit_status'] == BusinessBonusEnums::AUDIT_STATUS_CHECKING) { $is_applying = 1; } $info = [ 'benefit_intro' => $benefit_intro, 'level_name' => $level_info['level_name'] ?? '', 'bonus_rate' => $level_info['bonus_rate'] ?? 0, 'user_id' => $this->user->id, 'nickname' => $this->user->nickname, 'mobile' => $this->user->mobile, 'is_applying' => $is_applying ]; return $this->success('申请成为招商员', $info); } } /** * 获取等级说明 */ public function actionLevelDesc() { $request = Yii::$app->request; if ($request->isPost) { // 初级招商员的福利介绍 $config = Yii::$app->services->setting->addons->get($this->mall_id, BusinessBonusEnums::ADDONS_NAME, 'basic'); return $this->success('申请成为招商员', ['level_desc' => $config['level_desc'] ?? '']); } } /** * 申请成为招商员 */ public function actionApplyBusinessUser() { $request = Yii::$app->request; if ($request->isPost) { $res = BusinessBonusUpgradeApply::apply($this->mall_id, $this->user_id); if ($res == false) return $this->error(BusinessBonusUpgradeApply::getStaticError()); return $this->success('提交成功', ['res_code' => $res]); } } /** * 购买指定商品成为招商员-等级列表 */ public function actionBusinessUserLevel() { $request = Yii::$app->request; if ($request->isPost) { $params = $request->post(); $res = Yii::$app->services->validate->validate($params, [ [['page'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [ ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED], ]; $order = 'level asc'; $list = BusinessBonusLevel::listPage(compact('where', 'order'), false, true); $list['list'] = $list['list'] ?? []; $level_array = array_unique(array_filter(array_column($list['list'], 'level'))); $info_list = BusinessBonusLevelInfo::find() ->select('business_bonus_level,benefit_intro') ->andWhere(['=', 'status', StatusEnum::ENABLED]) ->andWhere(['in', 'business_bonus_level', $level_array]) ->andWhere(['=', 'mall_id', $this->mall_id]) ->asArray() ->all(); $level_info_data = array_column($info_list, 'benefit_intro', 'business_bonus_level'); $cond_list = BusinessBonusUpgradeCondition::find() ->select('business_bonus_level,goods_id,upgrade_type,is_audit') ->andWhere(['=', 'status', StatusEnum::ENABLED]) ->andWhere(['in', 'business_bonus_level', $level_array]) ->andWhere(['=', 'mall_id', $this->mall_id]) ->asArray() ->all(); $cond_data = array_column($cond_list, null, 'business_bonus_level'); $business_user = BusinessBonusUser::getOne([ ['=', 'mall_id', $this->mall_id], ['>=', 'status', StatusEnum::DISABLED], ['=', 'user_id', $this->user_id] ], true); foreach ($list['list'] as $key => $val) { $val['benefit_intro'] = $level_info_data[$val['level']] ?? ''; $condition = $cond_data[$val['level']] ?? []; $val['goods_id'] = $condition['goods_id'] ?? 0; $val['goods_id'] = explode(',', $val['goods_id'])[0]; // 防止有多个,目前只有一个 $val['upgrade_type'] = $condition['upgrade_type'] ?? 0; $val['current_level'] = $business_user['business_bonus_level'] ?? 0; $list['list'][$key] = $val; } return $this->success('招商员等级', $list); } } /** * 奖励记录 */ public function actionRewardList() { $request = Yii::$app->request; if ($request->isPost) { $params = $request->post(); $res = Yii::$app->services->validate->validate($params, [ [['page', 'bonus_status', 'store_id', 'store_type', 'add_order_goods'], 'integer'], [['time_value'], 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [ ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED], ['=', 'user_id', $this->user_id], ]; if ($params['bonus_status'] !== '' || $params['bonus_status'] !== null) { $where[] = ['=', 'bonus_status', $params['bonus_status']]; } if ($params['store_id']) { $where[] = ['=', 'store_id', $params['store_id']]; } if ($params['store_type'] == BusinessBonusEnums::STORE_TYPE_STORE) { $where[] = ['=', 'from_type', BusinessBonusEnums::FROM_TYPE_STORE]; } else if ($params['store_type'] == BusinessBonusEnums::STORE_TYPE_MCH) { $where[] = ['=', 'from_type', BusinessBonusEnums::FROM_TYPE_MCH]; } if ($params['time_value'] == 'today') { // 今天 $where[] = ['>=', 'created_at', strtotime('today')]; $where[] = ['<=', 'created_at', time()]; } else if ($params['time_value'] == 'one_week') { // 最近1周 $where[] = ['>=', 'created_at', strtotime('-1 week')]; $where[] = ['<=', 'created_at', time()]; } else if ($params['time_value'] == 'two_week') { // 最近2周 $where[] = ['>=', 'created_at', strtotime('-2 weeks')]; $where[] = ['<=', 'created_at', time()]; } else if ($params['time_value'] == 'one_month') { // 最近1个月 $where[] = ['>=', 'created_at', strtotime('-1 month')]; $where[] = ['<=', 'created_at', time()]; } else if ($params['time_value'] == 'three_month') { // 最近3个月 $where[] = ['>=', 'created_at', strtotime('-3 months')]; $where[] = ['<=', 'created_at', time()]; } else if ($params['time_value'] == 'six_month') { // 最近6个月 $where[] = ['>=', 'created_at', strtotime('-6 months')]; $where[] = ['<=', 'created_at', time()]; } else if ($params['time_value'] == 'one_year') { // 最近1年 $where[] = ['>=', 'created_at', strtotime('-1 year')]; $where[] = ['<=', 'created_at', time()]; } $order = 'id desc'; $select = 'id,order_no,settle_amount,bonus_rate,bonus_amount,from_type,store_id,order_id,created_at'; $list = BusinessBonusReward::listPage(compact('where', 'order', 'select'), false, true); $list['list'] = $list['list'] ?? []; $list['list'] = BusinessBonusReward::dealRewardList($list['list'], $this->mall_id, $params['add_order_goods']); if ($params['page'] == 1) $list['bonus_amount_count'] = BusinessBonusReward::getOne($where, true, '', '', 'sum(bonus_amount) as total_amount')['total_amount'] ?? 0; return $this->success('分红记录', $list); } } /** * 获取可选门店 * @return mixed|void */ public function actionStoreList() { $request = Yii::$app->request; if ($request->isPost) { $params = $request->post(); $res = Yii::$app->services->validate->validate($params, [ [['store_type'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $list = BusinessBonusStore::find() ->select('id,store_id,store_type') ->andWhere(['=', 'mall_id', $this->mall_id]) ->andWhere(['=', 'business_user_id', $this->user_id]) ->andWhere(['=', 'status', StatusEnum::ENABLED]); if ($params['store_type']) { $list = $list ->andWhere(['=', 'store_type', $params['store_type']]); } $list = $list ->orderBy('id desc') ->asArray() ->all(); $store_ids = $mch_ids = []; foreach ($list as $item) { if ($item['store_type'] == BusinessBonusEnums::STORE_TYPE_STORE) { $store_ids[] = $item['store_id']; } else { $mch_ids[] = $item['store_id']; } } $store_array = $mch_array = []; if ($store_ids) { $store_list = Store::find() ->select('id,user_id,store_name') ->andWhere(['>=', 'status', StatusEnum::DISABLED]) ->andWhere(['in', 'id', $store_ids]) ->andWhere(['=', 'mall_id', $this->mall_id]) ->asArray() ->all(); $store_array = array_column($store_list, null, 'id'); } if ($mch_ids) { $mch_list = Mch::find() ->select('id,user_id,store_name') ->andWhere(['>=', 'status', StatusEnum::DISABLED]) ->andWhere(['in', 'id', $mch_ids]) ->andWhere(['=', 'mall_id', $this->mall_id]) ->asArray() ->all(); $mch_array = array_column($mch_list, null, 'id'); } foreach ($list as $index => $value) { $value['store_name'] = ''; if ($value['store_type'] == BusinessBonusEnums::STORE_TYPE_STORE) { $value['store_name'] = $store_array[$value['store_id']]['store_name'] ?? ''; } else { $value['store_name'] = $mch_array[$value['store_id']]['store_name'] ?? ''; } unset($value['id']); $list[$index] = $value; } return $this->success('分红记录', $list); } } }