Index.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\page\Page as AppPage;
  4. use app\api\model\settings\Setting as SettingModel;
  5. use app\common\enum\settings\SettingEnum;
  6. use app\common\model\app\AppUpdate as AppUpdateModel;
  7. use app\common\model\supplier\Service as ServiceModel;
  8. use app\api\model\plus\chat\Chat as ChatModel;
  9. use think\facade\Cache;
  10. /**
  11. * 页面控制器
  12. */
  13. class Index extends Controller
  14. {
  15. /**
  16. * 首页
  17. */
  18. public function index($page_id = null, $url = '')
  19. {
  20. // 页面元素
  21. $data = AppPage::getPageData($this->getUser(false), $page_id);
  22. //消息条数
  23. $Chat = new ChatModel;
  24. $data['msgNum'] = $Chat->mCount($this->getUser(false));
  25. $data['setting'] = array(
  26. 'collection' => SettingModel::getItem('collection'),
  27. 'officia' => SettingModel::getItem('officia'),
  28. 'homepush' => SettingModel::getItem('homepush'),
  29. );
  30. // 扫一扫参数
  31. $data['signPackage'] = $this->getScanParams($url)['signPackage'];
  32. return $this->renderSuccess('', $data);
  33. }
  34. // 公众号客服
  35. public function mpService($shop_supplier_id)
  36. {
  37. $mp_service = ServiceModel::detail($shop_supplier_id);
  38. return $this->renderSuccess('', compact('mp_service'));
  39. }
  40. //底部导航
  41. public function nav()
  42. {
  43. $data['vars'] = SettingModel::getItem(SettingEnum::BOTTOMNAV);
  44. return $this->renderSuccess('', $data);
  45. }
  46. // app更新
  47. public function update($name, $version, $platform)
  48. {
  49. $result = [
  50. 'update' => false,
  51. 'wgtUrl' => '',
  52. 'pkgUrl' => '',
  53. ];
  54. try {
  55. $model = AppUpdateModel::getLast();
  56. // 这里简单判定下,不相等就是有更新。
  57. if ($model && $version != $model['version']) {
  58. $currentVersions = explode('.', $version);
  59. $resultVersions = explode('.', $model['version']);
  60. if ($currentVersions[0] < $resultVersions[0]) {
  61. // 说明有大版本更新
  62. $result['update'] = true;
  63. $result['pkgUrl'] = $platform == 'android' ? $model['pkg_url_android'] : $model['pkg_url_ios'];
  64. } else {
  65. // 其它情况均认为是小版本更新
  66. $result['update'] = true;
  67. $result['wgtUrl'] = $model['wgt_url'];
  68. }
  69. }
  70. } catch (\Exception $e) {
  71. }
  72. return $this->renderSuccess('', compact('result'));
  73. }
  74. }