| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\AccountLog;
- use app\models\SaaSLeaguePriceLog;
- use app\models\SaasUser;
- use app\models\Store;
- use app\modules\admin\models\AccountLogForm;
- use app\modules\admin\models\ActivityOrderRebateSelfForm;
- use Yii;
- class RechargeController extends BaseController
- {
- /**
- * 充值积分或者余额
- * @return \yii\web\Response
- * @throws \yii\base\Exception
- */
- public function actionUserRecharge() {
- $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->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());
- }
- }
|