function smshistoryAction() { $this->_helper->layout->disableLayout(); $idValue = explode('&', $this->_request->getParam('uid')); $uid = $idValue[0]; $incomingSmsDataArray = array(); $sentSmsDataArray = array(); $sparkSmsModel = new SparkSms(); $incomingSmsData = $sparkSmsModel->fetchAll('consumer_id=' . $uid); $db = Zend_Registry::get('db'); $sentSmsSelect = $db->select(); $sentSmsSelect->from('sent_sms', array('sent_sms.*')); $sentSmsSelect->join('consumer', 'consumer.phone = sent_sms.to and consumer.id=' . $uid); $sentSmsSelect->order('sent_sms.time DESC'); $sentSmsData = $db->fetchAll($sentSmsSelect); if (count($incomingSmsData)) { foreach ($incomingSmsData as $data) { $incomingSmsDataArray[] = $data->toArray(); } } // if(count($sentSmsData)){ // foreach($sentSmsData as $data){ // $sentSmsDataArray[] = $data->toArray(); // } // } //按照时间排序 $newSmsData = array(); $count = 0; for ($i = count($incomingSmsDataArray) - 1, $j = 0; $i >= 0 || $j < count($sentSmsData);) { if ($i < count($incomingSmsDataArray) && $j < count($sentSmsData)) { $income_time = $incomingSmsDataArray[$i]['time']; $sent_time = $sentSmsData[$j]['time']; if ($incomingSmsDataArray[$i]['time'] >= $sentSmsData[$j]['time']) { $newSmsData[$count] = $incomingSmsDataArray[$i]; $i--; } else { $newSmsData[$count] = $sentSmsData[$j]; $j++; } } elseif ($i >= count($incomingSmsDataArray) && $j < count($sentSmsData)) { $newSmsData[$count] = $sentSmsData[$j]; $j++; } elseif ($i < count($incomingSmsDataArray) && $j >= count($sentSmsData)) { $newSmsData[$count] = $incomingSmsDataArray[$i]; $i--; } $count++; } $this->view->sms = $newSmsData; }