| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?php
- namespace app\modules\admin\models\integralAppreciation;
- use app\models\CashExt;
- use app\models\Cat;
- use app\models\Goods;
- use app\models\GoodsCat;
- use app\models\IntegralAppreciationPool;
- use app\models\IntegralAppreciationPoolSub;
- use app\models\Option;
- use yii\base\Model;
- class SettingForm extends Model
- {
- public $store_id;
- public $integral_project_name;//增值积分活动名称
- public $integral_bg;//增值积分活动背景图片
- public $integral_custom_name;//增值积分自定义名称
- public $integral_init_price;//增值积分初始价格
- public $integral_payout_pool_profit;//增值积分提现回流奖金池比例
- public $integral_give_profit;//增值积分转赠手续费比例
- public $integral_amount_to_integral_profit;//奖金池铸造积分百分比
- public $pay_type;
- public $bank;
- public $lg;
- public $remaining_sum;
- public $cash_service_charge;
- public $min_money;
- public $cash_max_single_day;
- public $cash_max_day;
- public $cash_price_amount;
- public $cash_price_integral;
- public $cash_price_balance;
- public $cash_price_type;
- public $is_open_integral_to_balance; //是否开启增积分转余额【0否 1是】
- public $is_open_balance_to_integral; //是否开启余额转增积分【0否 1是】
- public $integral_to_balance_min; //增积分转余额最低限额
- public $integral_to_balance_max; //增积分转余额最高限额
- public $balance_to_integral_min; //余额转增积分最低限额
- public $balance_to_integral_max; //余额转增积分最高限额
- public $balance_to_integral_fee; //余额转增积分手续费比例
- public $integral_to_balance_fee; //增积分转余额手续费比例
- public $amount;//奖金池金额
- public $total_integral;//奖金池总积分
- public function rules()
- {
- return [
- [['store_id', 'pay_type', 'bank', 'remaining_sum'], 'integer'],
- [[ 'cash_service_charge',
- 'min_money', 'cash_max_single_day', 'cash_max_day', 'cash_price_amount', 'cash_price_integral', 'cash_price_balance'
- , 'integral_init_price', 'integral_payout_pool_profit', 'integral_give_profit', 'integral_amount_to_integral_profit',
- 'is_open_integral_to_balance','is_open_balance_to_integral', 'integral_to_balance_min','integral_to_balance_max',
- 'balance_to_integral_min','balance_to_integral_max','integral_to_balance_fee','balance_to_integral_fee','amount','total_integral'], 'number'],
- [['cash_price_type', 'integral_project_name', 'integral_bg' ,'integral_custom_name'], 'string'],
- [['bank', 'remaining_sum', 'lg','is_open_integral_to_balance','is_open_balance_to_integral'], 'in', 'range' => [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()
- ];
- }
- }
- }
|