/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/UserController.php (13566B)
render('index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams)
]
);
}
/**
*
* @return string
*
* @Title("Create")
*/
public function actionCreate()
{
$model = new User();
$post = Yii::$app->getRequest()->post();
$model->setScenario($model::SCENARIO_CREATE);
if ($model->load($post) && $model->validate()) {
$password = Yii::$app->security->generateRandomString(6);
$model->setPassword($password);
$model->referral_code = Com::generateRandomString(5, true);
$model->save(false);
$mailerQueueHelper = MailerQueueHelper::getInstance()
->setTo($model->email)
->setSubject('Customer Registration')
->setView(
'CustomerRegistration',
[
'username'=> $model->first_name.' '.$model->last_name,
'email' => $model->email,
'password' => $password,
])
->push();
Com::successFlash(Yii::t('backend','Created Successfully'));
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$post = Yii::$app->getRequest()->post();
$model->setScenario($model::SCENARIO_UPDATE);
if ($model->load($post) && $model->validate()) {
$adminUserData = Yii::$app->getUser()->getIdentity();
$adminUserName = $adminUserData->attributes['user_name'];
$customerName = $model->first_name.$model->last_name;
ActivityLog::log($adminUserName.' '. 'edited the tabaogo Credits for customer'.' '. $customerName);
$model->save();
Com::successFlash(Yii::t('backend','Updated Successfully'));
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Delete")
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model === null) {
Com::failureFlash('Unable to find the Item');
return $this->redirect(['index']);
}
$model->status = User::DELETE;
$model->save(false);
Com::successFlash(Yii::t('backend','Deleted Successfully'));
return $this->redirect(['index']);
}
/**
*
* @param type $id
* @return $model
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = User::findOne(['user_key' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
*
* @return Json
* @throws \yii\base\InvalidParamException
*
* @Title("User Status")
*/
public function actionChangeStatus()
{
$params = ['key', 'status'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if (!array_key_exists($param, $post)) {
$result['msg'] = 'Required param missing';
goto skip;
}
}
$model = User::findOne(['user_key' => $post['key']]);
if ($model === null) {
$result['msg'] = 'Unable to find the Customer';
goto skip;
}
$model->status = $post['status'];
$model->save(false);
$result['msg'] = Yii::t('backend','Customer deactivated successfully');
if ((int)$model->status === $model::ACTIVE) {
$result['msg'] = Yii::t('backend','Customer activated successfully');
}
$result['status'] = STATUS_SUCCESS;
skip:
return $this->asJson($result);
}
/**
* @return string
* @throws \yii\base\InvalidParamException
*/
public function actionGetCustomerDetails()
{
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => '' , 'model' => ''];
if (!array_key_exists('customer_id', $post)) {
$result['msg'] = 'Required Param Missing';
goto skip;
}
$model = User::findOne(['user_id' => $post['customer_id']]);
if ($model === null) {
$result['msg'] = 'Unable to find the customer details';
goto skip;
}
$result['model'] = $model;
$result['status'] = STATUS_SUCCESS;
$result['msg'] = 'Data Fetched Successfully';
skip:
return $this->asJson($result);
}
/**
* @return string
* @throws \yii\base\InvalidParamException
*/
public function actionGetCustomerAddressDetails()
{
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => '', 'model' => ''];
if (!array_key_exists('customer_address_id', $post)) {
$result['msg'] = 'Required Param Missing';
goto skip;
}
$query= UserAddress::find()
->alias('UA')
->select('UA.*')
->where(['UA.user_address_id' => $post['customer_address_id']]);
UserAddress::selectTranslation($query);
$model = $query->asArray()->one();
if ($model === null) {
$result['msg'] = 'Unable to find Customer Address Details';
goto skip;
}
$result['status'] = STATUS_SUCCESS;
$result['model'] = $model;
$result['msg'] = 'Data Fetched Successfully';
skip:
return $this->asJson($result);
}
/**
* @return string
* @throws \yii\base\InvalidParamException
*
* @Title("Quick View")
*/
public function actionQuickView()
{
$params = ['id'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if ( !array_key_exists($param, $post) ) {
$result['msg'] = Yii::t('backend', 'Required param missing');
goto skip;
}
}
$resposeArray = \backend\models\User::find()->where(['user_key' => $post['id']])->one();
if (empty($resposeArray)) {
$result['msg'] = Yii::t('backend', 'Invalid user key');
goto skip;
}
$aData['user'] = [
'user_key' => $resposeArray->user_key,
'user_id' => $resposeArray->user_id,
'first_name' => $resposeArray->first_name,
'last_name' => $resposeArray->last_name,
'email' => $resposeArray->email,
'mobile_number' => $resposeArray->mobile_number,
'status' => $resposeArray->status,
'wallet_point' => $resposeArray->wallet_point,
'loyality_point' => $resposeArray->loyality_point,
];
$model = \frontend\models\UserAddress::getaddress($resposeArray->user_id);
$addresstype = \frontend\models\AddressType::getaddresstype();
$aData['user_address'] = [];
if (!empty($model) && count($model) > 0) {
foreach ($model as $aKey => $aVal) {
$aData['user_address'][$aKey] = [
'user_address_id' => $aVal['user_address_id'],
'latitude' => $aVal['latitude'],
'longitude' => $aVal['longitude'],
'flat_no' => $aVal['flat_no'],
'apartment' => $aVal['apartment'],
'street_name' => $aVal['street_name'],
'city' => $aVal['city'],
'area' => $aVal['area'],
'company' => $aVal['company'],
'landmark' => $aVal['landmark'],
'address_type_name' => $aVal['address_type_name'],
'full_address' => $aVal['flat_no']. ','.$aVal['apartment'].','.$aVal['street_name'].','.$aVal['city'].','.$aVal['area'].','.$aVal['company'].','.$aVal['landmark'],
];
$fullAddress = str_replace(',', ', ', preg_replace('/,{2,}/',',',$aData['user_address'][$aKey]['full_address']));
$aData['user_address'][$aKey]['full_address'] = substr($fullAddress, 0, -2).'.';
}
}
$result['status'] = STATUS_SUCCESS;
$result['response'] = json_encode($resposeArray->toArray());
$result['data'] = $this->renderPartial('quick-view', ['resposeArray' => $aData]);
skip:
return $this->asJson($result);
}
public function actionSms() {
$request =""; //initialise the request variable
$param['method']= "sendMessage";
$param['send_to'] = "7904070932";
$param['msg'] = "1234 is the OTP to verify your mobile number on OPEN. It will expire in 15 minutes. Do not share it with anyone.";
$param['userid'] = "2000189927";
$param['password'] = "Ajeeshis100%";
$param['v'] = "1.1";
$param['msg_type'] = "TEXT"; //Can be "FLASH”/"UNICODE_TEXT"/”BINARY”
//$param['auth_scheme'] = "PLAIN";//Have to URL encode the values
foreach($param as $key=>$val) {
$request.= $key."=".urlencode($val);//we have to urlencode the values
$request.= "&";//append the ampersand (&) sign after eachparameter/value pair
}
$request = substr($request, 0, strlen($request)-1);//remove final (&) sign from the request
$url ="http://enterprise.smsgupshup.com/GatewayAPI/rest?".$request;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
print_r($curl_scraped_page); die;
echo $curl_scraped_page;
}
public function actionNotification()
{
$currentTime = Date('H:i');
$timeslots = [];
$userToken = [];
$t1 = strtotime('05:00');
$t2 = strtotime('23:00');
while ($t1 < $t2) {
$t1 = strtotime('+1 hour', $t1);
$timeslots[] = date('H:i', $t1);
}
if(in_array($currentTime, $timeslots)) {
$dateIndex = [
'1' => 'monday_status',
'2' => 'tuesday_status',
'3' => 'wednesday_status',
'4' => 'thursday_status',
'5' => 'friday_status',
'6' => 'startday_status',
'7' => 'sunday_status',
];
$modelUser = User::find()->where(['is_health_advice' => User::ACTIVE, 'status' => User::ACTIVE])->all();
foreach ($modelUser as $key => $user) {
$todayDateStatus = $dateIndex[date('w')];
$userReminder = UserReminder::find()
->where([
'user_id' => $user['user_id'],
'user_reminder_status' => User::ACTIVE
])
->andwhere(["$todayDateStatus" => User::ACTIVE])
->one();
if($userReminder != null && $user['device_token']) {
$userToken[] = $user['device_token'];
}
}
}
if($userToken != []) {
try
{
$oneSignal = OneSignal::getInstance();
$oneSignal->setAppId(Configuration::get(Configuration::PUSH_NOTIFICATION_APP_ID));
$oneSignal->setRestApiKey(Configuration::get(Configuration::PUSH_NOTIFICATION_REST_API_KEY));
$oneSignal->setIcon('http://online.kitokey.com/frontend/web/theme/images/notification.png');
$oneSignal->push(
['en' => 'Order status'],
['en' => 'Hi, now it is your water drinking time.. let`s go for drinking'],
$userToken,
['status' => 'Message Sent Successfully']
);
}
catch(Exception $e)
{
echo $e->getMessage();
}
}
}
}