· 7 years ago · Feb 15, 2019, 03:46 AM
1<?php
2defined('BASEPATH') OR exit('No direct script access allowed');
3
4class Webservice extends CI_Controller
5{
6 public function __construct()
7 {
8 parent::__construct();
9 $this -> load -> library('session');
10 $this -> load -> helper('form');
11 $this -> load -> helper('url');
12 $this -> load-> library('image_lib');
13 $this -> load->library('api');
14 $this -> load -> database();
15 $this -> load -> library('form_validation');
16 $this -> load -> model('Comman_model');
17 $this -> load -> model('Api_model');
18 header('Access-Control-Allow-Origin: *');
19 header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
20 }
21
22 public function index()
23 {
24 $getUserId=1;
25 echo $url= base_url().'Webservice/userActive?getUserId='.$getUserId;
26 }
27
28 /*Check User Session*/
29 public function checkUserKey($user_key, $user_id)
30 {
31 $getUser= $this->Api_model->getSingleRow('user_session', array('user_id'=>$user_id,'user_key'=>$user_key));
32 if(!$getUser)
33 {
34 $this->api->api_message(3, IN_USER);
35 exit();
36 }
37 }
38
39 /*Check User Session*/
40 public function checkUserStatus($user_id)
41 {
42 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
43
44 if($getUser)
45 {
46 if($getUser->status==0)
47 {
48 $this->api->api_message(3, NOT_ACT);
49 exit();
50 }
51 }
52 else
53 {
54 $this->api->api_message(3, USER_NOT_FOUND);
55 exit();
56 }
57 }
58
59
60 /*Get Neareast Artist*/
61 public function getNearestArtist()
62 {
63 $latitude = $this->input->post('latitude', TRUE);
64 $longitude = $this->input->post('longitude', TRUE);
65 $category_id = $this->input->post('category_id', TRUE);
66 $user_id = $this->input->post('user_id', TRUE);
67
68 $this->checkUserStatus($user_id);
69
70 if($category_id)
71 {
72 $get_artists=$this->Api_model->getNearestDataWhere($latitude,$longitude,ART_TBL,array('category_id'=>$category_id),$user_id, 1);
73 }
74 else
75 {
76 $get_artists=$this->Api_model->getNearestData($latitude,$longitude,ART_TBL,$user_id);
77 }
78
79 if($get_artists->price=='' || $get_artists->category_id==0 || $get_artists->name=='' || $get_artists->skills=='' || $get_artists->bio=='')
80 {
81 $this->api->api_message(0, NO_DATA);
82 die();
83 }
84
85 if($get_artists)
86 {
87
88 $artist_id=$get_artists->user_id;
89 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
90 $get_artists->image=base_url().$get_artists->image;
91 $get_artists->category_name=$get_cat->cat_name;
92
93 $where= array('artist_id'=>$artist_id);
94 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
95 if($ava_rating[0]->rating==null)
96 {
97 $ava_rating[0]->rating="0";
98 }
99 $get_artists->ava_rating=$ava_rating[0]->rating;
100
101 $skills=json_decode($get_artists->skills);
102 $skill= array();
103 if(!empty($skills))
104 {
105 foreach ($skills as $skills) {
106 $get_skills= $this->Api_model->getSingleRow('skills', array('id'=>$skills));
107 array_push($skill, $get_skills);
108 }
109 $get_artists->skills= $skill;
110 }
111 else
112 {
113 $get_artists->skills= array();
114 }
115
116 $get_products= $this->Api_model->getAllDataWhere(array('user_id'=>$get_artists->user_id), 'products');
117
118 $products= array();
119 foreach ($get_products as $get_products) {
120 # code...
121 $get_products->product_image=base_url().$get_products->product_image;
122 array_push($products, $get_products);
123 }
124 $get_artists->products=$products;
125
126 $get_reviews= $this->Api_model->getAllDataWhere(array('artist_id'=>$artist_id,'status'=>1), 'rating');
127 $review = array();
128 foreach ($get_reviews as $get_reviews) {
129
130 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_reviews->user_id));
131 $get_reviews->name= $get_user->name;
132 if($get_user->image)
133 {
134 $get_reviews->image= base_url().$get_user->image;
135 }
136 else
137 {
138 $get_reviews->image= base_url()."assets/images/image.png";
139 }
140
141 array_push($review, $get_reviews);
142 }
143 $get_artists->reviews=$review;
144
145 $get_gallery= $this->Api_model->getAllDataWhere(array('user_id'=>$artist_id), GLY_TBL);
146 $gallery = array();
147 foreach ($get_gallery as $get_gallery) {
148
149 $get_gallery->image= base_url().$get_gallery->image;
150 array_push($gallery, $get_gallery);
151 }
152 $get_artists->gallery=$gallery;
153
154 $get_qualifications= $this->Api_model->getAllDataWhere(array('user_id'=>$artist_id), 'qualifications');
155
156 $get_artists->qualifications=$get_qualifications;
157
158 $get_artists->jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id,'booking_flag'=>4));
159
160 $get_artists->totalJob=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id));
161
162 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
163 $get_artists->currency_type= $currency_setting->currency_symbol;
164
165 if($get_artists->totalJob==0)
166 {
167 $get_artists->completePercentages=0;
168 }
169 else
170 {
171 $get_artists->completePercentages=round(($get_artists->jobDone*100) / $get_artists->totalJob);
172 }
173
174 $this->api->api_message_data(1, ALL_SKILLS,'data' , $get_artists);
175 }
176 else
177 {
178 $this->api->api_message(0, NO_DATA);
179 }
180 }
181
182 /*SignUp User*/
183 public function SignUpV1()
184 {
185 $name = $this->input->post('name', TRUE);
186 $email_id = $this->input->post('email_id', TRUE);
187 $password = $this->input->post('password', TRUE);
188 $userRole = $this->input->post('role', TRUE);
189 if($userRole==1)
190 {
191 $userStatus = '1';
192 $approval_status = '0';
193 }
194 else
195 {
196 $userStatus = '0';
197 $approval_status = '1';
198 }
199
200 $created_at=time();
201 $updated_at=time();
202 $table= USR_TBL;
203 $condition = array('email_id'=>$email_id);
204 $columnName = 'email_id';
205 $referral_code=$this->api->random_num(6);
206 $data = array('name'=>$name,'email_id'=>$email_id,'password'=>$password,'role'=>$userRole,'status'=>$userStatus,'created_at'=>$created_at,'updated_at'=>$updated_at,'referral_code'=>$referral_code,'approval_status'=>$approval_status);
207
208 $get_user=$this->Api_model->getSingleRow($table, array('email_id'=>$email_id));
209
210 if(!$get_user)
211 {
212 $getUserId=$this->Api_model->insertGetId($table,$data);
213 if($getUserId)
214 {
215
216 if($userRole==1)
217 {
218 $msg='Obrigado por inscrever-se! Sua conta foi criada, aguarde a confirmação do administrador.';
219 }
220 else
221 {
222 $url= base_url().'Webservice/userActive?user_id='.$getUserId;
223 $msg='Obrigado por inscrever-se! Sua conta foi criada, você pode fazer o login com as seguintes credenciais depois de ter ativado sua conta, pressionando o URL abaixo. Por favor clique: ' .$url;
224 }
225
226 $this->send_email($email_id, REG_SUB, $msg);
227
228 $datatag='data';
229 $get_user=$this->Api_model->getSingleRow($table, array('user_id'=>$getUserId));
230 $this->api->api_message_data(1, USERRAGISTER,$datatag , $get_user);
231 }
232 else
233 {
234 $this->api->api_message(0, TRY_AGAIN);
235 }
236 }
237 elseif($get_user->status ==0)
238 {
239 $getUserId= $get_user->user_id;
240 $url= base_url().'Webservice/userActive?user_id='.$getUserId;
241 $msg='Obrigado por inscrever-se! Sua conta foi criada, você pode fazer o login com as seguintes credenciais depois de ter ativado sua conta, pressionando o URL abaixo. Por favor clique ' .$url;
242
243 $this->send_email($email_id, REG_SUB, $msg);
244 $this->api->api_message(0, CHECK_MAIL);
245 exit();
246 }
247 else
248 {
249 $this->api->api_message(0, USERALREADY);
250 exit();
251 }
252 }
253
254 /*SignUp User*/
255 public function SignUp()
256 {
257 $name = $this->input->post('name', TRUE);
258 $email_id = $this->input->post('email_id', TRUE);
259 $password = $this->input->post('password', TRUE);
260 $userRole = $this->input->post('role', TRUE);
261 $device_id = $this->input->post('device_id', TRUE);
262 $device_token = $this->input->post('device_token', TRUE);
263 $device_type = $this->input->post('device_type', TRUE);
264 $use_code = $this->input->post('use_code', TRUE);
265
266 if($use_code)
267 {
268 $getCode=$this->Api_model->getSingleRow(USR_TBL, array('referral_code'=>$referral_code));
269 if(!$getCode)
270 {
271 $this->api->api_message(0, "Please enter valid coupon code.");
272 }
273 }
274
275 if($userRole==1)
276 {
277 $userStatus = '1';
278 $approval_status = '1';
279 }
280 else
281 {
282 $userStatus = '1';
283 $approval_status = '1';
284 }
285
286 $created_at=time();
287 $updated_at=time();
288 $table= USR_TBL;
289 $condition = array('email_id'=>$email_id);
290 $columnName = 'email_id';
291 $referral_code=$this->api->random_num(6);
292 if($use_code)
293 {
294 $data = array('name'=>$name,'email_id'=>$email_id,'password'=>$password,'role'=>$userRole,'status'=>$userStatus,'created_at'=>$created_at,'updated_at'=>$updated_at,'referral_code'=>$referral_code,'approval_status'=>$approval_status,'user_referral_code'=>$use_code,'device_token'=>$device_token,'device_id'=>$device_id,'device_type'=>$device_type);
295 }
296 else
297 {
298 $data = array('name'=>$name,'email_id'=>$email_id,'password'=>$password,'role'=>$userRole,'status'=>$userStatus,'created_at'=>$created_at,'updated_at'=>$updated_at,'referral_code'=>$referral_code,'approval_status'=>$approval_status,'device_token'=>$device_token,'device_id'=>$device_id,'device_type'=>$device_type);
299 }
300
301 $get_user=$this->Api_model->getSingleRow($table, array('email_id'=>$email_id));
302
303 if(!$get_user)
304 {
305 $getUserId=$this->Api_model->insertGetId($table,$data);
306 if($getUserId){
307
308 if($userRole==1)
309 {
310 $msg='Obrigado por se registrar como artista na Ache na Gringa! Estamos felizes em dar nossos melhores serviços. Por favor entre.';
311 }
312 else
313 {
314 $url= base_url().'Webservice/userActive?user_id='.$getUserId;
315 $msg='Obrigado por inscrever-se! Sua conta foi criada, você pode fazer o login com as seguintes credenciais depois de ter ativado sua conta, pressionando o URL abaixo. Por favor clique ' .$url;
316 }
317 $this->send_email($email_id, REG_SUB, $msg);
318
319 $datatag='data';
320 $get_user=$this->Api_model->getSingleRow($table, array('user_id'=>$getUserId));
321 $this->api->api_message_data(1, USERRAGISTER,$datatag , $get_user);
322 }
323 else{
324 $this->api->api_message(0, TRY_AGAIN);
325 }
326 }
327 elseif($get_user->status ==0){
328
329 $getUserId= $get_user->user_id;
330
331 if($userRole==1)
332 {
333 $msg='Thanks for signing up! Your account has been created, please wait for the admin confirmation.';
334 }
335 else
336 {
337 $url= base_url().'Webservice/userActive?user_id='.$getUserId;
338 $msg='Obrigado por inscrever-se! Sua conta foi criada, você pode fazer o login com as seguintes credenciais depois de ter ativado sua conta, pressionando o URL abaixo. Por favor clique ' .$url;
339 }
340
341 $this->send_email($email_id, REG_SUB, $msg);
342 $this->api->api_message(0, CHECK_MAIL);
343 exit();
344 }
345 else
346 {
347 $this->api->api_message(0, USERALREADY);
348 exit();
349 }
350 }
351
352 /*Use Sign in*/
353 public function signInV1()
354 {
355 $email_id = $this->input->post('email_id', TRUE);
356 $password = $this->input->post('password', TRUE);
357 $table= USR_TBL;
358 $condition = array('email_id'=>$email_id);
359 $chkUser = $this->Api_model->getSingleRow($table, $condition);
360
361 if(!$chkUser)
362 {
363 $this->api->api_message(0, USER_NOT_FOUND);
364 exit();
365 }
366
367 //if($chkUser->password !=$password)
368 //{
369 //$this->api->api_message(0, PASS_NT_MTCH);
370 //exit();
371 //}
372
373 if($chkUser->status !=1)
374 {
375 $this->api->api_message(0, NOT_ACTIVE);
376 exit();
377 }
378
379 $user_id = $chkUser->user_id;
380 $name =$chkUser->name;
381 $email_id = $chkUser->email_id;
382 $role= $chkUser->role;
383 if($chkUser)
384 {
385 $datatag = 'data';
386
387 $this->api->api_message_data(1, LOGINSUCCESSFULL,$datatag , $chkUser);
388 }
389 else
390 {
391 $this->api->api_message(0, LOGINFAIL);
392 }
393 }
394
395 /*Use Sign in*/
396 public function signIn()
397 {
398 $email_id = $this->input->post('email_id', TRUE);
399 $password = $this->input->post('password', TRUE);
400 $role = $this->input->post('role', TRUE);
401 $datadevice['device_id'] = $this->input->post('device_id', TRUE);
402 $datadevice['device_token'] = $this->input->post('device_token', TRUE);
403 $datadevice['device_type'] = $this->input->post('device_type', TRUE);
404 $table= USR_TBL;
405 $condition = array('email_id'=>$email_id,'role'=>$role);
406 $chkUser = $this->Api_model->getSingleRow($table, $condition);
407
408 if(!$chkUser)
409 {
410 $this->api->api_message(0, USER_NOT_FOUND);
411 exit();
412 }
413
414 //if($chkUser->password !=$password)
415 //{
416 //$this->api->api_message(0, PASS_NT_MTCH);
417 //exit();
418 //}
419
420 if($chkUser->status !=1)
421 {
422 $this->api->api_message(0, NOT_ACTIVE);
423 exit();
424 }
425
426 if($chkUser->approval_status !=1)
427 {
428 $this->api->api_message(0, 'Hey, Please wait for the admin approval.');
429 exit();
430 }
431
432 $user_id = $chkUser->user_id;
433 $name =$chkUser->name;
434 $email_id = $chkUser->email_id;
435 $role= $chkUser->role;
436 if($chkUser)
437 {
438 if($role==1)
439 {
440 $checkArtist = $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$user_id));
441
442 if($checkArtist)
443 {
444 if($chkUser->image)
445 {
446 $chkUser->image= base_url().$chkUser->image;
447 }
448 else
449 {
450 $chkUser->image= base_url()."assets/images/image.png";
451 }
452 }
453 else
454 {
455 $chkUser->image= base_url()."assets/images/image.png";
456 }
457 }
458 else
459 {
460 if($chkUser->image)
461 {
462 $chkUser->image= base_url().$chkUser->image;
463 }
464 else
465 {
466 $chkUser->image= base_url()."assets/images/image.png";
467 }
468 }
469
470 $chkUser->device_id=$datadevice['device_id'];
471 $chkUser->device_type=$datadevice['device_type'];
472 $chkUser->device_token=$datadevice['device_token'];
473
474 $where = array('email_id'=>$email_id);
475 $updateUser= $this->Api_model->updateSingleRow(USR_TBL,$where,$datadevice);
476
477 $datatag = 'data';
478
479 $this->api->api_message_data(1, LOGINSUCCESSFULL,$datatag , $chkUser);
480 }
481 else
482 {
483 $this->api->api_message(0, LOGINFAIL);
484 }
485 }
486
487 /*Get all Category*/
488 public function getAllCaegory()
489 {
490 $user_id = $this->input->post('user_id', TRUE);
491
492 $this->checkUserStatus($user_id);
493 $get_cat=$this->Api_model->getAllDataWhere(array('status'=>1),CAT_TBL);
494
495 if($get_cat)
496 {
497 $get_cats= array();
498 foreach ($get_cat as $get_cat) {
499
500 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
501 if($commission_setting->commission_type==0)
502 {
503 $get_cat->price= $get_cat->price;
504 }
505 elseif($commission_setting->commission_type==1)
506 {
507 if($commission_setting->flat_type==2)
508 {
509 $get_cat->price= $commission_setting->flat_amount;
510 }
511 elseif ($commission_setting->flat_type==1)
512 {
513 $get_cat->price= $commission_setting->flat_amount;
514 }
515 }
516
517 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
518 $get_cat->currency_type= $currency_setting->currency_symbol;
519
520 array_push($get_cats, $get_cat);
521 }
522 $this->api->api_message_data(1, ALL_CAT,'data' , $get_cats);
523 }
524 else
525 {
526 $this->api->api_message(0, NO_DATA);
527 }
528 }
529
530 /*get Skills by Category*/
531 public function getSkillsByCategory()
532 {
533 $cat_id = $this->input->post('cat_id', TRUE);
534 $user_id = $this->input->post('user_id', TRUE);
535
536 $this->checkUserStatus($user_id);
537
538 $where=array('cat_id'=>$cat_id, 'status'=>1);
539
540 $get_skills=$this->Api_model->getAllDataWhere($where,'skills');
541
542 if($get_skills)
543 {
544 $this->api->api_message_data(1, ALL_SKILLS,'data' , $get_skills);
545 }
546 else
547 {
548 $this->api->api_message(0, NO_DATA);
549 }
550
551 }
552
553 /*Add gallery for artist*/
554 public function addGallery()
555 {
556 $user_id= $this->input->post('user_id');
557 $image= $this->input->post('image');
558
559 $this->checkUserStatus($user_id);
560
561 $this->load->library('upload');
562
563 $config['image_library'] = 'gd2';
564 $config['upload_path'] = './assets/images/gallery/';
565 $config['allowed_types'] = 'gif|jpg|jpeg|png';
566 $config['max_size'] = 10000;
567 $config['file_name'] = time();
568 $config['create_thumb'] = TRUE;
569 $config['maintain_ratio'] = TRUE;
570 $config['width'] = 250;
571 $config['height'] = 250;
572 $this->upload->initialize($config);
573 $galleryImage="";
574 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
575 {
576 $galleryImage='assets/images/gallery/'.$this->upload->data('file_name');
577 }
578 else
579 {
580 // echo $this->upload->display_errors();
581 }
582
583 $data['user_id']=$user_id;
584 $data['image']=$galleryImage;
585 $data['created_at']=time();
586 $data['updated_at']=time();
587 $getId=$this->Api_model->insertGetId(GLY_TBL,$data);
588 if($getId)
589 {
590 $this->api->api_message(1, ADD_GALLERY);
591 }
592 else
593 {
594 $this->api->api_message(0, NO_DATA);
595 }
596 }
597
598 public function send_email($email_id, $subject, $msg)
599 {
600 $this->load->library('email');
601 $this->email->set_mailtype("html");
602 $this->email->set_newline("\r\n");
603
604 $from_email = SENDER_EMAIL;
605 $this->email->from($from_email, "Ache na Gringa - Recuperação de Senha");
606 $this->email->to($email_id);
607 $this->email->subject($subject);
608
609 $datas['msg']=$msg;
610 $body = $this->load->view('main.php',$datas,TRUE);
611 $this->email->message($body);
612 $this->email->send();
613 }
614
615 /*Get all Category*/
616 public function getAllArtists()
617 {
618 $latitude_app=$this->input->post('latitude');
619 $longitude_app=$this->input->post('longitude');
620 $category_id=$this->input->post('category_id');
621 $distance=$this->input->post('distance');
622 $user_id=$this->input->post('user_id');
623 $page=$this->input->post('page');
624
625 $page= isset($page) ? $page: 1;
626
627 //$this->checkUserStatus($user_id);
628
629 if($category_id)
630 {
631 $where =array('category_id'=>$category_id,'update_profile'=>1,'booking_flag'=>0,'is_online'=>1);
632
633 $artist=$this->Api_model->getAllDataWhereLimit($where,ART_TBL,$page);
634 }
635 else
636 {
637 $artist=$this->Api_model->getAllDataWhereLimit(array('update_profile'=>1,'booking_flag'=>0,'is_online'=>1),ART_TBL,$page);
638 }
639
640 function distance($lat1, $lon1, $lat2, $lon2)
641 {
642
643 try
644 {
645 $theta = $lon1 - $lon2;
646 $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
647 $dist = acos($dist);
648 $dist = rad2deg($dist);
649 $miles = $dist * 60 * 1.1515;
650 return ($miles * 1.609344);
651 }
652
653 catch(Exception $e)
654 {
655 return (0.0);
656 }
657 }
658
659 if($artist)
660 {
661 $artists= array();
662 foreach ($artist as $artist)
663 {
664 $jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist->user_id,'booking_flag'=>4));
665
666 $artist->total=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist->user_id,));
667 if($artist->total==0)
668 {
669 $artist->percentages=0;
670 }
671 else
672 {
673 $artist->percentages=round(($jobDone*100) / $artist->total);
674 }
675 $artist->jobDone=$jobDone;
676
677 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$artist->category_id));
678 $getUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$artist->user_id));
679 if($getUser->image)
680 {
681 $artist->image=base_url().$getUser->image;
682 }
683 else
684 {
685 $artist->image=base_url()."assets/images/image.png";
686 }
687 $artist->category_name=$get_cat->cat_name;//
688
689
690 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
691
692 $artist->currency_type=$currency_setting->currency_symbol;
693 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
694 $artist->commission_type=$commission_setting->commission_type;
695 $artist->flat_type=$commission_setting->flat_type;
696 if($commission_setting->commission_type==0)
697 {
698 $artist->category_price=$get_cat->price;
699 }
700 elseif($commission_setting->commission_type==1)
701 {
702 if($commission_setting->flat_type==2)
703 {
704 $artist->category_price = $commission_setting->flat_amount;
705 }
706 elseif ($commission_setting->flat_type==1)
707 {
708 $artist->category_price = $commission_setting->flat_amount;
709 }
710 }
711
712 $distance =distance($latitude_app,$longitude_app,$artist->latitude,$artist->longitude);
713 $distance=round($distance);
714 $distance_str="$distance";
715 $artist->distance=$distance_str;
716 $where= array('artist_id'=>$artist->user_id);
717 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
718 if($ava_rating[0]->rating==null)
719 {
720 $ava_rating[0]->rating="0";
721 }
722 $artist->ava_rating= round($ava_rating[0]->rating, 2);
723
724
725 $check_fav= $this->Api_model->check_favorites($user_id,$artist->user_id);
726 $artist->fav_status= $check_fav ? "1":"0";
727
728 array_push($artists, $artist);
729 }
730
731 usort($artists, function($a,$b) {
732 if($a->distance == $b->distance) return 0;
733 return ($a->distance < $b->distance) ? -1 : 1;
734 });
735
736
737 $this->api->api_message_data(1, ALL_ARTISTS,'data' , $artists);
738 }
739 else
740 {
741 $this->api->api_message(0, NO_DATA);
742 }
743 }
744
745 /*get profile by user_id*/
746 public function getArtistByid()
747 {
748 $artist_id = $this->input->post('artist_id', TRUE);
749 $user_id = $this->input->post('user_id', TRUE);
750
751 $this->checkUserStatus($user_id);
752
753 $where=array('user_id'=>$artist_id);
754 $get_artists=$this->Api_model->getSingleRow(ART_TBL,$where);
755 if($get_artists)
756 {
757 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
758 $getUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_artists->user_id));
759 if ($getUser->image)
760 {
761 $get_artists->image=base_url().$getUser->image;
762 }
763 else
764 {
765 $get_artists->image=base_url()."assets/images/image.png";
766 }
767 $get_artists->category_name=$get_cat->cat_name;
768
769 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
770 $get_artists->currency_type=$currency_setting->currency_symbol;
771
772 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
773 $get_artists->commission_type=$commission_setting->commission_type;
774 $get_artists->flat_type=$commission_setting->flat_type;
775 if($commission_setting->commission_type==0)
776 {
777 $get_artists->category_price=$get_cat->price;
778 }
779 elseif($commission_setting->commission_type==1)
780 {
781 if($commission_setting->flat_type==2)
782 {
783 $get_artists->category_price = $commission_setting->flat_amount;
784 }
785 elseif ($commission_setting->flat_type==1)
786 {
787 $get_artists->category_price = $commission_setting->flat_amount;
788 }
789 }
790
791 $where= array('artist_id'=>$artist_id, 'status'=>1);
792 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
793 if($ava_rating[0]->rating==null)
794 {
795 $ava_rating[0]->rating="0";
796 }
797 $get_artists->ava_rating=$ava_rating[0]->rating;
798
799 $skills=json_decode($get_artists->skills);
800 $skill= array();
801 if(!empty($skills))
802 {
803 foreach ($skills as $skills)
804 {
805 $get_skills= $this->Api_model->getSingleRow('skills', array('id'=>$skills));
806 array_push($skill, $get_skills);
807 }
808 }
809
810 $get_artists->skills= $skill;
811
812 $get_products= $this->Api_model->getAllDataWhere(array('user_id'=>$get_artists->user_id), 'products');
813
814 $products= array();
815 foreach ($get_products as $get_products) {
816 $get_products->product_image=base_url().$get_products->product_image;
817 $get_products->currency_type=$currency_setting->currency_symbol;
818 array_push($products, $get_products);
819 }
820 $get_artists->products=$products;
821
822 $get_reviews= $this->Api_model->getAllDataWhere(array('artist_id'=>$artist_id,'status'=>1), 'rating');
823 $review = array();
824 foreach ($get_reviews as $get_reviews) {
825
826 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_reviews->user_id));
827 $get_reviews->name= $get_user->name;
828 if($get_user->image)
829 {
830 $get_reviews->image= base_url().$get_user->image;
831 }
832 else
833 {
834 $get_reviews->image= base_url()."assets/images/image.png";
835 }
836 array_push($review, $get_reviews);
837 }
838 $get_artists->reviews=$review;
839
840 $get_gallery= $this->Api_model->getAllDataWhere(array('user_id'=>$artist_id), GLY_TBL);
841
842 $gallery = array();
843 foreach ($get_gallery as $get_gallery) {
844
845 $get_gallery->image= base_url().$get_gallery->image;
846 array_push($gallery, $get_gallery);
847 }
848 $get_artists->gallery=$gallery;
849
850 $get_qualifications= $this->Api_model->getAllDataWhere(array('user_id'=>$artist_id), 'qualifications');
851
852 $get_artists->qualifications=$get_qualifications;
853
854 $artist_bookings= array();
855 $artist_booking1= array();
856 $artist_booking= $this->Api_model->getAllDataLimitWhere(ABK_TBL,array('artist_id'=>$artist_id, 'booking_flag'=>4), 7);
857 foreach ($artist_booking as $artist_booking)
858 {
859 $rat=$this->Api_model->getSingleRow('rating', array('booking_id'=>$artist_booking->id, 'status'=>1));
860 if($rat)
861 {
862 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$rat->user_id));
863 $artist_booking1['username']= $get_user->name;
864 if($get_user->image)
865 {
866 $artist_booking1['userImage']= base_url().$get_user->image;
867 }
868 else
869 {
870 $artist_booking1['userImage']= base_url()."assets/images/image.png";
871 }
872 $artist_booking1['rating']=$rat->rating;
873 $artist_booking1['comment']=$rat->comment;
874 $artist_booking1['ratingDate']=$rat->created_at;
875 }
876 else
877 {
878 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$artist_booking->user_id));
879 $artist_booking1['username']= $get_user->name;
880 if($get_user->image)
881 {
882 $artist_booking1['userImage']= base_url().$get_user->image;
883 }
884 else
885 {
886 $artist_booking1['userImage']= base_url()."assets/images/image.png";
887 }
888 $artist_booking1['rating']="0";
889 $artist_booking1['comment']="";
890 $artist_booking1['ratingDate']=$artist_booking->created_at;
891 }
892
893 $artist_booking1['price']=$artist_booking->price;
894 $artist_booking1['currency_type']=$currency_setting->currency_symbol;
895 $artist_booking1['booking_time']=$artist_booking->booking_time;
896 $artist_booking1['booking_date']=$artist_booking->booking_date;
897 array_push($artist_bookings, $artist_booking1);
898 }
899 $get_artists->artist_booking= $artist_bookings;
900
901 $earning=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id));
902
903 $get_artists->earning= round($earning->total_amount, 2);
904
905 $get_artists->jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id,'booking_flag'=>4));
906
907 $get_artists->totalJob=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id));
908
909 if($get_artists->totalJob==0)
910 {
911 $get_artists->completePercentages=0;
912 }
913 else
914 {
915 $get_artists->completePercentages=round(($get_artists->jobDone*100) / $get_artists->totalJob);
916 }
917 $check_fav= $this->Api_model->check_favorites($user_id,$artist_id);
918 $get_artists->fav_status= $check_fav ? "1":"0";
919
920 $this->api->api_message_data(1, "Get artist detail.",'data' , $get_artists);
921 }
922 else
923 {
924 $this->api->api_message(0, NO_DATA);
925 }
926 }
927
928 /*Update artist personal info*/
929 public function generateTicket()
930 {
931 $data['user_id'] = $this->input->post('user_id', TRUE);
932 $data['reason'] = $this->input->post('reason', TRUE);
933 $data['craeted_at'] = time();
934
935 $this->checkUserStatus($data['user_id']);
936
937 $ticketId=$this->Api_model->insertGetId('ticket',$data);
938 if($ticketId)
939 {
940 $this->api->api_message(1, "Ticket generated successfully.");
941 }
942 else
943 {
944 $this->api->api_message(0, NO_DATA);
945 }
946 }
947
948 /*get Ticket*/
949 public function getMyTicket()
950 {
951 $user_id= $this->input->post('user_id', TRUE);
952 $this->checkUserStatus($user_id);
953
954 $get_ticket= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'ticket');
955 if($get_ticket)
956 {
957 $this->api->api_message_data(1, "Get my tickets.",'my_ticket', $get_ticket);
958 }
959 else
960 {
961 $this->api->api_message(0, "Not yet any tickets.");
962 }
963 }
964
965 /*Add ticket Comments*/
966 public function addTicketComments()
967 {
968 $user_id= $this->input->post('user_id', TRUE);
969 $this->checkUserStatus($user_id);
970
971 $data['ticket_id']= $this->input->post('ticket_id', TRUE);
972 $data['comment']= $this->input->post('comment', TRUE);
973 $data['user_id']= $user_id;
974 $data['role']= 1;
975 $data['created_at']= time();
976
977 $ticketId=$this->Api_model->insertGetId('ticket_comments',$data);
978 if($ticketId)
979 {
980 $this->api->api_message(1, "Thanks for the review.");
981 }
982 else
983 {
984 $this->api->api_message(0, NO_DATA);
985 }
986 }
987
988 /*get Ticket Comments*/
989 public function getTicketComments()
990 {
991 $user_id= $this->input->post('user_id', TRUE);
992 $ticket_id= $this->input->post('ticket_id', TRUE);
993 $this->checkUserStatus($user_id);
994
995 $ticket_comments= $this->Api_model->getAllDataWhere(array('ticket_id'=>$ticket_id), 'ticket_comments');
996
997 $ticket_comment= array();
998 foreach ($ticket_comments as $ticket_comments)
999 {
1000 if($ticket_comments->user_id !=0)
1001 {
1002 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$ticket_comments->user_id));
1003 $ticket_comments->userName=$getUser->name;
1004 }
1005 else
1006 {
1007 $ticket_comments->userName="Admin";
1008 }
1009 array_push($ticket_comment, $ticket_comments);
1010 }
1011
1012 if($ticket_comments)
1013 {
1014 $this->api->api_message_data(1, "Get ticket comments.",'ticket_comment', $ticket_comment);
1015 }
1016 else
1017 {
1018 $this->api->api_message(0, "Not yet any tickets.");
1019 }
1020 }
1021
1022 /*get conversation*/
1023 public function getNotifications()
1024 {
1025 $user_id= $this->input->post('user_id', TRUE);
1026 $this->checkUserStatus($user_id);
1027
1028 $get_notifications= $this->Api_model->getAllDataWhereAndOr(array('user_id'=>$user_id), array('type'=>"All"), NTS_TBL);
1029 if($get_notifications)
1030 {
1031 $this->api->api_message_data(1, "Get my notifications.",'my_notifications', $get_notifications);
1032 }
1033 else
1034 {
1035 $this->api->api_message(0, "Not yet any notifications.");
1036 }
1037 }
1038
1039 /*Update artist personal info*/
1040 public function deleteProfileImage()
1041 {
1042 $user_id = $this->input->post('user_id', TRUE);
1043
1044 $this->checkUserStatus($user_id);
1045
1046 $updateUser= $this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$user_id),array('image'=>''));
1047
1048 $this->api->api_message(1, "Profile image deleted successfully.");
1049 }
1050
1051 public function artistImage()
1052 {
1053 $user_id = $this->input->post('user_id', TRUE);
1054 $image = $this->input->post('image', TRUE);
1055
1056 $this->load->library('upload');
1057
1058 $config['image_library'] = 'gd2';
1059 $config['upload_path'] = './assets/images/';
1060 $config['allowed_types'] = 'gif|jpg|jpeg|png';
1061 $config['max_size'] = 10000;
1062 $config['file_name'] = time();
1063 $config['create_thumb'] = TRUE;
1064 $config['maintain_ratio'] = TRUE;
1065 $config['width'] = 250;
1066 $config['height'] = 250;
1067 $this->upload->initialize($config);
1068 $updateduserimage="";
1069 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
1070 {
1071 $updateduserimage='assets/images/'.$this->upload->data('file_name');
1072 }
1073 else
1074 {
1075 // echo $this->upload->display_errors();
1076 }
1077
1078 $check_user = $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$user_id));
1079 if($check_user)
1080 {
1081 $data['image']=$updateduserimage;
1082
1083 $where= array('user_id'=>$user_id);
1084 $updateUser= $this->Api_model->updateSingleRow(ART_TBL,$where,$data);
1085 if($updateUser)
1086 {
1087 $checkUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
1088
1089 $checkartist=$this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$user_id));
1090
1091 if($checkartist->image)
1092 {
1093 $checkUser->image= base_url().$checkartist->image;
1094 }
1095 else
1096 {
1097 $checkUser->image= base_url().'assets/images/image.png';
1098 }
1099 $this->api->api_message_data(1, ARTIST_UPDATE,'data' , $checkUser);
1100 }
1101 else
1102 {
1103 $this->api->api_message(0, TRY_AGAIN);
1104 }
1105 }
1106 else{
1107
1108 $this->load->library('upload');
1109
1110 $config['image_library'] = 'gd2';
1111 $config['upload_path'] = './assets/images/';
1112 $config['allowed_types'] = 'gif|jpg|jpeg|png';
1113 $config['max_size'] = 10000;
1114 $config['file_name'] = time();
1115 $config['create_thumb'] = TRUE;
1116 $config['maintain_ratio'] = TRUE;
1117 $config['width'] = 250;
1118 $config['height'] = 250;
1119 $this->upload->initialize($config);
1120 $updateduserimage="";
1121 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
1122 {
1123 $updateduserimage='assets/images/'.$this->upload->data('file_name');
1124 }
1125 else
1126 {
1127 // echo $this->upload->display_errors();
1128 }
1129
1130 $data['user_id']=$user_id;
1131 if($updateduserimage)
1132 {
1133 $data['image']=$updateduserimage;
1134 }
1135
1136 $getUserId=$this->Api_model->insertGetId(ART_TBL,$data);
1137
1138 if($getUserId)
1139 {
1140
1141 $checkUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
1142
1143 $checkartist=$this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$user_id));
1144
1145 if($checkartist->image)
1146 {
1147 $checkUser->image= base_url().$checkartist->image;
1148 }
1149 else
1150 {
1151 $checkUser->image= base_url().'assets/images/image.png';
1152 }
1153
1154 $this->api->api_message_data(1, ARTIST_UPDATE,'data' , $checkUser);
1155 }
1156 else
1157 {
1158 $this->api->api_message(0, TRY_AGAIN);
1159 }
1160 }
1161 }
1162 /*Update artist personal info*/
1163 public function artistPrsonalInfo()
1164 {
1165 $user_id = $this->input->post('user_id', TRUE);
1166 $name = $this->input->post('name', TRUE);
1167 $category_id = $this->input->post('category_id', TRUE);
1168 $gender = $this->input->post('gender', TRUE);
1169 $city = $this->input->post('city', TRUE);
1170 $country = $this->input->post('country', TRUE);
1171 $preference = $this->input->post('preference', TRUE);
1172 $category_id = $this->input->post('category_id', TRUE);
1173 $about_us = $this->input->post('about_us', TRUE);
1174 $description = $this->input->post('description', TRUE);
1175 $bio = $this->input->post('bio', TRUE);
1176 $location = $this->input->post('location', TRUE);
1177 $image = $this->input->post('image', TRUE);
1178 $longitude = $this->input->post('longitude', TRUE);
1179 $latitude = $this->input->post('latitude', TRUE);
1180 $skills = $this->input->post('skills', TRUE);
1181 $price = $this->input->post('price', TRUE);
1182 $video_url = $this->input->post('video_url', TRUE);
1183
1184
1185 $this->checkUserStatus($user_id);
1186
1187 $check_user = $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$user_id));
1188 if($check_user)
1189 {
1190
1191 $this->load->library('upload');
1192
1193 $config['image_library'] = 'gd2';
1194 $config['upload_path'] = './assets/images/';
1195 $config['allowed_types'] = 'gif|jpg|jpeg|png';
1196 $config['max_size'] = 10000;
1197 $config['file_name'] = time();
1198 $config['create_thumb'] = TRUE;
1199 $config['maintain_ratio'] = TRUE;
1200 $config['width'] = 250;
1201 $config['height'] = 250;
1202 $this->upload->initialize($config);
1203 $updateduserimage="";
1204 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
1205 {
1206 $updateduserimage='assets/images/'.$this->upload->data('file_name');
1207 }
1208 else
1209 {
1210 // echo $this->upload->display_errors();
1211 }
1212
1213 $where= array('user_id'=>$user_id);
1214 $data['name']=isset($name) ? $name: $check_user->name;
1215
1216 $this->Api_model->updateSingleRow(USR_TBL,$where,$data);
1217
1218 if($check_user->longitude =='' || $check_user->longitude =NULL || $check_user->latitude =='' || $check_user->latitude =NULL)
1219 {
1220 $longitude=75.897542;
1221 $latitude=22.749753;
1222 }
1223 else
1224 {
1225 $longitude=$check_user->longitude;
1226 $latitude=$check_user->latitude;
1227 }
1228
1229 $data['gender']=isset($gender) ? $gender: $check_user->gender;
1230 $data['city']=isset($city) ? $city: $check_user->city;
1231 $data['country']=isset($country) ? $country: $check_user->country;
1232 $data['preference']=isset($preference) ? $preference: $check_user->preference;
1233 $data['price']=isset($price) ? $price: $check_user->price;
1234 $data['skills']=isset($skills) ? $skills: $check_user->skills;
1235 $data['about_us']=isset($about_us) ? $about_us: $check_user->about_us;
1236 $data['longitude']=isset($longitude) ? $longitude: $longitude;
1237 $data['latitude']=isset($latitude) ? $latitude: $latitude;
1238 $data['description']=isset($description) ? $description: $check_user->description;
1239 $data['video_url']=isset($video_url) ? $video_url: $check_user->video_url;
1240 if($updateduserimage)
1241 {
1242 $data['image']=$updateduserimage;
1243 }
1244
1245 $data['category_id']=isset($category_id) ? $category_id: $check_user->category_id;
1246 $data['bio']=isset($bio) ? $bio: $check_user->bio;
1247 $data['updated_at']=time();
1248 $data['update_profile']=1;
1249 $data['location']=isset($location) ? $location: $check_user->location;
1250 $updateUser= $this->Api_model->updateSingleRow(ART_TBL,$where,$data);
1251 if($updateUser)
1252 {
1253 $where =array('user_id'=>$user_id);
1254 $get_artists=$this->Api_model->getSingleRow(ART_TBL,$where);
1255 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
1256
1257 if(!empty($get_cat))
1258 {
1259 $get_artists->category_name=$get_cat->cat_name;
1260
1261 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
1262 if($commission_setting->commission_type==0)
1263 {
1264 $get_artists->category_price=$get_cat->price;
1265 }
1266 elseif($commission_setting->commission_type==1)
1267 {
1268 if($commission_setting->flat_type==2)
1269 {
1270 $get_artists->category_price = $commission_setting->flat_amount;
1271 }
1272 elseif ($commission_setting->flat_type==1)
1273 {
1274 $get_artists->category_price = $commission_setting->flat_amount;
1275 }
1276 }
1277
1278 }
1279 else
1280 {
1281 $get_artists->category_name="";
1282 $get_artists->category_price="";
1283 }
1284
1285 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
1286 $get_artists->currency_type=$currency_setting->currency_symbol;
1287
1288 $checkArtist = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_artists->user_id));
1289
1290 if($checkArtist->image)
1291 {
1292 $get_artists->image=base_url().$checkArtist->image;
1293 }
1294 else
1295 {
1296 $get_artists->image=base_url().'/assets/images/image.png';
1297 }
1298
1299 $where= array('artist_id'=>$get_artists->id);
1300 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
1301 if($ava_rating[0]->rating==null)
1302 {
1303 $ava_rating[0]->rating="0";
1304 }
1305 $get_artists->ava_rating=$ava_rating[0]->rating;
1306
1307 $skills=json_decode($get_artists->skills);
1308 $skill= array();
1309 if(!empty($skills))
1310 {
1311 foreach ($skills as $skills)
1312 {
1313 $get_skills= $this->Api_model->getSingleRow('skills', array('id'=>$skills));
1314 array_push($skill, $get_skills);
1315 }
1316 $get_artists->skills= $skill;
1317 }
1318 else
1319 {
1320 $get_artists->skills= array();
1321 }
1322
1323 $get_products= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'products');
1324
1325 $products= array();
1326 foreach ($get_products as $get_products) {
1327 # code...
1328 $get_products->product_image=base_url().$get_products->product_image;
1329 array_push($products, $get_products);
1330 }
1331 $get_artists->products=$products;
1332
1333 $get_reviews= $this->Api_model->getAllDataWhere(array('artist_id'=>$user_id, 'status'=>1), 'rating');
1334 $review = array();
1335 foreach ($get_reviews as $get_reviews) {
1336
1337 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_reviews->user_id));
1338 $get_reviews->name= $get_user->name;
1339
1340 if($get_user->image)
1341 {
1342 $get_reviews->image=base_url().$get_user->image;
1343 }
1344 else
1345 {
1346 $get_reviews->image=base_url().'/assets/images/image.png';
1347 }
1348
1349 array_push($review, $get_reviews);
1350 }
1351 $get_artists->reviews=$review;
1352
1353 $get_qualifications= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'qualifications');
1354
1355 $get_artists->qualifications=$get_qualifications;
1356
1357 $get_gallery= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), GLY_TBL);
1358
1359 $gallery = array();
1360 foreach ($get_gallery as $get_gallery) {
1361
1362 $get_gallery->image= base_url().$get_gallery->image;
1363 array_push($gallery, $get_gallery);
1364 }
1365 $get_artists->gallery=$gallery;
1366
1367 $earning=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$user_id));
1368
1369 $get_artists->earning= round($earning->total_amount, 2);
1370
1371 $get_artists->jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$user_id,'booking_flag'=>4));
1372
1373 $get_artists->totalJob=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$user_id));
1374
1375 if($get_artists->totalJob==0)
1376 {
1377 $get_artists->completePercentages=0;
1378 }
1379 else
1380 {
1381 $get_artists->completePercentages=round(($get_artists->jobDone*100) / $get_artists->totalJob);
1382 }
1383
1384 $artist_booking= $this->Api_model->getAllDataLimitWhere(ABK_TBL,array('artist_id'=>$user_id, 'booking_flag'=>4), 7);
1385 $artist_bookings = array();
1386 foreach ($artist_booking as $artist_booking)
1387 {
1388 $rat=$this->Api_model->getSingleRow('rating', array('booking_id'=>$artist_booking->id, 'status'=>1));
1389 if($rat)
1390 {
1391 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$rat->user_id));
1392 $artist_booking1['username']= $get_user->name;
1393 if($get_user->image)
1394 {
1395 $artist_booking1['userImage']= base_url().$get_user->image;
1396 }
1397 else
1398 {
1399 $artist_booking1['userImage']= base_url()."assets/images/image.png";
1400 }
1401 $artist_booking1['rating']=$rat->rating;
1402 $artist_booking1['comment']=$rat->comment;
1403 $artist_booking1['ratingDate']=$rat->created_at;
1404 }
1405 else
1406 {
1407 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$artist_booking->user_id));
1408 $artist_booking1['username']= $get_user->name;
1409 if($get_user->image)
1410 {
1411 $artist_booking1['userImage']= base_url().$get_user->image;
1412 }
1413 else
1414 {
1415 $artist_booking1['userImage']= base_url()."assets/images/image.png";
1416 }
1417 $artist_booking1['rating']="0";
1418 $artist_booking1['comment']="";
1419 $artist_booking1['ratingDate']=$artist_booking->created_at;
1420 }
1421
1422 $artist_booking1['price']=$artist_booking->price;
1423 $artist_booking1['booking_time']=$artist_booking->booking_time;
1424 $artist_booking1['booking_date']=$artist_booking->booking_date;
1425 array_push($artist_bookings, $artist_booking1);
1426 }
1427 $get_artists->artist_booking= $artist_bookings;
1428
1429 $this->api->api_message_data(1, ARTIST_UPDATE,'data' , $get_artists);
1430 }
1431 else
1432 {
1433 $this->api->api_message(0, TRY_AGAIN);
1434 }
1435 }
1436 else
1437 {
1438 $this->load->library('upload');
1439
1440 $config['image_library'] = 'gd2';
1441 $config['upload_path'] = './assets/images/';
1442 $config['allowed_types'] = 'gif|jpg|jpeg|png';
1443 $config['max_size'] = 10000;
1444 $config['file_name'] = time();
1445 $config['create_thumb'] = TRUE;
1446 $config['maintain_ratio'] = TRUE;
1447 $config['width'] = 250;
1448 $config['height'] = 250;
1449 $this->upload->initialize($config);
1450 $updateduserimage="";
1451 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
1452 {
1453 $updateduserimage='assets/images/'.$this->upload->data('file_name');
1454 }
1455 else
1456 {
1457 // echo $this->upload->display_errors();
1458 }
1459
1460 $data['user_id']=$user_id;
1461 $data['name']=isset($name) ? $name: "";
1462 if($updateduserimage)
1463 {
1464 $data['image']=$updateduserimage;
1465 }
1466 $this->Api_model->updateSingleRow(USR_TBL,array('user_id'=>$user_id),$data);
1467
1468 $data['created_at']=time();
1469 $data['update_profile']=1;
1470 $data['updated_at']=time();
1471 $data['gender']=isset($gender) ? $gender: "";
1472 $data['city']=isset($city) ? $city: "";
1473 $data['preference']=isset($preference) ? $preference: "";
1474 $data['about_us']=isset($about_us) ? $about_us: "";
1475 $data['price']=isset($price) ? $price: "";
1476 $data['skills']=isset($skills) ? $skills: "";
1477 $data['longitude']=isset($longitude) ? $longitude: "75.897542";
1478 $data['latitude']=isset($latitude) ? $latitude: "22.749753";
1479 $data['category_id']=isset($category_id) ? $category_id: "";
1480 $data['description']=isset($description) ? $description: "";
1481 $data['bio']=isset($bio) ? $bio: "";
1482 $data['location']=isset($location) ? $location: "";
1483
1484 $getUserId=$this->Api_model->insertGetId(ART_TBL,$data);
1485
1486 if($getUserId)
1487 {
1488 $where =array('user_id'=>$user_id);
1489 $get_artists=$this->Api_model->getSingleRow(ART_TBL,$where);
1490
1491 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
1492 $checkArtist = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_artists->user_id));
1493
1494 if($checkArtist->image)
1495 {
1496 $get_artists->image=base_url().$checkArtist->image;
1497 }
1498 else
1499 {
1500 $get_artists->image=base_url().'/assets/images/image.png';
1501 }
1502
1503 if(!empty($get_cat))
1504 {
1505 $get_artists->category_name=$get_cat->cat_name;
1506 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
1507 if($commission_setting->commission_type==0)
1508 {
1509 $get_artists->category_price=$get_cat->price;
1510 }
1511 elseif($commission_setting->commission_type==1)
1512 {
1513 if($commission_setting->flat_type==2)
1514 {
1515 $get_artists->category_price = $commission_setting->flat_amount;
1516 }
1517 elseif ($commission_setting->flat_type==1)
1518 {
1519 $get_artists->category_price = $commission_setting->flat_amount;
1520 }
1521 }
1522 }
1523 else
1524 {
1525 $get_artists->category_name="";
1526 $get_artists->category_price="";
1527 }
1528
1529 $where= array('artist_id'=>$user_id);
1530 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
1531 if($ava_rating[0]->rating==null)
1532 {
1533 $ava_rating[0]->rating="0";
1534 }
1535 $get_artists->ava_rating=$ava_rating[0]->rating;
1536
1537 $skills=json_decode($get_artists->skills);
1538 $skill= array();
1539 if(!empty($skills))
1540 {
1541 foreach ($skills as $skills) {
1542 $get_skills= $this->Api_model->getSingleRow('skills', array('id'=>$skills));
1543 array_push($skill, $get_skills);
1544 }
1545 $get_artists->skills= $skill;
1546 }
1547 else
1548 {
1549 $get_artists->skills= array();
1550 }
1551
1552 $get_products= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'products');
1553
1554 $products= array();
1555 foreach ($get_products as $get_products) {
1556 $get_products->product_image=base_url().$get_products->product_image;
1557 array_push($products, $get_products);
1558 }
1559 $get_artists->products=$products;
1560
1561 $get_reviews= $this->Api_model->getAllDataWhere(array('artist_id'=>$user_id), 'rating');
1562 $review = array();
1563 foreach ($get_reviews as $get_reviews) {
1564
1565 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
1566 $get_reviews->name= $get_user->name;
1567 if($get_user->image)
1568 {
1569 $get_reviews->image=base_url().$get_user->image;
1570 }
1571 else
1572 {
1573 $get_reviews->image=base_url().'/assets/images/image.png';
1574 }
1575 array_push($review, $get_reviews);
1576 }
1577 $get_artists->reviews=$review;
1578
1579 $get_qualifications= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'qualifications');
1580
1581 $get_artists->qualifications=$get_qualifications;
1582
1583 $get_gallery= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), GLY_TBL);
1584
1585 $gallery = array();
1586 foreach ($get_gallery as $get_gallery) {
1587
1588 $get_gallery->image= base_url().$get_gallery->image;
1589 array_push($gallery, $get_gallery);
1590 }
1591 $get_artists->gallery=$gallery;
1592
1593 $earning=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$user_id));
1594
1595 $get_artists->earning= round($earning->total_amount, 2);
1596
1597 $get_artists->jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$user_id,'booking_flag'=>4));
1598
1599 $get_artists->totalJob=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$user_id));
1600
1601 if($get_artists->totalJob==0)
1602 {
1603 $get_artists->completePercentages=0;
1604 }
1605 else
1606 {
1607 $get_artists->completePercentages=round(($get_artists->jobDone*100) / $get_artists->totalJob);
1608 }
1609
1610 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
1611 $get_artists->currency_type=$currency_setting->currency_symbol;
1612
1613 $artist_booking= $this->Api_model->getAllDataLimitWhere(ABK_TBL,array('artist_id'=>$user_id, 'booking_flag'=>4), 7);
1614 $artist_bookings = array();
1615 foreach ($artist_booking as $artist_booking)
1616 {
1617 $rat=$this->Api_model->getSingleRow('rating', array('booking_id'=>$artist_booking->id, 'status'=>1));
1618 if($rat)
1619 {
1620 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$rat->user_id));
1621 $artist_booking1['username']= $get_user->name;
1622 if($get_user->image)
1623 {
1624 $artist_booking1['userImage']= base_url().$get_user->image;
1625 }
1626 else
1627 {
1628 $artist_booking1['userImage']= base_url()."assets/images/image.png";
1629 }
1630 $artist_booking1['rating']=$rat->rating;
1631 $artist_booking1['comment']=$rat->comment;
1632 $artist_booking1['ratingDate']=$rat->created_at;
1633 }
1634 else
1635 {
1636 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$artist_booking->user_id));
1637 $artist_booking1['username']= $get_user->name;
1638 if($get_user->image)
1639 {
1640 $artist_booking1['userImage']= base_url().$get_user->image;
1641 }
1642 else
1643 {
1644 $artist_booking1['userImage']= base_url()."assets/images/image.png";
1645 }
1646 $artist_booking1['rating']="0";
1647 $artist_booking1['comment']="";
1648 $artist_booking1['ratingDate']=$artist_booking->created_at;
1649 }
1650
1651 $artist_booking1['price']=$artist_booking->price;
1652 $artist_booking1['booking_time']=$artist_booking->booking_time;
1653 $artist_booking1['booking_date']=$artist_booking->booking_date;
1654 array_push($artist_bookings, $artist_booking1);
1655 }
1656 $get_artists->artist_booking= $artist_bookings;
1657
1658 $this->api->api_message_data(1, ARTIST_UPDATE,'data' , $get_artists);
1659 }
1660 else
1661 {
1662 $this->api->api_message(0, TRY_AGAIN);
1663 }
1664 }
1665 }
1666
1667 /*Add product by artist*/
1668 public function addProduct()
1669 {
1670 $data['user_id'] = $this->input->post('user_id', TRUE);
1671 $data['product_name'] = $this->input->post('product_name', TRUE);
1672 $product_image = $this->input->post('product_image', TRUE);
1673 $data['price'] = $this->input->post('price', TRUE);
1674
1675 $this->checkUserStatus($data['user_id']);
1676
1677 $this->load->library('upload');
1678
1679 $config['image_library'] = 'gd2';
1680 $config['upload_path'] = './assets/images/';
1681 $config['allowed_types'] = 'gif|jpg|jpeg|png';
1682 $config['max_size'] = 10000;
1683 $config['file_name'] = time();
1684 $config['create_thumb'] = TRUE;
1685 $config['maintain_ratio'] = TRUE;
1686 $config['width'] = 250;
1687 $config['height'] = 250;
1688 $this->upload->initialize($config);
1689 $pruductImage="";
1690 if ( $this->upload->do_upload('product_image') && $this->load->library('image_lib', $config))
1691 {
1692 $pruductImage='assets/images/'.$this->upload->data('file_name');
1693 }
1694 else
1695 {
1696 // echo $this->upload->display_errors();
1697 }
1698
1699 if($pruductImage)
1700 {
1701 $data['product_image']=$pruductImage;
1702 }
1703 $data['created_at']=time();
1704 $data['updated_at']=time();
1705
1706 $productId=$this->Api_model->insertGetId('products',$data);
1707
1708 if($productId)
1709 {
1710 $this->api->api_message(1, PRODUCT_ADD);
1711 }
1712 else
1713 {
1714 $this->api->api_message(0, TRY_AGAIN);
1715 }
1716
1717 }
1718
1719
1720 /*Add Qualification by artist*/
1721 public function addQualification()
1722 {
1723 $data['user_id'] = $this->input->post('user_id', TRUE);
1724 $data['title'] = $this->input->post('title', TRUE);
1725 $data['description'] = $this->input->post('description', TRUE);
1726
1727 $this->checkUserStatus($data['user_id']);
1728
1729 $data['created_at']=time();
1730 $data['updated_at']=time();
1731
1732 $productId=$this->Api_model->insertGetId('qualifications',$data);
1733
1734 if($productId)
1735 {
1736 $this->api->api_message(1, QUALIFICATION_ADD);
1737 }
1738 else
1739 {
1740 $this->api->api_message(0, TRY_AGAIN);
1741 }
1742 }
1743
1744 /*Add Rating for artist*/
1745 public function addRating()
1746 {
1747 $data['user_id'] = $this->input->post('user_id', TRUE);
1748 $data['booking_id'] = $this->input->post('booking_id', TRUE);
1749 $data['artist_id'] = $this->input->post('artist_id', TRUE);
1750 $data['rating'] = $this->input->post('rating', TRUE);
1751 $data['comment'] = $this->input->post('comment', TRUE);
1752
1753 $this->checkUserStatus($data['user_id']);
1754 $this->checkUserStatus($data['artist_id']);
1755
1756 $data['created_at']=time();
1757
1758 $get_rating= $this->Api_model->getSingleRow('rating', array('user_id'=>$data['user_id'],'artist_id'=>$data['artist_id'],'booking_id'=>$data['booking_id']));
1759 if($get_rating)
1760 {
1761 $this->api->api_message(1, "you already give review this artist.");
1762 }
1763 else
1764 {
1765 $productId=$this->Api_model->insertGetId('rating',$data);
1766 if($productId)
1767 {
1768 $this->api->api_message(1, ADD_COMMENT);
1769 }
1770 else
1771 {
1772 $this->api->api_message(0, TRY_AGAIN);
1773 }
1774 }
1775 }
1776
1777 public function getToken()
1778 {
1779 echo $this->api->strongToken(6);
1780 }
1781 /*Forget PAssword*/
1782 public function forgotPassword()
1783 {
1784 $email_id = $this->input->post('email_id', TRUE);
1785
1786 $checkEmail = $this->Api_model->getSingleRow(USR_TBL, array('email_id'=>$email_id));
1787 if($checkEmail)
1788 {
1789 $password =$this->api->strongToken(6);
1790 $msg='Sua nova senha é '.$password;
1791 $this->send_email($email_id, PWD_SUB, $msg);
1792
1793 $data = array('password'=>$password);
1794 $updatePassword= $this->Api_model->updateSingleRow(USR_TBL,array('email_id'=>$email_id),$data);
1795 if($updatePassword==1)
1796 {
1797 $this->api->api_message(1, FOUND);
1798 }
1799 else
1800 {
1801 $this->api->api_message(0, NOTUPDATE);
1802 }
1803 }
1804 else
1805 {
1806 $this->api->api_message(0, NOTFOUND);
1807 }
1808 }
1809
1810 public function userActive()
1811 {
1812 $user_id= $_GET['user_id'];
1813 $get_user= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
1814 if($get_user)
1815 {
1816 $where = array('user_id'=>$get_user->user_id);
1817 $data = array('status'=>1);
1818 $update= $this->Api_model->updateSingleRow(USR_TBL, $where, $data);
1819
1820 echo "Account has been activated. Please Login";
1821 }
1822 }
1823
1824 public function onlineOffline()
1825 {
1826 $user_id = $this->input->post('user_id', TRUE);
1827 $is_online = $this->input->post('is_online', TRUE);
1828 $update= $this->Api_model->updateSingleRow(ART_TBL, array('user_id'=> $user_id), array('is_online'=>$is_online));
1829 if($is_online==1)
1830 {
1831 $this->api->api_message(1, "Artist online successfully.");
1832 }
1833 elseif ($is_online==0)
1834 {
1835 $this->api->api_message(1, "Artist offline successfully.");
1836 }
1837 }
1838
1839 /*Edit User Profile */
1840 function editPersonalInfo()
1841 {
1842 $name = $this->input->post('name', TRUE);
1843 $email_id = $this->input->post('email_id', TRUE);
1844 $user_id = $this->input->post('user_id', TRUE);
1845 $city = $this->input->post('city', TRUE);
1846 $country = $this->input->post('country', TRUE);
1847 $address = $this->input->post('address', TRUE);
1848 $latitude = $this->input->post('latitude', TRUE);
1849 $longitude = $this->input->post('longitude', TRUE);
1850 $gender = $this->input->post('gender', TRUE);
1851 $mobile = $this->input->post('mobile', TRUE);
1852 $office_address = $this->input->post('office_address', TRUE);
1853 $image = $this->input->post('image', TRUE);
1854 $password = $this->input->post('password', TRUE);
1855 $new_password = $this->input->post('new_password', TRUE);
1856
1857 $this->checkUserStatus($user_id);
1858
1859 $checkUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
1860 if($checkUser)
1861 {
1862 if($email_id != $checkUser->email_id)
1863 {
1864 $checkEmail=$this->Api_model->getSingleRow(USR_TBL, array('email_id'=>$email_id));
1865
1866 if($checkEmail)
1867 {
1868 $this->api->api_message(0, "Email id Already Exists.");
1869 exit();
1870 }
1871 }
1872
1873 if($password)
1874 {
1875 $checkPass=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id, 'password'=>$password));
1876
1877 if($checkPass)
1878 {
1879 $where= array('user_id'=>$user_id);
1880 $data['password']= $new_password;
1881 $updateUser =$this->Api_model->updateSingleRow(USR_TBL, $where, $data);
1882
1883 $this->api->api_message(0, EDITSUCCESSFULL);
1884 }
1885 else
1886 {
1887 $this->api->api_message(0, "Old Password does not matched.");
1888 }
1889 exit();
1890 }
1891
1892 $this->load->library('upload');
1893
1894 $config['image_library'] = 'gd2';
1895 $config['upload_path'] = './assets/images/';
1896 $config['allowed_types'] = 'gif|jpg|jpeg|png';
1897 $config['max_size'] = 100000;
1898 $config['file_name'] = time();
1899 $config['create_thumb'] = TRUE;
1900 $config['maintain_ratio'] = TRUE;
1901 $config['width'] = 250;
1902 $config['height'] = 250;
1903 $this->upload->initialize($config);
1904 $ProfileImage="";
1905 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
1906 {
1907 $ProfileImage='assets/images/'.$this->upload->data('file_name');
1908 }
1909 else
1910 {
1911 // echo $this->upload->display_errors();
1912 }
1913
1914 $where= array('user_id'=>$user_id);
1915 $data['name']=isset($name) ? $name: $checkUser->name;
1916 $this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$user_id),$data);
1917
1918 if($ProfileImage)
1919 {
1920 $data['image']=$ProfileImage;
1921 }
1922
1923 $data['latitude']=isset($latitude) ? $latitude: $checkUser->latitude;
1924 $data['longitude']=isset($longitude) ? $longitude: $checkUser->longitude;
1925 $data['gender']=isset($gender) ? $gender: $checkUser->gender;
1926 $data['mobile']=isset($mobile) ? $mobile: $checkUser->mobile;
1927 $data['office_address']=isset($office_address) ? $office_address: $checkUser->office_address;
1928 $data['email_id']=isset($email_id) ? $email_id: $checkUser->email_id;
1929 $data['address']=isset($address) ? $address: $checkUser->address;
1930 $data['city']=isset($city) ? $city: $checkUser->city;
1931 $data['country']=isset($country) ? $country: $checkUser->country;
1932
1933 $updateUser =$this->Api_model->updateSingleRow(USR_TBL, $where, $data);
1934 if($updateUser)
1935 {
1936 $checkUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
1937
1938 $user_id=$checkUser->user_id;
1939 $role=$checkUser->role;
1940 if($role==1)
1941 {
1942 if($checkUser->image)
1943 {
1944 $checkUser->image= base_url().$checkUser->image;
1945 }
1946 else
1947 {
1948 $checkUser->image= base_url()."assets/images/image.png";
1949 }
1950 }
1951 else
1952 {
1953 if($checkUser->image)
1954 {
1955 $checkUser->image= base_url().$checkUser->image;
1956 }
1957 else
1958 {
1959 $checkUser->image= base_url()."assets/images/image.png";
1960 }
1961 }
1962 $this->api->api_message_data(1, EDITSUCCESSFULL, 'data', $checkUser);
1963 }
1964 else
1965 {
1966 $this->api->api_message(0, EDITFAIL);
1967 }
1968 }
1969 else
1970 {
1971 $this->api->api_message(0, NOTAVAILABLE);
1972 }
1973 }
1974
1975 /*Book Appointment*/
1976 public function book_appointment()
1977 {
1978 $data['user_id'] = $this->input->post('user_id', TRUE);
1979 $data['artist_id'] = $this->input->post('artist_id', TRUE);
1980 $data['date_string']= $this->input->post('date_string', TRUE);
1981 $data['timezone']= $this->input->post('timezone', TRUE);
1982 $data['appointment_date'] = date('Y-m-d', strtotime($data['date_string']));
1983 $data['timing'] = date('h:i a', strtotime($data['date_string']));
1984 $data['created_at']=time();
1985 $data['updated_at']=time();
1986 $data['appointment_timestamp']=strtotime($data['date_string']);
1987
1988 $this->checkUserStatus($data['user_id']);
1989 $this->checkUserStatus($data['artist_id']);
1990
1991 $appId = $this->Api_model->insertGetId(APP_TBL, $data);
1992
1993 if($appId)
1994 {
1995 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$data['user_id']));
1996 $msg=$checkUser->name.': booked you on'.$data['timing'];
1997 $this->firebase_notification($data['artist_id'], "Book Appointment" ,$msg);
1998
1999 $this->api->api_message(1, BOOK_APP);
2000 }
2001 else
2002 {
2003 $this->api->api_message(0, TRY_AGAIN);
2004 }
2005 }
2006
2007 /*Edit Appointment*/
2008 public function edit_appointment()
2009 {
2010 $appointment_id= $this->input->post('appointment_id', TRUE);
2011 $data['user_id'] = $this->input->post('user_id', TRUE);
2012 $data['artist_id'] = $this->input->post('artist_id', TRUE);
2013 $data['date_string']= $this->input->post('date_string', TRUE);
2014 $data['timezone']= $this->input->post('timezone', TRUE);
2015 $data['appointment_date'] = date('Y-m-d', strtotime($data['date_string']));
2016 $data['timing'] = date('h:i a', strtotime($data['date_string']));
2017 $data['status']=1;
2018 $data['updated_at']=time();
2019 $data['appointment_timestamp']=strtotime($data['date_string']);
2020
2021 $this->checkUserStatus($data['user_id']);
2022 $this->checkUserStatus($data['artist_id']);
2023
2024 $appId = $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id));
2025
2026 if($appId)
2027 {
2028 $checkUser= $this->Api_model->updateSingleRow(APP_TBL, array('id'=>$appointment_id), $data);
2029
2030 $this->api->api_message(1, BOOK_APP);
2031 }
2032 else
2033 {
2034 $this->api->api_message(0, TRY_AGAIN);
2035 }
2036 }
2037
2038 /*Appointment Delete*/
2039 public function declineAppointment()
2040 {
2041 $appointment_id= $this->input->post('appointment_id', TRUE);
2042 $user_id= $this->input->post('user_id', TRUE);
2043 $this->checkUserStatus($user_id);
2044
2045 $get_appointment = $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id));
2046 if($get_appointment)
2047 {
2048 $this->Api_model->updateSingleRow(APP_TBL, array('id'=>$appointment_id), array('status'=>0));
2049 $this->api->api_message(1, APP_DECLINE);
2050 }
2051 else
2052 {
2053 $this->api->api_message(0, TRY_AGAIN);
2054 }
2055 }
2056
2057 public function getAppointment()
2058 {
2059 $user_id= $this->input->post('user_id', TRUE);
2060 $role = $this->input->post('role', TRUE);
2061
2062 $this->checkUserStatus($user_id);
2063
2064 if($role==1)
2065 {
2066 $where=array('artist_id'=>$user_id);
2067
2068 $get_appointment=$this->Api_model->getAllDataWhere($where,APP_TBL);
2069
2070 if($get_appointment)
2071 {
2072 $get_appointments = array();
2073 foreach ($get_appointment as $get_appointment)
2074 {
2075 $get_user= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_appointment->user_id));
2076
2077 $get_appointment->userName= $get_user->name;
2078 $get_appointment->userEmail= $get_user->email_id;
2079 $get_appointment->userMobile= $get_user->mobile;
2080
2081 if($get_user->image)
2082 {
2083 $get_appointment->userImage= base_url().$get_user->image;
2084 }
2085 else
2086 {
2087 $get_appointment->userImage= base_url()."assets/images/image.png";
2088 }
2089 $get_appointment->userAddress= $get_user->address;
2090
2091 $get_artist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$get_appointment->artist_id));
2092 $get_artistDetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_appointment->artist_id));
2093
2094 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artist->category_id));
2095 $get_appointment->category_name=$get_cat->cat_name;
2096 $get_appointment->category_price=$get_cat->price;
2097
2098 $get_appointment->artistName= $get_artist->name;
2099 $get_appointment->artistMobile= $get_artistDetails->mobile;
2100 $get_appointment->artistEmail= $get_artistDetails->email_id;
2101
2102 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2103 $get_appointment->currency_type=$currency_setting->currency_symbol;
2104
2105 if($get_artistDetails->image)
2106 {
2107 $get_appointment->artistImage= base_url().$get_artistDetails->image;
2108 }
2109 else
2110 {
2111 $get_appointment->artistImage= base_url()."assets/images/image.png";
2112 }
2113 $get_appointment->artistAddress= $get_artist->location;
2114
2115 array_push($get_appointments, $get_appointment);
2116 }
2117
2118 $this->api->api_message_data(1, GET_APP,'data' , $get_appointments);
2119 }
2120 else
2121 {
2122 $this->api->api_message(0, NOTFOUND);
2123 }
2124 }
2125 elseif($role==2)
2126 {
2127 $where=array('user_id'=>$user_id);
2128
2129 $get_appointment=$this->Api_model->getAllDataWhere($where,APP_TBL);
2130
2131 if($get_appointment)
2132 {
2133 $get_appointments = array();
2134 foreach ($get_appointment as $get_appointment)
2135 {
2136 $get_artist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$get_appointment->artist_id));
2137
2138 $get_artistDetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_appointment->artist_id));
2139 $get_appointment->artistMobile= $get_artistDetails->mobile;
2140 $get_appointment->artistEmail= $get_artistDetails->email_id;
2141
2142 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artist->category_id));
2143 $get_appointment->category_name=$get_cat->cat_name;
2144 $get_appointment->category_price=$get_cat->price;
2145
2146 if($get_artistDetails->image)
2147 {
2148 $get_appointment->artistImage= base_url().$get_artistDetails->image;
2149 }
2150 else
2151 {
2152 $get_appointment->artistImage= base_url()."assets/images/image.png";
2153 }
2154
2155 $get_appointment->artistName= $get_artist->name;
2156 $get_appointment->artistAddress= $get_artist->location;
2157 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2158 $get_appointment->currency_type=$currency_setting->currency_symbol;
2159
2160 $get_user= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_appointment->user_id));
2161 if($get_user->image)
2162 {
2163 $get_appointment->userImage= base_url().$get_user->image;
2164 }
2165 else
2166 {
2167 $get_appointment->userImage= base_url()."assets/images/image.png";
2168 }
2169
2170 $get_appointment->userName= $get_user->name;
2171 $get_appointment->userAddress= $get_user->address;
2172 $get_appointment->userEmail= $get_user->email_id;
2173 $get_appointment->userMobile= $get_user->mobile;
2174
2175 array_push($get_appointments, $get_appointment);
2176 }
2177 $this->api->api_message_data(1, GET_APP,'data' , $get_appointments);
2178 }
2179 else
2180 {
2181 $this->api->api_message(0, NOTFOUND);
2182 }
2183 }
2184 else
2185 {
2186 $this->api->api_message(0, "Invalid Request");
2187 }
2188 }
2189 /*Update or Create artist*/
2190 public function artistProfile()
2191 {
2192 $user_id = $this->input->post('user_id', TRUE);
2193 $name = $this->input->post('name', TRUE);
2194 $category_id = $this->input->post('category_id', TRUE);
2195 $description = $this->input->post('description', TRUE);
2196 $about_us = $this->input->post('about_us', TRUE);
2197 $qualification = $this->input->post('qualification', TRUE);
2198 $skills = $this->input->post('skills', TRUE);
2199 $job_done = $this->input->post('job_done', TRUE);
2200 $hire_rate = $this->input->post('hire_rate', TRUE);
2201 $bio = $this->input->post('bio', TRUE);
2202 $longitude = $this->input->post('longitude', TRUE);
2203 $latitude = $this->input->post('latitude', TRUE);
2204 $created_at = time();
2205 $updated_at = time();
2206 $address = $this->input->post('address', TRUE);
2207
2208 $this->checkUserStatus($user_id);
2209
2210 $data = array(
2211 'user_id' =>$user_id,
2212 'name' => $name,
2213 'category_id' =>$category_id,
2214 'description' =>$description,
2215 'about_us' =>$about_us,
2216 'qualification' =>$qualification,
2217 'skills' =>$skills,
2218 'job_done' =>$job_done,
2219 'hire_rate' =>$hire_rate,
2220 'bio' =>$bio,
2221 'longitude' =>$longitude,
2222 'latitude' =>$latitude,
2223 'created_at' => $created_at,
2224 'updated_at'=> $updated_at,
2225 'address' => $address
2226 );
2227 $table= ART_TBL;
2228 $columnName = 'user_id';
2229 $condition = array('user_id'=>$user_id);
2230 $checkArtist = $this->Api_model->checkData($table, $condition,$columnName);
2231 if($checkArtist == 1)
2232 {
2233 $this->api->api_message(0, FOUND);
2234 $addArtist = $this->Api_model->insert($table, $data);
2235 }
2236 else{
2237 $this->api->api_message(0, USERNOTFOND);
2238 }
2239 }
2240
2241 /*Book artist*/
2242 public function book_artist()
2243 {
2244 $data['user_id'] = $this->input->post('user_id', TRUE);
2245 $data['artist_id'] = $this->input->post('artist_id', TRUE);
2246 $data['price'] = $this->input->post('price', TRUE);
2247 $date_string= $this->input->post('date_string', TRUE);
2248 $data['time_zone']= $this->input->post('timezone', TRUE);
2249 $data['booking_date'] = date('Y-m-d', strtotime($date_string));
2250 $data['booking_time'] = date('h:i a', strtotime($date_string));
2251 $data['created_at']=time();
2252 $data['updated_at']=time();
2253 $data['booking_timestamp']=strtotime($date_string);
2254
2255 $this->checkUserStatus($data['user_id']);
2256 $this->checkUserStatus($data['artist_id']);
2257
2258 $checkArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id'],'booking_flag'=>1));
2259 if($checkArtist)
2260 {
2261 $this->api->api_message(0, "Artist Busy with another client. Please try after sometime.");
2262 exit();
2263 }
2264
2265 $getArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id']));
2266
2267 $category_id= $getArtist->category_id;
2268 $category= $this->Api_model->getSingleRow(CAT_TBL, array('id'=>$category_id));
2269
2270 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
2271
2272 $data['commission_type']=$commission_setting->commission_type;
2273 $data['flat_type']=$commission_setting->flat_type;
2274 if($commission_setting->commission_type==0)
2275 {
2276 $data['category_price']= $category->price;
2277 }
2278 elseif($commission_setting->commission_type==1)
2279 {
2280 if($commission_setting->flat_type==2)
2281 {
2282 $data['category_price']= $commission_setting->flat_amount;
2283 }
2284 elseif ($commission_setting->flat_type==1)
2285 {
2286 $data['category_price']= $commission_setting->flat_amount;
2287 }
2288 }
2289
2290 $appId = $this->Api_model->insertGetId(ABK_TBL, $data);
2291 if($appId)
2292 {
2293 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$data['user_id']));
2294 $msg=$checkUser->name.': booked you on'.$date_string;
2295 $this->firebase_notification($data['artist_id'], "Book Appointment" ,$msg);
2296
2297 $dataNotification['user_id']= $data['artist_id'];
2298 $dataNotification['title']= "Book Appointment";
2299 $dataNotification['msg']= $msg;
2300 $dataNotification['type']= "Individual";
2301 $dataNotification['created_at']=time();
2302 $this->Api_model->insertGetId(NTS_TBL,$dataNotification);
2303
2304 $updateUser=$this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$data['artist_id']),array('booking_flag'=>1));
2305 $this->api->api_message(1, BOOK_APP);
2306 }
2307 else
2308 {
2309 $this->api->api_message(0, TRY_AGAIN);
2310 }
2311 }
2312
2313 /*Decline Booking*/
2314 public function decline_booking()
2315 {
2316 $booking_id =$this->input->post('booking_id', TRUE);
2317 $user_id =$this->input->post('user_id', TRUE);
2318 $data['decline_by'] =$this->input->post('decline_by', TRUE);
2319 $data['decline_reason'] =$this->input->post('decline_reason', TRUE);
2320 $data['booking_flag'] =2;
2321
2322 $this->checkUserStatus($user_id);
2323
2324 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$booking_id));
2325 if($getBooking)
2326 {
2327 $updateBooking=$this->Api_model->updateSingleRow(ABK_TBL,array('id'=>$booking_id),$data);
2328
2329 if($updateBooking)
2330 {
2331 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
2332 $msg=$checkUser->name.': is decline your appointment.';
2333 $this->firebase_notification($getBooking->user_id, "Decline Appointment" ,$msg);
2334
2335 $updateUser=$this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$getBooking->artist_id),array('booking_flag'=>0));
2336 $this->api->api_message(1, "Booking Decline successfully.");
2337 }
2338 else
2339 {
2340 $this->api->api_message(0, TRY_AGAIN);
2341 }
2342 }
2343 else
2344 {
2345 $this->api->api_message(0, TRY_AGAIN);
2346 }
2347 }
2348
2349
2350 /*Case 1 accept booking 2 start booking 3 end booking*/
2351 public function booking_operation()
2352 {
2353 $request =$this->input->post('request', TRUE);
2354 $booking_id =$this->input->post('booking_id', TRUE);
2355 $user_id =$this->input->post('user_id', TRUE);
2356
2357 $this->checkUserStatus($user_id);
2358
2359 switch ($request)
2360 {
2361 case 1:
2362 $this->accept_booking($booking_id);
2363 break;
2364
2365 case 2:
2366 $this->start_booking($booking_id);
2367 break;
2368
2369 case 3:
2370 $this->end_booking($booking_id);
2371 break;
2372 default:
2373 $this->api->api_message(0, TRY_AGAIN);
2374 }
2375 }
2376
2377 /*Accept Booking*/
2378 public function accept_booking($booking_id)
2379 {
2380 $data['booking_flag'] =1;
2381
2382 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$booking_id));
2383 if($getBooking)
2384 {
2385 $updateBooking=$this->Api_model->updateSingleRow(ABK_TBL,array('id'=>$booking_id),$data);
2386
2387 if($updateBooking)
2388 {
2389 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
2390 $msg=$checkUser->name.': has accepted your appointment.';
2391 $this->firebase_notification($getBooking->user_id, "Booking" ,$msg);
2392
2393 $this->api->api_message(1, "Booking accepted successfully.");
2394 }
2395 else
2396 {
2397 $this->api->api_message(0, TRY_AGAIN);
2398 }
2399 }
2400 else
2401 {
2402 $this->api->api_message(0, TRY_AGAIN);
2403 }
2404 }
2405
2406 /*Start Booking*/
2407 public function start_booking($booking_id)
2408 {
2409 $data['booking_flag'] =3;
2410 $data['start_time'] =time();
2411
2412 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$booking_id));
2413 if($getBooking)
2414 {
2415 $checkArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$getBooking->artist_id,'booking_flag'=>1));
2416 if($getBooking->booking_type !=0)
2417 {
2418 if($checkArtist)
2419 {
2420 $this->api->api_message(0, "Artist Busy with another client. Please try after sometime.");
2421 exit();
2422 }
2423 }
2424
2425 $updateBooking=$this->Api_model->updateSingleRow(ABK_TBL,array('id'=>$booking_id),$data);
2426
2427 if($updateBooking)
2428 {
2429 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
2430 $msg='Your booking started successfully.';
2431 $this->firebase_notification($getBooking->user_id, "Start Booking" ,$msg);
2432
2433 $this->api->api_message(1, "Booking Started successfully.");
2434 }
2435 else
2436 {
2437 $this->api->api_message(0, TRY_AGAIN);
2438 }
2439 }
2440 else
2441 {
2442 $this->api->api_message(0, TRY_AGAIN);
2443 }
2444 }
2445
2446 /*Complete Booking (End)*/
2447 public function end_booking($booking_id)
2448 {
2449 $data['booking_flag'] = 4;
2450 $data['end_time'] =time();
2451
2452 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$booking_id));
2453 if($getBooking)
2454 {
2455 if($getBooking->booking_type==2)
2456 {
2457 $this->Api_model->updateSingleRow(AJB_TBL,array('job_id'=>$getBooking->job_id),array('status'=>2));
2458 }
2459 if($getBooking->booking_type==1)
2460 {
2461 $this->Api_model->updateSingleRow(APP_TBL,array('id'=>$getBooking->job_id),array('status'=>3));
2462 }
2463
2464 $updateBooking=$this->Api_model->updateSingleRow(ABK_TBL,array('id'=>$booking_id),$data);
2465
2466 $artist_id=$getBooking->artist_id;
2467 $user_id=$getBooking->user_id;
2468 $updateUser=$this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$artist_id),array('booking_flag'=>0));
2469
2470 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$booking_id));
2471 $working_min= (float)round(abs($getBooking->start_time - $getBooking->end_time) / 60,2);
2472 $min_price = ($getBooking->price)/60;
2473 $getArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$artist_id));
2474
2475 if($getArtist->artist_commission_type==2 || $getBooking->booking_type==2)
2476 {
2477 $f_amount =$getBooking->price;
2478 }
2479 else
2480 {
2481 $f_amount =$working_min*$min_price;
2482 }
2483
2484 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
2485
2486 $datainvoice['commission_type']=$commission_setting->commission_type;
2487 $datainvoice['flat_type']=$commission_setting->flat_type;
2488 if($commission_setting->commission_type==0)
2489 {
2490 $total_amount= $f_amount + $getBooking->category_price;
2491 $datainvoice['category_amount']= $getBooking->category_price;
2492 }
2493 elseif($commission_setting->commission_type==1)
2494 {
2495 if($commission_setting->flat_type==2)
2496 {
2497 $total_amount= $f_amount + $commission_setting->flat_amount;
2498 $datainvoice['category_amount']= $commission_setting->flat_amount;
2499 }
2500 elseif ($commission_setting->flat_type==1)
2501 {
2502 $total_amount= $f_amount + ($f_amount*$commission_setting->flat_amount)/100;
2503 $datainvoice['category_amount']= ($f_amount*$commission_setting->flat_amount)/100;
2504 }
2505 }
2506
2507 $datainvoice['artist_id']= $artist_id;
2508 $datainvoice['artist_amount']= round($f_amount, 2);
2509
2510 $getCommission= $this->Api_model->getSingleRow('artist_wallet',array('artist_id'=>$artist_id));
2511
2512 if($getCommission)
2513 {
2514 $amount = $getCommission->amount + $datainvoice['artist_amount'];
2515 $updateUser=$this->Api_model->updateSingleRow("artist_wallet",array('artist_id'=>$artist_id),array('amount'=>$amount));
2516 }
2517 else
2518 {
2519 $this->Api_model->insertGetId('artist_wallet',array('artist_id'=> $artist_id, 'amount'=>$datainvoice['artist_amount']));
2520 }
2521
2522 $datainvoice['total_amount']= round($total_amount,2);
2523 $datainvoice['final_amount']= round($total_amount,2);
2524 $datainvoice['user_id']= $user_id;
2525 $datainvoice['invoice_id']= strtoupper($this->api->strongToken());
2526 $datainvoice['booking_id']= $booking_id;
2527 $datainvoice['working_min']= (float)round($working_min,2);
2528 $datainvoice['tax']= 0;
2529 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2530
2531 $datainvoice['currency_type']= $currency_setting->currency_symbol;
2532 $date= date('Y-m-d');
2533 $datainvoice['created_at']=time();
2534 $datainvoice['updated_at']=time();
2535
2536 $invoiceId= $this->Api_model->insertGetId(IVC_TBL, $datainvoice);
2537
2538 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->user_id));
2539 $getBooking->userName= $getUser->name;
2540 $getBooking->address= $getUser->address;
2541 $getBooking->total_amount= $total_amount;
2542 $getBooking->working_min= (float)$working_min;
2543
2544 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2545 $getBooking->currency_type=$currency_setting->currency_symbol;
2546
2547 if($getUser->image)
2548 {
2549 $getBooking->userImage= base_url().$getUser->image;
2550 }
2551 else
2552 {
2553 $getBooking->userImage= base_url().'assets/images/image.png';
2554 }
2555
2556 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
2557 $msg='Your booking end successfully.';
2558 // $this->firebase_notification($getBooking->user_id, "End Booking" ,$msg);
2559 $dataNotification['user_id']= $getBooking->user_id;
2560 $dataNotification['title']= "End Appointment";
2561 $dataNotification['msg']= $msg;
2562 $dataNotification['type']= "Individual";
2563 $dataNotification['created_at']=time();
2564 $this->Api_model->insertGetId(NTS_TBL,$dataNotification);
2565
2566 $this->api->api_message_data(1, BOOKING_END, 'data', $getBooking);
2567 }
2568 else
2569 {
2570 $this->api->api_message(0, TRY_AGAIN);
2571 }
2572 }
2573
2574 /*Check coupon code*/
2575 public function checkCoupon()
2576 {
2577 $coupon_code= $this->input->post('coupon_code', TRUE);
2578 $user_id= $this->input->post('user_id', TRUE);
2579 $invoice_id= $this->input->post('invoice_id', TRUE);
2580
2581 $this->checkUserStatus($user_id);
2582
2583 $getCoupon= $this->Api_model->getSingleRow(DCP_TBL, array('coupon_code'=>$coupon_code,'status'=>1));
2584 if($getCoupon)
2585 {
2586 $getInvoice= $this->Api_model->getSingleRow(IVC_TBL, array('invoice_id'=>$invoice_id));
2587
2588 $total_amount= $getInvoice->total_amount;
2589 $discount=$getCoupon->discount;
2590
2591 $discount_type= $getCoupon->discount_type;
2592 if($discount_type==1)
2593 {
2594 $precentage= ($total_amount*$discount)/100;
2595 $final_amount= $total_amount- round($precentage, 2);
2596 }
2597 else
2598 {
2599 $final_amount= $total_amount- $discount;
2600 }
2601 if($final_amount < 0)
2602 {
2603 $final_amount= $total_amount;
2604 }
2605 $this->api->api_message_data(1, "Applied successfully.", 'final_amount',$final_amount);
2606 }
2607 else
2608 {
2609 $this->api->api_message(0, "Coupon code not valid.");
2610 }
2611 }
2612
2613 /*make payment*/
2614 public function makePayment()
2615 {
2616 $user_id= $this->input->post('user_id', TRUE);
2617 $payment_type= $this->input->post('payment_type', TRUE);
2618 $coupon_code= $this->input->post('coupon_code', TRUE);
2619 $invoice_id= $this->input->post('invoice_id', TRUE);
2620 $final_amount= $this->input->post('final_amount', TRUE);
2621 $payment_status= $this->input->post('payment_status', TRUE);
2622 $payment_type= $this->input->post('payment_type', TRUE);
2623
2624 $this->checkUserStatus($user_id);
2625
2626 $getCoupon= $this->Api_model->getSingleRow(DCP_TBL, array('coupon_code'=>$coupon_code));
2627 if($getCoupon)
2628 {
2629 if($getCoupon)
2630 {
2631 if($payment_status==1)
2632 {
2633 if(isset($payment_type))
2634 {
2635 $this->Api_model->updateSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id),array('final_amount'=>$final_amount,'coupon_code'=>$coupon_code,'flag'=>1,'payment_status'=>$payment_status,"payment_type"=>$payment_type));
2636 }
2637 else
2638 {
2639 $this->Api_model->updateSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id),array('final_amount'=>$final_amount,'coupon_code'=>$coupon_code,'flag'=>1,'payment_status'=>$payment_status));
2640 }
2641
2642
2643 $getInvoice=$this->Api_model->getSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id));
2644 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$getInvoice->booking_id));
2645
2646 $getInvoice->booking_time= $getBooking->booking_time;
2647 $getInvoice->booking_date= $getBooking->booking_date;
2648
2649 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->user_id));
2650
2651 $getInvoice->userName= $getUser->name;
2652 $getInvoice->userEmail= $getUser->email_id;
2653 $getInvoice->address= $getUser->address;
2654
2655 $get_artists= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$getInvoice->artist_id));
2656 $getArt= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->artist_id));
2657
2658 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
2659
2660 $getInvoice->ArtistName=$get_artists->name;
2661 $getInvoice->ArtistEmail=$getArt->email_id;
2662 $getInvoice->ArtistLocation=$get_artists->location;
2663 $getInvoice->categoryName=$get_cat->cat_name;
2664
2665 $subject=IVE_SUB;
2666 $this->send_invoice($getInvoice->userEmail, $subject, $getInvoice);
2667 $this->send_invoice($getInvoice->ArtistEmail, $subject, $getInvoice);
2668
2669 $this->api->api_message(1, PAYMENT_CONFIRM);
2670 }
2671 else
2672 {
2673 $this->Api_model->updateSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id),array('final_amount'=>$final_amount,'coupon_code'=>$coupon_code,'payment_status'=>$payment_status));
2674 if($payment_status==3)
2675 {
2676 $this->api->api_message(1, "Initiate payment.");
2677 }
2678 else
2679 {
2680 $this->api->api_message(0, "Please try again later.");
2681 }
2682 }
2683 }
2684 else
2685 {
2686 $this->api->api_message(0, "Coupon code not valid.");
2687 }
2688 }
2689 else
2690 {
2691 if($payment_status==1)
2692 {
2693 $this->Api_model->updateSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id),array('final_amount'=>$final_amount,'coupon_code'=>$coupon_code,'flag'=>1,'payment_status'=>$payment_status, 'payment_type'=>$payment_type));
2694
2695 $getInvoice=$this->Api_model->getSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id));
2696 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$getInvoice->booking_id));
2697
2698 $getInvoice->booking_time= $getBooking->booking_time;
2699 $getInvoice->booking_date= $getBooking->booking_date;
2700
2701 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->user_id));
2702
2703 $getInvoice->userName= $getUser->name;
2704 $getInvoice->userEmail= $getUser->email_id;
2705 $getInvoice->address= $getUser->address;
2706
2707 $get_artists= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$getInvoice->artist_id));
2708 $getArt= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->artist_id));
2709
2710 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
2711
2712 $getInvoice->ArtistName=$get_artists->name;
2713 $getInvoice->ArtistEmail=$getArt->email_id;
2714 $getInvoice->ArtistLocation=$get_artists->location;
2715 $getInvoice->categoryName=$get_cat->cat_name;
2716
2717 $subject=IVE_SUB;
2718 $this->send_invoice($getInvoice->userEmail, $subject, $getInvoice);
2719 $this->send_invoice($getInvoice->ArtistEmail, $subject, $getInvoice);
2720
2721 $this->api->api_message(1, PAYMENT_CONFIRM);
2722 }
2723 else
2724 {
2725 $this->Api_model->updateSingleRow(IVC_TBL,array('invoice_id'=>$invoice_id),array('final_amount'=>$final_amount,'coupon_code'=>$coupon_code,'payment_status'=>$payment_status));
2726 if($payment_status==3)
2727 {
2728 $this->api->api_message(1, "Initiate payment.");
2729 }
2730 else
2731 {
2732 $this->api->api_message(0, "Please try again later.");
2733 }
2734 }
2735 }
2736 }
2737
2738 /*Send Email Invoice*/
2739 public function send_invoice($email_id, $subject, $data)
2740 {
2741 $this->load->library('email');
2742 $this->email->set_mailtype("html");
2743 $this->email->set_newline("\r\n");
2744
2745 $from_email = SENDER_EMAIL;
2746 $this->email->from($from_email, "Ache na Gringa");
2747 $this->email->to($email_id);
2748 $this->email->subject($subject);
2749
2750 $body = $this->load->view('invoice_tmp.php',$data,TRUE);
2751 $this->email->message($body);
2752 $this->email->send();
2753 }
2754
2755 /*Get My last Booking*/
2756 public function getMyCurrentBooking()
2757 {
2758 $artist_id = $this->input->post('artist_id', TRUE);
2759
2760 $this->checkUserStatus($artist_id);
2761 $getBooking= $this->Api_model->getWhereInStatus(ABK_TBL, array('artist_id'=>$artist_id),'booking_flag',array(0,1,3));
2762 if($getBooking)
2763 {
2764 $get_reviews= $this->Api_model->getAllDataWhere(array('artist_id'=>$getBooking->artist_id,'status'=>1), 'rating');
2765 $review = array();
2766 foreach ($get_reviews as $get_reviews) {
2767 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_reviews->user_id));
2768 $get_reviews->name= $get_user->name;
2769 if($get_user->image)
2770 {
2771 $get_reviews->image= base_url().$get_user->image;
2772 }
2773 else
2774 {
2775 $get_reviews->image= base_url()."assets/images/image.png";
2776 }
2777
2778 array_push($review, $get_reviews);
2779 }
2780 $getBooking->reviews=$review;
2781
2782 $where=array('user_id'=>$getBooking->artist_id);
2783 $get_artists=$this->Api_model->getSingleRow(ART_TBL,$where);
2784 $getAdetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
2785 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
2786 if($getAdetails->image)
2787 {
2788 $getBooking->artistImage=base_url().$getAdetails->image;
2789 }
2790 else
2791 {
2792 $getBooking->artistImage=base_url()."assets/images/image.png";
2793 }
2794 $getBooking->category_name=$get_cat->cat_name;
2795 $getBooking->artistName=$get_artists->name;
2796 $getBooking->artistLocation=$get_artists->location;
2797
2798 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->user_id));
2799 $getBooking->userName= $getUser->name;
2800 $getBooking->address= $getUser->address;
2801 $getBooking->c_latitude= $getUser->latitude;
2802 $getBooking->c_longitude= $getUser->longitude;
2803 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2804 $getBooking->currency_type=$currency_setting->currency_symbol;
2805
2806 $where= array('artist_id'=>$artist_id, 'status'=>1);
2807 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
2808 if($ava_rating[0]->rating==null)
2809 {
2810 $ava_rating[0]->rating="0";
2811 }
2812 $getBooking->ava_rating=$ava_rating[0]->rating;
2813
2814 if($getBooking->start_time)
2815 {
2816 $getBooking->working_min= (float)round(abs($getBooking->start_time - time()) / 60,2);
2817 }
2818 else
2819 {
2820 $getBooking->working_min=0;
2821 }
2822
2823 if($getUser->image)
2824 {
2825 $getBooking->userImage= base_url().$getUser->image;
2826 }
2827 else
2828 {
2829 $getBooking->userImage= base_url().'assets/images/image.png';
2830 }
2831
2832 $this->api->api_message_data(1, CURRENT_BOOKING,'data' , $getBooking);
2833 }
2834 else
2835 {
2836 $this->api->api_message(0, NO_DATA);
2837 }
2838 }
2839
2840 /*Get My last Booking*/
2841 public function getMyCurrentBookingUser()
2842 {
2843 $user_id = $this->input->post('user_id', TRUE);
2844 $this->checkUserStatus($user_id);
2845
2846 $getBooking= $this->Api_model->getWhereInStatusResult(ABK_TBL, array('user_id'=>$user_id),'booking_flag',array(0,1,3));
2847
2848 if($getBooking)
2849 {
2850 $getBookings= array();
2851 foreach ($getBooking as $getBooking)
2852 {
2853
2854 $get_reviews= $this->Api_model->getAllDataWhere(array('artist_id'=>$getBooking->artist_id,'status'=>1), 'rating');
2855 $review = array();
2856 foreach ($get_reviews as $get_reviews)
2857 {
2858 $get_user = $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_reviews->user_id));
2859 $get_reviews->name= $get_user->name;
2860 if($get_user->image)
2861 {
2862 $get_reviews->image= base_url().$get_user->image;
2863 }
2864 else
2865 {
2866 $get_reviews->image= base_url()."assets/images/image.png";
2867 }
2868 array_push($review, $get_reviews);
2869 }
2870 $getBooking->reviews=$review;
2871
2872 $where=array('user_id'=>$getBooking->artist_id);
2873 $get_artists=$this->Api_model->getSingleRow(ART_TBL,$where);
2874 $getAdetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
2875 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
2876 if($getAdetails->image)
2877 {
2878 $getBooking->artistImage=base_url().$getAdetails->image;
2879 }
2880 else
2881 {
2882 $getBooking->artistImage=base_url()."assets/images/image.png";
2883 }
2884
2885 $getBooking->category_name=$get_cat->cat_name;
2886 $getBooking->artistName=$get_artists->name;
2887 $getBooking->artistLocation=$get_artists->location;
2888
2889 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->user_id));
2890 $getBooking->userName= $getUser->name;
2891 $getBooking->address= $getUser->address;
2892
2893 $getBooking->jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$getBooking->artist_id,'booking_flag'=>4));
2894 $get_artists->totalJob=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$getBooking->artist_id));
2895
2896 if($get_artists->totalJob==0)
2897 {
2898 $getBooking->completePercentages=0;
2899 }
2900 else
2901 {
2902 $getBooking->completePercentages=round(($getBooking->jobDone*100) / $get_artists->totalJob);
2903 }
2904
2905 $where= array('artist_id'=>$getBooking->user_id, 'status'=>1);
2906 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
2907 if($ava_rating[0]->rating==null)
2908 {
2909 $ava_rating[0]->rating="0";
2910 }
2911 $getBooking->ava_rating=$ava_rating[0]->rating;
2912
2913 if($getBooking->start_time)
2914 {
2915 if($getBooking->end_time)
2916 {
2917 $getBooking->working_min= (int)round(abs($getBooking->start_time - $getBooking->end_time) / 60,2);
2918 }
2919 else
2920 {
2921 $getBooking->working_min= (float)round(abs($getBooking->start_time - time()) / 60,2);
2922 }
2923 }
2924 else
2925 {
2926 $getBooking->working_min=0;
2927 }
2928 if($getUser->image)
2929 {
2930 $getBooking->userImage= base_url().$getUser->image;
2931 }
2932 else
2933 {
2934 $getBooking->userImage= base_url().'assets/images/image.png';
2935 }
2936
2937 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2938 $getBooking->currency_type=$currency_setting->currency_symbol;
2939
2940 $booking_id=$getBooking->id;
2941
2942 $getPrice= $this->Api_model->getSingleRow(IVC_TBL, array('booking_id'=>$booking_id,'flag'=>0));
2943 if($getPrice)
2944 {
2945 $getBooking->total_amount=$getPrice->total_amount;
2946 $getBooking->invoice_id=$getPrice->invoice_id;
2947 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2948 $getBooking->currency_type=$currency_setting->currency_symbol;
2949 }
2950 else
2951 {
2952 $getBooking->total_amount=0;
2953 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
2954 $getBooking->currency_type=$currency_setting->currency_symbol;
2955 $getBooking->invoice_id="";
2956 }
2957
2958 /*$getInvoice= $this->Api_model->getSingleRow('booking_invoice', array('booking_id'=>$booking_id,'flag'=>1));
2959 if($getInvoice)
2960 {
2961 $this->api->api_message(0, NO_DATA);
2962 }
2963 else
2964 {*/
2965 array_push($getBookings, $getBooking);
2966 }
2967 $this->api->api_message_data(1, CURRENT_BOOKING,'data' , $getBookings);
2968 /*}*/
2969 }
2970 else
2971 {
2972 $this->api->api_message(0, NO_DATA);
2973 }
2974 }
2975
2976 /*get my earning*/
2977 public function myEarning()
2978 {
2979 $artist_id= $this->input->post('artist_id');
2980 $date= date('Y-m-d');
2981 $today=strtotime($date);
2982
2983 $this->checkUserStatus($artist_id);
2984
2985 $data= array();
2986 $todatDay = date('D', $today);
2987
2988 $todayDay=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$today));
2989 if($todayDay->total_amount==null)
2990 {
2991 $todayDay->total_amount="0";
2992 }
2993 $todayDay->day=$todatDay;
2994 $data[]= $todayDay;
2995
2996 $secondDay=date('Y-m-d',(strtotime ( '-1 day' , strtotime ( $date) ) ));
2997 $secondDayTime=strtotime($secondDay);
2998 $secondDayName = date('D', $secondDayTime);
2999
3000 $second=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$secondDayTime));
3001 if($second->total_amount==null)
3002 {
3003 $second->total_amount="0";
3004 }
3005 $second->day=$secondDayName;
3006 $data[]= $second;
3007
3008 $thirdDay=date('Y-m-d',(strtotime ( '-2 day' , strtotime ( $date) ) ));
3009 $thirdDayTime=strtotime($thirdDay);
3010 $thirdDayName = date('D', $thirdDayTime);
3011
3012 $third=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$thirdDayTime));
3013 $third->day=$thirdDayName;
3014 if($third->total_amount==null)
3015 {
3016 $third->total_amount="0";
3017 }
3018 $data[]= $third;
3019
3020 $fourDay=date('Y-m-d',(strtotime ( '-3 day' , strtotime ( $date) ) ));
3021 $fourDayTime=strtotime($fourDay);
3022 $fourDayName = date('D', $fourDayTime);
3023
3024 $four=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$fourDayTime));
3025 if($four->total_amount==null)
3026 {
3027 $four->total_amount="0";
3028 }
3029 $four->day=$fourDayName;
3030 $data[]= $four;
3031
3032 $fiveDay=date('Y-m-d',(strtotime ( '-4 day' , strtotime ( $date) ) ));
3033 $fiveDayTime=strtotime($fiveDay);
3034 $fiveDayName = date('D', $fiveDayTime);
3035
3036 $five=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$fiveDayTime));
3037 if($five->total_amount==null)
3038 {
3039 $five->total_amount="0";
3040 }
3041 $five->day=$fiveDayName;
3042 $data[]= $five;
3043
3044 $sixDay=date('Y-m-d',(strtotime ( '-5 day' , strtotime ( $date) ) ));
3045 $sixDayTime=strtotime($sixDay);
3046 $sixDayName = date('D', $sixDayTime);
3047
3048 $six=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$sixDayTime));
3049 if($six->total_amount==null)
3050 {
3051 $six->total_amount="0";
3052 }
3053 $six->day=$sixDayName;
3054 $data[]= $six;
3055
3056 $sevenDay=date('Y-m-d',(strtotime ( '-6 day' , strtotime ( $date) ) ));
3057 $sevenDayTime=strtotime($sevenDay);
3058 $sevenDayName = date('D', $sevenDayTime);
3059
3060 $seven=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id,'created_at'=>$sevenDayTime));
3061 if($seven->total_amount==null)
3062 {
3063 $seven->total_amount="0";
3064 }
3065 $seven->day=$sevenDayName;
3066 $data[]= $seven;
3067
3068 $onlineEarning=$this->Api_model->getSumWhere('artist_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>0));
3069
3070 $onlineCommission=$this->Api_model->getSumWhere('category_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>0));
3071
3072 $offlineEarning=$this->Api_model->getSumWhere('artist_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>1));
3073
3074 $offlineCommission=$this->Api_model->getSumWhere('category_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>1));
3075
3076 $earning=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id));
3077
3078 $data['onlineEarning']=round($onlineEarning->artist_amount, 2);
3079 $data['offlineEarning']=round($offlineEarning->artist_amount, 2);
3080
3081 $getCommission= $this->Api_model->getSingleRow('artist_wallet',array('artist_id'=>$artist_id));
3082
3083 if($getCommission)
3084 {
3085 $data['walletAmount']= $getCommission->amount;
3086 }
3087 else
3088 {
3089 $data['walletAmount']= $data['onlineEarning'] - $data['offlineEarning'];
3090 }
3091
3092 $data['earning']= round($earning->total_amount, 2);
3093
3094 $data['jobDone']=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id,'booking_flag'=>4));
3095
3096 $data['totalJob']=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id));
3097
3098 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3099 $data['currency_symbol']= $currency_setting->currency_symbol;
3100
3101 if($data['totalJob']==0)
3102 {
3103 $data['completePercentages']=0;
3104 }
3105 else
3106 {
3107 $data['completePercentages']=round(($data['jobDone']*100) / $data['totalJob'], 2);
3108 }
3109
3110 $this->api->api_message_data(1, "Get my earning",'data' , $data);
3111 }
3112
3113
3114 public function myEarning1()
3115 {
3116 $artist_id= $this->input->post('artist_id');
3117 $date= date('Y-m-d');
3118 $today=strtotime($date);
3119
3120 $this->checkUserStatus($artist_id);
3121
3122 $data= array();
3123 $todatDay = date('D', $today);
3124
3125 $earningData=$this->Api_model->getMontlyRevenue1($artist_id);
3126
3127 $data['chartData']=$earningData;
3128
3129 $onlineEarning=$this->Api_model->getSumWhere('artist_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>0));
3130
3131 $onlineCommission=$this->Api_model->getSumWhere('category_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>0));
3132
3133 $offlineEarning=$this->Api_model->getSumWhere('artist_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>1));
3134
3135 $offlineCommission=$this->Api_model->getSumWhere('category_amount', IVC_TBL,array('artist_id'=>$artist_id,'payment_type'=>1));
3136
3137 $earning=$this->Api_model->getSumWhere('total_amount', IVC_TBL,array('artist_id'=>$artist_id));
3138
3139 $data['onlineEarning']=round($onlineEarning->artist_amount, 2);
3140 $data['cashEarning']=round($offlineEarning->artist_amount, 2);
3141
3142 $getCommission= $this->Api_model->getSingleRow('artist_wallet',array('artist_id'=>$artist_id));
3143
3144 if($getCommission)
3145 {
3146 $data['walletAmount']= $getCommission->amount;
3147 }
3148 else
3149 {
3150 $data['walletAmount']= $data['onlineEarning'] - $data['offlineEarning'];
3151 }
3152
3153 $data['totalEarning']= round($earning->total_amount, 2);
3154
3155 $data['jobDone']=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id,'booking_flag'=>4));
3156
3157 $data['totalJob']=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist_id));
3158
3159 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3160 $data['currency_symbol']= $currency_setting->currency_symbol;
3161
3162 if($data['totalJob']==0)
3163 {
3164 $data['completePercentages']=0;
3165 }
3166 else
3167 {
3168 $data['completePercentages']=round(($data['jobDone']*100) / $data['totalJob'], 2);
3169 }
3170
3171 $this->api->api_message_data(1, "Get my earning",'data' , $data);
3172 }
3173
3174 /*Get My Invoice*/
3175 public function getMyInvoice()
3176 {
3177 $user_id= $this->input->post('user_id', TRUE);
3178 $role= $this->input->post('role', TRUE);
3179
3180 $this->checkUserStatus($user_id);
3181
3182 if($role==1)
3183 {
3184 $where =array('artist_id'=> $user_id);
3185 }
3186 elseif($role==2)
3187 {
3188 $where =array('user_id'=> $user_id);
3189 }
3190
3191 $getInvoice= $this->Api_model->getAllDataWhereOrderTwo($where,IVC_TBL);
3192 if($getInvoice)
3193 {
3194 $getInvoices = array();
3195 foreach ($getInvoice as $getInvoice)
3196 {
3197 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$getInvoice->booking_id));
3198
3199 $getInvoice->booking_date= $getBooking->booking_date;
3200 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->user_id));
3201
3202 $getInvoice->userName= $getUser->name;
3203 $getInvoice->address= $getUser->address;
3204
3205 if($getUser->image)
3206 {
3207 $getInvoice->userImage= base_url().$getUser->image;
3208 }
3209 else
3210 {
3211 $getInvoice->userImage= base_url().'assets/images/image.png';
3212 }
3213
3214 $get_artists= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$getInvoice->artist_id));
3215 $getAdetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->artist_id));
3216 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
3217 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3218 $getInvoice->currency_type=$currency_setting->currency_symbol;
3219
3220 $getInvoice->ArtistName=$get_artists->name;
3221 $getInvoice->categoryName=$get_cat->cat_name;
3222 if($getAdetails->image)
3223 {
3224 $getInvoice->artistImage= base_url().$getAdetails->image;
3225 }
3226 else
3227 {
3228 $getInvoice->artistImage= base_url().'assets/images/image.png';
3229 }
3230 array_push($getInvoices, $getInvoice);
3231 }
3232 $this->api->api_message_data(1, MY_INVOICE,'data' , $getInvoices);
3233 }
3234 else
3235 {
3236 $this->api->api_message(0, NO_DATA);
3237 }
3238 }
3239
3240 /*Get My Invoice*/
3241 public function getMyHistory()
3242 {
3243 $artist_id= $this->input->post('artist_id', TRUE);
3244 $this->checkUserStatus($artist_id);
3245 $where =array('artist_id'=> $artist_id);
3246
3247 $getInvoice= $this->Api_model->getAllDataWhereOrderTwo($where,IVC_TBL);
3248 if($getInvoice)
3249 {
3250 $getInvoices = array();
3251 foreach ($getInvoice as $getInvoice)
3252 {
3253 $getBooking= $this->Api_model->getSingleRow(ABK_TBL, array('id'=>$getInvoice->booking_id));
3254
3255 $getInvoice->booking_time= $getBooking->booking_time;
3256 $getInvoice->booking_date= $getBooking->booking_date;
3257
3258 $getUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->user_id));
3259 $getInvoice->userName= $getUser->name;
3260 $getInvoice->address= $getUser->address;
3261 if($getUser->image)
3262 {
3263 $getInvoice->userImage= base_url().$getUser->image;
3264 }
3265 else
3266 {
3267 $getInvoice->userImage= base_url().'assets/images/image.png';
3268 }
3269
3270 $get_artists= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$getInvoice->artist_id));
3271 $getAdetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getInvoice->artist_id));
3272 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$get_artists->category_id));
3273 $getInvoice->ArtistName=$get_artists->name;
3274 $getInvoice->categoryName=$get_cat->cat_name;
3275
3276 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3277 $getInvoice->currency_type=$currency_setting->currency_symbol;
3278 if($getAdetails->image)
3279 {
3280 $getInvoice->artistImage= base_url().$getAdetails->image;
3281 }
3282 else
3283 {
3284 $getInvoice->artistImage= base_url().'assets/images/image.png';
3285 }
3286 array_push($getInvoices, $getInvoice);
3287 }
3288 $this->api->api_message_data(1, MY_INVOICE,'data' , array_reverse($getInvoices));
3289 }
3290 else
3291 {
3292 $this->api->api_message(0, NO_DATA);
3293 }
3294 }
3295
3296 /*Confirm Payment*/
3297 public function confirm_payment()
3298 {
3299 $invoice_id =$this->input->post('invoice_id', TRUE);
3300 $booking_id =$this->input->post('booking_id', TRUE);
3301
3302 $getInvoice= $this->Api_model->getSingleRow(IVC_TBL, array('invoice_id'=>$invoice_id,'booking_id'=>$booking_id));
3303 if($getInvoice)
3304 {
3305 $updateUser=$this->Api_model->updateSingleRow(IVC_TBL,array('booking_id'=>$booking_id),array('flag'=>1));
3306
3307 $this->api->api_message(1, PAYMENT_CONFIRM);
3308 }
3309 else
3310 {
3311 $this->api->api_message(0, NO_DATA);
3312 }
3313 }
3314
3315 public function strongID()
3316 {
3317 $id= $this->api->strongToken();
3318
3319 echo $id;
3320 }
3321
3322 /*Add to Cart*/
3323 public function addTocart()
3324 {
3325 $data['user_id'] =$this->input->post('user_id', TRUE);
3326 $data['product_id'] =$this->input->post('product_id', TRUE);
3327 $data['quantity'] =$this->input->post('quantity', TRUE);
3328
3329 $this->checkUserStatus($data['user_id']);
3330
3331 $data['created_at']= time();
3332 $data['updated_at']= time();
3333 $getId = $this->Api_model->insertGetId('product_basket', $data);
3334
3335 if($getId)
3336 {
3337 $this->api->api_message(1, "Product Add on your cart successfully.");
3338 }
3339 else
3340 {
3341 $this->api->api_message(0, NO_DATA);
3342 }
3343 }
3344
3345 /*Get My Cart*/
3346 public function getMyCart()
3347 {
3348 $user_id= $this->input->post('user_id', TRUE);
3349
3350 $this->checkUserStatus($user_id);
3351
3352 $get_cart= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'product_basket');
3353 if($get_cart)
3354 {
3355 $get_carts= array();
3356 foreach ($get_cart as $get_cart)
3357 {
3358 $product_id=$get_cart->product_id;
3359 $product= $this->Api_model->getSingleRow('products', array('id'=>$product_id));
3360 $quantity= $get_cart->quantity;
3361 $price= $product->price;
3362
3363 $get_cart->product_name=$product->product_name;
3364 $get_cart->p_rate=$product->price;
3365 $get_cart->product_image=$this->config->base_url().$product->product_image;
3366 $get_cart->product_total_price= $price*$quantity;
3367 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3368 $get_cart->currency_type=$currency_setting->currency_symbol;
3369 array_push($get_carts, $get_cart);
3370 }
3371 $this->api->api_message_data(1, "Get my Cart.",'my_cart', $get_carts);
3372 }
3373 else
3374 {
3375 $this->api->api_message(0, NO_DATA);
3376 }
3377 }
3378
3379 /*update Cart Quantity*/
3380 public function updateCartQuantity()
3381 {
3382 $basket_id = $this->input->post('basket_id',TRUE);
3383 $quantity = $this->input->post('quantity',TRUE);
3384 $user_id = $this->input->post('user_id',TRUE);
3385
3386 $this->checkUserStatus($user_id);
3387
3388 $table= 'product_basket';
3389 $condition = array('id'=>$basket_id, 'user_id'=> $user_id);
3390
3391 $check_basket = $this->Api_model->updateSingleRow('product_basket', array('id'=>$basket_id), array('quantity'=>$quantity));
3392 if ($check_basket)
3393 {
3394 $this->api->api_message(1, "CART UPDATE");
3395 }
3396 else
3397 {
3398 $this->api->api_message(0, NOT_RESPONDING);
3399 }
3400 }
3401
3402 /*Remove Product from Cart*/
3403 public function remove_product_cart()
3404 {
3405 $basket_id = $this->input->post('basket_id',TRUE);
3406 $user_id = $this->input->post('user_id',TRUE);
3407
3408 $this->checkUserStatus($user_id);
3409
3410 $this->Api_model->deleteRecord(array('id'=>$basket_id, 'user_id'=>$user_id), 'product_basket');
3411 $this->api->api_message(1, "REMOVE_CART");
3412 }
3413
3414 /*Get My referral Code*/
3415 public function getMyReferralCode()
3416 {
3417 $user_id= $this->input->post('user_id', TRUE);
3418
3419 $this->checkUserStatus($user_id);
3420
3421 $code=$this->Api_model->getSingleRowCloumn('referral_code',USR_TBL, array('user_id'=>$user_id));
3422 if($code)
3423 {
3424 $userCode['code']= $code->referral_code;
3425 $userCode['description']= COUPON_TEXT;
3426
3427 $this->api->api_message_data(1, "Get my Referral Code.",'my_referral_code', $userCode);
3428 }
3429 else
3430 {
3431 $this->api->api_message(0, NOT_RESPONDING);
3432 }
3433 }
3434
3435
3436 /*Send message (Chat)*/
3437 public function sendmsg()
3438 {
3439 $image= $this->input->post('image', TRUE);
3440 //$data['chat_type']= $this->input->post('chat_type', TRUE);
3441 $chat_type=$this->input->post('chat_type', TRUE);
3442 if(isset($chat_type))
3443 {
3444 $data['chat_type']=$this->input->post('chat_type', TRUE);
3445 }
3446 else
3447 {
3448 $data['chat_type']='1';
3449 }
3450 $data['user_id']= $this->input->post('user_id', TRUE);
3451 $data['artist_id']= $this->input->post('artist_id', TRUE);
3452 $data['message']= $this->input->post('message', TRUE);
3453 $data['send_by']= $this->input->post('send_by', TRUE);
3454 $data['sender_name']= $this->input->post('sender_name', TRUE);
3455 $data['date']= time();
3456 $data['send_at']= time();
3457
3458 $this->load->library('upload');
3459
3460 $config['image_library'] = 'gd2';
3461 $config['upload_path'] = './assets/images/';
3462 $config['allowed_types'] = 'gif|jpg|jpeg|png';
3463 $config['max_size'] = 10000;
3464 $config['file_name'] = time();
3465 $config['create_thumb'] = TRUE;
3466 $config['maintain_ratio'] = TRUE;
3467 $config['width'] = 250;
3468 $config['height'] = 250;
3469 $this->upload->initialize($config);
3470 $updateduserimage="";
3471 if ( $this->upload->do_upload('image') && $this->load->library('image_lib', $config))
3472 {
3473 $updateduserimage='assets/images/'.$this->upload->data('file_name');
3474 }
3475 else
3476 {
3477 // echo $this->upload->display_errors();
3478 }
3479
3480 if($updateduserimage)
3481 {
3482 $data['image']=$updateduserimage;
3483 }
3484
3485 $chatId=$this->Api_model->insertGetId(CHT_TBL,$data);
3486
3487 if($chatId)
3488 {
3489 if($data['send_by'] == $data['artist_id'])
3490 {
3491 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$data['artist_id']));
3492 $msg=$checkUser->name.':'.$data['message'];
3493 $this->firebase_notification($data['user_id'], "Chat" ,$msg);
3494 }
3495 elseif ($data['send_by'] == $data['user_id'])
3496 {
3497 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$data['user_id']));
3498 $msg=$checkUser->name.':'.$data['message'];
3499
3500 $this->firebase_notification($data['artist_id'], "Chat" ,$msg);
3501 }
3502 $get_chat= $this->Api_model->getAllDataWhere(array('user_id'=>$data['user_id'], 'artist_id'=>$data['artist_id']), CHT_TBL);
3503
3504 $get_chats = array();
3505 foreach ($get_chat as $get_chat)
3506 {
3507 if($get_chat->chat_type==2)
3508 {
3509 $get_chat->image= base_url().$get_chat->image;
3510 }
3511
3512 array_push($get_chats, $get_chat);
3513 }
3514
3515 $this->api->api_message_data(1, "Message sent successfully",'my_chat', $get_chats);
3516 }
3517 else
3518 {
3519 $this->api->api_message(0, NOT_RESPONDING);
3520 }
3521 }
3522
3523 /*get conversation*/
3524 public function getChat()
3525 {
3526 $user_id= $this->input->post('user_id', TRUE);
3527 $artist_id= $this->input->post('artist_id', TRUE);
3528
3529 $this->checkUserStatus($user_id);
3530
3531 $get_chat= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id, 'artist_id'=>$artist_id), CHT_TBL);
3532 if($get_chat)
3533 {
3534 $get_chats = array();
3535 foreach ($get_chat as $get_chat)
3536 {
3537 if($get_chat->chat_type==2)
3538 {
3539 $get_chat->image= base_url().$get_chat->image;
3540 }
3541
3542 array_push($get_chats, $get_chat);
3543 }
3544 $this->api->api_message_data(1, "Get my conversation.",'my_chat', $get_chats);
3545 }
3546 else
3547 {
3548 $this->api->api_message(0, "Not yet any conversation.");
3549 }
3550 }
3551
3552 /*get conversation*/
3553 public function getChatHistoryForArtist()
3554 {
3555 $artist_id= $this->input->post('artist_id', TRUE);
3556
3557 $this->checkUserStatus($artist_id);
3558
3559 $where=array('artist_id'=>$artist_id);
3560 $get_users= $this->Api_model->getAllDataWhereDistinct($where, CHT_TBL);
3561 if($get_users)
3562 {
3563 $chats= array();
3564 foreach ($get_users as $get_users)
3565 {
3566 $chat= $this->Api_model->getSingleRowOrderBy(CHT_TBL, array('artist_id'=>$artist_id,'user_id'=>$get_users->user_id));
3567 $user= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_users->user_id));
3568 $chat->userName= $user->name;
3569 if($user->image)
3570 {
3571 $chat->userImage= base_url().$user->image;
3572 }
3573 else
3574 {
3575 $chat->userImage= base_url()."assets/images/image.png";
3576 }
3577
3578 array_push($chats, $chat);
3579 }
3580 $this->api->api_message_data(1, "Get chat history.",'my_chat', $chats);
3581 }
3582 else
3583 {
3584 $this->api->api_message(0, "Not yet any conversation.");
3585 }
3586 }
3587
3588 /*get conversation*/
3589 public function getChatHistoryForUser()
3590 {
3591 $user_id= $this->input->post('user_id', TRUE);
3592 $this->checkUserStatus($user_id);
3593 $where=array('user_id'=>$user_id);
3594 $get_users= $this->Api_model->getAllDataWhereDistinctArtist($where, CHT_TBL);
3595
3596 if($get_users)
3597 {
3598 $chats= array();
3599 foreach ($get_users as $get_users)
3600 {
3601 $chat= $this->Api_model->getSingleRowOrderBy(CHT_TBL, array('artist_id'=>$get_users->artist_id,'user_id'=>$user_id));
3602 $getAdetails= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$get_users->artist_id));
3603 $user= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$get_users->artist_id));
3604 $chat->artistName= $user->name;
3605 if($getAdetails->image)
3606 {
3607 $chat->artistImage= base_url().$getAdetails->image;
3608 }
3609 else
3610 {
3611 $chat->artistImage= base_url()."assets/images/image.png";
3612 }
3613 array_push($chats, $chat);
3614 }
3615
3616 $this->api->api_message_data(1, "Get chat history.",'my_chat', $chats);
3617 }
3618 else
3619 {
3620 $this->api->api_message(0, "Not yet any conversation.");
3621 }
3622 }
3623
3624 public function firebase()
3625 {
3626 $mobile=$this->input->post('mobile');
3627 $title=$this->input->post('title');
3628 $msg=$this->input->post('msg');
3629
3630 for($i=0;$i<count($mobile);$i++)
3631 {
3632 $user = $this->db->where('mobile_no',$mobile[$i])->get('merchant')->row();
3633 $deviceToken = $user->device_token;
3634 $mobile_sent = $mobile[$i];
3635 $title_sent = $title;
3636 $msg_sent = $msg;
3637
3638 $ch = curl_init("https://fcm.googleapis.com/fcm/send");
3639
3640 //Creating the notification array.
3641 $notification = array('title' =>$title_sent , 'text' => $msg_sent);
3642
3643 //This array contains, the token and the notification. The 'to' attribute stores the token.
3644 $arrayToSend = array('to' => $deviceToken, 'notification' => $notification);
3645 //Generating JSON encoded string form the above array.
3646 $json = json_encode($arrayToSend);
3647
3648 //Setup headers:
3649 $headers = array();
3650 $headers[] = 'Content-Type: application/json';
3651
3652
3653 $headers[] = 'Authorization: key= AAAAK8LacGo:APA91bHAIIcXpf5GWEhopBsOpRZhU1CuxTGSL0J_GaT0eJ8aOB78iJl65UDeAjo9kCzsZv2_Rhs13Z_wtqv43MPR6xly39yBqfpDmLW-nn535WdwpGUzd4nvR5R7i5tFL8lDyas9p0Fq'; //server key here
3654
3655 //Setup curl, add headers and post parameters.
3656 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
3657 curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
3658 curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
3659
3660 //Send the request
3661 $result = curl_exec($ch );
3662
3663 //Close request
3664 curl_close($ch);
3665 //return $result;
3666 }
3667 return $result;
3668 }
3669
3670 /*Firebase for notification*/
3671 public function firebase_notification($user_id,$title,$msg1)
3672 {
3673 $get_data= $this->Api_model->getSingleRow(USR_TBL,array('user_id'=>$user_id));
3674
3675 if($get_data->device_token)
3676 {
3677 if($get_data->role==1)
3678 {
3679 $API_ACCESS_KEY= ARTIST_FIREBASE_KEY;
3680 }
3681 else
3682 {
3683 $API_ACCESS_KEY= USER_FIREBASE_KEY;
3684 }
3685
3686 $registrationIds =$get_data->device_token;
3687
3688 $msg = array
3689 (
3690 'body' => $msg1,
3691 'title' => $title,
3692 'icon' => 'myicon',/*Default Icon*/
3693 'sound' => 'mySound'/*Default sound*/
3694 );
3695 $fields = array
3696 (
3697 'to' => $registrationIds,
3698 'notification' => $msg
3699 );
3700 $headers = array
3701 (
3702 'Authorization: key=' . $API_ACCESS_KEY,
3703 'Content-Type: application/json'
3704 );
3705 #Send Reponse To FireBase Server
3706 $ch = curl_init();
3707 curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
3708 curl_setopt( $ch,CURLOPT_POST, true );
3709 curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
3710 curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
3711 curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
3712 curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
3713 $result = curl_exec($ch );
3714 curl_close( $ch );
3715 }
3716 }
3717
3718 public function fire_test($id)
3719 {
3720 $msg='Lorem Ipsum is simply dummy text of the printing and type setting industry.';
3721 $this->firebase_notification($id, "Chat" ,$msg);
3722 }
3723
3724 /*Artist Logout*/
3725 public function artistLogout()
3726 {
3727 $user_id = $this->input->post('artist_id', TRUE);
3728
3729 $this->checkUserStatus($user_id);
3730 $update= $this->Api_model->updateSingleRow(ART_TBL, array('user_id'=> $user_id), array('is_online'=>0));
3731 $this->api->api_message(1, "Artist logout successfully.");
3732 }
3733
3734 /*Artist Location Update*/
3735 public function updateLocation()
3736 {
3737
3738 $this->form_validation->set_rules('longitude','longitude', 'trim|required');
3739 $this->form_validation->set_rules('latitude','latitude', 'trim|required');
3740
3741 if ($this->form_validation->run() == FALSE)
3742 {
3743 $errors=array_values($this->form_validation->error_array());
3744 //$this->response(["success" => false, "message" =>$errors[0]]);
3745 $this->api->api_message(0, $errors[0]);
3746 }
3747 else
3748 {
3749 $user_id = $this->input->post('user_id', TRUE);
3750 $role = $this->input->post('role', TRUE);
3751 $longitude = $this->input->post('longitude', TRUE);
3752 $latitude = $this->input->post('latitude', TRUE);
3753
3754 $this->checkUserStatus($user_id);
3755 if($role==1)
3756 {
3757 $table=ART_TBL;
3758 }
3759 elseif($role==2)
3760 {
3761 $table=USR_TBL;
3762
3763 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$user_id));
3764 if(!$check_user->latitude)
3765 {
3766 $update= $this->Api_model->updateSingleRow($table, array('user_id'=> $user_id), array('latitude'=>$latitude,'longitude'=>$longitude));
3767 }
3768 }
3769
3770 $update= $this->Api_model->updateSingleRow($table, array('user_id'=> $user_id), array('live_lat'=>$latitude,'live_long'=>$longitude));
3771 $this->api->api_message(1, "Location updated successfully.");
3772 }
3773 }
3774
3775 /*Added By Varun*/
3776 function post_job()
3777 {
3778 $data['user_id'] = $this->input->post('user_id', TRUE);
3779 $price = $this->input->post('price', TRUE);
3780 $data['title'] = $this->input->post('title', TRUE);
3781 $data['description'] = $this->input->post('description', TRUE);
3782 $data['category_id'] = $this->input->post('category_id', TRUE);
3783 $data['address'] = $this->input->post('address', TRUE);
3784 $data['lati'] = $this->input->post('lati', TRUE);
3785 $data['longi'] = $this->input->post('longi', TRUE);
3786 $avtar = $this->input->post('avtar', TRUE);
3787
3788 $this->checkUserStatus($data['user_id']);
3789
3790 if(isset($price))
3791 {
3792 $data['price']=$price;
3793 }
3794
3795 $job_id = $this->api->random_string('alnum',6);
3796 $data['job_id'] = strtoupper($job_id);
3797 $table = 'post_job';
3798
3799 $this->load->library('upload');
3800
3801 $config['image_library'] = 'gd2';
3802 $config['upload_path'] = './assets/images/';
3803 $config['allowed_types'] = 'gif|jpg|jpeg|png';
3804 $config['max_size'] = 100000;
3805 $config['file_name'] = time();
3806 $config['create_thumb'] = TRUE;
3807 $config['maintain_ratio'] = TRUE;
3808 $config['width'] = 250;
3809 $config['height'] = 250;
3810 $this->upload->initialize($config);
3811 $ProfileImage="";
3812 if ( $this->upload->do_upload('avtar') && $this->load->library('image_lib', $config))
3813 {
3814 $ProfileImage='assets/images/'.$this->upload->data('file_name');
3815 }
3816 else
3817 {
3818
3819 }
3820
3821 if($ProfileImage)
3822 {
3823 $data['avtar']=$ProfileImage;
3824 }
3825
3826 $user_id = $this->Api_model->insertGetId($table, $data);
3827
3828 if ($user_id)
3829 {
3830 $this->api->api_message(1, "Job added successfully.");
3831 }
3832 else
3833 {
3834 $this->api->api_message(0, "Not added.");
3835 }
3836 }
3837
3838 function edit_post_job()
3839 {
3840 $job_id = $this->input->post('job_id',TRUE);
3841 $title = $this->input->post('title',TRUE);
3842 $price = $this->input->post('price',TRUE);
3843 $description = $this->input->post('description', TRUE);
3844 $category_id = $this->input->post('category_id', TRUE);
3845 $address = $this->input->post('address', TRUE);
3846 $lati = $this->input->post('lati', TRUE);
3847 $longi = $this->input->post('longi', TRUE);
3848 $avtar = $this->input->post('avtar', TRUE);
3849
3850 $table= 'post_job';
3851 $condition = array('job_id'=>$job_id);
3852
3853 if ($job_id!=''||$job_id!=NULL)
3854 {
3855
3856 $check_job = $this->Api_model->getSingleRow($table, $condition);
3857
3858 if ($check_job)
3859 {
3860 $this->load->library('upload');
3861 $config['image_library'] = 'gd2';
3862 $config['upload_path'] = './assets/images/';
3863 $config['allowed_types'] = 'gif|jpg|jpeg|png';
3864 $config['max_size'] = 100000;
3865 $config['file_name'] = time();
3866 $config['create_thumb'] = TRUE;
3867 $config['maintain_ratio'] = TRUE;
3868 $config['width'] = 250;
3869 $config['height'] = 250;
3870 $this->upload->initialize($config);
3871 $profileimage="";
3872 if ( $this->upload->do_upload('avtar'))
3873 {
3874 $profileimage='assets/images/'.$this->upload->data('file_name');
3875 }
3876 else
3877 {
3878
3879 }
3880 if($profileimage)
3881 {
3882 $data['avtar']= $profileimage;
3883 }
3884
3885 $data['title']=isset($title) ? $title: $check_job->title;
3886 $data['price']=isset($price) ? $price: $check_job->price;
3887 $data['description']=isset($description) ? $description: $check_job->description;
3888 $data['category_id']=isset($category_id) ? $category_id: $check_job->category_id;
3889 $data['address']=isset($address) ? $address: $check_job->address;
3890 $data['lati']=isset($lati) ? $lati: $check_job->lati;
3891 $data['longi']=isset($longi) ? $longi: $check_job->longi;
3892 $data['updated_at'] = date('Y-m-d H:i:s');
3893
3894 $this->Api_model->updateSingleRow($table, array('job_id'=>$job_id), $data);
3895
3896 $this->api->api_message(1, 'Job Update Successfully.');
3897 }
3898 else
3899 {
3900 $this->api->api_message(0, 'User not register');
3901 }
3902 }
3903 else
3904 {
3905 $this->api->api_message(0, "Job id not available.");
3906 }
3907 }
3908
3909 public function get_all_job()
3910 {
3911 $artist_id = $this->input->post('artist_id', TRUE);
3912 $get_jobs = $this->Api_model->getAllJobNotAppliedByArtist($artist_id);
3913
3914 if(empty($get_jobs))
3915 {
3916 $this->api->api_message(0, 'No jobs available.');
3917 }
3918 else
3919 {
3920
3921 $job_list = array();
3922 foreach ($get_jobs as $get_jobs)
3923 {
3924 $get_jobs->avtar= base_url().$get_jobs->avtar;
3925 $table= 'user';
3926 $condition = array('user_id'=>$get_jobs->user_id);
3927 $user = $this->Api_model->getSingleRow($table, $condition);
3928 $user->image= base_url().$user->image;
3929
3930 $table= 'category';
3931 $condition = array('id'=>$get_jobs->category_id);
3932 $cate = $this->Api_model->getSingleRow($table, $condition);
3933 $get_jobs->category_name = $cate->cat_name;
3934
3935 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
3936
3937 $get_jobs->commission_type = $commission_setting->commission_type;
3938 $get_jobs->flat_type = $commission_setting->flat_type;
3939 if($commission_setting->commission_type==0)
3940 {
3941 $get_jobs->category_price = $cate->price;
3942 }
3943 elseif($commission_setting->commission_type==1)
3944 {
3945 if($commission_setting->flat_type==2)
3946 {
3947 $get_jobs->category_price = $commission_setting->flat_amount;
3948 }
3949 elseif ($commission_setting->flat_type==1)
3950 {
3951 $get_jobs->category_price = $commission_setting->flat_amount;
3952 }
3953 }
3954
3955 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3956 $get_jobs->currency_symbol= $currency_setting->currency_symbol;
3957
3958 $get_jobs->user_image = $user->image;
3959 $get_jobs->user_name = $user->name;
3960 $get_jobs->user_address = $user->address;
3961 $get_jobs->user_mobile = $user->mobile;
3962
3963 array_push($job_list, $get_jobs);
3964 }
3965 $this->api->api_message_data(1, 'All Jobs Found','data' , $job_list);
3966 }
3967 }
3968
3969 public function get_all_job_user()
3970 {
3971 $user_id = $this->input->post('user_id', TRUE);
3972 $get_jobs=$this->Api_model->getAllDataWhereoderBy(array('user_id'=>$user_id, 'status !='=>'4'),'post_job');
3973 if($get_jobs)
3974 {
3975 $job_list = array();
3976 foreach ($get_jobs as $get_jobs)
3977 {
3978 $get_jobs->avtar= base_url().$get_jobs->avtar;
3979
3980 $job= $this->Api_model->getWhereInStatusResult('applied_job',array('job_id'=>$get_jobs->job_id),'status', array(0,1,5));
3981
3982 if($job)
3983 {
3984 $get_jobs->is_edit =0;
3985 }
3986 else
3987 {
3988 $get_jobs->is_edit =1;
3989 }
3990
3991 $table= 'category';
3992 $condition = array('id'=>$get_jobs->category_id);
3993 $cate = $this->Api_model->getSingleRow($table, $condition);
3994 $get_jobs->category_name = $cate->cat_name;
3995 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
3996 $get_jobs->currency_symbol= $currency_setting->currency_symbol;
3997 $get_jobs->category_price = $cate->price;
3998 array_push($job_list, $get_jobs);
3999 }
4000 $this->api->api_message_data(1, 'All Jobs Found','data' , $job_list);
4001 }
4002 else
4003 {
4004 $this->api->api_message(0, 'No jobs available.');
4005 }
4006 }
4007
4008 public function applied_job()
4009 {
4010 $price = $this->input->post('price', TRUE);
4011 $user_id = $this->input->post('user_id', TRUE);
4012 $artist_id = $this->input->post('artist_id', TRUE);
4013 $job_id = $this->input->post('job_id', TRUE);
4014 $description = $this->input->post('description', TRUE);
4015
4016 $table = 'applied_job';
4017 if(!$check=$this->Api_model->check_applied_job($artist_id, $job_id))
4018 {
4019
4020 if(isset($price))
4021 {
4022 $data['price']=$price;
4023 }
4024 $data['user_id']= $user_id;
4025 $data['artist_id']= $artist_id;
4026 $data['job_id']= $job_id;
4027 $data['description']= $description;
4028
4029 $id = $this->Api_model->insertGetId($table, $data);
4030 if ($id)
4031 {
4032 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$artist_id));
4033 $msg='Hey,'.$checkUser.' applied on your job.';
4034 $this->firebase_notification($checkUser->user_id, "Job" ,$msg);
4035
4036 $this->api->api_message(1, "Job applied successfully.");
4037 }
4038 else
4039 {
4040 $this->api->api_message(0, "Failed.");
4041 }
4042 }
4043 else
4044 {
4045 $this->api->api_message(0, 'Allready applied');
4046 }
4047 }
4048
4049 public function get_applied_job_by_id()
4050 {
4051 $job_id = $this->input->post('job_id', TRUE);
4052 $get_jobs=$this->Api_model->getAllDataWhereoderBy(array('job_id'=>$job_id),'applied_job');
4053
4054 if(empty($get_jobs))
4055 {
4056 $this->api->api_message(0, 'No jobs available.');
4057 }
4058 else
4059 {
4060
4061 $job_list = array();
4062 foreach ($get_jobs as $get_jobs)
4063 {
4064 $table= 'artist';
4065 $condition = array('user_id'=>$get_jobs->artist_id);
4066 $user = $this->Api_model->getSingleRow($table, $condition);
4067 $user->image= base_url().$user->image;
4068
4069 $get_jobs->artist_image = $user->image;
4070 $get_jobs->artist_name = $user->name;
4071
4072 $table= 'category';
4073 $condition = array('id'=>$user->category_id);
4074 $cate = $this->Api_model->getSingleRow($table, $condition);
4075 $get_jobs->category_name = $cate->cat_name;
4076 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
4077 $get_jobs->commission_type = $commission_setting->commission_type;
4078 $get_jobs->flat_type = $commission_setting->flat_type;
4079 if($commission_setting->commission_type==0)
4080 {
4081 $get_jobs->category_price = $cate->price;
4082 }
4083 elseif($commission_setting->commission_type==1)
4084 {
4085 if($commission_setting->flat_type==2)
4086 {
4087 $get_jobs->category_price = $commission_setting->flat_amount;
4088 }
4089 elseif ($commission_setting->flat_type==1)
4090 {
4091 $get_jobs->category_price = $commission_setting->flat_amount;
4092 }
4093 }
4094
4095 $table1= 'user';
4096 $condition = array('user_id'=>$get_jobs->artist_id);
4097 $artist = $this->Api_model->getSingleRow($table1, $condition);
4098
4099 $get_jobs->artist_address = $artist->address;
4100 $get_jobs->artist_mobile = $artist->mobile;
4101 $get_jobs->artist_email = $artist->email_id;
4102
4103 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
4104 $get_jobs->currency_symbol= $currency_setting->currency_symbol;
4105 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',array('artist_id'=>$get_jobs->artist_id));
4106 if($ava_rating[0]->rating==null)
4107 {
4108 $ava_rating[0]->rating="0";
4109 }
4110 $get_jobs->ava_rating= round($ava_rating[0]->rating, 2);
4111 array_push($job_list, $get_jobs);
4112 }
4113 $this->api->api_message_data(1, 'All Jobs Found','data' , $job_list);
4114 }
4115 }
4116
4117 public function job_status_user()
4118 {
4119 $aj_id = $this->input->post('aj_id', TRUE);
4120 $status = $this->input->post('status', TRUE);
4121 $job_id = $this->input->post('job_id', TRUE);
4122
4123 $table = 'applied_job';
4124 $condition = array('aj_id'=>$aj_id);
4125
4126 $job = $this->Api_model->getSingleRow($table, $condition);
4127
4128 if ($status == '1')
4129 {
4130 $update= $this->Api_model->updateSingleRow('applied_job', array('aj_id'=> $aj_id), array('status'=>$status));
4131
4132 $this->api->api_message(1, "Job confirm successfully.");
4133 $this->firebase_notification($job->artist_id, 'Job Status' ,'Your request is confirm.');
4134 }
4135 elseif($status == '2')
4136 {
4137 if ($job->status == '1')
4138 {
4139 $update= $this->Api_model->updateSingleRow('applied_job', array('aj_id'=> $aj_id), array('status'=>$status));
4140 $update1= $this->Api_model->updateJob('applied_job', array('aj_id !='=> $aj_id, 'job_id' =>$job_id), '3');
4141 $this->Api_model->updateSingleRow('post_job', array('job_id'=> $job->job_id), array('status'=>$status));
4142 $this->api->api_message(1, "Job Complete successfully.");
4143 $this->firebase_notification($job->artist_id, 'Job Status' ,'Job completed.');
4144 }
4145 else
4146 {
4147 $this->api->api_message(0, "Please confirm job first");
4148 }
4149 }
4150 elseif($status == '3')
4151 {
4152 if ($job->status != '2')
4153 {
4154 $update= $this->Api_model->updateSingleRow('applied_job', array('aj_id'=> $aj_id), array('status'=>$status));
4155 $this->api->api_message(1, "Job Rejected successfully.");
4156 $this->firebase_notification($job->artist_id, 'Job Status' ,'Job Rejected.');
4157 }
4158 else
4159 {
4160 $this->api->api_message(0, "Failed");
4161 }
4162 }
4163 else
4164 {
4165 $this->api->api_message(0, "Failed");
4166 }
4167 }
4168
4169 public function get_applied_job_artist()
4170 {
4171 $artist_id = $this->input->post('artist_id', TRUE);
4172 $get_jobs=$this->Api_model->getAllDataWhereoderBy(array('artist_id'=>$artist_id,'status !='=>'4'),'applied_job');
4173 if(empty($get_jobs))
4174 {
4175 $this->api->api_message(0, 'No jobs available.');
4176 }
4177 else
4178 {
4179 $job_list = array();
4180 foreach ($get_jobs as $get_jobs)
4181 {
4182 $table= 'user';
4183 $condition = array('user_id'=>$get_jobs->user_id);
4184 $user = $this->Api_model->getSingleRow($table, $condition);
4185 $job = $this->Api_model->getSingleRow('post_job', array('job_id'=>$get_jobs->job_id));
4186 $cat= $this->Api_model->getSingleRow(CAT_TBL, array('id'=>$job->category_id));
4187 $user->image= base_url().$user->image;
4188 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
4189 $get_jobs->currency_symbol= $currency_setting->currency_symbol;
4190 $get_jobs->category_name = $cat->cat_name;
4191 $get_jobs->user_image = $user->image;
4192 $get_jobs->user_name = $user->name;
4193 $get_jobs->user_address = $job->address;
4194 $get_jobs->user_mobile = $user->mobile;
4195 $get_jobs->user_email = $user->email_id;
4196
4197 array_push($job_list, $get_jobs);
4198 }
4199 $this->api->api_message_data(1, 'Trabalhos Aplicados DisponÃveis','data' , $job_list);
4200 }
4201 }
4202
4203 public function job_status_artist()
4204 {
4205 $aj_id = $this->input->post('aj_id', TRUE);
4206 $status = $this->input->post('status', TRUE);
4207
4208 $table = 'applied_job';
4209 $condition = array('aj_id'=>$aj_id);
4210
4211 $job = $this->Api_model->getSingleRow($table, $condition);
4212
4213 if($status == '3')
4214 {
4215 if ($job->status != '2')
4216 {
4217 $update= $this->Api_model->updateSingleRow('applied_job', array('aj_id'=> $aj_id), array('status'=>$status));
4218 $this->Api_model->updateSingleRow('post_job', array('job_id'=> $job->job_id), array('status'=>'0'));
4219 $this->api->api_message(1, "Job Rejected successfully.");
4220 $this->firebase_notification($job->artist_id, 'Job Status' ,'Job Rejected.');
4221 }
4222 else
4223 {
4224 $this->api->api_message(0, "Failed");
4225 }
4226 }
4227 else
4228 {
4229 $this->api->api_message(0, "Failed");
4230 }
4231 }
4232
4233 public function deletejob()
4234 {
4235 $job_id = $this->input->post('job_id', TRUE);
4236 $status = $this->input->post('status', TRUE);
4237
4238 $job= $this->Api_model->getWhereInStatusResult('applied_job',array('job_id'=>$job_id),'status', array(5));
4239 if(empty($job))
4240 {
4241 $this->Api_model->updateSingleRow('post_job', array('job_id'=> $job_id), array('status'=>$status));
4242 $this->api->api_message(1, "Job Delete successfully.");
4243 }
4244 else
4245 {
4246 $this->api->api_message(0, "Currently artist working on this job.");
4247 }
4248 }
4249
4250 /*Case 1 accept booking 2 start booking 3 end booking*/
4251 public function appointment_operation()
4252 {
4253 $request =$this->input->post('request', TRUE);
4254 $appointment_id =$this->input->post('appointment_id', TRUE);
4255 $user_id =$this->input->post('user_id', TRUE);
4256
4257 $this->checkUserStatus($user_id);
4258
4259 switch ($request)
4260 {
4261 case 1:
4262 $this->accept_appointment($appointment_id);
4263 break;
4264
4265 case 2:
4266 $this->reject_appointment($appointment_id);
4267 break;
4268
4269 case 3:
4270 $this->complete_appointment($appointment_id);
4271 break;
4272 case 4:
4273 $this->decline_appointment($appointment_id);
4274 break;
4275 default:
4276 $this->api->api_message(0, TRY_AGAIN);
4277 }
4278 }
4279
4280 /*Accept Booking*/
4281 public function accept_appointment($appointment_id)
4282 {
4283 $data['status'] =1;
4284
4285 $getBooking= $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id));
4286 if($getBooking)
4287 {
4288 $updateBooking=$this->Api_model->updateSingleRow(APP_TBL,array('id'=>$appointment_id),$data);
4289
4290 if($updateBooking)
4291 {
4292 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
4293 $msg=$checkUser->name.': has accepted your appointment.';
4294 $this->firebase_notification($getBooking->user_id, "Appointment" ,$msg);
4295
4296 $this->api->api_message(1, "Appointment accepted successfully.");
4297 }
4298 else
4299 {
4300 $this->api->api_message(0, TRY_AGAIN);
4301 }
4302 }
4303 else
4304 {
4305 $this->api->api_message(0, TRY_AGAIN);
4306 }
4307 }
4308
4309 /*Reject Booking*/
4310 public function reject_appointment($appointment_id)
4311 {
4312 $data['status'] =2;
4313
4314 $getBooking= $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id));
4315 if($getBooking)
4316 {
4317 $updateBooking=$this->Api_model->updateSingleRow(APP_TBL,array('id'=>$appointment_id),$data);
4318
4319 if($updateBooking)
4320 {
4321 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
4322 $msg=$checkUser->name.': has rejected your appointment.';
4323 $this->firebase_notification($getBooking->user_id, "Appointment" ,$msg);
4324
4325 $this->api->api_message(1, "Appointment rejected successfully.");
4326 }
4327 else
4328 {
4329 $this->api->api_message(0, TRY_AGAIN);
4330 }
4331 }
4332 else
4333 {
4334 $this->api->api_message(0, TRY_AGAIN);
4335 }
4336 }
4337
4338 /*Reject Booking*/
4339 public function complete_appointment($appointment_id)
4340 {
4341 $data['status'] =3;
4342
4343 $getBooking= $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id));
4344 if($getBooking)
4345 {
4346 $updateBooking=$this->Api_model->updateSingleRow(APP_TBL,array('id'=>$appointment_id),$data);
4347 if($updateBooking)
4348 {
4349 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
4350 $msg=$checkUser->name.': has completed your appointment.';
4351 $this->firebase_notification($getBooking->user_id, "Appointment" ,$msg);
4352
4353 $this->api->api_message(1, "Appointment completed successfully.");
4354 }
4355 else
4356 {
4357 $this->api->api_message(0, TRY_AGAIN);
4358 }
4359 }
4360 else
4361 {
4362 $this->api->api_message(0, TRY_AGAIN);
4363 }
4364 }
4365
4366
4367 /*Reject Booking*/
4368 public function decline_appointment($appointment_id)
4369 {
4370 $data['status'] =4;
4371
4372 $getBooking= $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id));
4373 if($getBooking)
4374 {
4375 $updateBooking=$this->Api_model->updateSingleRow(APP_TBL,array('id'=>$appointment_id),$data);
4376
4377 if($updateBooking)
4378 {
4379 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$getBooking->artist_id));
4380 $msg=$checkUser->name.': has decline your appointment.';
4381 $this->firebase_notification($getBooking->user_id, "Appointment" ,$msg);
4382
4383 $this->api->api_message(1, "Appointment decline successfully.");
4384 }
4385 else
4386 {
4387 $this->api->api_message(0, TRY_AGAIN);
4388 }
4389 }
4390 else
4391 {
4392 $this->api->api_message(0, TRY_AGAIN);
4393 }
4394 }
4395
4396
4397 public function add_favorites()
4398 {
4399 $user_id=$this->input->post('user_id', TRUE);
4400 $artist_id=$this->input->post('artist_id', TRUE);
4401 $data['user_id']= $user_id;
4402 $data['artist_id']= $artist_id;
4403
4404 if($this->Api_model->check_favorites($user_id,$artist_id))
4405 {
4406 $this->api->api_message(0, "Already Favorites.");
4407 }
4408 else
4409 {
4410 $this->Api_model->add_favorites($data);
4411 $this->api->api_message(1, "Add Favorites Successfully.");
4412 }
4413 }
4414
4415 public function remove_favorites()
4416 {
4417 $user_id=$this->input->post('user_id', TRUE);
4418 $artist_id=$this->input->post('artist_id', TRUE);
4419 $this->Api_model->remove_favorites($user_id, $artist_id);
4420 $this->api->api_message(1, "Remove Favorites Successfully.");
4421 }
4422
4423 public function getLocationArtist()
4424 {
4425 $artist_id=$this->input->post('artist_id', TRUE);
4426 $role='1';
4427
4428 $checkUser = $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$artist_id));
4429 $user_latlongs = array();
4430 if ($checkUser)
4431 {
4432 $user_latlongs['lati'] = $checkUser->live_lat;
4433 $user_latlongs['longi'] = $checkUser->live_long;
4434
4435 $this->api->api_message_data(1, 'Lat Longs','data' , $user_latlongs);
4436 }
4437 else
4438 {
4439 $this->api->api_message(0, "Failed");
4440 }
4441 }
4442
4443 public function changeCommissionArtist()
4444 {
4445 $artist_id =$this->input->post('artist_id', TRUE);
4446 $data['artist_commission_type'] =$this->input->post('artist_commission_type', TRUE);
4447 $this->checkUserStatus($artist_id);
4448
4449 $checkUser = $this->Api_model->getSingleRow('user', array('user_id'=>$artist_id));
4450
4451 if($checkUser)
4452 {
4453 $updateUser= $this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$artist_id),$data);
4454 $this->api->api_message(1, 'Commission type change successfully.');
4455 }
4456 else
4457 {
4458 $this->api->api_message(0, TRY_AGAIN);
4459 }
4460 }
4461
4462 public function getCurrencyType()
4463 {
4464 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
4465 $data['currency_type']= $currency_setting->currency_symbol;
4466 $this->api->api_message_data(1, 'Get currency type','currency_type' , $data);
4467 }
4468
4469
4470 /*Start Job*/
4471 public function startJob()
4472 {
4473 $job_id = $this->input->post('job_id', TRUE);
4474 $data['user_id'] = $this->input->post('user_id', TRUE);
4475 $data['artist_id'] = $this->input->post('artist_id', TRUE);
4476 $data['price'] = $this->input->post('price', TRUE);
4477 $date_string= date('Y-m-d h:i a');
4478 $data['time_zone']= $this->input->post('timezone', TRUE);
4479 $data['booking_date'] = date('Y-m-d');
4480 $data['booking_time'] = date('h:i a');
4481 $data['start_time']=time();
4482 $data['created_at']=time();
4483 $data['booking_type']=2;
4484 $data['booking_flag']=3;
4485 $data['updated_at']=time();
4486 $data['booking_timestamp']=strtotime($date_string);
4487
4488 $this->checkUserStatus($data['user_id']);
4489 $this->checkUserStatus($data['artist_id']);
4490
4491 $checkArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id'],'booking_flag'=>1));
4492
4493 if($checkArtist)
4494 {
4495 $this->api->api_message(0, "Artist Busy with another client. Please try after sometime.");
4496 exit();
4497 }
4498
4499 $checkJob= $this->Api_model->getSingleRow(AJB_TBL, array('job_id'=>$job_id,'status'=>1,'artist_id'=>$data['artist_id']));
4500 if($checkJob)
4501 {
4502 $data['job_id']= $job_id;
4503 $this->Api_model->updateSingleRow(AJB_TBL,array('job_id'=>$job_id),array('status'=>5));
4504
4505 $checkArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id'],'booking_flag'=>1));
4506 if($checkArtist)
4507 {
4508 $this->api->api_message(0, "Artist Busy with another client. Please try after sometime.");
4509 exit();
4510 }
4511
4512 $getArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id']));
4513
4514 $category_id= $getArtist->category_id;
4515 $category= $this->Api_model->getSingleRow(CAT_TBL, array('id'=>$category_id));
4516
4517 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
4518
4519 $data['commission_type']=$commission_setting->commission_type;
4520 $data['flat_type']=$commission_setting->flat_type;
4521 if($commission_setting->commission_type==0)
4522 {
4523 $data['category_price']= $category->price;
4524 }
4525 elseif($commission_setting->commission_type==1)
4526 {
4527 if($commission_setting->flat_type==2)
4528 {
4529 $data['category_price']= $commission_setting->flat_amount;
4530 }
4531 elseif ($commission_setting->flat_type==1)
4532 {
4533 $data['category_price']= $commission_setting->flat_amount;
4534 }
4535 }
4536
4537 $appId = $this->Api_model->insertGetId(ABK_TBL, $data);
4538 if($appId)
4539 {
4540 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$data['user_id']));
4541 $msg=$checkUser->name.': start your job'.$date_string;
4542 $this->firebase_notification($data['artist_id'], "Start Job" ,$msg);
4543
4544 $dataNotification['user_id']= $data['artist_id'];
4545 $dataNotification['title']= "Start Job";
4546 $dataNotification['msg']= $msg;
4547 $dataNotification['type']= "Individual";
4548 $dataNotification['created_at']=time();
4549 $this->Api_model->insertGetId(NTS_TBL,$dataNotification);
4550
4551 $updateUser=$this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$data['artist_id']),array('booking_flag'=>1));
4552 $this->api->api_message(1, BOOK_APP);
4553 }
4554 else
4555 {
4556 $this->api->api_message(0, TRY_AGAIN);
4557 }
4558 }
4559 else
4560 {
4561 $this->api->api_message(0, "Nenhum trabalho encontrado no estado inicial. Por favor, tente mais tarde.");
4562 exit();
4563 }
4564 }
4565
4566
4567 /*Start Job*/
4568 public function startAppointment()
4569 {
4570 $appointment_id = $this->input->post('appointment_id', TRUE);
4571 $data['user_id'] = $this->input->post('user_id', TRUE);
4572 $data['artist_id'] = $this->input->post('artist_id', TRUE);
4573 $data['price'] = $this->input->post('price', TRUE);
4574 $date_string= date('Y-m-d h:i a');
4575 $data['time_zone']= $this->input->post('timezone', TRUE);
4576 $data['booking_date'] = date('Y-m-d');
4577 $data['booking_time'] = date('h:i a');
4578 $data['start_time']=time();
4579 $data['created_at']=time();
4580 $data['booking_type']=1;
4581 $data['booking_flag']=3;
4582 $data['updated_at']=time();
4583 $data['booking_timestamp']=strtotime($date_string);
4584
4585 $this->checkUserStatus($data['user_id']);
4586 $this->checkUserStatus($data['artist_id']);
4587
4588 $checkJob= $this->Api_model->getSingleRow(APP_TBL, array('id'=>$appointment_id,'status'=>1,'artist_id'=>$data['artist_id']));
4589 if($checkJob)
4590 {
4591 $data['job_id']= $appointment_id;
4592 $this->Api_model->updateSingleRow(APP_TBL,array('id'=>$appointment_id),array('status'=>5));
4593
4594 $checkArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id'],'booking_flag'=>1));
4595 if($checkArtist)
4596 {
4597 $this->api->api_message(0, "Artista Ocupado com outro cliente. Por favor, tente depois de algum tempo.");
4598 exit();
4599 }
4600
4601 $getArtist= $this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$data['artist_id']));
4602
4603 $category_id= $getArtist->category_id;
4604 $category= $this->Api_model->getSingleRow(CAT_TBL, array('id'=>$category_id));
4605
4606 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
4607
4608 $data['commission_type']=$commission_setting->commission_type;
4609 $data['flat_type']=$commission_setting->flat_type;
4610 if($commission_setting->commission_type==0)
4611 {
4612 $data['category_price']= $category->price;
4613 }
4614 elseif($commission_setting->commission_type==1)
4615 {
4616 if($commission_setting->flat_type==2)
4617 {
4618 $data['category_price']= $commission_setting->flat_amount;
4619 }
4620 elseif ($commission_setting->flat_type==1)
4621 {
4622 $data['category_price']= $commission_setting->flat_amount;
4623 }
4624 }
4625
4626 $appId = $this->Api_model->insertGetId(ABK_TBL, $data);
4627 if($appId)
4628 {
4629 $checkUser= $this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$data['user_id']));
4630 $msg=$checkUser->name.': start your job'.$date_string;
4631 $this->firebase_notification($data['artist_id'], "Start Job" ,$msg);
4632
4633 $dataNotification['user_id']= $data['artist_id'];
4634 $dataNotification['title']= "Start Job";
4635 $dataNotification['msg']= $msg;
4636 $dataNotification['type']= "Individual";
4637 $dataNotification['created_at']=time();
4638 $this->Api_model->insertGetId(NTS_TBL,$dataNotification);
4639
4640 $updateUser=$this->Api_model->updateSingleRow(ART_TBL,array('user_id'=>$data['artist_id']),array('booking_flag'=>3));
4641 $this->api->api_message(1, BOOK_APP);
4642 }
4643 else
4644 {
4645 $this->api->api_message(0, TRY_AGAIN);
4646 }
4647 }
4648 else
4649 {
4650 $this->api->api_message(0, "Nenhum compromisso encontrado no estado inicial. Por favor, tente mais tarde.");
4651 exit();
4652 }
4653 }
4654
4655 /*Mark as complete*/
4656 public function jobComplete()
4657 {
4658 $user_id=$this->input->post('user_id', TRUE);
4659 $job_id=$this->input->post('job_id', TRUE);
4660
4661 $this->checkUserStatus($user_id);
4662
4663 $job= $this->Api_model->getWhereInStatusResult('applied_job',array('job_id'=>$job_id),'status', array(5));
4664 if(empty($job))
4665 {
4666 $jobs=$this->Api_model->getWhereInStatusResult('applied_job',array('job_id'=>$job_id),'status', array(0,1));
4667 foreach ($jobs as $jobs)
4668 {
4669 $this->Api_model->updateSingleRow('applied_job', array('aj_id'=> $jobs->aj_id), array('status'=>3));
4670 }
4671 $this->Api_model->updateSingleRow('post_job', array('job_id'=> $job_id), array('status'=>2));
4672 $this->api->api_message(1, "Job finished successfully.");
4673 }
4674 else
4675 {
4676 $this->api->api_message(0, "Currently artist working on this job.");
4677 }
4678 }
4679
4680 /*Request For Wallet Amount*/
4681 public function walletRequest()
4682 {
4683 $user_id=$this->input->post('user_id', TRUE);
4684
4685 $this->checkUserStatus($user_id);
4686
4687 $data['artist_id']= $user_id;
4688 $data['created_at']= time();
4689 $reqGet= $this->Api_model->getSingleRow("wallet_request", array('artist_id'=>$user_id, 'status'=>0));
4690 if($reqGet)
4691 {
4692 $this->api->api_message(0, TRY_AGAIN);
4693 exit();
4694 }
4695
4696 $id=$this->Api_model->insertGetId("wallet_request",$data);
4697 if($id)
4698 {
4699 $this->api->api_message(1, "Thanks for the request. We will approved your request");
4700 }
4701 else
4702 {
4703 $this->api->api_message(0, TRY_AGAIN);
4704 }
4705 }
4706
4707 /*PayPal Payment gateway*/
4708 public function paypal()
4709 {
4710 $pkf_name=$this->input->get('pkf_name');
4711 $amount=$this->input->get('amount');
4712 $userId=$this->input->get('userId');
4713 $pkgId=$this->input->get('pkgId');
4714 $data = array('pkgName' =>$pkf_name ,'amount' =>$amount,'userId'=>$userId,'pkgId' =>$pkgId );
4715 $this->load->view('paypal', $data);
4716 }
4717
4718 public function payusuccess()
4719 {
4720 $this->load->view('payusuccess');
4721 }
4722
4723 public function payufailure()
4724 {
4725 $this->load->view('payufailure');
4726 }
4727
4728 /*Get My favourite*/
4729 public function getMyFavourite()
4730 {
4731 $user_id=$this->input->post('user_id', TRUE);
4732 $longitude_app=$this->input->post('longitude_app', TRUE);
4733 $latitude_app=$this->input->post('latitude_app', TRUE);
4734 $this->checkUserStatus($user_id);
4735
4736 function distance($lat1, $lon1, $lat2, $lon2)
4737 {
4738 try
4739 {
4740 $theta = $lon1 - $lon2;
4741 $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
4742 $dist = acos($dist);
4743 $dist = rad2deg($dist);
4744 $miles = $dist * 60 * 1.1515;
4745 return ($miles * 1.609344);
4746 }
4747
4748 catch(Exception $e)
4749 {
4750 return (0.0);
4751 }
4752 }
4753
4754 $getFavourite= $this->Api_model->getAllDataWhere(array('user_id'=>$user_id), 'favourite');
4755 if($getFavourite)
4756 {
4757 $artists= array();
4758 foreach ($getFavourite as $getFavourite)
4759 {
4760 $artist=$this->Api_model->getSingleRow(ART_TBL, array('user_id'=>$getFavourite->artist_id));
4761
4762 $jobDone=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist->user_id,'booking_flag'=>4));
4763
4764 $artist->total=$this->Api_model->getTotalWhere(ABK_TBL,array('artist_id'=>$artist->user_id,));
4765 if($artist->total==0)
4766 {
4767 $artist->percentages=0;
4768 }
4769 else
4770 {
4771 $artist->percentages=round(($jobDone*100) / $artist->total);
4772 }
4773 $artist->jobDone=$jobDone;
4774
4775 $get_cat=$this->Api_model->getSingleRow(CAT_TBL, array('id'=>$artist->category_id));
4776 $getUser=$this->Api_model->getSingleRow(USR_TBL, array('user_id'=>$artist->user_id));
4777 if($getUser->image)
4778 {
4779 $artist->image=base_url().$getUser->image;
4780 }
4781 else
4782 {
4783 $artist->image=base_url()."assets/images/image.png";
4784 }
4785 $artist->category_name=$get_cat->cat_name;//
4786
4787
4788 $currency_setting= $this->Api_model->getSingleRow('currency_setting',array('status'=>1));
4789
4790 $artist->currency_type=$currency_setting->currency_symbol;
4791 $commission_setting= $this->Api_model->getSingleRow('commission_setting',array('id'=>1));
4792 $artist->commission_type=$commission_setting->commission_type;
4793 $artist->flat_type=$commission_setting->flat_type;
4794 if($commission_setting->commission_type==0)
4795 {
4796 $artist->category_price=$get_cat->price;
4797 }
4798 elseif($commission_setting->commission_type==1)
4799 {
4800 if($commission_setting->flat_type==2)
4801 {
4802 $artist->category_price = $commission_setting->flat_amount;
4803 }
4804 elseif ($commission_setting->flat_type==1)
4805 {
4806 $artist->category_price = $commission_setting->flat_amount;
4807 }
4808 }
4809
4810
4811 $distance =distance($latitude_app,$longitude_app,$artist->latitude,$artist->longitude);
4812 $distance=round($distance);
4813 $distance_str="$distance";
4814 $artist->distance=$distance_str;
4815 $where= array('artist_id'=>$artist->user_id);
4816 $ava_rating=$this->Api_model->getAvgWhere('rating', 'rating',$where);
4817 if($ava_rating[0]->rating==null)
4818 {
4819 $ava_rating[0]->rating="0";
4820 }
4821 $artist->ava_rating= round($ava_rating[0]->rating, 2);
4822
4823 $check_fav= $this->Api_model->check_favorites($user_id,$artist->user_id);
4824 $artist->fav_status= $check_fav ? "1":"0";
4825
4826 array_push($artists, $artist);
4827 }
4828
4829 usort($artists, function($a,$b) {
4830 if($a->distance == $b->distance) return 0;
4831 return ($a->distance < $b->distance) ? -1 : 1;
4832 });
4833 $this->api->api_message_data(1, ALL_ARTISTS,'data' , $artists);
4834 }
4835 else
4836 {
4837 $this->api->api_message(0, NO_DATA);
4838 }
4839 }
4840}