Index.php 2.5 KB

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