[0, 1]], [['pay_type'], 'in', 'range' => [0, 1, 2, 3]] ]; } public function attributeLabels() { return [ 'store_id' => 'Store Id', 'share_group_direct_profit' => '直推佣金比例', 'share_group_support_profit' => '帮扶佣金比例', 'share_group_auto_switch' => '成团佣金自动复购开关', 'share_group_commission_profit' => '成团佣金奖励比例', 'share_group_balance_profit' => '成团余额奖励比例', 'share_group_other_accounts_switch' => '开始拼团区小号限制开关', 'share_group_support_freeze_profit' => '冻结帮扶佣金奖励比例', 'pay_type' => '提现方式【0微信 1支付宝 2微信&支付宝】', 'bank' => '是否开启银行卡提现', 'lg' => '是否开启灵工提现', 'remaining_sum' => '是否开启余额提现', 'cash_service_charge' => '提现手续费', 'min_money' => '最少提现金额', 'cash_max_single_day' => '每日提现上限', 'cash_max_day' => '平台提现上限', 'goods_ids' => '商品ID', 'share_group_bg' => '37拼购背景图' ]; } public function settingIndex() { try { $store_id = $this->store_id; $data = [ 'share_group_direct_profit' => 0, 'share_group_support_profit' => 0, 'share_group_auto_switch' => 0, 'share_group_commission_profit' => 0, 'share_group_balance_profit' => 0, 'share_group_other_accounts_switch' => 0, 'share_group_support_freeze_profit' => 0, 'pay_type' => '', 'bank' => 0, 'remaining_sum' => 0, 'lg' => 0, 'cash_service_charge' => 0, 'min_money' => 0, 'cash_max_single_day' => 0, 'cash_max_day' => 0, 'goods_ids' => '', 'support_group_price_send_type' => 0,//帮扶区直推佣金发放:0=原上级 1=新上级 'share_group_bg' => '' ]; $share_group_setting = Option::get('share_group_setting', $store_id, 'share_group')['value']; $share_group_setting = json_decode($share_group_setting ?? '', true); if (empty($share_group_setting)) { $share_group_setting = $data; } if (!isset($share_group_setting['cash_price_type'])) { $share_group_setting = array_merge($share_group_setting, [ 'cash_price_type' => '1', 'cash_price_amount' => 100, 'cash_price_integral' => 0, 'cash_price_balance' => 0, ]); } if (!isset($share_group_setting['support_group_price_send_type'])) { $share_group_setting['support_group_price_send_type'] = 0; } if (!isset($share_group_setting['lg'])) { $share_group_setting['lg'] = 0; } $share_group_setting['goods_info'] = []; $goods_ids = explode(',', $share_group_setting['goods_ids'] ?? ''); if (!empty($goods_ids)) { $goods = Goods::find()->where(['id' => $goods_ids, 'is_delete' => 0, 'store_id' => $store_id]) ->select('id, name, cover_pic, price, goods_num')->orderBy('id')->asArray()->all(); $goods_ids = array_column($goods, 'id'); $share_group_setting['goods_ids'] = implode(',', $goods_ids); foreach ($goods as &$item) { $goods_cat = GoodsCat::find()->alias('gc') ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id') ->where([ 'gc.goods_id' => $item['id'], 'c.is_delete' => 0, 'gc.is_delete' => 0, 'c.store_id' => $store_id]) ->select(['c.name']) ->column(); $item['cat'] = implode(' ', $goods_cat); } $share_group_setting['goods_info'] = $goods; } $share_group_setting['share_group_bg'] = $share_group_setting['share_group_bg'] ?? ''; return [ 'code' => 0, 'msg' => '获取成功', 'data' => $share_group_setting ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function settingEdit() { try { $store_id = $this->store_id; if (!$this->validate()) { throw new \Exception($this->getErrorSummary(false)[0]); } $data = [ 'share_group_direct_profit' => floatval($this->share_group_direct_profit), 'share_group_support_profit' => floatval($this->share_group_support_profit), 'share_group_auto_switch' => intval($this->share_group_auto_switch), 'share_group_commission_profit' => floatval($this->share_group_commission_profit), 'share_group_balance_profit' => floatval($this->share_group_balance_profit), 'share_group_other_accounts_switch' => intval($this->share_group_other_accounts_switch), 'share_group_support_freeze_profit' => floatval($this->share_group_support_freeze_profit), 'support_group_price_send_type' => intval($this->support_group_price_send_type), 'pay_type' => intval($this->pay_type), 'bank' => intval($this->bank), 'lg' => intval($this->lg), 'remaining_sum' => intval($this->remaining_sum), 'cash_service_charge' => floatval($this->cash_service_charge), 'min_money' => floatval($this->min_money), 'cash_max_single_day' => floatval($this->cash_max_single_day), 'cash_max_day' => floatval($this->cash_max_day), 'goods_ids' => $this->goods_ids, 'cash_price_type' => $this->cash_price_type ?? '1', 'cash_price_amount' => $this->cash_price_amount ?? 100, 'cash_price_integral' => $this->cash_price_integral ?? 0, 'cash_price_balance' => $this->cash_price_balance ?? 0, 'share_group_bg' => $this->share_group_bg ]; // $total_profit = 0; // $cash_price_type = explode(',', $this->cash_price_type); // if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->cash_price_amount, 2); // } // if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->cash_price_integral, 2); // } // if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->cash_price_balance, 2); // } // if ($total_profit != 100) { // return [ // 'code' => 1, // 'msg' => '佣金/积分/余额比例设置错误' // ]; // } $goods_ids = explode(',', $data['goods_ids'] ?? ''); if (empty($goods_ids)) { throw new \Exception('请选择商品'); } foreach ($goods_ids as $goods_id) { $goods = Goods::findOne(['id' => $goods_id, 'is_delete' => 0, 'store_id' => $store_id]); if (!$goods) { throw new \Exception('商品信息错误' . $goods_id); } } Option::set('share_group_setting', json_encode($data), $store_id, 'share_group'); return [ 'code' => 0, 'msg' => '保存成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }