Common.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api;
  12. use app\common\repositories\delivery\DeliveryOrderRepository;
  13. use app\common\repositories\store\product\ProductAssistSetRepository;
  14. use app\common\repositories\store\product\ProductGroupBuyingRepository;
  15. use app\common\repositories\store\product\ProductGroupRepository;
  16. use app\common\repositories\store\product\ProductPresellRepository;
  17. use app\common\repositories\store\product\ProductRepository;
  18. use app\common\repositories\store\shipping\ExpressRepository;
  19. use app\common\repositories\store\StoreCategoryRepository;
  20. use app\common\repositories\system\attachment\AttachmentCategoryRepository;
  21. use app\common\repositories\system\attachment\AttachmentRepository;
  22. use app\common\repositories\system\CacheRepository;
  23. use app\common\repositories\system\diy\DiyRepository;
  24. use app\common\repositories\system\groupData\GroupDataRepository;
  25. use app\common\repositories\system\groupData\GroupRepository;
  26. use app\common\repositories\system\merchant\MerchantRepository;
  27. use app\common\repositories\system\notice\SystemNoticeConfigRepository;
  28. use app\common\repositories\user\UserRepository;
  29. use app\common\repositories\user\UserSignRepository;
  30. use app\common\repositories\user\UserVisitRepository;
  31. use app\common\repositories\wechat\TemplateMessageRepository;
  32. use app\common\repositories\wechat\WechatUserRepository;
  33. use crmeb\basic\BaseController;
  34. use crmeb\services\AlipayService;
  35. use crmeb\services\CopyCommand;
  36. use crmeb\services\ImageWaterMarkService;
  37. use crmeb\services\MiniProgramService;
  38. use crmeb\services\UploadService;
  39. use crmeb\services\WechatService;
  40. use Exception;
  41. use Joypack\Tencent\Map\Bundle\Location;
  42. use Joypack\Tencent\Map\Bundle\LocationOption;
  43. use think\exception\ValidateException;
  44. use think\facade\Cache;
  45. use think\facade\Log;
  46. use think\Response;
  47. use app\controller\api\store\product\BindSpreadTrait;
  48. /**
  49. * Class Common
  50. * @package app\controller\api
  51. * @author xaboy
  52. * @day 2020/5/28
  53. */
  54. class Common extends BaseController
  55. {
  56. use BindSpreadTrait;
  57. /**
  58. * @return mixed
  59. * @author xaboy
  60. * @day 2020/5/28
  61. */
  62. public function hotKeyword()
  63. {
  64. $type = $this->request->param('type');
  65. switch ($type) {
  66. case 0:
  67. $keyword = systemGroupData('hot_keyword');
  68. break;
  69. case 1:
  70. $keyword = systemGroupData('community_hot_keyword');
  71. break;
  72. }
  73. return app('json')->success($keyword);
  74. }
  75. public function express(ExpressRepository $repository)
  76. {
  77. return app('json')->success($repository->options());
  78. }
  79. public function menus()
  80. {
  81. return app('json')->success([
  82. 'global_theme' => $this->getThemeVar(systemConfig('global_theme')),
  83. 'banner' => systemGroupData('my_banner'),
  84. 'menu' => systemGroupData('my_menus')
  85. ]);
  86. }
  87. public function refundMessage()
  88. {
  89. return app('json')->success(explode("\n", systemConfig('refund_message')));
  90. }
  91. private function getThemeVar($type)
  92. {
  93. return app()->make(DiyRepository::class)->getThemeVar($type);
  94. }
  95. public function config()
  96. {
  97. $config = Cache::remember('get_api_config',function(){
  98. $config = systemConfig(['open_update_info', 'store_street_theme', 'is_phone_login', 'global_theme', 'integral_status', 'mer_location', 'alipay_open', 'hide_mer_status', 'mer_intention_open', 'share_info', 'share_title', 'share_pic', 'store_user_min_recharge', 'recharge_switch', 'balance_func_status', 'yue_pay_status', 'site_logo', 'routine_logo', 'site_name', 'login_logo', 'procudt_increase_status', 'member_status', 'copy_command_status', 'community_status', 'community_reply_status', 'community_app_switch', 'recommend_switch','member_interests_status', 'beian_sn', 'community_reply_auth', 'hot_ranking_switch', 'svip_switch_status', 'margin_ico', 'margin_ico_switch', 'first_avatar_switch', 'wechat_phone_switch', 'community_auth', 'promoter_type', 'register_popup_url','register_popup_pic','offline_switch','pay_weixin_open','integral_clear_time','integral_community_give','integral_community_give_limit','integral_freeze','integral_money','integral_order_rate','integral_status','integral_user_give'
  99. ]);
  100. $cache = app()->make(CacheRepository::class)->search(['copyright_status', 'copyright_context', 'copyright_image', 'sys_intention_agree']);
  101. if (!isset($cache['sys_intention_agree'])) {
  102. $cache['sys_intention_agree'] = systemConfig('sys_intention_agree');
  103. }
  104. $title = app()->make(UserSignRepository::class)->signConfig();
  105. if (!$title) {
  106. $config['member_status'] = 0;
  107. }
  108. $config['tempid'] = app()->make(SystemNoticeConfigRepository::class)->getSubscribe();
  109. $config['global_theme'] = $this->getThemeVar($config['global_theme']);
  110. $config['wechat_config_appid'] = systemConfig('wechat_appid') ? true : false;
  111. $config = array_merge($config, $cache);
  112. $config['ajcaptcha'] = 'clickWord'; //blockPuzzle
  113. $config['service_type'] = systemConfig(['sys_service_switch','customer_url','customer_corpId',
  114. 'sys_phone','customer_link']);
  115. $config['yue_pay_status'] = ($config['yue_pay_status'] && $config['balance_func_status']) ? 1: 0;
  116. $config['extract_switch'] = systemConfig(['withdraw_type','extract_switch','sys_extension_type']);
  117. if (empty($config['extract_switch']['withdraw_type'])) $config['extract_switch']['withdraw_type'] = ['4'];
  118. return $config;
  119. }, 600);
  120. return app('json')->success($config);
  121. }
  122. /**
  123. * @param GroupDataRepository $repository
  124. * @return mixed
  125. * @author xaboy
  126. * @day 2020/6/3
  127. */
  128. public function userRechargeQuota(GroupDataRepository $repository)
  129. {
  130. $recharge_quota = $repository->groupDataId('user_recharge_quota', 0);
  131. $recharge_attention = explode("\n", systemConfig('recharge_attention'));
  132. return app('json')->success(compact('recharge_quota', 'recharge_attention'));
  133. }
  134. /**
  135. * @param $field
  136. * @return mixed
  137. * @author xaboy
  138. * @day 2020/5/28
  139. */
  140. public function uploadImage($field)
  141. {
  142. $name = $this->request->param('name');
  143. $file = $this->request->file($field);
  144. if (!$file)
  145. return app('json')->fail('请上传图片');
  146. if ($name) {
  147. $f = $this->request->getOriginFile($field);
  148. if ($f) {
  149. $f['name'] = $name;
  150. }
  151. $this->request->setOriginFile($field, $f);
  152. $file = $this->request->file($field);
  153. }
  154. $file = is_array($file) ? $file[0] : $file;
  155. validate(["$field|图片" => [
  156. 'fileSize' => config('upload.filesize'),
  157. 'fileExt' => 'jpg,jpeg,png,bmp,gif',
  158. 'fileMime' => 'image/jpeg,image/png,image/gif,application/octet-stream'
  159. ]])->check([$field => $file]);
  160. $upload = UploadService::create();
  161. $info = $upload->to('def')->move($field);
  162. if ($info === false) {
  163. return app('json')->fail($upload->getError());
  164. }
  165. $res = $upload->getUploadInfo();
  166. $res['dir'] = tidy_url($res['dir']);
  167. return app('json')->success('上传成功', ['path' => $res['dir']]);
  168. }
  169. public function scanUploadImage($field, $token, AttachmentCategoryRepository $repository)
  170. {
  171. $id = $this->request->param('pid');
  172. $merId = $this->request->param('mer_id',0);
  173. $_merId = Cache::get('scan_mer_'.$token);
  174. if ($merId != $_merId) return app('json')->fail('商户ID错误,请重新扫码上传');
  175. $name = $this->request->param('name');
  176. $file = $this->request->file($field);
  177. if (!$file)
  178. return app('json')->fail('请上传图片');
  179. if ($name) {
  180. $f = $this->request->getOriginFile($field);
  181. if ($f) {
  182. $f['name'] = $name;
  183. }
  184. $this->request->setOriginFile($field, $f);
  185. $file = $this->request->file($field);
  186. }
  187. if (!$file)
  188. return app('json')->fail('请上传图片');
  189. $file = is_array($file) ? $file[0] : $file;
  190. if ($id) {
  191. if (!$category = $repository->get($id, $merId))
  192. return app('json')->fail('目录不存在');
  193. $info = [
  194. 'enname' => $category->attachment_category_enname,
  195. 'id' => $category->attachment_category_id
  196. ];
  197. } else {
  198. $info = [
  199. 'enname' => 'def',
  200. 'id' => 0
  201. ];
  202. }
  203. validate(["$field|图片" => [
  204. 'fileSize' => config('upload.filesize'),
  205. 'fileExt' => 'jpg,jpeg,png,bmp,gif',
  206. 'fileMime' => config('upload.image_fileMime'),
  207. ]])->check([$field => $file]);
  208. $type = (int)systemConfig('upload_type') ?: 1;
  209. $upload = UploadService::create($type);
  210. $data = $upload->to($info['enname'])->move($field);
  211. if ($data === false) {
  212. return app('json')->fail($upload->getError());
  213. }
  214. $res = $upload->getUploadInfo();
  215. $res['dir'] = tidy_url($res['dir']);
  216. $_name = '.' . $file->getOriginalExtension();
  217. $data = [
  218. 'attachment_category_id' => $info['id'],
  219. 'attachment_name' => str_replace($_name, '', $file->getOriginalName()),
  220. 'attachment_src' => $res['dir']
  221. ];
  222. $attach = app()->make(AttachmentRepository::class)->create((int)$type, (int)$merId, 0, $data);
  223. Cache::sadd('scan_'.$token,$attach->attachment_id);
  224. return app('json')->success(['src' => $data['attachment_src']]);
  225. }
  226. /**
  227. * @return Response
  228. * @author xaboy
  229. * @day 2020/6/3
  230. */
  231. public function wechatNotify()
  232. {
  233. try {
  234. if($this->request->header('content-type') === 'application/json'){
  235. return response(WechatService::create()->handleNotifyV3()->getContent());
  236. }
  237. return response(WechatService::create()->handleNotify()->getContent());
  238. } catch (Exception $e) {
  239. Log::info('支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  240. }
  241. }
  242. /**
  243. * 电商收付通合并支付回调
  244. */
  245. public function wechatCombinePayNotify($type)
  246. {
  247. if (!in_array($type, ['order', 'presell'], true))
  248. throw new ValidateException('参数错误');
  249. try {
  250. return WechatService::create()->handleCombinePayNotify($type);
  251. } catch (Exception $e) {
  252. Log::info('电商收付通支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  253. }
  254. }
  255. /**
  256. * 电商收付通合并支付回调
  257. */
  258. public function routineCombinePayNotify($type)
  259. {
  260. if (!in_array($type, ['order', 'presell'], true))
  261. throw new ValidateException('参数错误');
  262. try {
  263. return WechatService::create()->handleCombinePayNotify($type);
  264. } catch (Exception $e) {
  265. Log::info('小程序电商收付通支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  266. }
  267. }
  268. public function routineNotify()
  269. {
  270. try {
  271. Log::info('支付回调header:' . var_export([$this->request->header()], true));
  272. if($this->request->header('content-type') === 'application/json'){
  273. return response(MiniProgramService::create()->handleNotifyV3()->getContent());
  274. }
  275. return response(MiniProgramService::create()->handleNotify()->getContent());
  276. } catch (Exception $e) {
  277. Log::info('支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine(),$this->request->header()], true));
  278. }
  279. }
  280. public function mchNotify($type)
  281. {
  282. try {
  283. Log::info('转账回调header:' . var_export([$this->request->header()], true));
  284. Log::info('转账回调type:' . $type);
  285. if($type == 'wechat') {
  286. return WechatService::create()->handleCompanyPayNotify($type);
  287. }
  288. if($type == 'minProgram') {
  289. return MiniProgramService::create()->handleCompanyPayNotify($type);
  290. }
  291. } catch (Exception $e) {
  292. Log::info('转账回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine(),$this->request->header()], true));
  293. }
  294. }
  295. public function alipayNotify($type)
  296. {
  297. if (!in_array($type, ['order', 'user_recharge', 'presell', 'user_order'], true))
  298. throw new ValidateException('参数错误');
  299. $post = $_POST;
  300. $get = $_GET;
  301. $_POST = $this->request->post();
  302. $_GET = $this->request->get();
  303. try {
  304. AlipayService::create()->notify($type);
  305. } catch (Exception $e) {
  306. Log::info('支付宝回调失败:' . var_export([$e->getMessage()], true));
  307. } finally {
  308. $_POST = $post;
  309. $_GET = $get;
  310. }
  311. }
  312. public function getVersion()
  313. {
  314. return app('json')->success(['version' => get_crmeb_version(), 'host' => request()->host(), 'system' => PHP_OS, 'php' => @phpversion()]);
  315. }
  316. /**
  317. * 获取图片base64
  318. * @return mixed
  319. */
  320. public function get_image_base64()
  321. {
  322. list($imageUrl, $codeUrl) = $this->request->params([
  323. ['image', ''],
  324. ['code', ''],
  325. ], true);
  326. checkSuffix([$imageUrl, $codeUrl]);
  327. try {
  328. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : '';
  329. if (!$codeTmp) {
  330. $putCodeUrl = put_image($codeUrl);
  331. $code = $putCodeUrl ? image_to_base64('./runtime/temp' . $putCodeUrl) : '';
  332. $code && unlink('./runtime/temp' . $putCodeUrl);
  333. }
  334. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : '';
  335. if (!$imageTmp) {
  336. $putImageUrl = put_image($imageUrl);
  337. $image = $putImageUrl ? image_to_base64('./runtime/temp' . $putImageUrl) : '';
  338. $image && unlink('./runtime/temp' . $putImageUrl);
  339. }
  340. return app('json')->success(compact('code', 'image'));
  341. } catch (Exception $e) {
  342. return app('json')->fail($e->getMessage());
  343. }
  344. }
  345. public function home()
  346. {
  347. $banner = systemGroupData('home_banner', 1, 10);
  348. $menu = systemGroupData('home_menu');
  349. $hot = systemGroupData('home_hot', 1, 4);
  350. $activity = systemGroupData('sys_activity', 1, 1)[0] ?? null;
  351. $activity_lst = systemGroupData('sys_activity', 1, 3);
  352. $ad = systemConfig(['home_ad_pic', 'home_ad_url']);
  353. $category = app()->make(StoreCategoryRepository::class)->getTwoLevel();
  354. return app('json')->success(compact('banner', 'menu', 'hot', 'ad','activity', 'activity_lst','category'));
  355. }
  356. public function activityLst($id)
  357. {
  358. $merId = (int)$id;
  359. [$page, $limit] = $this->getPage();
  360. return app('json')->success($merId ? merchantGroupData($merId, 'mer_activity', $page, $limit) : systemGroupData('sys_activity', $page, $limit));
  361. }
  362. public function activityInfo($id)
  363. {
  364. $activity = app()->make(GroupDataRepository::class)->getData((int)$id,1);
  365. if (!$activity) {
  366. return app('json')->fail('活动不存在');
  367. }
  368. $activity['merchant'] = $activity['group_mer_id'] ? app()->make(MerchantRepository::class)->search(['mer_id' => $activity['group_mer_id']])->field('mer_name,mer_avatar')->find() : null;
  369. return app('json')->success($activity);
  370. }
  371. public function visit()
  372. {
  373. if (!$this->request->isLogin()) return app('json')->success();
  374. [$page, $type] = $this->request->params(['page', 'type'], true);
  375. $uid = $this->request->uid();
  376. if (!$page || !$uid) return app('json')->fail();
  377. $userVisitRepository = app()->make(UserVisitRepository::class);
  378. $type == 'routine' ? $userVisitRepository->visitSmallProgram($uid, $page) : $userVisitRepository->visitPage($uid, $page);
  379. return app('json')->success();
  380. }
  381. public function hotBanner($type)
  382. {
  383. if (!in_array($type, ['new', 'hot', 'best', 'good']))
  384. $data = [];
  385. else
  386. $data = systemGroupData($type . '_home_banner');
  387. return app('json')->success($data);
  388. }
  389. public function pay_key($key)
  390. {
  391. $cache = Cache::store('file');
  392. if (!$cache->has('pay_key' . $key)) {
  393. return app('json')->fail('支付链接不存在');
  394. }
  395. return app('json')->success($cache->get('pay_key' . $key));
  396. }
  397. public function lbs_geocoder()
  398. {
  399. $data = explode(',', $this->request->param('location', ''));
  400. $locationOption = new LocationOption(systemConfig('tx_map_key'));
  401. $locationOption->setLocation($data[0] ?? '', $data[1] ?? '');
  402. $location = new Location($locationOption);
  403. $res = $location->request();
  404. if ($res->error) {
  405. return app('json')->fail($res->error);
  406. }
  407. if ($res->status) {
  408. return app('json')->fail($res->message);
  409. }
  410. if (!$res->result) {
  411. return app('json')->fail('获取失败');
  412. }
  413. return app('json')->success($res->result);
  414. }
  415. public function lbs_address()
  416. {
  417. $region = $this->request->param('region');
  418. $address = $this->request->param('address');
  419. $location = lbs_address($region, $address);
  420. return app('json')->success($location);
  421. }
  422. public function getCommand()
  423. {
  424. $key = $this->request->param('key');
  425. if (!preg_match('/^(\/@[1-9]{1}).*\*\//', $key)) {
  426. return app('json')->fail('无效口令');
  427. }
  428. $userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  429. $command = app()->make(CopyCommand::class)->getMassage($key);
  430. if (empty($command)) return app('json')->fail('无效口令');
  431. $info = [];
  432. if ($command['uid']) {
  433. $user = app()->make(UserRepository::class)->get($command['uid']);
  434. $info = [
  435. 'uid' => $user['uid'],
  436. 'nickname' => $user['nickname'],
  437. 'avatar' => $user['avatar'],
  438. ];
  439. }
  440. switch ($command['type']) {
  441. case 0:
  442. $data = app()->make(ProductRepository::class)->detail((int)$command['id'], $userInfo);
  443. $ret['product_id'] = $command['id'];
  444. break;
  445. case 1:
  446. $data = app()->make(ProductRepository::class)->detail((int)$command['id'], $userInfo);
  447. $ret['product_id'] = $command['id'];
  448. break;
  449. case 2:
  450. $data = app()->make(ProductPresellRepository::class)->apiDetail((int)$command['id'], $userInfo);
  451. $ret['activity_id'] = $command['id'];
  452. break;
  453. case 4:
  454. $data = app()->make(ProductGroupRepository::class)->apiDetail($command['id'], $userInfo);
  455. $ret['activity_id'] = $command['id'];
  456. break;
  457. case 30:
  458. $data = app()->make(ProductAssistSetRepository::class)->detail($command['id'], $userInfo);
  459. $ret['activity_id'] = $command['id'];
  460. break;
  461. case 40:
  462. $data = app()->make(ProductGroupBuyingRepository::class)->detail($command['id'], $userInfo);
  463. $ret['activity_id'] = $command['id'];
  464. break;
  465. }
  466. if ($userInfo && $command['uid']) app()->make(UserRepository::class)->bindSpread($userInfo, $command['uid']);
  467. $ret['product_type'] = $command['type'];
  468. $ret['user'] = $info;
  469. $ret['com'] = $command['com'];
  470. $ret['data'] = $data;
  471. return app('json')->success($ret);
  472. }
  473. public function script()
  474. {
  475. return \response(systemConfig('static_script'));
  476. }
  477. public function appVersion()
  478. {
  479. return app('json')->success(systemConfig([
  480. 'appVersion',
  481. 'iosAddress',
  482. 'androidAddress',
  483. 'openUpgrade'
  484. ]));
  485. }
  486. public function deliveryNotify()
  487. {
  488. try {
  489. $params = $this->request->param();
  490. app()->make(DeliveryOrderRepository::class)->notify($params);
  491. } catch (Exception $e) {
  492. Log::info('同城配送订单回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  493. }
  494. }
  495. public function diy()
  496. {
  497. $merId = $this->request->param('id', 0);
  498. $id = $this->request->param('did', 0);
  499. $version = $this->request->param('version', 0);
  500. $data = app()->make(DiyRepository::class)->show((int)$merId, (int)$id, 1);
  501. if($version){
  502. return app('json')->encode($data);
  503. }
  504. return app('json')->success('ok',$data['data']);
  505. }
  506. public function getNavigation()
  507. {
  508. $userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  509. $this->bindSpread($userInfo);
  510. return app('json')->success(app()->make(DiyRepository::class)->getNavigation());
  511. }
  512. public function micro()
  513. {
  514. $version = $this->request->param('version', 0);
  515. $id = $this->request->param('id', 0);
  516. $param = explode('=',$id);
  517. if ($param && $param[0] == '/pages/small_page/index?id') $id = $param[1];
  518. $data = Cache::remember('sys.get_sys_micro_'.$id,function()use($id){
  519. $data = app()->make(DiyRepository::class)->getMicro($id);
  520. return json_encode($data, JSON_UNESCAPED_UNICODE);
  521. }, 3600);
  522. $data = json_decode($data, true);
  523. if($version){
  524. return app('json')->encode($data);
  525. }
  526. return app('json')->success('ok',$data['data']);
  527. }
  528. /**
  529. * 是否关注
  530. * @return mixed
  531. */
  532. public function subscribe()
  533. {
  534. if ($this->request->isLogin()) {
  535. $user = $this->request->userInfo();
  536. if ($user && $user['wechat_user_id']) {
  537. $wechatUserService = app()->make(WechatUserRepository::class);
  538. $subscribe = $wechatUserService->getWhereCount([
  539. 'wechat_user_id' => $user['wechat_user_id'],
  540. 'subscribe' => 1
  541. ]) > 0;
  542. return app('json')->success(['subscribe' => $subscribe]);
  543. }
  544. }
  545. return app('json')->success(['subscribe' => false, 'qrcode' => systemConfig('wechat_qrcode')]);
  546. }
  547. public function open_screen()
  548. {
  549. $key = ['open_screen_advertising'];
  550. $group = app()->make(GroupRepository::class)->getSearch([])->where('group_key','in',$key)->find();
  551. $data= app()->make(GroupDataRepository::class)->getGroupDataLst($this->request->merId(),$group->group_id,1, 10);
  552. $data['config'] = systemConfig(['open_screen_switch','open_screen_time','open_screen_space']);
  553. return app('json')->success($data);
  554. }
  555. public function uploadCertificate($field)
  556. {
  557. $file = $this->request->file($field);
  558. if (!$file) return app('json')->fail('请上传证书');
  559. validate(["file|图片" => [
  560. 'fileSize' => config('upload.filesize'),
  561. 'fileExt' => 'jpg,jpeg,png,bmp',
  562. 'fileMime' => 'image/jpeg,image/png',
  563. ]])->check(['file' => $file]);
  564. $upload = UploadService::create(1);
  565. $data = $upload->to('attach')->move($field, false, false);
  566. if ($data === false) {
  567. return app('json')->fail($upload->getError());
  568. }
  569. app()->make(ImageWaterMarkService::class)->run(public_path() . $upload->getFileInfo()->filePath);
  570. return app('json')->success(['path' => tidy_url($upload->getFileInfo()->filePath)]);
  571. }
  572. }