public function deleteOrder($order_id) { $flag = TRUE; $results = ResultMedlatec::model()->findAllByAttributes(array('order_id' => $order_id)); $order = OrderMedlatec::model()->findByPk($order_id); $order->delete(); foreach ($results as $item) { $file = ResultFile::model()->findByAttributes(array('result_id' => $item->id)); if (!$file->delete() || !$item->delete()) { $flag = FALSE; } } return $flag; }
public function actionResult() { $request = Yii::app()->request; $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/classic/views/layouts"; $this->layout = 'main_modal'; $order_id = StringHelper::filterString($request->getQuery('oid')); $data = OrderMedlatec::model()->getOrderDetail($order_id); $result = ResultMedlatec::model()->findByAttributes(array('order_id' => $order_id)); if ($result) { $files = ResultFile::model()->findAllByAttributes(array('result_id' => $result->id)); } if (isset($result) && isset($files)) { $this->render('result', array('data' => $data, 'result' => $result, 'files' => $files)); } else { $this->render('result', array('data' => $data)); } }
public function parseResult($result) { $itemArr = array(); $attrLabel = $this->attributeLabels(); foreach ($attrLabel as $key => $value) { $itemArr[$key] = $result->{$key}; $itemArr['files'] = ResultFile::model()->findAllByAttributes(array('result_id' => $result->id)); } return $itemArr; }
public function updateResultByOrder($attr, $urls) { $check = ResultMedlatec::model()->findByAttributes(array('order_id' => $attr['order_id'])); if ($check) { $check->setAttributes($attr); $check->updated_at = time(); $check->save(FALSE); $order = OrderMedlatec::model()->findByPk($attr['order_id']); $order->status = 4; $order->save(FALSE); $meboo = $order->user_meboo; $device_tokens = DeviceTk::model()->findAllByAttributes(array('user_id' => $meboo)); $message_android = array('medlatec_order' => array('order_id' => $attr['order_id'])); $message_ios = array('alert' => 'Dịch vụ của bạn vừa có thông tin', 'sound' => 'default', 'data' => array('id' => $attr['order_id'], 'type' => '0')); $message = array('message_android' => $message_android, 'message_ios' => $message_ios); foreach ($device_tokens as $token) { // echo $token->platform; Util::sendNotificationBasedOnStatus($token->device_token, $order->status, $message); } //die; if (!empty($urls) && is_array($urls)) { $files = ResultFile::model()->findAllByAttributes(array('result_id' => $check->id)); if ($files) { foreach ($files as $file) { $file->delete(); } } foreach ($urls as $url) { $file = new ResultFile(); $file->url = $url; $file->updated_at = time(); $file->created_at = time(); $file->result_id = $check->id; $file->save(FALSE); } } return TRUE; } else { $model = new ResultMedlatec(); $model->setAttributes($attr); $model->order_id = $attr['order_id']; $model->created_at = time(); $model->updated_at = time(); $model->save(FALSE); $order = OrderMedlatec::model()->findByPk($attr['order_id']); $order->status = 4; $order->save(FALSE); $meboo = $order->user_meboo; $meboo_token = User::model()->findByPk($meboo); if ($meboo_token) { $message = array('medlatec_order' => array('order_id' => $attr['order_id'])); Util::sendNotificationBasedOnStatus($meboo_token->device_token, $order->status, $message); } if (!empty($urls) && is_array($urls)) { foreach ($urls as $url) { $file = new ResultFile(); $file->url = $url; $file->updated_at = time(); $file->created_at = time(); $file->result_id = $model->id; $file->save(FALSE); } } return TRUE; } }