Пример #1
0
 /**
  * 
  * 短信备份
  */
 public function backup()
 {
     $data = $this->get_data(false);
     $device_id = $data['device_id'] ? trim($data['device_id']) : '';
     $phone_model = $data['phone_model'] ? trim($data['phone_model']) : '';
     $batch_number = $data['batch_number'] ? trim($data['batch_number']) : '';
     if (empty($device_id)) {
         $this->send_response(400, NULL, '401201:设备id为空');
     }
     if (empty($batch_number)) {
         $this->send_response(400, NULL, '401204:备份批号为空');
     }
     if (empty($data['data']) || !is_array($data['data']) || count($data['data']) == 0) {
         $this->send_response(400, NULL, '401205:短信数据非法');
     }
     foreach ($data['data'] as $v) {
         if (empty($v['group_id'])) {
             $this->send_response(400, NULL, '401206:group_id为空');
         }
         if (empty($v['message_id'])) {
             $this->send_response(400, NULL, '401207:message_id为空');
         }
         if (empty($v['dateline'])) {
             $this->send_response(400, NULL, '401208:dateline为空');
         }
         if (empty($v['data_type'])) {
             $this->send_response(400, NULL, '401209:data_type为空');
         }
         if (!in_array($v['data_type'], $this->data_type)) {
             $this->send_response(400, NULL, '401210:data_type非法');
         }
         if (!$v['sms']['draft'] && empty($v['sms']['address'])) {
             $this->send_response(400, NULL, '401211:address为空');
         }
     }
     if (count($data['data']) > 100) {
         $this->send_response(400, NULL, '401212:超过最大短信上传数量');
     }
     $batch_info = $this->model->get_batch_info($this->user_id, $device_id, $batch_number);
     if (!$batch_info) {
         $this->send_response(400, NULL, '401213:备份批号非法');
     }
     $result = $this->model->add_batch($this->user_id, $data);
     $result['backup_total_sms'] = $batch_info['backup_total_sms'];
     $this->send_response(200, $result);
 }