asJson([ 'code' => 1, 'msg' => '提现记录不存在' ]); } $store = Store::findOne($store_id); $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value']; if ($store->is_platform_transfers == 1) { $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value']; } // if (empty($wechat_cash)) { // return $this->asJson([ // 'code' => 1, // 'msg' => '未开启微信提现功能' // ]); // } // $wechat_cash = json_decode($wechat_cash, true); // if (empty($wechat_cash)) { // return $this->asJson([ // 'code' => 1, // 'msg' => '未开启微信提现功能' // ]); // } $name = $cash->name; if (intval($cash->type) === Cash::TYPE_RECHARGE) { $user_id = $cash->user_id; $user = User::findOne($user_id); $saas_user = SaasUser::findOne(['mobile' => $user->binding, 'is_delete' => 0]); $name = $saas_user->name; } $is_platform_transfers = $cash->is_platform_transfers; $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value']; if ($is_platform_transfers == 1) { $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value']; } $wechat_cash = json_decode($wechat_cash, true); $package = ''; if (!empty($cash->wx_cash_result_info)) { $wx_cash_result_info = json_decode($cash->wx_cash_result_info, true); $package = $wx_cash_result_info['package_info']; } $is_user_confirm = 1; $status = $cash->status; //如果是微信提现且为自动打款 if ($cash->type == Cash::TYPE_WX && $cash->status == Cash::STATUS_GIVEN) { //如果使用的是微信新版打款方式 if (intval($cash->wx_cash_type)) { //如果微信新版状态是等待用户确认 if ($cash->wx_cash_state == 'WAIT_USER_CONFIRM') { $is_user_confirm = 0; // $status = Cash::STATUS_CONFIRM; } } else { //如果是微信旧版打款方式 且为微信提交打款请求但是未成功或失败状态 if ($cash->wx_cash_status == 0) { $status = Cash::STATUS_CONFIRM; } } } $price = Cash::getServiceMoney($cash); $data = [ 'type' => Cash::$type[$cash->type],//提现方式 'status' => $status,//提现状态 'order_no' => $cash->order_no, 'created_at' => date('Y-m-d H:i:s', $cash->created_at), 'updated_at' => $cash->updated_at > 0 ? date('Y-m-d H:i:s', $cash->updated_at) : '', 'name' => $name, 'appid' => $wechat_cash['appid'], 'mch_id' => $wechat_cash['mch_id'], 'package' => $package, 'is_user_confirm' => $is_user_confirm, 'price' => $price, ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data ]); } public function actionGetPrice() { $cash_type = get_params('cash_type'); $form = new ShareForm(); $cash = Option::get(OptionSetting::CASH_SETTING, get_store_id(), 'store')['value']; if ($cash) { $res['data'] = json_decode($cash, true); $res['data']['is_set_new_cash_setting'] = 1; } else { $res['data']['is_set_new_cash_setting'] = 0; } $form->store_id = get_store_id(); $form->user_id = get_user_id(); $res['data']['price'] = $form->getPrice(); if ($cash_type == Cash::IS_CASH_TYPE_TEAM_GRADES) { $userTeamGrades = TeamGrades::getUserTeamGrades(get_user_id()); if ($res['data']['price']['price'] > $userTeamGrades['price']) { $res['data']['price']['price'] = $userTeamGrades['price']; } } elseif ($cash_type == Cash::IS_CASH_TYPE_SHARE_GROUP_PURCHASE) { $shareGroupPurchaseUser = ShareGroupPurchaseUser::findOne(['user_id' => get_user_id()]); if ($res['data']['price']['price'] > $shareGroupPurchaseUser->price) { $res['data']['price']['price'] = $shareGroupPurchaseUser->price; } } elseif ($cash_type == Cash::IS_CASH_TYPE_SUPER_SALES) { $superSalesUser = SuperSalesUser::findOne(['user_id' => get_user_id()]); if ($res['data']['price']['price'] > $superSalesUser->price) { $res['data']['price']['price'] = $superSalesUser->price; } } elseif ($cash_type == Cash::IS_CASH_TYPE_INTEGRAL_APPRECIATION) { $integralAppreciationUser = IntegralAppreciationUser::findOne(['user_id' => get_user_id()]); //与其他不一样 增值积分需要先根据提现金额 计算一下实际的提现金额 $res['data']['price']['price'] = $integralAppreciationUser->integral ?: '0.00'; } if ($res['data']['cash_service_charge'] == 0) { $res['data']['service_content'] = ""; } else { $res['data']['service_content'] = "提现需要加收{$res['data']['cash_service_charge']}%手续费"; } $cash_last = Cash::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'is_delete' => 0]) ->orderBy(['id' => SORT_DESC])->select(['name', 'mobile', 'type', 'bank_name'])->asArray()->one(); $res['data']['cash_last'] = $cash_last; $cash_max_day = floatval($res['data']['cash_max_day']); if ($cash_max_day) { $query = Cash::find()->where([ 'store_id' => get_store_id(), 'is_delete' => 0, 'status' => [0, 1, 2, 5], ]); $cash_sum = $query->andWhere([ 'AND', ['>=', 'created_at', strtotime(date('Y-m-d 00:00:00'))], ['<=', 'created_at', strtotime(date('Y-m-d 23:59:59'))], ])->sum('price'); $cash_max_day = $cash_max_day - ($cash_sum ? $cash_sum : 0); $res['data']['cash_max_day'] = max(0, floatval(sprintf('%.2f', $cash_max_day))); } else { $res['data']['cash_max_day'] = -1; } if ($res['data']['cash_max_day'] !== 0) { $cash_max_single_day = $res['data']['cash_max_single_day']; if ($cash_max_single_day) { if ($res['data']['cash_max_day'] > $cash_max_single_day) { $res['data']['cash_max_day'] = $cash_max_single_day; } } else { $res['data']['cash_max_day'] = -1; } } $wxappUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/wxapp/images'; $payTypeList = [ [ 'icon' => $wxappUrl . '/icon-share-wechat.png', 'name' => '微信', 'is_show' => false ], [ 'icon' => $wxappUrl . '/icon-share-ant.png', 'name' => '支付宝', 'is_show' => false ], [ 'icon' => $wxappUrl . '/icon-share-bank.png', 'name' => '银行卡', 'is_show' => false ], [ 'icon' => $wxappUrl . '/gold.png', 'name' => '余额', 'is_show' => false ], [ 'icon' => $wxappUrl . '/icon-share-bank.png', 'name' => '灵工提现', 'is_show' => false ], ]; switch ($res['data']['pay_type']) { case 0: if(isset($res['data']['pay_type'])){ $payTypeList[0]['is_show'] = true; } break; case 1: $payTypeList[1]['is_show'] = true; break; case 2: $payTypeList[0]['is_show'] = true; $payTypeList[1]['is_show'] = true; break; default: break; } if ($res['data']['pay_wechat'] == 1) { $payTypeList[0]['is_show'] = true; } if ($res['data']['pay_alipay'] == 1) { $payTypeList[1]['is_show'] = true; } if ($res['data']['bank'] == 1) { $payTypeList[2]['is_show'] = true; } if ($res['data']['remaining_sum'] == 1) { $payTypeList[3]['is_show'] = true; } //灵工提现 if ($res['data']['lg'] == 1) { $payTypeList[4]['is_show'] = true; } $res['data']['pay_type_list'] = $payTypeList; $res['data']["cash_success_tpl"] = ''; $res['data']["cash_fail_tpl"] = ''; // 新提现方式 $res['data']['cash_method_list'] = []; $saas_user = get_saas_user(); $cash_method = []; if (!empty($saas_user->withdraw_method)) { $cash_method = json_decode($saas_user->withdraw_method, true); } $money = [ [ 'type' => 'money' ] ]; $cash_method = array_merge($cash_method, $money); //判断是否灵工进件 $lg_info = Lg::find()->where(['user_id' => $saas_user->id, 'store_id' => get_store_id(), 'status' => 1, 'is_delete' => 0])->one(); if ($lg_info) { $lg = [ [ 'type' => 'lg' ] ]; $cash_method = array_merge($cash_method, $lg); } if (is_array($cash_method)) { foreach ($cash_method as $index => &$item) { if ($item['type'] === 'wechat' && $payTypeList[0]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'alipay' && $payTypeList[1]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'bank_card' && $payTypeList[2]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'money' && $payTypeList[3]['is_show'] === false) { unset($cash_method[$index]); } if ($item['type'] === 'lg' && $payTypeList[4]['is_show'] === false) { unset($cash_method[$index]); } } $res['data']['cash_method_list'] = array_values($cash_method);; } return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res['data']]); } public function actionGetCashFront() { $post = post_params(); $cash_price = $post['price']; try { $amount_price = 0; $integral_price = 0; $balance_price = 0; $real_amount_price = 0; $real_integral_price = 0; $real_balance_price = 0; $cash = Option::get(OptionSetting::CASH_SETTING, get_store_id(), 'store')['value']; if ($cash) { $cash = json_decode($cash, true); $cash_price_amount = $cash['cash_price_amount'] ?? 100; $cash_price_integral = $cash['cash_price_integral'] ?? 0; $cash_price_balance = $cash['cash_price_balance'] ?? 0; $cash_service_charge = $cash['cash_service_charge'] ?? 0; $cash_price_type = $cash['cash_price_type'] ?? '1'; } else { $cash_price_amount = 0; $cash_price_integral = 0; $cash_price_balance = 0; $cash_service_charge = 0; $cash_price_type = '1'; } $real_cash_price = bcsub($cash_price, bcdiv(bcmul($cash_price, $cash_service_charge, 2), 100, 2), 2);//实际可提现金额 $total_profit = 0; $cash_price_type = explode(',', $cash_price_type); if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) { $total_profit = bcadd($total_profit, $cash_price_amount, 2); $amount_price = bcdiv(bcmul($cash_price, $cash_price_amount, 2), 100, 2); $real_amount_price = bcdiv(bcmul($real_cash_price, $cash_price_amount, 2), 100, 2);//99.4 * 1 } if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) { $total_profit = bcadd($total_profit, $cash_price_integral, 2); $integral_price = bcdiv(bcmul($cash_price, $cash_price_integral, 2), 100, 2); //兼容计算精度问题 if ($cash_price_balance <= 0 || !in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { $real_integral_price = bcsub($real_cash_price, $real_amount_price, 2); } else { $real_integral_price = bcdiv(bcmul($real_cash_price, $cash_price_integral, 2), 100, 2); } } if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { $total_profit = bcadd($total_profit, $cash_price_balance, 2); $balance_price = bcdiv(bcmul($cash_price, $cash_price_balance, 2), 100, 2); //兼容计算精度问题 $real_balance_price = bcsub($real_cash_price, bcadd($real_amount_price, $real_integral_price, 2), 2); } if ($total_profit != 100) { throw new \Exception('计算失败,佣金配置错误'); } return $this->asJson([ 'code' => 0, 'msg' => '计算成功', 'data' => [ 'amount_price' => $amount_price, 'integral_price' => $integral_price, 'balance_price' => $balance_price, 'cash_service_charge' => $cash_service_charge, 'real_amount_price' => $real_amount_price, 'real_integral_price' => $real_integral_price, 'real_balance_price' => $real_balance_price, ] ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } public function actionGetCashMethod() { $saas_user = get_saas_user(); $payTypeList = [ [ 'name' => '微信', 'is_show' => false, 'type' => 'wechat', 'is_bind' => false ], [ 'name' => '支付宝', 'is_show' => false, 'type' => 'alipay', 'is_bind' => false ], [ 'name' => '银行卡', 'is_show' => false, 'type' => 'bank_card', 'is_bind' => false ], [ 'name' => '灵工提现', 'is_show' => false, 'type' => 'lg', 'is_bind' => false ], ]; $cash = Option::get(OptionSetting::CASH_SETTING, get_store_id(), 'store')['value']; if ($cash) { $setting = json_decode($cash, true); $is_set_new_cash_setting = 1; if ($setting['pay_wechat'] == 1) { $payTypeList[0]['is_show'] = true; } if ($setting['pay_alipay'] == 1) { $payTypeList[1]['is_show'] = true; } if ($setting['bank'] == 1) { $payTypeList[2]['is_show'] = true; } if ($setting['lg'] == 1) { $payTypeList[3]['is_show'] = true; } if (!empty($saas_user->withdraw_method)) { $decode = json_decode($saas_user->withdraw_method, true); if (is_array($decode)) { $cash_method = $decode; foreach ($payTypeList as &$pay_item) { foreach ($cash_method as $item) { if ($item['type'] === $pay_item['type']) { $pay_item['is_bind'] = true; $pay_item = array_merge($pay_item, $item); } } } } } //判断灵工是否绑定 foreach ($payTypeList as &$item) { $lg = Lg::find()->where(['user_id' => $saas_user->id, 'is_delete' => 0, 'status' => 1])->one(); if ($lg) { if ('lg' === $item['type']) { $item['is_bind'] = true; $item = array_merge($item, $item); } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'is_set_new_cash_setting' => 1, 'list' => $payTypeList, ], ]); } else { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'is_set_new_cash_setting' => 0, 'list' => [], ], ]); } } public function actionApply() { $form = new CashForm(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); $form->attributes = post_params(); return $this->asJson($form->saveNew()); } }