| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\models\Lg;
- use app\models\Option;
- use app\constants\OptionSetting;
- use app\models\Level;
- use app\models\Order;
- use app\models\Recharge;
- use app\models\RechargeModule;
- use app\models\ReOrder;
- use app\models\Store;
- use app\models\User;
- use app\modules\client\behaviors\Auth;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\DetailForm;
- use app\modules\client\models\v1\RechargePayDataForm;
- use app\modules\client\models\v1\RechargeSubmitForm;
- use app\modules\client\models\v1\RecordForm;
- use yii\base\BaseObject;
- use app\modules\admin\models\ReOrderForm;
- use app\modules\client\models\v1\CashForm;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Json;
- use yii\helpers\VarDumper;
- class RechargeController extends BaseController
- {
- public function behaviors()
- {
- return parent::behaviors();
- }
- /**
- * 申请提现
- */
- public function actionCashApply()
- {
- $form = new CashForm();
- $form->user_id = get_user_id();
- $form->store_id = get_store_id();
- $form->attributes = post_params();
- return $this->asJson($form->cashBalance());
- }
- /**
- * 获取提现相关
- */
- public function actionGetPrice()
- {
- $store_id = get_store_id();
- $store = Store::findOne($store_id);
- $balancToCash = (int)Option::get(OptionSetting::BALANCE_TO_CASH, $store_id, 'recharge', 0)['value'];
- if (!$balancToCash) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提现功能未开启'
- ]);
- }
- $balancToCashSet = json_decode(Option::get(OptionSetting::BALANCE_TO_CASH_SETTING, $this->store_id, 'recharge', '{}')['value'], true);
- if (!isset($balancToCashSet['cash_service_charge'])) {
- $balancToCashSet['cash_service_charge'] = 0;
- }
- $saas_user = get_saas_user();
- $lg_info = Lg::find()->where(['user_id' => $saas_user->id, 'store_id' => get_store_id(),'status'=>1,'is_delete'=>0])->one();
- $res = [
- 'money' => get_user()->money,
- 'balancToCash' => $balancToCash,
- 'balancToCashSet' => $balancToCashSet,
- ];
- // 新提现方式
- $res['cash_method_list'] = [];
- $saas_user = get_saas_user();
- if (!empty($saas_user->withdraw_method)) {
- $cash_method = json_decode($saas_user->withdraw_method, true);
- if($lg_info){
- //灵工
- $cash_method = array_merge($cash_method, [[
- 'type' => 'lg'
- ]]);
- }
- if (is_array($cash_method)) {
- foreach($cash_method as $i => $item){
- if ($item['type'] === 'wechat' && $balancToCashSet['balance_to_cash_pay_type']['wechat'] == 0) {
- unset($cash_method[$i]);
- }
- if ($item['type'] === 'alipay' && $balancToCashSet['balance_to_cash_pay_type']['alipay'] == 0) {
- unset($cash_method[$i]);
- }
- if ($item['type'] === 'bank_card' && $balancToCashSet['balance_to_cash_pay_type']['bank_card'] == 0) {
- unset($cash_method[$i]);
- }
- if ($item['type'] === 'lg' && $store->lg_cash == 0) {
- unset($cash_method[$i]);
- }
- }
- $res['cash_method_list'] = array_values($cash_method);
- }
- }else{
- if($lg_info){
- //灵工
- $cash_method[]['type'] = 'lg';
- $res['cash_method_list'] = array_values($cash_method);
- }
- }
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]);
- }
- public function actionIndex()
- {
- $user = get_user();
- // 搜索指定月份的充值记录及余额消费记录
- $form = new RecordForm();
- $form->user = $user;
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $res = $form->search();
- if ($res['code'] == 1) {
- return $this->asJson($res);
- }
- // 余额页设置
- $form = new RechargeModule();
- $form->store_id = get_store_id();
- $setting = $form->search_recharge();
- $data = [
- 'money' => $user->money,
- 'list' => $res['data']['list'],
- 'setting' => $setting,
- 'date' => $res['data']['date'],
- ];
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]);
- }
- /**
- * 搜索指定月份的充值记录及余额消费记录
- * @return \yii\web\Response
- * @throws \yii\db\Exception
- */
- public function actionRecord()
- {
- $user = get_user();
- $form = new RecordForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user = $user;
- $res = $form->search();
- return $this->asJson($res);
- }
- //充值记录
- public function actionRechargeOrder()
- {
- $user = get_user();
- $form = new RecordForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user = $user;
- return $this->asJson($form->rechargeOrder());
- }
- //充值订单申请退款
- public function actionRechargeOrderRefundMoneyApply()
- {
- $user = get_user();
- $form = new ReOrderForm();
- $form->store_id = get_store_id();
- $order_id = input_params('order_id', 0);
- $desc_user = input_params('desc_user', '');
- return $this->asJson($form->refundMoneyApply($user->id, $order_id, $desc_user));
- }
- //充值订单退款列表
- public function actionRechargeOrderRefundMoneyList()
- {
- $form = new ReOrderForm();
- $form->store_id = get_store_id();
- $form->user_id = get_user_id();
- $form->order_id = input_params('order_id', 0);
- return $this->asJson($form->refundMoneyList());
- }
- public function actionLeagueRecord()
- {
- $user = get_user();
- $form = new RecordForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->user = $user;
- $res = $form->league_search();
- return $this->asJson($res);
- }
- /**
- * 充值可选列表
- * @return \yii\web\Response
- */
- public function actionList()
- {
- $name = [
- 'recharge_wallet_status',
- 'recharge_custom_status',
- 'recharge_pic_url',
- 'recharge_ad_pic_url',
- 'recharge_page_url',
- 'recharge_p_pic_url',
- 'recharge_help',
- ];
- $data = Option::get($name, get_store_id(), 'recharge');
- $data = array_column($data, null, 'name');
- $balance = [
- 'status' => $data['recharge_wallet_status']['value'],
- 'pic_url' => $data['recharge_pic_url']['value'],
- 'ad_pic_url' => $data['recharge_ad_pic_url']['value'],
- 'page_url' => $data['recharge_page_url']['value'],
- 'p_pic_url' => $data['recharge_p_pic_url']['value'],
- 'help' => $data['recharge_help']['value'],
- 'type' => $data['recharge_custom_status']['value'],
- ];
- $list = Recharge::find()->where(['store_id' => get_store_id(), 'is_delete' => 0])
- ->orderBy(['pay_price' => SORT_DESC])->asArray()->all();
- $levelType = Level::find()->where(['store_id' => get_store_id(), 'is_delete' => Level::NOT_DELETE])->asArray()->all();
- foreach ($list as &$val) {
- foreach ($levelType as $type) {
- if ($val['level_up'] == $type['level']) {
- $val['level_up_name'] = $type['name'];
- break;
- }
- }
- }
- // $list = array_filter($list, function($item) {
- // return $item['level_up'] != get_user()->level;
- // });
-
- // TODO: msg_id
- $data = [
- 'list' => array_values($list),
- 'tpl_msg_id' => '',
- 'balance' => $balance
- ];
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]);
- }
- /**
- * 充值提交
- * @return \yii\web\Response
- */
- public function actionSubmit()
- {
- $form = new RechargeSubmitForm();
- $form->store_id = get_store_id();
- $form->user = get_user();
- $form->attributes = post_params();
- // if (get_params('_form') === 'h5') {
- // $form->pay_type = 1;
- // }
- return $this->asJson($form->save());
- }
- /**
- * 余额收支详情
- * @return \yii\web\Response
- */
- public function actionDetail()
- {
- $form = new DetailForm();
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- //充值方式
- public function actionGetPayTypeList() {
- $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'pay', Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store', '{"wechat":{"value":1}}')['value']);
- $pay_type_list = Json::decode($pay_type_list_json['value']);
- $user_pay_list_json = Option::get('payment_' . get_user_id(), get_store_id(), 'user')['value'];
- if ($user_pay_list_json) {
- $user_pay_list_arr = Json::decode($user_pay_list_json);
- foreach ($pay_type_list as $key => &$value) {
- if (isset($user_pay_list_arr[$key]) && $user_pay_list_arr[$key]['value'] == 0 && $value['value'] == 1) {
- $value['value'] = 0;
- }
- }
- }
- $new_list = [];
- foreach ($pay_type_list as $index => $pay_type_value) {
- if ((is_wechat_platform() || is_h5() || is_app_platform()) && $index == 'wechat' && $pay_type_value['value'] == 1) {
- $new_list[] = [
- 'name' => '微信支付',
- 'payment' => 1,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
- ];
- }
- if ((is_wechat_platform()) && $index == Order::PAY_TYPE_KEY_WX_B2B && $pay_type_value['value'] == 1) {
- $new_list[] = [
- 'name' => Order::PAY_TYPE_NAME_WX_B2B,
- 'payment' => Order::PAY_TYPE_WX_B2B,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
- ];
- }
- if ((is_alipay_platform() || is_h5() || is_app_platform()) && $index == 'alipay' && $pay_type_value['value'] == 1) {
- $new_list[] = [
- 'name' => '支付宝支付',
- 'payment' => 4,
- 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png'
- ];
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => $new_list
- ]);
- }
- }
|