80 lines
2.9 KiB
PHP
Executable File
80 lines
2.9 KiB
PHP
Executable File
<?php
|
|
require_once('../../../fixed/config/go_con.php');
|
|
|
|
$tretment_id = mysqli_real_escape_string($db, $_POST['tretment_id']);
|
|
|
|
$erorr = 0;
|
|
if (empty($tretment_id)) {
|
|
echo "
|
|
<script>
|
|
swalfun('حدث خطأ', 'لم يتم ارسال البيانات بشكل صحيح', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
$erorr++;
|
|
}
|
|
|
|
$tretment_query = mysqli_query($db, "SELECT `number` FROM `tretment` WHERE `id` = $tretment_id");
|
|
$tr_data = mysqli_fetch_assoc($tretment_query);
|
|
|
|
$tretment_has_coupons_query = mysqli_query($db, "SELECT COUNT(`tretment_has_coupons`.`coupons_id`) AS `total` FROM `tretment_has_coupons` WHERE `coupons_id` = 1");
|
|
$tretment_has_coupons_data = mysqli_fetch_assoc($tretment_has_coupons_query);
|
|
|
|
if (!$tretment_has_coupons_query) {
|
|
if ($tretment_has_coupons_data['total'] >= 1000) {
|
|
echo "
|
|
<script>
|
|
swalfun('حدث خطأ', 'تم استخدام 1000 كوبون', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
$erorr++;
|
|
}
|
|
$erorr++;
|
|
}
|
|
|
|
//sms
|
|
$just_U = 'LkjgHJKLGjklHLJKhgjklGHHJKLghjkGKLU';
|
|
$tretmentNumber = mysqli_real_escape_string($db, $tr_data['number']);
|
|
$cou_number = 'AQ'.($tretment_has_coupons_data['total'] + 1).'-RUH';
|
|
|
|
$m_body =
|
|
'يوم الرجل العالمي
|
|
انت قدها ..
|
|
خصم 20٪ لمنسوبي الأمانة العامة بمنطقة الرياض
|
|
هذا الكوبون '.$cou_number.'
|
|
صالح لمدة شهرين من تاريخ 20-11-2022';
|
|
|
|
if ($erorr == 0) {
|
|
|
|
$check_has_coupons = mysqli_query($db, "SELECT `coupons_id` FROM `tretment_has_coupons` WHERE `tretment_id` = $tretment_id");
|
|
if (mysqli_num_rows($check_has_coupons) == 0) {
|
|
if (mysqli_query(
|
|
$db,
|
|
"INSERT INTO `tretment_has_coupons`(`tretment_id`, `coupons_id`, `code`, `date_time`, `user_id`, `activation_id`) VALUES ('$tretment_id','1','$cou_number','$date_time','$admin_id','2')"
|
|
)) {
|
|
//sms
|
|
require_once('../../../fixed/sms/send_message.php');
|
|
echo "
|
|
<script type='text/javascript'>
|
|
swalfun('تم إضافة الكوبون بنجاح','', 'success');
|
|
location.reload();
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('تنبية', 'تم تسجيل كوبون لهذا العميل', 'warning');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
}
|
|
} else {
|
|
echo "
|
|
<script>
|
|
swalfun('حدث خطأ', 'لم يتم ارسال البيانات بشكل صحيح', 'error');
|
|
click = 0;
|
|
</script>
|
|
";
|
|
} |