| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\constants\OptionSetting;
- use app\plugins\scanCodePay\models\Order as ScanCodePayOrder;
- use app\plugins\scanCodePay\models\Order as ScanOrder;
- use app\utils\OrderNo;
- use app\utils\yunst\src\OrderYunst;
- use yii\base\Exception;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- use Yii;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%plugin_pool_config}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $is_delete
- * @property integer $status
- * @property string $name
- * @property string $rate
- * @property string $time_type
- * @property integer $created_at
- * @property integer $reward_type
- * @property integer $time_value
- */
- class PluginPoolConfig extends \yii\db\ActiveRecord
- {
- const MODEL_SHOP = 0;
- const MODEL_ALLIANCE = 1;
- const TYPE_CONFIG_POOL_SECRET = 'config_pool_secret';
- const MODEL_NAME_LIST = array(
- self::MODEL_SHOP => '小模型',
- self::MODEL_ALLIANCE => '大模型',
- );
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%plugin_pool_config}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ]
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['is_delete', 'store_id', 'status', 'time_value','reward_type'], 'integer'],
- [['name', 'time_type'], 'string'],
- [['rate'], 'number'],
- [['created_at'], 'safe']
- ];
- }
- public static function transfer($order)
- {
- if (!$order->is_pay) return false;
- $store_id = $order->store_id;
- $setting = Option::getDecode(OptionSetting::SHARE_STRING_CODE_DEFAULT_SETTING, $store_id, OptionSetting::SHARE_GROUP_NAME);
- /*$check_res = self::checkSettingByStoreId($store_id, $setting);
- if (!$check_res) return false;*/
- $is_scan = $order instanceof ScanOrder ? 1 : 0;
- if ($is_scan) return false;
- $t = \Yii::$app->db->beginTransaction();
- try {
- $config = PluginPoolConfig::poolSetting($store_id);
- if (empty($config)) throw new \Exception('无配置');
- if(($order->channel_id) == 9999){
- $pv0 = 0;
- $pv1 = $order->balance;
- }else{
- $pv0 = OrderDetail::find()->andWhere(['order_id' => $order['id'], 'is_delete' => 0])->select(['sum(pv_0)'])->scalar();
- $pv1 = OrderDetail::find()->andWhere(['order_id' => $order['id'], 'is_delete' => 0])->select(['sum(pv_1)'])->scalar();
- }
- //$pv0 = 0;
- //debug_log([__METHOD__, __LINE__, 'configPoolPush start'], "app_debug.log");
- self::configPoolPush($config, $order, $setting, $pv0, $pv1);//插入池子
- $add_money0 = bcmul($pv0, $setting['string_code_pv_scale_0'] / 100, 4);
- $add_money1 = bcmul($pv1, $setting['string_code_pv_scale_1'] / 100, 4);
- //self::areaAward($config, $store_id, $order, $add_money0, 0);
- self::areaAward($config, $store_id, $order, $add_money1, 1);
- self::appointAward($config, $order, $add_money0, $add_money1);
- self::currencyAward($config, $order, $add_money0, $add_money1);
- $t->commit();
- } catch (\Exception $e) {
- $t->rollBack();
- \Yii::$app->db->createCommand()->insert('cyy_pay_log', [
- 'order_no'=>$order->order_no,
- 'desc'=>'奖励错误'.$e->getMessage(),
- 'add_time'=>time(),
- ])->execute();
- ActionLog::addLog(1, '/PluginPoolConfig/transfer', $e->getMessage());
- }
- $UserStringCodeOrderlist = UserStringCodeOrder::findAll([
- 'order_id' => $order->id,
- 'is_scan' => $is_scan,
- 'type' => [
- UserStringCodeOrder::TYPE_STORE_USER_REFERRER,
- UserStringCodeOrder::TYPE_STORE_USER_AFFILIATED,
- UserStringCodeOrder::TYPE_STORE_REFERRER,
- UserStringCodeOrder::TYPE_BRAND_USER_REFERRER,
- UserStringCodeOrder::TYPE_BRAND_USER_AFFILIATED,
- UserStringCodeOrder::TYPE_BRAND_REFERRER,
- UserStringCodeOrder::TYPE_AREA_AWARD,
- UserStringCodeOrder::TYPE_BRAND_USER_STORE_REFERRER,
- UserStringCodeOrder::TYPE_SUPRISE_RED,
- ] // 用数组指定多个类型
- ]);
- $league_arr = UserStringCodeOrder::TYPE_LEAGUE_PRICE;
- $Leaguelist = SaaSLeaguePriceLog::findAll([
- 'order_id' => $order->id,
- 'is_scan' => $is_scan,
- 'type' => [
- $league_arr[UserStringCodeOrder::TYPE_STORE_USER_REFERRER],
- $league_arr[UserStringCodeOrder::TYPE_STORE_USER_AFFILIATED],
- $league_arr[UserStringCodeOrder::TYPE_STORE_REFERRER],
- $league_arr[UserStringCodeOrder::TYPE_BRAND_USER_REFERRER],
- $league_arr[UserStringCodeOrder::TYPE_BRAND_USER_AFFILIATED],
- $league_arr[UserStringCodeOrder::TYPE_BRAND_REFERRER],
- $league_arr[UserStringCodeOrder::TYPE_AREA_AWARD],
- $league_arr[UserStringCodeOrder::TYPE_BRAND_USER_STORE_REFERRER],
- $league_arr[UserStringCodeOrder::TYPE_SUPRISE_RED],
- ]
- ]);
- if (count($UserStringCodeOrderlist) > 0 || count($Leaguelist) > 0) {
- $order->team_reward_status = 1;
- $order->save();
- }
- }
- public static function configPoolPush($config, $order, $setting, $pv0, $pv1)
- {
- try {
- if (!isset($config['pools']) || empty($config['pools'])) throw new \Exception('无配置分红池');
- foreach ($config['pools'] as $p) {
- $pool = self::find()->where(['status' => 1, 'is_delete' => 0, 'id' => $p['config_id']])->one();
- if (empty($pool)) continue;
- if (!isset($p['rate']) || $p['rate'] <= 0) continue;
- self::pushCP($p['config_id'], $order, $pv0, $setting['string_code_pv_scale_0'], $p['rate'], $setting['string_code_model'], 0);
- self::pushCP($p['config_id'], $order, $pv1, $setting['string_code_pv_scale_1'], $p['rate'], $setting['string_code_model'], 1);
- }
- } catch (\Exception $e) {
- ActionLog::addLog(1, '/configPoolPush', $e->getMessage());
- }
- }
- public static function pushCP($config_id, $order, $order_pv, $code_percent, $rate, $string_code_model, $model_val)
- {
- try {
- $code_percent = 100;
- //if (in_array($model_val, $string_code_model)) {
- //debug_log([__METHOD__, __LINE__, "大模型比例 : " . ($code_percent / 100)], "app_debug.log");
- $add_money = bcmul($order_pv, $code_percent / 100, 4);
- $money = bcmul($add_money, $rate / 100, 4);
- //debug_log([__METHOD__, __LINE__, "大模型:order_pv : " . $order_pv . ',$add_money:' . $add_money . ',$money:' . $money], "app_debug.log");
- if (bccomp($money, 0, 4) > 0) {
- $desc = self::MODEL_NAME_LIST[$model_val] . " " . "订单号:【{$order->order_no}】分红增加";
- PluginPool::poolPush($config_id, $order, $money, $desc, $order_pv, $rate, $code_percent, $model_val, $add_money);
- }
- // }
- } catch (\Exception $e) {
- ActionLog::addLog(1, 'pushCP', $e->getMessage());
- }
- }
- public static function appointAward($config, $order, $pv0, $pv1)
- {
- try {
- if (!isset($config['users']) || empty($config['users'])) throw new \Exception('无配置分红池');
- foreach ($config['users'] as $p) {
- if (!isset($p['rate']) || $p['rate'] <= 0 || !isset($p['saas_id']) || !$p['saas_id'] || !isset($p['remark']) || !$p['remark']) continue;
- /*$money = bcmul($pv0, $p['rate'] / 100, 6);
- if ($money > 0){
- //UserStringCodeOrder::configAddUserWallet($order, $p['saas_id'], $money, UserStringCodeOrder::TYPE_APPOINT_AWARD, 0, $p['remark']);
- UserStringCodeOrder::goCouponAdd($order->store_id, $p['saas_id'], $money, UserStringCodeOrder::STORE_DESIGNATED_PROFIT_SHARING,$order);
- }*/
- $money = bcmul($pv1, $p['rate'] / 100, 6);
- if ($money > 0){
- //UserStringCodeOrder::configAddUserWallet($order, $p['saas_id'], $money, UserStringCodeOrder::TYPE_APPOINT_AWARD, 1, $p['remark']);
- UserStringCodeOrder::goCouponAdd($order->store_id, $p['saas_id'], $money, UserStringCodeOrder::STORE_DESIGNATED_PROFIT_SHARING,$order);
- }
- }
- } catch (\Exception $e) {
- //ActionLog::addLog(1, 'appointAward', $e->getMessage());
- }
- }
- public static function currencyAward($config, $order, $pv0, $pv1)
- {
- try {
- if (!isset($config['currencys']) || empty($config['currencys'])) throw new \Exception('无配置分红池');
- $saas_id = SaasUser::findSaasIdByUserId($order->user_id);
- foreach ($config['currencys'] as $p) {
- if (!isset($p['rate']) || $p['rate'] <= 0 || !isset($p['mark']) || !$p['mark']|| !isset($p['currency_id']) || !$p['currency_id']) continue;
- $currency = CurrencyCoin::findOne($p['currency_id']);
- if (!$currency) continue;
- //$currency_money_0 = bcdiv($pv0, $currency->cny_price, 6);
- $currency_money_1 = bcdiv($pv1, $currency->cny_price, 6);
- //$currency_money_0 = bcmul($currency_money_0, $p['rate']/100, 6);
- $currency_money_1 = bcmul($currency_money_1, $p['rate']/100, 6);
- /*if ($currency_money_0 > 0){
- $res = CurrencyCoin::addSaasMoney($currency->id,$saas_id, 1, $currency_money_0, $p['mark']);
- if (!$res) {
- continue;
- }
- }*/
- if ($currency_money_1 > 0){
- $res = CurrencyCoin::addSaasMoney($currency->id,$saas_id, 1, $currency_money_1, $p['mark'],$order->store_id);
- if (!$res) {
- continue;
- }
- }
- /*$wallet = UserWalletCoin::findOne(['currency_id'=>$currency->id,'store_id'=>$order->store_id,'is_open'=>1]);
- if (!$wallet) continue;
- $money = truncateDecimal(bcmul($pv0, $p['rate'] / 100, 6));
- if ($money > 0){
- $data = [
- "order_id"=>$order->id,
- "order_no"=>$order->order_no,
- "pay_price"=>$money,
- "desc"=>$p['mark'],
- 'huifu_id'=>$wallet->huifu_id,
- 'huifu_id_name'=>self::getHuifuName($wallet->huifu_id),
- 'percent'=>0,
- "create_time"=>time(),
- "is_type"=>2
- ];
- \Yii::$app->db->createCommand()->insert('cyy_scan_code_pay_order_percent', $data)->execute();
- }
- $money = truncateDecimal(bcmul($pv1, $p['rate'] / 100, 6));
- if ($money > 0){
- $data = [
- "order_id"=>$order->id,
- "order_no"=>$order->order_no,
- "pay_price"=>$money,
- "desc"=>$p['mark'],
- 'is_type'=>2,
- 'huifu_id'=>$wallet->huifu_id,
- 'huifu_id_name'=>self::getHuifuName($wallet->huifu_id),
- 'percent'=>0,
- "create_time"=>time(),
- ];
- \Yii::$app->db->createCommand()->insert('cyy_scan_code_pay_order_percent', $data)->execute();
- }*/
- }
- } catch (\Exception $e) {
- ActionLog::addLog(1, UserStringCodeOrder::TYPE_CURRENCY_AWARD, $e->getMessage());
- }
- }
- public static function getHuifuName($huifuId)
- {
- $storebanklist = Storebanklist::findOne(['huifu_id' => $huifuId]);
- if (empty($storebanklist)) {
- $localHuifuMerchant = LocalHuifuMerchant::findOne(['huifu_id' => $huifuId]);
- return $localHuifuMerchant->huifu_name ?? '';
- }
- return $storebanklist->short_name ?? '';
- }
- public static function areaAward($config, $store_id, $order, $order_pv, $model)
- {
- try {
- if ($order_pv <= 0) throw new Exception('pv为0,' . self::MODEL_NAME_LIST[$model]);
- self::stringCodeStoreArea($config, $store_id, $order, $order_pv, 4, $model);//区代理
- self::stringCodeStoreArea($config, $store_id, $order, $order_pv, 3, $model);//区代理
- self::stringCodeStoreArea($config, $store_id, $order, $order_pv, 2, $model);//市代理
- self::stringCodeStoreArea($config, $store_id, $order, $order_pv, 1, $model);//省代理
- //debug_log([__METHOD__, __LINE__, "PV:" . $order_pv], "app_debug.log");
- //self::stringCodeStoreReferrer($order, $config, $store_id, $order_pv, $model);
- //self::stringCodeStoreUserAffiliated($order, $config, $order_pv, $model);
- //self::stringCodeStoreUserReferrer($order, $config, $order_pv, $model);
- //self::supriseRed($order, $config, $order_pv, $model);
- self::brandUserStoreReferrer($order, $config, $order_pv, $model);
- } catch (\Exception $e) {
- ActionLog::addLog(1, 'areaAward', $e->getMessage());
- }catch (\Throwable $e) {
- ActionLog::addLog(1, 'areaAward', $e->getMessage());
- }
- }
- public static function stringCodeStoreArea($config, $store_id, $order, $order_pv, $agent_type, $model)
- {
- try {
- $holder = null;
- $area_type = "";
- switch ($agent_type) {
- case 4:
- $desc = '街道代理';
- //$rate = $config['street_rate'];
- $area_type = UserStringCodeOrder::STORE_T_PROFIT_SHARING;
- $rate = 0;
- $holder = PoolConfigHolder::find()->where(['store_id' => $store_id, 'status' => 1, 'is_delete' => 0, 'agent_type' => 4, 'town_id' => $order['town_id']])->one();
- if (!empty($holder) && $holder->user_id) break;
- case 3:
- if ($agent_type == 3){
- $desc = '区代理';
- $rate = $config['area_rate'];
- $area_type = UserStringCodeOrder::STORE_A_PROFIT_SHARING;
- }
- $holder = PoolConfigHolder::find()->where(['store_id' => $store_id, 'status' => 1, 'is_delete' => 0, 'agent_type' => 3, 'district_id' => $order['district_id']])->one();
- if (!empty($holder) && $holder->user_id) break;
- case 2:
- if ($agent_type == 2) {
- $desc = '市代理';
- $rate = $config['city_rate'];
- $area_type = UserStringCodeOrder::STORE_C_PROFIT_SHARING;
- }
- $holder = PoolConfigHolder::find()->where(['store_id' => $store_id, 'status' => 1, 'is_delete' => 0, 'agent_type' => 2, 'city_id' => $order['city_id']])->one();
- if (!empty($holder) && $holder->user_id) break;
- case 1:
- if ($agent_type == 1) {
- $desc = '省代理';
- $rate = $config['province_rate'];
- $area_type = UserStringCodeOrder::STORE_P_PROFIT_SHARING;
- }
- $holder = PoolConfigHolder::find()->where(['store_id' => $store_id, 'status' => 1, 'is_delete' => 0, 'agent_type' => 1, 'province_id' => $order['province_id']])->one();
- break;
- default:
- $rate = 0;
- break;
- }
- $agent_id = !empty($holder) && $holder->user_id ? SaasUser::findSaasIdByUserId($holder->user_id) : ($config['string_code_store_push_id'] ?: 0);
- if ($rate <= 0 || !$agent_id) {
- throw new \Exception('rate:' . $rate . ',agent_id:' . $agent_id);
- }
- $money = bcmul($order_pv, $rate / 100, 4);
- //UserStringCodeOrder::configAddUserWallet($order, $agent_id, $money, UserStringCodeOrder::TYPE_AREA_AWARD, $model, $desc);
- UserStringCodeOrder::goCouponAdd($order->store_id, $agent_id, $money, $area_type,$order);
- } catch (\Exception $e) {
- ActionLog::addLog(1, 'stringCodeStoreArea', $e->getMessage());
- }
- }
- public static function stringCodeStoreReferrer($order, $setting, $store_id, $transfer_money, $model_val)
- {
- $referrer = 0;
- if ($order instanceof ScanOrder) {
- if (isset($setting['string_code_store_referrer']) && $setting['string_code_store_referrer'] > 0) {
- $referrer = $setting['string_code_store_referrer'];
- }
- } else {
- if (isset($setting['string_code_brand_referrer']) && $setting['string_code_brand_referrer'] > 0) {
- $referrer = $setting['string_code_brand_referrer'];
- }
- }
- if ($referrer > 0) {
- $store_referral = SaasStoreReferral::findOne(['store_id' => $store_id]);
- $saas_id = $store_referral['referral_id'];
- $money = bcmul($transfer_money, $referrer / 100, 4);
- //debug_log([__METHOD__, __LINE__, "stringCodeStoreReferrer:" . $transfer_money.'$referrer'.$referrer], "app_debug.log");
- $type = UserStringCodeOrder::TYPE_STORE_REFERRER;
- UserStringCodeOrder::transferAddUserWallet($order, $saas_id, $money, $type, $model_val);
- }
- }
- public static function brandUserStoreReferrer($order, $setting, $transfer_money, $model_val)
- {
- $referrer = 0;
- if ($order instanceof ScanOrder) {
- if (isset($setting['string_code_store_referrer']) && $setting['string_code_store_referrer'] > 0) {
- $referrer = $setting['string_code_store_referrer'];
- }
- } else {
- if (isset($setting['brand_user_store_referrer']) && $setting['brand_user_store_referrer'] > 0) {
- $referrer = $setting['brand_user_store_referrer'];
- }
- }
- $user = User::findOne($order->user_id);
- $user->parent_id = $user->old_parent_id;
- \Yii::$app->db->createCommand()->insert('cyy_pay_log', [
- 'order_no'=>$order->order_no,
- 'desc'=>"推荐人".$user->parent_id."百分比:".$referrer,
- 'add_time'=>time(),
- ])->execute();
- if ($user->parent_id > 0 && $referrer > 0) {
- $saas_id = SaasUser::findSaasIdByUserId($user->parent_id);
- $money = bcmul($transfer_money, $referrer / 100, 4);
- //$type = UserStringCodeOrder::TYPE_BRAND_USER_STORE_REFERRER;
- $type = UserStringCodeOrder::STORE_DIRECT_REFERRAL_REWARD;
- //debug_log([__METHOD__, __LINE__, "brandUserStoreReferrer:" . $transfer_money.'$referrer'.$referrer], "app_debug.log");
- //UserStringCodeOrder::transferAddUserWallet($order, $saas_id, $money, $type, $model_val);
- UserStringCodeOrder::goCouponAdd($order->store_id, $saas_id, $money, $type,$order);
- }
- }
- public static function supriseRed($order, $setting, $transfer_money, $model_val)
- {
- $referrer = 0;
- if ($order instanceof ScanOrder) {
- if (isset($setting['store_surprise_Red']) && $setting['store_surprise_Red'] > 0) {
- $referrer = $setting['store_surprise_Red'];
- }
- } else {
- if (isset($setting['surprise_Red']) && $setting['surprise_Red'] > 0) {
- $referrer = $setting['surprise_Red'];
- }
- }
- $saas_id = SaasUser::findSaasIdByUserId($order->user_id);
- if ($saas_id > 0 && $referrer > 0){
- $money = bcmul($transfer_money, $referrer / 100, 4);
- $type = UserStringCodeOrder::TYPE_SUPRISE_RED;
- UserStringCodeOrder::transferAddUserWallet($order, $saas_id, $money, $type, $model_val);
- }
- }
- public static function stringCodeStoreUserAffiliated($order, $setting, $transfer_money, $model_val)
- {
- $affiliated = 0;
- if ($order instanceof ScanOrder) {
- if (isset($setting['string_code_store_user_affiliated']) && $setting['string_code_store_user_affiliated'] > 0) {
- $affiliated = $setting['string_code_store_user_affiliated'];
- }
- } else {
- if (isset($setting['string_code_brand_user_affiliated']) && $setting['string_code_brand_user_affiliated'] > 0) {
- $affiliated = $setting['string_code_brand_user_affiliated'];
- }
- }
- if ($affiliated > 0) {
- $first_store_id = SaasUser::findFirstStoreIdByUserId($order->user_id);
- $store_admin = Admin::findOne(['type' => 'store', 'type_id' => $first_store_id, 'is_delete' => 0]);
- $saas_id = $store_admin['saas_user_id'];
- $money = bcmul($transfer_money, $affiliated / 100, 4);
- $type = UserStringCodeOrder::TYPE_STORE_USER_AFFILIATED;
- //debug_log([__METHOD__, __LINE__, "stringCodeStoreUserAffiliated:" . $transfer_money.'$referrer'.$affiliated], "app_debug.log");
- UserStringCodeOrder::transferAddUserWallet($order, $saas_id, $money, $type, $model_val);
- }
- }
- public static function stringCodeStoreUserReferrer($order, $setting, $transfer_money, $model_val)
- {
- $referrer = 0;
- if ($order instanceof ScanOrder) {
- if (isset($setting['string_code_store_user_referrer']) && $setting['string_code_store_user_referrer'] > 0) {
- $referrer = $setting['string_code_store_user_referrer'];
- }
- } else {
- if (isset($setting['string_code_brand_user_referrer']) && $setting['string_code_brand_user_referrer'] > 0) {
- $referrer = $setting['string_code_brand_user_referrer'];
- }
- }
- if ($referrer > 0) {
- $user = User::findOne($order->user_id);
- if ($user->id > 0) {
- $saas_id = SaasUser::findSaasParentIdByUserId($order->user_id);
- $money = bcmul($transfer_money, $referrer / 100, 4);
- $type = UserStringCodeOrder::TYPE_STORE_USER_REFERRER;
- //debug_log([__METHOD__, __LINE__, "stringCodeStoreUserReferrer:" . $transfer_money.'$referrer'.$referrer], "app_debug.log");
- UserStringCodeOrder::transferAddUserWallet($order, $saas_id, $money, $type, $model_val);
- }
- }
- }
- /**
- * @param $store_id
- * @return bool
- */
- public static function checkSettingByStoreId($store_id, $setting)
- {
- if (!$setting) {
- //debug_log([__METHOD__, __LINE__, "店铺:【{$store_id}】未配置串码设置"], "app_debug.log");
- return false;
- }
- if (!isset($setting['string_code_store_switch']) || $setting['string_code_store_switch'] != 1) {
- //debug_log([__METHOD__, __LINE__, "店铺:【{$store_id}】未开启串码功能"], "app_debug.log");
- return false;
- }
- if (!isset($setting['string_code_model'])) {
- //debug_log([__METHOD__, __LINE__, "店铺:【{$store_id}】未设置串码模式"], "app_debug.log");
- return false;
- }
- if (!is_array($setting['string_code_model'])) {
- //debug_log([__METHOD__, __LINE__, "店铺:【{$store_id}】串码模式配置不是数组"], "app_debug.log");
- return false;
- }
- return true;
- }
- public static function getDefPools($bd_pools, $store_pools)
- {
- // 确保都是数组格式
- $bd_pools = array_map(function($item) {
- return is_array($item) ? $item : (array)$item;
- }, $bd_pools);
- $store_pools = array_map(function($item) {
- return is_array($item) ? $item : (array)$item;
- }, $store_pools);
- $currentIds = ArrayHelper::getColumn($bd_pools, 'config_id');
- $targetIds = ArrayHelper::getColumn($store_pools, 'config_id');
- $idsToDelete = array_diff($currentIds, $targetIds);
- $idsToAdd = array_diff($targetIds, $currentIds);
- // 删除操作
- if (!empty($idsToDelete)) {
- $bd_pools = array_values(array_filter($bd_pools, function($pool) use ($idsToDelete) {
- return !in_array($pool['config_id'], $idsToDelete);
- }));
- }
- // 新增操作
- if (!empty($idsToAdd)) {
- foreach ($store_pools as $item) {
- if (in_array($item['config_id'], $idsToAdd)) {
- $newItem = $item;
- $newItem['rate'] = 0;
- $bd_pools[] = $newItem;
- }
- }
- }
- return $bd_pools;
- }
- public static function getAwardType($store_id, $is_scan,$award_type = 'award_type')
- {
- if (!$is_scan){
- $store_setting = Option::getDecode(OptionSetting::PLUGIN_CONFIG_POOL_SETTING, $store_id, OptionSetting::SHARE_GROUP_NAME);
- $type = $store_setting[$award_type] ?? 1;
- }else{
- $bd_admin = Admin::findOne(['store_id'=>$store_id,'type'=>'bd_agent','is_delete'=>0,'is_enable'=>1]);
- if (empty($bd_admin)){
- $admin_id = Salesman::getBdId($store_id);
- if ($admin_id){
- $bd_admin = Admin::findOne(['id'=>$admin_id,'type'=>'bd_agent','is_delete'=>0,'is_enable'=>1]);
- }
- }
- $bd_setting = [];
- if ($bd_admin){
- $bd_setting = Option::getDecode(OptionSetting::SHARE_STRING_CODE_SALE_SETTING_BD, $bd_admin->id, OptionSetting::SHARE_GROUP_NAME);
- }
- $type = $bd_setting[$award_type] ?? 1;
- }
- return $type;
- }
- public static function poolSetting($store_id)
- {
- $plugin_setting = Option::getDecode(OptionSetting::PLUGIN_CONFIG_POOL_SETTING, $store_id, OptionSetting::SHARE_GROUP_NAME);
- if (empty($plugin_setting) || !isset($plugin_setting['is_enable']) || !$plugin_setting['is_enable']) {
- $plugin_setting = Option::getDecode(OptionSetting::PLUGIN_CONFIG_POOL_SETTING, 197, OptionSetting::SHARE_GROUP_NAME);
- if (empty($plugin_setting) || !isset($plugin_setting['is_enable']) || !$plugin_setting['is_enable']) {
- return false;
- }
- }
- return $plugin_setting;
- }
- }
|