将值字段更改为codeigniter OSPOS中的百分比字段

时间:2017-08-27 05:45:13

标签: php codeigniter

add new giftcard

这是在CodeGniter中的OSPOS中添加新礼品页面。 gifcard_id,person_id,giftcard_number,我想要的值中有四个字段将值字段更改为客户购买的商品总价格的百分比。这些项目存储在另一个表格中。我怎么能这样做?

我的模特

/*
    Gets gift card value
    */
    public function get_giftcard_value($giftcard_number)
    {
        if( !$this->exists($this->get_giftcard_id($giftcard_number)) )
        {
            return 0;
        }

        $this->db->from('giftcards');
        $this->db->where('giftcard_number', $giftcard_number);

        return $this->db->get()->row()->value;
    }

    /*
    Updates gift card value
    */
    public function update_giftcard_value($giftcard_number, $value)
    {
        $this->db->where('giftcard_number', $giftcard_number);
        $this->db->update('giftcards', array('value' => $value));
    }

我的控制器

public function save($giftcard_id = -1)
    {
        $giftcard_number = $this->input->post('giftcard_number');

        if($giftcard_id == -1 && trim($giftcard_number) == '')
        {
            $giftcard_number = $this->Giftcard->generate_unique_giftcard_name($this->input->post('value'));
        }

        $giftcard_data = array(
            'record_time' => date('Y-m-d H:i:s'),
            'giftcard_number' => $giftcard_number,
            'value' => parse_decimals($this->input->post('value')),
            'person_id' => $this->input->post('person_id') == '' ? NULL : $this->input->post('person_id')
        );

        if($this->Giftcard->save($giftcard_data, $giftcard_id))
        {
            $giftcard_data = $this->xss_clean($giftcard_data);

            //New giftcard
            if($giftcard_id == -1)
            {
                echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_adding') . ' ' .
                                $giftcard_data['giftcard_number'], 'id' => $giftcard_data['giftcard_id']));
            }
            else //Existing giftcard
            {
                echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('giftcards_successful_updating') . ' ' .
                                $giftcard_data['giftcard_number'], 'id' => $giftcard_id));
            }
        }
        else //failure
        {
            $giftcard_data = $this->xss_clean($giftcard_data);

            echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('giftcards_error_adding_updating') . ' ' .
                            $giftcard_data['giftcard_number'], 'id' => -1));
        }
    }

0 个答案:

没有答案