This commit is contained in:
2024-01-31 11:36:25 +07:00
parent caef156a05
commit 4561bd68d1
125 changed files with 9117 additions and 58 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Hura8\Components\Marketing\AdminController;
use Hura8\Components\Marketing\Controller\bCouponController;
use Hura8\Interfaces\iEntityAdminController;
use Hura8\Traits\AdminEntityBaseControllerTraits;
class ACouponController extends bCouponController implements iEntityAdminController
{
use AdminEntityBaseControllerTraits;
public function updateProduct($product_id, $coupon_id, array $info)
{
return $this->objCouponModel->updateProduct($product_id, $coupon_id, $info);
}
public function removeProduct($product_id, $coupon_id)
{
return $this->objCouponModel->removeProduct($product_id, $coupon_id);
}
public function addProduct($product_id, $coupon_id, $ordering=0)
{
return $this->objCouponModel->addProduct($product_id, $coupon_id, $ordering);
}
protected function deleteFileBeforeDeleteItem($item_id): bool
{
// TODO: Implement deleteFileBeforeDeleteItem() method.
return true;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Hura8\Components\Marketing\AdminController;
use Hura8\Components\Marketing\Model\PosterModel;
use Hura8\System\Controller\aAdminEntityBaseController;
class APosterController extends aAdminEntityBaseController
{
/* @var PosterModel $objPosterModel */
protected $objPosterModel;
public function __construct()
{
$this->objPosterModel = new PosterModel();
parent::__construct($this->objPosterModel);
}
protected function deleteFileBeforeDeleteItem($item_id): bool
{
// TODO: Implement deleteFileBeforeDeleteItem() method.
return true;
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Hura8\Components\Marketing\AdminController;
use Hura8\Components\Marketing\Controller\bProductFeedController;
use Hura8\Components\Marketing\Model\ProductFeedModel;
use Hura8\Interfaces\iEntityAdminController;
use Hura8\System\Controller\aAdminEntityBaseController;
use Hura8\Traits\AdminEntityBaseControllerTraits;
class AProductFeedController extends bProductFeedController implements iEntityAdminController
{
use AdminEntityBaseControllerTraits;
public function getAllCategories() {
return $this->objProductFeedModel->getAllCategories();
}
public function getAllProductListIds( $list_id){
return $this->objProductFeedModel->getAllProductListIds($list_id);
}
public function getProductListTotal($list_id) {
return $this->objProductFeedModel->getProductListTotal($list_id);
}
public function getProductList($list_id, $page = 1, $numPerPage = 30) {
return $this->objProductFeedModel->getProductList($list_id, $page, $numPerPage);
}
public function deleteAllProductFromList($list_id) {
$this->objProductFeedModel->deleteAllProductFromList($list_id);
}
//remove product from a list
public function deleteProductFromList($pro_list, $list_id){
return $this->objProductFeedModel->deleteProductFromList($pro_list, $list_id);
}
//add product to a list
public function addProductToList($pro_list, $list_id){
return $this->objProductFeedModel->addProductToList($pro_list, $list_id);
}
protected function deleteFileBeforeDeleteItem($item_id): bool
{
return true;
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Hura8\Components\Marketing\Controller;
use Hura8\Components\Marketing\Model\CouponModel;
use Hura8\System\Controller\aEntityBaseController;
class bCouponController extends aEntityBaseController
{
protected $type_list = array(
'pro' => "Tặng sản phẩm",
'cash' => "Tặng tiền mặt",
'priceoff' => "Giảm giá %",
'other' => "Khác"
);
/* @var CouponModel $objCouponModel */
protected $objCouponModel;
public function __construct()
{
$this->objCouponModel = new CouponModel();
parent::__construct($this->objCouponModel);
}
public function getTotalProduct($coupon_id, array $condition = [])
{
return $this->objCouponModel->getTotalProduct($coupon_id, $condition);
}
public function getListProduct($coupon_id, array $condition = []) {
return $this->objCouponModel->getListProduct($coupon_id, $condition);
}
public function getTypeList() {
return $this->type_list;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Hura8\Components\Marketing\Controller;
use Hura8\Components\Marketing\Model\ProductFeedModel;
use Hura8\System\Controller\aEntityBaseController;
class bProductFeedController extends aEntityBaseController
{
protected $objProductFeedModel;
public function __construct()
{
$this->objProductFeedModel = new ProductFeedModel();
parent::__construct($this->objProductFeedModel);
}
public function getInfoByPublicId($public_id)
{
return $this->objProductFeedModel->getInfoByPublicId($public_id);
}
}

View File

@@ -0,0 +1,130 @@
<?php
namespace Hura8\Components\Marketing\Model;
use Hura8\Components\Product\Model\ProductModel;
use Hura8\Interfaces\AppResponse;
use Hura8\Interfaces\EntityType;
use Hura8\System\IDGenerator;
use Hura8\System\Model\aEntityBaseModel;
use Hura8\System\Security\DataClean;
use Hura8\System\Security\DataType;
use Hura8\System\TimeManager;
class CouponModel extends aEntityBaseModel
{
protected $tb_coupon_product = "tb_coupon_product";
public function __construct() {
parent::__construct(EntityType::COUPON);
}
protected function extendedFilterOptions() : array
{
return [
// empty for now
];
}
public function getTotalProduct($coupon_id, array $condition = [])
{
$query = $this->db->runQuery(
" SELECT COUNT(*) as total FROM `".$this->tb_coupon_product."` WHERE `coupon_id` = ? ",
['d'], [$coupon_id]
);
$total = 0;
if ($rs = $this->db->fetchAssoc($query)) {
$total = $rs['total'];
}
return $total;
}
public function getListProduct($coupon_id, array $condition = [])
{
$numPerPage = (isset($condition['numPerPage']) && $condition['numPerPage'] > 0 ) ? intval($condition['numPerPage']) : 20 ;
$page = (isset($condition['page']) && $condition['page'] > 0 ) ? intval($condition['page']) : 1 ;
$order_by = " `ordering` DESC, `id` DESC";
$query = $this->db->runQuery(
"SELECT `product_id` FROM ".$this->tb_coupon_product." WHERE `coupon_id` = ?
ORDER BY ".$order_by."
LIMIT ".(($page-1) * $numPerPage).", ".$numPerPage ,
['d'], [$coupon_id]
) ;
$item_list = array();
$counter = ($page-1) * $numPerPage;
foreach ( $this->db->fetchAll($query) as $item ) {
$counter += 1;
$item_list[$item['product_id']] = [
'counter' => $counter,
];
}
$objProductModel = new ProductModel();
$product_list_info = $objProductModel->getListByIds(array_keys($item_list));
// final list
$final_list = [];
foreach ($item_list as $_pro_id => $_pro_info_in_collection) {
$pro_basic = $product_list_info[$_pro_id] ?? null;
if($pro_basic) {
$final_list[] = array_merge($pro_basic, $_pro_info_in_collection);
}
}
return $final_list;
}
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
{
/*$condition = array(
"q" => getRequest("q", ''),
"featured" => (int) getRequest("featured"),
"status" => (int) getRequest("status"),
);*/
$catCondition = [];
$bind_types = [];
$bind_values = [];
if(isset($filter_condition["letter"]) && strlen($filter_condition["letter"]) == 1){
$catCondition[] = " AND `letter` = ? ";
$bind_types[] = 's';
$bind_values[] = $filter_condition["letter"];
}
return array( join(" ", $catCondition), $bind_types, $bind_values);
}
protected function createUniqueCode($current_item_id, $wanted_code = ''){
if(!$wanted_code) $wanted_code = IDGenerator::createStringId(10);
$clean_code = DataClean::makeInputSafe($wanted_code, DataType::ID);
$clean_code = strtoupper($clean_code);
//if exist and belong other id, create a new one
$query = $this->db->runQuery("SELECT `id` FROM `".$this->tb_entity."` WHERE `code` = ? LIMIT 1 ", ['s'], [$clean_code]) ;
if($info = $this->db->fetchAssoc($query)){
if($info['id'] != $current_item_id) {
$new_code = IDGenerator::createStringId(6);
return $this->createUniqueCode($current_item_id, $new_code);
}
}
return $clean_code;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Hura8\Components\Marketing\Model;
use Hura8\Interfaces\AppResponse;
use Hura8\System\Model\aEntityBaseModel;
class PosterModel extends aEntityBaseModel
{
public function __construct() {
parent::__construct('poster');
}
protected function extendedFilterOptions() : array
{
return [
// empty for now
];
}
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
{
$catCondition = [];
$bind_types = [];
$bind_values = [];
return array( join(" ", $catCondition), $bind_types, $bind_values);
}
}

View File

@@ -0,0 +1,126 @@
<?php
namespace Hura8\Components\Marketing\Model;
use Hura8\Components\Product\AdminController\AProductController;
use Hura8\Interfaces\AppResponse;
use Hura8\System\IDGenerator;
use Hura8\System\Model\aEntityBaseModel;
class ProductFeedModel extends aEntityBaseModel
{
protected $tb_feed_product = "tb_feed_product";
public function __construct() {
parent::__construct('feed');
//$this->all_brands = $this->buildAllBrands();
//$this->all_categories = $this->buildAllCategories();
}
protected function extendedFilterOptions() : array
{
return [
// empty for now
];
}
public function getInfoByPublicId($public_id)
{
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `public_id` = ? LIMIT 1 ", ['s'], [$public_id]) ;
if( $item_info = $this->db->fetchAssoc($query)){
return $this->formatItemInfo($item_info);
}
return false;
}
public function getProductListTotal($list_id) {
$query = $this->db->runQuery(
" SELECT COUNT(*) AS total FROM `".$this->tb_feed_product."` WHERE `list_id` = ? ",
['d'], [$list_id]
);
$total = 0;
if ($info = $this->db->fetchAssoc($query)) {
$total = $info['total'];
}
return $total;
}
public function getProductList($list_id, $page = 1, $numPerPage = 30) {
$query = $this->db->runQuery(
" SELECT `pro_id` FROM `".$this->tb_feed_product."`
WHERE `list_id` = ?
ORDER BY `id` DESC
LIMIT ".( ($page - 1) * $numPerPage ).", ".$numPerPage,
['d'], [$list_id]
);
$product_list_ids = array_map(function ($item) { return $item['pro_id'];}, $this->db->fetchAll($query));
$objAProductController = new AProductController();
$stt = ($page - 1) * $numPerPage;
$item_list = [];
foreach ($objAProductController->getListByIds($product_list_ids) as $_id => $info) {
$stt++;
$info["counter"] = $stt;
$item_list[] = $info;
}
return $item_list;
}
//--------------------
public function getAllCategories() {
return $this->all_categories;
}
public function getAllProductListIds( $list_id){
if(!$list_id) return [];
$query = $this->db->runQuery("SELECT `pro_id` FROM `".$this->tb_feed_product."` WHERE `list_id` = ? ", ['d'], [ $list_id ]);
$item_list = array();
foreach ( $this->db->fetchAll($query) as $rs ) {
$item_list[] = $rs['pro_id'];
}
return $item_list;
}
//--------------------
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
{
/*$condition = array(
"letter" => "",
);*/
$catCondition = [];
$bind_types = [];
$bind_values = [];
if(isset($filter_condition["letter"]) && strlen($filter_condition["letter"]) == 1){
$catCondition[] = " AND `letter` = ? ";
$bind_types[] = 's';
$bind_values[] = $filter_condition["letter"];
}
return array( join(" ", $catCondition), $bind_types, $bind_values);
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Hura8\Components\Marketing\Model;
class UProductFeedModel
{
}