thắc mắc [PHP] Hỏi đáp thắc mắc

  • Người tạo chủ đề Người tạo chủ đề merciless
  • Ngày bắt đầu Ngày bắt đầu

merciless

Đã tốn tiền
Hi các thím,
Em bị tình trạng này mong các thím giúp đỡ ạ.

Mô tả:
Web hiển thị nút Xóa.
Người dùng cần có quyền xóa (quyền số 13 trong mảng của group_permission)
Tình trạng lỗi: Người dùng có hay không có quyền số 13 đều Xóa được nội dung.
Kiểm thử với ($this->db->trans_status() === FALSE) thì không thấy kết quả, cũng không hiển thị được thông báo thất bại. Em google chiều giờ mà chưa tìm ra nguyên nhân.
Dưới đây là các đoạn code liên quan.
Rất mong các thím hướng dẫn cách khắc phục :sad:


1. Đoạn code hiển thị nút xóa

<i class="fa fa-trash-o" style="color: darkred;" title="<?php if ($option == 1)
echo 'Xóa vĩnh viễn';
else
echo 'Xóa'?>"
onclick="<?php if ($option == 1)
echo 'cms_del_order';
else
echo 'cms_del_temp_order'?>(<?php echo $item['ID'] . ',' . $page; ?>)"></i>

2. Đoạn code update và điều kiện khi người dùng bấm nút xóa

public function cms_del_temp_order($id)
{
if ($this->auth == null || !in_array(13, $this->auth['group_permission']))
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');

$id = (int)$id;
$order = $this->db->from('orders')->where(['ID' => $id, 'deleted' => 0])->get()->row_array();
$store_id = $order['store_id'];
$this->db->trans_begin();
$user_init = $this->auth['id'];
if (isset($order) && count($order)) {
if ($order['order_status'] == 1) {
$list_products = json_decode($order['detail_order'], true);
foreach ($list_products as $item) {
$inventory_quantity = $this->db->select('quantity')->from('inventory')->where(['store_id' => $store_id, 'product_id' => $item['id']])->get()->row_array();
if (!empty($inventory_quantity)) {
$this->db->where(['store_id' => $store_id, 'product_id' => $item['id']])->update('inventory', ['quantity' => $inventory_quantity['quantity'] + $item['quantity'], 'user_upd' => $user_init]);
} else {
$inventory = ['store_id' => $store_id, 'product_id' => $item['id'], 'quantity' => $item['quantity'], 'user_init' => $user_init];
$this->db->insert('inventory', $inventory);
}

$product = $this->db->select('prd_sls')->from('products')->where('ID', $item['id'])->get()->row_array();
$sls['prd_sls'] = $product['prd_sls'] + $item['quantity'];
$this->db->where('ID', $item['id'])->update('products', $sls);
$this->db->where(['transaction_id' => $id, 'product_id' => $item['id'], 'store_id' => $store_id])->update('report', ['deleted' => 1, 'user_upd' => $user_init]);
}

$this->db->where('order_id', $id)->update('receipt', ['deleted' => 1, 'user_upd' => $user_init]);
$this->db->where('ID', $id)->update('orders', ['deleted' => 1, 'user_upd' => $user_init]);
$this->cms_del_temp_input($id);

} else {
$this->db->where('ID', $id)->update('orders', ['deleted' => 1, 'user_upd' => $user_init]);
}
}

if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}


public function cms_del_order($id)
{
if ($this->auth == null || !in_array(13, $this->auth['group_permission']))
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');

$id = (int)$id;
$order = $this->db->from('orders')->where(['ID' => $id, 'deleted' => 1])->get()->row_array();
$this->db->trans_begin();
if (isset($order) && count($order)) {
$this->db->where('ID', $id)->update('orders', ['deleted' => 2, 'user_upd' => $this->auth['id']]);
} else
echo $this->messages = "0";

if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}

3. Đoạn js thông báo thành công _ lỗi
function cms_del_temp_order($id, $page) {
var conf = confirm('Bạn chắc chắn muốn xóa đơn hàng này?');
if (conf) {
var $param = {
'type': 'POST',
'url': 'orders/cms_del_temp_order/' + $id,
'data': null,
'callback': function (data) {
if (data == '1') {
cms_paging_order($page);
$('.ajax-success-ct').html('Xóa đơn hàng thành công.').parent().fadeIn().delay(1000).fadeOut('slow');
} else if (data == '0') {
$('.ajax-error-ct').html('Oops! This system is errors! please try again.').parent().fadeIn().delay(1000).fadeOut('slow');
}
}
};
cms_adapter_ajax($param);
}
}
 
if ($this->auth == null || !in_array(13, $this->auth['group_permission'])) return
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');
 
if ($this->auth == null || !in_array(13, $this->auth['group_permission'])) return
$this->cms_common_string->cms_redirect(CMS_BASE_URL . 'backend');
Ôi thím ơi em yêu thím vđ :sexy: Thím xài điện thoại mạng gì em gửi cái card cảm ơn ạ :D
Mà thím cho em hỏi, sao ok vậy mà messages = "0" nó vẫn không nhận giá trị nhỉ ? Xóa thì có thông báo mà trả về 0 thì lại im re.
 
Ôi thím ơi em yêu thím vđ :sexy: Thím xài điện thoại mạng gì em gửi cái card cảm ơn ạ :D
Mà thím cho em hỏi, sao ok vậy mà messages = "0" nó vẫn không nhận giá trị nhỉ ? Xóa thì có thông báo mà trả về 0 thì lại im re.
Không hiểu ý thím lắm, messages = 0 khi trường hợp nào thế?
 
Không hiểu ý thím lắm, messages = 0 khi trường hợp nào thế?

Khúc slse if này có vấn đề gì không thím? Với thím xài mạng gì ạ, em tặng thím cái card đt cảm ơn.
Mã:
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}
 
Khúc slse if này có vấn đề gì không thím? Với thím xài mạng gì ạ, em tặng thím cái card đt cảm ơn.
Mã:
if ($this->db->trans_status() === FALSE) {
$this->db->trans_rollback();
echo $this->messages = "0";
} else {
$this->db->trans_commit();
echo $this->messages = "1";
}
}
Thôi ko cần card gì đâu, cảm ơn thím, code theo mình thấy ko có vấn đề, thím mô tả luồng hoạt động trường hợp này đi, và sai như thế nào
 
Em muốn check truy vấn quyền hạn phía trên khi user xóa bài, nếu FALSE thì xuất hiện thông báo lỗi gọi từ file js, còn có quyền và xóa được thì xuất thông báo thành công.
Hàm chỉ xuất thông báo thành công mà không thấy call được messages lỗi ạ.
Cảm ơn thím đã giúp em, phiền thím nhiều quá.
 
Em thấy do trans_status không nhận giá trị mà chưa tìm ra tìm ra nguyên nhân do đâu.
 
Em đang bị lú khi lm backend. Cần một cao nhân chỉ điểm về ORM và autoload. Có hậu tạ!
 
demo ngày xưa code autoload ko có composer

PHP:
<?php



class autoload
{

    /**
     * Application constructor.
     */
    public function __construct()
    {
        spl_autoload_register(array($this, '_autoload'));
    }

    /**
     * @param $file
     */
    public function _autoload($file)
    {
        $file = str_replace("\\", "/", trim($file, '\\')) . '.php';
        if (file_exists($file))
        {
            require_once($file);
        }
    }
}
 
Các bác cho em hỏi với ạ, ví dụ nếu em tạo 1 layout html css cố định, giờ muốn code một cái giao diện viết bài. Khi muốn viết 1 bài mới thì nội dung sẽ vào đúng trong layout đó. Không biết em nên tìm hiểu gì ạ, web php nhé các bác.
 

[Nhờ vả]Convert code từ dotnet sang PHP​

Bác nào sửa giúp mình chạy tốt. Mình hậu tạ thẻ 200k
Mình có xin đc đoạn code tính lịch ngày âm này khoảng 200 dòng. Nhờ bác nào rảnh convert giúp mình với xin cảm ơn nhiều.
var tv = new DAMME3DTuVi.TuVi();
tv.setDate(27,11,1995);
Ngày âm : " + tv.dayLunar(); //kết quả: Nhâm Tuất
dữ liệu đầu vào ngaysinh: 27/11/1995.
kết quả mong muốn : Nhâm Tuất

Mã:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
namespace DAMME3DTuVi
{
    public class TuVi
    {
        private int day, month, year, hour, minute, second, gender;
        private String name;
        private String[] CAN = { "Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Qúy" };
        private String[] CHI = { "Tí", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi" };
        public void setDate(int day, int month, int year)
        {
            this.day = day;
            this.month = month;
            this.year = year;
        }
        public void setTime(int hour, int minute, int second)
        {
            this.hour = hour;
            this.minute = minute;
            this.second = second;
        }
        public TuVi(String name, int day, int month, int year)
        {
            this.name = name;
            this.day = day;
            this.month = month;
            this.year = year;
            this.hour = -1;
            this.minute = -1;
            this.second = -1;
            this.gender = -1;
        }
        public String dayLunar()
        {
            int iCan = 3, iChi = 9;
            TuVi tmp = new TuVi(this.day, this.month, this.year);
            int numDays = getDayBetweenDate(new TuVi(1, 3, 1996));
            if (tmp.lessThan(new TuVi(1, 3, 1996)))
            {
                iCan = (iCan - numDays % 10 + 10) % 10;
                iChi = (iChi - numDays % 12 + 12) % 12;
            }
            else
            {
                if (tmp.moreThan(new TuVi(1, 3, 1996)))
                {
                    iCan = (iCan + numDays % 10) % 10;
                    iChi = (iChi + numDays % 12) % 12;
                }
            }
            return CAN[iCan] + " " + CHI[iChi];
        }
        public int getDayBetweenDate(TuVi hs)
        {
            int count = 0;
            TuVi tmp = new TuVi(this.day, this.month, this.year);

            if (lessThan(hs))
            {
                while (!equal(hs))
                {
                    increaseOneDay();
                    count++;
                }
            }
            else
            {
                if (moreThan(hs))
                {
                    while (!equal(hs))
                    {
                        decreaseOneDay();
                        count++;
                    }
                }
            }
            this.day = tmp.day;
            this.month = tmp.month;
            this.year = tmp.year;
            return count;
        }
        public void decreaseOneDay()
        {
            if (isBeginMonth())
            {
                if (isBeginOfYear())
                {
                    this.month = 12;
                    this.year--;
                }
                else
                    this.month--;
                this.day = getDaysOfMonth(this.month, this.year);
            }
            else
                this.day--;
        }
        public int getDaysOfMonth(int m, int y)
        {
            int numberDays = 0;
            switch (m)
            {
                case 2:
                    if (isLeapYear(y))
                        numberDays = 29;
                    else
                        numberDays = 28;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    numberDays = 30;
                    break;
                default:
                    numberDays = 31;
                    break;
            }
            return numberDays;
        }
        public bool isLeapYear(int year)
        {
            return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
        }

        public bool isBeginOfYear()
        {
            return (this.day == 1 && this.month == 1);
        }
        public bool isBeginMonth()
        {
            return this.day == 1;
        }
        public bool moreThan(TuVi hs)
        {
            bool check;
            if (this.year > hs.year)
                check = true;
            else
            {
                if (this.year == hs.year)
                {
                    if (this.month > hs.month)
                        check = true;
                    else
                    {
                        if (this.month == hs.month)
                        {
                            if (this.day > hs.day)
                                check = true;
                            else
                                check = false;
                        }
                        else
                            check = false;
                    }
                }
                else
                    check = false;
            }
            return check;
        }
        public void increaseOneDay()
        {
            if (isEndMonth())
            {
                if (isEndOfYear())
                {
                    this.month = 1;
                    this.year++;
                }
                else
                    this.month++;
                this.day = 1;
            }
            else
                this.day++;
        }
        public bool isEndMonth()
        {
            return ((this.day == 30 && (this.month == 4 || this.month == 6 || this.month == 9 || this.month == 11))
                    || (this.day == 31 && (this.month == 1 || this.month == 3
                    || this.month == 5 || this.month == 7 || this.month == 8 || this.month == 10 || this.month == 12))
                    || (isLeapYear() ? this.day == 29 && this.month == 2 : this.day == 28 && this.month == 2));
        }
        public bool isEndOfYear()
        {
            return (this.day == 31 && this.month == 12);
        }

        public bool lessThan(TuVi hs)
        {
            bool check;
            if (this.year < hs.year)
                check = true;
            else
            {
                if (this.year == hs.year)
                {
                    if (this.month < hs.month)
                        check = true;
                    else
                    {
                        if (this.month == hs.month)
                        {
                            if (this.day < hs.day)
                                check = true;
                            else
                                check = false;
                        }
                        else
                            check = false;
                    }
                }
                else
                    check = false;
            }
            return check;
        }
    }
}
 
Sửa lần cuối:
copy nguyên cái đống code này xong biến thì xóa bỏ type và thêm cái dấu $ ở trước mỗi biến. sửa tí là được thôi mà. :sad: Thời gian fen lập thớt chờ người convert tự sửa nhanh hơn nhiều. chắc k đến 2 phút
 
Code đơn giản vậy tự làm đi thím.
Toàn ifelse ko mà
thực sự là về class thì mình không biết nhiều thử tự làm báo lỗi lung tung cả.
đoạn này cũng ko hiểu làm thế nào nữa ở bên php
TuVi tmp = new TuVi(this.day, this.month, this.year);
int numDays = getDayBetweenDate(new TuVi(1, 3, 1996));
Mã:
public int getDayBetweenDate(TuVi hs)
        {
            int count = 0;
            TuVi tmp = new TuVi(this.day, this.month, this.year);
            if (lessThan(hs))
            {
                while (!equal(hs))
                {
                    increaseOneDay();
                    count++;
                }
            }
            else
            {
                if (moreThan(hs))
                {
                    while (!equal(hs))
                    {
                        decreaseOneDay();
                        count++;
                    }
                }
            }
            this.day = tmp.day;
            this.month = tmp.month;
            this.year = tmp.year;
            return count;
        }
 
thực sự là về class thì mình không biết nhiều thử tự làm báo lỗi lung tung cả.
đoạn này cũng ko hiểu làm thế nào nữa ở bên php
TuVi tmp = new TuVi(this.day, this.month, this.year);
int numDays = getDayBetweenDate(new TuVi(1, 3, 1996));
public int getDayBetweenDate(TuVi hs)
{
......
}

Là sao ông thần? Bên Php cũng có class , cũng có constructor cũng có method, prooperty. Mắc mớ j ko làm đc?
Còn nếu thím ko biết PHP thì thuê tụi sinh viên đi cho lẹ. Xong trả nó 200k -300k cafe
 
Là sao ông thần? Bên Php cũng có class , cũng có constructor cũng có method, prooperty. Mắc mớ j ko làm đc?
Còn nếu thím ko biết PHP thì thuê tụi sinh viên đi cho lẹ. Xong trả nó 200k -300k cafe
bạn sửa hộ mình đi, hậu tạ card điện thoại 200k :)
 

Thống kê chủ đề

Ngày tạo
merciless,
Người trả lời cuối
trinhtrang22,
Trả lời
229
Lượt xem
11.343
Quay lại
Lên đầu trang