| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/3/9
- * Time: 下午5:26
- */
- namespace app\backend\modules\setting\controllers;
- use app\backend\modules\goods\models\Goods;
- use app\backend\modules\uploadVerificate\UploadVerificationBaseController;
- use app\common\components\BaseController;
- use app\common\facades\RichText;
- use app\common\helpers\Cache;
- use app\common\helpers\Url;
- use app\common\facades\Setting;
- use app\common\models\AccountWechats;
- use app\common\models\Address;
- use app\common\models\LogisticsSet;
- use app\common\models\MemberLevel;
- use app\common\models\notice\MessageTemp;
- use app\common\models\Protocol;
- use app\common\models\Street;
- use app\common\modules\refund\services\RefundService;
- use app\common\services\MyLink;
- use app\common\services\Utils;
- use Hamcrest\Core\Set;
- use Mews\Captcha\Captcha;
- use Yunshop\Diyform\models\DiyformTypeModel;
- use Gregwar\Captcha\CaptchaBuilder;
- use Gregwar\Captcha\PhraseBuilder;
- use app\common\models\PayType;
- use app\common\models\notice\MinAppTemplateMessage;
- use app\backend\modules\member\models\MemberShopInfo;
- use app\common\services\YunqianRequest;
- class ShopController extends UploadVerificationBaseController
- {
- /**
- * 商城设置
- * @return mixed
- */
- public function index()
- {
- return view('setting.shop.shop');
- }
- public function shopSetInfo()
- {
- if (request()->ajax()) {
- $shop = Setting::get('shop.shop');
- $shop['logo_url'] = !empty($shop['logo_url']) ? $shop['logo_url'] : yz_tomedia($shop['logo']);
- $shop['signimg_url'] = !empty($shop['signimg_url']) ? $shop['signimg_url'] : yz_tomedia($shop['signimg']);
- $shop['copyrightImg_url'] = !empty($shop['copyrightImg_url']) ? $shop['copyrightImg_url'] : yz_tomedia($shop['copyrightImg']);
- $level = MemberLevel::get(['id', 'level_name']);
- $requestModel = request()->shop;
- if ($requestModel) {
- if (Cache::has('shop_setting')) {
- Cache::forget('shop_setting');
- }
- $requestModel['credit'] = empty($requestModel['credit']) ? "余额" : $requestModel['credit'];
- if (Setting::set('shop.shop', $requestModel)) {
- return $this->successJson('商城设置成功');
- } else {
- return $this->errorJson('商城设置失败');
- }
- }
- return $this->successJson('请求接口成功', [
- 'shop' => $shop,
- 'level' => $level,
- ]);
- }
- }
- /**
- * 会员设置
- * @return mixed
- */
- public function member()
- {
- if (request()->ajax()) {
- $member = Setting::get('shop.member');
- $shop = Setting::get('shop.shop');
- $requestModel = request()->member;
- $member['headimg_url'] = !empty($member['headimg_url']) ? $member['headimg_url'] : yz_tomedia($member['headimg']);
- if ($requestModel) {
- if ($requestModel['is_bind_mobile'] !== '0' && $requestModel['invite_page'] == '1') {
- return $this->errorJson('强制绑定手机号跟邀请页面不能同时开启');
- }
- if (Cache::has('shop_member')) {
- Cache::forget('shop_member');
- }
- if (Setting::set('shop.member', $requestModel)) {
- return $this->successJson('会员设置成功');
- } else {
- $this->errorJson('会员设置失败');
- }
- }
- $is_diyform = \YunShop::plugin()->get('diyform');
- $diyForm = [];
- if ($is_diyform) {
- $diyForm = DiyformTypeModel::getDiyformList()->get();
- }
- return $this->successJson('成功', [
- 'set' => $member,
- 'shop' => $shop,
- 'is_diyform' => $is_diyform,
- 'diyForm' => $diyForm,
- ]);
- }
- return view('setting.shop.member')->render();
- }
- /**
- * 会员设置
- * @return mixed
- */
- public function register()
- {
- $register = Setting::get('shop.register');
- $requestModel = request()->register;
- if ($requestModel) {
- if (Cache::has('shop_register')) {
- Cache::forget('shop_register');
- }
- if (!empty($requestModel['protocol'])) {
- $shop = Protocol::uniacid()->first();
- if (empty($shop)) {
- $shop = new Protocol();
- $shop->uniacid = \YunShop::app()->uniacid;
- }
- $shop->status = $requestModel['protocol']['status'];
- $shop->title = $requestModel['protocol']['title'];
- $shop->content = $requestModel['protocol']['content'];
- $shop->save();
- $requestModel['protocol']['content'] = '';
- }
- unset($requestModel['protocol']['content']);
- if (Setting::set('shop.register', $requestModel)) {
- return $this->successJson('设置成功', Url::absoluteWeb('setting.shop.register'));
- } else {
- $this->errorJson('设置失败');
- }
- }
- $protocol = Protocol::uniacid()->first();
- return view('setting.shop.register', [
- 'register' => $register,
- 'protocol' => $protocol,
- ])->render();
- }
- /**
- * 订单设置
- * @return mixed|string
- * @throws \Throwable
- */
- public function order()
- {
- if (request()->ajax()) {
- $order = Setting::get('shop.order');
- $requestModel = request()->order;
- if ($requestModel) {
- if ($requestModel['receipt_goods_notice']) {
- RichText::set('shop.order_receipt_goods_notice', $requestModel['receipt_goods_notice']);
- unset($requestModel['receipt_goods_notice']);
- }
- if (Cache::has('shop_order')) {
- Cache::forget('shop_order');
- }
- $requestModel['receipt_goods_notice'] = RichText::get('shop.order_receipt_goods_notice');
- if (Setting::set('shop.order', $requestModel)) {
- return $this->successJson('订单设置成功');
- } else {
- $this->errorJson('订单设置失败');
- }
- }
- if (!empty($order['goods'])) {
- $goods = Goods::select('id', 'title', 'thumb')
- ->where('status', 1)
- ->whereIn('id', $order['goods'])
- ->where('plugin_id', 0)
- ->get();
- if (!$goods->isEmpty()) {
- $goods->map(function ($q) {
- return $q->thumb_url = yz_tomedia($q->thumb);
- });
- }
- } else {
- $goods = [];
- }
- $order['goods'] = array_values($order['goods']);
- return $this->successJson('请求接口成功 ', [
- 'set' => $order,
- 'goods' => $goods,
- ]);
- }
- return view('setting.shop.order');
- }
- /**
- * 模板设置
- * @return mixed
- */
- public function temp()
- {
- if (request()->ajax()) {
- $temp = Setting::get('shop.temp');
- $styles = [];//模板数据,数据如何来的待定?
- $styles_pc = [];//pc模板数据,待定
- $requestModel = \YunShop::request()->temp;
- if ($requestModel) {
- if (Setting::set('shop.temp', $requestModel)) {
- return $this->successJson('模板设置成功');
- } else {
- $this->errorJson('模板设置失败');
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $temp,
- 'styles' => $styles,
- 'styles_pc' => $styles_pc
- ]);
- }
- return view('setting.shop.temp');
- }
- /**
- * 分类层级设置
- * @return mixed
- */
- public function category()
- {
- if (request()->ajax()) {
- $category = Setting::get('shop.category');
- $category['cat_adv_img_url'] = !empty($category['cat_adv_img_url']) ? $category['cat_adv_img_url'] : yz_tomedia($category['cat_adv_img']);
- $requestModel = request()->category;
- if ($requestModel) {
- if (Setting::set('shop.category', $requestModel)) {
- if (Cache::has('shop_category')) {
- Cache::forget('shop_category');
- }
- return $this->successJson(' 分类层级设置成功');
- } else {
- $this->errorJson('分类层级设置失败');
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $category,
- ]);
- }
- return view('setting.shop.category');
- }
- /**
- * 联系方式设置
- * @return mixed
- */
- public function contact()
- {
- if (request()->ajax()) {
- $contact = Setting::get('shop.contact');
- $requestModel = request()->contact;
- if ($requestModel) {
- if (Setting::set('shop.contact', $requestModel)) {
- return $this->successJson(' 联系方式设置成功');
- } else {
- $this->errorJson('联系方式设置失败');
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $contact,
- ]);
- }
- return view('setting.shop.contact');
- }
- /**
- * 短信设置
- * @return mixed
- */
- public function sms()
- {
- if (request()->ajax()) {
- $sms = Setting::get('shop.sms');
- $requestModel = request()->sms;
- if ($requestModel) {
- if (Setting::set('shop.sms', $requestModel)) {
- return $this->successJson(' 短信设置成功', Url::absoluteWeb('setting.shop.sms'));
- } else {
- $this->errorJson('短信设置失败', Url::absoluteWeb('setting.shop.sms'));
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $sms,
- ]);
- }
- return view('setting.shop.sms');
- }
- //验证码测试
- public static function captchapp()
- {
- $phrase = new PhraseBuilder();
- $code = $phrase->build(4);
- $builder = new CaptchaBuilder($code, $phrase);
- $builder->setBackgroundColor(150, 150, 150);
- $builder->setMaxAngle(25);
- $builder->setMaxBehindLines(0);
- $builder->setMaxFrontLines(0);
- $builder->build($width = 100, $height = 40, $font = null);
- $phrase = $builder->getPhrase();
- \Session::flash('code', $phrase);
- header('Cache-Control: no-cache, must-revalidate');
- header('Content-Type: image/jpeg');
- $builder->output();
- }
- /**
- * 分享引导设置
- * @return mixed
- */
- public function share()
- {
- if (request()->ajax()) {
- $share = Setting::get('shop.share');
- $share['follow_img_url'] = !empty($share['follow_img_url']) ? $share['follow_img_url'] : yz_tomedia($share['follow_img']);
- $share['icon_url'] = !empty($share['icon_url']) ? $share['icon_url'] : yz_tomedia($share['icon']);
- $requestModel = request()->share;
- if ($requestModel) {
- if (Setting::set('shop.share', $requestModel)) {
- return $this->successJson(' 引导分享设置成功');
- } else {
- $this->errorJson('引导分享设置失败');
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $share,
- ]);
- }
- return view('setting.shop.share');
- }
- /**
- * 消息提醒设置
- * @return mixed
- */
- public function notice()
- {
- if (request()->ajax()) {
- $default_temp_id = MessageTemp::getDefaultList();
- $notice = Setting::get('shop.notice');
- $default_temp = $this->getIsDefaultTemp($default_temp_id, $notice);
- $requestModel = request()->yz_notice;
- $temp_list = MessageTemp::getList()->toArray();
- if (!empty($requestModel)) {
- foreach ($requestModel['salers'] as $key => &$item) {
- $item['openid'] = $item['has_one_fans']['openid'];
- unset($item['has_one_fans']);
- }
- if (Setting::set('shop.notice', $requestModel)) {
- return $this->successJson(' 消息提醒设置成功');
- } else {
- $this->errorJson('消息提醒设置失败');
- }
- }
- foreach ($notice['salers'] as $key => &$item) {
- if (strstr($item['avatar'], 'http') && !strstr($item['avatar'], 'https')) {
- $item['avatar'] = str_replace('http', 'https', $item['avatar']);
- }
- }
- $notice['salers'] = array_values($notice['salers']);
- return $this->successJson('请求接口成功', [
- 'set' => $notice,
- 'temp_list' => $temp_list,
- 'default_temp' => $default_temp,
- ]);
- }
- return view('setting.shop.notice');
- }
- private function getIsDefaultTemp($default_temp_id, $notice)
- {
- $default_temp = [];
- foreach ($notice as $k => $value) {
- if (in_array($value, $default_temp_id)) {
- $default_temp[$k] = 1;
- } else {
- $default_temp[$k] = 0;
- }
- }
- unset($default_temp['toggle'], $default_temp['salers']);
- return $default_temp;
- }
- /**
- * 小程序消息提醒设置
- * @return mixed
- */
- public function miniNotice()
- {
- $notice = Setting::get('shop.miniNotice');
- // $salers = []; //订单通知的商家列表,数据如何取待定?
- //$new_type = []; //通知方式的数组,数据如何来的待定?
- $requestModel = \YunShop::request()->yz_notice;
- $temp_list = MessageTemp::getList();
- if (!empty($requestModel)) {
- if (Setting::set('shop.miniNotice', $requestModel)) {
- return $this->message(' 消息提醒设置成功', Url::absoluteWeb('setting.shop.notice'));
- } else {
- $this->error('消息提醒设置失败');
- }
- }
- return view('setting.shop.mini-notice', [
- 'set' => $notice,
- 'temp_list' => $temp_list
- ])->render();
- }
- /**
- * 交易设置
- * @return mixed
- */
- public function trade()
- {
- if (request()->ajax()) {
- $trade = Setting::get('shop.trade');
- $requestModel = request()->trade;
- if ($requestModel) {
- if (Setting::set('shop.trade', $requestModel)) {
- (new \app\common\services\operation\SettingLog('shop.trade'))->recordLog($trade, $requestModel);
- return $this->successJson(' 交易设置成功');
- } else {
- return $this->errorJson('交易设置失败');
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $trade
- ]);
- }
- return view('setting.shop.trade')->render();
- }
- /**
- * 支付方式设置
- * @return mixed
- */
- //支付设置上传文件接口
- public function newUpload()
- {
- $updatefile = $this->updateFile($_FILES);
- if (!is_null($updatefile)) {
- if ($updatefile['status'] == -1) {
- return $this->errorJson('上传文件类型错误', Url::absoluteWeb('setting.shop.pay'));
- }
- if ($updatefile['status'] == 0) {
- return $this->errorJson('上传文件失败', Url::absoluteWeb('setting.shop.pay'));
- }
- return $this->successJson('文件上传成功', ['data' => $updatefile]);
- } else {
- return $this->errorJson('上传文件类型错误', Url::absoluteWeb('setting.shop.pay'));
- }
- }
- public function pay()
- {
- $pay = Setting::get('shop.pay');
- $account = AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid);
- if (empty($pay['weixin_appid']) && empty($pay['weixin_secret']) && !empty($account)) {
- $pay['weixin_appid'] = $account->key;
- $pay['weixin_secret'] = $account->secret;
- }
- $data = [
- 'weixin_jie_cert' => '',
- 'weixin_jie_key' => '',
- 'weixin_jie_root' => ''
- ];//借用微信支付证书,在哪里取得数据待定?
- if (request()->ajax()) {
- $requestModel = request()->pay;
- if (isset($requestModel['weixin_version']) && $requestModel['weixin_version'] == 1) {
- if (!empty($requestModel['new_weixin_cert']) && !empty($requestModel['new_weixin_key'])) {
- $updatefile_v2 = $this->updateFileV2(['weixin_cert' => $requestModel['new_weixin_cert'], 'weixin_key' => $requestModel['new_weixin_key']]);
- if ($updatefile_v2['status'] == 0) {
- return $this->errorJson('文件保存失败1', Url::absoluteWeb('setting.shop.pay'));
- }
- $requestModel = array_merge($requestModel, $updatefile_v2['data']);
- }
- }
- if (isset($pay['secret']) && 1 == $pay['secret']) {
- Utils::dataEncrypt($requestModel);
- }
- if (Setting::set('shop.pay', $requestModel)) {
- (new \app\common\services\operation\ShopPayLog(['old' => $pay, 'new' => $requestModel], 'update'));
- $this->setAlipayParams($requestModel);
- return $this->successJson('支付方式设置成功', Url::absoluteWeb('setting.shop.pay'));
- } else {
- $this->errorJson('支付方式设置失败');
- }
- }
- if (isset($pay['secret']) && 1 == $pay['secret']) {
- try {
- Utils::dataDecrypt($pay);
- } catch (\Exception $e) {
- \Log::debug('------error msg------', [$e->getMessage()]);
- }
- }
- return view('setting.shop.pay', [
- 'set' => json_encode($pay),
- 'data' => json_encode($data),
- ])->render();
- }
- private function setAlipayParams($data)
- {
- Setting::set('alipay.pem', storage_path() . '/cert/cacert.pem');
- Setting::set('alipay.partner_id', $data['alipay_partner']);
- Setting::set('alipay.seller_id', $data['alipay_account']);
- Setting::set('alipay-mobile.sign_type', 'RSA');
- Setting::set('alipay-mobile.private_key_path', storage_path() . '/cert/private_key.pem');
- Setting::set('alipay-mobile.public_key_path', storage_path() . '/cert/public_key.pem');
- Setting::set('alipay-mobile.notify_url', Url::shopSchemeUrl('payment/alipay/notifyUrl.php'));
- Setting::set('alipay-web.key', $data['alipay_secret']);
- Setting::set('alipay-web.sign_type', 'MD5');
- Setting::set('alipay-web.notify_url', Url::shopSchemeUrl('payment/alipay/notifyUrl.php'));
- Setting::set('alipay-web.return_url', Url::shopSchemeUrl('payment/alipay/returnUrl.php'));
- }
- private function upload($fileinput)
- {
- $valid_ext = ['pem', 'crt'];
- $file = \Request::file($fileinput);
- if ($file->isValid()) {
- // 获取文件相关信息
- $originalName = $file->getClientOriginalName(); // 文件原名
- $ext = $file->getClientOriginalExtension(); // 扩展名
- $realPath = $file->getRealPath(); //临时文件的绝对路径
- $i = \YunShop::app()->uniacid;
- $upload_file = $i . '_' . $originalName;
- if (!in_array($ext, $valid_ext)) {
- return ['status' => -1];
- }
- $bool = \Storage::disk('cert')->put($upload_file, file_get_contents($realPath));
- return $bool ? ['status' => 1, 'file' => $originalName] : ['status' => 0];
- }
- }
- /**
- * 前端入口二维码
- *
- * @return string
- */
- public function entry()
- {
- return view('setting.shop.entry', [
- ])->render();
- }
- private function updateFile($file)
- {
- $data = [];
- $file = array_keys($file)[0];
- $update = $this->upload($file);
- if ($update['status'] == -1 || $update['status'] == 0) {
- return $update;
- }
- if ($update['status'] == 1) {
- $uniacid = \YunShop::app()->uniacid;
- $path_name = storage_path('cert/' . $uniacid . "_" . $update['file']);
- $data['key'] = $file;
- $data['value'] = $path_name;
- $data[$file] = $path_name;
- }
- if (!empty($data)) {
- return ['status' => 1, 'data' => $data];
- }
- return null;
- }
- private function updateFileV2($file_data)
- {
- $data = [];
- $uniacid = \YunShop::app()->uniacid;
- $file_suffix = '.pem';
- foreach ($file_data as $key => $value) {
- $file_name = $uniacid . "_" . $key . $file_suffix;
- $bool = \Storage::disk('cert')->put($file_name, $value);
- if ($bool) {
- $data[$key] = storage_path('cert/' . $file_name);
- } else {
- return ['status' => 0];
- }
- }
- if (!empty($data)) {
- return ['status' => 1, 'data' => $data];
- }
- return null;
- }
- /**
- * 设置分享默认值
- */
- public function shareDefault()
- {
- $share = \Setting::get('shop.share');
- if (!$share) {
- $requestModel = [
- 'follow_url' => '',
- 'title' => '',
- 'icon' => '',
- 'desc' => '',
- 'url' => ''
- ];
- \Setting::set('shop.share', $requestModel);
- }
- }
- /**
- * 设置物流查询
- */
- public function expressInfo()
- {
- if (request()->ajax()) {
- $set = LogisticsSet::uniacid()->first();//快递鸟1002状态为免费,8001状态为收费
- $statistics = [];
- if ($set->type == 2) {
- $data = unserialize($set->data);
- $data = $this->getApiFrequency($data);
- $statistics = [
- 'apiTotalCount' => $data['data']['statistics']['apiTotalCount'],
- 'statistics' => $data['data']['statistics']['apiTotalUsed'],
- 'apiTotalPrice' => $data['data']['statistics']['apiTotalPrice'],
- 'expireData' => $data['data']['data']['data'][0]['endTime'] ?: '未知'
- ];
- }
- $requestModel = request()->express_info;
- $type = request()->type;
- if ($requestModel) {
- if (!$set) {
- $set = new LogisticsSet();
- }
- $data = [
- 'uniacid' => \Yunshop::app()->uniacid,
- 'type' => $type,
- 'data' => serialize($requestModel),
- ];
- $set->setRawAttributes($data);
- $validator = $set->validator($set->getAttributes());
- if ($validator->fails()) {
- $this->error($validator->messages());
- } else {
- if ($set->save()) {
- //显示信息并跳转
- return $this->successJson(' 物流查询信息设置成功');
- } else {
- return $this->errorJson('物流查询信息设置失败');
- }
- }
- }
- $set_data = unserialize($set->data);
- if (empty($set_data['KDN']['package_type'])) {
- $set_data['KDN']['package_type'] = 1;
- }
- return $this->successJson('请求接口成功', [
- 'set' => $set_data,
- 'type' => $set->type,
- 'statistics' => $statistics
- ]);
- }
- return view('setting.shop.express_info');
- }
- public function getApiFrequency($data)
- {
- $reqURL = 'https://www.yunqiankeji.com/addons/yun_shop/api.php?i=1&uuid=0&type=5&shop_id=null&validate_page=1&scope=home&route=plugin.yunqian-api.api.recharge.query-list';
- $server_name = $_SERVER['SERVER_NAME'];
- if (strexists($server_name, 'dev')) {
- //dev环境用本地
- $reqURL = 'https://dev1.yunzmall.com/addons/yun_shop/api.php?i=2&uuid=0&type=5&shop_id=null&validate_page=1&scope=home&route=plugin.yunqian-api.api.recharge.query-list';
- }
- $pa = json_encode([
- 'apiItemId' => 3,
- 'orderField' => 'end_time',
- 'orderBy' => 'desc'
- ]);
- $app_id = trim($data['YQ']['appId']);
- $app_secret = trim($data['YQ']['appSecret']);
- $yq = new YunqianRequest($pa, $reqURL, $app_id, $app_secret);
- $result = $yq->getResult();
- return $result ?: [];
- }
- public function dataClear()
- {
- $config = \app\common\modules\shop\ShopConfig::current()->get('data-clear');
- $data = [];
- foreach ($config as $key=>$item) {
- $data[] = [
- 'plugin' => $key,
- 'name' => $item['name']
- ];
- }
- return view('setting.shop.data_clear',['data'=>$data]);
- }
- public function clearHandle()
- {
- try {
- $plugin = request()->plugin;
- $start = request()->start;
- $end = request()->end;
- if (!$start || !$end) {
- throw new \Exception('请上传时间');
- }
- $config = \app\common\modules\shop\ShopConfig::current()->get('data-clear.'.$plugin);
- if (!$config) {
- throw new \Exception('配置未找到');
- }
- $class = $config['class'];
- $function = $config['function'];
- if (!$class || !class_exists($class) || !$function || !method_exists($class,$function)) {
- throw new \Exception('配置错误');
- }
- $res = $class::$function(['start'=>$start,'end'=>$end]);
- if (!$res['status']) {
- throw new \Exception($res['msg']);
- }
- return $this->successJson($res['msg']);
- } catch (\Exception $e) {
- return $this->errorJson($e->getMessage());
- }
- }
- // public function expressInfo()
- // {
- // if(request()->ajax()){
- // $set = Setting::get('shop.express_info');//快递鸟1002状态为免费,8001状态为收费
- // $requestModel = request()->express_info;
- // $type = request()->type;
- // dd($requestModel,$type);
- // if ($requestModel) {
- // if (Setting::set('shop.express_info', $requestModel)) {
- // return $this->successJson(' 物流查询信息设置成功');
- // } else {
- // return $this->errorJson('物流查询信息设置失败');
- // }
- // }
- // return $this->successJson('请求接口成功', [
- // 'set' => $set,
- // ]);
- // }
- // return view('setting.shop.express_info');
- // }
- /**
- * 检查是否存在邀请码
- * @return \Illuminate\Http\JsonResponse
- */
- public function checkInviteCode()
- {
- $data = request()->invite_code ?: '';
- if ($data) {
- if (MemberShopInfo::where('invite_code', '=', request()->invite_code)->count() > 0) {
- return $this->successJson('请求接口成功', [
- 'data' => 1
- ]);
- } else {
- return $this->errorJson('默认邀请码有误,请重新输入', [
- 'data' => 2//不存的邀请码
- ]);
- }
- }
- return $this->successJson('请求接口成功', [
- 'data' => 0
- ]);
- }
- public function email()
- {
- if (request()->ajax()) {
- $email = Setting::get('shop.email');
- $requestModel = request()->email;
- if ($requestModel) {
- if (Setting::set('shop.email', $requestModel)) {
- return $this->successJson('邮件配置设置成功', Url::absoluteWeb('setting.shop.email'));
- } else {
- $this->errorJson('邮件配置设置失败', Url::absoluteWeb('setting.shop.email'));
- }
- }
- return $this->successJson('请求接口成功', [
- 'set' => $email,
- ]);
- }
- return view('setting.shop.email');
- }
- }
|