ShopController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/9
  6. * Time: 下午5:26
  7. */
  8. namespace app\backend\modules\setting\controllers;
  9. use app\backend\modules\goods\models\Goods;
  10. use app\backend\modules\uploadVerificate\UploadVerificationBaseController;
  11. use app\common\components\BaseController;
  12. use app\common\facades\RichText;
  13. use app\common\helpers\Cache;
  14. use app\common\helpers\Url;
  15. use app\common\facades\Setting;
  16. use app\common\models\AccountWechats;
  17. use app\common\models\Address;
  18. use app\common\models\LogisticsSet;
  19. use app\common\models\MemberLevel;
  20. use app\common\models\notice\MessageTemp;
  21. use app\common\models\Protocol;
  22. use app\common\models\Street;
  23. use app\common\modules\refund\services\RefundService;
  24. use app\common\services\MyLink;
  25. use app\common\services\Utils;
  26. use Hamcrest\Core\Set;
  27. use Mews\Captcha\Captcha;
  28. use Yunshop\Diyform\models\DiyformTypeModel;
  29. use Gregwar\Captcha\CaptchaBuilder;
  30. use Gregwar\Captcha\PhraseBuilder;
  31. use app\common\models\PayType;
  32. use app\common\models\notice\MinAppTemplateMessage;
  33. use app\backend\modules\member\models\MemberShopInfo;
  34. use app\common\services\YunqianRequest;
  35. class ShopController extends UploadVerificationBaseController
  36. {
  37. /**
  38. * 商城设置
  39. * @return mixed
  40. */
  41. public function index()
  42. {
  43. return view('setting.shop.shop');
  44. }
  45. public function shopSetInfo()
  46. {
  47. if (request()->ajax()) {
  48. $shop = Setting::get('shop.shop');
  49. $shop['logo_url'] = !empty($shop['logo_url']) ? $shop['logo_url'] : yz_tomedia($shop['logo']);
  50. $shop['signimg_url'] = !empty($shop['signimg_url']) ? $shop['signimg_url'] : yz_tomedia($shop['signimg']);
  51. $shop['copyrightImg_url'] = !empty($shop['copyrightImg_url']) ? $shop['copyrightImg_url'] : yz_tomedia($shop['copyrightImg']);
  52. $level = MemberLevel::get(['id', 'level_name']);
  53. $requestModel = request()->shop;
  54. if ($requestModel) {
  55. if (Cache::has('shop_setting')) {
  56. Cache::forget('shop_setting');
  57. }
  58. $requestModel['credit'] = empty($requestModel['credit']) ? "余额" : $requestModel['credit'];
  59. if (Setting::set('shop.shop', $requestModel)) {
  60. return $this->successJson('商城设置成功');
  61. } else {
  62. return $this->errorJson('商城设置失败');
  63. }
  64. }
  65. return $this->successJson('请求接口成功', [
  66. 'shop' => $shop,
  67. 'level' => $level,
  68. ]);
  69. }
  70. }
  71. /**
  72. * 会员设置
  73. * @return mixed
  74. */
  75. public function member()
  76. {
  77. if (request()->ajax()) {
  78. $member = Setting::get('shop.member');
  79. $shop = Setting::get('shop.shop');
  80. $requestModel = request()->member;
  81. $member['headimg_url'] = !empty($member['headimg_url']) ? $member['headimg_url'] : yz_tomedia($member['headimg']);
  82. if ($requestModel) {
  83. if ($requestModel['is_bind_mobile'] !== '0' && $requestModel['invite_page'] == '1') {
  84. return $this->errorJson('强制绑定手机号跟邀请页面不能同时开启');
  85. }
  86. if (Cache::has('shop_member')) {
  87. Cache::forget('shop_member');
  88. }
  89. if (Setting::set('shop.member', $requestModel)) {
  90. return $this->successJson('会员设置成功');
  91. } else {
  92. $this->errorJson('会员设置失败');
  93. }
  94. }
  95. $is_diyform = \YunShop::plugin()->get('diyform');
  96. $diyForm = [];
  97. if ($is_diyform) {
  98. $diyForm = DiyformTypeModel::getDiyformList()->get();
  99. }
  100. return $this->successJson('成功', [
  101. 'set' => $member,
  102. 'shop' => $shop,
  103. 'is_diyform' => $is_diyform,
  104. 'diyForm' => $diyForm,
  105. ]);
  106. }
  107. return view('setting.shop.member')->render();
  108. }
  109. /**
  110. * 会员设置
  111. * @return mixed
  112. */
  113. public function register()
  114. {
  115. $register = Setting::get('shop.register');
  116. $requestModel = request()->register;
  117. if ($requestModel) {
  118. if (Cache::has('shop_register')) {
  119. Cache::forget('shop_register');
  120. }
  121. if (!empty($requestModel['protocol'])) {
  122. $shop = Protocol::uniacid()->first();
  123. if (empty($shop)) {
  124. $shop = new Protocol();
  125. $shop->uniacid = \YunShop::app()->uniacid;
  126. }
  127. $shop->status = $requestModel['protocol']['status'];
  128. $shop->title = $requestModel['protocol']['title'];
  129. $shop->content = $requestModel['protocol']['content'];
  130. $shop->save();
  131. $requestModel['protocol']['content'] = '';
  132. }
  133. unset($requestModel['protocol']['content']);
  134. if (Setting::set('shop.register', $requestModel)) {
  135. return $this->successJson('设置成功', Url::absoluteWeb('setting.shop.register'));
  136. } else {
  137. $this->errorJson('设置失败');
  138. }
  139. }
  140. $protocol = Protocol::uniacid()->first();
  141. return view('setting.shop.register', [
  142. 'register' => $register,
  143. 'protocol' => $protocol,
  144. ])->render();
  145. }
  146. /**
  147. * 订单设置
  148. * @return mixed|string
  149. * @throws \Throwable
  150. */
  151. public function order()
  152. {
  153. if (request()->ajax()) {
  154. $order = Setting::get('shop.order');
  155. $requestModel = request()->order;
  156. if ($requestModel) {
  157. if ($requestModel['receipt_goods_notice']) {
  158. RichText::set('shop.order_receipt_goods_notice', $requestModel['receipt_goods_notice']);
  159. unset($requestModel['receipt_goods_notice']);
  160. }
  161. if (Cache::has('shop_order')) {
  162. Cache::forget('shop_order');
  163. }
  164. $requestModel['receipt_goods_notice'] = RichText::get('shop.order_receipt_goods_notice');
  165. if (Setting::set('shop.order', $requestModel)) {
  166. return $this->successJson('订单设置成功');
  167. } else {
  168. $this->errorJson('订单设置失败');
  169. }
  170. }
  171. if (!empty($order['goods'])) {
  172. $goods = Goods::select('id', 'title', 'thumb')
  173. ->where('status', 1)
  174. ->whereIn('id', $order['goods'])
  175. ->where('plugin_id', 0)
  176. ->get();
  177. if (!$goods->isEmpty()) {
  178. $goods->map(function ($q) {
  179. return $q->thumb_url = yz_tomedia($q->thumb);
  180. });
  181. }
  182. } else {
  183. $goods = [];
  184. }
  185. $order['goods'] = array_values($order['goods']);
  186. return $this->successJson('请求接口成功 ', [
  187. 'set' => $order,
  188. 'goods' => $goods,
  189. ]);
  190. }
  191. return view('setting.shop.order');
  192. }
  193. /**
  194. * 模板设置
  195. * @return mixed
  196. */
  197. public function temp()
  198. {
  199. if (request()->ajax()) {
  200. $temp = Setting::get('shop.temp');
  201. $styles = [];//模板数据,数据如何来的待定?
  202. $styles_pc = [];//pc模板数据,待定
  203. $requestModel = \YunShop::request()->temp;
  204. if ($requestModel) {
  205. if (Setting::set('shop.temp', $requestModel)) {
  206. return $this->successJson('模板设置成功');
  207. } else {
  208. $this->errorJson('模板设置失败');
  209. }
  210. }
  211. return $this->successJson('请求接口成功', [
  212. 'set' => $temp,
  213. 'styles' => $styles,
  214. 'styles_pc' => $styles_pc
  215. ]);
  216. }
  217. return view('setting.shop.temp');
  218. }
  219. /**
  220. * 分类层级设置
  221. * @return mixed
  222. */
  223. public function category()
  224. {
  225. if (request()->ajax()) {
  226. $category = Setting::get('shop.category');
  227. $category['cat_adv_img_url'] = !empty($category['cat_adv_img_url']) ? $category['cat_adv_img_url'] : yz_tomedia($category['cat_adv_img']);
  228. $requestModel = request()->category;
  229. if ($requestModel) {
  230. if (Setting::set('shop.category', $requestModel)) {
  231. if (Cache::has('shop_category')) {
  232. Cache::forget('shop_category');
  233. }
  234. return $this->successJson(' 分类层级设置成功');
  235. } else {
  236. $this->errorJson('分类层级设置失败');
  237. }
  238. }
  239. return $this->successJson('请求接口成功', [
  240. 'set' => $category,
  241. ]);
  242. }
  243. return view('setting.shop.category');
  244. }
  245. /**
  246. * 联系方式设置
  247. * @return mixed
  248. */
  249. public function contact()
  250. {
  251. if (request()->ajax()) {
  252. $contact = Setting::get('shop.contact');
  253. $requestModel = request()->contact;
  254. if ($requestModel) {
  255. if (Setting::set('shop.contact', $requestModel)) {
  256. return $this->successJson(' 联系方式设置成功');
  257. } else {
  258. $this->errorJson('联系方式设置失败');
  259. }
  260. }
  261. return $this->successJson('请求接口成功', [
  262. 'set' => $contact,
  263. ]);
  264. }
  265. return view('setting.shop.contact');
  266. }
  267. /**
  268. * 短信设置
  269. * @return mixed
  270. */
  271. public function sms()
  272. {
  273. if (request()->ajax()) {
  274. $sms = Setting::get('shop.sms');
  275. $requestModel = request()->sms;
  276. if ($requestModel) {
  277. if (Setting::set('shop.sms', $requestModel)) {
  278. return $this->successJson(' 短信设置成功', Url::absoluteWeb('setting.shop.sms'));
  279. } else {
  280. $this->errorJson('短信设置失败', Url::absoluteWeb('setting.shop.sms'));
  281. }
  282. }
  283. return $this->successJson('请求接口成功', [
  284. 'set' => $sms,
  285. ]);
  286. }
  287. return view('setting.shop.sms');
  288. }
  289. //验证码测试
  290. public static function captchapp()
  291. {
  292. $phrase = new PhraseBuilder();
  293. $code = $phrase->build(4);
  294. $builder = new CaptchaBuilder($code, $phrase);
  295. $builder->setBackgroundColor(150, 150, 150);
  296. $builder->setMaxAngle(25);
  297. $builder->setMaxBehindLines(0);
  298. $builder->setMaxFrontLines(0);
  299. $builder->build($width = 100, $height = 40, $font = null);
  300. $phrase = $builder->getPhrase();
  301. \Session::flash('code', $phrase);
  302. header('Cache-Control: no-cache, must-revalidate');
  303. header('Content-Type: image/jpeg');
  304. $builder->output();
  305. }
  306. /**
  307. * 分享引导设置
  308. * @return mixed
  309. */
  310. public function share()
  311. {
  312. if (request()->ajax()) {
  313. $share = Setting::get('shop.share');
  314. $share['follow_img_url'] = !empty($share['follow_img_url']) ? $share['follow_img_url'] : yz_tomedia($share['follow_img']);
  315. $share['icon_url'] = !empty($share['icon_url']) ? $share['icon_url'] : yz_tomedia($share['icon']);
  316. $requestModel = request()->share;
  317. if ($requestModel) {
  318. if (Setting::set('shop.share', $requestModel)) {
  319. return $this->successJson(' 引导分享设置成功');
  320. } else {
  321. $this->errorJson('引导分享设置失败');
  322. }
  323. }
  324. return $this->successJson('请求接口成功', [
  325. 'set' => $share,
  326. ]);
  327. }
  328. return view('setting.shop.share');
  329. }
  330. /**
  331. * 消息提醒设置
  332. * @return mixed
  333. */
  334. public function notice()
  335. {
  336. if (request()->ajax()) {
  337. $default_temp_id = MessageTemp::getDefaultList();
  338. $notice = Setting::get('shop.notice');
  339. $default_temp = $this->getIsDefaultTemp($default_temp_id, $notice);
  340. $requestModel = request()->yz_notice;
  341. $temp_list = MessageTemp::getList()->toArray();
  342. if (!empty($requestModel)) {
  343. foreach ($requestModel['salers'] as $key => &$item) {
  344. $item['openid'] = $item['has_one_fans']['openid'];
  345. unset($item['has_one_fans']);
  346. }
  347. if (Setting::set('shop.notice', $requestModel)) {
  348. return $this->successJson(' 消息提醒设置成功');
  349. } else {
  350. $this->errorJson('消息提醒设置失败');
  351. }
  352. }
  353. foreach ($notice['salers'] as $key => &$item) {
  354. if (strstr($item['avatar'], 'http') && !strstr($item['avatar'], 'https')) {
  355. $item['avatar'] = str_replace('http', 'https', $item['avatar']);
  356. }
  357. }
  358. $notice['salers'] = array_values($notice['salers']);
  359. return $this->successJson('请求接口成功', [
  360. 'set' => $notice,
  361. 'temp_list' => $temp_list,
  362. 'default_temp' => $default_temp,
  363. ]);
  364. }
  365. return view('setting.shop.notice');
  366. }
  367. private function getIsDefaultTemp($default_temp_id, $notice)
  368. {
  369. $default_temp = [];
  370. foreach ($notice as $k => $value) {
  371. if (in_array($value, $default_temp_id)) {
  372. $default_temp[$k] = 1;
  373. } else {
  374. $default_temp[$k] = 0;
  375. }
  376. }
  377. unset($default_temp['toggle'], $default_temp['salers']);
  378. return $default_temp;
  379. }
  380. /**
  381. * 小程序消息提醒设置
  382. * @return mixed
  383. */
  384. public function miniNotice()
  385. {
  386. $notice = Setting::get('shop.miniNotice');
  387. // $salers = []; //订单通知的商家列表,数据如何取待定?
  388. //$new_type = []; //通知方式的数组,数据如何来的待定?
  389. $requestModel = \YunShop::request()->yz_notice;
  390. $temp_list = MessageTemp::getList();
  391. if (!empty($requestModel)) {
  392. if (Setting::set('shop.miniNotice', $requestModel)) {
  393. return $this->message(' 消息提醒设置成功', Url::absoluteWeb('setting.shop.notice'));
  394. } else {
  395. $this->error('消息提醒设置失败');
  396. }
  397. }
  398. return view('setting.shop.mini-notice', [
  399. 'set' => $notice,
  400. 'temp_list' => $temp_list
  401. ])->render();
  402. }
  403. /**
  404. * 交易设置
  405. * @return mixed
  406. */
  407. public function trade()
  408. {
  409. if (request()->ajax()) {
  410. $trade = Setting::get('shop.trade');
  411. $requestModel = request()->trade;
  412. if ($requestModel) {
  413. if (Setting::set('shop.trade', $requestModel)) {
  414. (new \app\common\services\operation\SettingLog('shop.trade'))->recordLog($trade, $requestModel);
  415. return $this->successJson(' 交易设置成功');
  416. } else {
  417. return $this->errorJson('交易设置失败');
  418. }
  419. }
  420. return $this->successJson('请求接口成功', [
  421. 'set' => $trade
  422. ]);
  423. }
  424. return view('setting.shop.trade')->render();
  425. }
  426. /**
  427. * 支付方式设置
  428. * @return mixed
  429. */
  430. //支付设置上传文件接口
  431. public function newUpload()
  432. {
  433. $updatefile = $this->updateFile($_FILES);
  434. if (!is_null($updatefile)) {
  435. if ($updatefile['status'] == -1) {
  436. return $this->errorJson('上传文件类型错误', Url::absoluteWeb('setting.shop.pay'));
  437. }
  438. if ($updatefile['status'] == 0) {
  439. return $this->errorJson('上传文件失败', Url::absoluteWeb('setting.shop.pay'));
  440. }
  441. return $this->successJson('文件上传成功', ['data' => $updatefile]);
  442. } else {
  443. return $this->errorJson('上传文件类型错误', Url::absoluteWeb('setting.shop.pay'));
  444. }
  445. }
  446. public function pay()
  447. {
  448. $pay = Setting::get('shop.pay');
  449. $account = AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid);
  450. if (empty($pay['weixin_appid']) && empty($pay['weixin_secret']) && !empty($account)) {
  451. $pay['weixin_appid'] = $account->key;
  452. $pay['weixin_secret'] = $account->secret;
  453. }
  454. $data = [
  455. 'weixin_jie_cert' => '',
  456. 'weixin_jie_key' => '',
  457. 'weixin_jie_root' => ''
  458. ];//借用微信支付证书,在哪里取得数据待定?
  459. if (request()->ajax()) {
  460. $requestModel = request()->pay;
  461. if (isset($requestModel['weixin_version']) && $requestModel['weixin_version'] == 1) {
  462. if (!empty($requestModel['new_weixin_cert']) && !empty($requestModel['new_weixin_key'])) {
  463. $updatefile_v2 = $this->updateFileV2(['weixin_cert' => $requestModel['new_weixin_cert'], 'weixin_key' => $requestModel['new_weixin_key']]);
  464. if ($updatefile_v2['status'] == 0) {
  465. return $this->errorJson('文件保存失败1', Url::absoluteWeb('setting.shop.pay'));
  466. }
  467. $requestModel = array_merge($requestModel, $updatefile_v2['data']);
  468. }
  469. }
  470. if (isset($pay['secret']) && 1 == $pay['secret']) {
  471. Utils::dataEncrypt($requestModel);
  472. }
  473. if (Setting::set('shop.pay', $requestModel)) {
  474. (new \app\common\services\operation\ShopPayLog(['old' => $pay, 'new' => $requestModel], 'update'));
  475. $this->setAlipayParams($requestModel);
  476. return $this->successJson('支付方式设置成功', Url::absoluteWeb('setting.shop.pay'));
  477. } else {
  478. $this->errorJson('支付方式设置失败');
  479. }
  480. }
  481. if (isset($pay['secret']) && 1 == $pay['secret']) {
  482. try {
  483. Utils::dataDecrypt($pay);
  484. } catch (\Exception $e) {
  485. \Log::debug('------error msg------', [$e->getMessage()]);
  486. }
  487. }
  488. return view('setting.shop.pay', [
  489. 'set' => json_encode($pay),
  490. 'data' => json_encode($data),
  491. ])->render();
  492. }
  493. private function setAlipayParams($data)
  494. {
  495. Setting::set('alipay.pem', storage_path() . '/cert/cacert.pem');
  496. Setting::set('alipay.partner_id', $data['alipay_partner']);
  497. Setting::set('alipay.seller_id', $data['alipay_account']);
  498. Setting::set('alipay-mobile.sign_type', 'RSA');
  499. Setting::set('alipay-mobile.private_key_path', storage_path() . '/cert/private_key.pem');
  500. Setting::set('alipay-mobile.public_key_path', storage_path() . '/cert/public_key.pem');
  501. Setting::set('alipay-mobile.notify_url', Url::shopSchemeUrl('payment/alipay/notifyUrl.php'));
  502. Setting::set('alipay-web.key', $data['alipay_secret']);
  503. Setting::set('alipay-web.sign_type', 'MD5');
  504. Setting::set('alipay-web.notify_url', Url::shopSchemeUrl('payment/alipay/notifyUrl.php'));
  505. Setting::set('alipay-web.return_url', Url::shopSchemeUrl('payment/alipay/returnUrl.php'));
  506. }
  507. private function upload($fileinput)
  508. {
  509. $valid_ext = ['pem', 'crt'];
  510. $file = \Request::file($fileinput);
  511. if ($file->isValid()) {
  512. // 获取文件相关信息
  513. $originalName = $file->getClientOriginalName(); // 文件原名
  514. $ext = $file->getClientOriginalExtension(); // 扩展名
  515. $realPath = $file->getRealPath(); //临时文件的绝对路径
  516. $i = \YunShop::app()->uniacid;
  517. $upload_file = $i . '_' . $originalName;
  518. if (!in_array($ext, $valid_ext)) {
  519. return ['status' => -1];
  520. }
  521. $bool = \Storage::disk('cert')->put($upload_file, file_get_contents($realPath));
  522. return $bool ? ['status' => 1, 'file' => $originalName] : ['status' => 0];
  523. }
  524. }
  525. /**
  526. * 前端入口二维码
  527. *
  528. * @return string
  529. */
  530. public function entry()
  531. {
  532. return view('setting.shop.entry', [
  533. ])->render();
  534. }
  535. private function updateFile($file)
  536. {
  537. $data = [];
  538. $file = array_keys($file)[0];
  539. $update = $this->upload($file);
  540. if ($update['status'] == -1 || $update['status'] == 0) {
  541. return $update;
  542. }
  543. if ($update['status'] == 1) {
  544. $uniacid = \YunShop::app()->uniacid;
  545. $path_name = storage_path('cert/' . $uniacid . "_" . $update['file']);
  546. $data['key'] = $file;
  547. $data['value'] = $path_name;
  548. $data[$file] = $path_name;
  549. }
  550. if (!empty($data)) {
  551. return ['status' => 1, 'data' => $data];
  552. }
  553. return null;
  554. }
  555. private function updateFileV2($file_data)
  556. {
  557. $data = [];
  558. $uniacid = \YunShop::app()->uniacid;
  559. $file_suffix = '.pem';
  560. foreach ($file_data as $key => $value) {
  561. $file_name = $uniacid . "_" . $key . $file_suffix;
  562. $bool = \Storage::disk('cert')->put($file_name, $value);
  563. if ($bool) {
  564. $data[$key] = storage_path('cert/' . $file_name);
  565. } else {
  566. return ['status' => 0];
  567. }
  568. }
  569. if (!empty($data)) {
  570. return ['status' => 1, 'data' => $data];
  571. }
  572. return null;
  573. }
  574. /**
  575. * 设置分享默认值
  576. */
  577. public function shareDefault()
  578. {
  579. $share = \Setting::get('shop.share');
  580. if (!$share) {
  581. $requestModel = [
  582. 'follow_url' => '',
  583. 'title' => '',
  584. 'icon' => '',
  585. 'desc' => '',
  586. 'url' => ''
  587. ];
  588. \Setting::set('shop.share', $requestModel);
  589. }
  590. }
  591. /**
  592. * 设置物流查询
  593. */
  594. public function expressInfo()
  595. {
  596. if (request()->ajax()) {
  597. $set = LogisticsSet::uniacid()->first();//快递鸟1002状态为免费,8001状态为收费
  598. $statistics = [];
  599. if ($set->type == 2) {
  600. $data = unserialize($set->data);
  601. $data = $this->getApiFrequency($data);
  602. $statistics = [
  603. 'apiTotalCount' => $data['data']['statistics']['apiTotalCount'],
  604. 'statistics' => $data['data']['statistics']['apiTotalUsed'],
  605. 'apiTotalPrice' => $data['data']['statistics']['apiTotalPrice'],
  606. 'expireData' => $data['data']['data']['data'][0]['endTime'] ?: '未知'
  607. ];
  608. }
  609. $requestModel = request()->express_info;
  610. $type = request()->type;
  611. if ($requestModel) {
  612. if (!$set) {
  613. $set = new LogisticsSet();
  614. }
  615. $data = [
  616. 'uniacid' => \Yunshop::app()->uniacid,
  617. 'type' => $type,
  618. 'data' => serialize($requestModel),
  619. ];
  620. $set->setRawAttributes($data);
  621. $validator = $set->validator($set->getAttributes());
  622. if ($validator->fails()) {
  623. $this->error($validator->messages());
  624. } else {
  625. if ($set->save()) {
  626. //显示信息并跳转
  627. return $this->successJson(' 物流查询信息设置成功');
  628. } else {
  629. return $this->errorJson('物流查询信息设置失败');
  630. }
  631. }
  632. }
  633. $set_data = unserialize($set->data);
  634. if (empty($set_data['KDN']['package_type'])) {
  635. $set_data['KDN']['package_type'] = 1;
  636. }
  637. return $this->successJson('请求接口成功', [
  638. 'set' => $set_data,
  639. 'type' => $set->type,
  640. 'statistics' => $statistics
  641. ]);
  642. }
  643. return view('setting.shop.express_info');
  644. }
  645. public function getApiFrequency($data)
  646. {
  647. $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';
  648. $server_name = $_SERVER['SERVER_NAME'];
  649. if (strexists($server_name, 'dev')) {
  650. //dev环境用本地
  651. $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';
  652. }
  653. $pa = json_encode([
  654. 'apiItemId' => 3,
  655. 'orderField' => 'end_time',
  656. 'orderBy' => 'desc'
  657. ]);
  658. $app_id = trim($data['YQ']['appId']);
  659. $app_secret = trim($data['YQ']['appSecret']);
  660. $yq = new YunqianRequest($pa, $reqURL, $app_id, $app_secret);
  661. $result = $yq->getResult();
  662. return $result ?: [];
  663. }
  664. public function dataClear()
  665. {
  666. $config = \app\common\modules\shop\ShopConfig::current()->get('data-clear');
  667. $data = [];
  668. foreach ($config as $key=>$item) {
  669. $data[] = [
  670. 'plugin' => $key,
  671. 'name' => $item['name']
  672. ];
  673. }
  674. return view('setting.shop.data_clear',['data'=>$data]);
  675. }
  676. public function clearHandle()
  677. {
  678. try {
  679. $plugin = request()->plugin;
  680. $start = request()->start;
  681. $end = request()->end;
  682. if (!$start || !$end) {
  683. throw new \Exception('请上传时间');
  684. }
  685. $config = \app\common\modules\shop\ShopConfig::current()->get('data-clear.'.$plugin);
  686. if (!$config) {
  687. throw new \Exception('配置未找到');
  688. }
  689. $class = $config['class'];
  690. $function = $config['function'];
  691. if (!$class || !class_exists($class) || !$function || !method_exists($class,$function)) {
  692. throw new \Exception('配置错误');
  693. }
  694. $res = $class::$function(['start'=>$start,'end'=>$end]);
  695. if (!$res['status']) {
  696. throw new \Exception($res['msg']);
  697. }
  698. return $this->successJson($res['msg']);
  699. } catch (\Exception $e) {
  700. return $this->errorJson($e->getMessage());
  701. }
  702. }
  703. // public function expressInfo()
  704. // {
  705. // if(request()->ajax()){
  706. // $set = Setting::get('shop.express_info');//快递鸟1002状态为免费,8001状态为收费
  707. // $requestModel = request()->express_info;
  708. // $type = request()->type;
  709. // dd($requestModel,$type);
  710. // if ($requestModel) {
  711. // if (Setting::set('shop.express_info', $requestModel)) {
  712. // return $this->successJson(' 物流查询信息设置成功');
  713. // } else {
  714. // return $this->errorJson('物流查询信息设置失败');
  715. // }
  716. // }
  717. // return $this->successJson('请求接口成功', [
  718. // 'set' => $set,
  719. // ]);
  720. // }
  721. // return view('setting.shop.express_info');
  722. // }
  723. /**
  724. * 检查是否存在邀请码
  725. * @return \Illuminate\Http\JsonResponse
  726. */
  727. public function checkInviteCode()
  728. {
  729. $data = request()->invite_code ?: '';
  730. if ($data) {
  731. if (MemberShopInfo::where('invite_code', '=', request()->invite_code)->count() > 0) {
  732. return $this->successJson('请求接口成功', [
  733. 'data' => 1
  734. ]);
  735. } else {
  736. return $this->errorJson('默认邀请码有误,请重新输入', [
  737. 'data' => 2//不存的邀请码
  738. ]);
  739. }
  740. }
  741. return $this->successJson('请求接口成功', [
  742. 'data' => 0
  743. ]);
  744. }
  745. public function email()
  746. {
  747. if (request()->ajax()) {
  748. $email = Setting::get('shop.email');
  749. $requestModel = request()->email;
  750. if ($requestModel) {
  751. if (Setting::set('shop.email', $requestModel)) {
  752. return $this->successJson('邮件配置设置成功', Url::absoluteWeb('setting.shop.email'));
  753. } else {
  754. $this->errorJson('邮件配置设置失败', Url::absoluteWeb('setting.shop.email'));
  755. }
  756. }
  757. return $this->successJson('请求接口成功', [
  758. 'set' => $email,
  759. ]);
  760. }
  761. return view('setting.shop.email');
  762. }
  763. }