render($this->action->id, [ 'is_install_logistics' => MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_LOGISTICS) ? StatusEnum::ENABLED : StatusEnum::DISABLED, 'mall_id' => $this->mall_id ]); } // 资产设置 public function actionAssets() { $withdraw_cond = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_LIMIT_COND, $this->mall_id); $checked_condition_values = []; if (!empty($withdraw_cond)) { foreach ($withdraw_cond as $item) { $key = $item['addons_name'] . $item['id']; $value = []; if (!empty($item['render_setting']['setting'])) { foreach ($item['render_setting']['setting'] as $val) { if ($val['type'] == 'text') $value[$val['name']] = 0; } } $checked_condition_values[$key] = [ 'key' => $key, 'value' => $value, ]; } } $balanceWithdrawTotalWeightLimitOption = WithdrawEnum::BALANCE_WITHDRAW_TOTAL_WEIGHT_LIMIT_OPTION; return $this->render($this->action->id, [ 'withdraw_cond' => $withdraw_cond, 'checked_condition_values' => json_encode($checked_condition_values), 'balance_withdraw_total_weight_limit_option' => json_encode($balanceWithdrawTotalWeightLimitOption), 'balance_withdraw_total_weight_limit_default_values' => json_encode(array_column($balanceWithdrawTotalWeightLimitOption, 'value')) ]); } // 会员设置 public function actionUser() { return $this->render($this->action->id); } // 订单设置 public function actionOrder() { return $this->render($this->action->id); } //购物车设置 public function actionCart() { return $this->render($this->action->id); } // 编辑或获取配置信息 public function actionEdit() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); if (empty($setting['withdraw_income']['level_withdrwas_reward']['value'])) $setting['withdraw_income']['level_withdrwas_reward']['value'] = []; if (!empty($setting['area']['area_limit']['value'])) { $setting['area']['area_limit']['value'] = json_decode($setting['area']['area_limit']['value'], true); } // 重新组合配置 $data = self::makeUpParams($this->mall_id, $setting); // 修改当抵扣选择字段为空时默认存在 if ($data['order'] && empty($data['order']['score_deduct_value_list'])) { $data['order']['score_deduct_value_list'] = []; } if ($data['order'] && empty($data['order']['achievement_goods_ids'])) { $data['order']['achievement_goods_ids'] = []; } if ($data['score'] && empty($data['score']['level_limit_levels'])) { $data['score']['level_limit_levels'] = []; } if ($data['order'] && !empty($data['order']['goods_deduct_list'])) { $data['order']['goods_deduct_list'] = []; } $is_reset_data = false; //如果业绩开关开启,且设置了业绩商品 if (!empty($data['order']['achievement_goods_ids']) && $data['order']['is_designated_achievement_goods']) { $achievement_goods_ids = json_decode($data['order']['achievement_goods_ids'], true); //获取修改之前设置的商品数据 $last_achievement_goods_ids = \Yii::$app->services->setting->mall->get($this->mall_id, 'order.achievement_goods_ids'); //出现商品修改则需要重新累计数据 if (!empty($last_achievement_goods_ids)) { $last_achievement_goods_ids = json_decode($last_achievement_goods_ids, true); $difference = array_diff($achievement_goods_ids, $last_achievement_goods_ids); } else { $difference = $achievement_goods_ids; } if (!empty($difference)) $is_reset_data = true; } !isset($data['withdraw_income']['balance_withdraw_total_weight_limit_selected']) && $data['withdraw_income']['balance_withdraw_total_weight_limit_selected'] = []; $res = Yii::$app->services->setting->mall->set($this->mall_id, $data); if ($res === false) return $this->error(Yii::$app->services->setting->mall->getError()); if (($data['basic'] ?? false) && ($data['basic']['name'] ?? false)) { $mall_data['name'] = $data['basic']['name']; $mall_data['mall_id'] = $this->mall_id; MallSetting::editMallName($mall_data); //修改商城名称 } if(UserFreezeCommission::getSwitchStatus($this->mall_id) == false) { UserFreezeCommission::clearUserData($this->mall_id); } //如果字段状态为true,对订单利润数据重新累计 // if ($is_reset_data) { // Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_LONG_DURATION, RabbitMqEnum::LONG_DURATION_QUEUE, // ['mall_id' => $this->mall_id], UserTeamProfitStatistics::class, 'orderProfit'); // } $this->success('保存成功'); } else { $params = \Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($params, [ [['type'], 'required'], [['type'], 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; // 获取分组 $groups = SettingEnum::getMallType($params['type']); $data = MallSetting::getConfByGroup($mall_id, $groups, true); $notice_wechat_template_message_list = WechatTemplate::getMap(); unset($notice_wechat_template_message_list['store_order_pay_success']); $notice_wechat_template_message_value= []; if(!empty($data['notice_wechat']['template_message']['value'])){ $notice_wechat_template_message_value = json_decode($data['notice_wechat']['template_message']['value'],true); if(isset($notice_wechat_template_message_value['commission_receipt'])) unset($notice_wechat_template_message_value['commission_receipt']); } foreach ($notice_wechat_template_message_list as $key=>$template_name){ if(!isset($notice_wechat_template_message_value[$key])){ $notice_wechat_template_message_value[$key] = ['tem_key'=>'', 'name'=>$template_name, 'tempid'=>'',]; } } if(isset($notice_wechat_template_message_value['team_add'])) unset($notice_wechat_template_message_value['team_add']); if(isset($notice_wechat_template_message_value['order_refund_agree'])) unset($notice_wechat_template_message_value['order_refund_agree']); $data['notice_wechat']['template_message']['value'] = json_encode($notice_wechat_template_message_value); // 根据类型返回对应内容 switch ($params['type']) { case SettingEnum::MALL_BASIC: $web_url = rtrim(\Yii::$app->services->setting->get('system.h5_url'), '/') . '/#/?sign=' . $this->mall['mall_sign']; $return = array_merge(self::returnArray($data), ['web_url' => $web_url]); break; case SettingEnum::MALL_USER: $user_level = UserLevel::getUserLevelArr($this->mall_id); $return = array_merge(self::returnArray($data), ['user_level' => $user_level]); break; case SettingEnum::MALL_ASSETS: if (empty(Yii::$app->services->setting->get('system.h5_url'))) { $data['recharge']['page_link']['value'] = ''; } else { $data['recharge']['page_link']['value'] = rtrim(Yii::$app->services->setting->get('system.h5_url'), '/') . '/#/plugins/pages/center/recharge/recharge?sign=' . $this->mall['mall_sign']; } $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2); // 全局获取提现方式 $extension_withdraw_way = GlobalInvoke::exec( GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id] ); $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way);; $data['income_withdraw_way'] = $all_withdraw; unset($all_withdraw[WithdrawWayEnum::BALANCE]); // dd($all_withdraw); $data['balance_withdraw_way'] = $all_withdraw; //提现条件 $checked_condition_values = []; if (!empty($data['withdraw_balance']['checked_condition_values']['value'])) { $checked_condition_values = json_decode($data['withdraw_balance']['checked_condition_values']['value'], true); } $withdraw_cond = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_LIMIT_COND, $this->mall_id); if (!empty($withdraw_cond)) { foreach ($withdraw_cond as $item) { $key = $item['addons_name'] . $item['id']; if (!isset($checked_condition_values[$key])) { $value = []; if (!empty($item['render_setting']['setting'])) { foreach ($item['render_setting']['setting'] as $val) { if ($val['type'] == 'text') $value[$val['name']] = 0; } } $checked_condition_values[$key] = [ 'key' => $key, 'value' => $value, ]; } } } $data['withdraw_balance']['checked_condition_values']['value'] = json_encode($checked_condition_values); if(!isset($data['withdraw_income']['is_login']['value'])){ $data['withdraw_income']['is_login'] = $data['withdraw_income']['is_income_cash']; $data['withdraw_income']['is_login']['value'] = 0; $data['withdraw_income']['is_login']['name'] = 'is_login'; } if(!isset($data['withdraw_income']['show_type']['value'])){ $data['withdraw_income']['show_type']['value'] = 1; } $return = self::returnArray($data); // 公共调用 $addons_list = GlobalInvoke::exec(GlobalInvoke::GET_INSTALL_ADDONS_LIST, $this->mall_id, [ 'mall_id' => $this->mall_id, ]); $return['addons_list'] = $addons_list; break; default: $return = self::returnArray($data); break; } $return['mall_sign'] = $mall['mall_sign'] ?? ''; if (!empty($return['balance_withdraw_way']['alipay_tax'])) { $return['balance_withdraw_way']['alipay_tax'] = $return['balance_withdraw_way']['alipay_tax']['name']; } if (!empty($return['income_withdraw_way']['alipay_tax'])) { $return['income_withdraw_way']['alipay_tax'] = $return['income_withdraw_way']['alipay_tax']['name']; } $return['user_levels'] = UserLevel::getUserLevel([['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED]], [], true, 'id,level,name'); // $return['user_levels'][] = ['id' => 0, 'level' => 0, 'name' => '普通用户']; $return['user_levels_normal'] = $return['user_levels']; array_unshift($return['user_levels_normal'], ['id' => 0, 'level' => 0, 'name' => MallSetting::getDefaultLevelName($mall_id)]); $return['is_withdraw_repurchase'] = isset(\Yii::$app->params['is_withdraw_repurchase']) ? \Yii::$app->params['is_withdraw_repurchase'] : false; //是否安装了优惠劵插件 $is_installed_coupon = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_COUPON); $return['marketing']['is_install_coupon']['value'] = 0; if ($is_installed_coupon) { $return['marketing']['is_install_coupon']['value'] = 1; } //是否安装了红包插件 $is_installed_redpack = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_REDPACK); $return['marketing']['is_installed_redpack']['value'] = 0; if ($is_installed_redpack) { $return['marketing']['is_installed_redpack']['value'] = 1; } $is_installed_devote = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DEVOTE); if (!MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE)) { $return['cart']['install_o2o'] = 0; } else { $return['cart']['install_o2o'] = 1; } $return['cart_list'] = CartEnum::getMap(); if (empty($data['cart']['cart_name'])) { $return['cart']['cart_name']['value'] = json_encode([1 =>['name' => $return['cart_list'][1], 'is_show' => 0], 2 => ['name' => $return['cart_list'][2], 'is_show' => 0]]); } $currency = [ 'balance' => '余额', 'score' => '积分' ]; if($is_installed_devote) $currency['frozen_devote'] = '贡献值'; $return['currency_list'] = $currency; $return['digital']['install_devote']['value'] = $is_installed_devote ? 1 : 0; if(!MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_REDPACK)) { $return['user_reward_redpacket']['is_open']=0; } else { $return['user_reward_redpacket']['is_open']=1; } if (!empty($return['withdraw_income']['level_withdrwas_reward']['value'])) { $return['withdraw_income']['level_withdrwas_reward']['value'] = json_decode($return['withdraw_income']['level_withdrwas_reward']['value'], true); } if (!empty($return['order']['is_designated_achievement_goods']['value'])) { $goodsIds = json_decode($return['order']['achievement_goods_ids']['value'], true); if (!empty($goodsIds)) { $return['achievementGoodsList'] = Goods::lists(['where' => [['id' => $goodsIds]], 'select' => 'id, cover_pic, goods_name']); } } if($params['type']==SettingEnum::MALL_ORDER){ $sun_single_default = MallSetting::getDefaultSunSingle(); $sun_single = MallSetting::getConfByGroup($mall_id, 'sun_single', true); $sun_single = self::returnArray($sun_single); if(empty($sun_single['type']['value'])){ $sun_single = $sun_single_default; } $return['sun_single'] = $sun_single; $scoreGiveSetting = json_decode($return['marketing']['score_give_setting']['value'],true); if(!isset($scoreGiveSetting['score_giving_goods_type'])){ $scoreGiveSetting['score_giving_goods_type'] = []; } if(!isset($scoreGiveSetting['score_giving_calculation'])){ $scoreGiveSetting['score_giving_calculation'] = 0; } $return['marketing']['score_give_setting']['value'] = json_encode($scoreGiveSetting); } $user_level_all = UserLevel::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['<>' , 'status', StatusEnum::DELETE] ], 'order' => 'level', // 'index' => 'level', ], true); // $user_level_all[0] = ['name' => '普通会员', 'level' => 0]; $return['user_level_all'] = $user_level_all; if (empty($return['withdraw_income']['indep_withdrwas_reward'])){ $return['withdraw_income']['indep_withdrwas_reward'] = ['value' => []]; } else { $return['withdraw_income']['indep_withdrwas_reward']['value'] = json_decode($return['withdraw_income']['indep_withdrwas_reward']['value'], true); } foreach ($return['user_level_all'] as $key => $value) { if (empty($return['withdraw_income']['indep_withdrwas_reward']['value'][$value['level']])) { $return['withdraw_income']['indep_withdrwas_reward']['value'][$value['level']] = [ 'direct_withdraws_reward' => 0, 'indirect_withdraws_reward' => 0 ]; } } $return['order']['goods_deduct_list']['value'] = []; $return['order']['goods_deduct_list']['value'][] = ['name'=> '渠道分红', 'value' => 'agent']; if(MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AGENT_BASE)) { $return['order']['goods_deduct_list']['value'][] = [ 'name'=> '渠道业绩', 'value' => 'agent_base' ]; } $this->success('获取成功', $return); } } } /** * 数组重组 * @param array $params * @return array */ private static function makeUpParams($mallId, array $params) { $data = []; // 重新组合配置 foreach ($params as $group => $value) { foreach ($value as $name => $val) { isset($val['value']) && $data[$group][$name] = is_array($val['value']) ? Json::encode($val['value']) : $val['value']; } } return $data; } /** * 字符串转数组 * @param array $data * @param string $changeText * @return array */ private static function returnArray(array $data, $changeText = 'checkbox') { foreach ($data as $key => $item) { foreach ($item as $k => $value) { $type = $value['type'] ?? ''; if ($type == $changeText) { $data[$key][$k]['value'] = Json::decode($value['value'], true); } // 月份数组 if (in_array($k, ['month', 'repurchase_user_level_limit', 'score_giving_goods_type'])) { !is_array($data[$key][$k]['value']) && $data[$key][$k]['value'] = Json::decode($value['value'], true); } } } return $data; } /** * 打印机设置 * @param int $printer_id 打印机ID */ public function actionPrinterSetting() { $printer_id = \Yii::$app->request->get('printer_id'); $params['where'][] = ['=', 'printer_id', $printer_id]; $params['where'][] = ['=', 'mall_id', $this->mall_id]; $params['where'][] = ['=', 'is_delete', 0]; $params['limit'] = 10; $pageData = Printer::listPage($params, false); array_walk($pageData['list'], function (&$v) { $v['type'] = json_decode($v['type'], true); }); return $this->success('获取成功', $pageData); } public function actionPrinter() { if (\Yii::$app->request->isAjax) { $printer = Yii::$app->services->setting->mall->get($this->mall_id, 'printer.printer'); return $this->success('操作成功', json_decode($printer)); } return $this->render('printer'); } /** * 编辑门店打印机设置 * @param int 是否开启 * @param json type 商户设置 * @param int is_attr 是否使用规格 * @param int store_id 门店ID * @param string name 打印机名字 * @param int printer_id 打印机ID * @author hpei * @return mixed */ public function actionEditPrinterSetting() { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['is_attr', 'status', 'type', 'store_id', 'name', 'printer_id'], 'required'], [['id'], 'safe'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $res = Printer::editSetting($params); if ($res === false) return $this->error(Printer::getStaticError()); return $this->success('保存成功'); } /** * 获取打印机类型 * * @author hpei * @return array */ public function actionGetPrinterType() { $printerType = Printer::PRINTER_TYPE; return $this->success('获取成功', $printerType); } /** * 添加打印机 * * @author hpei * @return mixed */ public function actionEditPrinter() { $params = \Yii::$app->request->post(); try { $printers = MallSetting::getConfByGroup($this->mall_id, 'printer', true); $printers = !empty($printers) && !empty($printers['printer']['value']) ? json_decode($printers['printer']['value'], true) : []; if (isset($params['id']) && !empty($params['id'])) { $printers = array_column($printers, null, 'id'); if (!isset($printers[$params['id']])) throw new \Exception('打印机不存在'); $printer['id'] = $params['id']; } else { $max_id = empty($printers) ? 1 : max(array_column($printers, 'id')) + 1; $printer['id'] = $max_id; } $printer['type'] = $params['type']; $printer['name'] = $params['name']; $printer['brand'] = $params['brand']; unset($params['type'], $params['name'], $params['brand'], $params['print_name'], $params['_csrf']); $printer['printer_config'] = $params; if (isset($params['id']) && !empty($params['id'])) { $printers[$params['id']] = $printer; $printers = array_values($printers); } else { array_push($printers, $printer); } Yii::$app->services->setting->mall->set($this->mall_id, ['printer' => ['printer' => $printers]]); return $this->success('添加成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 删除打印机 * * @author hpei * @return mixed */ public function actionDelePrinter() { $id = \Yii::$app->request->post('id'); try { $printer = Yii::$app->services->setting->mall->get($this->mall_id, 'printer.printer'); if (empty($printer)) return $this->error('打印机不存在'); $printer = json_decode($printer, true); $printer = array_column($printer, null, 'id'); unset($printer[$id]); $printer = array_values($printer); Yii::$app->services->setting->mall->set($this->mall_id, ['printer' => ['printer' => $printer]]); Printer::deleSetting(['printer_id' => $id]); return $this->success('删除成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 修改是否启用,是否使用规格 * */ public function actionChangePrinterSetting() { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['is_attr', 'status'], 'required'], [['id'], 'safe'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $res = Printer::changeSetting($params); if ($res === false) return $this->error(Printer::getStaticError()); return $this->success('修改成功'); } /** * 删除打印机设置 */ public function actionDelePrinterSetting() { $id = \Yii::$app->request->post('id', ''); if (empty($id)) { return $this->error('Id cannot be blank'); } $params['id'] = $id; $res = Printer::deleSetting($params); if ($res === false) return $this->error(Printer::getStaticError()); return $this->success('删除成功'); } //测试短信发送 public function actionSendSms() { try { $params = \Yii::$app->request->post(); if (empty($params['mobile'])) return $this->error('请输入手机号码'); $area_code = ''; // 初始化区号 $gateways = 'domestic'; // 默认国内短信 // 检测是登录并且区号不为空则使用国际短信 if (!empty($this->user) && !empty($this->user->area_code)) { $gateways = 'international'; $area_code = $this->user->area_code; } // 判断是否有区号 if (!empty($params['area_code']) && $params['area_code'] != 86) { $gateways = 'international'; $area_code = $params['area_code']; } $sms = new Sms($this->mall_id, $gateways); switch ($params['type']) { case 1: if ($sms->sendNewUser($params['mobile'], 'test', $area_code) === false) return $this->error('发送失败'); break; case 2: if ($sms->sendOrderOn($params['mobile'], 'sxxxxxxxxxxxxxxxxxxxxxxxx', $area_code) === false) return $this->error('发送失败'); break; case 3: if ($sms->sendRefundOrderOn($params['mobile'], 'rxxxxxxxxxxxxxxxxxxxxxxxx', $area_code) === false) return $this->error('发送失败'); break; case 4: try { if ($sms->sendCaptcha($params['mobile'], $area_code) === false) return $this->error('发送失败'); }catch (\Exception $e){ return $this->error($e->getMessage()); } break; case 5: if ($sms->sendUserLevelExpired($params['mobile'], 'nickname', $area_code) === false) return $this->error('发送失败'); break; default: } return $this->success('发送成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } private function createNoncestr($length = 32) { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; $str = ""; for ($i = 0; $i < $length; $i++) { $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); } return $str; } private function createAuthorization($url, $mch_id, $serial_no, $mch_private_key, $nonce, $http_method = 'GET') { if (!in_array('sha256WithRSAEncryption', openssl_get_md_methods(true))) { throw new \RuntimeException("当前PHP环境不支持SHA256withRSA"); } $url_parts = parse_url($url); $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : "")); //私钥地址 //商户号 $merchant_id = $mch_id; //当前时间戳 $timestamp = time(); //随机字符串 $body = ''; //POST请求时 需要 转JSON字符串 $message = $http_method . "\n" . $canonical_url . "\n" . $timestamp . "\n" . $nonce . "\n" . $body . "\n"; //生成签名 openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption'); $sign = base64_encode($raw_sign); //Authorization 类型 $schema = 'WECHATPAY2-SHA256-RSA2048'; //生成token $token = sprintf('mchid="%s",serial_no="%s",nonce_str="%s",timestamp="%d",signature="%s"', $merchant_id, $serial_no, $nonce, $timestamp, $sign); $header = [ 'Content-Type:application/json', 'Accept:application/json', 'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36', 'Authorization: ' . $schema . ' ' . $token ]; return $header; } private function decryptToString($aesKey, $associatedData, $nonceStr, $ciphertext) { $ciphertext = \base64_decode($ciphertext); if (strlen($ciphertext) <= self::AUTH_TAG_LENGTH_BYTE) { return false; } // ext-sodium (default installed on >= PHP 7.2) if ( function_exists('\sodium_crypto_aead_aes256gcm_is_available') && \sodium_crypto_aead_aes256gcm_is_available() ) { return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey); } // ext-libsodium (need install libsodium-php 1.x via pecl) if ( function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && \Sodium\crypto_aead_aes256gcm_is_available() ) { return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey); } // openssl (PHP >= 7.1 support AEAD) if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) { $ctext = substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE); $authTag = substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE); return \openssl_decrypt( $ctext, 'aes-256-gcm', $aesKey, \OPENSSL_RAW_DATA, $nonceStr, $authTag, $associatedData ); } throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php'); } private function doGet($url, $header) { $curl = curl_init(); // 启动一个CURL会话 curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_HTTPHEADER, $header); $data = curl_exec($curl); return json_decode($data, true); } //生成支付平台证书,用于商家打款到零钱 public function actionCreatePayCredentials() { $url = "https://api.mch.weixin.qq.com/v3/certificates"; $config = \Yii::$app->services->pay->getConfig($this->mall_id, 'wechat'); $nonce = $this->createNoncestr(); $header = $this->createAuthorization($url, $config['wechat_mch_id'], $config['wechat_serial'], $config['wechat_key_pem'], $nonce); //增加平台证书序列号 , 平台证书序列号方法 getcertificates() $header[] = 'Wechatpay-Serial:' . $config['wechat_serial']; $data = $this->doGet($url, $header); if (!empty($data['data'][0]['encrypt_certificate']['ciphertext'])) { $associated_data = $data['data'][0]['encrypt_certificate']['associated_data']; $ciphertext = $data['data'][0]['encrypt_certificate']['ciphertext']; $nonce = $data['data'][0]['encrypt_certificate']['nonce']; $res = $this->decryptToString($config['wechat_pay_secret_v3'], $associated_data, $nonce, $ciphertext); if (!empty($res)) { $dir = dirname(Yii::$app->basePath) . '/backend/runtime/pem/' . $this->mall_id; if (!is_dir($dir)) mkdir($dir, 0755,true); $file_name = $dir . '/wechatpay.pem'; file_put_contents($file_name, $res); return $this->success('操作成功'); } } if (!empty($data['message'])) { return $this->error($data['message']); } return $this->error('操作失败'); } //重置未读消息 public function actionOrderMsg() { // 查询会员订单信息 $user_id = Yii::$app->request->get('user_id', ''); $model = OrderUnreadMsg::findOne(['user_id' => $user_id, 'mall_id' => $this->mall_id]); $model->order_pay_num = 0; $model->order_received_num = 0; $model->order_goods_num = 0; $model->order_evaluate_num = 0; $model->order_return_num = 0; $model->save(); if ($user_id) { $params['mall_id'] = $this->mall_id; $params['user_id'] = $user_id; $data = OrderUnreadMsg::orderStatistic($params); } echo '操作成功'; } public function actionMemory() { return $this->render($this->action->id); } public function actionGetMemory() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->post()) { $setting = \Yii::$app->request->post('setting'); $trans = \Yii::$app->db->beginTransaction(); try { $data = self::makeUpParams($this->mall_id, $setting); $res = Yii::$app->services->setting->mall->set($this->mall_id, $data); if ($res === false) return $this->error(Yii::$app->services->setting->mall->getError()); $trans->commit(); $this->success('操作成功'); } catch (\Exception $e) { $trans->rollBack(); \Yii::error('edit mallSetting error:' . $e->getMessage()); $this->error('编辑失败'); } } else { $params = \Yii::$app->request->get(); // 检查提交的参数 $res = Yii::$app->services->validate->validate($params, [ [['type'], 'required'], [['type'], 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $mall_id = $this->mall_id; $groups = SettingEnum::getMallType($params['type']); $data = MallSetting::getConfByGroup($mall_id, $groups, true); $this->success('操作成功', $data); } } } /** * 获取商城h5链接 * @Author: lun * @DateTime: 2023/6/20 0020 9:16 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionGetMallUrl() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $web_url = Yii::$app->services->setting->platform->get('system.h5_url'); if (empty($web_url)) return $this->error('请设置域名'); $h5_url = $web_url .'/#/?sign=' . $this->mall['mall_sign']; return $this->success('操作成功', $h5_url); } } public function actionGetCurrencyText(){ if (Yii::$app->request->isAjax) { if(Yii::$app->request->isGet){ $params = Yii::$app->request->get(); $currency = $params['currency']; $score_name = \Yii::$app->services->setting->mall->get($this->mall_id, 'score.score_name') ?? '积分'; $digital_name = \Yii::$app->services->setting->mall->get($this->mall_id, 'digital.name') ?? '数字币'; $all_currency = [ 'commission' => '佣金', 'digital' => $digital_name, 'score' => $score_name ]; $data = []; foreach($currency as $v){ if(isset($all_currency[$v])){ $data[$v] = $all_currency[$v]; } } return $this->success('数据请求成功', $data); } } } /** * 获取微信消息模版ID * @return mixed|void|null * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ public function actionGetWechatNotice() { if (Yii::$app->request->isAjax && Yii::$app->request->post()) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['key'], 'required'], [['key'], 'string'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); // 根据key获取对应的微信消息模板ID try { $data = MallSetting::getConfByGroup($this->mall_id, 'notice_wechat', true); $tempid = ''; if(!empty($data['template_message']['value'])){ $notice_wechat_template_message_value = json_decode($data['template_message']['value'],true); if(!empty($notice_wechat_template_message_value[$params['key']]['tempid'])){ $tempid = $notice_wechat_template_message_value[$params['key']]['tempid']; } } $template = new WechatTemplate($this->mall_id); $response = $template->addTemplate($params['key'],$tempid); if ($response['errcode'] != 0) return $this->error('获取失败:' . $response['errmsg']); return $this->success('获取模板成功,记得左下角按钮进行保存哦', $response['template_id']); } catch (\Exception $e) { return $this->error('获取失败:' . $e->getMessage()); } } } public function actionLoadExtraData() { try{ $is_installed_fun_town = (int)MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_FUN_TOWN); $data = compact('is_installed_fun_town'); return $this->success('数据获取成功', $data); }catch(\Exception $e){ return $this->error($e->getMessage()); } } }