| Server IP : 103.48.194.25 / Your IP : 216.73.216.74 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/namduongmarket.com-bk/public_html/site/components/api/controllers/ |
Upload File : |
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Product extends MX_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('common');
$this->load->helper('api') ;
}
/********** Start *****************/
function add()
{
$is_save = true;
$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{
try {
$req['pcode'] = $this->input->post('pcode');
$req['pro_code'] = $this->input->post('pro_code');
$req['pro_name'] = $this->input->post('pro_name');
$req['pro_alias'] = $this->input->post('pro_alias');
$req['proimg'] = $this->input->post('proimg');
$req['sumary'] = $this->input->post('sumary');
$req['pro_desc'] = $this->input->post('pro_desc');
$req['price'] = $this->input->post('price');
$req['price_old'] = $this->input->post('price_old');
$req['pro_status'] = (int) $this->input->post('pro_status');
$req['status_text'] = $this->input->post('status_text');
$req['size'] = $this->input->post('size');
$req['weight'] = $this->input->post('weight');
$req['warranty'] = $this->input->post('warranty');
$req['metatitle'] = $this->input->post('metatitle');
$req['metadesc'] = $this->input->post('metadesc');
$req['metakey'] = $this->input->post('metakey');
$req['dt_modify'] = date("Y-m-d H:i:s");
$req['bl_active'] = (int) $this->input->post('bl_active');
$path = $this->input->post('path');
$list_img = $this->input->post('list_img');
$pcode = $this->input->post('pcode');
$pro_code = $this->input->post('pro_code');
$proid = $this->input->post('proid');
if($is_save && $pcode)
{
$rs = $this->common->get_id('product','pcode',$pcode);
if($rs && empty($rs->phamvi))
{
$proid = $this->common->save('product',$req,'proid',$rs->proid);
$this->saveimg($req['proimg'],$path);
$this->_add_list_img($proid,$list_img);
$is_save = false;
$res['msg'] = 'Cập nhật theo pcode: '.$pcode;
$res['proid'] = $rs->proid;
}
if($rs && !empty($rs->phamvi))
{
$is_save = false;
$res['msg'] = 'Đã khóa cập nhật theo pcode';
$res['proid'] = $rs->proid;
}
}
if($is_save && $proid)
{
$rs = $this->common->get_id('product','proid',$proid);
if($rs && empty($rs->phamvi))
{
$proid = $this->common->save('product',$req,'proid',$rs->proid);
$this->saveimg($req['proimg'],$path);
$this->_add_list_img($proid,$list_img);
$is_save = false;
$res['proid'] = $proid;
$res['msg'] = 'Cập nhật sản phẩm theo proid '.$proid;
}
if($rs && !empty($rs->phamvi))
{
$is_save = false;
$res['msg'] = 'Đã khóa cập nhật theo proid';
$res['proid'] = $rs->proid;
}
}
if($is_save && $pro_code)
{
$rs = $this->common->get_id('product','pro_code',$pro_code);
if($rs && empty($rs->phamvi))
{
$proid = $this->common->save('product',$req,'proid',$rs->proid);
$this->saveimg($req['proimg'],$path);
$this->_add_list_img($proid,$list_img);
$is_save = false;
$res['msg'] = 'Cập nhật theo pro_code';
$res['proid'] = $rs->proid;
}
if($rs && !empty($rs->phamvi))
{
$is_save = false;
$res['msg'] = 'Đã khóa cập nhật theo pro_code';
$res['proid'] = $rs->proid;
}
}
if($is_save)
{
//trit05-04-2020: san pham an dung đe cap nhat tay. Chỉ them moi
//Kiểm tra xem có sp ẩn ko
/*$rs = $this->common->get_record('product',array('bl_active'=>0));
if($rs)
{
$proid = $this->common->save('product',$req,'proid',$rs->proid);
$this->saveimg($req['proimg'],$path);
$this->_add_list_img($proid,$list_img);
$is_save = false;
$res['msg'] = 'Cập nhật theo sản phẩm ẩn: '.$proid;
$res['proid'] = $proid;
}
else
{*/
$proid = $this->common->save('product',$req);
$this->saveimg($req['proimg'],$path);
$this->_add_list_img($proid,$list_img);
$is_save = false;
$res['msg'] = 'Thêm mới sản phẩm';
$res['proid'] = $proid;
//}
}
header("Content-type: application/json; charset=utf-8");
$res['code'] = 1;
echo json_encode($res);
}
catch (Exception $e)
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['msg'] = $e->getMessage();
$res['code'] = 0;
echo json_encode($res);
}
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Key không hợp lệ';
echo json_encode($res);
}
}
function saveimg($proimg='',$path='')
{
if($proimg && $path)
{
$fullpath = $path.$proimg;
$source = file_get_contents($fullpath);
$upto = ROOT_IMG.'products/800/'.$proimg;
write_file($upto,$source);
}
}
//cập nhật danh sách hình ảnh
function _add_list_img($proid,$list_img)
{
$list_img = json_decode($list_img); //trit($list_img);
if($list_img)
{
$this->common->del('productimage','proid',$proid);
foreach ($list_img as $img) :
$this->_built_frm($proid,$img);
endforeach ;
}
}
function _built_frm($proid,$img)
{
$req['proid'] = $proid;
$req['ImageName'] = $img->ImageName;
$req['ImagePath'] = 'products/800/';
$req['ImageType'] = 1;
$proid = $this->common->save('productimage',$req);
$path = $this->input->post('path');
$this->saveimg($req['ImageName'],$path);
}
/********** End *****************/
/**
* Ver : 1.0
* Date : 01-01-2020
* Desc : Cập nhật thông tin giá, size, weight, warranty và trạng thái sản phẩm
* Params :
*/
function upprice()
{
$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{
$req['price'] = $this->input->post('price');
$req['price_old'] = $this->input->post('price_old');
$req['pro_status'] = $this->input->post('pro_status');
$req['size'] = $this->input->post('size');
$req['weight'] = $this->input->post('weight');
$req['warranty'] = $this->input->post('warranty');
//Lay thong tin product ID tham chiếu
$proid = $this->input->post('proid');
if($proid)
{
$proid = $this->common->save('product',$req,'proid',$proid);
header("Content-type: application/json; charset=utf-8");
$res['proid'] = $proid;
$res['code'] = 1;
$res['msg'] = 'Cập nhật sản phẩm theo proid';
echo json_encode($res);
}
else
{
//Nếu không tìm thấy pID tham chiếu dùng code
$pro_code = $this->input->post('pro_code');
$rs = $this->common->get_record('product',array('pro_code'=>$pro_code));
if($rs)
{
$this->common->save('product',$req,'proid',$rs->proid);
header("Content-type: application/json; charset=utf-8");
$res['proid'] = $rs->proid;
$res['code'] = 1;
$res['msg'] = 'Cập nhật sản phẩm theo code';
echo json_encode($res);
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Không tìm thấy sản phẩm';
echo json_encode($res);
}
}
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Key không hợp lệ';
echo json_encode($res);
}
}
/*function upprice()
{
$incoming = file_get_contents("php://input");
$obj = json_decode($incoming, TRUE);
$key = isset($obj["key"])? $obj['key'] : '';
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{
$req['price'] = isset($obj['price'])? to_number($obj['price']) : 0;
$req['price_old'] = isset($obj['price_old'])? to_number($obj['price_old']) : 0;
$req['pro_status'] = isset($obj['pro_status'])? $obj['pro_status'] : 0;
$req['size'] = isset($obj['size'])? $obj['size'] : '';
$req['weight'] = isset($obj['weight'])? floatval($obj['weight']) : 0;
$req['warranty'] = isset($obj['warranty'])? floatval($obj['warranty']) : 0;
//Lay thong tin product ID tham chiếu
$proid = isset($obj['proid'])? $obj['proid'] : 0;
if($proid)
{
$req['pro_code'] = isset($obj['pro_code'])? $obj['pro_code'] : '';
$proid = $this->common->save('product',$req,'proid',$proid);
header("Content-type: application/json; charset=utf-8");
$res['proid'] = $proid;
echo json_encode($res);
}
else
{
//Nếu không tìm thấy pID tham chiếu dùng code
$pro_code = isset($obj['pro_code'])? $obj['pro_code'] : '';
$rs = $this->common->get_record('product',array('pro_code'=>$pro_code));
if($rs)
{
$proid = $this->common->save('product',$req,'pro_code',$pro_code);
header("Content-type: application/json; charset=utf-8");
$res['proid'] = $rs->proid;
echo json_encode($res);
}
else
{
//neu khong tim thay san pham tuong dong thi ko cap nhat gia
//$proid = $this->common->save('product',$req);
//tra ve thong tin thất bại
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
echo json_encode($res);
}
}
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
echo json_encode($res);
}
}*/
/**
* Ver : 1.0
* Date : 01-01-2020
* Desc : Show form start get price
* Params :
*/
function upmeta()
{
$msg = '';
$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{
$req['metatitle'] = $this->input->post('metatitle');
$req['metadesc'] = $this->input->post('metadesc');
$req['metakey'] = $this->input->post('metakey');
//Lay thong tin product ID tham chiếu
$proid = $this->input->post('proid');
if($proid)
{
$proid = $this->common->save('product',$req,'proid',$proid);
header("Content-type: application/json; charset=utf-8");
$res['proid'] = $proid;
$res['code'] = 1;
$res['msg'] = 'Cập nhật sản phẩm thành công';
echo json_encode($res);
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = $proid;
$res['code'] = 0;
$res['msg'] = 'Không tìm thấy proid sản phẩm';
echo json_encode($res);
}
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Key không hợp lệ';
echo json_encode($res);
}
}
//Các function khong còn dùng nữa
function addcategory()
{
header('Access-Control-Allow-Origin: *');
header('Content-Type:application/json');
$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{
$req['cat_name'] = $this->input->post('cat_name');
$req['cat_alias'] = $this->input->post('cat_alias');
$req['parent_id'] = (int) $this->input->post('parent_id');
$req['nb_level'] = (int) $this->input->post('nb_level');
$req['is_home'] = (int) $this->input->post('is_home');
$req['is_mainmenu'] = (int) $this->input->post('is_mainmenu');
$req['nb_order'] = (int) $this->input->post('nb_order');
$req['metatitle'] = $this->input->post('metatitle');
$req['metadesc'] = $this->input->post('metadesc');
$req['metakey'] = $this->input->post('metakey');
$req['bl_active'] = (int) $this->input->post('bl_active');
$rs = $this->common->get_record('category','cat_name',$req['cat_name']);
if($rs)
{
$catid = $this->common->save('category',$req,'catid',$rs->catid);
echo $catid;
// $res["status"] = "failed";
// $res["catid"] = 0;
// echo json_encode($res);
}
else
{
$catid = $this->common->save('category',$req);
echo $catid;
// $res["status"] = "success";
// $res["catid"] = $catid;
// echo json_encode($res);
}
}
else
{
echo 0;
//$res["status"] = "failed";
// $res["catid"] = 0;
// echo json_encode($res);
}
}
/**
* Ver : 1.0
* Date : 01-01-2020
* Desc : Hien thi danh sac cac san pham theo cac chuyen muc
* Params :
*/
function home()
{
$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{
try {
}
catch (Exception $e)
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['msg'] = $e->getMessage();
$res['code'] = 0;
echo json_encode($res);
}
}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Key không hợp lệ';
echo json_encode($res);
}
}
/**
* Ver : 1.0
* Date : 01-01-2020
* Desc : Show sản phẩm cho các trang khác
* Params :
*/
function category()
{
/*$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{*/
try {
$catid = $this->input->post('catid');
$rs_cat = $this->common->get_id('category','catid',$catid);
$listpro = $this->common->get_result('product',array('catid'=>$catid),'',20,0);
header("Content-type: application/json; charset=utf-8");
$res['status'] = 1;
$res['rs_cat'] = $rs_cat;
$res['listpro'] = $listpro;
$res['code'] = 1;
echo json_encode($res);
}
catch (Exception $e)
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['msg'] = $e->getMessage();
$res['code'] = 0;
echo json_encode($res);
}
/*}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Key không hợp lệ';
echo json_encode($res);
}*/
}
/**
* Ver : 1.0
* Date : 31-07-2020
* Desc : Hiển thị sản phẩm chi tiết cho các trang khác
* Params :
*/
function detail($proid=0)
{
if(empty($proid)) showfail();
/*$key = $this->input->post('key');
if($key == 'xbKjXT56a9Fbqvfr4ztdF2gbQ7vM7zKhe4sGwZ6x')
{*/
try {
$rs = $this->common->get_id('product','proid',$proid);
$rs_cat = $this->common->get_id('category','catid',$rs->catid);
//sản phẩm cùng nhóm
$list_img = $this->common->get_result('productimage',array('proid'=>$proid),'',20,0);
$listpro = $this->common->get_result('product',array('catid'=>$rs->catid),'',20,0);
header("Content-type: application/json; charset=utf-8");
$res['status'] = 1;
$res['rs_cat'] = $rs_cat;
$res['rs'] = $rs;
$res['listpro'] = $listpro;
$res['list_img'] = $list_img;
$res['code'] = 1;
echo json_encode($res);
}
catch (Exception $e)
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['msg'] = $e->getMessage();
$res['code'] = 0;
echo json_encode($res);
}
/*}
else
{
header("Content-type: application/json; charset=utf-8");
$res['proid'] = 0;
$res['code'] = 0;
$res['msg'] = 'Key không hợp lệ';
echo json_encode($res);
}*/
}
}
?>