store_id = get_store_id(); $form->admin = Yii::$app->jwt->getAdmin(); $form->attributes = $data; return $this->asJson($form->recharge()); } public function actionBatchUserRecharge() { $form = new AccountLogForm(); $data = post_params(); $form->store_id = get_store_id(); $form->admin = Yii::$app->jwt->getAdmin(); $form->attributes = $data; return $this->asJson($form->batchRecharge()); } /** * 充值联盟券 */ public function actionUserLeague() { $saas_user_id = post_params('user_id'); $league_price = post_params('money'); $type = post_params('recharge_type');//1 新增 2 扣除 $role = intval(post_params('role')); if (!in_array($role, [SaaSLeaguePriceLog::ROLE_USER, SaaSLeaguePriceLog::ROLE_STORE])) { return $this->asJson( [ 'code' => 0, 'msg' => '设置失败 权限错误' ] ); } $model = SaasUser::findOne($saas_user_id); $before = $model->league_price; $saas_id = $model->id; $store_id = 0; if ($role == SaaSLeaguePriceLog::ROLE_STORE) { $model = Store::findOne($saas_user_id); $before = $model->league_price; $store_id = $model->id; } if($type == 1){ //增加 $model->updateCounters(['league_price' => $league_price]); $send_or_take_type = SaaSLeaguePriceLog::SEND_TYPE; }else{ if ($model->league_price < $league_price) { return $this->asJson( [ 'code' => 0, 'msg' => '设置失败 账户余额不足' ] ); } //减少 $model->updateCounters(['league_price' => -$league_price]); $send_or_take_type = SaaSLeaguePriceLog::TAKE_TYPE; } SaaSLeaguePriceLog::setLeaguePriceLog( $store_id, $saas_id, $league_price, $before, SaaSLeaguePriceLog::TYPE_PLATFORM_SET, $send_or_take_type, $role ); return $this->asJson( [ 'code' => 0, 'msg' => '设置成功' ] ); } /** * 充值联盟积分 */ public function actionSaasUserIntegral() { $t = \Yii::$app->db->beginTransaction(); try { $saas_user_id = post_params('user_id'); $money = post_params('money'); $type = post_params('recharge_type');//1 新增 2 扣除 $saas_user_model = SaasUser::findOne($saas_user_id); $before = $saas_user_model->integral; if($type == 1){ //新增 $saas_user_model->updateCounters(['integral' => $money, 'total_integral' => $money]); $log_type = AccountLog::LOG_TYPE_INCOME; }else{ $saas_user_model->updateCounters(['integral' => -$money]); $log_type = AccountLog::LOG_TYPE_EXPEND; } $account_log = new AccountLog(); $account_log->store_id = 0; $account_log->saas_id = $saas_user_model->id; $account_log->user_id = 0; $account_log->type = AccountLog::TYPE_INTEGRAL; $account_log->log_type = $log_type; $account_log->amount = $money; $account_log->desc = "平台操作用户积分"; $account_log->before = $before; $account_log->after = $saas_user_model->integral; $account_log->operator = 'system'; $account_log->operator_id = 0; $account_log->operator_type = AccountLog::TYPE_OPERATOR_BACK; $account_log->created_at = time(); $account_log->order_id = 0; $account_log->order_type = AccountLog::TYPE_RECHARGE_ORDER;; if (!$account_log->save()) { throw new \Exception($account_log->errors); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '赠送成功' ]); } catch (\Exception $e) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } /** * 导入会员增加积分和佣金 * @return \yii\web\Response */ public function actionImportUserRecharge() { $form = new ActivityOrderRebateSelfForm(); $form->store_id = get_store_id(); $form->admin = Yii::$app->jwt->getAdmin(); return $this->asJson($form->importUserRecharge()); } /** * 充值记录 * @return \yii\web\Response */ public function actionList() { $form = new AccountLogForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); return $this->asJson($form->getRechargeList()); } /** * 联盟券记录 */ public function actionLeagueList() { $form = new AccountLogForm(); $form->attributes = get_params(); $form->saas_user_id = get_params('saas_user_id'); return $this->asJson($form->getLeagueList()); } }