コード例 #1
0
ファイル: MStatcodeService.php プロジェクト: tianyunchong/php
 /**
  * 审核操作!
  * 如果通过了,标记m表中的状态为1, 并把数据更新到gc表中
  * 如果拒审了,只更新m表
  * @param  integer $id [<description>]
  * @return
  */
 public function check($id, $state, $name, $checkdesc = '')
 {
     if ($id < 1 || !in_array($state, array(1, -1))) {
         return $this->outputData('', '401', '数据校检失败');
     }
     $data = MStatcode::findFirst(array('conditions' => 'id=:id:', 'bind' => array('id' => $id)));
     if (!$data) {
         return $this->outputData('', '402', '信息不存在');
     }
     if (!isset($data->state) || $data->state != 0) {
         return $this->outputData('', '403', '已被审核');
     }
     //审核通过操作
     if ($state == 1) {
         $data->state = $state;
         $data->checkdesc = '审核成功';
         $data->name = $name;
         $data->checktime = time();
         //更新完状态之后,将信息保存或更新到正常表中
         if ($data->save()) {
             //关系性太强了! 必须判断是否存在,存在则更新,不存在则新增
             $findData = Statcode::findFirst(array('conditions' => 'supid=:supid: and state=1', 'bind' => array('supid' => $data->supid)));
             if ($findData) {
                 $findData->statcode = $data->statcode;
                 $res = $findData->save();
             } else {
                 $StatcodeService = new Statcode();
                 $StatcodeService->supid = $data->supid;
                 $StatcodeService->cid = 0;
                 $StatcodeService->closttime = 0;
                 $StatcodeService->statcode = $data->statcode;
                 $StatcodeService->state = $data->state;
                 $res = $StatcodeService->save();
             }
             if ($res) {
                 return $this->outputData('操作成功');
             } else {
                 return $this->outputData('', 503, '操作失败');
             }
         }
         //审核失败操作
     } else {
         $data->state = $state;
         $data->checkdesc = $checkdesc;
         $data->name = $name;
         $data->checktime = time();
         $res = $data->save();
         //更新完状态之后,将信息保存或更新到正常表中
         if ($res) {
             if ($res) {
                 return $this->outputData('操作成功');
             } else {
                 return $this->outputData('', 503, '操作失败');
             }
         }
     }
 }