[0, 1]], [['pay_type'], 'in', 'range' => [0, 1, 2, 3]] ]; } public function attributeLabels() { return [ 'store_id' => 'Store Id', 'integral_project_name' => '增值积分活动名称', 'integral_bg' => '增值积分活动背景图片', 'integral_custom_name' => '增值积分自定义名称', 'integral_init_price' => '增值积分初始价格', 'integral_payout_pool_profit' => '增值积分提现回流奖金池比例', 'integral_give_profit' => '增值积分转赠手续费比例', 'integral_amount_to_integral_profit' => '奖金池铸造积分百分比', 'is_open_integral_to_balance'=>'是否开启增值积分转余额【0否 1是】', 'integral_to_balance_fee'=> '增值积分转余额手续费比例', 'integral_to_balance_min'=> '增值积分转余额最低限额', 'integral_to_balance_max'=> '增值积分转余额最高限额', 'is_open_balance_to_integral' => '是否开启余额转启增值积分【0否 1是】', 'balance_to_integral_fee'=> '余额转增值积分手续费比例', 'balance_to_integral_min'=> '余额转增值积分最低限额', 'balance_to_integral_max'=> '余额转增值积分最高限额', 'amount'=>'积分底池金额', 'total_integral'=>'池子总积分', 'pay_type' => '提现方式【0微信 1支付宝 2微信&支付宝】', 'bank' => '是否开启银行卡提现', 'lg' => '是否开启灵工提现', 'remaining_sum' => '是否开启余额提现', 'cash_service_charge' => '提现手续费', 'min_money' => '最少提现金额', 'cash_max_single_day' => '每日提现上限', 'cash_max_day' => '平台提现上限', ]; } public function settingIndex() { try { $store_id = $this->store_id; $baseUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl; $data = [ 'integral_project_name' => '', 'integral_bg' => $baseUrl . '/web/v1/statics/clientImg/integral_appreciation/integral_bg.png', 'integral_custom_name' => '增值积分', 'integral_init_price' => '0', 'integral_payout_pool_profit' => '0', 'integral_give_profit' => '0', 'integral_amount_to_integral_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, 'cash_price_type' => '1', 'cash_price_amount' => 100, 'cash_price_integral' => 0, 'cash_price_balance' => 0, 'is_open_integral_to_balance' => 0,//是否开启增值积分转余额 0否 1是 'is_open_balance_to_integral' => 0,//是否开启余额转启增值积分 0否 1是 'integral_to_balance_min'=>0, //增值积分转余额最低限额 0不限制 'integral_to_balance_max'=>0, //增值积分转余额最高限额 0不限制 'balance_to_integral_min'=>0, //余额转增值积分最低限额 0不限制 'balance_to_integral_max'=>0, //余额转增值积分最高限额 0不限制 'integral_to_balance_fee'=>0, //增积分转余额手续费比例 0不限制 'balance_to_integral_fee'=>0, //余额转增积分手续费比例 0不限制 'amount'=>0, //积分底池金额 'total_integral'=>0, //池子总积分 ]; $integral_appreciation_setting = Option::get('integral_appreciation_setting', $store_id, 'integral_appreciation')['value']; $integral_appreciation_setting = json_decode($integral_appreciation_setting ?? '', true); if (empty($integral_appreciation_setting)) { $integral_appreciation_setting = $data; } $integralAppreciationPool = IntegralAppreciationPool::findOne(['store_id' => $store_id]); $total_integral = $integralAppreciationPool->total_integral ?: 0; $amount = $integralAppreciationPool->amount ?: 0; $integral_price = $integralAppreciationPool->integral_price ?: 0; $integral_appreciation_setting['total_integral'] = $total_integral; $integral_appreciation_setting['amount'] = $amount; $integral_appreciation_setting['integral_init_price'] = $integral_price; return [ 'code' => 0, 'msg' => '获取成功', 'data' => $integral_appreciation_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]); } $baseUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl; $data = [ 'integral_project_name' => $this->integral_project_name ?: '增值积分中心', 'integral_bg' => $this->integral_bg ?: $baseUrl . '/web/v1/statics/clientImg/integral_appreciation/integral_bg.png', 'integral_custom_name' => $this->integral_custom_name ?: '增值积分', 'integral_init_price' => $this->integral_init_price ?: '0', 'integral_payout_pool_profit' => $this->integral_payout_pool_profit ?: '0', 'integral_give_profit' => $this->integral_give_profit ?: '0', 'integral_amount_to_integral_profit' => $this->integral_amount_to_integral_profit ?: '0', '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), '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, 'is_open_integral_to_balance' => $this->is_open_integral_to_balance, 'is_open_balance_to_integral' => $this->is_open_balance_to_integral, 'integral_to_balance_min'=>$this->integral_to_balance_min, 'integral_to_balance_max'=>$this->integral_to_balance_max, 'balance_to_integral_min'=>$this->balance_to_integral_min, 'balance_to_integral_max'=>$this->balance_to_integral_max, 'integral_to_balance_fee'=>$this->integral_to_balance_fee, 'balance_to_integral_fee'=>$this->balance_to_integral_fee, 'amount'=>$this->amount, 'total_integral'=>$this->total_integral, ]; $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' => '佣金/积分/余额比例设置错误' // ]; // } if ($data['integral_init_price'] <= 0) { throw new \Exception('初始积分价格必须大于0'); } if($data['amount'] <= 0){ throw new \Exception('底池金额必须大于0'); } if($data['total_integral'] <= 0){ throw new \Exception('总积分必须大于0'); } $integral_price = round($data['amount'] / $data['total_integral'], 2); if($data['integral_init_price']!=$integral_price){ throw new \Exception('底池金额除总积分不等于积分价格'); } Option::set('integral_appreciation_setting', json_encode($data, JSON_UNESCAPED_UNICODE), $store_id, 'integral_appreciation'); //初始化池子 $pool = IntegralAppreciationPool::findOne(['store_id' => $store_id]); if(!$pool){ $pool = new IntegralAppreciationPool(); $pool->store_id = $store_id; $pool->amount = $data['amount']; $pool->total_integral = $data['total_integral']; $pool->integral_price = $data['integral_init_price']; $pool->save(); //资金池记录 $poolSub = new IntegralAppreciationPoolSub(); $poolSub->store_id = $store_id; $poolSub->amount = $data['amount']; $poolSub->integral_price = $data['integral_init_price']; $poolSub->integral = $data['total_integral']; $poolSub->reflux_type=3; $poolSub->after_integral_price=$data['integral_init_price']; $poolSub->save(); }else{ //如果价格不一致,则记录资金池变动 if($pool['integral_price']!=$data['integral_init_price']){ $pool->amount = $data['amount']; $pool->total_integral = $data['total_integral']; $pool->integral_price = $data['integral_init_price']; $pool->save(); $poolSub = new IntegralAppreciationPoolSub(); $poolSub->store_id = $store_id; $poolSub->amount = $data['amount']-$pool['amount']; $poolSub->integral_price = $pool['integral_price']; $poolSub->integral = $data['total_integral']; $poolSub->reflux_type=3; $poolSub->after_integral_price=$data['integral_init_price']; $poolSub->save(); } } return [ 'code' => 0, 'msg' => '保存成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }