123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- class DpyhAppVersionAction extends CommonAction {
- const tableName = 'dpyh_app_version';
- const pkName = 'ID';
-
-
- function sys_list( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'AddTime desc';
- //权限回调
- $list->right_filter = function($right,$type){
- $page = $_SERVER['PATH_INFO'];
- return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
- };
- $list->sql_filter = function($search,&$cond){
- if( $search['AppName'] ){
- $cond['AppName'] = $search['AppName'];
- }
- };
- $list->row_filter = function(&$row)use($list){
- if( $row['AppName'] == 'zndp' ){
- $row['AppName'] = '智能大棚';
- }elseif( $row['AppName'] == 'nyt' ){
- $row['AppName'] = '农用通';
- }
- $options = array('rule'=>array('required'=>true,'pattern'=>'digit'));
- $row['AppVersionCode'] = $list->renderXEditableInput('编辑版本代码',$row,'AppVersionCode',$options);
- };
-
- $list->display($this);
- }
-
-
- function sys_addedit( ){
- $form = new \Jms\Gui\ClForm();
- $form->before_display = function(&$data){
- $data['AppName'] = $data['AppName'] == '农用通' ? 'nyt' : 'zndp';
- if(!$data['AppPath']){
- $data['AppPath'] = 'http://zndp.rltest.cn/apk/zndp/';
- }
- };
- $form->before_add = function(&$data){ //添加前回调
- //检查版本号是否重复
- $where = array('AppVersion'=>$data['AppVersion'],'AppName'=>$data['AppName']);
- if( M('dpyh_app_version')->where($where)->count() > 0 ){
- json_fail('版本号已存在');
- }
- $model = M('dpyh_app_version');
- // 代码格式:v1.0.1 = 101
- $apk = substr($data['AppPath'],strrpos($data['AppPath'],'/')+1);
- $version_arr = preg_match_all('/\d+/',$apk,$arr);
- $data['AppVersionCode'] = $arr[0][0].$arr[0][1].$arr[0][2];
-
- /*
- $max_code = $model->max('AppVersionCode'); //取最大版本代码
- if(!$max_code){
- $max_code = 1;
- }else{
- ++$max_code;
- }
- $data['AppVersionCode'] = $max_code; //给版本代码赋值
- */
- };
- $form->before_modify = function(&$data){ // 修改前回调
- //检查版本号是否重复
- $where = array(
- 'ID' => array('neq',$data['ID']),
- 'AppVersion'=>$data['AppVersion'],
- 'AppName'=>$data['AppName'],
- );
- if( M('dpyh_app_version')->where($where)->count() > 0 ){
- json_fail('版本号已存在');
- }
- };
- $form->before_save = function(&$data){ // 保存前回调
- //判断是否为apk文件
- $pattern = '/^http:\/\/.*\.apk$/';
- if( !preg_match($pattern,$data['AppPath']) ){
- json_fail('文件格式不正确');
- }
- $file_header = get_headers($data['AppPath'],1);
- if( preg_match('/40/',$file_header[0]) ){
- json_fail('文件不存在或没有权限');
- }
- if( $file_header['Content-Length'] == 0 ){
- json_fail('文件为空');
- }
- if( preg_match('/50/',$file_header[0]) ){
- json_fail('服务器错误');
- }
- $data['AppName'] = $data['AppName'] == 'nyt' ? '农用通' : '智能大棚';
-
-
- };
- $form->display($this);
- }
-
-
- public function sys_del( ){
- $grid = new \Jiaruan\GridData();
-
- $grid->deleteByPk($this);
- }
-
-
- function sys_list_search( ){
-
- }
-
-
- function sys_list_tmp( ){
- $list = new \Jms\Gui\ClGrid();
- $list->sql_sort = 'AddTime desc';
- $list->right_filter = function($right,$type){
- $page = $_SERVER['PATH_INFO'];
- return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
- };
- $list->sql_filter = function($search,&$cond){
- $cond['AppName'] = '农用通';
- };
- $list->row_filter = function(&$row)use($list){
- $row['AppName_text'] = "手机APP";
- };
-
- $list->display($this);
- }
-
-
- function sys_addedit_oss( ){
- $form = new \Jms\Gui\ClForm();
- $form->before_save = function(&$data){ //添加前回调
- $data['AppVersion'] = trim($data['AppVersion']);
- $dpyh_app_version = M('dpyh_app_version');
- // 代码格式:v1.0.1 = 101
- $version_arr = preg_match_all('/\d+/',$data['AppVersion'],$arr);
- $data['AppVersionCode'] = $arr[0][0].$arr[0][1].$arr[0][2];
- // 检查版本是否存在
- $where = array(
- 'AppVersionCode' => $data['AppVersionCode'],
- 'AppName' => $data['AppName'],
- );
- if( $id = I('get.id') ){
- $where['ID'] = array('neq',$id);
- }
- if( $dpyh_app_version->where($where)->count() > 0 ){
- json_fail('版本号已存在');
- }
- // 保存MD5散列,用于校验app文件是否正确
- $data['Md5Hash'] = md5_file($data['AppPath']);
- };
- $form->display($this);
- }
-
- }
|