isSaas()) { $admin_logo = Option::get('admin_logo', 0, 'saas', ''); $admin_copyright = Option::get('admin_copyright', 0, 'saas', ''); $admin_name = Option::get('name', 0, 'saas', ''); $help_logo = Option::get('help_logo', 0, 'saas', ''); $describe = Option::get('describe', 0, 'saas', ''); } else { $store_id = get_store_id(); $admin_logo = Option::get('web_log', $store_id, 'web', ''); $admin_copyright = Option::get('copyright', $store_id, 'web', ''); $admin_name = Option::get('web_name', $store_id, 'web', ''); $help_logo = Option::get('help_logo', $store_id, 'web', ''); $describe = Option::get('describe', $store_id, 'web', ''); $passport_bg = Option::get('passport_bg', $store_id, 'web', ''); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'admin_logo' => $admin_logo['value'], 'admin_copyright' => $admin_copyright['value'], 'admin_name' => $admin_name['value'], 'help_logo' => $help_logo['value'], 'describe' => $describe['value'], 'passport_bg' => $passport_bg['value'] ?? null ], ]); } public function actionSetPlatformAppParams() { try { if (\Yii::$app->request->isPost) { $key = [ 'platform_app_store_android', 'platform_app_store_android_version', 'platform_app_store_ios', 'platform_app_logo', 'platform_app_bg', ]; $params = post_params(); $value = [ $params['platform_app_store_android'], $params['platform_app_store_android_version'], $params['platform_app_store_ios'], $params['platform_app_logo'], $params['platform_app_bg'], ]; Option::set($key, $value, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '' ]); } else { $keys = [ 'platform_app_store_android', 'platform_app_store_android_version', 'platform_app_store_ios', 'platform_app_logo', 'platform_app_bg', ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'platform_app_store_android' => '', 'platform_app_store_android_version' => '', 'platform_app_store_ios' => '', 'platform_app_logo' => '', 'platform_app_bg' => '', ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } public function actionOneStoreWechatSetting() { if (Yii::$app->request->getIsPost()) { $appid = post_params('one_store_wechat_appid', ''); $secret = post_params('one_store_wechat_secret', ''); $is_shenhe = post_params('one_store_is_shenhe', false); $switch_store = post_params('one_store_switch_store', false); $default_store = post_params('one_store_default_store', 0); $show_apply = post_params('one_store_hide_apply', 0); $one_store_lock_store = post_params('one_store_lock_store', 0); $mch_id = post_params('one_store_mch_id', ''); $pay_key = post_params('one_store_pay_key', ''); $apiclient_cert = post_params('one_store_apiclient_cert', ''); $apiclient_key = post_params('one_store_apiclient_key', ''); $apiclient_cert_url = post_params('one_store_apiclient_cert_url', ''); $apiclient_key_url = post_params('one_store_apiclient_key_url', ''); if (!empty($apiclient_cert_url)) { $apiclient_cert = file_get_contents($apiclient_cert_url); } else { if (!empty($apiclient_cert)) { $apiclient_cert_url = WechatConfigForm::handlePemFile($apiclient_cert); } } if (!empty($apiclient_key_url)) { $apiclient_key = file_get_contents($apiclient_key_url); } else { if (!empty($apiclient_key)) { $apiclient_key_url = WechatConfigForm::handlePemFile($apiclient_key); } } $app_appid = post_params('one_store_app_wechat_appid', ''); $app_secret = post_params('one_store_app_wechat_secret', ''); $app_mch_id = post_params('one_store_app_mch_id', ''); $app_pay_key = post_params('one_store_app_pay_key', ''); $app_apiclient_cert = post_params('one_store_app_apiclient_cert', ''); $app_apiclient_key = post_params('one_store_app_apiclient_key', ''); $app_apiclient_cert_url = post_params('one_store_app_apiclient_cert_url', ''); $app_apiclient_key_url = post_params('one_store_app_apiclient_key_url', ''); if (!empty($app_apiclient_cert_url)) { $app_apiclient_cert = file_get_contents($app_apiclient_cert_url); } else { if (!empty($app_apiclient_cert)) { $app_apiclient_cert_url = WechatConfigForm::handlePemFile($app_apiclient_cert); } } if (!empty($app_apiclient_key_url)) { $app_apiclient_key = file_get_contents($app_apiclient_key_url); } else { if (!empty($app_apiclient_key)) { $app_apiclient_key_url = WechatConfigForm::handlePemFile($app_apiclient_key); } } $one_store_app_android = post_params('one_store_app_android', '');//app下载地址 android版本 $one_store_app_android_version = post_params('one_store_app_android_version', '');//安卓app版本 $one_store_app_ios = post_params('one_store_app_ios', '');//app包下载地址 ios版本 $one_store_wechat_h5_sub_mch_id = post_params('one_store_wechat_h5_sub_mch_id', ''); $one_store_wechat_official_appid = post_params('one_store_wechat_official_appid', ''); $one_store_wechat_official_secret = post_params('one_store_wechat_official_secret', ''); $one_store_wechat_official_token = post_params('one_store_wechat_official_token', ''); $one_store_wechat_official_auto_reply = post_params('one_store_wechat_official_auto_reply', ''); $one_store_official_pay_key = post_params('one_store_official_pay_key', ''); $one_store_official_apiclient_cert_url = post_params('one_store_official_apiclient_cert_url', ''); $one_store_official_apiclient_key_url = post_params('one_store_official_apiclient_key_url', ''); $one_store_official_apiclient_cert = post_params('one_store_official_apiclient_cert', ''); $one_store_official_apiclient_key = post_params('one_store_official_apiclient_key', ''); $one_store_wechat_official_sub_mch_id = post_params('one_store_wechat_official_sub_mch_id', ''); if (!empty($one_store_official_apiclient_cert_url)) { $one_store_official_apiclient_cert = file_get_contents($one_store_official_apiclient_cert_url); } else { if (!empty($one_store_official_apiclient_cert)) { $one_store_official_apiclient_cert_url = WechatConfigForm::handlePemFile($one_store_official_apiclient_cert); } } if (!empty($one_store_official_apiclient_key_url)) { $one_store_official_apiclient_key = file_get_contents($one_store_official_apiclient_key_url); } else { if (!empty($one_store_official_apiclient_key)) { $one_store_official_apiclient_key_url = WechatConfigForm::handlePemFile($one_store_official_apiclient_key); } } //供应链App包上传以及版本管理 $alipay = post_params('alipay'); Option::set('one_store_alipay_config', json_encode($alipay), 0, 'saas'); Option::set('one_store_wechat_appid', $appid, 0, 'saas'); Option::set('one_store_wechat_secret', $secret, 0, 'saas'); Option::set('one_store_is_shenhe', $is_shenhe ? 1 : 0, 0, 'saas'); Option::set('one_store_switch_store', $switch_store ? 1 : 0, 0, 'saas'); Option::set('one_store_default_store', $default_store, 0, 'saas'); Option::set('one_store_mch_id', $mch_id, 0, 'saas'); Option::set('one_store_pay_key', $pay_key, 0, 'saas'); Option::set('one_store_apiclient_cert', $apiclient_cert, 0, 'saas'); Option::set('one_store_apiclient_key', $apiclient_key, 0, 'saas'); Option::set('one_store_apiclient_cert_url', $apiclient_cert_url, 0, 'saas'); Option::set('one_store_apiclient_key_url', $apiclient_key_url, 0, 'saas'); Option::set('one_store_hide_apply', $show_apply, 0, 'saas'); Option::set('one_store_lock_store', $one_store_lock_store, 0, 'saas'); //app配置 Option::set('one_store_app_wechat_appid', $app_appid, 0, 'saas'); Option::set('one_store_app_wechat_secret', $app_secret, 0, 'saas'); Option::set('one_store_app_mch_id', $app_mch_id, 0, 'saas'); Option::set('one_store_app_pay_key', $app_pay_key, 0, 'saas'); Option::set('one_store_app_apiclient_cert', $app_apiclient_cert, 0, 'saas'); Option::set('one_store_app_apiclient_key', $app_apiclient_key, 0, 'saas'); Option::set('one_store_app_apiclient_cert_url', $app_apiclient_cert_url, 0, 'saas'); Option::set('one_store_app_apiclient_key_url', $app_apiclient_key_url, 0, 'saas'); Option::set('one_store_app_android', $one_store_app_android, 0, 'saas'); Option::set('one_store_app_android_version', $one_store_app_android_version, 0, 'saas'); Option::set('one_store_app_ios', $one_store_app_ios, 0, 'saas'); Option::set('one_store_wechat_h5_sub_mch_id', $one_store_wechat_h5_sub_mch_id, 0, 'saas'); //供应链 Option::set('one_store_wechat_official_appid', $one_store_wechat_official_appid, 0, 'saas'); Option::set('one_store_wechat_official_secret', $one_store_wechat_official_secret, 0, 'saas'); Option::set('one_store_wechat_official_token', $one_store_wechat_official_token, 0, 'saas'); Option::set('one_store_wechat_official_auto_reply', $one_store_wechat_official_auto_reply, 0, 'saas'); Option::set('one_store_official_pay_key', $one_store_official_pay_key, 0, 'saas'); Option::set('one_store_official_apiclient_cert_url', $one_store_official_apiclient_cert_url, 0, 'saas'); Option::set('one_store_official_apiclient_key_url', $one_store_official_apiclient_key_url, 0, 'saas'); Option::set('one_store_official_apiclient_cert', $one_store_official_apiclient_cert, 0, 'saas'); Option::set('one_store_official_apiclient_key', $one_store_official_apiclient_key, 0, 'saas'); Option::set('one_store_wechat_official_sub_mch_id', $one_store_wechat_official_sub_mch_id, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $appid = Option::get('one_store_wechat_appid', 0, 'saas', ''); $secret = Option::get('one_store_wechat_secret', 0, 'saas', ''); $is_shenhe = Option::get('one_store_is_shenhe', 0, 'saas', 0); $switch_store = Option::get('one_store_switch_store', 0, 'saas', 0); $default_store = Option::get('one_store_default_store', 0, 'saas', 1)['value']; $mch_id = Option::get('one_store_mch_id', 0, 'saas', ''); $pay_key = Option::get('one_store_pay_key', 0, 'saas', ''); $apiclient_cert = Option::get('one_store_apiclient_cert', 0, 'saas', ''); $apiclient_key = Option::get('one_store_apiclient_key', 0, 'saas', ''); $apiclient_cert_url = Option::get('one_store_apiclient_cert_url', 0, 'saas', '')['value']; $apiclient_key_url= Option::get('one_store_apiclient_key_url', 0, 'saas', '')['value']; if (empty($apiclient_cert_url) && !empty($apiclient_cert['value'])) { $apiclient_cert_url = WechatConfigForm::handlePemFile($apiclient_cert['value']); } if (empty($apiclient_key_url) && !empty($apiclient_key['value'])) { $apiclient_key_url = WechatConfigForm::handlePemFile($apiclient_key['value']); } $alipay = Option::get('one_store_alipay_config', 0, 'saas', '')['value']; $show_apply = Option::get('one_store_hide_apply', 0, 'saas', '0'); $one_store_lock_store = Option::get('one_store_lock_store', 0, 'saas', '0'); $app_appid = Option::get('one_store_app_wechat_appid', 0, 'saas', ''); $app_secret = Option::get('one_store_app_wechat_secret', 0, 'saas', ''); $app_mch_id = Option::get('one_store_app_mch_id', 0, 'saas', ''); $app_pay_key = Option::get('one_store_app_pay_key', 0, 'saas', ''); $app_apiclient_cert = Option::get('one_store_app_apiclient_cert', 0, 'saas', ''); $app_apiclient_key = Option::get('one_store_app_apiclient_key', 0, 'saas', ''); $app_apiclient_cert_url = Option::get('one_store_app_apiclient_cert_url', 0, 'saas', '')['value']; $app_apiclient_key_url = Option::get('one_store_app_apiclient_key_url', 0, 'saas', '')['value']; if (empty($app_apiclient_cert_url) && !empty($app_apiclient_cert['value'])) { $app_apiclient_cert_url = WechatConfigForm::handlePemFile($app_apiclient_cert['value']); } if (empty($app_apiclient_key_url) && !empty($app_apiclient_key['value'])) { $app_apiclient_key_url = WechatConfigForm::handlePemFile($app_apiclient_key['value']); } $one_store_app_android = Option::get('one_store_app_android', 0, 'saas', ''); $one_store_app_android_version = Option::get('one_store_app_android_version', 0, 'saas', ''); $one_store_app_ios = Option::get('one_store_app_ios', 0, 'saas', ''); $one_store_wechat_h5_sub_mch_id = Option::get('one_store_wechat_h5_sub_mch_id', 0, 'saas', ''); $one_store_wechat_official_appid = Option::get('one_store_wechat_official_appid', 0, 'saas', ''); $one_store_wechat_official_secret = Option::get('one_store_wechat_official_secret', 0, 'saas', ''); $one_store_wechat_official_token = Option::get('one_store_wechat_official_token', 0, 'saas', ''); $one_store_wechat_official_auto_reply = Option::get('one_store_wechat_official_auto_reply', 0, 'saas', ''); //供应链公众号设置需要显示服务器地址以及支付目录 $one_store_official_server_url = 'https://' . \Yii::$app->request->hostName . '/index.php?r=common/wechat-callback/index&store_id=0'; $one_store_official_pay_url = 'https://' . \Yii::$app->request->hostName . '/'; $one_store_official_pay_key = Option::get('one_store_official_pay_key', 0, 'saas', ''); $one_store_official_apiclient_cert_url = Option::get('one_store_official_apiclient_cert_url', 0, 'saas', ''); $one_store_official_apiclient_key_url = Option::get('one_store_official_apiclient_key_url', 0, 'saas', ''); $one_store_official_apiclient_cert = Option::get('one_store_official_apiclient_cert', 0, 'saas', ''); $one_store_official_apiclient_key = Option::get('one_store_official_apiclient_key', 0, 'saas', ''); $one_store_wechat_official_sub_mch_id = Option::get('one_store_wechat_official_sub_mch_id', 0, 'saas', ''); if (empty($alipay)) { $alipay = [ 'aes_key' => '', 'alipay_public_key' => '', 'app_id' => '', 'app_private_key' => '', 'app_public_key' => '', 'name' => '', 'user_id' => '', 'one_store_is_shenhe' => false, 'one_store_lock_store' => 0 ]; } else { $alipay = json_decode($alipay, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'one_store_wechat_appid' => $appid['value'], 'one_store_wechat_secret' => $secret['value'], 'one_store_is_shenhe' => (bool)$is_shenhe['value'], 'one_store_switch_store' => (bool)$switch_store['value'], 'one_store_default_store' => $default_store ?: '1', 'one_store_mch_id' => $mch_id['value'], 'one_store_pay_key' => $pay_key['value'], 'one_store_apiclient_cert' => $apiclient_cert['value'], 'one_store_apiclient_key' => $apiclient_key['value'], 'one_store_apiclient_cert_url' => $apiclient_cert_url, 'one_store_apiclient_key_url' => $apiclient_key_url, 'alipay' => $alipay, 'one_store_hide_apply' => (string)$show_apply['value'], 'one_store_lock_store' => (int)$one_store_lock_store['value'], 'one_store_app_wechat_appid' => $app_appid['value'], 'one_store_app_wechat_secret' => $app_secret['value'], 'one_store_app_mch_id' => $app_mch_id['value'], 'one_store_app_pay_key' => $app_pay_key['value'], 'one_store_app_apiclient_cert' => $app_apiclient_cert['value'], 'one_store_app_apiclient_key' => $app_apiclient_key['value'], 'one_store_app_apiclient_cert_url' => $app_apiclient_cert_url, 'one_store_app_apiclient_key_url' => $app_apiclient_key_url, 'one_store_app_android' => $one_store_app_android['value'], 'one_store_app_android_version' => $one_store_app_android_version['value'], 'one_store_app_ios' => $one_store_app_ios['value'], 'one_store_wechat_h5_sub_mch_id' => $one_store_wechat_h5_sub_mch_id['value'], 'one_store_wechat_official_appid' => $one_store_wechat_official_appid['value'], 'one_store_wechat_official_secret' => $one_store_wechat_official_secret['value'], 'one_store_wechat_official_token' => $one_store_wechat_official_token['value'], 'one_store_wechat_official_auto_reply' => $one_store_wechat_official_auto_reply['value'], 'one_store_official_server_url' => $one_store_official_server_url, 'one_store_official_pay_url' => $one_store_official_pay_url, 'one_store_official_pay_key' => $one_store_official_pay_key['value'], 'one_store_official_apiclient_cert_url' => $one_store_official_apiclient_cert_url['value'], 'one_store_official_apiclient_key_url' => $one_store_official_apiclient_key_url['value'], 'one_store_official_apiclient_cert' => $one_store_official_apiclient_cert['value'], 'one_store_official_apiclient_key' => $one_store_official_apiclient_key['value'], 'one_store_wechat_official_sub_mch_id' => $one_store_wechat_official_sub_mch_id['value'], ], ]); } /** * 设置联盟入驻协议 * */ public function actionUnionProtocol() { if (Yii::$app->request->getIsPost()) { $protocol = post_params('protocol', ''); $is_debug = post_params('is_debug', 0); $describe = post_params('describe', ''); $name = post_params('name', ''); $logo = post_params('logo', ''); $help_logo = post_params('help_logo', ''); $union_client_loading_logo = post_params('union_client_loading_logo', ''); $admin_logo = post_params('admin_logo', ''); $admin_copyright = post_params('admin_copyright', ''); $search_keyword = post_params('search_keyword', []); $lang = post_params('lang', 'zh-CN'); $shenhe = post_params('shenhe', 0); $is_show_kefu_download = post_params('is_show_kefu_download', 1); // $tencent_map_key = post_params('tencent_map_key', ''); Option::set('is_debug', $is_debug, 0, 'saas'); Option::set('protocol', $protocol, 0, 'saas'); Option::set('store_apply_agreement', $protocol, 0, 'saas'); Option::set('describe', $describe, 0, 'saas'); Option::set('name', $name, 0, 'saas'); Option::set('logo', $logo, 0, 'saas'); Option::set('help_logo', $help_logo, 0, 'saas'); Option::set('union_client_loading_logo', $union_client_loading_logo, 0, 'saas'); Option::set('admin_copyright', $admin_copyright, 0, 'saas'); Option::set('admin_logo', $admin_logo, 0, 'saas'); Option::set('lang', $lang, 0, 'saas'); Option::set('lang', $lang, 0, 'saas'); Option::set('search_keyword', json_encode($search_keyword), 0, 'saas'); Option::set('shenhe', $shenhe, 0, 'saas'); Option::set('is_show_kefu_download', $is_show_kefu_download, 0, 'saas'); // Option::set('tencent_map_key', $tencent_map_key, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $is_debug = Option::get('is_debug', 0, 'saas', ''); $protocol = Option::get('protocol', 0, 'saas', ''); $describe = Option::get('describe', 0, 'saas', ''); $name = Option::get('name', 0, 'saas', ''); $logo = Option::get('logo', 0, 'saas', ''); $help_logo = Option::get('help_logo', 0, 'saas', ''); $union_client_loading_logo = Option::get('union_client_loading_logo', 0, 'saas', ''); $admin_logo = Option::get('admin_logo', 0, 'saas', ''); $admin_copyright = Option::get('admin_copyright', 0, 'saas', ''); $lang = Option::get('lang', 0, 'saas', 'zh-CN'); $search_keyword = Option::get('search_keyword', 0, 'saas', json_encode([])); $shenhe = Option::get('shenhe', 0, 'saas', 0); $is_show_kefu_download = Option::get('is_show_kefu_download', 0, 'saas', 1); // $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', ''); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'is_debug'=>$is_debug['value'], 'protocol' => $protocol['value'], 'describe' => $describe['value'], 'name' => $name['value'], 'logo' => $logo['value'], 'help_logo' => $help_logo['value'], 'union_client_loading_logo' => $union_client_loading_logo['value'], 'admin_logo' => $admin_logo['value'], 'admin_copyright' => $admin_copyright['value'], 'lang' => $lang['value'], 'shenhe' => (int)$shenhe['value'], 'search_keyword' => json_decode($search_keyword['value']), 'is_show_kefu_download' => intval($is_show_kefu_download['value']) // 'tencent_map_key' => $tencent_map_key['value'] ] ]); } } public function actionUnionProtocolStore() { if(\Yii::$app->isSaas()){ // return; } if (Yii::$app->request->getIsPost()) { $describe = post_params('describe', ''); $help_logo = post_params('help_logo', ''); Option::set('describe', $describe, 0, 'saas'); Option::set('help_logo', $help_logo, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $describe = Option::get('describe', 0, 'saas', ''); $help_logo = Option::get('help_logo', 0, 'saas', ''); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'describe' => $describe['value'], 'help_logo' => $help_logo['value'], ] ]); } } public function actionSaasMapSetting() { $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', ''); if (Yii::$app->request->getIsPost()) { $tencent_map_key = post_params('tencent_map_key', ''); $amap_key = post_params('amap_key', ''); $amap_security_js_code = post_params('amap_security_js_code', ''); $amap_service_host = post_params('amap_service_host', ''); Option::set('tencent_map_key', $tencent_map_key, 0, 'saas'); Option::set('amap_key', $amap_key, 0, 'saas'); Option::set('amap_security_js_code', $amap_security_js_code, 0, 'saas'); Option::set('amap_service_host', $amap_service_host, 0, 'saas'); // 更新h5的腾讯地图key \app\utils\UpdateAfter::UpdateQQMapKey($tencent_map_key); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $amap_key = Option::get('amap_key', 0, 'saas', ''); $amap_security_js_code = Option::get('amap_security_js_code', 0, 'saas', ''); $amap_service_host = Option::get('amap_service_host', 0, 'saas', ''); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'tencent_map_key' => $tencent_map_key['value'], 'amap_key' => $amap_key['value'], 'amap_security_js_code' => $amap_security_js_code['value'], 'amap_service_host' => $amap_service_host['value'], ] ]); } } /** * 设置银行卡信息(服务商) * * @return void */ public function actionBankSetting() { if (Yii::$app->request->getIsPost()) { $conf = post_params('conf', []); $set = SaasForm::bankSettingSave(1, 0, $conf); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', 'set' => $set, ]); } else { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => SaasForm::bankSetting(1), 'store_id' => get_store_id(), ]); } } /** * 设置通联配置信息(服务商) * * @return void */ public function actionYunstSetting() { if (Yii::$app->request->getIsPost()) { $conf = post_params('content', []); $set = SaasForm::yunstSettingSave(1, 0, $conf); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', 'set' => $set, ]); } else { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => SaasForm::yunstSetting(1), 'store_id' => get_store_id(), ]); } } /** * 设置银行卡信息(店铺) * * @return void */ public function actionStoreBankSetting() { $store_id = get_store_id(); if (Yii::$app->request->getIsPost()) { $conf = post_params('conf', []); $set = SaasForm::bankSettingSave(0, $store_id, $conf); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', 'set' => $set, ]); } else { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => SaasForm::bankSetting(0, $store_id), 'store_id' => get_store_id(), ]); } } /** * 设置线下转账信息(店铺) * * @return void */ public function actionOfflineSetting() { $store_id = get_store_id(); if (Yii::$app->request->getIsPost()) { $conf = post_params('conf', []); $set = SaasForm::offlineSettingSave($store_id, $conf); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', 'set' => $set, ]); } else { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => ['conf' => SaasForm::offlineSetting($store_id)], 'store_id' => get_store_id(), ]); } } /** * 设置微信支付信息(服务商) * * @return void */ public function actionWechatSetting() { if (Yii::$app->request->getIsPost()) { $sp_name = post_params('sp_name', ''); $sp_appid = post_params('sp_appid', ''); $sp_mch_id = post_params('sp_mch_id', ''); $sp_key = post_params('sp_key', ''); $sp_apiclient_cert = post_params('sp_apiclient_cert', ''); $sp_apiclient_key = post_params('sp_apiclient_key', ''); $sp_apiclient_cert_url = post_params('sp_apiclient_cert_url', ''); $sp_apiclient_key_url = post_params('sp_apiclient_key_url', ''); if (!empty($sp_apiclient_cert_url)) { $sp_apiclient_cert = file_get_contents($sp_apiclient_cert_url); } else { if (!empty($sp_apiclient_cert)) { $sp_apiclient_cert_url = WechatConfigForm::handlePemFile($sp_apiclient_cert); } } if (!empty($sp_apiclient_key_url)) { $sp_apiclient_key = file_get_contents($sp_apiclient_key_url); } else { if (!empty($sp_apiclient_key)) { $sp_apiclient_key_url = WechatConfigForm::handlePemFile($sp_apiclient_key); } } $platform_public_key = post_params('platform_public_key', ''); $platform_public_key_id = post_params('platform_public_key_id', ''); $platform_api_key = post_params('platform_api_key', ''); $platform_serial_no = post_params('platform_serial_no', ''); $pay_rate = post_params('pay_rate', '0.2'); $pay_rate = sprintf('%.2f', $pay_rate); //保留两位 //$pay_rate < 0.2 || if ($pay_rate < 0 || $pay_rate > 0.6) { return $this->asJson([ 'code' => 1, 'msg' => '默认支付费率应在0 ~ 0.6区间', ]); } Option::set([ 'sp_name', 'sp_appid', 'sp_mch_id', 'sp_key', 'sp_apiclient_cert', 'sp_apiclient_key', 'sp_apiclient_cert_url', 'sp_apiclient_key_url', 'platform_public_key', 'platform_public_key_id', 'platform_api_key', 'platform_serial_no', 'pay_rate' ], [ $sp_name, $sp_appid, $sp_mch_id, $sp_key, $sp_apiclient_cert, $sp_apiclient_key, $sp_apiclient_cert_url, $sp_apiclient_key_url, $platform_public_key, $platform_public_key_id, $platform_api_key, $platform_serial_no, $pay_rate ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'sp_name', 'sp_appid', 'sp_mch_id', 'sp_key', 'sp_apiclient_cert', 'sp_apiclient_key', 'sp_apiclient_cert_url', 'sp_apiclient_key_url', 'platform_public_key', 'platform_public_key_id', 'platform_api_key', 'platform_serial_no', 'pay_rate' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'sp_name' => '', 'sp_appid' => '', 'sp_mch_id' => '', 'sp_key' => '', 'sp_apiclient_cert' => '', 'sp_apiclient_key' => '', 'sp_apiclient_cert_url' => '', 'sp_apiclient_key_url' => '', 'platform_public_key'=>"", 'platform_public_key_id'=>"", 'platform_api_key'=>"", 'platform_serial_no'=>"", 'pay_rate' => '0.2' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } if (empty($arr['sp_apiclient_cert_url']) && !empty($arr['sp_apiclient_cert'])) { $arr['sp_apiclient_cert_url'] = WechatConfigForm::handlePemFile($arr['sp_apiclient_cert']); } if (empty($arr['sp_apiclient_key_url']) && !empty($arr['sp_apiclient_key'])) { $arr['sp_apiclient_key_url'] = WechatConfigForm::handlePemFile($arr['sp_apiclient_key']); } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置地址识别配置 * * @return void */ public function actionAddressRecognitionSetting() { if (Yii::$app->request->getIsPost()) { $kuaidi100_secret_key = post_params(OptionSetting::KUAIDI100_SECRET_KEY, ''); $kuaidi100_secret_code = post_params(OptionSetting::KUAIDI100_SECRET_CODE, ''); $kuaidi100_secret_secret = post_params(OptionSetting::KUAIDI100_SECRET_SECRET, ''); $kuaidi100_secret_sign = post_params(OptionSetting::KUAIDI100_SECRET_SIGN, ''); Option::set([ OptionSetting::KUAIDI100_SECRET_KEY, OptionSetting::KUAIDI100_SECRET_CODE, OptionSetting::KUAIDI100_SECRET_SECRET, OptionSetting::KUAIDI100_SECRET_SIGN ], [ $kuaidi100_secret_key, $kuaidi100_secret_code, $kuaidi100_secret_secret, $kuaidi100_secret_sign, ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ OptionSetting::KUAIDI100_SECRET_KEY, OptionSetting::KUAIDI100_SECRET_CODE, OptionSetting::KUAIDI100_SECRET_SECRET, OptionSetting::KUAIDI100_SECRET_SIGN, ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ OptionSetting::KUAIDI100_SECRET_KEY => '', OptionSetting::KUAIDI100_SECRET_CODE => '', OptionSetting::KUAIDI100_SECRET_SECRET => '', OptionSetting::KUAIDI100_SECRET_SIGN => '', ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 店铺缴费设置 * * @return void */ public function actionStoreReOrder() { if (Yii::$app->request->getIsPost()) { $open_price = post_params('open_price', '0.00'); $profit = post_params('profit', '0.00'); $renew_price = post_params('renew_price', '0.00'); Option::set([ 'open_price', 'profit', 'renew_price' ], [ $open_price, $profit, $renew_price, ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'open_price', 'profit', 'renew_price' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'open_price' => '0.00', 'profit' => '0.00', 'renew_price' => '0.00' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 店铺让利比例设置 * * @return void */ public function actionStoreTransferProfitParams() { if (Yii::$app->request->getIsPost()) { $transfer_profit = post_params('transfer_profit', '0.00'); Option::set([ 'transfer_profit' ], [ $transfer_profit ], -1, OptionSetting::SHARE_GROUP_NAME); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $data = Option::get('transfer_profit', -1, OptionSetting::SHARE_GROUP_NAME)['value']; if (empty($data)) { $data = '0.00'; } else { $data = json_decode($data, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 店铺分销默认设置 * * @return void */ public function actionStoreDefaultParams() { $data = Option::get(OptionSetting::SHARE_STORE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value']; if (empty($data)) { $data = [ 'store_share_switch' => '0', 'store_share_type' => '0', 'store_share_value' => '0' ]; } else { $data = json_decode($data, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } public function actionGetProfitSetting() { // $store_recharge_profit_model = Option::findOne(['name' => 'store_recharge_profit']); $store_profit_max_model = Option::findOne(['name' => 'store_profit_max']); $store_profit_min_model = Option::findOne(['name' => 'store_profit_min']); $store_send_min_model = Option::findOne(['name' => 'store_send_min']); // $store_send_profit_model = Option::findOne(['name' => 'store_send_profit']); $data = [ // 'store_recharge_profit' => $store_recharge_profit_model->value, 'store_profit_max' => $store_profit_max_model->value, 'store_profit_min' => $store_profit_min_model->value, 'store_send_min' => $store_send_min_model->value, 'store_send_profit' => 100, ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } /** * 联盟分销默认设置 * * @return void */ public function actionSaasDefaultParams() { $data = Option::get(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value']; if (empty($data)) { $data = [ 'is_rebate' => 0, 'level' => 1, 'level_one' => "0.00", 'level_three' => "0.00", 'level_two' => "0.00", 'price_type' => 0 ]; } else { $data = json_decode($data, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } /** * 店铺推荐人分销默认设置 * * @return void */ public function actionSaasReferralDefaultParams() { $data = Option::get(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value']; if (empty($data)) { $data = [ 'is_enable' => '0', 'referral_rebate' => '0' ]; } else { $data = json_decode($data, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } /** * 供货商推荐人分销默认设置 * * @return void */ public function actionSaasSupplierReferralDefaultParams() { $data = Option::get(OptionSetting::SHARE_SAAS_SUPPLIER_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value']; if (empty($data)) { $data = [ 'is_enable' => '0', 'referral_rebate' => '0' ]; } else { $data = json_decode($data, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } /** * 消费返利分销默认设置 * * @return void */ public function actionSelfRebateDefaultParams() { $data = Option::get(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME)['value']; if (empty($data)) { $data = [ 'self_rebate_switch' => '0', 'self_rebate_value' => '0' ]; } else { $data = json_decode($data, true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } /** * 设置支付宝商盟小程序客户端 * */ public function actionAlipayPlatformSetting() { if (Yii::$app->request->getIsPost()) { $info = post_params(); $info = json_encode($info); Option::set([ 'alipay_platform', ], [ $info ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); }else{ $keys = [ 'alipay_platform' ]; $data = Option::get($keys, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => isset($data[0]) ? json_decode($data[0]['value'],true) : NULL ]); } } /** * 设置支付宝服务商 * */ public function actionAlipaySetting() { if (Yii::$app->request->getIsPost()) { $alipay_appid = post_params('alipay_appid', ''); $alipay_public_key = post_params('alipay_public_key', ''); $alipay_app_public_key = post_params('alipay_app_public_key', ''); $alipay_app_private_key = post_params('alipay_app_private_key', ''); $alipay_user_id = post_params('alipay_user_id', ''); $alipay_aes_key = post_params('alipay_aes_key', ''); $name = post_params('alipay_name', ''); if (empty($alipay_user_id) || empty($name)) { return $this->asJson([ 'code' => 1, 'msg' => '务必完善企业名称和USER_ID' ]); } Option::set([ 'alipay_appid', 'alipay_public_key', 'alipay_app_public_key', 'alipay_app_private_key', 'alipay_user_id', 'alipay_name', 'alipay_aes_key' ], [ $alipay_appid, $alipay_public_key, $alipay_app_public_key, $alipay_app_private_key, $alipay_user_id, $name, $alipay_aes_key ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'alipay_appid', 'alipay_public_key', 'alipay_app_public_key', 'alipay_app_private_key', 'alipay_user_id', 'alipay_name', 'alipay_aes_key' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'alipay_appid' => '', 'alipay_public_key' => '', 'alipay_app_public_key' => '', 'alipay_app_private_key' => '', 'alipay_user_id' => '', 'alipay_name' => '', 'alipay_aes_key'=>'' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置微信支付信息(用于提现) * * @return void */ public function actionWechatPlatformSetting() { if (Yii::$app->request->getIsPost()) { $platform_app_appid = post_params('platform_app_appid', ''); $platform_appid = post_params('platform_appid', ''); $platform_mch_id = post_params('platform_mch_id', ''); $platform_key = post_params('platform_key', ''); $platform_apiclient_cert = post_params('platform_apiclient_cert', ''); $platform_apiclient_key = post_params('platform_apiclient_key', ''); $platform_apiclient_cert_url = post_params('platform_apiclient_cert_url', ''); $platform_apiclient_key_url = post_params('platform_apiclient_key_url', ''); $platform_pay_key = post_params('platform_pay_key', ''); $platform_gh_id = post_params('platform_gh_id', ''); if (!empty($platform_apiclient_cert_url)) { $platform_apiclient_cert = file_get_contents($platform_apiclient_cert_url); } else { if (!empty($platform_apiclient_cert)) { $platform_apiclient_cert_url = WechatConfigForm::handlePemFile($platform_apiclient_cert); } } if (!empty($platform_apiclient_key_url)) { $platform_apiclient_key = file_get_contents($platform_apiclient_key_url); } else { if (!empty($platform_apiclient_key)) { $platform_apiclient_key_url = WechatConfigForm::handlePemFile($platform_apiclient_key); } } Option::set([ 'platform_appid', 'platform_mch_id', 'platform_key', 'platform_apiclient_cert', 'platform_apiclient_key', 'platform_apiclient_cert_url', 'platform_apiclient_key_url', 'platform_pay_key', 'platform_app_appid', 'platform_gh_id' ], [ $platform_appid, $platform_mch_id, $platform_key, $platform_apiclient_cert, $platform_apiclient_key, $platform_apiclient_cert_url, $platform_apiclient_key_url, $platform_pay_key, $platform_app_appid, $platform_gh_id ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'platform_appid', 'platform_mch_id', 'platform_key', 'platform_apiclient_cert', 'platform_apiclient_key', 'platform_apiclient_cert_url', 'platform_apiclient_key_url', 'platform_pay_key', 'platform_app_appid', 'platform_gh_id' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'platform_appid' => '', 'platform_mch_id' => '', 'platform_key' => ' ', 'platform_apiclient_cert' => '', 'platform_apiclient_key' => '', 'platform_apiclient_cert_url' => '', 'platform_apiclient_key_url' => '', 'platform_pay_key' => '', 'platform_app_appid' => '', 'platform_gh_id' => '' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } if (empty($arr['platform_apiclient_cert_url']) && !empty($arr['platform_apiclient_cert'])) { $arr['platform_apiclient_cert_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_cert']); } if (empty($arr['platform_apiclient_key_url']) && !empty($arr['platform_apiclient_key'])) { $arr['platform_apiclient_key_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_key']); } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置商家小程序配置 * * @return void */ public function actionWechatPlatformMchSetting() { if (Yii::$app->request->getIsPost()) { $platform_mch_is_shenhe = post_params('platform_mch_is_shenhe', false); $platform_mch_appid = post_params('platform_mch_appid', ''); $platform_mch_key = post_params('platform_mch_key', ''); $platform_mch_id = post_params('platform_mch_id', ''); $platform_apiclient_cert = post_params('platform_apiclient_cert', ''); $platform_apiclient_key = post_params('platform_apiclient_key', ''); $platform_apiclient_cert_url = post_params('platform_apiclient_cert_url', ''); $platform_apiclient_key_url = post_params('platform_apiclient_key_url', ''); $platform_pay_key = post_params('platform_pay_key', ''); $platform_mch_api_key = post_params('platform_mch_api_key', ''); $platform_mch_api_serial_no = post_params('platform_mch_api_serial_no', ''); $platform_mch_public_key = post_params('platform_mch_public_key', ''); $platform_mch_public_key_id = post_params('platform_mch_public_key_id', ''); if (!empty($platform_apiclient_cert_url)) { $platform_apiclient_cert = file_get_contents($platform_apiclient_cert_url); } else { if (!empty($platform_apiclient_cert)) { $platform_apiclient_cert_url = WechatConfigForm::handlePemFile($platform_apiclient_cert); } } if (!empty($platform_apiclient_key_url)) { $platform_apiclient_key = file_get_contents($platform_apiclient_key_url); } else { if (!empty($platform_apiclient_key)) { $platform_apiclient_key_url = WechatConfigForm::handlePemFile($platform_apiclient_key); } } Option::set([ 'platform_mch_is_shenhe', 'platform_mch_appid', 'platform_mch_key', 'platform_mch_id', 'platform_apiclient_cert', 'platform_apiclient_key', 'platform_apiclient_cert_url', 'platform_apiclient_key_url', 'platform_mch_public_key', 'platform_mch_public_key_id', 'platform_pay_key', 'platform_mch_api_key', 'platform_mch_api_serial_no' ], [ $platform_mch_is_shenhe, $platform_mch_appid, $platform_mch_key, $platform_mch_id, $platform_apiclient_cert, $platform_apiclient_key, $platform_apiclient_cert_url, $platform_apiclient_key_url, $platform_mch_public_key, $platform_mch_public_key_id, $platform_pay_key, $platform_mch_api_key, $platform_mch_api_serial_no ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'platform_mch_is_shenhe', 'platform_mch_appid', 'platform_mch_key', 'platform_mch_id', 'platform_apiclient_cert', 'platform_apiclient_key', 'platform_apiclient_cert_url', 'platform_apiclient_key_url', 'platform_mch_public_key', 'platform_mch_public_key_id', 'platform_pay_key', 'platform_mch_api_key', 'platform_mch_api_serial_no' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'platform_mch_is_shenhe' => false, 'platform_mch_appid' => '', 'platform_mch_key' => '', 'platform_mch_id' => '', 'platform_apiclient_cert' => '', 'platform_apiclient_key' => '', 'platform_apiclient_cert_url' => '', 'platform_apiclient_key_url' => '', 'platform_mch_public_key'=>"", 'platform_mch_public_key_id'=>"", 'platform_pay_key' => '', 'platform_mch_api_key' => '', 'platform_mch_api_serial_no' => '' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } if (empty($arr['platform_apiclient_cert_url']) && !empty($arr['platform_apiclient_cert'])) { $arr['platform_apiclient_cert_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_cert']); } if (empty($arr['platform_apiclient_key_url']) && !empty($arr['platform_apiclient_key'])) { $arr['platform_apiclient_key_url'] = WechatConfigForm::handlePemFile($arr['platform_apiclient_key']); } $data = $arr; } if ($data['platform_mch_is_shenhe'] === '') { $data['platform_mch_is_shenhe'] = false; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置联盟服务协议隐私政策配置 * */ public function actionAllianceArticle() { if (Yii::$app->request->getIsPost()) { $alliance_service_article = post_params('alliance_service_article', ''); $alliance_privacy_article = post_params('alliance_privacy_article', ''); $alliance_about_us_article = post_params('alliance_about_us_article', ''); $data = [ [ 'name' => '服务协议', 'type' => AboutArticle::TYPE_SERVICE, 'desc' => $alliance_service_article ], [ 'name' => '隐私政策', 'type' => AboutArticle::TYPE_PRIVACY, 'desc' => $alliance_privacy_article ], [ 'name' => '关于我们', 'type' => AboutArticle::TYPE_ABOUT_US, 'desc' => $alliance_about_us_article ] ]; foreach ($data as $item) { $article = AboutArticle::find()->where(['type' => $item['type'], 'is_delete' => 0, 'store_id' => -1])->one(); $article = $article ?? new AboutArticle(); $article->store_id = -1; $article->name = $item['name']; $article->desc = $item['desc']; $article->type = $item['type']; $article->save(); } return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $alliance_service_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_SERVICE, 'is_delete' => 0]) ->select(['desc'])->asArray()->one(); $alliance_privacy_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_PRIVACY, 'is_delete' => 0]) ->select(['desc'])->asArray()->one(); $alliance_about_us_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_ABOUT_US, 'is_delete' => 0]) ->select(['desc'])->asArray()->one(); $data = [ 'alliance_service_article' => $alliance_service_article['desc'] ?? '', 'alliance_privacy_article' => $alliance_privacy_article['desc'] ?? '', 'alliance_about_us_article' => $alliance_about_us_article['desc'] ?? '', ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置支付宝第三方信息 * * @return void */ public function actionAliThirdSetting() { $ali_plugin_goodsDetail_key = OptionSetting::ALI_MINI_PLUGIN_goodsDetail; if (Yii::$app->request->getIsPost()) { $ali_template_token = post_params('ali_template_token', '');//消息验证token $ali_template_aes = post_params('ali_template_aes','');//加密key $ali_template_appid = post_params('ali_template_appid','');//模板小程序appid $ali_template_store_id = post_params('ali_template_store_id','');//模板默认店铺id $ali_template_mini_id = post_params('ali_template_mini_id','');//模板默认小程序id $ali_plugin_goodsDetail = post_params($ali_plugin_goodsDetail_key, 1); Option::set([ 'ali_template_store_id', 'ali_template_mini_id', 'ali_template_token', 'ali_template_aes', 'ali_template_appid', $ali_plugin_goodsDetail_key, ], [ $ali_template_store_id, $ali_template_mini_id, $ali_template_token, $ali_template_aes, $ali_template_appid, $ali_plugin_goodsDetail, ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'ali_template_store_id', 'ali_template_mini_id', 'ali_template_token', 'ali_template_aes', 'ali_template_appid' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'ali_template_store_id'=>'', 'ali_template_mini_id'=>'', 'ali_template_token'=>'', 'ali_template_aes'=>'', 'ali_template_appid'=>'', $ali_plugin_goodsDetail_key => 1, ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; $ali_plugin_goodsDetail = Option::get($ali_plugin_goodsDetail_key, 0, 'saas', 1)['value']; $data[$ali_plugin_goodsDetail_key] = $ali_plugin_goodsDetail; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置微信第三方信息 * * @return void */ public function actionWechatThirdSetting() { if (Yii::$app->request->getIsPost()) { $platform_token = post_params('platform_token', '');//消息验证token $platform_encodingAesKey = post_params('platform_encodingAesKey','');//加密key $platform_phone = post_params('platform_phone','');//平台手机号 $platform_third_appid = post_params("platform_third_appid","");//三方平台Appid $platform_third_secret = post_params("platform_third_secret","");//三方平台AppSecret $platform_template_id = post_params("platform_template_id","");//三方平台模板ID $platform_wechat_third_appid = post_params('platform_wechat_third_appid','');//三方绑定的小程序appid $platform_wechat_b2b_store_min_rate = post_params('platform_wechat_b2b_store_min_rate','');//店铺内b2b优惠费率最低值 $platform_wechat_fuwu_appid = post_params('platform_wechat_fuwu_appid','wx2455c3e38caf34a0');//服务市场企业appid $platform_wechat_fuwu_secret = post_params('platform_wechat_fuwu_secret','483b2c2357868b91825a415bbba45cc7');//服务市场企业secret $platform_wechat_fuwu_serviceId = post_params('platform_wechat_fuwu_serviceId','');//三方绑定的视频号小店serviceId,多个用逗号隔开 $platform_wechat_fuwu_help_qrcode = post_params('platform_wechat_fuwu_help_qrcode','');//视频号小店指南-二维码 $platform_wechat_fuwu_help_tel = post_params('platform_wechat_fuwu_help_tel','');//视频号小店指南-电话 $platform_wechat_fuwu_help_link = post_params('platform_wechat_fuwu_help_link','');//视频号小店指南-文档链接 $local_sym_sn = post_params('local_sym_sn','');//对称密钥编号 $local_sym_key = post_params('local_sym_key','');//对称密钥密钥明文 $rsa_sn = post_params('rsa_sn','');//非对称密钥编号 $rsa_private_key = post_params('rsa_private_key','');//非对称密钥私玥 Option::set([ 'platform_token', 'platform_encodingAesKey', 'platform_phone', "platform_third_appid", "platform_third_secret", "platform_template_id", 'platform_wechat_third_appid', 'platform_wechat_b2b_store_min_rate', 'platform_wechat_fuwu_appid', 'platform_wechat_fuwu_secret', 'platform_wechat_fuwu_serviceId', 'platform_wechat_fuwu_help_qrcode', 'platform_wechat_fuwu_help_tel', 'platform_wechat_fuwu_help_link', ], [ $platform_token, $platform_encodingAesKey, $platform_phone, $platform_third_appid, $platform_third_secret, $platform_template_id, $platform_wechat_third_appid, $platform_wechat_b2b_store_min_rate, $platform_wechat_fuwu_appid, $platform_wechat_fuwu_secret, $platform_wechat_fuwu_serviceId, $platform_wechat_fuwu_help_qrcode, $platform_wechat_fuwu_help_tel, $platform_wechat_fuwu_help_link, ], 0, 'saas'); Option::set([ 'local_sym_sn', 'local_sym_key', 'rsa_sn', 'rsa_private_key', ], [ $local_sym_sn, $local_sym_key, $rsa_sn, $rsa_private_key ], 0, 'delivery'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'platform_token', 'platform_encodingAesKey', 'platform_phone', 'platform_third_appid', 'platform_third_secret', 'platform_template_id', 'platform_wechat_fuwu_appid', 'platform_wechat_fuwu_secret', 'platform_wechat_fuwu_serviceId', 'platform_wechat_third_appid', 'platform_wechat_b2b_store_min_rate', 'platform_wechat_fuwu_help_qrcode', 'platform_wechat_fuwu_help_tel', 'platform_wechat_fuwu_help_link', ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'platform_token'=>'', 'platform_encodingAesKey'=>'', 'platform_phone'=>'', 'platform_third_appid'=>"", 'platform_third_secret'=>"", 'platform_template_id'=>"", 'platform_wechat_fuwu_appid'=>"", 'platform_wechat_fuwu_secret'=>"", 'platform_wechat_fuwu_serviceId'=>"", 'platform_wechat_third_appid' => '', 'platform_wechat_b2b_store_min_rate' => '', 'platform_wechat_fuwu_help_qrcode' => '', 'platform_wechat_fuwu_help_tel' => '', 'platform_wechat_fuwu_help_link' => '', ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } $keys = [ 'local_sym_sn', 'local_sym_key', 'rsa_sn', 'rsa_private_key' ]; $delivery_data = Option::get($keys, 0, 'delivery'); if (empty($data)) { $delivery_data = [ 'local_sym_sn' => '', 'local_sym_key' => '', 'rsa_sn' => '', 'rsa_private_key' => '', ]; } else { $arr = []; foreach ($delivery_data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $delivery_data = $arr; } $data = array_merge($data, $delivery_data); //服务url $data['platform_wechat_fuwu_serviceUrl'] = \Yii::$app->request->hostInfo . "/index.php/wechat/fuwu-buyer-login"; // if($data['platform_wechat_fuwu_serviceId']){ $data['platform_wechat_fuwu_serviceId_qr'] = (new \app\modules\admin\models\WechatThirdForm())->serviceQrcode($data['platform_wechat_fuwu_serviceId']); // } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置代理中心配置 */ public function actionAgencyConfig(){ if (Yii::$app->request->getIsPost()) { $params = [ 'lowerLevelShop' => get_params('lowerLevelShop', ""), 'lowerLevelShopIcon' => get_params('lowerLevelShopIcon', ""), 'renewOrder' => get_params('renewOrder', ""), 'renewOrderIcon' => get_params('renewOrderIcon', ""), // 'Withdrawal' => get_params('Withdrawal', ""), // 'WithdrawalIcon' => get_params('WithdrawalIcon', ""), // 'commissionDetail' => get_params('commissionDetail', ""), // 'commissionDetailIcon' => get_params('commissionDetailIcon', ""), // 'WithdrawalLog' => get_params('WithdrawalLog', ""), // 'WithdrawalLogIcon' => get_params('WithdrawalLogIcon', ""), 'shopOrder' => get_params('shopOrder', ""), 'shopOrderIcon' => get_params('shopOrderIcon', "") ]; Option::set('agency_config', json_encode($params), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); }else{ $option = Option::get('agency_config', 0, 'saas'); $option = json_decode($option['value'], true); $data = [ 'lowerLevelShop' => $option['lowerLevelShop'] ?: "", 'lowerLevelShopIcon' => $option['lowerLevelShopIcon'] ?: "", 'renewOrder' => $option['renewOrder'] ?: "", 'renewOrderIcon' => $option['renewOrderIcon'] ?: "", // 'Withdrawal' => $option['Withdrawal'] ?: "", // 'WithdrawalIcon' => $option['WithdrawalIcon'] ?: "", // 'commissionDetail' => $option['commissionDetail'] ?: "", // 'commissionDetailIcon'=> $option['commissionDetailIcon'] ?: "", // 'WithdrawalLog' => $option['WithdrawalLog'] ?: "", // 'WithdrawalLogIcon' => $option['WithdrawalLogIcon'] ?: "", 'shopOrder' => $option['shopOrder'] ?: "", 'shopOrderIcon' => $option['shopOrderIcon'] ?: "" ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置产品代理中心配置 */ public function actionGoodsAgentPriceConfig(){ try { if (Yii::$app->request->getIsPost()) { $params = [ 'goods_agent_percent' => post_params('goods_agent_percent', "0.00"), 'goods_agent_install_percent' => post_params('goods_agent_install_percent', ""), ]; Option::set('goods_agent_price_config', json_encode($params), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); }else{ $option = Option::get('goods_agent_price_config', 0, 'saas'); if ($option['value']) { $option = json_decode($option['value'], true); } $data = [ 'goods_agent_percent' => $option['goods_agent_percent'] ?: "0.00", 'goods_agent_install_percent' => $option['goods_agent_install_percent'] ?: "0.00", ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } /** * 设置代理中心配置 */ public function actionAgencyPriceConfig(){ if (Yii::$app->request->getIsPost()) { $params = [ 'supplier_province_percent' => post_params('supplier_province_percent', ""), 'supplier_city_percent' => post_params('supplier_city_percent', ""), 'supplier_district_percent' => post_params('supplier_district_percent', ""), 'model_type' => post_params('model_type', 0),//运营模式 'province_percent' => post_params('province_percent', ""), 'city_percent' => post_params('city_percent', ""), 'district_percent' => post_params('district_percent', ""), ]; Option::set('agency_price_config', json_encode($params), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); }else{ $option = Option::get('agency_price_config', 0, 'saas'); if ($option['value']) { $option = json_decode($option['value'], true); } $data = [ 'province_percent' => $option['province_percent'] ?: "", 'city_percent' => $option['city_percent'] ?: "", 'district_percent' => $option['district_percent'] ?: "", 'supplier_province_percent' => $option['supplier_province_percent'] ?: "", 'supplier_city_percent' => $option['supplier_city_percent'] ?: "", 'supplier_district_percent' => $option['supplier_district_percent'] ?: "", 'model_type' => $option['model_type'] ?: 0 ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置推广代理佣金配置 */ public function actionBdAgencyPriceConfig(){ $option = Option::get('bd_agency_price_config', 0, 'saas')['value']; if ($option) { $option = json_decode($option, true); } if (Yii::$app->request->getIsPost()) { $option['bd_agent_percent'] = post_params('bd_agent_percent', ""); $option['supplier_bd_agent_percent'] = post_params('supplier_bd_agent_percent', ""); Option::set('bd_agency_price_config', json_encode($option), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); }else{ $data = [ 'bd_agent_percent' => $option['bd_agent_percent'] ?: 0, 'supplier_bd_agent_percent' => $option['supplier_bd_agent_percent'] ?: 0, ]; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } /** * 设置商户分销 * * @return void */ public function actionStoreShareSetting() { if (Yii::$app->request->getIsPost()) { $params = [ 'level' => post_params('level', 0), 'is_rebate' => post_params('is_rebate', 0), 'price_type' => post_params('price_type', 0), 'level_one' => post_params('level_one', 0), 'level_two' => post_params('level_two', 0), 'level_three' => post_params('level_three', 0), ]; Option::set('store_share', json_encode($params), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $data = Option::get('store_share', 0, 'saas'); if (empty($data['value'])) { $data = [ 'level' => 0, 'is_rebate' => 0, 'price_type' => 0, 'level_one' => 0, 'level_two' => 0, 'level_three' => 0, ]; } else { $data = json_decode($data['value'], true); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } public function actionProfitReceiver() { $form = new ProfitReceiverForm(); if (Yii::$app->request->getIsPost()) { $form->attributes = post_params(); $form->ratio = post_params('ratio'); $form->max_amount = post_params('max_amount'); return $this->asJson($form->save()); } $form->search_key = get_params('search_key'); return $this->asJson($form->search()); } public function actionDeleteReceiver() { $res = ProfitSharingReceiver::find()->where(['store_id' => get_store_id(), 'id' => post_params('id'), 'is_delete' => 0])->one(); if (!$res) { return $this->asJson([ 'code' => 1, 'msg' => '未找到该记录' ]); } $res->is_delete = 1; if ($res->save()) { return $this->asJson([ 'code' => 0, 'msg' => '删除成功' ]); } return $this->asJson([ 'code' => 1, 'msg' => $res->errors[0] ]); } /** * 分帐记录情况 * @return \yii\web\Response */ public function actionShareProfitRecord() { $form = new ShareProfitListForm(); $form->store_id = get_store_id(); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * 财务列表 * @return \yii\web\Response */ public function actionFinanciaList() { $params = get_params(); if (isset($params['isExprot'])) { $params['isExport'] = 1; } $form = new ShareFinancialListForm(); $form->attributes = $params; return $this->asJson($form->financialList()); } /** * 订单列表(成本价) */ public function actionOrderCostProfitList() { $form = new CostProfitListForm(); $form->store_id = get_store_id(); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * 联盟佣金平台提现审核列表 * @return \yii\web\Response */ public function actionProfitCash() { $form = new PlatformProfitCashForm(); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * 审核 * @return \yii\web\Response */ public function actionProfitCashAudit() { $form = new PlatformProfitCashForm(); $form->attributes = post_params(); return $this->asJson($form->audit()); } /** * 提现记录删除 * @return \yii\web\Response */ public function actionProfitCashDel() { $form = new PlatformProfitCashForm(); $form->attributes = post_params(); return $this->asJson($form->del()); } public function actionSmsSetting() { $default = [ 'id' => '', 'secret' => '', 'template' => '', ]; if (Yii::$app->request->getIsPost()) { $content = post_params('content', $default); Option::set('sms', json_encode($content), 0, 'saas'); $SmsSetting = SmsSetting::findOne(['store_id' => -1]) ?: new SmsSetting(); $SmsSetting->AccessKeyId = $content['id']; $SmsSetting->AccessKeySecret = $content['secret']; $SmsSetting->sign = $content['template']; $SmsSetting->store_id = -1; $SmsSetting->created_at = time(); $SmsSetting->save(); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $content = Option::get('sms', 0, 'saas', json_encode($default)); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => json_decode($content['value']), ]); } } /** * saas上传设置 */ public function actionUploadConfig() { $model = UploadConfig::findOne([ 'store_id' => 0, 'is_delete' => 0, ]); if (!$model) { $model = new UploadConfig(); } $mho = Option::get(OptionSetting::MCH_HIDE_OSS, 0, 'saas', '0')['value']; $runOverDefault = [ 'max_picture' => 10, 'max_file' => 10, 'over_picture' => 0, 'over_file' => 0 ]; if (\Yii::$app->request->isPost) { $mho = post_params('mch_hide_oss', 0); Option::set(OptionSetting::MCH_HIDE_OSS, $mho, 0, 'saas'); $runOver = \post_params('runOver', $runOverDefault); if (!isset($runOver['max_file'])) { $runOver['max_file'] = $runOver['max_picture']; } if (!isset($runOver['over_file'])) { $runOver['over_file'] = $runOver['over_picture']; } Option::set(OptionSetting::PLATFORM_UPLOAD_LIMIT, \json_encode($runOver), 0, 'saas'); $form = new CommonUpload(); $form->attributes = post_params(); $form->model = $model; $form->store_id = 0; return $this->asJson($form->save()); } else { $model->aliyun = json_decode($model->aliyun, true); $model->qcloud = json_decode($model->qcloud, true); $model->qiniu = json_decode($model->qiniu, true); $model->storage_type = !empty($model->storage_type) ? $model->storage_type : 'local'; $runOver = Option::get(OptionSetting::PLATFORM_UPLOAD_LIMIT, 0, 'saas', \json_encode($runOverDefault))['value']; $runOver = \json_decode($runOver, true); if (!isset($runOver['max_file'])) { $runOver['max_file'] = $runOver['max_picture']; } if (!isset($runOver['over_file'])) { $runOver['over_file'] = $runOver['over_picture']; } return $this->asJson([ 'code' => 0, 'data' => $model, 'mch_hide_oss' => $mho, 'runOver' => $runOver, ]); } } /** * 平台抖音小程序配置 * */ public function actionBytedanceSetting() { if (Yii::$app->request->getIsPost()) { $platform_appid = post_params('bytedance_platform_appid', ''); $platform_salt = post_params('bytedance_platform_salt', ''); $platform_token = post_params('bytedance_platform_token', ''); $platform_mch_id = post_params('bytedance_platform_mch_id', ''); $platform_key = post_params('bytedance_platform_key', ''); $platform_apiclient_cert = post_params('bytedance_platform_apiclient_cert', ''); $platform_apiclient_key = post_params('bytedance_platform_apiclient_key', ''); Option::set([ 'bytedance_platform_appid', 'bytedance_platform_mch_id', 'bytedance_platform_key', 'bytedance_platform_apiclient_cert', 'bytedance_platform_apiclient_key', 'bytedance_platform_salt', 'bytedance_platform_token', ], [ $platform_appid, $platform_mch_id, $platform_key, $platform_apiclient_cert, $platform_apiclient_key, $platform_salt, $platform_token ], 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $keys = [ 'bytedance_platform_appid', 'bytedance_platform_mch_id', 'bytedance_platform_key', 'bytedance_platform_apiclient_cert', 'bytedance_platform_apiclient_key', 'bytedance_platform_salt', 'bytedance_platform_token' ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'bytedance_platform_appid' => '', 'bytedance_platform_mch_id' => '', 'bytedance_platform_key' => '', 'bytedance_platform_apiclient_cert' => '', 'bytedance_platform_apiclient_key' => '', 'bytedance_platform_salt' => '', 'bytedance_platform_token' => '' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } public function actionSalesman() { $admin = get_admin(); $name = get_params('name'); $mobile = get_params('mobile'); $status = get_params('status', -1); if (!in_array($status, [-1, 0, 1])) { $status = -1; } // $query = Store::find()->alias('s')->leftJoin(['ss' => Salesman::tableName()], 's.salesman_id = ss.id') // ->leftJoin(['su' => SaasUser::tableName()], 'su.id=ss.saas_user_id') // ->where(['ss.is_delete' => 0]) // ->where(['<>', 's.salesman_id', 0]) // ->select('ss.id,ss.status,su.name,su.avatar,ss.created_at, su.mobile, s.name as store_name, s.logo as store_logo')->orderBy('s.id desc'); $query = Salesman::find()->alias('s') ->leftJoin(['su' => SaasUser::tableName()], 'su.id=s.saas_user_id') ->leftJoin(['a' => Admin::tableName()], 'a.id = s.admin_id') ->where(['s.is_delete' => 0, 'a.type' => Admin::ADMIN_TYPE_BD_AGENT]) ->select('s.id,s.status,su.name,su.avatar,s.created_at,su.mobile,a.name as admin_name') ->orderBy('s.created_at desc'); if ($admin->username != 'admin') { $query->andWhere(['s.admin_id' => $admin->id]); } if ($name) { $query->andWhere(['like', 'su.name', $name]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if ($status >= 0) { $query->andWhere(['s.status' => $status]); } $list = pagination_make($query); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], 'admin' => $admin ] ]); } // 修改业务员状态 public function actionSalesmanStatus() { $id = post_params('id'); $status = post_params('status'); if (!in_array($status, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => 'status参数值只能是0或1', ]); } $salesman = Salesman::findOne($id); if (!$salesman) { return $this->asJson([ 'code' => 1, 'msg' => '业务员不存在', ]); } $salesman->status = $status; if (!$salesman->save()) { return $this->asJson([ 'code' => 1, 'msg' => $salesman->errors[0], ]); } return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } public function actionSalesmanDel() { $id = post_params('id'); $salesman = Salesman::findOne($id); if (!$salesman) { return $this->asJson([ 'code' => 1, 'msg' => '业务员不存在', ]); } $salesman->is_delete = 1; if (!$salesman->save()) { return $this->asJson([ 'code' => 1, 'msg' => $salesman->errors[0], ]); } SaasUser::updateAll(['is_salesman' => 0], ['id' => $salesman->saas_user_id]); return $this->asJson([ 'code' => 0, 'msg' => '删除成功', ]); } public function actionSalesmanAdd() { $admin = get_admin(); $admin_id = post_params('admin_id'); $saas_user_id = post_params('saas_user_id'); $status = post_params('status', 1); if (!$saas_user_id || !in_array($status, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数有误', ]); } $salesman = Salesman::findOne(['is_delete' => 0, 'saas_user_id' => $saas_user_id]); if ($salesman) { $admin_ = Admin::findOne(['id' => $salesman->admin_id, 'is_delete' => 0, 'type' => Admin::ADMIN_TYPE_BD_AGENT]); if ($admin_) { return $this->asJson([ 'code' => 1, 'msg' => '业务员已存在', ]); } $salesman->is_delete = 1; $salesman->save(); } $salesman = new Salesman(); if ($admin->username == 'admin' && $admin_id) { $salesman->admin_id = $admin_id; } else { $salesman->admin_id = $admin->id; } $salesman->saas_user_id = $saas_user_id; $salesman->status = $status; if (!$salesman->save()) { return $this->asJson([ 'code' => 1, 'msg' => $salesman->errors[0], ]); } SaasUser::updateAll(['is_salesman' => 1], ['id' => $saas_user_id]); return $this->asJson([ 'code' => 0, 'msg' => '添加成功', ]); } public function actionOtherInfo() { $store_apply_banner = Option::get('store_apply_banner', 0, 'saas', '')['value']; $admin_copyright = Option::get('store_apply_agreement', 0, 'saas', '')['value']; $store_apply_audit = Option::get('store_apply_audit', 0, 'saas', '0')['value']; $store_apply_free = Option::get('store_apply_free', 0, 'saas', '0')['value']; $store_apply_free_days = Option::get('store_apply_free_days', 0, 'saas', 5)['value']; $store_apply_buy_type = Option::get('store_apply_buy_type', 0, 'saas', 'free')['value'];//free/once/renew $store_apply_buy_money = Option::get('store_apply_buy_money', 0, 'saas', 0)['value']; $admin_profit = Option::get('admin_profit', 0, 'saas', 0)['value']; $store_apply_renew = Option::get('store_apply_renew', 0, 'saas', 'sys')['value']; //sys/custom $sysPriceList = StorePrice::findOne(['is_delete' => 0, 'is_sys' => 1]); if (!$sysPriceList) { $this->handleSysPriceList(); } $priceList = StorePrice::findAll(['is_delete' => 0]); return $this->asJson([ 'code' => 0, 'data' => [ 'store_apply_banner' => $store_apply_banner ? Json::decode($store_apply_banner) : [], 'store_apply_agreement' => $admin_copyright, 'store_apply_audit' => $store_apply_audit, 'store_apply_free' => $store_apply_free, 'store_apply_free_days' => $store_apply_free_days, 'store_apply_buy_type' => $store_apply_buy_type, 'store_apply_buy_money' => $store_apply_buy_money, 'store_apply_renew' => $store_apply_renew, 'priceList' => $priceList, 'admin_profit' => $admin_profit ] ]); } public function handleSysPriceList() { $sysPriceList = StorePrice::findOne(['is_delete' => 0, 'is_sys' => 1]); if (!$sysPriceList) { $arr = [ [ 'day' => 30, 'price' => 0.00, 'text' => '1个月' ], [ 'day' => 90, 'price' => 0.00, 'text' => '3个月' ], [ 'day' => 365, 'price' => 0.00, 'text' => '1年' ], ]; foreach ($arr as $item) { $price_item = StorePrice::findOne(['is_delete' => 0, 'is_sys' => 1, 'days' => $item['day']]); if (!$price_item) { $price_item = new StorePrice(); $price_item->days = $item['day']; $price_item->price = $item['price']; $price_item->name = $item['text']; $price_item->discount_name = ''; $price_item->used = 1; $price_item->is_sys = 1; $price_item->save(); } } } } public function actionSubmitOtherInfo() { // $store_apply_banner = post_params('store_apply_banner', []); // $store_apply_agreement = post_params('store_apply_agreement', ''); // Option::set('store_apply_banner', Json::encode($store_apply_banner), 0, 'saas'); // Option::set('store_apply_agreement', $store_apply_agreement, 0, 'saas'); Option::set('store_apply_audit', input_params('store_apply_audit', 0), 0, 'saas'); Option::set('store_apply_free', input_params('store_apply_free', 0), 0, 'saas'); Option::set('store_apply_free_days', input_params('store_apply_free_days', 0), 0, 'saas'); Option::set('store_apply_buy_type', input_params('store_apply_buy_type'), 0, 'saas'); Option::set('store_apply_buy_money', input_params('store_apply_buy_money', 0), 0, 'saas'); Option::set('store_apply_renew', input_params('store_apply_renew'), 0, 'saas'); Option::set('admin_profit', input_params('admin_profit'), 0, 'saas'); $priceList = input_params('priceList'); foreach ($priceList as $item) { $model = StorePrice::findOne($item['id']); $model->name = $item['name']; $model->price = $item['price']; $model->discount_name = $item['discount_name']; $model->used = $item['used']; $model->save(); } return $this->asJson([ 'code' => 0, 'msg' => '更新成功' ]); } public function actionStorePriceAdd() { $model = new StorePrice(); $id = input_params('id'); if($id){ $model = StorePrice::findOne($id); } $model->days = input_params('days'); $model->name = input_params('name'); $model->price = input_params('price'); $model->discount_name = input_params('discount_name'); $save = $model->save(); return $this->asJson([ 'code' => $save ? 0 : 1, 'msg' => $save ? '成功' : '失败', ]); } public function actionStorePriceDel() { $model = StorePrice::findOne(input_params('id')); $model->is_delete = 1; $save = $model->save(); return $this->asJson([ 'code' => $save ? 0 : 1, 'msg' => $save ? '删除成功' : '删除失败', ]); } public function actionGetCloudApplyInfo() { $cloud_apply_banner = Option::get('cloud_apply_banner', 0, 'saas', '')['value']; $cloud_apply_agreement = Option::get('cloud_apply_agreement', 0, 'saas', '')['value']; return $this->asJson([ 'code' => 0, 'data' => [ 'cloud_apply_banner' => $cloud_apply_banner ? Json::decode($cloud_apply_banner) : [], 'cloud_apply_agreement' => $cloud_apply_agreement ] ]); } public function actionSubmitCloudApplyInfo() { $cloud_apply_banner = post_params('cloud_apply_banner', []); $cloud_apply_agreement = post_params('cloud_apply_agreement', ''); Option::set('cloud_apply_banner', Json::encode($cloud_apply_banner), 0, 'saas'); Option::set('cloud_apply_agreement', $cloud_apply_agreement, 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '更新成功' ]); } public function actionMerchantList() { $name = get_params('name'); $salesman = get_params('salesman'); $status = get_params('status'); $admin = get_admin(); $query = MerchantInfo::find()->alias('mi')->leftJoin(['su' => SaasUser::tableName()], 'su.id=mi.saas_user_id') ->leftJoin(['s' => Store::tableName()], 's.id=mi.store_id') ->where(['s.is_delete' => 0, 'mi.is_delete' => 0]); if ($name) { $query->andWhere(['or', ['like', 'mi.business_info', $name], ['like', 'mi.subject_info', $name]]); } if ($status != -1) { $query->andWhere(['mi.status' => $status]); } if ($salesman) { $query->andWhere(['like', 'su.name', $salesman]); } // 如果不是超级管理员,就查找业务员的进件列表 if ($admin->username != 'admin') { $saas_user_id_arr = Salesman::find()->where(['admin_id' => $admin->id, 'is_delete' => 0, 'status' => 1]) ->select('saas_user_id')->column(); // $saas_user_id = empty($admin->saas_user_id) ? $admin->saas_user_id : -1; $query->andWhere(['mi.saas_user_id' => $saas_user_id_arr ?: -1]); } $query->orderBy('mi.created_at desc, mi.updated_at desc')->select(['mi.*', 'su.name']); $list = pagination_make($query); foreach ($list['list'] as &$value) { $value['store_logo'] = ''; $value['store_name'] = ''; if ($value['bind_store_id'] > 0) { $store = Store::findOne($value['bind_store_id']); if ($store) { $value['store_logo'] = $store->logo; $value['store_name'] = $store->name; } } if (!empty($value['business_info'])) { $business_info = Json::decode($value['business_info']); $value['merchant_name'] = $business_info['merchant_shortname']; } else { $store = Store::findOne($value['bind_store_id']); if ($store) { $value['merchant_name'] = $store->name; } else { $value['merchant_name'] = ''; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * ocr接口调用参数配置 * @return \yii\web\Response */ public function actionOcrSetting() { $default = [ 'app_secret' => '', 'app_key' => '', ]; if (\Yii::$app->request->getIsPost()) { $content = post_params('content', $default); Option::set('ocr', json_encode($content), 0, 'saas'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } else { $content = Option::get('ocr', 0, 'saas', json_encode($default)); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => json_decode($content['value']), ]); } } /** * 灵工接口调用参数配置 * @return \yii\web\Response */ public function actionLgSetting() { $default = [ 'app_secret' => '', 'app_key' => '', ]; if (\Yii::$app->request->getIsPost()) { $content = post_params('content', $default); $store = Store::find()->where(['id'=> get_store_id()])->one(); $store->lg_mch_id = $content['lg_mch_id']; $store->lg_project_code = $content['lg_project_code']; $store->lg_park_code = $content['lg_park_code']; $store->lg_pkey = $content['lg_pkey']; $store->lg_key = $content['lg_key']; if ($store->save()){ return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); }else{ return $this->asJson([ 'code' => 1, 'msg' => '保存失败', ]); } } else { $store = Store::find()->where(['id'=> get_store_id()])->select('lg_mch_id,lg_project_code,lg_park_code,lg_pkey,lg_key')->asArray()->one(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' =>$store, ]); } } /** * 云cloud接口调用参数配置 * @return \yii\web\Response */ public function actionCloudSetting() { $default = [ 'name' => '', 'pwd' => '', 'rate' => '', ]; if (\Yii::$app->request->getIsPost()) { $post = post_params(); $domain = (new OptionSetting)->getCloudDomainName(); $url = $domain."/user/getToken"; $data =[]; $data['name'] = $post['name']; $data['pwd'] = $post['pwd']; // $response = cloud_post($url,$data); // $response = json_decode($response,true); // if($response['code'] != 0 || !$response['taken']){ // return $this->asJson([ // 'code' => 1, // 'msg' => '保存失败', // ]); // } // \Yii::$app->cache->set('cloud_admin_cache_token', $response['taken'], 2 * 24 * 3600); // $data['access_token'] = $response['taken']; $data['rate'] = isset($post['rate']) ? (float)$post['rate'] : 10; $data['time'] = time(); Option::set('cloud', json_encode($data), 0, 'saas'); \Yii::$app->cache->delete('cloud_admin_cache_token'); get_platform_token(); return $this->asJson([ 'code' => 0, 'msg' => 'success', ]); } else { $content = Option::get('cloud', 0, 'saas', json_encode($default)); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => json_decode($content['value']), ]); } } // 云仓采购端配置自定义表单 public function actionCloudCustomForm() { try { $default = [ 'name' => '', 'pwd' => '', 'rate' => '', 'sale_day' => 0 ]; if (\Yii::$app->request->getIsPost()) { $post = post_params(); // $domain = OptionSetting::CLOUD_DOMAIN_NAME; // $url = $domain."/user/getToken"; $data =[]; $data['name'] = $post['name']; $data['pwd'] = $post['pwd']; $data['sale_day'] = $post['sale_day']; // $response = cloud_post($url,$data); // $response = json_decode($response,true); // if ($response['code'] != 0 || !$response['taken']) { // return $this->asJson([ // 'code' => 1, // 'msg' => '保存失败', // ]); // } // $data['access_token'] = $response['taken']; // \Yii::$app->cache->set('cloud_admin_cache_token', $response['taken'], 2 * 24 * 3600); $data['rate'] = isset($post['rate']) ? (float)$post['rate'] : 10; $data['time'] = time(); Option::set('cloud', json_encode($data), 0, 'saas'); $cloud_domain_name = $post['cloud_domain_name']; if ($cloud_domain_name) { Option::set('cloud_domain_name', $cloud_domain_name, 0, 'cloud'); } $list = post_params('list'); $supplier_list = post_params('supplier_list'); if (!$list) { return $this->asJson([ 'code' => 1, 'msg' => '缺少必要参数' ]); } $cloud_apply_banner = post_params('cloud_apply_banner', []); $cloud_supplier_banner = post_params('cloud_supplier_banner', []); $cloud_apply_agreement = post_params('cloud_apply_agreement', ''); $cloud_supplier_apply_agreement = post_params('cloud_supplier_apply_agreement', ''); $is_supplier_set_price = post_params('is_supplier_set_price', 1); Option::set('cloud_apply_banner', Json::encode($cloud_apply_banner), 0, 'saas'); Option::set('cloud_supplier_banner', Json::encode($cloud_supplier_banner), 0, 'saas'); Option::set('cloud_apply_agreement', $cloud_apply_agreement, 0, 'saas'); Option::set('cloud_supplier_apply_agreement', $cloud_supplier_apply_agreement, 0, 'saas'); Option::set('cloud_custom_form', json_encode($list), 0, 'saas'); Option::set('supplier_custom_form', json_encode($supplier_list), 0, 'saas'); Option::set('is_supplier_set_price', $is_supplier_set_price, 0, 'cloud'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } $cloud_apply_banner = Option::get('cloud_apply_banner', 0, 'saas', '')['value']; $cloud_supplier_banner = Option::get('cloud_supplier_banner', 0, 'saas', '')['value']; $cloud_apply_agreement = Option::get('cloud_apply_agreement', 0, 'saas', '')['value']; $cloud_supplier_apply_agreement = Option::get('cloud_supplier_apply_agreement', 0, 'saas', '')['value']; $content = Option::get('cloud', 0, 'saas', json_encode($default)); $list = Option::get('cloud_custom_form', 0, 'saas', json_encode([])); $supplier_custom_form = Option::get('supplier_custom_form', 0, 'saas', json_encode([])); $cloud_domain_name = Option::get('cloud_domain_name', 0, 'cloud', 'http://yuncang.tianxin100.vip')['value']; $is_supplier_set_price = Option::get('is_supplier_set_price', 0, 'cloud', 1)['value']; $content = json_decode($content['value'], true); $content = array_merge($content, [ 'cloud_domain_name' => $cloud_domain_name ]); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => json_decode($list['value']), 'supplier_custom_form' => json_decode($supplier_custom_form['value']), 'cloud_apply_banner' => $cloud_apply_banner ? Json::decode($cloud_apply_banner) : [], 'cloud_supplier_banner' => $cloud_supplier_banner ? Json::decode($cloud_supplier_banner) : [], 'cloud_apply_agreement' => $cloud_apply_agreement, 'cloud_supplier_apply_agreement' => $cloud_supplier_apply_agreement, 'is_supplier_set_price' => (int)$is_supplier_set_price, 'content' => $content, ] ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } /** * 获取信息 * @return \yii\web\Response */ public function actionOcrInfo() { $type = post_params('type'); if (empty($type) || !in_array($type, OcrApi::$validType)) { return $this->asJson([ 'code' => 1, 'msg' => '类型参数错误' ]); } $side = post_params('side'); if (empty($side) && $type == OcrApi::TYPE_ID_CARD) { return $this->asJson([ 'code' => 1, 'msg' => '身份证参数有误' ]); } $url = post_params('url'); if (empty($url)) { return $this->asJson([ 'code' => 1, 'msg' => '图片地址为空' ]); } try { $ocr = new OcrApi(true); switch ($type) { case OcrApi::TYPE_LICENSE: $res = $ocr->getBusinessLicense($url); break; case OcrApi::TYPE_ID_CARD: $res = $ocr->getIDCard($url, $side); break; case OcrApi::TYPE_BANK: $res = $ocr->getBankCard($url); break; } if ($res['code'] == 0 && !empty($res['data'])) { return $this->asJson($res); } return $this->asJson([ 'code' => -1, 'msg' => '获取信息失败' ]); } catch (\Exception $e) { return $this->asJson([ 'code' => -1, 'msg' => $e->getMessage() ]); } } /** * 获取积分赠送规则 */ public function actionGetIntegralRules() { $form = new SaasForm(); $form->attributes = post_params(); return $this->asJson($form->getInfo()); } /** * @return \yii\web\Response * 获取列表 */ public function actionGetList() { $form = new SaasForm(); $form->attributes = post_params(); return $this->asJson($form->getRulesList()); } /** * 获取商城信息 */ public function actionGetStore() { $form = new SaasForm(); $form->attributes = post_params(); return $this->asJson($form->getStoreList()); } /** * 修改规则状态 */ public function actionSetStatus() { $form = new SaasForm(); $form->attributes = post_params(); return $this->asJson($form->SetStatus()); } /** * 店铺分销列表 * @return \yii\web\Response */ public function actionStoreShareList() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); if (!in_array($status, [-1, 0, 1])) { $status = -1; } $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id'); $query->where(['s.is_delete' => 0]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'a.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'a.mobile', $mobile]); } if ($status > -1) { $query->andWhere(['s.store_share_switch' => $status]); } $query->select('s.id, s.name as store_name, s.logo, a.name as nickname, a.mobile, s.store_share_switch, s.store_share_type, s.store_share_value'); $list = pagination_make($query); $defaultSet = Option::get(OptionSetting::SHARE_STORE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); $defaultSet = json_decode($defaultSet['value'], true); foreach ($list['list'] as &$item) { $amount = SharingReceiver::find()->where([ 'store_id' => $item['id'], 'from' => 0, 'is_delete' => 0, ])->sum('amount'); $item['income'] = $amount ?: '0.00'; $item['expenditure'] = '0.00'; $item['use_default'] = 0; if($item['store_share_switch'] != 0 && $item['store_share_value'] == 0){ if(!empty($defaultSet['store_share_switch']) && !empty($defaultSet['store_share_value'])){ $item['store_share_value'] = $defaultSet['store_share_value']; $item['use_default'] = 1; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'defaultSet' => $defaultSet, 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 修改店铺间分销设置 * @return Response * @throws InvalidConfigException * @throws StaleObjectException * @throws Exception */ public function actionSetIntegralRules() { $form = new SaasForm(); $form->attributes = post_params(); return $this->asJson($form->save()); } /** * 修改店铺间分销设置 * @return Response * @throws InvalidConfigException * @throws StaleObjectException * @throws Exception */ public function actionStoreShareOption() { $store_id = post_params('store_id'); $store_share_switch = post_params('store_share_switch'); $store_share_type = post_params('store_share_type'); $store_share_value = post_params('store_share_value'); // $store_recharge_profit = post_params('store_recharge_profit'); $store_profit_max = post_params('store_profit_max'); $store_profit_min = post_params('store_profit_min'); $store_send_min = post_params('store_send_min'); // $store_send_profit = post_params('store_send_profit'); // Option::set('store_recharge_profit', $store_recharge_profit, 0); Option::set('store_profit_max', $store_profit_max, 0); Option::set('store_profit_min', $store_profit_min, 0); Option::set('store_send_min', $store_send_min, 0); // Option::set('store_send_profit', $store_send_profit, 0); //默认配置 if(intval($store_id) === -1){ $json = json_encode([ 'store_share_switch' => $store_share_switch, 'store_share_type' => $store_share_type, 'store_share_value' => $store_share_value, 'store_profit_max' => $store_profit_max, 'store_profit_min' => $store_profit_min, 'store_send_min' => $store_send_min, // 'store_send_profit' => $store_send_profit, // 'store_recharge_profit' => $store_recharge_profit, ]); $res = Option::set(OptionSetting::SHARE_STORE_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME); if(!$res){ return $this->asJson([ 'code' => 1, 'msg' => '默认配置编辑失败', ]); } return $this->asJson([ 'code' => 0, 'msg' => '默认配置编辑成功', ]); } if (empty($store_id)) { return $this->asJson([ 'code' => 1, 'msg' => '缺少必要参数', ]); } $store = Store::findOne($store_id); if (!$store) { return $this->asJson([ 'code' => 1, 'msg' => '商城未找到', ]); } if ($store_share_switch !== null) { if (!in_array($store_share_switch, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $store->store_share_switch = $store_share_switch; } if ($store_share_type !== null) { if (!in_array($store_share_type, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $store->store_share_type = $store_share_type; } if (isset($store_share_value)) { $store->store_share_value = $store_share_value; } if (!union_share_scale_check($store)) { return $this->asJson([ 'code' => 1, 'msg' => '保存失败,分销比例超过100%', ]); } if (!$store->save()) { return $this->asJson([ 'code' => 1, 'msg' => $store->errors[0], ]); } return $this->asJson([ 'code' => 0, 'msg' => '编辑成功', ]); } /** * 店铺间分销佣金明细 * @return Response * @throws InvalidConfigException * @throws Throwable * @throws Exception */ public function actionStoreShareLog() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); $start_date = get_params('start_date'); $end_date = get_params('end_date'); if (!in_array($status, [-1, 0, 1])) { $status = -1; } $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id') ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id') ->where(['sr.is_delete' => 0, 'sr.from' => SharingReceiver::FROM_STORE_TO_STORE]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if ($status > -1) { $query->andWhere(['sr.is_pay' => $status]); } if ($start_date) { $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]); } if ($end_date) { $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]); } $query->select('sr.id, sr.to_store_id, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.account, sr.is_pay, sr.created_at, sr.err_code_des ,sr.execute_type, sr.updated_at'); $list = pagination_make($query); foreach ($list['list'] as &$item) { //未改动前端 只调了数据 if ($item['to_store_id']) { $store = Store::findOne($item['to_store_id']); $item['avatar'] = $store->logo ?? ''; $item['name'] = $store->name ?? ''; } $item['created_at'] = date("Y-m-d H:i", $item['created_at']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 联盟分销列表 * @return \yii\web\Response */ public function actionSaasShareList() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id'); $query->where(['s.is_delete' => 0]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'a.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'a.mobile', $mobile]); } $query->select('s.id, s.name as store_name, s.logo, a.name as nickname, a.mobile, s.share_setting'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $amount = SharingReceiver::find()->where([ 'store_id' => $item['id'], 'from' => 1, 'is_delete' => 0, ])->sum('amount'); $item['expenditure'] = $amount ?: '0.00'; if (empty($item['share_setting'])) { $item['switch'] = 0; $item['price_type'] = 0; $item['level_one'] = '0.00'; $item['level_two'] = '0.00'; $item['level_three'] = '0.00'; $item['is_rebate'] = 0; } else { $option = json_decode($item['share_setting'], true); $item['switch'] = $option['level']; $item['price_type'] = $option['price_type']; $item['level_one'] = $option['level_one']; $item['level_two'] = $option['level_two']; $item['level_three'] = $option['level_three']; $item['is_rebate'] = $option['is_rebate']; } $item['use_default'] = 0; if($item['switch'] != 0 && $item['level_one'] == 0 && $item['level_two'] == 0 && $item['level_three'] == 0){ $defaultSet = Option::get(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); $defaultSet = json_decode($defaultSet['value'], true); if(!empty($defaultSet['level']) && (!empty($defaultSet['level_one']) || !empty($defaultSet['level_two']) || !empty($defaultSet['level_three']))){ $item['switch'] = $defaultSet['level']; $item['price_type'] = $defaultSet['price_type']; $item['level_one'] = $defaultSet['level_one']; $item['level_two'] = $defaultSet['level_two']; $item['level_three'] = $defaultSet['level_three']; $item['is_rebate'] = $defaultSet['is_rebate']; $item['use_default'] = 1; } } } //默认配置 $defaultSet = Option::get(OptionSetting::SHARE_SAAS_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'defaultSet' => json_decode($defaultSet['value']), 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 联盟分销佣金明细 * @return Response * @throws InvalidConfigException * @throws Throwable * @throws Exception */ public function actionSaasShareLog() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); $start_date = get_params('start_date'); $end_date = get_params('end_date'); if (!in_array($status, [-1, 0, 1])) { $status = -1; } $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id') //->leftJoin(['su' => SaasUser::tableName()], 'sr.user_id = su.id') ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id') ->where(['sr.is_delete' => 0, 'sr.from' => 1]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if ($status > -1) { $query->andWhere(['sr.is_pay' => $status]); } if ($start_date) { $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]); } if ($end_date) { $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]); } $query->select('sr.id, su.avatar, su.name, su.mobile, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.is_pay, sr.created_at, sr.err_code_des, sr.execute_type, sr.updated_at, sr.remark')->orderBy('sr.created_at desc'); $list = pagination_make($query); foreach ($list['list'] as &$item) { if(!$item['avatar'] && $item['id']){ $userInfo = User::find()->where(['id'=>$item['id'],'is_delete'=>0])->one(); if(!empty($userInfo) && !empty($userInfo->avatar_url)){ $item['avatar'] = $userInfo->avatar_url; $item['name'] = $userInfo->nickname; } } $item['created_at'] = date("Y-m-d H:i", $item['created_at']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 供货商推荐人列表 */ public function actionSupplierReferralList() { $supplier_name = get_params('supplier_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); if (!in_array($status, [-1, 0, 1])) { $status = -1; } $query = SaasSupplierReferral::find()->alias('ssr') ->leftJoin(['su' => SaasUser::tableName()], 'ssr.referral_id = su.id') ->leftJoin(['s' => Supplier::tableName()], 'ssr.supplier_id = s.id'); $query->where(['s.is_delete' => 0]); if ($supplier_name) { $query->andWhere(['like', 's.name', $supplier_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if ($status > -1) { $query->andWhere(['ssr.is_enable' => $status]); } $query->orderBy('ssr.id DESC'); $query->select('ssr.id, ssr.supplier_id, ssr.referral_id, ssr.is_enable, s.supplier_name, s.logo as supplier_logo, s.phone as supplier_phone, ssr.referral_rebate, su.avatar, su.name as nickname, su.mobile, su.id as user_id '); $list = pagination_make($query); //默认配置 $defaultSet = Option::get(OptionSetting::SHARE_SAAS_SUPPLIER_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}')['value']; $defaultSet = json_decode($defaultSet, true); foreach ($list['list'] as &$item) { $item['amount'] = SaasUserPriceLog::find()->where(['saas_id' => $item['referral_id'], 'amount_type' => SaasUserPriceLog::AMOUNT_TYPE_SUPPLIER_PARENT])->sum('amount') ?: '0.00'; $item['use_default'] = 0; if($item['is_enable'] != 0 && $item['referral_rebate'] == 0){ if(!empty($defaultSet['is_enable']) && !empty($defaultSet['referral_rebate'])){ $item['referral_rebate'] = $defaultSet['referral_rebate']; $item['use_default'] = 1; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'defaultSet' => $defaultSet, 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 供货商推荐人新增编辑 */ public function actionEditSupplierReferral() { $id = post_params('id'); $supplier_id = post_params('supplier_id'); $is_enable = post_params('is_enable'); $referral_id = post_params('referral_id'); $referral_rebate = post_params('referral_rebate', '0.00'); if (!$id) { $has = SaasSupplierReferral::findOne([ 'supplier_id' => $supplier_id ]); if($has){ return $this->asJson([ 'code' => 1, 'msg' => '不能重复添加', ]); } } //默认配置 if(intval($supplier_id) === -1){ $json = json_encode([ 'is_enable' => $is_enable, 'referral_rebate' => $referral_rebate, ]); $res = Option::set(OptionSetting::SHARE_SAAS_SUPPLIER_REFERRAL_DEFAULT_SETTING, $json, $supplier_id, OptionSetting::SHARE_GROUP_NAME); if(!$res){ return $this->asJson([ 'code' => 1, 'msg' => '默认配置编辑失败', ]); } return $this->asJson([ 'code' => 0, 'msg' => '默认配置编辑成功', ]); } if (!in_array($is_enable, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $supplier = Supplier::findOne($supplier_id); if (!$supplier) { return $this->asJson([ 'code' => 1, 'msg' => '供货商不存在', ]); } if ($id) { $item = SaasSupplierReferral::findOne($id); if ($is_enable !== null) { $item->is_enable = $is_enable; } if (isset($referral_rebate)) { $item->referral_rebate = $referral_rebate; } $item->save(); return $this->asJson([ 'code' => 0, 'msg' => '编辑成功', ]); } else { $saasUser = SaasUser::findOne($referral_id); if (!$saasUser) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在', ]); } $item = new SaasSupplierReferral(); $item->supplier_id = $supplier_id; $item->referral_id = $referral_id; $item->referral_rebate = $referral_rebate; $item->is_enable = $is_enable; $item->save(); return $this->asJson([ 'code' => 0, 'msg' => '绑定成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } /** * 推荐人列表 * @return Response * @throws InvalidConfigException * @throws Throwable * @throws Exception */ public function actionReferralList() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); $query = SaasStoreReferral::find()->alias('ssr') ->leftJoin(['su' => SaasUser::tableName()], 'ssr.referral_id = su.id') ->leftJoin(['s' => Store::tableName()], 'ssr.store_id = s.id'); $query->where(['s.is_delete' => 0, 'ssr.type' => 1]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if (isset($status) && in_array($status, [0, 1])) { $query->andWhere(['ssr.is_enable' => $status]); } $query->orderBy('ssr.id DESC'); $query->select('ssr.id, ssr.store_id, ssr.referral_id, ssr.is_enable, s.name as store_name, s.logo as store_logo, s.contact_tel, ssr.referral_rebate, su.avatar, su.name as nickname, su.mobile, su.id as user_id '); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['amount'] = SharingReceiver::find()->where(['is_delete' => 0, 'saas_id' => $item['user_id'], 'from' => SharingReceiver::FROM_NEW_STORE_RECOMMEND]) ->sum('amount') ?: '0.00'; $item['use_default'] = 0; if($item['is_enable'] != 0 && $item['referral_rebate'] == 0){ $defaultSet = Option::get(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); $defaultSet = json_decode($defaultSet['value'], true); if(!empty($defaultSet['is_enable']) && !empty($defaultSet['referral_rebate'])){ $item['referral_rebate'] = $defaultSet['referral_rebate']; $item['use_default'] = 1; } } } //默认配置 $defaultSet = Option::get(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'defaultSet' => json_decode($defaultSet['value']), 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 推荐人新增编辑 * @return Response * @throws InvalidConfigException * @throws StaleObjectException * @throws Exception * @throws NotSupportedException * @throws InvalidArgumentException * @throws GlobalException */ public function actionEditReferral() { $id = post_params('id'); $store_id = post_params('store_id'); $is_enable = post_params('is_enable'); $referral_id = post_params('referral_id'); $referral_rebate = post_params('referral_rebate', '0.00'); if (!$id) { $has = SaasStoreReferral::findOne([ 'store_id' => $store_id, 'type' => 1 ]); if($has){ return $this->asJson([ 'code' => 1, 'msg' => '不能重复添加', ]); } } //默认配置 if(intval($store_id) === -1){ $json = json_encode([ 'is_enable' => $is_enable, 'referral_rebate' => $referral_rebate, ]); $res = Option::set(OptionSetting::SHARE_SAAS_REFERRAL_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME); if(!$res){ return $this->asJson([ 'code' => 1, 'msg' => '默认配置编辑失败', ]); } return $this->asJson([ 'code' => 0, 'msg' => '默认配置编辑成功', ]); } if (!in_array($is_enable, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $store = Store::findOne($store_id); if (!$store) { return $this->asJson([ 'code' => 1, 'msg' => '商城不存在', ]); } $scale = union_share_scale($store, true); if ($id) { $item = SaasStoreReferral::findOne($id); if ($is_enable !== null) { $item->is_enable = $is_enable; } if (isset($referral_rebate)) { // 检查比例是否超过100% $referral = SaasStoreReferral::find() ->where(['store_id' => $store->id, 'type' => 1]) ->andWhere(['<>', 'id', $id]) ->asArray() ->all(); if (count($referral) > 0) { foreach ($referral as $iitem) { $scale += $iitem['referral_rebate']; } } $scale += $referral_rebate; if ($scale > 100) { return $this->asJson([ 'code' => 1, 'msg' => '编辑失败,分销比例超过100% 当前累计分销比例:' . $scale .'%', ]); } $item->referral_rebate = $referral_rebate; } $item->save(); return $this->asJson([ 'code' => 0, 'msg' => '编辑成功', ]); } else { $saasUser = SaasUser::findOne($referral_id); if (!$saasUser) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在', ]); } // 检查比例是否超过100% $referral = SaasStoreReferral::find() ->where(['store_id' => $store->id, 'type' => 1]) ->asArray() ->all(); if (count($referral) > 0) { foreach ($referral as $item) { $scale += $item['referral_rebate']; } } $scale += $referral_rebate; if ($scale > 100) { return $this->asJson([ 'code' => 1, 'msg' => '创建失败,分销比例超过100% 当前累计分销比例:' . $scale .'%', ]); } $item = new SaasStoreReferral(); $item->store_id = $store_id; $item->referral_id = $referral_id; $item->referral_rebate = $referral_rebate; $item->is_enable = $is_enable; $item->type = 1; $item->save(); return $this->asJson([ 'code' => 0, 'msg' => '绑定成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } /** * 删除绑定推荐人 * @return Response * @throws InvalidConfigException * @throws StaleObjectException * @throws GlobalException * @throws Throwable */ public function actionDeleteReferral() { $id = post_params('id'); $item = SaasStoreReferral::findOne($id); if (!$item) { return $this->asJson([ 'code' => 1, 'msg' => '数据不存在', ]); } $item->delete(); return $this->asJson([ 'code' => 0, 'msg' => '删除成功', ]); } /** * 删除绑定推荐人 * @return Response * @throws InvalidConfigException * @throws StaleObjectException * @throws GlobalException * @throws Throwable */ public function actionDeleteSupplierReferral() { $id = post_params('id'); $item = SaasSupplierReferral::findOne($id); if (!$item) { return $this->asJson([ 'code' => 1, 'msg' => '数据不存在', ]); } $item->delete(); return $this->asJson([ 'code' => 0, 'msg' => '删除成功', ]); } /** * 联盟推荐人佣金明细 * @return Response * @throws InvalidConfigException * @throws Throwable * @throws Exception */ public function actionReferralShareLog() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); $start_date = get_params('start_date'); $end_date = get_params('end_date'); $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id') ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id') ->where(['sr.is_delete' => 0, 'sr.from' => SharingReceiver::FROM_NEW_STORE_RECOMMEND]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if (isset($status) && in_array($status, [0, 1])) { $query->andWhere(['ssr.is_enable' => $status]); } if ($start_date) { $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]); } if ($end_date) { $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]); } $query->select('sr.id, sr.saas_id, sr.user_id, su.avatar, su.name, su.mobile, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.is_pay, sr.created_at ,sr.err_code_des ,sr.execute_type, sr.updated_at'); $list = pagination_make($query); foreach ($list['list'] as &$item) { if(!$item['saas_id']){ $orderNoHead = substr($item['order_no'], 0, 2); if($orderNoHead == 'SC'){ $order = \app\plugins\scanCodePay\models\Order::findOne(['order_no' => $item['order_no']]); }else{ $order = Order::findOne(['order_no' => $item['order_no']]); } if($order->is_platform){ $userInfo = SaasUser::findOne($item['user_id']); if(!empty($userInfo) && !empty($userInfo->avatar)){ $item['avatar'] = $userInfo->avatar; $item['name'] = $userInfo->name; $item['mobile'] = $userInfo->mobile; } }else{ $userInfo = User::findOne($item['user_id']); if(!empty($userInfo) && !empty($userInfo->avatar_url)){ $item['avatar'] = $userInfo->avatar_url; $item['name'] = $userInfo->nickname; $item['mobile'] = $userInfo->binding; } } } $item['created_at'] = date("Y-m-d H:i", $item['created_at']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } public function actionSupplierReferralShareLog() { $supplier_name = get_params('supplier_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $start_date = get_params('start_date'); $end_date = get_params('end_date'); $query = SaasUserPriceLog::find()->alias('sr') ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id') ->leftJoin(['ssr' => SaasSupplierReferral::tableName()], 'ssr.referral_id = su.id') ->leftJoin(['s' => Supplier::tableName()], 'ssr.supplier_id = s.id') ->where(['sr.amount_type' => SaasUserPriceLog::AMOUNT_TYPE_SUPPLIER_PARENT]); if ($supplier_name) { $query->andWhere(['like', 's.name', $supplier_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if ($start_date) { $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]); } if ($end_date) { $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]); } $query->select('sr.*, su.avatar, su.name, su.mobile, s.name as supplier_name'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['created_at'] = date("Y-m-d H:i", $item['created_at']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 消费返利列表 * @return \yii\web\Response */ public function actionStoreSelfRebateList() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); if (!in_array($status, [-1, 0, 1])) { $status = -1; } $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id'); $query->where(['s.is_delete' => 0]); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'a.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'a.mobile', $mobile]); } if ($status > -1) { $query->andWhere(['s.self_rebate_switch' => $status]); } $query->select('s.id, s.name as store_name, s.logo, a.name as nickname, a.mobile, s.self_rebate_switch, s.self_rebate_value'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $amount = SharingReceiver::find()->where([ 'store_id' => $item['id'], 'from' => 1, 'is_delete' => 0, ])->andWhere(['like', 'remark', '自购返利'])->sum('amount'); $item['income'] = $amount ?: '0.00'; $item['use_default'] = 0; if($item['self_rebate_switch'] != 0 && $item['self_rebate_value'] == 0){ $defaultSet = Option::get(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); $defaultSet = json_decode($defaultSet['value'], true); if(!empty($defaultSet['self_rebate_switch']) && !empty($defaultSet['self_rebate_value'])){ $item['self_rebate_value'] = $defaultSet['self_rebate_value']; $item['use_default'] = 1; } } } //默认配置 $defaultSet = Option::get(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, -1, OptionSetting::SHARE_GROUP_NAME, '{}'); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'defaultSet' => json_decode($defaultSet['value']), 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } /** * 编辑消费返利设置 * @return \yii\web\Response * @throws \yii\base\InvalidConfigException * @throws \yii\db\StaleObjectException * @throws \yii\db\Exception * @author Syan mzsongyan@gmail.com * @date 2022-05-13 */ public function actionStoreSelfRebateOption() { $store_id = post_params('store_id'); $switch = post_params('switch'); $rate = post_params('rate'); //默认配置 if(intval($store_id) === -1){ $json = json_encode([ 'self_rebate_switch' => $switch, 'self_rebate_value' => $rate, ]); $res = Option::set(OptionSetting::SHARE_SELF_REBATE_DEFAULT_SETTING, $json, $store_id, OptionSetting::SHARE_GROUP_NAME); if(!$res){ return $this->asJson([ 'code' => 1, 'msg' => '默认配置编辑失败', ]); } return $this->asJson([ 'code' => 0, 'msg' => '默认配置编辑成功', ]); } if (!$store_id || $switch === null) { return $this->asJson([ 'code' => 1, 'msg' => '缺少必要参数', ]); } if (!in_array($switch, [0, 1])) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $store = Store::findOne($store_id); if (!$store) { return $this->asJson([ 'code' => 1, 'msg' => '商城不存在', ]); } $store->self_rebate_switch = $switch; if ($rate !== null) { $store->self_rebate_value = $rate; } if (!union_share_scale_check($store)) { return $this->asJson([ 'code' => 1, 'msg' => '保存失败,分销比例不能超过100%', ]); } if ($store->save()) { return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '保存失败', ]); } /** * 消费返利佣金明细 * @return \yii\web\Response * @throws \yii\base\InvalidConfigException * @throws \Throwable * @throws \yii\db\Exception * @author Syan mzsongyan@gmail.com * @date 2022-05-13 */ public function actionStoreSelfRebateLog() { $store_name = get_params('store_name'); $nickname = get_params('nickname'); $mobile = get_params('mobile'); $status = get_params('status', -1); $start_date = get_params('start_date'); $end_date = get_params('end_date'); if (!in_array($status, [-1, 0, 1])) { $status = -1; } $query = SharingReceiver::find()->alias('sr')->leftJoin(['s' => Store::tableName()], 'sr.store_id = s.id') //->leftJoin(['su' => SaasUser::tableName()], 'sr.user_id = su.id') ->leftJoin(['su' => SaasUser::tableName()], 'sr.saas_id = su.id') ->where(['sr.is_delete' => 0, 'sr.from' => 5]); $query->andWhere(['like', 'sr.remark', '自购返利']); if ($store_name) { $query->andWhere(['like', 's.name', $store_name]); } if ($nickname) { $query->andWhere(['like', 'su.name', $nickname]); } if ($mobile) { $query->andWhere(['like', 'su.mobile', $mobile]); } if ($status > -1) { $query->andWhere(['sr.is_pay' => $status]); } if ($start_date) { $query->andWhere(['>=', 'sr.created_at', strtotime($start_date)]); } if ($end_date) { $query->andWhere(['<=', 'sr.created_at', strtotime($end_date)]); } $query->select('sr.id, su.avatar, su.name, su.mobile, sr.order_no, s.name as store_name, sr.rate, sr.amount, sr.is_pay, sr.created_at, sr.err_code_des ,sr.execute_type, sr.updated_at , sr.created_at '); $query->orderBy('sr.created_at desc'); $list = pagination_make($query); foreach ($list['list'] as &$item) { if(!$item['avatar'] && $item['id']){ $userInfo = User::find()->where(['id' => $item['id'], 'is_delete' => 0])->one(); if(!empty($userInfo) && !empty($userInfo->avatar_url)){ $item['avatar'] = $userInfo->avatar_url; $item['name'] = $userInfo->nickname; } } $item['created_at'] = date("Y-m-d H:i", $item['created_at']); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ] ]); } //设置入驻协议 public function actionSaasProtocol() { try { if (\Yii::$app->request->isPost) { $data = post_params(); //店铺入驻协议 if (!empty($data['store_apply_agreement'])) { Option::set('store_apply_agreement', $data['store_apply_agreement'], 0, 'saas'); } //采购申请协议 if (!empty($data['cloud_apply_agreement'])) { Option::set('cloud_apply_agreement', $data['cloud_apply_agreement'], 0, 'saas'); } //供货商入驻协议 if (!empty($data['cloud_supplier_apply_agreement'])) { Option::set('cloud_supplier_apply_agreement', $data['cloud_supplier_apply_agreement'], 0, 'saas'); } //区域管理协议 if (!empty($data['area_agent_apply_agreement'])) { Option::set('area_agent_apply_agreement', $data['area_agent_apply_agreement'], 0, 'saas'); } //推广代理申请协议 if (!empty($data['bd_agent_apply_agreement'])) { Option::set('bd_agent_apply_agreement', $data['bd_agent_apply_agreement'], 0, 'saas'); } //产品代理入驻协议 if (!empty($data['goods_agent_apply_agreement'])) { Option::set('goods_agent_apply_agreement', $data['goods_agent_apply_agreement'], 0, 'saas'); } return $this->asJson([ 'code' => 0, 'msg' => "设置完成" ]); } else { $keys = [ 'store_apply_agreement', 'cloud_apply_agreement', 'cloud_supplier_apply_agreement', 'area_agent_apply_agreement', 'bd_agent_apply_agreement', 'goods_agent_apply_agreement', ]; $data = Option::get($keys, 0, 'saas'); if (empty($data)) { $data = [ 'store_apply_agreement' => '', 'cloud_apply_agreement' => '', 'cloud_supplier_apply_agreement' => '', 'area_agent_apply_agreement' => '', 'bd_agent_apply_agreement' => '', 'goods_agent_apply_agreement' => '' ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } } catch (\Exception $e) { return $this->asJson( [ 'code' => 1, 'msg' => $e->getMessage() ] ); } } public function actionWechatCashConfig() { try { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $params = post_params(); $data = [ 'is_open' => $params['is_open'] ?: 1,//是否使用新版商家转账(申请后可以用)//https://pay.weixin.qq.com/doc/v3/merchant/4012711988 'mch_id' => $params['mch_id'] ?: '', 'appid' => $params['appid'] ?: '', 'mch_private_key' => $params['mch_private_key'] ?: '', 'mch_api_key' => $params['mch_api_key'] ?: '', 'serial_no' => $params['serial_no'] ?: '', 'mch_public_key' => $params['mch_public_key'] ?: '', 'pay_public_key' => $params['pay_public_key'] ?: '', 'pay_public_key_id' => $params['pay_public_key_id'] ?: '', ]; Option::set('wechat_cash', json_encode($data), $store_id, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } else { $data = json_encode([ 'is_open' => 1, 'mch_id' => '', 'appid' => '', 'mch_private_key' => '', 'serial_no' => '', 'mch_api_key' => '', 'mch_public_key' => '', 'pay_public_key' => '', 'pay_public_key_id' => '', ]); $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value']; if (!$wechat_cash) { $wechat_cash = $data; } $wechat_cash = json_decode($wechat_cash, true); if (!isset($wechat_cash['is_open'])) { $wechat_cash['is_open'] = 1; } if (!isset($wechat_cash['mch_api_key'])) { $wechat_cash['mch_api_key'] = ''; } if (!isset($wechat_cash['mch_public_key'])) { $wechat_cash['mch_public_key'] = ''; } return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $wechat_cash ]); } } catch (\Exception $e) { return $this->asJson( [ 'code' => 1, 'msg' => $e->getMessage() ] ); } } public function actionStoreWechatCashConfig() { try { $store_id = get_store_id(); if (\Yii::$app->request->isPost) { $params = post_params(); $data = [ 'is_open' => $params['is_open'] ?: '',//是否使用新版商家转账(申请后可以用)//https://pay.weixin.qq.com/doc/v3/merchant/4012711988 'mch_id' => $params['mch_id'] ?: '', 'appid' => $params['appid'] ?: '', 'mch_private_key' => $params['mch_private_key'] ?: '', 'mch_api_key' => $params['mch_api_key'] ?: '', 'serial_no' => $params['serial_no'] ?: '', 'mch_public_key' => $params['mch_public_key'] ?: '', 'pay_public_key' => $params['pay_public_key'] ?: '', 'pay_public_key_id' => $params['pay_public_key_id'] ?: '', ]; Option::set('store_wechat_cash', json_encode($data), $store_id, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } else { $data = json_encode([ 'is_open' => 1, 'mch_id' => '', 'appid' => '', 'mch_private_key' => '', 'mch_api_key' => '', 'serial_no' => '', 'mch_public_key' => '', 'pay_public_key' => '', 'pay_public_key_id' => '', ]); $store_wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value']; if (!$store_wechat_cash) { $store_wechat_cash = $data; } $store_wechat_cash = json_decode($store_wechat_cash, true); if (!isset($store_wechat_cash['is_open'])) { $store_wechat_cash['is_open'] = 1; } if (!isset($store_wechat_cash['mch_api_key'])) { $store_wechat_cash['mch_api_key'] = ''; } if (!isset($store_wechat_cash['mch_public_key'])) { $store_wechat_cash['mch_public_key'] = ''; } return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $store_wechat_cash ]); } } catch (\Exception $e) { return $this->asJson( [ 'code' => 1, 'msg' => $e->getMessage() ] ); } } public function actionProfitStrategyUpdate() { $id = \Yii::$app->cache->get('profit_strategy_job_id'); if ($id && !\Yii::$app->queue->isDone($id)) { \Yii::$app->queue->remove($id); } $id = \queue_push(new \app\jobs\SetProfitStrategyJob(), 0, 1); \Yii::$app->cache->set('profit_strategy_job_id', $id); return $this->asJson([ 'code' => 0, 'msg' => '正在更新,请稍后' ]); } //设置策略 public function actionProfitStrategy() { try { if (\Yii::$app->request->isPost) { $params = post_params(); $data = [ 'service_charge_model' => $params['service_charge_model'] ?: 0,//服务收费模式 'service_charge_rate' => $params['service_charge_rate'] ?: sprintf('%.2f', '0'),//抽成比例 'is_risk_control' => $params['is_risk_control'] ?: 0,//是否开启风控 'risk_control_model' => $params['risk_control_model'] ?: 0,//风控规则 // 'is_markup_protection' => $params['is_markup_protection'] ?: 0,//加价保护是否开启 // 'markup_protection_rules' => [//加价保护规则 // 'title' => $params['markup_protection_rules']['title'] ?: 0,//加价保护规则名称 // 'compare' => $params['markup_protection_rules']['compare'] ?: 0, // 'price' => $params['markup_protection_rules']['price'] ?: sprintf('%.2f', '0'), // 'operate' => $params['markup_protection_rules']['operate'] ?: 0, // ] ]; Option::set('platform_profit_strategy', json_encode($data), 0, 'store'); return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } else { $data = json_encode([ 'service_charge_model' => 0,//服务收费模式 'service_charge_rate' => sprintf('%.2f', '0'),//抽成比例 'is_risk_control' => 0,//是否开启风控 'risk_control_model' => 0,//风控规则 // 'is_markup_protection' => 0,//加价保护是否开启 // 'markup_protection_rules' => [//加价保护规则 // 'title' => 0,//加价保护规则名称 // 'compare' => 0, // 'price' => sprintf('%.2f', '0'), // 'operate' => 0, // ] ]); $wechat_cash = Option::get('platform_profit_strategy', 0, 'store')['value']; if (!$wechat_cash) { $wechat_cash = $data; } return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => json_decode($wechat_cash, true) ]); } } catch (\Exception $e) { return $this->asJson( [ 'code' => 1, 'msg' => $e->getMessage() ] ); } } public function actionGetVersion() { $type = get_params('type'); $key = 'store_dandianpu_version'; if ($type == 'merchant') { $key = 'store_merchant_version'; } $cache = cacheLock(); return $this->asJson([ 'code' => 0, 'data' => [ 'version' => $cache->get($key) ?: '', 'cyy_version' => cyy_version() ] ]); } // 判断供应链版本是否有h5端权限 public function actionCheckDandianpuHasH5() { $cliented = \Yii::$app->getAttr('client'); return $this->asJson([ 'code' => 0, 'data' => \Yii::$app->prod_is_dandianpu() ? in_array('h5', $cliented['store']) : true, ]); } }