DpyhAppVersionAction.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. class DpyhAppVersionAction extends CommonAction {
  3. const tableName = 'dpyh_app_version';
  4. const pkName = 'ID';
  5. function sys_list( ){
  6. $list = new \Jms\Gui\ClGrid();
  7. $list->sql_sort = 'AddTime desc';
  8. //权限回调
  9. $list->right_filter = function($right,$type){
  10. $page = $_SERVER['PATH_INFO'];
  11. return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
  12. };
  13. $list->sql_filter = function($search,&$cond){
  14. if( $search['AppName'] ){
  15. $cond['AppName'] = $search['AppName'];
  16. }
  17. };
  18. $list->row_filter = function(&$row)use($list){
  19. if( $row['AppName'] == 'zndp' ){
  20. $row['AppName'] = '智能大棚';
  21. }elseif( $row['AppName'] == 'nyt' ){
  22. $row['AppName'] = '农用通';
  23. }
  24. $options = array('rule'=>array('required'=>true,'pattern'=>'digit'));
  25. $row['AppVersionCode'] = $list->renderXEditableInput('编辑版本代码',$row,'AppVersionCode',$options);
  26. };
  27. $list->display($this);
  28. }
  29. function sys_addedit( ){
  30. $form = new \Jms\Gui\ClForm();
  31. $form->before_display = function(&$data){
  32. $data['AppName'] = $data['AppName'] == '农用通' ? 'nyt' : 'zndp';
  33. if(!$data['AppPath']){
  34. $data['AppPath'] = 'http://zndp.rltest.cn/apk/zndp/';
  35. }
  36. };
  37. $form->before_add = function(&$data){ //添加前回调
  38. //检查版本号是否重复
  39. $where = array('AppVersion'=>$data['AppVersion'],'AppName'=>$data['AppName']);
  40. if( M('dpyh_app_version')->where($where)->count() > 0 ){
  41. json_fail('版本号已存在');
  42. }
  43. $model = M('dpyh_app_version');
  44. // 代码格式:v1.0.1 = 101
  45. $apk = substr($data['AppPath'],strrpos($data['AppPath'],'/')+1);
  46. $version_arr = preg_match_all('/\d+/',$apk,$arr);
  47. $data['AppVersionCode'] = $arr[0][0].$arr[0][1].$arr[0][2];
  48. /*
  49. $max_code = $model->max('AppVersionCode'); //取最大版本代码
  50. if(!$max_code){
  51. $max_code = 1;
  52. }else{
  53. ++$max_code;
  54. }
  55. $data['AppVersionCode'] = $max_code; //给版本代码赋值
  56. */
  57. };
  58. $form->before_modify = function(&$data){ // 修改前回调
  59. //检查版本号是否重复
  60. $where = array(
  61. 'ID' => array('neq',$data['ID']),
  62. 'AppVersion'=>$data['AppVersion'],
  63. 'AppName'=>$data['AppName'],
  64. );
  65. if( M('dpyh_app_version')->where($where)->count() > 0 ){
  66. json_fail('版本号已存在');
  67. }
  68. };
  69. $form->before_save = function(&$data){ // 保存前回调
  70. //判断是否为apk文件
  71. $pattern = '/^http:\/\/.*\.apk$/';
  72. if( !preg_match($pattern,$data['AppPath']) ){
  73. json_fail('文件格式不正确');
  74. }
  75. $file_header = get_headers($data['AppPath'],1);
  76. if( preg_match('/40/',$file_header[0]) ){
  77. json_fail('文件不存在或没有权限');
  78. }
  79. if( $file_header['Content-Length'] == 0 ){
  80. json_fail('文件为空');
  81. }
  82. if( preg_match('/50/',$file_header[0]) ){
  83. json_fail('服务器错误');
  84. }
  85. $data['AppName'] = $data['AppName'] == 'nyt' ? '农用通' : '智能大棚';
  86. };
  87. $form->display($this);
  88. }
  89. public function sys_del( ){
  90. $grid = new \Jiaruan\GridData();
  91. $grid->deleteByPk($this);
  92. }
  93. function sys_list_search( ){
  94. }
  95. function sys_list_tmp( ){
  96. $list = new \Jms\Gui\ClGrid();
  97. $list->sql_sort = 'AddTime desc';
  98. $list->right_filter = function($right,$type){
  99. $page = $_SERVER['PATH_INFO'];
  100. return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
  101. };
  102. $list->sql_filter = function($search,&$cond){
  103. $cond['AppName'] = '农用通';
  104. };
  105. $list->row_filter = function(&$row)use($list){
  106. $row['AppName_text'] = "手机APP";
  107. };
  108. $list->display($this);
  109. }
  110. function sys_addedit_oss( ){
  111. $form = new \Jms\Gui\ClForm();
  112. $form->before_save = function(&$data){ //添加前回调
  113. $data['AppVersion'] = trim($data['AppVersion']);
  114. $dpyh_app_version = M('dpyh_app_version');
  115. // 代码格式:v1.0.1 = 101
  116. $version_arr = preg_match_all('/\d+/',$data['AppVersion'],$arr);
  117. $data['AppVersionCode'] = $arr[0][0].$arr[0][1].$arr[0][2];
  118. // 检查版本是否存在
  119. $where = array(
  120. 'AppVersionCode' => $data['AppVersionCode'],
  121. 'AppName' => $data['AppName'],
  122. );
  123. if( $id = I('get.id') ){
  124. $where['ID'] = array('neq',$id);
  125. }
  126. if( $dpyh_app_version->where($where)->count() > 0 ){
  127. json_fail('版本号已存在');
  128. }
  129. // 保存MD5散列,用于校验app文件是否正确
  130. $data['Md5Hash'] = md5_file($data['AppPath']);
  131. };
  132. $form->display($this);
  133. }
  134. }