request->isAjax) { return $this->render('/setting/index'); } $is_install_distribution = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION); $is_install_agent = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AGENT); $is_install_boss = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_BOSS); $is_install_area = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AREA); $is_install_double_copy = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DOUBLE_COPY); $is_install_rebate = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_REBATE); if (\Yii::$app->request->isGet) { $web_url = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.web_url'); if (empty($web_url)) { $h5_domain = 'https://h5.qijianshirjcs.com/'; $mall_sign = ''; } else { $url_info = explode('?', $web_url); $h5_domain = $url_info[0]; $mall_sign = substr($url_info[1], mb_strlen('sign=')); } $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic'); $cashier = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'cashier'); $enter = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter'); $mode = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'mode'); $decoration = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'decoration'); $goodsStore = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'goodsStore'); $finance = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'finance'); $payment = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'payment'); $tips = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'tips'); $advertising = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'advertising'); $scoreGive = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'scoreGive'); $rating_setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'rating_setting'); $sms_setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'sms_setting'); if (!empty($enter['goods_ids'])) { $goods_ids = json_decode($enter['goods_ids'], true); $goods = Goods::find() ->select('id,goods_name,cover_pic') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $goods_ids]) ->asArray() ->all(); } else { $goods_ids = $goods = []; } if (empty($enter)) { $enter = null; } else { $enter['goods_ids'] = $goods_ids; $enter['goods_list'] = $goods; $enter['template_store'] = empty($enter['template_store']) ? '' : json_decode($enter['template_store'], true); } if (empty($basic)) { $basic = [ 'is_distribution_enable' => $is_install_distribution, 'is_agent_enable' => $is_install_agent, 'is_boss_enable' => $is_install_boss, 'is_area_enable' => $is_install_area, 'is_basic_null' => true, 'is_double_copy_enable' => $is_install_double_copy, 'is_rebate_enable' => $is_install_rebate, ]; } else { $basic['is_distribution_enable'] = $is_install_distribution; $basic['is_agent_enable'] = $is_install_agent; $basic['is_boss_enable'] = $is_install_boss; $basic['is_area_enable'] = $is_install_area; $basic['is_double_copy_enable'] = $is_install_double_copy; $basic['is_rebate_enable'] = $is_install_rebate; } if(empty($basic['service_fee_settle_type'])) $basic['service_fee_settle_type'] = 1; if(empty($basic['localtion_limit'])) $basic['localtion_limit'] = 10; if(empty($basic['double_copy_status'])) $basic['double_copy_status'] = 0; if(empty($basic['store_distribution_status'])) $basic['store_distribution_status'] = 0; if(empty($basic['store_agent_status'])) $basic['store_agent_status'] = 0; if(empty($basic['store_area_status'])) $basic['store_area_status'] = 0; if(empty($basic['store_boss_status'])) $basic['store_boss_status'] = 0; if(empty($basic['store_rebate_status'])) $basic['store_rebate_status'] = 0; if(empty($basic['store_distribution_fee_type'])) $basic['store_distribution_fee_type'] = 1; if(empty($basic['store_area_fee_type'])) $basic['store_area_fee_type'] = 1; if(empty($basic['service_fee_type'])) $basic['service_fee_type'] = 0; if(empty($basic['max_platform_ratio'])) $basic['max_platform_ratio'] = null; if(empty($basic['min_platform_ratio'])) $basic['min_platform_ratio'] = null; if(empty($scoreGive['score_give_setting'])) { $scoreGive['score_give_setting'] = [ 'is_open'=>0, 'bear'=>0, 'condition'=>1, 'give_type'=>1, 'give_num'=>0, 'settlement'=>0 ]; }else{ $scoreGive['score_give_setting'] = json_decode($scoreGive['score_give_setting'],true); } if(!isset($scoreGive['score_give_is_store_alone'])){ $scoreGive['score_give_is_store_alone'] = 0; } $scoreGive['store_limit_type'] = $scoreGive['store_limit_type'] ?? 0; $scoreGive['store_limit_stores'] = isset($scoreGive['store_limit_stores']) ? json_decode($scoreGive['store_limit_stores'], true) : []; $scoreGive['store_limit_protocol'] = $scoreGive['store_limit_protocol'] ?? ''; if(empty($advertising)) { $advertising= ['is_open'=>0,'type'=>1, 'pic'=>'', 'url'=>'']; }else{ if(!isset($advertising['type'])) $advertising['type']= 1; } if(empty($rating_setting)) { $rating_setting= ['total_score'=>1,'environment_score'=>1, 'service_score'=>1, 'staff_score'=>1]; } if (empty($sms_setting)) { $sms_setting = [ 'is_pay_remind' => 0, 'pay_template_id' => '', 'pay_template_variable' => '', 'is_alert_expire' => 0, 'expire_day' => '', 'expire_template_id' => '', 'expire_template_variable' => '' ]; } /* cashier */ /* ---------- 用户权重相关配置处理 start ------ */ $member_levels = UserLevel::find() ->select('level,name as level_name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); if (empty($member_levels)) { $member_levels = [ // ['level' => 0, 'level_name' => '默认权重'], ]; } if (!empty($cashier['members'])) { $setting_members = json_decode($cashier['members'], true); $mem_levels = array_column($setting_members, 'level'); $mem_level_discount_map = array_column($setting_members, 'discount', 'level'); } else { $mem_levels = []; $mem_level_discount_map = []; } foreach ($member_levels as &$mlevel) { if (!in_array($mlevel['level'], $mem_levels)) { $mlevel['discount'] = 0; } else { $mlevel['discount'] = floatval($mem_level_discount_map[$mlevel['level']] ?? 0); } } //获取服务费比例 $platform_basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic'); $cashier['platform_service_fee_setting'] = [ 'max_platform_ratio' => $platform_basic['max_platform_ratio'], 'min_platform_ratio' => $platform_basic['min_platform_ratio'] ]; // dd($member_levels); /* ---------- 用户权重相关配置处理 end ------ */ $currency_arr = ['commission' => '佣金', 'score' => '积分']; $mode['distribution_currency'] = $currency_arr; $currency = array_keys($currency_arr); // $addons_currency_arr = GlobalInvoke::exec(GlobalInvoke::INVOKE_COMMISSION_TYPE, $this->mall_id, ['mall_id' => $this->mall_id]); $addons_currency_arr = []; $addons_currency = []; $all_addons_currency = []; foreach ($addons_currency_arr as $v) { $mode['distribution_currency'] = array_merge($mode['distribution_currency'], array_column($v, 'label', 'name')); $temp_currency = array_column($v, 'name'); $currency = array_merge($currency, $temp_currency); $addons_currency = array_merge($addons_currency, $temp_currency); $all_addons_currency = array_merge($all_addons_currency, array_column($v, 'label', 'name')); } /* ---------- 分销权重相关配置处理 start ------ */ $level = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION, 'basic.level'); if (empty($level)) $level = 0; $distribution_levels = []; if (!$is_install_distribution) { $is_distribution_enable = 0; } else { $is_distribution_enable = 1; $distribution_levels = DistributionLevel::find() ->select('level,name as level_name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $init_data = ['level' => 0, 'level_name' => '默认权重']; if (empty($distribution_levels)) { $distribution_levels = [$init_data]; } else { array_unshift($distribution_levels, $init_data); } } /* ---------- 分销权重相关配置处理 end ------ */ /* ---------- 经销权重相关配置处理 start ------ */ $cashier_agent_currency = ['settings' => '佣金']; $cashier['cashier_agent_currencys'] = array_merge($cashier_agent_currency, $all_addons_currency); $cashier_agent_currency_arr = array_keys($cashier['cashier_agent_currencys']); $agent_enable = $this->getCashierEnable(['settings' => ''], $addons_currency, $cashier, 'agent'); $cashier = array_merge($cashier, $agent_enable['cashier']); $cashier['agent_enable_keys'] = $agent_enable['enable_keys'] ?? ''; // 保存数据是额外验证的字段 $cashier['validate_fields'] = array_merge($agent_enable['keys'], $agent_enable['ratio']); if (!$is_install_agent) { $agent_setting_keys = []; foreach ($cashier_agent_currency_arr as $agent_currency) { $agent_currency_key = 'agent_' . $agent_currency; $agent_setting_keys[] = $agent_currency_key; $cashier[$agent_currency_key] = [ 'team_rewards' => [], 'equal_rewards' => [], 'over_rewards' => [], ]; } $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $agent_setting_keys); // $agent_settings = [ // 'team_rewards' => [ // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0], // ], // 'equal_rewards' => [ // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0], // ], // 'over_rewards' => [ // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0], // ], // ]; $is_agent_enable = 0; } else { $is_agent_enable = 1; $agent_levels = AgentLevel::find() ->select('level,name as level_name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); if (empty($agent_levels)) { $agent_levels = [ // ['level' => 0, 'level_name' => '默认权重'], ]; } $agent_data = $this->getCashierAgentData($agent_levels, $cashier_agent_currency_arr, $cashier); $cashier = array_merge($cashier, $agent_data['data']); $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $agent_data['currency_keys']); // if (!empty($cashier['agent_settings'])) { // $agent_settings = json_decode($cashier['agent_settings'], true); // } else { // $agent_settings = [ // 'team_rewards' => [ // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0], // ], // 'equal_rewards' => [ // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0], // ], // 'over_rewards' => [ // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0], // ], // ]; // } // foreach ($agent_settings as $reward_name => $setting) { // foreach ($setting as $val) { // $agent_settings[$reward_name][$val['level']] = $val; // } // } // $ag_levels = array_column($agent_settings['team_rewards'], 'level'); // $agent_level_settings = []; // foreach ($agent_levels as $alevel) { // if (!in_array($alevel['level'], $ag_levels)) { // $arr = $alevel; // $arr['commission_rate'] = 0; // $agent_level_settings['team_rewards'][] = $arr; // $agent_level_settings['equal_rewards'][] = $arr; // $agent_level_settings['over_rewards'][] = $arr; // } else { // $arr = [ // 'level' => $alevel['level'], // 'level_name' => $alevel['level_name'], // 'commission_rate' => $agent_settings['team_rewards'][$alevel['level']]['commission_rate'] ?? 0, // ]; // $agent_level_settings['team_rewards'][] = $arr; // $arr['commission_rate'] = $agent_settings['equal_rewards'][$alevel['level']]['commission_rate'] ?? 0; // $agent_level_settings['equal_rewards'][] = $arr; // $arr['commission_rate'] = $agent_settings['over_rewards'][$alevel['level']]['commission_rate'] ?? 0; // $agent_level_settings['over_rewards'][] = $arr; // } // } // $agent_settings = $agent_level_settings; /* ---------- 经销权重相关配置处理 end ------ */ } if (empty($cashier)) { $cashier = [ 'service_fee_ratio' => 0, 'member_status' => 0, 'is_distribution' => 0, 'is_agent' => 0, ]; } $cashier['deepNames'] = []; if ($level > 0) $cashier['deepNames'][] = '一级'; if ($level > 1) $cashier['deepNames'][] = '二级'; if ($level > 2) $cashier['deepNames'][] = '三级'; $cashier['members'] = $member_levels; $cashier_distribution_currencys = ['settings' => '佣金', 'settings_score' => '积分']; $cashier_distribution_currencys = array_merge($cashier_distribution_currencys, $all_addons_currency); $distribution_settings = $this->cashierDistributionData($distribution_levels, $cashier, array_keys($cashier_distribution_currencys)); $cashier = array_merge($cashier, $distribution_settings['response']); $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $distribution_settings['distribution_currency_key']); $cashier['is_distribution_enable'] = $is_distribution_enable; // $cashier['agent_settings'] = $agent_settings; $cashier['is_agent_enable'] = $is_agent_enable; // 分销收银配置是否开启的开关 $distribution_enable_arr = ['settings' => '', 'settings_score' => 'score']; $distribution_enable = $this->getCashierEnable($distribution_enable_arr, $addons_currency, $cashier, 'distribution'); $cashier = array_merge($cashier, $distribution_enable['cashier']); $distribution_enable_keys = $distribution_enable['enable_keys'] ?? ''; $cashier['distribution_enable_keys'] = $distribution_enable_keys; $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $distribution_enable['keys'], $distribution_enable['ratio']); $cashier['cashier_distribution_currencys'] = $cashier_distribution_currencys; /* 模式相关设置 */ /* 分销模式设置 ---- start ------ */ $mode['is_distribution_enable'] = $is_distribution_enable; if ($is_install_distribution) { $mode['Distribution'] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_DISTRIBUTION] ?? '', $distribution_levels, $currency, AddonsEnum::ADDONS_NAME_DISTRIBUTION); } else { $mode['Distribution'] = null; } /* 分销模式设置 ---- end ------ */ /* 经销模式设置 ---- start ------ */ $mode['is_agent_enable'] = $is_agent_enable; $mode['agent_currency'] = $mode['distribution_currency']; if ($is_install_agent) { $mode['Agent'] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_AGENT] ?? '', $agent_levels, $currency, AddonsEnum::ADDONS_NAME_AGENT); } else { $mode['Agent'] = null; } /* 经销模式设置 ---- end ------ */ /* 股东分红模式设置 ---- start ------ */ if ($is_install_boss) { $cashier['is_boss_enable'] = 1; $levels = AddonsBossLevel::find() ->select('level,name as level_name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $cashier_boss_settings=[]; if(isset($cashier['boss_settings'])){ $cashier['boss_settings']=json_decode($cashier['boss_settings'],true); $cashier_boss_settings=isset($cashier['boss_settings']['rewards'])?$cashier['boss_settings']['rewards']:[]; } $cashier['boss_settings']['rewards']=$this->getBossSetting($levels,$cashier_boss_settings); $cashier['boss_settings']['is_boss']=isset($cashier['boss_settings']['is_boss'])?$cashier['boss_settings']['is_boss']:0; $mode_boss_settings=[]; if(isset($mode['boss_settings'])){ $mode['boss_settings']=json_decode($mode['boss_settings'],true); $mode_boss_settings=isset($mode['boss_settings']['rewards'])?$mode['boss_settings']['rewards']:[]; } $mode['boss_settings']['rewards']=$this->getBossSetting($levels,$mode_boss_settings); if(!empty($mode['boss_settings']['rewards'])){ array_multisort(array_column($mode['boss_settings']['rewards'], 'level'), SORT_ASC, $mode['boss_settings']['rewards']); } $mode['boss_settings']['is_boss']=isset($mode['boss_settings']['is_boss'])?$mode['boss_settings']['is_boss']:0; $mode['is_boss_enable'] = 1; // $bs_details = []; // if (!empty($mode['Boss'])) { // $mode_boss_settings = json_decode($mode['Boss'], true); // if (!empty($mode_boss_settings['detail'])) { // foreach ($mode_boss_settings['detail'] as $detail) { // $bs_details[$detail['level']] = $detail; // } // } // } // $bs_level_settings = []; // foreach ($boss_levels as $blevel) { // if (empty($bs_details[$blevel['level']])) { // $arr = [ // 'level' => $blevel['level'], // 'level_name' => $blevel['level_name'], // 'prize' => 0, // 'extra_prize' => 0, // ]; // $bs_level_settings[] = $arr; // } else { // $bs_details[$blevel['level']]['level_name'] = $blevel['level_name']; // $bs_level_settings[] = $bs_details[$blevel['level']]; // } // } // if (!empty($bs_level_settings)) { // $mode_boss_settings['detail'] = $bs_level_settings; // } // $mode['Boss'] = $mode_boss_settings; } else { $mode['is_boss_enable'] = 0; // $mode['Boss'] = null; } $boss_key=['boss_settings']; $cashier['validate_fields'] = array_merge($cashier['validate_fields'],$boss_key); /* 股东分红模式设置 ---- end ------ */ /* 区域分红模式设置 ---- start ------ */ $area_currency_arr = ['detail' => '佣金', 'detail_score' => '积分']; $area_currency_list = array_merge($area_currency_arr, $all_addons_currency); $mode['area_currency'] = $area_currency_list; $cashier['area_currency'] = $area_currency_list; $area_currency = array_keys($area_currency_arr); $area_currency = array_merge($area_currency, $addons_currency); if ($is_install_area) { $mode['is_area_enable'] = 1; $area_levels = [ 6 => ['level' => 6, 'level_name' => '大区代'], 1 => ['level' => 1, 'level_name' => '省代'], 2 => ['level' => 2, 'level_name' => '市代'], 3 => ['level' => 3, 'level_name' => '区代'], 4 => ['level' => 4, 'level_name' => '镇代'], 5 => ['level' => 5, 'level_name' => '小区代'] ]; $mode['Area'] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_AREA] ?? '', $area_levels, $area_currency, AddonsEnum::ADDONS_NAME_AREA, 0, ['remaining_ratio']); } else { $mode['is_area_enable'] = 0; $mode['Area'] = null; } /* 收银台区域分红模式设置 ---- start ------ */ if ($is_install_area) { $area_levels = [ 6 => ['level' => 6, 'level_name' => '大区代'], 1 => ['level' => 1, 'level_name' => '省代'], 2 => ['level' => 2, 'level_name' => '市代'], 3 => ['level' => 3, 'level_name' => '区代'], 4 => ['level' => 4, 'level_name' => '镇代'], 5 => ['level' => 5, 'level_name' => '小区代'] ]; // 获取配置信息 $areaSystem = $this->getAddonsData( $cashier['AreaCashier'] ?? '', $area_levels, $area_currency, AddonsEnum::ADDONS_NAME_AREA, 0, ['remaining_ratio'] ); $cashier['is_area_enable_cashier'] = 1; $cashier['AreaCashier'] = $areaSystem; } else { $cashier['is_area_enable_cashier'] = 0; $cashier['AreaCashier'] = null; } /* 收银台区域分红模式设置 ---- end ------ */ /* 股东分红模式设置 ---- end ------ */ $double_copy_carshier_key = AddonsEnum::ADDONS_NAME_DOUBLE_COPY.'_Cashier'; if ($is_install_double_copy) { $double_copy_levels = DoubleCopyLevel::find() ->select('level,name as level_name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $mode[AddonsEnum::ADDONS_NAME_DOUBLE_COPY] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_DOUBLE_COPY] ?? '', $double_copy_levels, ['commission'], AddonsEnum::ADDONS_NAME_DOUBLE_COPY, 1, [], ['is_percent' => 0]); $mode[$double_copy_carshier_key] = $this->getAddonsData($mode[$double_copy_carshier_key] ?? '', $double_copy_levels, ['commission'], AddonsEnum::ADDONS_NAME_DOUBLE_COPY, 1, [], ['is_percent' => 0]); $cashier['is_double_copy_enable_cashier'] = 1; $cashier[$double_copy_carshier_key] = $this->getAddonsData($cashier[$double_copy_carshier_key] ?? '', $double_copy_levels, ['commission'], AddonsEnum::ADDONS_NAME_DOUBLE_COPY, 1, [], ['is_percent' => 0]); } else { $mode[AddonsEnum::ADDONS_NAME_DOUBLE_COPY] = null; $mode[$double_copy_carshier_key] = null; $cashier['is_double_copy_enable_cashier'] = 0; } if ($is_install_rebate) { $mode[AddonsEnum::ADDONS_NAME_REBATE] = $this->getRebateData($mode[AddonsEnum::ADDONS_NAME_REBATE] ?? ''); } else { $mode[AddonsEnum::ADDONS_NAME_REBATE] = null; } // dd($mode); if(!isset( $cashier['member_status'])){ $cashier['member_status'] = 0; } $goodsStore['is_limit_max_price'] = isset($goodsStore['is_limit_max_price'])&&$goodsStore['is_limit_max_price']=='true'?true:false; $H5Url = \Yii::$app->services->setting->platform->get('system.h5_url'); $store_h5_login_url = $H5Url . '/#/plugins2/Store/admin/login?sign=' . $this->mall['mall_sign']; $store_setting['store_h5_login_url'] =$store_h5_login_url ; //收银台设置 $cashier['collect_reward_info'] = json_decode($cashier['collect_reward_info'] ?? '', true) ?? []; $cashier['payment_reward_info'] = json_decode($cashier['payment_reward_info'] ?? '', true) ?? []; $cashier['collect_reward'] = array_column($cashier['collect_reward_info'],'type'); $cashier['payment_reward'] = array_column($cashier['payment_reward_info'],'type'); $payment_reward_info = []; $collect_reward_info = []; $scoreExpansionConfig = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_SCORE_EXPANSION, 'basic'); if(!empty($scoreExpansionConfig) && !empty($scoreExpansionConfig['frozen_status'])){ $name = empty($scoreExpansionConfig['integral_name']) ? '激活积分' : '激活'.$scoreExpansionConfig['integral_name']; $payment_reward_info[] = [ 'name'=> $name, 'type' => 'payment_parent_reward_score', 'value' => '', ]; $payment_reward_info[] = [ 'name'=> $name, 'type' => 'payment_reward_score', 'value' => '', ]; $collect_reward_info[] = [ 'name'=> $name, 'type' => 'collect_reward_score', 'value' => '', ]; $collect_reward_info[] = [ 'name'=>$name, 'type' => 'collect_parent_reward_score', 'value' => '', ]; } if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_CONTRIBUTION_CURRENCY)) { $collect_reward_info[] = [ 'name'=> '贡献值', 'type' => 'collect_reward_contribution', 'value' => '', ]; } if(!empty($collect_reward_info) && !empty($cashier['collect_reward_info'])){ foreach($collect_reward_info as &$info){ foreach($cashier['collect_reward_info'] as $item){ if($item['type'] == $info['type']){ $info['value'] = $item['value']; } } } } if(!empty($payment_reward_info) && !empty($cashier['payment_reward_info'])){ foreach($payment_reward_info as &$info){ foreach($cashier['payment_reward_info'] as $item){ if($item['type'] == $info['type']){ $info['value'] = $item['value']; } } } } //收款方 $cashier['collect_reward_info'] = $collect_reward_info; $cashier['preferential_undertaking'] = $cashier['preferential_undertaking']??'1'; //付款方 $cashier['payment_reward_info'] = $payment_reward_info; //收款码额度 $cashier['cashier_amount_info'] = json_decode($cashier['cashier_amount_info'] ?? '',true) ?? []; $cashier['cashier_amount'] = array_column($cashier['cashier_amount_info'],'type'); $cashier_amount_info = [ ['type' => 'cashier_amount','value' => 0], ['type' => 'cashier_amount_month','value' => 0] ]; if(!empty($cashier_amount_info) && !empty($cashier['cashier_amount_info'])){ foreach($cashier_amount_info as &$info){ foreach($cashier['cashier_amount_info'] as $item){ if($item['type'] == $info['type']){ $info['value'] = $item['value']; } } } } $cashier['cashier_amount_info'] = $cashier_amount_info; $cashier['cashier_settle_type'] = $cashier['cashier_settle_type'] ?? 1; //货款设置 $basic['payment_settle_info'] = json_decode($basic['payment_settle_info'],true) ?? []; $basic['payment_settle'] = array_column($basic['payment_settle_info'],'type'); $payment_settle_info = [ ['type' => 'settle_judge_yes','value' => 0], ['type' => 'settle_judge_no','value' => 0] ]; if(!empty($payment_settle_info) && !empty($basic['payment_settle_info'])){ foreach($payment_settle_info as &$info){ foreach($basic['payment_settle_info'] as $item){ if($item['type'] == $info['type']){ $info['value'] = $item['value']; } } } } $basic['payment_settle_info'] = $payment_settle_info; //资产设置 $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2); $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY,$this->mall_id); $all_withdraw = array_merge($default_withdraw_way,$extension_withdraw_way); if (!empty($all_withdraw['alipay_tax'])) { $all_withdraw['alipay_tax'] = $all_withdraw['alipay_tax']['name']; } $finance['balance_withdraw_way'] = $all_withdraw; //提现条件 if(!empty($finance['balance_cash_type'])){ $finance['balance_cash_type'] = json_decode($finance['balance_cash_type'],true); }else{ //默认银行卡/余额提现 $finance['balance_cash_type'] = ['balance','bank']; } if(!isset($finance['balance_cash_service_fee'])){ $balance_cash_service_fee = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance.balance_cash_service_fee'); $finance['balance_cash_service_fee'] = $balance_cash_service_fee; } if(!isset($finance['balance_cash_service_fee_limit'])){ $finance['balance_cash_service_fee_limit'] = 0; } //支付方式 if(!isset($payment['payment_is_enable'])){ $payment['payment_is_enable'] = 0; } if(!isset($payment['score_pay_setting'])){ $payment['score_pay_setting'] = 0; } if(!isset($payment['score_pay'])){ $payment['score_pay'] = 0; } if(!isset($payment['score_pay_password_status'])){ $payment['score_pay_password_status'] = 0; } if(empty($payment['payment_type'])){ $payment['payment_type'] = []; }else{ $payment['payment_type'] = json_decode($payment['payment_type'],true); } if (empty($payment['pay_after_link'])) { $payment['pay_after_link'] = ''; } else { $payment['pay_after_link'] = json_decode($payment['pay_after_link'], true); } $payment['payment_way'] = \Yii::$app->services->pay->getEnablePaymentType($this->mall_id); if(!isset($payment['score_open_type'])) $payment['score_open_type'] = 1; $goodsStore['express_title_arr'] = ($goodsStore['express_title_arr'] ?? '') ? json_decode($goodsStore['express_title_arr'] ?? '',true) : ShippingTypeEnum::getMap(); $deduction_proportion = [['min'=>'','max'=>'','deduction_ratio'=>'']]; if(empty($payment['score_deduction'])){ $payment['score_deduction'] = [ 'is_score_deduction' => 0, 'effective' => 1, 'bear' => 0, 'score_balance_ratio' => '', 'deduction_proportion' => $deduction_proportion, 'deduction_type' => 0, 'max_deduction_percent' => 0, 'store_limit_type' => 0, 'store_limit_stores' => [], 'store_limit_stores_deduction' => [] ]; }else{ $payment['score_deduction'] = json_decode($payment['score_deduction'],true); if(empty($payment['score_deduction']['deduction_proportion'])){ $payment['score_deduction']['deduction_proportion'] = $deduction_proportion; } $payment['score_deduction']['deduction_type'] = $payment['score_deduction']['deduction_type'] ?? 0; $payment['score_deduction']['max_deduction_percent'] = $payment['score_deduction']['max_deduction_percent'] ?? 0; $payment['score_deduction']['store_limit_type'] = $payment['score_deduction']['store_limit_type'] ?? 0; $payment['score_deduction']['store_limit_stores_deduction'] = $payment['score_deduction']['store_limit_stores_deduction'] ?? []; $payment['score_deduction']['store_limit_stores'] = array_keys($payment['score_deduction']['store_limit_stores_deduction']); } if(!isset($decoration['default_store_cate_style'])){ $decoration['default_store_cate_style'] = 1; } $settings = [ 'basic' => $basic, 'cashier' => $cashier, 'enter' => $enter, 'mode' => $mode, 'decoration' => $decoration, 'goodsStore' => $goodsStore, 'store_setting' => $store_setting, 'finance' => $finance, 'payment' => $payment, 'tips' => empty($tips) ? ['link_tips' => '', 'bank_account_tips' => '',] : $tips, 'advertising' => $advertising, 'scoreGive' => $scoreGive, 'rating_setting' => $rating_setting, 'sms_setting' => $sms_setting, ]; $group = \Yii::$app->request->get('group'); if (!empty($group)) { $settings = $settings[$group] ?? []; } $settings['h5_domain'] = MallHost::getHost($this->mall_id, 'h5_url'); $settings['mall_sign'] = $this->mall['mall_sign']; $settings['level'] = $level; $settings['basic']['o2o_url'] = 'plugins2/Store/store/storeindex'; $notice_wechat_config = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'notice'); $notice_wechat_template_message_list = StoreEnum::getWechatTemplateMap(); $notice_wechat = empty($notice_wechat_config['notice_wechat']) ? [] : json_decode($notice_wechat_config['notice_wechat'],true); $notice_wechat_template_message_value = $notice_wechat['template_message'] ?? []; foreach ($notice_wechat_template_message_list as $key=>$template_name){ if(!isset($notice_wechat_template_message_value[$key])){ $notice_wechat_template_message_value[$key] = ['tem_key'=>'', 'name'=>$template_name, 'tempid'=>'',]; } } $settings['notice_wechat']['is_logging'] = $notice_wechat['is_logging'] ?? 1; $settings['notice_wechat']['template_message'] = $notice_wechat_template_message_value; return $this->success('success', $settings); } else { $post = \Yii::$app->request->post(); $group = $post['group'] ?? ''; unset($post['_csrf'], $post['group']); if (empty($group)) { return $this->error('参数错误'); } $validate_fields = []; if ($group == 'cashier') { $validate_fields = $post[$group]['validate_fields']; } $rules = [ 'basic' => [ [['o2o_url', 'goods_auth', 'service_fee', 'settle_type', 'platform_ratio', 'risk_management', 'risk_management_ratio', 'settle_scene', 'store_distribution_status', 'store_agent_status', 'store_area_status', 'store_boss_status', 'double_copy_status','store_rebate_status','service_fee_settle_type'], 'required'], [['o2o_url','platform_address','suona_appSecret','suona_appId','suona_host'], 'string', 'max' => 255], [['goods_auth', 'settle_type', 'risk_management', 'settle_scene', 'store_distribution_status', 'store_agent_status', 'store_area_status', 'store_boss_status','watch_times','recommend_nums','is_show_location_store', 'double_copy_status','store_rebate_status','is_enable_dollars_symbol', 'is_location_limit', 'service_fee_type', 'store_distribution_fee_type', 'store_area_fee_type','service_fee_settle_type'], 'integer'], [['service_fee', 'platform_ratio', 'risk_management_ratio', 'min_platform_ratio','max_platform_ratio'], 'number', 'min' => 0, 'max' => 100, 'message' => '比例取值在 0 ~ 100 之间'], [['localtion_limit'], 'number'], [['payment_settle_info','payment_settle','score_give_setting','total_score','speciality','service_attitude','timeliness'],'safe'], [['dollars_symbol'],'string'], ], 'cashier' => [ //distribution_settings distribution_settings_score no required [['service_fee_ratio', 'member_status', 'is_distribution', 'is_agent','preferential_undertaking'], 'required'], [['member_status', 'is_distribution', 'is_distribution_score', 'is_agent', 'cashier_settle_type'], 'integer'], [array_merge(['members', 'agent_settings'], $validate_fields), 'safe'], [['service_fee_ratio'], 'number', 'min' => 0, 'max' => 100, 'message' => '比例取值在 0 ~ 100 之间'], [['collect_reward','payment_reward','collect_reward_info','payment_reward_info','cashier_amount','cashier_amount_info','cashier_bg_img','payment_settle_info','DoubleCopy_Cashier', 'AreaCashier'],'safe'], ], 'enter' => [ [['is_enable', 'time_status', 'expired_days', 'store_audit', 'upload_license_image', 'mode'], 'required'], [['is_enable', 'time_status', 'expired_days', 'store_audit', 'upload_license_image', 'mode','store_auth', 'is_template', 'is_front_template'], 'integer'], [['recruit_title', 'recruit_content', 'recruit_btn_text', 'dow_center_agreement'], 'string'], ['goods_ids', 'safe'], [['buy_store_num', 'finish_order_num','template_store'], 'safe'], ], 'mode' => [ [['is_enable_mode'], 'required'], ['is_enable_mode', 'integer'], [['Distribution', 'Agent', 'Boss', 'Area','boss_settings', 'DoubleCopy','Rebate'], 'safe'] ], 'decoration' => [ [['custom_goods_style','default_goods_style','custom_store_style','default_store_style','default_store_cate_style', 'store_category_switch'], 'integer'], [['near_shop_title'],'string'] ], 'goodsStore' => [ [['min_price','max_price','is_limit_max_price', 'is_hidden_goods_store'], 'safe'], [['express_title_arr'],'safe'] ], 'store' => [ [['store_h5_login_url'], 'safe'], [['service_fee_ratio', 'member_status', 'is_distribution', 'is_agent','preferential_undertaking'], 'required'], ], 'finance' => [ ['freeze_is_enable', 'integer'], ['finance_name', 'string'], [['balance_cash_type','balance_cash_service_fee','balance_cash_service_fee_limit','balance_cash_service_fee_month','balance_cash_service_fee_diff','balance_cash_service_fee_month'],'safe'], ], 'payment' => [ [['payment_is_enable','score_pay_setting','score_pay','score_pay_password_status','score_open_type'], 'integer'], [['store_limit_protocol'], 'string'], [['payment_type', 'pay_after_link','score_deduction'],'safe'], ], 'tips' => [ [['bank_account_tips', 'link_tips'],'string'], ], 'advertising' => [ [['is_open','type'],'integer'], [['pic', 'url'],'string'], ], 'rating_setting' => [ [['total_score','environment_score','service_score','staff_score'],'integer'], ], 'scoreGive' => [ [['score_give_setting', 'store_limit_stores'], 'safe'], [['score_give_is_store_alone', 'store_limit_type'], 'integer'], [['store_limit_protocol'], 'string'] ], 'sms_setting' => [ [['is_pay_remind', 'pay_template_id', 'pay_template_variable'], 'safe'], [['is_pay_remind', 'is_alert_expire', 'expire_day'], 'integer'], [['pay_template_id', 'pay_template_variable', 'expire_template_id', 'expire_template_variable'], 'string'] ], 'notice' => [ [['notice_wechat'], 'safe'], ] ]; $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if ('basic' == $group) { // if(isset($post['basic']['recommend_nums'])){ // $store_goods= StoreGoods::find() // ->select("count(*) counts,store_id") // ->where(['mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED,'is_recommend'=>1]) // ->groupBy('store_id')->orderBy('counts desc')->asArray()->one(); // if(!empty($store_goods['counts'])&&$post['basic']['recommend_nums']<$store_goods['counts']){ // return $this->error('允许推荐商品数量不能低于'.$store_goods['counts']); // } // } $post[$group]['o2o_url'] = trim($post[$group]['o2o_url']); if (!empty($post[$group]['payment_settle'])) { foreach($post[$group]['payment_settle_info'] as $key => $item){ if(!in_array($item['type'],$post[$group]['payment_settle'])){ unset($post[$group]['payment_settle_info'][$key]); } } }else{ $post[$group]['payment_settle_info'] = []; } unset($post[$group]['payment_settle']); if ($post[$group]['service_fee'] == 1 && $post[$group]['service_fee_type'] == 1) { if ($post[$group]['min_platform_ratio'] > $post[$group]['max_platform_ratio']) { return $this->error('服务费最高比例不能小于最低比例'); } } } elseif ('enter' == $group) { if (empty($post[$group]['goods_ids'])) { $post[$group]['goods_ids'] = ''; } else { $post[$group]['goods_ids'] = json_encode($post[$group]['goods_ids']); } if (empty($post[$group]['template_store'])) { $post[$group]['template_store'] = ''; } else { $post[$group]['template_store'] = json_encode($post[$group]['template_store']); } }elseif ('goodsStore' == $group) { if($post['goodsStore']['is_limit_max_price']=='false'){ if($post['goodsStore']['min_price']>$post['goodsStore']['max_price']){ return $this->error('最低价格不能大于最高价格'); } } }elseif ('cashier' == $group) { if (!empty($post[$group]['collect_reward'])) { foreach($post[$group]['collect_reward_info'] as $key => $item){ if(in_array($item['type'],$post[$group]['collect_reward'])){ unset($post[$group]['collect_reward_info'][$key]['name']); }else{ unset($post[$group]['collect_reward_info'][$key]); } } }else{ $post[$group]['collect_reward_info'] = []; } unset($post[$group]['collect_reward']); if (!empty($post[$group]['payment_reward'])) { foreach($post[$group]['payment_reward_info'] as $key => $item){ if(in_array($item['type'],$post[$group]['payment_reward'])){ unset($post[$group]['payment_reward_info'][$key]['name']); }else{ unset($post[$group]['payment_reward_info'][$key]); } } }else{ $post[$group]['payment_reward_info'] = []; } unset($post[$group]['payment_reward']); if (!empty($post[$group]['cashier_amount'])) { foreach($post[$group]['cashier_amount_info'] as $key => $item){ if(!in_array($item['type'],$post[$group]['cashier_amount'])){ unset($post[$group]['cashier_amount_info'][$key]); } } }else{ $post[$group]['cashier_amount_info'] = []; } unset($post[$group]['cashier_amount']); $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic'); //需要收取服务费 if (!empty($basic['service_fee']) && !empty($post[$group]['service_fee_ratio'])) { //收银台服务费是否在基础设置的服务费区间 if ($post[$group]['service_fee_ratio'] > $basic['max_platform_ratio'] || $post[$group]['service_fee_ratio'] < $basic['min_platform_ratio']) { return $this->error('只能设置在平台服务费比例区间内的比例当前平台服务费比例:' . $basic['min_platform_ratio'] . '%~' . $basic['max_platform_ratio'] . '%'); } } }elseif ('finance' == $group) { if (empty($post[$group]['balance_cash_type'])) { $post[$group]['balance_cash_type'] = ''; } else { $post[$group]['balance_cash_type'] = json_encode($post[$group]['balance_cash_type']); } }elseif ('payment' == $group) { if (empty($post[$group]['payment_type'])) { $post[$group]['payment_type'] = ''; } else { $post[$group]['payment_type'] = json_encode($post[$group]['payment_type']); } if (!empty($post[$group]['pay_after_link'])) { $post[$group]['pay_after_link'] = json_encode($post[$group]['pay_after_link']); } empty($post[$group]['score_deduction']['store_limit_stores_deduction']) && $post[$group]['score_deduction']['store_limit_stores_deduction'] = []; if(isset($post[$group]['score_deduction']['store_limit_stores'])) unset($post[$group]['score_deduction']['store_limit_stores']); }elseif ('tips' == $group) { }elseif ('scoreGive' == $group) { if(empty($post[$group]['score_give_setting']['give_num'])){ $post[$group]['score_give_setting']['give_num'] = 0; } empty($post[$group]['store_limit_stores']) && $post[$group]['store_limit_stores'] = []; }elseif ('rating_setting' == $group) { if (empty($post[$group]['total_score']) && empty($post[$group]['environment_score']) && empty($post[$group]['service_score']) && empty($post[$group]['staff_score'])) { return $this->error('请设置评分设置'); } } elseif ('sms_setting' == $group) { if ($post[$group]['is_pay_remind'] && (empty($post[$group]['pay_template_id'] || empty($post[$group]['pay_template_variable'])))) { return $this->error('请完善短信设置'); } } \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, $post); if ('basic' == $group && $post[$group]['service_fee_type']) { //收银设置服务费 $cashier_service_fee_ratio = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'cashier.service_fee_ratio'); if ($cashier_service_fee_ratio > $post[$group]['max_platform_ratio'] || $cashier_service_fee_ratio < $post[$group]['min_platform_ratio']) { \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, ['cashier' => [ 'service_fee_ratio' => $post[$group]['max_platform_ratio'] ]]); } //服务费是区间的时候 要处理 O2O的服务费独立设置 \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [ 'mall_id' => $this->mall_id, 'max_platform_ratio' => $post[$group]['max_platform_ratio'], 'min_platform_ratio' => $post[$group]['min_platform_ratio'], ], StoreGoodsExtra::class, 'updateServiceFeeSetting'); \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [ 'mall_id' => $this->mall_id, 'max_platform_ratio' => $post[$group]['max_platform_ratio'], 'min_platform_ratio' => $post[$group]['min_platform_ratio'], ], StoreSettings::class, 'updateServiceFeeSetting'); } return $this->success('保存成功'); } } public function actionSendSms() { try { $post = \Yii::$app->request->post(); // $params = \Yii::$app->request->post(); // if (empty($params['mobile'])) return $this->error('请输入手机号码'); $smsConfig = MallSetting::getConfByGroup($this->mall_id, 'notice_sms', true); switch ($smsConfig['platform']['value']) { case 'aliyun'://阿里云配置 $mobile = $smsConfig['mobile']['value']; break; case 'qcloud'://阿里云配置 $mobile = $smsConfig['qcloud_mobile']['value']; break; case 'submail'://阿里云配置 $mobile = $smsConfig['submail_mobile']['value']; break; } if (!$mobile) { return $this->error('请完善平台设置-短信设置-手机号'); } $SmsConfig = new Sms($this->mall_id); switch ($post['type']) { case 3: // $SmsConfig = new SmsConfig($this->mall_id); $easy_sms = $SmsConfig->easySms; $message = new PayRemindMessage($this->mall_id, 'order_123', '自提'); break; case 4: // $SmsConfig = new Sms($this->mall_id); $easy_sms = $SmsConfig->easySms; $message = new ShopExpireMessage($this->mall_id, '6', '测试门店'); break; } $easy_sms->send($mobile, $message); return $this->success('发送成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function getCashierEnable($init_enable_arr, $addons_currency, $cashier, $addon_key) { $addons_distribution_enable_arr = []; foreach ($addons_currency as $v) { $addons_distribution_enable_arr[$v] = $v; } $enable_keys = []; $keys = []; $ratio = []; $remaining_ratio = []; $loop_enble_arr = array_merge($init_enable_arr, $addons_distribution_enable_arr); foreach ($loop_enble_arr as $k => $item) { $ratio_index = $addon_key . '_' . $k . '_remaining_ratio'; $ratio[] = $ratio_index; $remaining_ratio[$ratio_index] = $cashier[$ratio_index] ?? 0; if (empty($item)) { $keys[] = 'is_' . $addon_key; $enable_keys['is_' . $addon_key] = 0; } else { $keys[] = 'is_' . $addon_key . '_' . $item; $enable_keys['is_' . $addon_key . '_' . $item] = 0; } } foreach (array_merge($enable_keys, $remaining_ratio) as $k => $v) { if (!isset($cashier[$k])) { $cashier[$k] = $v; } } return compact('cashier', 'keys', 'ratio'); } public function getCashierAgentData($agent_levels, $currencys, $cashier) { $data = []; $currency_keys = []; foreach ($currencys as $currency) { $currency_key = 'agent_' . $currency; $currency_keys[] = $currency_key; if (!empty($cashier[$currency_key])) { $currency_settings = json_decode($cashier[$currency_key], true); } else { $currency_settings = [ 'team_rewards' => [], 'equal_rewards' => [], 'over_rewards' => [], ]; } foreach ($currency_settings as $reward_name => $setting) { foreach ($setting as $val) { $currency_settings[$reward_name][$val['level']] = $val; } } $ag_levels = array_column($currency_settings['team_rewards'], 'level'); $level_settings = []; foreach ($agent_levels as $alevel) { if (!in_array($alevel['level'], $ag_levels)) { $arr = $alevel; $arr['commission_rate'] = 0; $level_settings['team_rewards'][] = $arr; $level_settings['equal_rewards'][] = $arr; $level_settings['over_rewards'][] = $arr; } else { $arr = [ 'level' => $alevel['level'], 'level_name' => $alevel['level_name'], 'commission_rate' => $currency_settings['team_rewards'][$alevel['level']]['commission_rate'] ?? 0, ]; $level_settings['team_rewards'][] = $arr; $arr['commission_rate'] = $currency_settings['equal_rewards'][$alevel['level']]['commission_rate'] ?? 0; $level_settings['equal_rewards'][] = $arr; $arr['commission_rate'] = $currency_settings['over_rewards'][$alevel['level']]['commission_rate'] ?? 0; $level_settings['over_rewards'][] = $arr; } } $data[$currency_key] = $level_settings; } return compact('data', 'currency_keys'); } /** * @Description: 处理插件模式数据 * @Author: qi * @DateTime 2022-11-10 09:59:45 * @param string $init_data * @param array $level_data * @param array $currencys * @param string $addons_name * @param integer $level * @param array $append_fields * @param array $ext * @return array */ protected function getAddonsData($init_data, $level_data, $currencys, $addons_name, $level = 1, $append_fields = [], $ext = []) { $settings = []; $container_arr = []; if (!empty($init_data)) { // 已存储的数据 $settings = json_decode($init_data, true); foreach ($currencys as $currency) { if (!isset($settings[$currency])) continue; $currency_detail = $level == 1 ? $settings[$currency]['detail'] : $settings[$currency]; if(!empty($currency_detail)){ foreach ($currency_detail as $detail) { // 币种对应的权重数据 if (!isset($detail['level'])) { continue; } $container_arr[$currency . '_' . $detail['level']] = $detail; } } } }else{ foreach ($currencys as $currency) { $settings[$currency]['is_enable'] = 0; if(!empty($ext)){ foreach($ext as $key => $val){ $settings[$currency][$key] = $val; } } } } $method_name = 'get' . $addons_name . 'InitData'; foreach ($currencys as $item) { $level_settings = []; // 不存在该权重数据就初始化,存在该权重则更新权重名称 foreach ($level_data as $dlevel) { if (!isset($container_arr[$item . '_' . $dlevel['level']])) { $arr = [ 'level' => $dlevel['level'], 'level_name' => $dlevel['level_name'], ]; $arr = array_merge($arr, $this->$method_name()); $level_settings[] = $arr; } else { // 更新对应权重名称 $container_arr[$item . '_' . $dlevel['level']]['level_name'] = $dlevel['level_name']; $level_settings[] = $container_arr[$item . '_' . $dlevel['level']]; } } if (!empty($level_settings)) { if ($level == 1) { $settings[$item]['detail'] = $level_settings; } else { $settings[$item] = $level_settings; } } } foreach ($currencys as $v) { foreach ($append_fields as $field) { if (isset($settings[$v . '_' . $field])) continue; $settings[$v . '_' . $field] = 0; } } unset($container_arr); return $settings; } /** * 获取推三返一数据 * 作者:zengfanhua * 创建时间:2024/07/14 02:11:21 */ protected function getRebateData($init_data) { $settings = []; if (!empty($init_data)) { // 已存储的数据 $settings = json_decode($init_data, true); return $settings; } else { $detail=$this->getRebateInitData(); return ['is_enable'=>0,'detail'=>$detail]; } } protected function getDistributionInitData() { return [ 'first_prize' => 0, 'second_prize' => 0, 'third_prize' => 0, 'is_percent' => 0, 'remaining_ratio' => 0 ]; } protected function getAgentInitData() { return [ 'agent_team_prize' => 0, 'agent_equal_prize' => 0, 'agent_over_prize' => 0, 'agent_extra_prize' => 0, 'remaining_ratio' => 0, 'is_percent_over' => 0, 'is_percent_equal' => 0, 'is_percent_team' => 0, 'is_percent_extra' => 0 ]; } protected function getAreaInitData() { return [ 'prize' => 0, 'equal_prize' => 0, ]; } protected function getDoubleCopyInitData() { return [ 'first_prize' => 0, 'indirect_prize' => 0, 'second_prize' => 0, 'equal_prize' => 0, 'allowance_price' => 0, ]; } protected function getRebateInitData() { return [ 'initiate_type' => 0, 'initiate_level' => [], 'consume_type' => 0, 'consume_level' => [], 'reward_type' => 1, 'reward_info' => [], 'is_repeat' => 0, 'join_type' => 0, 'repeat_setting' => 0, 'agent_limit_num' => 0, ]; } protected function cashierDistributionData($distribution_levels, $cashier, $currencys = []) { // $data = []; // $level_arr = []; // switch ($type) { // case 'score': // if (!empty($cashier['distribution_settings_score'])) { // $distribution_settings_score = json_decode($cashier['distribution_settings_score'], true); // $level_arr = array_column($distribution_settings_score, 'level'); // $data = $distribution_settings_score; // } // break; // case 'commission': // if (!empty($cashier['distribution_settings'])) { // $distribution_settings = json_decode($cashier['distribution_settings'], true); // $level_arr = array_column($distribution_settings, 'level'); // $data = $distribution_settings; // } // break; // } // foreach ($distribution_levels as $val) { // if (!in_array($val['level'], $level_arr)) { // $data[] = [ // 'level' => $val['level'], // 'level_name' => $val['level_name'], // 'commission_rate' => [0, 0] // ]; // } // if (isset($data[$val['level']])) { // $data[$val['level']]['level_name'] = $val['level_name']; // } // } // return $data; $response = []; $distribution_currency_key = []; $now_level_arr = (array)array_column($distribution_levels, 'level'); foreach ($currencys as $currency) { $level_arr = []; $currency_key = 'distribution_' . $currency; $distribution_currency_key[] = $currency_key; if (!empty($cashier[$currency_key])) { $settings = json_decode($cashier[$currency_key], true); $level_arr = array_column($settings, 'level'); $response[$currency_key] = $settings; } if(isset($response[$currency_key]) && !empty($response[$currency_key])){ foreach($response[$currency_key] as $key => $value){ if(!in_array($value['level'], $now_level_arr)){ unset($response[$currency_key][$key]); } } $response[$currency_key] = array_values($response[$currency_key]); } foreach ($distribution_levels as $val) { if (!in_array($val['level'], $level_arr)) { $response[$currency_key][] = [ 'level' => $val['level'], 'level_name' => $val['level_name'], 'commission_rate' => [0, 0], ]; } if (isset($response[$currency_key][$val['level']])) { $response[$currency_key][$val['level']]['level_name'] = $val['level_name']; } } } return compact('response', 'distribution_currency_key'); } protected function getBossSetting($level=[],$boss_levels=[]) { $level_arr=[]; foreach ($level as $k => $v) { $level_arr[$k]['level']=$v['level']; $level_arr[$k]['level_name']=$v['level_name']; if(count($boss_levels)==0){ $level_arr[$k]['prize']=0; $level_arr[$k]['extra_prize']=0; }else{ foreach ($boss_levels as $val) { $i=1; if($v['level']==$val['level']){ $level_arr[$k]['prize']=$val['prize']; $level_arr[$k]['extra_prize']=$val['extra_prize']; }else{ $i++; } if($i>count($level)){ $level_arr[$k]['prize']=0; $level_arr[$k]['extra_prize']=0; } } } } return $level_arr; } /** * 让利列表 * @return mixed|string|null */ public function actionReduceProfit() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { // 审核 $setting = $this->request->post(); // 数据校验 $res = \Yii::$app->services->validate->validate($setting, [ [['id', 'status', 'remark'], 'required'], [['id', 'status'], 'integer'], [['remark'], 'string'] ], [ 'id' => '审核对象', ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); try { $ret = (new MerchantReduceProfitService())->audit($this->mall_id, $setting['id'], $this->admin->id, $setting['status'], $setting['remark']); return is_string($ret) ? $this->error($ret) : $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } else { $params = $this->request->post(); // 数据校验 $res = \Yii::$app->services->validate->validate($params, [ [['store_keyword', 'date_start', 'date_end'], 'string'], [['rate'], 'number'], [['status', 'page', 'limit', 'cate'], 'integer'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new MerchantReduceProfitService())->page($this->mall_id, $params); if (is_array($ret)) { $cate_list = StoreCate::find() ->select('id,name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $ret['cate_list'] = $cate_list; } return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } } return $this->render($this->action->id); } public function actionScoreStoreApply() { $search = $this->request->get(); // 数据校验 $res = \Yii::$app->services->validate->validate($search, [ [['store_info', 'store_cate'], 'string'], [['check_status', 'score_method', 'page', 'limit'], 'integer'], [['date'], 'safe'] ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $where = [['mall_id' => $this->mall_id], ['score_method' => $search['score_method'] ?? 1], ['<>', 'status', StatusEnum::DELETE]]; isset($search['check_status']) && $where[] = ['check_status' => $search['check_status']]; if (!empty($search['store_info'])) { $store_ids = Store::find()->where(['or', ['id' => trim($search['store_info'])], ['like', 'store_name', trim($search['store_info'])], ['like', 'shop_owner', trim($search['store_info'])] ])->select('id')->column(); $where[] = ['store_id' => $store_ids]; } if (!empty($search['date'])) { $where[] = ['or', ['between', 'created_at', strtotime($search['date'][0]), strtotime($search['date'][1])], ['between', 'check_time', strtotime($search['date'][0]), strtotime($search['date'][1])]]; } if (!empty($search['store_cate'])) { $cate_ids = StoreCate::find()->where(['like', 'name', trim($search['store_cate'])])->select('id')->column(); $where[] = ['store_c_id' => $cate_ids]; } $result = StoreScoreStoreApply::listPage(['where' => $where, 'page' => $search['page'], 'limit' => $search['limit'], 'with' => ['store' => function ($query) { $query->select('id, c_id, store_name, logo_img, shop_owner, shop_mobile, address, ')->with(['cate']); }], 'order' => 'created_at desc']); if (!empty($result['list'])) { $user_ids_arr = array_unique(array_column($result['list'], 'store_user_id')); $user_list = \common\models\user\User::lists(['where' => [['id' => $user_ids_arr]], 'index' => 'id', 'select' => 'id, nickname, mobile, avatar_url']); foreach ($result['list'] as &$item) { $item['user'] = isset($user_list[$item['store_user_id']]) ? $user_list[$item['store_user_id']] : null; } } $result['list'] = $result['list'] ?? []; $result['status_map'] = [ '-1' => '未通过', '0' => '待审核', '1' => '已通过' ]; return $this->success('获取成功', $result); } public function actionScoreStoreCheck() { $trans = \Yii::$app->db->beginTransaction(); try { $request = \Yii::$app->request; if (!$request->isPost) throw new \Exception("非法请求"); $data = $request->post(); $res = \Yii::$app->services->validate->validate($data, [ [['id', 'check_status'], 'required'], [['id', 'check_status'], 'integer'], [['reason'], 'string'] ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $model = StoreScoreStoreApply::findOne(['mall_id' => $this->mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]); if (empty($model)) throw new \Exception("当前数据不存在,无法执行修改状态"); $data['check_time'] = time(); $model->load($data, ''); if (!$model->save()) throw new \Exception("修改状态失败,原因:". $model->getErrorMessage()); if ($data['check_status'] == 1) { // 添加门店限制 if ($model->score_method == 2) { $score_deduction_config = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'payment.score_deduction', true); $score_deduction_config = json_decode($score_deduction_config, true); $score_deduction_config['store_limit_stores_deduction'] = $score_deduction_config['store_limit_stores_deduction'] ?? []; $store_limit_stores_deduction = &$score_deduction_config['store_limit_stores_deduction']; if (!isset($store_limit_stores_deduction[$model->store_id])) { $store_limit_stores_deduction[$model->store_id] = ""; }; \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, ['payment' => [ 'score_deduction' => $score_deduction_config ]]); $store_limit_stores = array_keys($store_limit_stores_deduction); }else { $store_limit_stores = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'scoreGive.store_limit_stores', true); $store_limit_stores = !empty($store_limit_stores) ? json_decode($store_limit_stores, true) : []; if (!in_array($model->store_id, $store_limit_stores)){ array_unshift($store_limit_stores, (string)$model->store_id); }; \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, ['scoreGive' => [ 'store_limit_stores' => $store_limit_stores ]]); } } $trans->commit(); return $this->success('修改状态成功', $store_limit_stores ?? []); }catch (\Exception $e){ $trans->rollBack(); return $this->error($e->getMessage()); } } public function actionStoreServiceRatioLog() { try { if (\Yii::$app->request->isAjax) { $get = $this->request->get(); $page = \Yii::$app->request->get('page'); $limit = \Yii::$app->request->get('limit'); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]; if ($get['keyword']) { $store_list = Store::lists([ 'where' => [ [ 'OR', ['like', 'store_name', $get['keyword']], ['like', 'shop_mobile', $get['keyword']], // ['=', 'id', $get['shop_mobile']], ], ['=', 'mall_id', $this->mall_id] ], 'select' => 'id' ]); if ($store_list) { $store_ids = array_column($store_list, 'id'); $wheres[] = ['in', 'store_id', $store_ids]; } } if ($get['start_time'] && $get['end_time']) { //搜索订单支付时间 $start_time = strtotime($get['start_time']); $end_time = strtotime($get['end_time']); $wheres[] = ['between', 'created_at', $start_time, $end_time]; } $with = ['store']; $search = [ 'where' => $wheres, 'page' => $page, 'order' => 'id desc', 'limit' => $limit, 'with' => $with, ]; $list = StoreServiceRatioLog::listPage($search); return $this->success('success', $list); } // return $this->render('/store-service-ratio-log/store-service-ratio-log'); return $this->render($this->action->id); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 获取微信消息模版ID * @return mixed|void|null * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function actionGetWechatNotice() { if (\Yii::$app->request->isAjax && \Yii::$app->request->post()) { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['key'], 'required'], [['key'], 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 根据key获取对应的微信消息模板ID try { $notice_wechat_config = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'notice'); $notice_wechat = empty($notice_wechat_config['notice_wechat']) ? [] : json_decode($notice_wechat_config['notice_wechat'],true); $notice_wechat_template_message_value = $notice_wechat['template_message'] ?? []; $tempid = ''; if(!empty($notice_wechat_template_message_value)){ if(!empty($notice_wechat_template_message_value[$params['key']]['tempid'])){ $tempid = $notice_wechat_template_message_value[$params['key']]['tempid']; } } $template = new WechatTemplate($this->mall_id); $response = $template->addTemplate($params['key'],$tempid); if ($response['errcode'] != 0) return $this->error('获取失败:' . $response['errmsg']); return $this->success('获取模板成功,记得左下角按钮进行保存哦', $response['template_id']); } catch (\Exception $e) { return $this->error('获取失败:' . $e->getMessage()); } } } }