RechargeController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\models\AccountLog;
  9. use app\models\SaaSLeaguePriceLog;
  10. use app\models\SaasUser;
  11. use app\models\Store;
  12. use app\modules\admin\models\AccountLogForm;
  13. use app\modules\admin\models\ActivityOrderRebateSelfForm;
  14. use Yii;
  15. class RechargeController extends BaseController
  16. {
  17. /**
  18. * 充值积分或者余额
  19. * @return \yii\web\Response
  20. * @throws \yii\base\Exception
  21. */
  22. public function actionUserRecharge() {
  23. $form = new AccountLogForm();
  24. $data = post_params();
  25. $form->store_id = get_store_id();
  26. $form->admin = Yii::$app->jwt->getAdmin();
  27. $form->attributes = $data;
  28. return $this->asJson($form->recharge());
  29. }
  30. public function actionBatchUserRecharge() {
  31. $form = new AccountLogForm();
  32. $data = post_params();
  33. $form->store_id = get_store_id();
  34. $form->admin = Yii::$app->jwt->getAdmin();
  35. $form->attributes = $data;
  36. return $this->asJson($form->batchRecharge());
  37. }
  38. /**
  39. * 充值联盟券
  40. */
  41. public function actionUserLeague()
  42. {
  43. $saas_user_id = post_params('user_id');
  44. $league_price = post_params('money');
  45. $type = post_params('recharge_type');//1 新增 2 扣除
  46. $role = intval(post_params('role'));
  47. if (!in_array($role, [SaaSLeaguePriceLog::ROLE_USER, SaaSLeaguePriceLog::ROLE_STORE])) {
  48. return $this->asJson(
  49. [
  50. 'code' => 0,
  51. 'msg' => '设置失败 权限错误'
  52. ]
  53. );
  54. }
  55. $model = SaasUser::findOne($saas_user_id);
  56. $before = $model->league_price;
  57. $saas_id = $model->id;
  58. $store_id = 0;
  59. if ($role == SaaSLeaguePriceLog::ROLE_STORE) {
  60. $model = Store::findOne($saas_user_id);
  61. $before = $model->league_price;
  62. $store_id = $model->id;
  63. }
  64. if($type == 1){
  65. //增加
  66. $model->updateCounters(['league_price' => $league_price]);
  67. $send_or_take_type = SaaSLeaguePriceLog::SEND_TYPE;
  68. }else{
  69. if ($model->league_price < $league_price) {
  70. return $this->asJson(
  71. [
  72. 'code' => 0,
  73. 'msg' => '设置失败 账户余额不足'
  74. ]
  75. );
  76. }
  77. //减少
  78. $model->updateCounters(['league_price' => -$league_price]);
  79. $send_or_take_type = SaaSLeaguePriceLog::TAKE_TYPE;
  80. }
  81. SaaSLeaguePriceLog::setLeaguePriceLog(
  82. $store_id,
  83. $saas_id,
  84. $league_price,
  85. $before,
  86. SaaSLeaguePriceLog::TYPE_PLATFORM_SET,
  87. $send_or_take_type,
  88. $role
  89. );
  90. return $this->asJson(
  91. [
  92. 'code' => 0,
  93. 'msg' => '设置成功'
  94. ]
  95. );
  96. }
  97. /**
  98. * 充值联盟积分
  99. */
  100. public function actionSaasUserIntegral()
  101. {
  102. $t = \Yii::$app->db->beginTransaction();
  103. try {
  104. $saas_user_id = post_params('user_id');
  105. $money = post_params('money');
  106. $type = post_params('recharge_type');//1 新增 2 扣除
  107. $saas_user_model = SaasUser::findOne($saas_user_id);
  108. $before = $saas_user_model->integral;
  109. if($type == 1){
  110. //新增
  111. $saas_user_model->updateCounters(['integral' => $money, 'total_integral' => $money]);
  112. $log_type = AccountLog::LOG_TYPE_INCOME;
  113. }else{
  114. $saas_user_model->updateCounters(['integral' => -$money]);
  115. $log_type = AccountLog::LOG_TYPE_EXPEND;
  116. }
  117. $account_log = new AccountLog();
  118. $account_log->store_id = 0;
  119. $account_log->saas_id = $saas_user_model->id;
  120. $account_log->user_id = 0;
  121. $account_log->type = AccountLog::TYPE_INTEGRAL;
  122. $account_log->log_type = $log_type;
  123. $account_log->amount = $money;
  124. $account_log->desc = "平台操作用户积分";
  125. $account_log->before = $before;
  126. $account_log->after = $saas_user_model->integral;
  127. $account_log->operator = 'system';
  128. $account_log->operator_id = 0;
  129. $account_log->operator_type = AccountLog::TYPE_OPERATOR_BACK;
  130. $account_log->created_at = time();
  131. $account_log->order_id = 0;
  132. $account_log->order_type = AccountLog::TYPE_RECHARGE_ORDER;;
  133. if (!$account_log->save()) {
  134. throw new \Exception($account_log->errors);
  135. }
  136. $t->commit();
  137. return $this->asJson([
  138. 'code' => 0,
  139. 'msg' => '赠送成功'
  140. ]);
  141. } catch (\Exception $e) {
  142. $t->rollBack();
  143. return $this->asJson([
  144. 'code' => 1,
  145. 'msg' => $e->getMessage()
  146. ]);
  147. }
  148. }
  149. /**
  150. * 导入会员增加积分和佣金
  151. * @return \yii\web\Response
  152. */
  153. public function actionImportUserRecharge() {
  154. $form = new ActivityOrderRebateSelfForm();
  155. $form->store_id = get_store_id();
  156. $form->admin = Yii::$app->jwt->getAdmin();
  157. return $this->asJson($form->importUserRecharge());
  158. }
  159. /**
  160. * 充值记录
  161. * @return \yii\web\Response
  162. */
  163. public function actionList() {
  164. $form = new AccountLogForm();
  165. $form->attributes = get_params();
  166. $form->store_id = get_store_id();
  167. return $this->asJson($form->getRechargeList());
  168. }
  169. /**
  170. * 联盟券记录
  171. */
  172. public function actionLeagueList()
  173. {
  174. $form = new AccountLogForm();
  175. $form->attributes = get_params();
  176. $form->saas_user_id = get_params('saas_user_id');
  177. return $this->asJson($form->getLeagueList());
  178. }
  179. }