public function actionCodeImport() { set_time_limit(0); $scratchId = Yii::app()->request->getParam('scratchId'); $type = Yii::app()->request->getParam('type', Globals::CODE_TYPE_LEGAL); $file = $_FILES; if ($file && $scratchId) { $tmpFile = "upload/" . $_FILES["file"]["name"]; if (file_exists($tmpFile)) { @unlink($_FILES["file"]["name"]); } else { move_uploaded_file($_FILES["file"]["tmp_name"], $tmpFile); } $handle = @fopen($tmpFile, "r"); if ($handle) { while (!feof($handle)) { $code = fgets($handle, 4096); //入库 if (trim($code)) { $tableName = 'scratch_awards'; $CodeModel = new ScratchAwardsModel($tableName); $CodeModel->scratchId = $scratchId; $CodeModel->grade = 0; $CodeModel->code = trim($code); $CodeModel->type = $type; $CodeModel->save(); } } fclose($handle); } @unlink($tmpFile); $msg = "导入成功!"; } else { $msg = '提交错误'; } echo $msg; }
/** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return GiftCodeModel the static model class */ public static function model($table_name) { self::$tableName = $table_name; return parent::model(__CLASS__); }
public function actionWinnerList($id) { $table = 'scratch_awards'; $winnerList = array(); $winner = ScratchAwardsModel::model($table)->findAll('scratchId=:scratchId and grade>0 and status>0', array(':scratchId' => $id)); foreach ($winner as $w) { $winnerList[] = array('telphone' => $w->telphone, 'grade' => $w->grade, 'code' => $w->code, 'datetime' => date('Y-m-d H:i:s', $w->datetime)); } echo json_encode($winnerList); }
public function actionSave() { //status 更新为2 $success = false; $table = 'scratch_awards'; $tel = $_POST['tel']; $msg = '中奖信息失效或系统异常'; $encryption = $_POST['encryption']; $name = $_POST['code']; list($openid, $grade, $scratchId) = explode('|', Globals::authcode($encryption, 'DECODE')); $scratchInfo = ScratchModel::model()->findByPk($scratchId); if ($scratchInfo && $tel) { $awards = unserialize($scratchInfo->awards); if ($awards[$grade] && $awards[$grade]['name'] == $name) { $success = true; $msg = '你的信息已收录,我们会及时联系你'; //存储用户信息 $codeInfo = ScratchAwardsModel::model($table)->find('openId=:openId and scratchId=:scratchId and grade=:grade', array(':openId' => $openid, ':scratchId' => $scratchId, ':grade' => $grade)); $codeInfo->status = 2; $codeInfo->telphone = $tel; $codeInfo->save(); } } echo json_encode(array('success' => $success, 'msg' => $msg)); }