'现金', self::CASH_PRICE_TYPE_INTEGRAL => '积分', self::CASH_PRICE_TYPE_BALANCE => '余额' ]; /** * {@inheritdoc} */ public static function tableName() { return '{{%cash_ext}}'; } public function behaviors() { return [ [ 'class' => TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'] ] ] ]; } /** * {@inheritdoc} */ public function rules() { return [ [['id', 'cash_id', 'cash_price_type', 'is_pay', 'created_at', 'updated_at'], 'integer'], [['price', 'service_charge', 'real_price'], 'number'] ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => '', 'cash_id' => '提现ID', 'cash_price_type' => '提现金额类型:1现金;2积分;3余额', 'price' => '提现金额', 'is_pay' => '是否打款', 'service_charge' => '手续费', 'real_price' => '实际打款金额', 'created_at' => '创建时间', 'updated_at' => '', ]; } /** * 提现前计算各项提现金额 * @param $type * @param $store_id * @param $cash_price * @return array */ public static function cashFront($type, $store_id, $cash_price,$cashType = 0) { try { $cash_price_type = ''; $cash_price_amount = 0; $cash_price_integral = 0; $cash_price_balance = 0; $cash_service_charge = 0; if ($type == self::CASH_TYPE_SHARE) { $share_basic_setting = Option::get(OptionSetting::SHARE_BASIC_SETTING, $store_id, OptionSetting::SHARE_GROUP_NAME)['value']; $share_basic_setting = json_decode($share_basic_setting ?: '', true); $cash_price_type = $share_basic_setting['cash_price_type']['value'] ?? '1'; $cash_price_amount = $share_basic_setting['cash_price_amount']['value'] ?? 100; $cash_price_integral = $share_basic_setting['cash_price_integral']['value'] ?? 0; $cash_price_balance = $share_basic_setting['cash_price_balance']['value'] ?? 0; $cash_service_charge = $share_basic_setting['cash_service_charge']['value'] ?? 0; } if ($type == self::CASH_TYPE_SHARE_HOLDER) { $cash_price_type = Option::get('cash_price_type', $store_id, 'bonus_pool', '1')['value']; $cash_price_amount = Option::get('cash_price_amount', $store_id, 'bonus_pool', 100)['value']; $cash_price_integral = Option::get('cash_price_integral', $store_id, 'bonus_pool', 0)['value']; $cash_price_balance = Option::get('cash_price_balance', $store_id, 'bonus_pool', 0)['value']; $cash_service_charge = Option::get('shareHolderCashProfit', $store_id, 'bonus_pool', 0)['value']; } if ($type == self::CASH_TYPE_AREA_DIVIDEND) { $cash_price_type = Option::get('cash_price_type', $store_id, 'bonus_pool_area_agent', '1')['value']; $cash_price_amount = Option::get('cash_price_amount', $store_id, 'bonus_pool_area_agent', 100)['value']; $cash_price_integral = Option::get('cash_price_integral', $store_id, 'bonus_pool_area_agent', 0)['value']; $cash_price_balance = Option::get('cash_price_balance', $store_id, 'bonus_pool_area_agent', 0)['value']; $cash_service_charge = Option::get('shareHolderCashProfit', $store_id, 'bonus_pool_area_agent', 0)['value']; } if ($type == self::CASH_TYPE_TEAM_BONUS) { $teamBonus = Option::get(OptionSetting::TEAM_BONUS_SETTING, $store_id, 'store')['value']; $teamBonus = json_decode($teamBonus ?: '', true); $cash_price_type = $teamBonus['cash_price_type'] ?? '1'; $cash_price_amount = $teamBonus['cash_price_amount'] ?? 100; $cash_price_integral = $teamBonus['cash_price_integral'] ?? 0; $cash_price_balance = $teamBonus['cash_price_balance'] ?? 0; $cash_service_charge = $setting['cash_rate'] ?? 0; } if ($type == self::CASH_TYPE_SHARE_GROUP) { $share_group_setting = Option::get('share_group_setting', $store_id, 'share_group')['value']; $share_group_setting = json_decode($share_group_setting ?: '', true); $cash_price_type = $share_group_setting['cash_price_type'] ?? '1'; $cash_price_amount = $share_group_setting['cash_price_amount'] ?? 100; $cash_price_integral = $share_group_setting['cash_price_integral'] ?? 0; $cash_price_balance = $share_group_setting['cash_price_balance'] ?? 0; $cash_service_charge = $share_group_setting['cash_service_charge'] ?? 0; } if ($type == self::CASH_TYPE_SUPER_SALES) { $share_group_setting = Option::get('super_sales_setting', $store_id, 'super_sales')['value']; $share_group_setting = json_decode($share_group_setting ?: '', true); $cash_price_type = $share_group_setting['cash_price_type'] ?? '1'; $cash_price_amount = $share_group_setting['cash_price_amount'] ?? 100; $cash_price_integral = $share_group_setting['cash_price_integral'] ?? 0; $cash_price_balance = $share_group_setting['cash_price_balance'] ?? 0; $cash_service_charge = $share_group_setting['cash_service_charge'] ?? 0; } if ($type == self::CASH_TYPE_INTEGRAL_APPRECIATION) { $integral_appreciation_setting = Option::get('integral_appreciation_setting', $store_id, 'integral_appreciation')['value']; $integral_appreciation_setting = json_decode($integral_appreciation_setting ?: '', true); $cash_price_type = $integral_appreciation_setting['cash_price_type'] ?? '1'; $cash_price_amount = $integral_appreciation_setting['cash_price_amount'] ?? 100; $cash_price_integral = $integral_appreciation_setting['cash_price_integral'] ?? 0; $cash_price_balance = $integral_appreciation_setting['cash_price_balance'] ?? 0; $cash_service_charge = $integral_appreciation_setting['cash_service_charge'] ?? 0; } $cash = Option::get(OptionSetting::CASH_SETTING, get_store_id(), 'store')['value']; if ($cash) { $res = json_decode($cash, true); $cash_price_type = $res['cash_price_type'] ?? '1'; $cash_price_amount = $res['cash_price_amount'] ?? 100; $cash_price_integral = $res['cash_price_integral'] ?? 0; $cash_price_balance = $res['cash_price_balance'] ?? 0; $cash_service_charge = $res['cash_service_charge'] ?? 0; } if($cashType == Cash::TYPE_RECHARGE){ $cash_service_charge = 0; } $amount_price = 0; $integral_price = 0; $balance_price = 0; $real_amount_price = 0; $real_integral_price = 0; $real_balance_price = 0; $real_cash_price = bcsub($cash_price, bcdiv(bcmul($cash_price, $cash_service_charge, 2), 100, 2), 2);//实际可提现金额 $total_profit = 0; $cash_price_type = explode(',', $cash_price_type); if (in_array(self::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) { $total_profit = bcadd($total_profit, $cash_price_amount, 2); $amount_price = bcdiv(bcmul($cash_price, $cash_price_amount, 2), 100, 2); $real_amount_price = bcdiv(bcmul($real_cash_price, $cash_price_amount, 2), 100, 2);//99.4 * 1 } if (in_array(self::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) { $total_profit = bcadd($total_profit, $cash_price_integral, 2); $integral_price = bcdiv(bcmul($cash_price, $cash_price_integral, 2), 100, 2); //兼容计算精度问题 if ($cash_price_balance <= 0 || !in_array(self::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { $real_integral_price = bcsub($real_cash_price, $real_amount_price, 2); } else { $real_integral_price = bcdiv(bcmul($real_cash_price, $cash_price_integral, 2), 100, 2); } } if (in_array(self::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { $total_profit = bcadd($total_profit, $cash_price_balance, 2); $balance_price = bcdiv(bcmul($cash_price, $cash_price_balance, 2), 100, 2); // $real_balance_price = bcmul($cash_price_service, bcdiv($cash_price_balance, 100, 2), 2); //兼容计算精度问题 $real_balance_price = bcsub($real_cash_price, bcadd($real_amount_price, $real_integral_price, 2), 2); } if ($total_profit != 100) { throw new \Exception('计算失败,佣金配置错误'); } return [ 'code' => 0, 'msg' => '计算成功', 'data' => [ 'amount_price' => $amount_price, 'integral_price' => $integral_price, 'balance_price' => $balance_price, 'cash_service_charge' => $cash_service_charge, 'real_amount_price' => $real_amount_price, 'real_integral_price' => $real_integral_price, 'real_balance_price' => $real_balance_price, ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), ]; } } public static function cashExtSave($cash_id, $cash_price_type, $price, $service_charge, $real_price) { try { $model = new self(); $model->cash_id = $cash_id; $model->cash_price_type = $cash_price_type; $model->price = $price; $model->service_charge = $service_charge; $model->real_price = $real_price; if (!$model->save()) { throw new \Exception(implode(';', array_values($model->firstErrors))); } return [ 'code' => 0, 'msg' => '添加成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), ]; } } //计算增值积分提现金额 public static function integral_appreciation_cash($cash_price, $store_id) { $integral_pool = IntegralAppreciationPool::findOne(['store_id' => $store_id]); $integral_appreciation_setting = Option::get('integral_appreciation_setting', $store_id, 'integral_appreciation')['value']; $integral_appreciation_setting = json_decode($integral_appreciation_setting ?: '', true); //提现回流奖金池比例 $integral_payout_pool_profit = $integral_appreciation_setting['integral_payout_pool_profit']; //增值积分初始金额 $integral_price = $integral_appreciation_setting['integral_init_price'] ?? 0; //将增值积分转为实际金额进行计算 if ($integral_pool) { $integral_price = $integral_pool->integral_price; } //计算积分回流后的实际提现到账金额 $cash_price = bcmul($cash_price, $integral_price, 2); $payout_pool_price = bcdiv(bcmul($cash_price, $integral_payout_pool_profit, 2), 100, 2); $cash_price = bcsub($cash_price, $payout_pool_price, 2); if ($cash_price <= 0) { $cash_price = 0; } return [ 'cash_price' => $cash_price,//实际提现金额 'integral_payout_pool_profit' => $integral_payout_pool_profit,//回流比例 'integral_price' => $integral_price,//增值积分价格 'payout_pool_price' => $payout_pool_price//回流金额 ]; } }