| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\constants\OptionSetting;
- use app\models\CashExt;
- use app\models\Goods;
- use app\models\Option;
- use yii\base\Model;
- class ShareSettingForm extends Model
- {
- public $data;
- public $name;
- public $model;
- public $store_id;
- /**
- * 设置分销金额
- */
- public function setMoneySetting() {
- $this->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];
- }
- }
|