| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace common\models\user;
- use common\models\base\BaseActiveRecord;
- use common\enums\StatusEnum;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%withdraws_limit_log}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 消费者ID
- * @property float $amount 提现额度,单位:元
- * @property int $from 提现来源1佣金2余额
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $type 0:公共额度(如果开启提现余额限额则不包含余额的额度),1:提现余额额度
- */
- class WithdrawsLimitLog extends BaseActiveRecord
- {
- const COMMON_LIMIT = 0;
- const BALANCE_LIMIT = 1;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%withdraws_limit_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'from', 'status', 'created_at', 'updated_at', 'type'], 'integer'],
- [['amount'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'amount' => 'Amount',
- 'from' => 'From',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'type' => 'Type',
- ];
- }
- /**
- * 保存数据
- * @param array $params
- * @return bool|UserWallet
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['user_id'])) {
- $model = self::findOne(['user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'type' => $params['type']]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- } else {
- if (empty($model)) throw new Exception('用户尚未注册,请先注册');
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function resetCashAmount($params){
- $user_id = $params['user_id'];
- $mall_id = $params['mall_id'];
- $payment = \Yii::$app->services->setting->mall->get($mall_id, 'withdraw_income');
- if(!empty($payment["withdraws_limit_enable"])){
- $withdraws_limit_money = isset($payment["withdraws_limit_money"]) ? $payment["withdraws_limit_money"] : 0;
- $withdrawsLimitLog = self::findOne(['user_id' => $user_id, 'status' => StatusEnum::ENABLED,'from'=>1, 'type' => self::COMMON_LIMIT]);
- if(!empty($withdrawsLimitLog)){
- $withdrawsLimitLog->amount = $withdraws_limit_money;
- if(!$withdrawsLimitLog->save()){
- \Yii::error('提现额度保存失败,user_id:'.$user_id);
- return false;
- }
- }
- if (!empty($payment['is_independent_balance_withdraw'])) {
- $withdraws_limit_money = $payment["independent_balance_withdraw_max_amount"] ?? 0;
- $withdrawsLimitLog = self::findOne(['user_id' => $user_id, 'status' => StatusEnum::ENABLED,'from'=>1, 'type' => self::BALANCE_LIMIT]);
- if(!empty($withdrawsLimitLog)){
- $withdrawsLimitLog->amount = $withdraws_limit_money;
- if(!$withdrawsLimitLog->save()){
- \Yii::error('提现额度保存失败,user_id:'.$user_id);
- return false;
- }
- }
- }
- }
- return true;
- }
- /**
- * 根据配置如果开启了 提现余额限额 则type=1
- *
- * @param int $mallId
- * @param string $withdrawType
- * @param array $setting
- *
- * @return int
- */
- public static function getType(int $mallId, string $withdrawType, array $setting = []): int
- {
- if ($withdrawType !== 'balance') {
- return self::COMMON_LIMIT;
- }
- if (empty($setting)) {
- $setting = \Yii::$app->services->setting->mall->get($mallId, 'withdraw_income');
- }
- return !empty($setting['withdraws_limit_enable']) && !empty($setting['is_independent_balance_withdraw']) ? self::BALANCE_LIMIT : self::COMMON_LIMIT;
- }
- }
|