model->store_id = $this->store_id; $this->model->group = OptionSetting::SHARE_GROUP_NAME; $this->model->name = OptionSetting::SHARE_MONEY_SETTING; $this->model->value = json_encode($this->data); if (!$this->model->isNewRecord) { $this->model->updated_at = time(); } if (!$this->model->save()) { foreach ($this->model->errors as $error) { return [ 'code' => 1, 'msg' => $error, ]; } } return [ 'code' => 0, 'msg' => '保存成功' ]; } /** * 设置分销 */ public function setBasicSetting() { if (!is_numeric($this->data['min_money']) || !is_numeric($this->data['cash_max_day']) || !is_numeric($this->data['auto_share_val'])) { return ['code' => 1, 'msg' => '金额字段请输入数字']; } if ($this->data['share_goods_status'] == 2) { if (empty($this->data['share_goods_id'])) { return ['code' => 1, 'msg' => '请选择指定商品']; } } $data = [ 'level'=> [ 'text' => '开启分销', 'value' => $this->data['level'] ], 'is_rebate' => [ 'text' => '自购返利开关', 'value' => $this->data['is_rebate'] ], 'condition' => [ 'text' => '成为下线条件', 'value' => $this->data['condition'] ], 'enforce_bind_parent' => [ 'text' => '强制绑定上级', 'value' => $this->data['enforce_bind_parent'] ], 'share_condition' => [ 'text' => '成为分销商条件', 'value' => $this->data['share_condition'] ], 'rec_member_integral' => [ 'text' => '推荐会员送积分', 'value' => intval($this->data['rec_member_integral']) ], 'd_rec_member_integral' => [ 'text' => '被推荐会员送积分', 'value' => intval($this->data['d_rec_member_integral']) ], 'pay_type' => [ 'text' => '提现方式', 'value' => $this->data['pay_type'] ], 'auto_money' => [ 'text' => '自动打款金额', 'value' => $this->data['auto_money'] ], 'min_money' => [ 'text' => '最小提现额度', 'value' => $this->data['min_money'] ], 'cash_max_day' => [ 'text' => '每天最大提现额度', 'value' => $this->data['cash_max_day'] ], 'cash_max_single_day' => [ 'text' => '每人每天提现额度', 'value' => $this->data['cash_max_single_day'] ], 'cash_service_charge' => [ 'text' => '提现手续费', 'value' => floatval($this->data['cash_service_charge']) ], 'auto_share_val' => [ 'text' => '消费自动成为分销商', 'value' => $this->data['auto_share_val'] ], 'share_goods_status' => [ 'text' => '购买指定商品成为分销商', 'value' => $this->data['share_goods_status'] ], 'share_goods_id' => [ 'text' => '购买指定商品id', 'value' => $this->data['share_goods_id'] ], 'content' => [ 'text' => '用户须知', 'value' => $this->data['content'] ], 'agree' => [ 'text' => '协议', 'value' => $this->data['agree'] ], 'remaining_sum' => [ 'text' => '余额提现', 'value' => $this->data['remaining_sum'] ], 'bank' => [ 'text' => '银行卡', 'value' => $this->data['bank'] ], 'lg' => [ 'text' => '灵工提现', 'value' => $this->data['lg'] ], 'apply_image' => [ 'text' => '申请页面', 'value' => $this->data['apply_image'] ], 'no_checked_image' => [ 'text' => '待审核页面', 'value' => $this->data['no_checked_image'] ], 'wx_title' => [ 'text' => '小程序标题昵称', 'value' => $this->data['wx_title'] ], 'parent_label' => [ 'text' => '自定义上级名称显示', 'value' => $this->data['parent_label'] ], 'cash_price_type' => [ 'text' => '佣金到账类型', 'value' => $this->data['cash_price_type'] ?? '1' ], 'cash_price_amount' => [ 'text' => '现金', 'value' => $this->data['cash_price_amount'] ?? 100 ], 'cash_price_integral' => [ 'text' => '积分', 'value' => $this->data['cash_price_integral'] ?? 0 ], 'cash_price_balance' => [ 'text' => '余额', 'value' => $this->data['cash_price_balance'] ?? 0 ], 'invite_type' => [ 'text' => '邀请类型', 'value' => $this->data['invite_type']??1 ], ]; // $total_profit = 0; // $cash_price_type = explode(',', $this->data['cash_price_type']); // if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->data['cash_price_amount'], 2); // } // if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->data['cash_price_integral'], 2); // } // if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->data['cash_price_balance'], 2); // } // if ($total_profit != 100) { // return [ // 'code' => 1, // 'msg' => '佣金/积分/余额比例设置错误' // ]; // } $this->model->store_id = $this->store_id; $this->model->group = OptionSetting::SHARE_GROUP_NAME; $this->model->name = OptionSetting::SHARE_BASIC_SETTING; $this->model->value = json_encode($data); if (!$this->model->isNewRecord) { $this->model->updated_at = time(); } if (!$this->model->save()) { foreach ($this->model->errors as $error) { return [ 'code' => 1, 'msg' => $error, ]; } } return [ 'code' => 0, 'msg' => '保存成功' ]; } /** * 设置saas分销 */ public function setSaasBasicSetting() { if (!is_numeric($this->data['min_money']) || !is_numeric($this->data['cash_max_day']) ) { return ['code' => 1, 'msg' => '金额字段请输入数字']; } $data = [ 'pay_type' => [ 'text' => '提现方式', 'value' => $this->data['pay_type'] ], 'min_money' => [ 'text' => '最小提现额度', 'value' => $this->data['min_money'] ], 'cash_max_day' => [ 'text' => '每天最大提现额度', 'value' => $this->data['cash_max_day'] ], 'cash_service_charge' => [ 'text' => '提现手续费', 'value' => floatval($this->data['cash_service_charge']) ] ]; //商盟固定store_id $this->model->store_id = -1; $this->model->group = OptionSetting::SHARE_GROUP_NAME; $this->model->name = OptionSetting::SHARE_BASIC_SETTING; $this->model->value = json_encode($data); if (!$this->model->isNewRecord) { $this->model->updated_at = time(); } if (!$this->model->save()) { foreach ($this->model->errors as $error) { return [ 'code' => 1, 'msg' => $error, ]; } } return [ 'code' => 0, 'msg' => '保存成功' ]; } /** * 获取设置 */ public function getShareSetting() { if (empty($this->name)) { return [ 'code' => 1, "msg" => $this->getErrorSummary(false)[0] ]; } $values = Option::find()->where(['store_id' => $this->store_id, 'group' => OptionSetting::SHARE_GROUP_NAME, 'name' => $this->name])->select('value')->One(); if($values){ $data = json_decode($values->value, true); }else{ $data = []; } $goods = []; if (isset($data['share_goods_id']['value'])) { $ids = \explode(',', $data['share_goods_id']['value']); $goods = Goods::find()->select('cover_pic, goods_num, id, is_negotiable, name, original_price, price, product_type') ->where(['id' => $ids])->all(); } if ($this->name === 'share_basic_setting') { $data_ = [ 'auto_share_val' => [ 'text' => '消费自动成为分销商', 'value' => 0 ], 'share_condition' => [ 'text' => '成为分销商条件', 'value' => 0 ], 'level'=> [ 'text' => '开启分销', 'value' => 1 ], 'is_rebate' => [ 'text' => '自购返利开关', 'value' => 0 ], 'condition' => [ 'text' => '成为下线条件', 'value' => 0 ], 'enforce_bind_parent' => [ 'text' => '强制绑定上级', 'value' => 0 ], 'rec_member_integral' => [ 'text' => '推荐会员送积分', 'value' => 0 ], 'd_rec_member_integral' => [ 'text' => '被推荐会员送积分', 'value' => 0 ], 'pay_type' => [ 'text' => '提现方式', 'value' => '' ], 'min_money' => [ 'text' => '最小提现额度', 'value' => 0 ], 'cash_max_day' => [ 'text' => '每天最大提现额度', 'value' => 100 ], 'cash_max_single_day' => [ 'text' => '每人每天提现额度', 'value' => 100 ], 'cash_service_charge' => [ 'text' => '提现手续费', 'value' => floatval(0) ], 'share_goods_status' => [ 'text' => '购买指定商品成为分销商', 'value' => '' ], 'share_goods_id' => [ 'text' => '购买指定商品id', 'value' => '' ], 'content' => [ 'text' => '用户须知', 'value' => '' ], 'agree' => [ 'text' => '协议', 'value' => '' ], 'remaining_sum' => [ 'text' => '余额提现', 'value' => 0 ], 'bank' => [ 'text' => '银行卡', 'value' => 0 ], 'cash_price_type' => [ 'text' => '佣金到账类型', 'value' => '1' ], 'cash_price_amount' => [ 'text' => '现金', 'value' => 100 ], 'cash_price_integral' => [ 'text' => '积分', 'value' => 0 ], 'cash_price_balance' => [ 'text' => '余额', 'value' => 0 ], 'auto_money' => [ 'text' => '自动打款金额', 'value' => 0 ] ]; $data = array_merge($data_, $data); } if($this->name === 'share_money_setting' && !$data){ $data = [ 'cash_price_amount' => ['text' => '现金','value' => 100], 'cash_price_balance' => ['text' => '余额','value' => 0], 'cash_price_integral' => ['text' => '积分','value' => 0], 'cash_price_type' => ['text' => '佣金到账类型','value' => "1"], 'commission_type' => [2], 'expire_day' => "0", 'giveType' => 1, 'level_one' => ['text' => '一级分销','value' => 0], 'level_three' => ['text' => '三级分销','value' => 0], 'level_two' => ['text' => '二级分销','value' => 0], 'scale' => "0", 'share_goods_id' => [] ]; } if ($this->name === 'share_basic_setting') { if (!isset($data['cash_price_type'])) { $data = array_merge($data, [ 'cash_price_type' => [ 'text' => '佣金到账类型', 'value' => '1' ], 'cash_price_amount' => [ 'text' => '现金', 'value' => 100 ], 'cash_price_integral' => [ 'text' => '积分', 'value' => 0 ], 'cash_price_balance' => [ 'text' => '余额', 'value' => 0 ], ]); } } if ($this->name === 'share_money_setting') { if (!isset($data['commission_type'])) { $data['commission_type'] = [2]; } if (!isset($data['expire_day'])) { $data['expire_day'] = 0; } if (!isset($data['giveType'])) { $data['giveType'] = 1; } if (!isset($data['scale'])) { $data['scale'] = '0'; } } $data['share_goods_id']['value'] = $data['share_goods_id']['value'] ?? ''; return ['code' => 0, 'msg' => 'success', 'data' => $data, 'goods' => $goods]; } }