search
This commit is contained in:
44
assets/script/RowExpand.js
Normal file
44
assets/script/RowExpand.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
const RowExpand = (function (){
|
||||||
|
|
||||||
|
const $status_expand_all = $("#js-row-expand-all");
|
||||||
|
|
||||||
|
let track_open_rows = [];
|
||||||
|
|
||||||
|
function open_child_row(child_class_name){
|
||||||
|
const $children = $(`.${child_class_name}`);
|
||||||
|
|
||||||
|
if(!track_open_rows.includes(child_class_name)) {
|
||||||
|
$children.css('display', 'table-row');
|
||||||
|
track_open_rows.push(child_class_name);
|
||||||
|
}else{
|
||||||
|
$children.css('display', 'none');
|
||||||
|
track_open_rows = [...Util.removeItemFromArray(track_open_rows, child_class_name)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function open_all_row(){
|
||||||
|
if(!track_open_rows.includes('expand_all')) {
|
||||||
|
$(".row").css('display', 'table-row');
|
||||||
|
track_open_rows.push('expand_all');
|
||||||
|
|
||||||
|
$status_expand_all.html("[-]");
|
||||||
|
|
||||||
|
}else{
|
||||||
|
// collapse all
|
||||||
|
$(".row").css('display', 'none');
|
||||||
|
// open only first parent
|
||||||
|
$(".parent_0").css('display', 'table-row');
|
||||||
|
|
||||||
|
track_open_rows = [];
|
||||||
|
|
||||||
|
$status_expand_all.html("[+]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
open_child: open_child_row,
|
||||||
|
open_all: open_all_row
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
@@ -39,6 +39,19 @@ input[type=number] {
|
|||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=date]::-webkit-calendar-picker-indicator {
|
||||||
|
background: transparent;
|
||||||
|
bottom: 0;
|
||||||
|
color: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
height: auto;
|
||||||
|
left: 0;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
color: #000;
|
color: #000;
|
||||||
font-family: "Inter", sans-serif;
|
font-family: "Inter", sans-serif;
|
||||||
@@ -353,7 +366,7 @@ a {
|
|||||||
height: 41px;
|
height: 41px;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.admin-menu .item:nth-child(n+13) .sub-menu {
|
.admin-menu .item:nth-child(n+10) .sub-menu {
|
||||||
top: unset;
|
top: unset;
|
||||||
}
|
}
|
||||||
.admin-menu .sub-menu {
|
.admin-menu .sub-menu {
|
||||||
@@ -808,6 +821,14 @@ input[type=radio]:focus:before {
|
|||||||
background-position: -145px -82px;
|
background-position: -145px -82px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.order-detail-page .icon-edit {
|
||||||
|
border: transparent;
|
||||||
|
background-color: transparent;
|
||||||
|
margin: 0;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
.is-close-btn {
|
.is-close-btn {
|
||||||
background: #ececec !important;
|
background: #ececec !important;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
@@ -859,6 +880,10 @@ input[type=radio]:focus:before {
|
|||||||
content: none;
|
content: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.marketing-coupon-page .order-page-table td {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
.table-brand th {
|
.table-brand th {
|
||||||
padding: 7px 5px;
|
padding: 7px 5px;
|
||||||
background: #f6f6f6;
|
background: #f6f6f6;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -32,6 +32,18 @@ input::-webkit-inner-spin-button {
|
|||||||
input[type="number"] {
|
input[type="number"] {
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
|
input[type='date']::-webkit-calendar-picker-indicator {
|
||||||
|
background: transparent;
|
||||||
|
bottom: 0;
|
||||||
|
color: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
height: auto;
|
||||||
|
left: 0;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
body {
|
body {
|
||||||
color: #000;
|
color: #000;
|
||||||
font-family: "Inter", sans-serif;
|
font-family: "Inter", sans-serif;
|
||||||
@@ -340,7 +352,7 @@ a {
|
|||||||
height: 41px;
|
height: 41px;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
&:nth-child(n + 13) {
|
&:nth-child(n + 10) {
|
||||||
.sub-menu {
|
.sub-menu {
|
||||||
top: unset;
|
top: unset;
|
||||||
}
|
}
|
||||||
@@ -827,6 +839,15 @@ input[type="radio"] {
|
|||||||
background-position: -145px -82px;
|
background-position: -145px -82px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.order-detail-page{
|
||||||
|
.icon-edit {
|
||||||
|
border: transparent;
|
||||||
|
background-color: transparent;
|
||||||
|
margin: 0;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
}
|
||||||
.is-close-btn {
|
.is-close-btn {
|
||||||
background: #ececec !important;
|
background: #ececec !important;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
@@ -877,6 +898,11 @@ input[type="radio"] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.marketing-coupon-page {
|
||||||
|
.order-page-table td {
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.table-brand {
|
.table-brand {
|
||||||
th {
|
th {
|
||||||
|
|||||||
@@ -1,17 +1,55 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return _get_order_list();
|
|
||||||
|
|
||||||
// helpers
|
use Hura8\Components\Order\AdminController\AOrderController;
|
||||||
function _get_order_list() {
|
use Hura8\Components\Order\Controller\OrderStatus;
|
||||||
$main_items = [
|
use Hura8\System\Paging;
|
||||||
'detail_new',
|
|
||||||
|
$numPerPage = 30;
|
||||||
|
|
||||||
|
$conditions = array(
|
||||||
|
'orderCode' => getRequest('orderCode', ''),
|
||||||
|
'q' => getRequest('q', ''),
|
||||||
|
//'coupon' => getRequest('coupon', ''),
|
||||||
|
'cus_id' => getRequest('cus_id', ''),
|
||||||
|
'province' => getRequest('province', ''),
|
||||||
|
//'district' => getRequest('district', ''),
|
||||||
|
'folder' => getRequest('folder', ''),
|
||||||
|
'view_status' => getRequest('view_status', ''),
|
||||||
|
'update_by' => getRequest('update_by', ''),
|
||||||
|
//'shipping_status' => getRequest('shipping_status', ''),
|
||||||
|
'assign_to' => getRequest('assign_to', ''),
|
||||||
|
'from_date' => getRequest('from_date', ''),
|
||||||
|
'to_date' => getRequest('to_date', ''),
|
||||||
|
//'from_hour' => getRequest('from_hour', ''),
|
||||||
|
//'to_hour' => getRequest('to_hour', ''),
|
||||||
|
'payment' => getRequest('payment', ''),
|
||||||
|
'fullfillment' => getRequest('fullfillment', ''),
|
||||||
|
'status' => getRequest('status', ''),
|
||||||
|
//'excluded_ids' => getRequest('', ''),
|
||||||
|
//'included_ids' => getRequest('', ''),
|
||||||
|
'list' => getRequest('list', ''),
|
||||||
|
'numPerPage' => $numPerPage,
|
||||||
|
'page' => getPageId(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$objAOrderController = new AOrderController();
|
||||||
|
$totalResults = $objAOrderController->getTotal($conditions);
|
||||||
|
$item_list = $objAOrderController->getList($conditions);
|
||||||
|
|
||||||
|
debug_var($item_list);
|
||||||
|
|
||||||
|
list($page_collection, $tb_page, $total_pages) = Paging::paging_template($totalResults, $numPerPage);
|
||||||
|
|
||||||
|
return [
|
||||||
|
"total" => $totalResults,
|
||||||
|
"item_list" => $item_list,
|
||||||
|
"pagination" => [
|
||||||
|
'collection' => $page_collection,
|
||||||
|
'html' => $tb_page,
|
||||||
|
'total_pages' => $total_pages,
|
||||||
|
],
|
||||||
|
"order_status_list" => OrderStatus::ORDER_STATUS ,
|
||||||
|
"payment_status_list" => OrderStatus::PAYMENT_STATUS,
|
||||||
|
"fullfillment_status_list" => OrderStatus::FULFILLMENT_STATUS ,
|
||||||
];
|
];
|
||||||
|
|
||||||
$menu_list = [];
|
|
||||||
foreach ($main_items as $item) {
|
|
||||||
$menu_list[$item] = include_once __DIR__."/".$item.".php";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $menu_list;
|
|
||||||
}
|
|
||||||
|
|||||||
102
data/product/category.php
Normal file
102
data/product/category.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Hura8\Components\Product\AdminController\AProductCategoryController;
|
||||||
|
|
||||||
|
$objAProductCategoryController = new AProductCategoryController();
|
||||||
|
|
||||||
|
$category_collection = $objAProductCategoryController->getAllParent();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'category_list' => get_category_list(0, getRequest("id"), $level=1, $prefix="", $category_collection )
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
function get_category_list($parentId=0, $currentCat="",$level=1, $prefix="", $category_collection = array()){
|
||||||
|
|
||||||
|
$categoryTree = "";
|
||||||
|
$extra_space = "";
|
||||||
|
for($i = 1; $i < $level; $i++){
|
||||||
|
$extra_space .= " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$stt = 0;
|
||||||
|
if(isset($category_collection[$parentId])) {
|
||||||
|
|
||||||
|
foreach($category_collection[$parentId] as $index => $cat_info){
|
||||||
|
$cat_id = $cat_info['id'];
|
||||||
|
|
||||||
|
$stt ++;
|
||||||
|
$imgUrl = (strlen($cat_info["thumbnail"]) > 2) ? " <img src=\"".$cat_info["thumbnail"]."\" style=\"max-width:30px; max-height:30px;\" />" : "";
|
||||||
|
|
||||||
|
if($cat_info["status"]) $status = "<a href=\"javascript:update_status(".$cat_id.",'off')\">Hạ xuống</a>";
|
||||||
|
else $status = "<a href=\"javascript:update_status(".$cat_id.",'on')\" style=\"background-color:#FFCC00;\">Hiển thị</a>";
|
||||||
|
|
||||||
|
$edit_link ="/admin/product/category-form?id=".$cat_id;
|
||||||
|
|
||||||
|
$hide_this = ($parentId > 0) ? "style='display: none;'" : '';
|
||||||
|
|
||||||
|
$show_category_name = $cat_info["title"];
|
||||||
|
|
||||||
|
if(!IS_DEFAULT_LANGUAGE && isset($cat_info["not_translated"]) && $cat_info["not_translated"]) {
|
||||||
|
$show_category_name = "<span style='color: red'>[Chưa dịch]</span> ".$cat_info["title"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($cat_info['is_parent']) {
|
||||||
|
$show_category_name = "<a href=\"javascript:;\" onclick=\"RowExpand.open_child('parent_".$cat_id."')\">".$show_category_name."</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$categoryTree .= "
|
||||||
|
<tr id='row_".$cat_id."' class='parent_".$parentId." row' ". $hide_this ."
|
||||||
|
onmouseover=\"this.className='row-hover parent_".$parentId."'\" onmouseout=\"this.className='parent_".$parentId."'\">
|
||||||
|
|
||||||
|
<td>".$cat_id."</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<a name='cat_".$cat_id."'></a>
|
||||||
|
". $extra_space . $prefix . $stt.". ". $show_category_name . $imgUrl."
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>".$cat_info['item_count']." - <a href='/admin/product?category=".$cat_id."'>Xem</a></td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<a href='".$cat_info['request_path']."' title='Mở tại website' target='_blank'>Web</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<input type=text id=order_".$cat_id." value='".$cat_info["ordering"]."' size=2 onchange=\"update_order(".$cat_id.",this.value)\" />
|
||||||
|
<span class='status-ordering-".$cat_id."'></span>
|
||||||
|
</td>
|
||||||
|
";
|
||||||
|
|
||||||
|
if(IS_DEFAULT_LANGUAGE) {
|
||||||
|
$categoryTree .= "
|
||||||
|
<td>
|
||||||
|
<a href='/admin/product/category-attribute?id=".$cat_id."&popup=1' class='pop-up'>Thuộc tính</a> (".$cat_info['attribute_count'].")
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span id=status-".$cat_id.">".$status."</span> |
|
||||||
|
<a href=\"".$edit_link."\">Sửa lại</a> |
|
||||||
|
<span class='status-delete-".$cat_id."'><a href=\"javascript:deleteThis(".$cat_id.")\">Xóa</a></span>
|
||||||
|
</td>
|
||||||
|
";
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$categoryTree .= "
|
||||||
|
<td>
|
||||||
|
<a href=\"".$edit_link."\">Sửa lại</a>
|
||||||
|
</td>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
$categoryTree .= "
|
||||||
|
</tr>
|
||||||
|
";
|
||||||
|
|
||||||
|
if($cat_info["is_parent"]) $categoryTree .= get_category_list($cat_id, $currentCat, $level + 1, $prefix . $stt.".", $category_collection);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $categoryTree;
|
||||||
|
}
|
||||||
|
|
||||||
18
data/product/category_form.php
Normal file
18
data/product/category_form.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Components\Product\AdminController\AProductCategoryController;
|
||||||
|
|
||||||
|
$objAProductCategoryController = new AProductCategoryController();
|
||||||
|
|
||||||
|
|
||||||
|
$id = (int) getRequest("id");
|
||||||
|
$item_info = ($id > 0) ? $objAProductCategoryController->getFullInfo($id) : null;
|
||||||
|
if(!$item_info) $item_info = $objAProductCategoryController->getEmptyInfo([]);
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
'item_info' => $item_info,
|
||||||
|
'categoryDropBox' => $objAProductCategoryController->getDropBox( $item_info['parent_id'], 0, 1),
|
||||||
|
'update_status' => getRequest("us"),
|
||||||
|
];
|
||||||
@@ -13,6 +13,7 @@ class AppAdmin
|
|||||||
protected $current_route_info = [
|
protected $current_route_info = [
|
||||||
"module" => 'home',
|
"module" => 'home',
|
||||||
"view" => 'home',
|
"view" => 'home',
|
||||||
|
"url" => '/admin/product'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $data = [];
|
protected $data = [];
|
||||||
@@ -56,6 +57,7 @@ class AppAdmin
|
|||||||
$global_data = [
|
$global_data = [
|
||||||
"module" => $this->current_route_info['module'],
|
"module" => $this->current_route_info['module'],
|
||||||
"view" => $this->current_route_info['view'],
|
"view" => $this->current_route_info['view'],
|
||||||
|
"url" => $this->current_route_info['url'],
|
||||||
"main_menu" => include_once ROOT_DIR."/data/menu.php",
|
"main_menu" => include_once ROOT_DIR."/data/menu.php",
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -83,7 +85,7 @@ class AppAdmin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$template_file_path = $this->tpl_path ."/". $this->current_route_info['module'];
|
$template_file_path = $this->tpl_path ."/". $this->current_route_info['module'];
|
||||||
$template_file_name = $this->current_route_info['view'].".html";
|
$template_file_name = str_replace("-", '_', $this->current_route_info['view']).".html";
|
||||||
$template_file_full_path = $template_file_path."/".$template_file_name;
|
$template_file_full_path = $template_file_path."/".$template_file_name;
|
||||||
|
|
||||||
//check exist
|
//check exist
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Analytics\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Analytics\Model\TrackingModel;
|
||||||
|
|
||||||
|
class bTrackingController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $objTrackingModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objTrackingModel = new TrackingModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
inc/Hura8/Components/Analytics/Model/TrackDeviceInfo.php
Normal file
19
inc/Hura8/Components/Analytics/Model/TrackDeviceInfo.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Analytics\Model;
|
||||||
|
|
||||||
|
class TrackDeviceInfo
|
||||||
|
{
|
||||||
|
public $ip_address;
|
||||||
|
public $user_agent;
|
||||||
|
public $referrer;
|
||||||
|
public $is_mobile;
|
||||||
|
|
||||||
|
public function __construct(string $ip_address, string $user_agent, string $referrer, bool $is_mobile)
|
||||||
|
{
|
||||||
|
$this->ip_address = $ip_address;
|
||||||
|
$this->user_agent = $user_agent;
|
||||||
|
$this->referrer = $referrer;
|
||||||
|
$this->is_mobile = $is_mobile;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
inc/Hura8/Components/Analytics/Model/TrackRouteInfo.php
Normal file
28
inc/Hura8/Components/Analytics/Model/TrackRouteInfo.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Analytics\Model;
|
||||||
|
|
||||||
|
class TrackRouteInfo
|
||||||
|
{
|
||||||
|
public $url;
|
||||||
|
public $module;
|
||||||
|
public $view;
|
||||||
|
public $view_id;
|
||||||
|
public $query;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
string $url,
|
||||||
|
string $module,
|
||||||
|
string $view,
|
||||||
|
string $view_id,
|
||||||
|
array $query = []
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
$this->module = $module;
|
||||||
|
$this->view = $view;
|
||||||
|
$this->view_id = $view_id;
|
||||||
|
$this->query = $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
inc/Hura8/Components/Analytics/Model/TrackUserInfo.php
Normal file
19
inc/Hura8/Components/Analytics/Model/TrackUserInfo.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Analytics\Model;
|
||||||
|
|
||||||
|
class TrackUserInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public $web_user_id;
|
||||||
|
public $customer_id;
|
||||||
|
public $is_crawler;
|
||||||
|
|
||||||
|
public function __construct(string $web_user_id, string $customer_id, bool $is_crawler)
|
||||||
|
{
|
||||||
|
$this->web_user_id = $web_user_id;
|
||||||
|
$this->customer_id = $customer_id;
|
||||||
|
$this->is_crawler = $is_crawler ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
inc/Hura8/Components/Analytics/Model/TrackingModel.php
Normal file
32
inc/Hura8/Components/Analytics/Model/TrackingModel.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Analytics\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
|
||||||
|
class TrackingModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_track_ip = "tb_analyics_track_ip";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(
|
||||||
|
"analyics_user_log"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions(): array
|
||||||
|
{
|
||||||
|
// TODO: Implement extendedFilterOptions() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition): ?array
|
||||||
|
{
|
||||||
|
// TODO: Implement _buildQueryConditionExtend() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Article\Controller\bArticleCategoryController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminCategoryController;
|
||||||
|
use Hura8\Traits\AdminEntityCategoryControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class AArticleCategoryController extends bArticleCategoryController implements iEntityAdminCategoryController
|
||||||
|
{
|
||||||
|
use AdminEntityCategoryControllerTraits;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Article\Controller\bArticleController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class AArticleController extends bArticleController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
public function updateTableInfo($item_id, array $new_item_info) {
|
||||||
|
if(!$this->isDefaultLanguage()) {
|
||||||
|
return $this->iEntityLanguageModel->update($item_id, $new_item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->objArticleModel->updateTableInfo($item_id, $new_item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Article\Model\ArticleCategoryLanguageModel;
|
||||||
|
use Hura8\Components\Article\Model\ArticleCategoryModel;
|
||||||
|
use Hura8\System\Controller\aCategoryBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class bArticleCategoryController extends aCategoryBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var ArticleCategoryModel $objArticleCategoryModel */
|
||||||
|
protected $objArticleCategoryModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objArticleCategoryModel = new ArticleCategoryModel();
|
||||||
|
|
||||||
|
if(!$this->isDefaultLanguage()) {
|
||||||
|
|
||||||
|
parent::__construct(
|
||||||
|
$this->objArticleCategoryModel,
|
||||||
|
new ArticleCategoryLanguageModel()
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
parent::__construct($this->objArticleCategoryModel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Components\Article\Model\ArticleLanguageModel;
|
||||||
|
use Hura8\Components\Article\Model\ArticleModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
class bArticleController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
static $image_folder = "media/article";
|
||||||
|
|
||||||
|
static $resized_sizes = array(
|
||||||
|
't' => ['width' => 200,] ,
|
||||||
|
'l' => ['width' => 600,] ,
|
||||||
|
);
|
||||||
|
|
||||||
|
/* @var ArticleModel $objArticleModel */
|
||||||
|
protected $objArticleModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objArticleModel = new ArticleModel();
|
||||||
|
|
||||||
|
if(!$this->isDefaultLanguage()) {
|
||||||
|
parent::__construct(
|
||||||
|
$this->objArticleModel,
|
||||||
|
new ArticleLanguageModel()
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
parent::__construct($this->objArticleModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getFullInfo($id)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!$id) return null;
|
||||||
|
|
||||||
|
return self::getCache("getFullInfo-".$id."-".$this->view_language, function () use ($id){
|
||||||
|
|
||||||
|
$info = $this->objArticleModel->getFullInfo($id);
|
||||||
|
|
||||||
|
if($this->iEntityLanguageModel && $info ) {
|
||||||
|
$item_language_info = $this->iEntityLanguageModel->getInfo($id) ?? ["not_translated" => true];
|
||||||
|
return $this->formatItemInfo(array_merge($info, $item_language_info));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($info) ? $this->formatItemInfo($info) : null;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info)
|
||||||
|
{
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info)
|
||||||
|
{
|
||||||
|
if(!$item_info) return null;
|
||||||
|
|
||||||
|
$info = $item_info;
|
||||||
|
$info['image'] = self::getResizedImageCollection($info['thumbnail']);
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getResizedImageCollection($image_name) {
|
||||||
|
$image = [];
|
||||||
|
|
||||||
|
$size_in_full = [
|
||||||
|
't' => 'thumb' ,
|
||||||
|
's' => 'small' ,
|
||||||
|
'l' => 'large' ,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$image[$size_in_full[$size]] = ($image_name) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $image_name : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\System\Model\EntityLanguageModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
|
||||||
|
class ArticleCategoryLanguageModel extends EntityLanguageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $richtext_fields = [
|
||||||
|
'description',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::ARTICLE_CATEGORY, '', $this->richtext_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
inc/Hura8/Components/Article/Model/ArticleCategoryModel.php
Normal file
33
inc/Hura8/Components/Article/Model/ArticleCategoryModel.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\System\Model\aCategoryBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityCategoryModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
|
||||||
|
class ArticleCategoryModel extends aCategoryBaseModel implements iEntityCategoryModel
|
||||||
|
{
|
||||||
|
|
||||||
|
static $url_module = "article";
|
||||||
|
static $url_view = "category";
|
||||||
|
static $url_type = "article:category";
|
||||||
|
|
||||||
|
protected $tb_article_per_category = "tb_article_per_category";
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::ARTICLE_CATEGORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
inc/Hura8/Components/Article/Model/ArticleLanguageModel.php
Normal file
19
inc/Hura8/Components/Article/Model/ArticleLanguageModel.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Model\EntityLanguageModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
class ArticleLanguageModel extends EntityLanguageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $richtext_fields = [
|
||||||
|
'description',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::ARTICLE, '', $this->richtext_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
150
inc/Hura8/Components/Article/Model/ArticleModel.php
Normal file
150
inc/Hura8/Components/Article/Model/ArticleModel.php
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Controller\UrlManagerController;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\System\ModuleManager;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
|
||||||
|
class ArticleModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
static $url_type = "article:detail";
|
||||||
|
|
||||||
|
protected $tb_article_info = "tb_article_info";
|
||||||
|
protected $tb_article_per_category = 'tb_article_per_category';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(
|
||||||
|
EntityType::ARTICLE,
|
||||||
|
"",
|
||||||
|
new ArticleSearchModel()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getFullInfo($id) : ?array
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT * FROM `".$this->tb_entity."` basic, `".$this->tb_article_info."` info
|
||||||
|
WHERE basic.`id` = info.`article_id` AND basic.id = ?
|
||||||
|
LIMIT 1 ",
|
||||||
|
['d'], [$id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if( $item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
"category" => getRequestInt("category"),
|
||||||
|
"no_image" => 0,//1
|
||||||
|
);*/
|
||||||
|
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
//Tim danh muc
|
||||||
|
if(isset($filter_condition["category"]) && $filter_condition["category"]) {
|
||||||
|
|
||||||
|
$objArticleCategoryModel = new ArticleCategoryModel();
|
||||||
|
$category_info = $objArticleCategoryModel->getInfo($filter_condition["category"]);
|
||||||
|
|
||||||
|
if($category_info) {
|
||||||
|
if($category_info['is_parent']) {
|
||||||
|
$catCondition[] = " AND `id` IN (SELECT `item_id` FROM `".$this->tb_article_per_category."` WHERE `category_id` IN (".$category_info['child_ids'].") ) ";
|
||||||
|
//$bind_types[] = 'd';
|
||||||
|
//$bind_values[] = $filter_condition["category"];
|
||||||
|
}else{
|
||||||
|
$catCondition[] = " AND `id` IN (SELECT `item_id` FROM `".$this->tb_article_per_category."` WHERE `category_id` = ? ) ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition["category"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function addArticleToCategory($item_id, array $category_list_id) {
|
||||||
|
$this->db->runQuery("DELETE FROM `".$this->tb_article_per_category."` WHERE `item_id` = ? ", ['d'], [$item_id]);
|
||||||
|
|
||||||
|
$bulk_inserts = [];
|
||||||
|
foreach($category_list_id as $cat_id) {
|
||||||
|
if (! $cat_id) continue;
|
||||||
|
|
||||||
|
$bulk_inserts[] = [
|
||||||
|
'category_id' => $cat_id,
|
||||||
|
'item_id' => $item_id,
|
||||||
|
'status' => 1,
|
||||||
|
'create_time' => CURRENT_TIME,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sizeof($bulk_inserts)) {
|
||||||
|
$this->db->bulk_insert($this->tb_article_per_category, $bulk_inserts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update counter
|
||||||
|
$objArticleCategoryModel = new ArticleCategoryModel();
|
||||||
|
foreach($category_list_id as $cat_id) {
|
||||||
|
$objArticleCategoryModel->updateItemCount($cat_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateUrl($id, $url_index): bool
|
||||||
|
{
|
||||||
|
|
||||||
|
$module_routing = ModuleManager::getModuleRouting("article");
|
||||||
|
$request_path_config = isset($module_routing["detail"]) ? $module_routing["detail"]['url_manager']['request_path'] : '';
|
||||||
|
|
||||||
|
if(!$request_path_config) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request_path = UrlManagerController::translateRequestPathConfig($request_path_config, $id, $url_index);
|
||||||
|
$id_path = UrlManagerController::createIdPath("article", "detail", $id);
|
||||||
|
|
||||||
|
$objUrlManager = new UrlManagerController();
|
||||||
|
$new_request_path = $objUrlManager->createUrl("article:detail", $request_path, $id_path, 0);
|
||||||
|
|
||||||
|
if($new_request_path) {
|
||||||
|
$this->db->update(
|
||||||
|
$this->tb_entity,
|
||||||
|
[
|
||||||
|
'request_path' => $new_request_path,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => $id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
29
inc/Hura8/Components/Article/Model/ArticleSearchModel.php
Normal file
29
inc/Hura8/Components/Article/Model/ArticleSearchModel.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\Model\aSearchBaseModel;
|
||||||
|
|
||||||
|
class ArticleSearchModel extends aSearchBaseModel implements iSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
private $filter_fields = [
|
||||||
|
"status"=> "tb_article.status",
|
||||||
|
];
|
||||||
|
|
||||||
|
private $fulltext_fields = [
|
||||||
|
"keywords" => ["tb_article.title", ],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
"tb_article",
|
||||||
|
$this->fulltext_fields,
|
||||||
|
$this->filter_fields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
55
inc/Hura8/Components/Article/Model/UArticleModel.php
Normal file
55
inc/Hura8/Components/Article/Model/UArticleModel.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Article\Model;
|
||||||
|
|
||||||
|
class UArticleModel extends ArticleModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getSameCategoryArticle($main_id, $category_id){
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
(
|
||||||
|
SELECT `item_id`
|
||||||
|
FROM ".$this->tb_article_per_category."
|
||||||
|
WHERE `category_id` = ? AND `status`=1 AND `item_id` > ?
|
||||||
|
ORDER BY `item_id` DESC
|
||||||
|
LIMIT 10
|
||||||
|
|
||||||
|
) UNION ALL (
|
||||||
|
SELECT `item_id`
|
||||||
|
FROM ".$this->tb_article_per_category."
|
||||||
|
WHERE `category_id` = ? AND `status`=1 AND `item_id` < ?
|
||||||
|
ORDER BY `item_id` DESC
|
||||||
|
LIMIT 10
|
||||||
|
)
|
||||||
|
",
|
||||||
|
['d', 'd', 'd', 'd'],
|
||||||
|
[$category_id, $main_id, $category_id, $main_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$article_list_id = [];
|
||||||
|
$article_item_info = array();
|
||||||
|
$article_item = [];
|
||||||
|
|
||||||
|
foreach ( $this->db->fetchAll($query) as $rs ) {
|
||||||
|
if(!isset($article_item_info[$rs["item_id"]])) $article_item_info[$rs["item_id"]] = array();
|
||||||
|
if(!in_array($rs["item_id"], $article_list_id)) $article_list_id[] = $rs["item_id"];
|
||||||
|
|
||||||
|
if($rs["item_id"] > $main_id) {
|
||||||
|
$article_item['new'][$rs["item_id"]] = &$article_item_info[$rs["item_id"]];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$article_item['old'][$rs["item_id"]] = &$article_item_info[$rs["item_id"]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$list_article_info = $this->getListByIds($article_list_id);
|
||||||
|
foreach ($article_list_id as $_id) {
|
||||||
|
if(isset($list_article_info[$_id])) $article_item_info[$_id] = $list_article_info[$_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $article_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Banner\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Banner\Controller\bBannerController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class ABannerController extends bBannerController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Banner\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Banner\Model\BannerLocationModel;
|
||||||
|
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class ABannerLocationController extends aAdminEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(new BannerLocationModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplateBanner() {
|
||||||
|
return ABannerController::$template_banners;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
67
inc/Hura8/Components/Banner/Controller/bBannerController.php
Normal file
67
inc/Hura8/Components/Banner/Controller/bBannerController.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Banner\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Banner\Model\BannerLocationModel;
|
||||||
|
use Hura8\Components\Banner\Model\BannerModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
class bBannerController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
static $image_folder = "media/banner";
|
||||||
|
|
||||||
|
static $template_banners = array(
|
||||||
|
//"index" => "Toàn bộ website" ,
|
||||||
|
"header" => "Đầu trang" ,
|
||||||
|
"homepage" => "Trang chủ" ,
|
||||||
|
"column_left" => "Cột trái" ,
|
||||||
|
"column_right" => "Cột phải" ,
|
||||||
|
"footer" => "Chân trang" ,
|
||||||
|
"product_detail"=> "Chi tiết sản phẩm" ,
|
||||||
|
"product_list" => "Danh sách & Danh mục sản phẩm" ,
|
||||||
|
"collection_list" => "Bộ sưu tập" ,
|
||||||
|
"article_home" => "Trang chủ tin tức" ,
|
||||||
|
"brand_detail" => "Chi tiết thương hiệu",
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
protected $objBannerModel;
|
||||||
|
protected $objBannerLocationModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objBannerModel = new BannerModel();
|
||||||
|
$this->objBannerLocationModel = new BannerLocationModel();
|
||||||
|
|
||||||
|
parent::__construct($this->objBannerModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info)
|
||||||
|
{
|
||||||
|
return self::formatFile($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info)
|
||||||
|
{
|
||||||
|
return self::formatFile($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function formatFile(array $item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
if($item_info['file_url']) {
|
||||||
|
$item_info['display_file'] = STATIC_DOMAIN ."/". static::$image_folder ."/". $item_info['file_url'];
|
||||||
|
}else if($item_info['file_external_url']) {
|
||||||
|
$item_info['display_file'] = $item_info['file_external_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$item_info['html_code'] = "<a href=\"/ad.php?id=".$item_info['tracking_id']."\" target='_blank' rel='nofollow'><img border='0' src=\"".$item_info['display_file']."\" alt=\"".htmlspecialchars($item_info['title'])."\" /></a>";
|
||||||
|
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
30
inc/Hura8/Components/Banner/Model/BannerLocationModel.php
Normal file
30
inc/Hura8/Components/Banner/Model/BannerLocationModel.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Banner\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\System\Security\DataClean;
|
||||||
|
use Hura8\System\Security\DataType;
|
||||||
|
|
||||||
|
|
||||||
|
class BannerLocationModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::BANNER_LOCATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function extendedFilterOptions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
90
inc/Hura8/Components/Banner/Model/BannerModel.php
Normal file
90
inc/Hura8/Components/Banner/Model/BannerModel.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Banner\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
|
||||||
|
class BannerModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_banner_location = "tb_banner_location";
|
||||||
|
protected $tb_banner_per_category = "tb_banner_per_category";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(
|
||||||
|
EntityType::BANNER, "", new BannerSearchModel()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfoByTrackingId($tracking_id)
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `tracking_id` = ? LIMIT 1 ", ['s'], [$tracking_id]) ;
|
||||||
|
if( $item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBannerPerTemplate(array $template_list, $numberOfBannerPerTpl=100){
|
||||||
|
|
||||||
|
$all_bind_types = [];
|
||||||
|
$all_bind_values = [];
|
||||||
|
|
||||||
|
$view_id = 0;
|
||||||
|
|
||||||
|
$build_query = [];
|
||||||
|
foreach($template_list as $tpl) {
|
||||||
|
|
||||||
|
list($where_condition, $bind_types, $bind_values) = $this->buildQueryPerTpl($tpl, $view_id, $numberOfBannerPerTpl);
|
||||||
|
|
||||||
|
$build_query[] = " (".$where_condition.") ";
|
||||||
|
$all_bind_types = array_merge($all_bind_types, $bind_types);
|
||||||
|
$all_bind_values = array_merge($all_bind_values, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sizeof($build_query)) return [];
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(join(" UNION ALL ", $build_query), $all_bind_types, $all_bind_values);
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
[location] => 2
|
||||||
|
[category] => 0
|
||||||
|
);*/
|
||||||
|
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
if(isset($filter_condition['location']) && $filter_condition['location']) {
|
||||||
|
$catCondition[] = " AND `location` = ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition['location'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($filter_condition['category']) && $filter_condition['category']) {
|
||||||
|
$catCondition[] = " AND `id` IN ( SELECT `banner_id` FROM `".$this->tb_banner_per_category."` WHERE `category_id` = ? ) ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition['category'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
33
inc/Hura8/Components/Banner/Model/BannerSearchModel.php
Normal file
33
inc/Hura8/Components/Banner/Model/BannerSearchModel.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Banner\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\Model\aSearchBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class BannerSearchModel extends aSearchBaseModel implements iSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
private $filter_fields = [
|
||||||
|
"location" => "tb_banner.location",
|
||||||
|
"status" => "tb_banner.status",
|
||||||
|
];
|
||||||
|
|
||||||
|
private $fulltext_fields = [
|
||||||
|
"keywords" => ["tb_banner.title",],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
"tb_banner",
|
||||||
|
$this->fulltext_fields,
|
||||||
|
$this->filter_fields
|
||||||
|
);
|
||||||
|
|
||||||
|
//$this->createTableSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Brand\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Brand\Controller\bBrandController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class ABrandController extends bBrandController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
public function getGroupByFirstLetter() {
|
||||||
|
return $this->objBrandModel->getGroupByFirstLetter();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
// delete thumb files
|
||||||
|
$item_info = $this->getInfo($item_id);
|
||||||
|
if($item_info['thumbnail']) {
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $item_info['thumbnail'];
|
||||||
|
unlink($file_local_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove original file
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $item_info['thumbnail'];
|
||||||
|
unlink($file_local_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
//delete media files?
|
||||||
|
// todo:
|
||||||
|
|
||||||
|
// ok
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
73
inc/Hura8/Components/Brand/Controller/bBrandController.php
Normal file
73
inc/Hura8/Components/Brand/Controller/bBrandController.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Brand\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Brand\Model\BrandLanguageModel;
|
||||||
|
use Hura8\Components\Brand\Model\BrandModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class bBrandController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
static $image_folder = "media/brand";
|
||||||
|
|
||||||
|
static $resized_sizes = array(
|
||||||
|
's' => ['width' => 200,] ,
|
||||||
|
);
|
||||||
|
|
||||||
|
/* @var BrandModel $objBrandModel */
|
||||||
|
protected $objBrandModel;
|
||||||
|
/* @var BrandLanguageModel $objBrandLanguageModel */
|
||||||
|
protected $objBrandLanguageModel;
|
||||||
|
protected $view_language = '';
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objBrandModel = new BrandModel();
|
||||||
|
|
||||||
|
if(!$this->isDefaultLanguage()) {
|
||||||
|
$this->objBrandLanguageModel = new BrandLanguageModel();
|
||||||
|
//$this->objVideoLanguageModel->createTableLang();
|
||||||
|
parent::__construct($this->objBrandModel, $this->objBrandLanguageModel);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
parent::__construct($this->objBrandModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfoByUrl(string $band_index) : ?array
|
||||||
|
{
|
||||||
|
return $this->objBrandModel->getInfoByUrl($band_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info) : array
|
||||||
|
{
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info) : ?array
|
||||||
|
{
|
||||||
|
if(!$item_info) return null;
|
||||||
|
|
||||||
|
$info = static::formatItemImage($item_info);
|
||||||
|
|
||||||
|
$info['url'] = "/brand/".$info['brand_index'];
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function formatItemImage(array $item_info) {
|
||||||
|
$info = $item_info;
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$info['image'][$size] = ($info['thumbnail']) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $info['thumbnail'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
inc/Hura8/Components/Brand/Model/BrandLanguageModel.php
Normal file
19
inc/Hura8/Components/Brand/Model/BrandLanguageModel.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Brand\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Model\EntityLanguageModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
class BrandLanguageModel extends EntityLanguageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $richtext_fields = [
|
||||||
|
'description',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::BRAND, '', $this->richtext_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
72
inc/Hura8/Components/Brand/Model/BrandModel.php
Normal file
72
inc/Hura8/Components/Brand/Model/BrandModel.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Brand\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Config;
|
||||||
|
use Hura8\System\Controller\UrlManagerController;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\Interfaces\TableName;
|
||||||
|
|
||||||
|
|
||||||
|
class BrandModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
static $url_type = "brand:detail";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::BRAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getGroupByFirstLetter() {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `letter`, COUNT(*) AS item_count FROM `".$this->tb_entity."` GROUP BY `letter` ORDER BY `letter` ASC "
|
||||||
|
);
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfoByUrl($brand_index) : ?array
|
||||||
|
{
|
||||||
|
$brand_index = preg_replace("/[^a-z0-9\.\-\_]/i", '', $brand_index);
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `brand_index` = ? LIMIT 1 ", ['s'], [$brand_index]);
|
||||||
|
if($item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ComboSet\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\ComboSet\Controller\bComboSetController;
|
||||||
|
use Hura8\Components\Product\AdminController\AProductController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
class AComboSetController extends bComboSetController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
}
|
||||||
148
inc/Hura8/Components/ComboSet/Controller/bComboSetController.php
Normal file
148
inc/Hura8/Components/ComboSet/Controller/bComboSetController.php
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ComboSet\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\ComboSet\Model\ComboSetLanguageModel;
|
||||||
|
use Hura8\Components\ComboSet\Model\ComboSetModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
class bComboSetController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
/* @var ComboSetModel $objComboSetModel */
|
||||||
|
protected $objComboSetModel;
|
||||||
|
|
||||||
|
/* @var ComboSetLanguageModel $objComboSetLanguageModel */
|
||||||
|
protected $objComboSetLanguageModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objComboSetModel = new ComboSetModel();
|
||||||
|
|
||||||
|
if(!$this->isDefaultLanguage()) {
|
||||||
|
$this->objComboSetLanguageModel = new ComboSetLanguageModel();
|
||||||
|
//$this->objVideoLanguageModel->createTableLang();
|
||||||
|
parent::__construct($this->objComboSetModel, $this->objComboSetLanguageModel);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
parent::__construct($this->objComboSetModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getAllSetIdsForAProduct($product_id)
|
||||||
|
{
|
||||||
|
return $this->objComboSetModel->getAllSetIdsForAProduct($product_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTotalProductUseSet($set_id)
|
||||||
|
{
|
||||||
|
return $this->objComboSetModel->getTotalProductUseSet($set_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getListProductUseSet($set_id, $numPerPage)
|
||||||
|
{
|
||||||
|
return $this->objComboSetModel->getListProductUseSet($set_id, $numPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function getProductListInfoInConfig(array $category) {
|
||||||
|
$product_list_ids = [];
|
||||||
|
foreach ($category as $index => $_category_info) {
|
||||||
|
foreach ($_category_info['suggest_list'] as $_proindex => $_pro_info) {
|
||||||
|
$product_list_ids[] = $_pro_info['real_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_unique($product_list_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function buildConfig( $category, $product) {
|
||||||
|
|
||||||
|
$group_category = [];
|
||||||
|
|
||||||
|
foreach ($category as $category_index => $_category_info) {
|
||||||
|
$category_product = [];
|
||||||
|
foreach ($product[$category_index] as $product_index => $_product_info) {
|
||||||
|
//$_product_info['price'] = clean_price($_product_info['price']);
|
||||||
|
$category_product[] = $_product_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
$group_category[] = [
|
||||||
|
"title" => $_category_info['title'],
|
||||||
|
//"type" => "category",
|
||||||
|
//"real_id" => $_category_info['real_id'],
|
||||||
|
//"select_type" => $_category_info['select_type'],//checkbox|radio
|
||||||
|
"suggest_list" => $category_product,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $group_category;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function decomposeConfig($config) {
|
||||||
|
$tab = [];
|
||||||
|
$group = [];
|
||||||
|
$category = [];
|
||||||
|
$product = [];
|
||||||
|
|
||||||
|
$group_index = 0;
|
||||||
|
$category_index = 0;
|
||||||
|
$product_index = 0;
|
||||||
|
|
||||||
|
foreach ($config as $tab_index => $tab_info) {
|
||||||
|
//construct tab
|
||||||
|
$tab[$tab_index] = [
|
||||||
|
'title' => $tab_info['title'],
|
||||||
|
];
|
||||||
|
|
||||||
|
//construct group
|
||||||
|
foreach ($tab_info['child'] as $child_group) {
|
||||||
|
$group_index += 1;
|
||||||
|
|
||||||
|
$group[$tab_index][$group_index] = [
|
||||||
|
'title' => $child_group['title'],
|
||||||
|
];
|
||||||
|
|
||||||
|
//construct category
|
||||||
|
foreach ($child_group['child'] as $child_category) {
|
||||||
|
$category_index += 1;
|
||||||
|
|
||||||
|
$category[$group_index][$category_index] = [
|
||||||
|
'title' => $child_category['title'],
|
||||||
|
'real_id' => $child_category['real_id'],
|
||||||
|
'select_type' => $child_category['select_type'],
|
||||||
|
];
|
||||||
|
|
||||||
|
//construct product
|
||||||
|
foreach ($child_category['suggest_list'] as $child_product) {
|
||||||
|
$product_index += 1;
|
||||||
|
|
||||||
|
$product[$category_index][$product_index] = [
|
||||||
|
'title' => $child_product['title'],
|
||||||
|
'real_id' => $child_product['real_id'],
|
||||||
|
'is_default' => $child_product['is_default'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
"tab" => $tab,
|
||||||
|
"group" => $group,
|
||||||
|
'category' => $category,
|
||||||
|
'product' => $product,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ComboSet\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\System\Model\EntityLanguageModel;
|
||||||
|
|
||||||
|
|
||||||
|
class ComboSetLanguageModel extends EntityLanguageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct('combo_set');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
165
inc/Hura8/Components/ComboSet/Model/ComboSetModel.php
Normal file
165
inc/Hura8/Components/ComboSet/Model/ComboSetModel.php
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ComboSet\Model;
|
||||||
|
|
||||||
|
use Hura8\Components\Product\AdminController\AProductController;
|
||||||
|
use Hura8\Components\Product\Model\ProductSearchModel;
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class ComboSetModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_set_product = 'tb_combo_set_product';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct('combo_set');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getAllSetIdsForAProduct($product_id)
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
" SELECT `set_id` FROM ".$this->tb_set_product." WHERE `product_id` = ? ",
|
||||||
|
['d'], [$product_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$item_list = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
$item_list[] = $info['set_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTotalProductUseSet($set_id)
|
||||||
|
{
|
||||||
|
// search
|
||||||
|
$keyword = getRequest("q");
|
||||||
|
if($keyword) {
|
||||||
|
$search = new ProductSearchModel();
|
||||||
|
$match_result = $search->find($keyword);
|
||||||
|
$catCondition = (sizeof($match_result) > 0) ? " AND `product_id` IN (".join(",", $match_result).") " : " AND `product_id` = -1 ";
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
SELECT COUNT(product_id) AS total_product
|
||||||
|
FROM ".$this->tb_set_product."
|
||||||
|
WHERE `set_id` = ? " . $catCondition ."
|
||||||
|
", ['d'], [$set_id]);
|
||||||
|
|
||||||
|
if ($info = $this->db->fetchAssoc($query)) {
|
||||||
|
return $info['total_product'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$set_info = $this->getInfo($set_id);
|
||||||
|
|
||||||
|
return $set_info['product_count'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getListProductUseSet($set_id, $numPerPage)
|
||||||
|
{
|
||||||
|
$page = getPageId();
|
||||||
|
|
||||||
|
// search
|
||||||
|
$catCondition = "";
|
||||||
|
$keyword = getRequest("q");
|
||||||
|
if($keyword) {
|
||||||
|
$search = new ProductSearchModel();
|
||||||
|
$match_result = $search->find($keyword);
|
||||||
|
$catCondition = (sizeof($match_result) > 0) ? " AND `product_id` IN (".join(",", $match_result).") " : " AND `product_id` = -1 ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
SELECT `product_id`
|
||||||
|
FROM ".$this->tb_set_product."
|
||||||
|
WHERE `set_id` = ? " . $catCondition ."
|
||||||
|
ORDER BY id desc
|
||||||
|
LIMIT ".($page - 1) * $numPerPage .", ".$numPerPage."
|
||||||
|
", ['d'], [$set_id]);
|
||||||
|
|
||||||
|
$item_list = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
$item_list[] = $info['product_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryOrderBy(string $sort_by = "new")
|
||||||
|
{
|
||||||
|
$order_condition = "";
|
||||||
|
|
||||||
|
switch ($sort_by) {
|
||||||
|
case "ordering";
|
||||||
|
$order_condition = " `ordering` desc ";
|
||||||
|
break;
|
||||||
|
case "old";
|
||||||
|
$order_condition = " id asc ";
|
||||||
|
break;
|
||||||
|
case "last_show_time";
|
||||||
|
$order_condition = " last_show_time ASC ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order_condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info) : array
|
||||||
|
{
|
||||||
|
$from_time = $item_info['from_time'];
|
||||||
|
$from_time_date = ($from_time > 0) ? date("d-m-Y", $from_time) : '';
|
||||||
|
$from_time_minute = ($from_time > 0) ? date("H:i", $from_time) : "00:00";
|
||||||
|
|
||||||
|
$to_time = $item_info['to_time'];
|
||||||
|
$to_time_date = ($to_time > 0) ? date("d-m-Y", $to_time) : '';
|
||||||
|
$to_time_minute = ($to_time > 0) ? date("H:i", $to_time) : "00:00";
|
||||||
|
|
||||||
|
$item_info['from_time_date'] = $from_time_date;
|
||||||
|
$item_info['from_time_minute'] = $from_time_minute;
|
||||||
|
$item_info['to_time_date'] = $to_time_date;
|
||||||
|
$item_info['to_time_minute'] = $to_time_minute;
|
||||||
|
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///---------
|
||||||
|
///
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
|
||||||
|
$catCondition = "";
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
if(isset($filter_condition["product_id"]) && $filter_condition["product_id"]){
|
||||||
|
$catCondition .= " AND `id` IN ( SELECT `set_id` FROM ".$this->tb_set_product." WHERE `product_id` = ? ) ";
|
||||||
|
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition['product_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$catCondition, $bind_types, $bind_values];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ConfigGroup\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\ConfigGroup\Controller\bConfigGroupController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class AConfigGroupController extends bConfigGroupController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
public function deleteAttribute($id, $group_id = 0) {
|
||||||
|
$this->objConfigGroupModel->deleteAttribute($id, $group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateAttribute($id, $info) {
|
||||||
|
$this->objConfigGroupModel->updateAttribute($id, $info) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function createAttribute($info) {
|
||||||
|
return $this->objConfigGroupModel->createAttribute($info) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function createAttributeValue($info) {
|
||||||
|
$this->objConfigGroupModel->createAttributeValue($info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function deleteAttributeValue($id) {
|
||||||
|
$this->objConfigGroupModel->deleteAttributeValue($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateAttributeValue($id, $info) {
|
||||||
|
$this->objConfigGroupModel->updateAttributeValue($id, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function createProduct($product_id, $group_id, array $attribute_config) {
|
||||||
|
$this->objConfigGroupModel->createProduct($product_id, $group_id, $attribute_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function deleteProduct($product_id, $group_id) {
|
||||||
|
$this->objConfigGroupModel->deleteProduct($product_id, $group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateProduct($product_id, $group_id, array $attribute_config, $product_name_in_group = '') {
|
||||||
|
|
||||||
|
return $this->objConfigGroupModel->updateProduct($product_id, $group_id, $attribute_config, $product_name_in_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProductInGroup($group_id){
|
||||||
|
return $this->objConfigGroupModel->getProductInGroup($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getGroupConfig($item_id) {
|
||||||
|
return $this->objConfigGroupModel->getGroupConfig($item_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ConfigGroup\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\ConfigGroup\Model\ConfigGroupModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class bConfigGroupController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var ConfigGroupModel $objConfigGroupModel */
|
||||||
|
protected $objConfigGroupModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objConfigGroupModel = new ConfigGroupModel();
|
||||||
|
parent::__construct($this->objConfigGroupModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
500
inc/Hura8/Components/ConfigGroup/Model/ConfigGroupModel.php
Normal file
500
inc/Hura8/Components/ConfigGroup/Model/ConfigGroupModel.php
Normal file
@@ -0,0 +1,500 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\ConfigGroup\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Components\Product\Model\ProductModel;
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigGroupModel extends aEntityBaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_config_group = "";
|
||||||
|
protected $tb_config_group_product = "tb_config_group_product";
|
||||||
|
protected $tb_config_group_product_cache = "tb_config_group_product_cache";
|
||||||
|
protected $tb_config_group_attribute = "tb_config_group_attribute";
|
||||||
|
protected $tb_config_group_attribute_value = "tb_config_group_attribute_value";
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct('config_group');
|
||||||
|
$this->tb_config_group = $this->tb_entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function updateGroupAttributeCount($group_id) {
|
||||||
|
$this->db->runQuery(
|
||||||
|
"UPDATE `".$this->tb_config_group."` SET
|
||||||
|
`attribute_count` = ( SELECT COUNT(*) FROM `".$this->tb_config_group_attribute."` WHERE `group_id` = ? )
|
||||||
|
WHERE `id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'], [ $group_id, $group_id ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function updateGroupProductCount($group_id) {
|
||||||
|
$this->db->runQuery(
|
||||||
|
"UPDATE `".$this->tb_config_group."` SET
|
||||||
|
`item_count` = ( SELECT COUNT(*) FROM `".$this->tb_config_group_product."` WHERE `group_id` = ? )
|
||||||
|
WHERE `id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'], [ $group_id, $group_id ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//attribute value
|
||||||
|
public function deleteAttributeValue($att_value_id) {
|
||||||
|
|
||||||
|
$attr_id = 0;
|
||||||
|
$query = $this->db->runQuery("SELECT `attr_id` FROM `".$this->tb_config_group_attribute_value."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $att_value_id ]);
|
||||||
|
if ($info = $this->db->fetchAssoc($query)) {
|
||||||
|
$attr_id = $info['attr_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$group_id = $this->getGroupIdFromAttribute($attr_id);
|
||||||
|
|
||||||
|
$this->db->runQuery("DELETE FROM `".$this->tb_config_group_attribute_value."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $att_value_id ]);
|
||||||
|
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
|
||||||
|
$this->updateAttributeValueCount($attr_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function updateAttributeValueCount($attr_id) {
|
||||||
|
$this->db->runQuery(
|
||||||
|
"UPDATE `".$this->tb_config_group_attribute."` SET
|
||||||
|
`value_count` = ( SELECT COUNT(*) FROM `".$this->tb_config_group_attribute_value."` WHERE `attr_id` = ? )
|
||||||
|
WHERE `id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'],
|
||||||
|
[$attr_id, $attr_id ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateAttributeValue($id, $info) {
|
||||||
|
|
||||||
|
$updated_info = $info;
|
||||||
|
|
||||||
|
$updated_info['last_update'] = CURRENT_TIME;
|
||||||
|
$updated_info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
$this->db->update(
|
||||||
|
$this->tb_config_group_attribute_value,
|
||||||
|
$updated_info,
|
||||||
|
[
|
||||||
|
"id" => $id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$group_id = $this->getGroupIdFromAttributeValue($id);
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function createAttributeValue($info) {
|
||||||
|
$updated_info = $info;
|
||||||
|
|
||||||
|
$updated_info['create_time'] = CURRENT_TIME;
|
||||||
|
$updated_info['create_by'] = ADMIN_NAME;
|
||||||
|
$updated_info['last_update'] = CURRENT_TIME;
|
||||||
|
$updated_info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
$this->db->insert($this->tb_config_group_attribute_value, $updated_info );
|
||||||
|
|
||||||
|
$group_id = $this->getGroupIdFromAttribute($info['attr_id']);
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
|
||||||
|
$this->updateAttributeValueCount($info['attr_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//attribute
|
||||||
|
public function deleteAttribute($id, $group_id = 0) {
|
||||||
|
if(!$group_id) $group_id = $this->getGroupIdFromAttribute($id);
|
||||||
|
$this->db->runQuery("DELETE FROM `".$this->tb_config_group_attribute."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $id ]);
|
||||||
|
$this->db->runQuery("DELETE FROM `".$this->tb_config_group_attribute_value."` WHERE `attr_id` = ? LIMIT 1 ", ['d'], [ $id ]);
|
||||||
|
|
||||||
|
$this->updateGroupAttributeCount($group_id);
|
||||||
|
|
||||||
|
//todo: update for product attribute_config ?
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAttribute($id, $info) {
|
||||||
|
|
||||||
|
$updated_info = $info;
|
||||||
|
|
||||||
|
$updated_info['last_update'] = CURRENT_TIME;
|
||||||
|
$updated_info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
$this->db->update(
|
||||||
|
$this->tb_config_group_attribute,
|
||||||
|
$updated_info,
|
||||||
|
[
|
||||||
|
'id' => $id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$group_id = $this->getGroupIdFromAttribute($id);
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createAttribute($info) {
|
||||||
|
|
||||||
|
$updated_info = $info;
|
||||||
|
|
||||||
|
$updated_info['create_time'] = CURRENT_TIME;
|
||||||
|
$updated_info['create_by'] = ADMIN_NAME;
|
||||||
|
$updated_info['last_update'] = CURRENT_TIME;
|
||||||
|
$updated_info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
$this->db->insert($this->tb_config_group_attribute, $updated_info );
|
||||||
|
|
||||||
|
$this->resetProductConfigCache($info['group_id']);
|
||||||
|
|
||||||
|
$this->updateGroupAttributeCount($info['group_id']);
|
||||||
|
|
||||||
|
return $this->db->get_insert_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getGroupIdFromAttributeValue($att_value_id) {
|
||||||
|
$attr_id = 0;
|
||||||
|
$query = $this->db->runQuery("SELECT `attr_id` FROM `".$this->tb_config_group_attribute_value."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $att_value_id ]);
|
||||||
|
if ($info = $this->db->fetchAssoc($query)) {
|
||||||
|
$attr_id = $info['attr_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getGroupIdFromAttribute($attr_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getGroupIdFromAttribute($attr_id) {
|
||||||
|
$group_id = 0;
|
||||||
|
$query = $this->db->runQuery("SELECT `group_id` FROM `".$this->tb_config_group_attribute."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $attr_id ]);
|
||||||
|
if ($info = $this->db->fetchAssoc($query)) {
|
||||||
|
$group_id = $info['group_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $group_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//create or update product in a group
|
||||||
|
public function createProduct($product_id, $group_id, array $attribute_config) {
|
||||||
|
if($this->isProductInGroup($product_id, $group_id)) {
|
||||||
|
|
||||||
|
$this->updateProduct($product_id, $group_id, $attribute_config);
|
||||||
|
|
||||||
|
}else {
|
||||||
|
|
||||||
|
$updated_info = [
|
||||||
|
"product_id" => $product_id,
|
||||||
|
"group_id" => $group_id,
|
||||||
|
"attribute_config" => json_encode($attribute_config),
|
||||||
|
|
||||||
|
"create_time" => CURRENT_TIME,
|
||||||
|
"create_by" => ADMIN_NAME,
|
||||||
|
"last_update" => CURRENT_TIME,
|
||||||
|
"last_update_by" => ADMIN_NAME,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->db->insert($this->tb_config_group_product, $updated_info );
|
||||||
|
|
||||||
|
$this->updateGroupProductCount($group_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteProduct($product_id, $group_id) {
|
||||||
|
$this->db->runQuery(
|
||||||
|
"DELETE FROM `".$this->tb_config_group_product."` WHERE `product_id` = ? AND `group_id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'], [ $product_id, $group_id ]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->deleteProductConfigCache($product_id);
|
||||||
|
|
||||||
|
$this->updateGroupProductCount($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateProduct($product_id, $group_id, array $attribute_config, $product_name_in_group = '') {
|
||||||
|
|
||||||
|
$this->db->update(
|
||||||
|
$this->tb_config_group_product,
|
||||||
|
[
|
||||||
|
"attribute_config" => json_encode($attribute_config),
|
||||||
|
"product_name_in_group" => substr($product_name_in_group, 0, 140),
|
||||||
|
"last_update" => CURRENT_TIME,
|
||||||
|
"last_update_by" => ADMIN_NAME,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"product_id" => $product_id,
|
||||||
|
"group_id" => $group_id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->resetProductConfigCache($group_id);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//we want to reset all caches for products in a group
|
||||||
|
//we need to do this when we make changes to group's attributes, or create new products/ update product in group
|
||||||
|
protected function resetProductConfigCache($group_id) {
|
||||||
|
$query = $this->db->runQuery("SELECT `product_id` FROM `".$this->tb_config_group_product."` WHERE `group_id` = ? ", ['d'], [$group_id]) ;
|
||||||
|
$product_list = array();
|
||||||
|
foreach( $this->db->fetchAll($query) as $item ){
|
||||||
|
$product_list[] = $item['product_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sizeof($product_list)) {
|
||||||
|
$this->db->query("UPDATE `".$this->tb_config_group_product_cache."` SET
|
||||||
|
`value` = NULL
|
||||||
|
WHERE `product_id` IN (".join(",", $product_list).") ") ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteProductConfigCache($product_id) {
|
||||||
|
$this->db->runQuery("DELETE FROM `".$this->tb_config_group_product_cache."` WHERE `product_id` = ? LIMIT 1 ", ['d'], [$product_id]) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function saveProductConfigCache($product_id, $value) {
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `product_id` FROM `".$this->tb_config_group_product_cache."` WHERE `product_id` = ? LIMIT 1 ",
|
||||||
|
['d'], [$product_id]
|
||||||
|
) ;
|
||||||
|
|
||||||
|
if($this->db->fetchAssoc($query)){
|
||||||
|
$this->db->runQuery(
|
||||||
|
"UPDATE `".$this->tb_config_group_product_cache."` SET
|
||||||
|
`value` = '".$this->db->escape(json_encode($value))."'
|
||||||
|
WHERE `product_id` = ? LIMIT 1 ",
|
||||||
|
['d'], [$product_id]
|
||||||
|
) ;
|
||||||
|
}else{
|
||||||
|
$this->db->runQuery("INSERT INTO `".$this->tb_config_group_product_cache."` (`product_id`, `value`)
|
||||||
|
VALUES ('". (int) $product_id."', '".$this->db->escape(json_encode($value))."') ") ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProductConfigCache($product_id) {
|
||||||
|
$query = $this->db->runQuery("SELECT `value` FROM `".$this->tb_config_group_product_cache."` WHERE `product_id` = ? LIMIT 1 ", ['d'], [$product_id]) ;
|
||||||
|
if($item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return ($item_info['value']) ? \json_decode($item_info['value'], true) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//get all group config
|
||||||
|
public function getGroupConfig($group_id) {
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT
|
||||||
|
a.id AS attribute_id ,
|
||||||
|
a.name AS attribute_name ,
|
||||||
|
a.ordering AS attr_ordering ,
|
||||||
|
v.id AS value_id ,
|
||||||
|
v.name AS value_name ,
|
||||||
|
v.image AS image ,
|
||||||
|
v.color_code AS color ,
|
||||||
|
v.ordering ,
|
||||||
|
v.description AS description
|
||||||
|
FROM `".$this->tb_config_group_attribute."` a
|
||||||
|
LEFT JOIN `".$this->tb_config_group_attribute_value."` v ON a.id = v.attr_id
|
||||||
|
WHERE a.group_id = ?
|
||||||
|
ORDER BY attr_ordering DESC, `ordering` DESC
|
||||||
|
",
|
||||||
|
['d'], [$group_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$group_attribute = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
if(!isset($group_attribute[$info['attribute_id']])) {
|
||||||
|
$group_attribute[$info['attribute_id']] = array(
|
||||||
|
'id' => $info['attribute_id'],
|
||||||
|
'name' => $info['attribute_name'],
|
||||||
|
'ordering' => $info['attr_ordering'],
|
||||||
|
'list' => array(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($info['value_id']) {
|
||||||
|
$group_attribute[$info['attribute_id']]['list'][] = array(
|
||||||
|
'id' => $info['value_id'],
|
||||||
|
'name' => $info['value_name'],
|
||||||
|
'image' => $info['image'],
|
||||||
|
'color' => $info['color'],
|
||||||
|
'ordering' => $info['ordering'],
|
||||||
|
'description' => $info['description'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $group_attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProductConfigGroupId($product_id) {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `group_id` FROM `".$this->tb_config_group_product."` WHERE `product_id` = ? LIMIT 1 ",
|
||||||
|
['d'], [$product_id]
|
||||||
|
) ;
|
||||||
|
|
||||||
|
if($item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $item_info['group_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProductInGroup($group_id){
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `product_id`, `product_name_in_group`, `attribute_config`
|
||||||
|
FROM `".$this->tb_config_group_product."`
|
||||||
|
WHERE `group_id` = ?
|
||||||
|
",
|
||||||
|
['d'], [$group_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$product_list = array();
|
||||||
|
$product_ids = array();
|
||||||
|
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
$product_ids[] = $info['product_id'];
|
||||||
|
|
||||||
|
$product_list[$info['product_id']] = array(
|
||||||
|
"id" => $info['product_id'],
|
||||||
|
"name" => "",
|
||||||
|
"product_name_in_group" => $info['product_name_in_group'],
|
||||||
|
"attribute" => \json_decode($info['attribute_config'], true),
|
||||||
|
"url" => "",
|
||||||
|
"sku" => "",
|
||||||
|
"price" => 0,
|
||||||
|
"image" => "",
|
||||||
|
"status" => "",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//find product urls
|
||||||
|
if(sizeof($product_ids)) {
|
||||||
|
$objProductModel = new ProductModel();
|
||||||
|
$product_list_info = $objProductModel->getListByIds($product_ids);
|
||||||
|
|
||||||
|
// debug_var($product_list_info);
|
||||||
|
// update $product_list
|
||||||
|
foreach ($product_list as $_pro_id => $_info) {
|
||||||
|
$_pro_info = $product_list_info[$_pro_id] ?? null;
|
||||||
|
if($_pro_info) {
|
||||||
|
$product_list[$_pro_id]['name'] = $_pro_info['title'];
|
||||||
|
$product_list[$_pro_id]['price'] = $_pro_info['price'];
|
||||||
|
$product_list[$_pro_id]['sku'] = $_pro_info['sku'];
|
||||||
|
$product_list[$_pro_id]['image'] = $_pro_info['thumbnail'];
|
||||||
|
$product_list[$_pro_id]['url'] = $_pro_info['request_path'];
|
||||||
|
$product_list[$_pro_id]['status'] = $_pro_info['status'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $product_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function isProductInGroup($product_id, $group_id) {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT * FROM `".$this->tb_config_group_product."` WHERE `product_id` = ? AND `group_id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'],
|
||||||
|
[$product_id, $group_id]
|
||||||
|
) ;
|
||||||
|
|
||||||
|
return ($this->db->fetchAssoc($query));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
"q" => "",
|
||||||
|
"numPerPage" => 20,
|
||||||
|
"order_by" => '',
|
||||||
|
);*/
|
||||||
|
|
||||||
|
$catCondition = "";
|
||||||
|
|
||||||
|
return [
|
||||||
|
$catCondition,
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeCreateItem(array $input_info): AppResponse
|
||||||
|
{
|
||||||
|
$info = $input_info;
|
||||||
|
|
||||||
|
$info['create_time'] = CURRENT_TIME;
|
||||||
|
$info['create_by'] = ADMIN_NAME;
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||||
|
{
|
||||||
|
// TODO: Implement afterCreateItem() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info):AppResponse
|
||||||
|
{
|
||||||
|
$info = $new_input_info;
|
||||||
|
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||||
|
{
|
||||||
|
// TODO: Implement afterUpdateItem() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeDeleteItem($item_id, $item_info):AppResponse
|
||||||
|
{
|
||||||
|
return new AppResponse('ok' );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterDeleteItem($item_id, $item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT `id` FROM `".$this->tb_config_group_attribute."` WHERE `group_id` = ? ", ['d'], [$item_id]);
|
||||||
|
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
$this->deleteAttribute($info['id'], $item_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->runQuery(
|
||||||
|
"DELETE FROM `".$this->tb_config_group_product_cache."` WHERE `product_id` IN (SELECT product_id FROM config_group_product WHERE `group_id` = ? ) ",
|
||||||
|
['d'], [$item_id]
|
||||||
|
) ;
|
||||||
|
|
||||||
|
$this->db->runQuery("DELETE FROM `".$this->tb_config_group_product."` WHERE `group_id` = ? ", ['d'], [$item_id]) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Customer\Controller\bCustomerController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class ACustomerController extends bCustomerController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
// TODO: Implement deleteFileBeforeDeleteItem() method.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Customer\Model\CustomerGroupModel;
|
||||||
|
use Hura8\Components\Province\AdminController\AProvinceController;
|
||||||
|
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class ACustomerGroupController extends aAdminEntityBaseController
|
||||||
|
{
|
||||||
|
/* @var CustomerGroupModel $objCustomerGroupModel */
|
||||||
|
protected $objCustomerGroupModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objCustomerGroupModel = new CustomerGroupModel();
|
||||||
|
parent::__construct($this->objCustomerGroupModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getAllGroup() {
|
||||||
|
return $this->objCustomerGroupModel->getList(["numPerPage" => 1000]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function removeCustomer($customer_id, $group_id)
|
||||||
|
{
|
||||||
|
return $this->objCustomerGroupModel->removeCustomer($customer_id, $group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addCustomer($customer_id, $group_id)
|
||||||
|
{
|
||||||
|
return $this->objCustomerGroupModel->addCustomer($customer_id, $group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTotalCustomer($group_id, array $condition = [])
|
||||||
|
{
|
||||||
|
return $this->objCustomerGroupModel->getTotalCustomer($group_id, $condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getListCustomer($group_id, array $condition = []) {
|
||||||
|
|
||||||
|
$objProvinceController = new AProvinceController();
|
||||||
|
|
||||||
|
return array_map(function ($item) use ($objProvinceController){
|
||||||
|
|
||||||
|
$item['province_name'] = $objProvinceController->getProvinceName($item['province']);
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
|
||||||
|
}, $this->objCustomerGroupModel->getListCustomer($group_id, $condition));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
// TODO: Implement deleteFileBeforeDeleteItem() method.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Customer\Controller\bCustomerLoyaltyController;
|
||||||
|
|
||||||
|
class ACustomerLoyaltyController extends bCustomerLoyaltyController {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Customer\Model\CustomerModel;
|
||||||
|
use Hura8\Components\Province\AdminController\AProvinceController;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
class bCustomerController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var CustomerModel $objCustomerModel */
|
||||||
|
protected $objCustomerModel;
|
||||||
|
|
||||||
|
/* @var AProvinceController $objProvinceController */
|
||||||
|
protected $objProvinceController;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objCustomerModel = new CustomerModel();
|
||||||
|
$this->objProvinceController = new AProvinceController();
|
||||||
|
parent::__construct($this->objCustomerModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function formatItemInList(array $item_info)
|
||||||
|
{
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function formatItemInfo(array $item_info)
|
||||||
|
{
|
||||||
|
$info = $item_info;
|
||||||
|
$info['province_name'] = $this->objProvinceController->getProvinceName($item_info['province']);
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Controller;
|
||||||
|
|
||||||
|
use ClientExtend\UserLoyaltyPointCalculation;
|
||||||
|
use Hura8\Components\Customer\Model\CustomerLoyaltyModel;
|
||||||
|
|
||||||
|
|
||||||
|
class bCustomerLoyaltyController
|
||||||
|
{
|
||||||
|
|
||||||
|
public static $POINT_NAME = 'điểm';
|
||||||
|
|
||||||
|
protected $point_setting = [];
|
||||||
|
protected $point_setting_config_file = ROOT_DIR . "/config/build/customer_point.php";
|
||||||
|
|
||||||
|
protected $level_setting = [];
|
||||||
|
protected $level_setting_config_file = ROOT_DIR . "/config/client/customer_level.php";
|
||||||
|
|
||||||
|
protected $level_by = '';// point|total_purchase_value as set by constant CHANGE_CUSTOMER_LEVEL_BY
|
||||||
|
|
||||||
|
/* @var $objUserLoyaltyPointCalculation UserLoyaltyPointCalculation */
|
||||||
|
protected $objUserLoyaltyPointCalculation;
|
||||||
|
|
||||||
|
/* @var CustomerLoyaltyModel $objCustomerLoyaltyModel */
|
||||||
|
protected $objCustomerLoyaltyModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objCustomerLoyaltyModel = new CustomerLoyaltyModel();
|
||||||
|
|
||||||
|
// import settings
|
||||||
|
//$new_info_file = "../config/build/customer_point.php" ;
|
||||||
|
//$config_file = ROOT_DIR . "/config/build/customer_point.php";
|
||||||
|
if(@file_exists($this->point_setting_config_file)) {
|
||||||
|
$this->point_setting = include $this->point_setting_config_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// customer level based on point gain
|
||||||
|
if( defined("ENABLE_CUSTOMER_POINT") && ENABLE_CUSTOMER_POINT ) {
|
||||||
|
if(@file_exists($this->level_setting_config_file)) {
|
||||||
|
$this->level_setting = include $this->level_setting_config_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default is point
|
||||||
|
$this->level_by = (defined('CHANGE_CUSTOMER_LEVEL_BY')) ? CHANGE_CUSTOMER_LEVEL_BY : 'point';
|
||||||
|
|
||||||
|
$this->objUserLoyaltyPointCalculation = new UserLoyaltyPointCalculation($this->point_setting);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPointSettingConfigFile() {
|
||||||
|
return $this->point_setting_config_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPointSetting() {
|
||||||
|
return $this->point_setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLevelSetting(){
|
||||||
|
return $this->level_setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
// show estimate cart point
|
||||||
|
public function getEstimateCartPoint($cart_value){
|
||||||
|
$conversion_rate = (isset($this->point_setting['reward']['buy']['rate'])) ? $this->point_setting['reward']['buy']['rate'] : 0;
|
||||||
|
return ($conversion_rate) ? round($cart_value / $conversion_rate) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserPoint($user_id, array $condition, $return_type)
|
||||||
|
{
|
||||||
|
return $this->objCustomerLoyaltyModel->getUserPoint($user_id, $condition, $return_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove rewarded point i.e. reward for successfull order and now order is marked canceled
|
||||||
|
public function reclaimRewardedPoint($user_id, $activity_type_tracker){
|
||||||
|
// todo:
|
||||||
|
}
|
||||||
|
|
||||||
|
public function usePoint($user_id, $use_point, $activity_type, $activity_type_tracker, $reason = '', $point_args = ['order_value' => 0]){
|
||||||
|
// no user or no config
|
||||||
|
if(!$user_id || !ENABLE_CUSTOMER_POINT) return false;
|
||||||
|
|
||||||
|
$result = $this->objUserLoyaltyPointCalculation->calculateUsePoint($user_id, $use_point, $activity_type, $activity_type_tracker, $point_args);
|
||||||
|
|
||||||
|
$this->pointOp('use', $user_id, $result['use_point'], $activity_type, $activity_type_tracker, $reason);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function rewardPoint($user_id, $activity_type, $activity_type_tracker, $reason = '', $point_args = ['order_id' => 0]){
|
||||||
|
// no user or no config
|
||||||
|
if(!$user_id || !ENABLE_CUSTOMER_POINT) return false;
|
||||||
|
|
||||||
|
$point = $this->objUserLoyaltyPointCalculation->calculateRewardPoint($user_id, $activity_type, $activity_type_tracker, $point_args);
|
||||||
|
|
||||||
|
$this->pointOp('reward', $user_id, $point, $activity_type, $activity_type_tracker, $reason);
|
||||||
|
|
||||||
|
return $point;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $operation: reward|use
|
||||||
|
// $change_point: positive (reward) or nagative (use)
|
||||||
|
protected function pointOp($operation, $user_id, $change_point, $activity_type, $activity_type_tracker, $reason = '') {
|
||||||
|
|
||||||
|
if(!$change_point) return false;
|
||||||
|
|
||||||
|
$reason_prefix = ($operation == 'use') ? 'Sử dụng' : 'Thưởng';
|
||||||
|
if($activity_type == 'return') $reason_prefix = 'Hoàn lại';
|
||||||
|
$full_reason = join(" ", [$reason_prefix, $change_point, static::$POINT_NAME, ":", $reason]);
|
||||||
|
|
||||||
|
if($operation == 'use') $change_point = -1 * $change_point;
|
||||||
|
|
||||||
|
// security: hash the row to avoid editing point directly in the database
|
||||||
|
$hash_value = sha1(join(".", [
|
||||||
|
$operation,
|
||||||
|
$user_id,
|
||||||
|
$change_point,
|
||||||
|
$activity_type,
|
||||||
|
$activity_type_tracker,
|
||||||
|
CURRENT_TIME,
|
||||||
|
'ass@ss'
|
||||||
|
]));
|
||||||
|
|
||||||
|
$new_id = $this->db->insert(
|
||||||
|
$this->tb_point ,
|
||||||
|
[
|
||||||
|
'customer_id' => $user_id ,
|
||||||
|
'activity_type' => $activity_type,
|
||||||
|
'activity_type_tracker' => $activity_type_tracker ,
|
||||||
|
'operation' => $operation,
|
||||||
|
'point' => $change_point,
|
||||||
|
'create_time' => CURRENT_TIME,
|
||||||
|
'reason' => substr($full_reason, 0, 200),
|
||||||
|
'referer_url' => substr(REFERER_URL, 0, 150) ,
|
||||||
|
'hash_value' => $hash_value ,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//update user reward balance
|
||||||
|
if($new_id) {
|
||||||
|
$this->updateStat($user_id, $change_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateStat($user_id, $changed_point, $changed_order_value=0) {
|
||||||
|
return $this->objCustomerLoyaltyModel->updateStat($user_id, $changed_point, $changed_order_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateLevelByPoint($point) {
|
||||||
|
//if the point in between -> return the lowest level
|
||||||
|
$all_level = array_keys($this->level_setting);
|
||||||
|
|
||||||
|
foreach ( $all_level as $level) {
|
||||||
|
$next_level = $level + 1;
|
||||||
|
if(!in_array($next_level, $all_level)) $next_level = 0;
|
||||||
|
|
||||||
|
if($next_level) {
|
||||||
|
if( $point >= $this->level_setting[$level]["point_require"]
|
||||||
|
&& $point < $this->level_setting[$next_level]["point_require"] ) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if($point >= $this->level_setting[$level]["point_require"]) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateLevelByOrderValue($aggregate_purchase_value = 0) {
|
||||||
|
|
||||||
|
//if the point in between -> return the lowest level
|
||||||
|
$all_level = array_keys($this->level_setting);
|
||||||
|
|
||||||
|
//tinh hang thanh vien theo so tien tich luy
|
||||||
|
foreach ( $all_level as $level ) {
|
||||||
|
$next_level = $level + 1;
|
||||||
|
if(!in_array($next_level, $all_level)) $next_level = 0;
|
||||||
|
|
||||||
|
if($next_level) {
|
||||||
|
if( $aggregate_purchase_value >= $this->level_setting[$level]["total_order_value"] &&
|
||||||
|
$aggregate_purchase_value < $this->level_setting[$next_level]["total_order_value"]
|
||||||
|
) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if( $aggregate_purchase_value >= $this->level_setting[$level]["total_order_value"]) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
79
inc/Hura8/Components/Customer/Model/CustomerAuthModel.php
Normal file
79
inc/Hura8/Components/Customer/Model/CustomerAuthModel.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Model\AuthModel;
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerAuthModel extends AuthModel
|
||||||
|
{
|
||||||
|
|
||||||
|
private $tb_customer_login = "tb_customer_login";
|
||||||
|
private $tb_customer_access_code = "tb_customer_access_code";
|
||||||
|
private $tb_customer_login_log = "tb_customer_login_log";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct($this->tb_customer_login, $this->tb_customer_access_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getLoginListByIds(array $staff_ids) {
|
||||||
|
if(!sizeof($staff_ids)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
list($parameterized_ids, $bind_types) = create_bind_sql_parameter_from_value_list($staff_ids, 'int');
|
||||||
|
|
||||||
|
$bind_values = $staff_ids;
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `user_id`, `last_login_time`, `last_login_ip`, `last_login_device`, `last_login_browser`
|
||||||
|
FROM ".$this->tb_customer_login."
|
||||||
|
WHERE `user_id` IN (".$parameterized_ids.") ",
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
);
|
||||||
|
|
||||||
|
$item_list = [];
|
||||||
|
foreach ($this->db->fetchAll($query) as $item) {
|
||||||
|
$item_list[$item['user_id']] = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getLoginLog(array $conditions = []) {
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT * FROM ".$this->tb_customer_login_log." WHERE 1 ORDER BY `id` DESC LIMIT 100 ",
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $email
|
||||||
|
* @param string $login_status ok or error
|
||||||
|
* @param string $login_msg
|
||||||
|
*/
|
||||||
|
public function logLogin($email, $login_status, $login_msg) {
|
||||||
|
$this->db->insert(
|
||||||
|
$this->tb_customer_login_log,
|
||||||
|
[
|
||||||
|
"email" => substr($email, 0, 45),
|
||||||
|
"login_status" => $login_status,
|
||||||
|
"login_msg" => substr($login_msg, 0, 45),
|
||||||
|
"ip_address" => substr(USER_IP, 0, 45),
|
||||||
|
"user_agent" => substr(USER_AGENT, 0, 99),
|
||||||
|
"create_time" => CURRENT_TIME,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
213
inc/Hura8/Components/Customer/Model/CustomerGroupModel.php
Normal file
213
inc/Hura8/Components/Customer/Model/CustomerGroupModel.php
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\System\Controller\UrlManagerController;
|
||||||
|
use Hura8\System\IDGenerator;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
|
||||||
|
class CustomerGroupModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_customer_per_group = "tb_customer_per_group";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct('customer_group');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateItemCount($group_id) {
|
||||||
|
$this->db->runQuery(
|
||||||
|
"UPDATE `".$this->tb_entity."` SET
|
||||||
|
`customer_count` = (SELECT COUNT(*) AS total FROM `".$this->tb_customer_per_group."` WHERE `group_id` = ? )
|
||||||
|
WHERE `id` = ? LIMIT 1
|
||||||
|
",
|
||||||
|
['d', 'd'], [$group_id, $group_id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTotalCustomer($group_id, array $condition = [])
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
" SELECT COUNT(*) as total FROM `".$this->tb_customer_per_group."` WHERE `group_id` = ? ",
|
||||||
|
['d'], [$group_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$total = 0;
|
||||||
|
if ($rs = $this->db->fetchAssoc($query)) {
|
||||||
|
$total = $rs['total'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getListCustomer($group_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 = " `id` DESC";
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `customer_id` FROM ".$this->tb_customer_per_group." WHERE `group_id` = ?
|
||||||
|
ORDER BY ".$order_by."
|
||||||
|
LIMIT ".(($page-1) * $numPerPage).", ".$numPerPage ,
|
||||||
|
['d'], [$group_id]
|
||||||
|
) ;
|
||||||
|
|
||||||
|
$item_list_ids = array_map(function ($item){ return $item['customer_id'];}, $this->db->fetchAll($query));
|
||||||
|
|
||||||
|
$objCustomerModel = new CustomerModel();
|
||||||
|
$list_info = $objCustomerModel->getListByIds($item_list_ids);
|
||||||
|
|
||||||
|
// final list
|
||||||
|
$final_list = [];
|
||||||
|
foreach ($item_list_ids as $_id) {
|
||||||
|
$final_list[] = $list_info[$_id] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $final_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function removeCustomerFromAllGroup($customer_id)
|
||||||
|
{
|
||||||
|
$this->db->runQuery(
|
||||||
|
"DELETE FROM `".$this->tb_customer_per_group."` WHERE `customer_id` = ?",
|
||||||
|
['d'], [$customer_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function removeCustomer($customer_id, $group_id)
|
||||||
|
{
|
||||||
|
$this->db->runQuery(
|
||||||
|
"DELETE FROM `".$this->tb_customer_per_group."` WHERE `group_id` =? AND `customer_id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'],
|
||||||
|
[$group_id, $customer_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->updateItemCount($group_id);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addCustomer($customer_id, $group_id)
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
" SELECT * FROM `".$this->tb_customer_per_group."` WHERE `group_id` = ? AND `customer_id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'],
|
||||||
|
[$group_id, $customer_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->db->fetchAssoc($query)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->insert(
|
||||||
|
$this->tb_customer_per_group,
|
||||||
|
[
|
||||||
|
"group_id" => $group_id,
|
||||||
|
"customer_id" => $customer_id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->updateItemCount($group_id);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition): ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
"q" => "",
|
||||||
|
"status" => 0,
|
||||||
|
);*/
|
||||||
|
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||||
|
{
|
||||||
|
$info = $input_info;
|
||||||
|
|
||||||
|
if(!$info['group_code']) $info['group_code'] = $info['title'];
|
||||||
|
$info['group_code'] = $this->createUniqueCode(0, $info['group_code']);
|
||||||
|
|
||||||
|
$info['create_time'] = CURRENT_TIME;
|
||||||
|
$info['create_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info): AppResponse
|
||||||
|
{
|
||||||
|
$info = $new_input_info;
|
||||||
|
|
||||||
|
if(isset($info['group_code'])) {
|
||||||
|
if(!$info['group_code']) $info['group_code'] = $info['title'];
|
||||||
|
$info['group_code'] = $this->createUniqueCode($item_id, $info['group_code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function createUniqueCode($current_item_id, $wanted_code){
|
||||||
|
|
||||||
|
$clean_code = UrlManagerController::create_url_index($wanted_code);
|
||||||
|
|
||||||
|
//if exist and belong other id, create a new one
|
||||||
|
$query = $this->db->runQuery("SELECT `id` FROM `".$this->tb_entity."` WHERE `group_code` = ? LIMIT 1 ", ['s'], [$clean_code]) ;
|
||||||
|
if($info = $this->db->fetchAssoc($query)){
|
||||||
|
if($info['id'] != $current_item_id) {
|
||||||
|
$new_code = $clean_code."-".IDGenerator::createStringId(3);
|
||||||
|
return $this->createUniqueCode($current_item_id, $new_code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $clean_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||||
|
{
|
||||||
|
return new AppResponse('ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterDeleteItem($item_id, $item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function extendedFilterOptions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
268
inc/Hura8/Components/Customer/Model/CustomerLoyaltyModel.php
Normal file
268
inc/Hura8/Components/Customer/Model/CustomerLoyaltyModel.php
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Model;
|
||||||
|
|
||||||
|
use ClientExtend\UserLoyaltyPointCalculation;
|
||||||
|
use Hura8\Database\iConnectDB;
|
||||||
|
use Hura8\Interfaces\TableName;
|
||||||
|
|
||||||
|
class CustomerLoyaltyModel
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var iConnectDB $db */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
protected $tb_point = TableName::CUSTOMER_POINT; // "idv_customer_point";
|
||||||
|
protected $tb_customer = TableName::CUSTOMER; // "idv_customer";
|
||||||
|
|
||||||
|
public static $POINT_NAME = 'điểm';
|
||||||
|
|
||||||
|
protected $point_setting = [];
|
||||||
|
protected $point_setting_config_file = ROOT_DIR . "/config/build/customer_point.php";
|
||||||
|
|
||||||
|
protected $level_setting = [];
|
||||||
|
protected $level_setting_config_file = ROOT_DIR . "/config/client/customer_level.php";
|
||||||
|
|
||||||
|
protected $level_by = '';// point|total_purchase_value as set by constant CHANGE_CUSTOMER_LEVEL_BY
|
||||||
|
|
||||||
|
/* @var $objUserLoyaltyPointCalculation UserLoyaltyPointCalculation */
|
||||||
|
protected $objUserLoyaltyPointCalculation;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->db = get_db("", ENABLE_DB_DEBUG);
|
||||||
|
|
||||||
|
// import settings
|
||||||
|
//$new_info_file = "../config/build/customer_point.php" ;
|
||||||
|
//$config_file = ROOT_DIR . "/config/build/customer_point.php";
|
||||||
|
if(@file_exists($this->point_setting_config_file)) {
|
||||||
|
$this->point_setting = include $this->point_setting_config_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// customer level based on point gain
|
||||||
|
if( defined("ENABLE_CUSTOMER_POINT") && ENABLE_CUSTOMER_POINT ) {
|
||||||
|
if(@file_exists($this->level_setting_config_file)) {
|
||||||
|
$this->level_setting = include $this->level_setting_config_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default is point
|
||||||
|
$this->level_by = (defined('CHANGE_CUSTOMER_LEVEL_BY')) ? CHANGE_CUSTOMER_LEVEL_BY : 'point';
|
||||||
|
|
||||||
|
$this->objUserLoyaltyPointCalculation = new UserLoyaltyPointCalculation($this->point_setting);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPointSettingConfigFile() {
|
||||||
|
return $this->point_setting_config_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPointSetting() {
|
||||||
|
return $this->point_setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLevelSetting(){
|
||||||
|
return $this->level_setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
// show estimate cart point
|
||||||
|
public function getEstimateCartPoint($cart_value){
|
||||||
|
$conversion_rate = (isset($this->point_setting['reward']['buy']['rate'])) ? $this->point_setting['reward']['buy']['rate'] : 0;
|
||||||
|
return ($conversion_rate) ? round($cart_value / $conversion_rate) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserPoint($user_id, array $condition, $return_type)
|
||||||
|
{
|
||||||
|
|
||||||
|
if($return_type == "total") {
|
||||||
|
//Lay tong so
|
||||||
|
$query = $this->db->runQuery("SELECT COUNT(*) AS total FROM `". $this->tb_point ."` WHERE `customer_id` = ? " , ['d'], [$user_id]);
|
||||||
|
if($resultTotal = $this->db->fetchAssoc($query)){
|
||||||
|
return $resultTotal['total'];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$numPerPage = (isset($condition['numPerPage'])) ? intval($condition['numPerPage']) : 50;
|
||||||
|
$page = getPageId();
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
SELECT * FROM `". $this->tb_point ."`
|
||||||
|
WHERE `customer_id` = ?
|
||||||
|
ORDER BY id DESC
|
||||||
|
LIMIT ".($page - 1) * $numPerPage .", ".$numPerPage." " , ['d'], [$user_id]);
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
$i = ($page - 1) * $numPerPage;
|
||||||
|
foreach ( $this->db->fetchAll($query) as $rs){
|
||||||
|
$i++;
|
||||||
|
$rs['counter'] = $i;
|
||||||
|
$rs['activity_type_name'] = (isset($this->point_setting[$rs['operation']][$rs['activity_type']])) ? $this->point_setting[$rs['operation']][$rs['activity_type']]['name'] : '--';
|
||||||
|
$result[] = $rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function usePoint($user_id, $use_point, $activity_type, $activity_type_tracker, $reason = '', $point_args = ['order_value' => 0]){
|
||||||
|
// no user or no config
|
||||||
|
if(!$user_id || !ENABLE_CUSTOMER_POINT) return false;
|
||||||
|
|
||||||
|
$result = $this->objUserLoyaltyPointCalculation->calculateUsePoint($user_id, $use_point, $activity_type, $activity_type_tracker, $point_args);
|
||||||
|
|
||||||
|
$this->pointOp('use', $user_id, $result['use_point'], $activity_type, $activity_type_tracker, $reason);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function rewardPoint($user_id, $activity_type, $activity_type_tracker, $reason = '', $point_args = ['order_id' => 0]){
|
||||||
|
// no user or no config
|
||||||
|
if(!$user_id || !ENABLE_CUSTOMER_POINT) return false;
|
||||||
|
|
||||||
|
$point = $this->objUserLoyaltyPointCalculation->calculateRewardPoint($user_id, $activity_type, $activity_type_tracker, $point_args);
|
||||||
|
|
||||||
|
$this->pointOp('reward', $user_id, $point, $activity_type, $activity_type_tracker, $reason);
|
||||||
|
|
||||||
|
return $point;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// $operation: reward|use
|
||||||
|
// $change_point: positive (reward) or nagative (use)
|
||||||
|
protected function pointOp($operation, $user_id, $change_point, $activity_type, $activity_type_tracker, $reason = '') {
|
||||||
|
|
||||||
|
if(!$change_point) return false;
|
||||||
|
|
||||||
|
$reason_prefix = ($operation == 'use') ? 'Sử dụng' : 'Thưởng';
|
||||||
|
if($activity_type == 'return') $reason_prefix = 'Hoàn lại';
|
||||||
|
$full_reason = join(" ", [$reason_prefix, $change_point, static::$POINT_NAME, ":", $reason]);
|
||||||
|
|
||||||
|
if($operation == 'use') $change_point = -1 * $change_point;
|
||||||
|
|
||||||
|
// security: hash the row to avoid editing point directly in the database
|
||||||
|
$hash_value = sha1(join(".", [
|
||||||
|
$operation,
|
||||||
|
$user_id,
|
||||||
|
$change_point,
|
||||||
|
$activity_type,
|
||||||
|
$activity_type_tracker,
|
||||||
|
CURRENT_TIME,
|
||||||
|
'ass@ss'
|
||||||
|
]));
|
||||||
|
|
||||||
|
$new_id = $this->db->insert(
|
||||||
|
$this->tb_point ,
|
||||||
|
[
|
||||||
|
'customer_id' => $user_id ,
|
||||||
|
'activity_type' => $activity_type,
|
||||||
|
'activity_type_tracker' => $activity_type_tracker ,
|
||||||
|
'operation' => $operation,
|
||||||
|
'point' => $change_point,
|
||||||
|
'create_time' => CURRENT_TIME,
|
||||||
|
'reason' => substr($full_reason, 0, 200),
|
||||||
|
'referer_url' => substr(REFERER_URL, 0, 150) ,
|
||||||
|
'hash_value' => $hash_value ,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//update user reward balance
|
||||||
|
if($new_id) {
|
||||||
|
$this->updateStat($user_id, $change_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateStat($user_id, $changed_point, $changed_order_value=0) {
|
||||||
|
$user_id = intval($user_id);
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT
|
||||||
|
`loyalty_point`,
|
||||||
|
`loyalty_level`,
|
||||||
|
`total_value_success`
|
||||||
|
FROM ".$this->tb_customer."
|
||||||
|
WHERE `id` = ?
|
||||||
|
LIMIT 1 " , ['d'], [$user_id]);
|
||||||
|
|
||||||
|
if($current = $this->db->fetchAssoc($query)){
|
||||||
|
$new_point = $current['loyalty_point'] + $changed_point;
|
||||||
|
$new_purchase_value = $current['total_value_success'] + $changed_order_value;
|
||||||
|
|
||||||
|
$level = $current['loyalty_level'];
|
||||||
|
if($this->level_by == 'point' && $changed_point != 0) $level = $this->calculateLevelByPoint($new_point);
|
||||||
|
else if($changed_order_value) $level = $this->calculateLevelByOrderValue($new_purchase_value);
|
||||||
|
|
||||||
|
$this->db->update(
|
||||||
|
$this->tb_customer ,
|
||||||
|
[
|
||||||
|
'loyalty_point' => $new_point,
|
||||||
|
'loyalty_level' => $level,
|
||||||
|
'total_value_success' => $new_purchase_value,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => $user_id,
|
||||||
|
],
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function calculateLevelByPoint($point) {
|
||||||
|
//if the point in between -> return the lowest level
|
||||||
|
$all_level = array_keys($this->level_setting);
|
||||||
|
|
||||||
|
foreach ( $all_level as $level) {
|
||||||
|
$next_level = $level + 1;
|
||||||
|
if(!in_array($next_level, $all_level)) $next_level = 0;
|
||||||
|
|
||||||
|
if($next_level) {
|
||||||
|
if( $point >= $this->level_setting[$level]["point_require"]
|
||||||
|
&& $point < $this->level_setting[$next_level]["point_require"] ) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if($point >= $this->level_setting[$level]["point_require"]) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateLevelByOrderValue($aggregate_purchase_value = 0) {
|
||||||
|
|
||||||
|
//if the point in between -> return the lowest level
|
||||||
|
$all_level = array_keys($this->level_setting);
|
||||||
|
|
||||||
|
//tinh hang thanh vien theo so tien tich luy
|
||||||
|
foreach ( $all_level as $level ) {
|
||||||
|
$next_level = $level + 1;
|
||||||
|
if(!in_array($next_level, $all_level)) $next_level = 0;
|
||||||
|
|
||||||
|
if($next_level) {
|
||||||
|
if( $aggregate_purchase_value >= $this->level_setting[$level]["total_order_value"] &&
|
||||||
|
$aggregate_purchase_value < $this->level_setting[$next_level]["total_order_value"]
|
||||||
|
) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if( $aggregate_purchase_value >= $this->level_setting[$level]["total_order_value"]) {
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
128
inc/Hura8/Components/Customer/Model/CustomerModel.php
Normal file
128
inc/Hura8/Components/Customer/Model/CustomerModel.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\IDGenerator;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\System\Security\DataValidator;
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $user_types = [
|
||||||
|
"auto" => "Chưa đăng ký",
|
||||||
|
"register" => "Đăng ký thành viên",
|
||||||
|
];
|
||||||
|
|
||||||
|
/* @var iSearch $objSearchModel */
|
||||||
|
protected $objSearchModel;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objSearchModel = new CustomerSearchModel();
|
||||||
|
|
||||||
|
parent::__construct(
|
||||||
|
EntityType::CUSTOMER,
|
||||||
|
"",
|
||||||
|
$this->objSearchModel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'province' => 0,
|
||||||
|
'user_type' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getInfoByCRMCode($code)
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `crm_code` = ? LIMIT 1 ", ['s'], [$code]) ;
|
||||||
|
if( $item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getInfoByEmail($email, $user_type='register')
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT * FROM `".$this->tb_entity."` WHERE `email` = ? AND `type` = ? LIMIT 1 ",
|
||||||
|
['s', 's'], [$email, $user_type]
|
||||||
|
) ;
|
||||||
|
|
||||||
|
if( $item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getInfoByVerifiedEmail($email)
|
||||||
|
{
|
||||||
|
$info = $this->getInfoByEmail($email);
|
||||||
|
if($info && $info['is_email_verify']) {
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition): ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
"user_type" => ''
|
||||||
|
"q" => "",
|
||||||
|
"status" => 0,
|
||||||
|
);*/
|
||||||
|
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
|
||||||
|
if(isset($filter_condition["province"]) && $filter_condition["province"]) {
|
||||||
|
$catCondition[] = " AND `province` = ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition["province"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// user_type
|
||||||
|
if(isset($filter_condition["user_type"]) && array_key_exists($filter_condition["user_type"], $this->user_types) ){
|
||||||
|
$catCondition[] = " AND `type` = ? ";
|
||||||
|
$bind_types[] = 's';
|
||||||
|
$bind_values[] = $filter_condition["user_type"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info): array
|
||||||
|
{
|
||||||
|
if($item_info["birth_day"] && $item_info["birth_year"]) {
|
||||||
|
$item_info["birth_day"] = $item_info["birth_day"]."-".$item_info["birth_year"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function createWebCRMCode($input_code = '') {
|
||||||
|
return $input_code ?: "Web-".IDGenerator::createStringId(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
34
inc/Hura8/Components/Customer/Model/CustomerSearchModel.php
Normal file
34
inc/Hura8/Components/Customer/Model/CustomerSearchModel.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Customer\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\Model\aSearchBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class CustomerSearchModel extends aSearchBaseModel implements iSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
private $filter_fields = [
|
||||||
|
"type" => "tb_customer.type",
|
||||||
|
"province" => "tb_customer.province",
|
||||||
|
"is_email_verify" => "tb_customer.is_email_verify",
|
||||||
|
"total_value" => "tb_customer.total_value",
|
||||||
|
];
|
||||||
|
|
||||||
|
private $fulltext_fields = [
|
||||||
|
"keywords" => ["tb_customer.name", "tb_customer.crm_code", "tb_customer.email","tb_customer.mobile",],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
"tb_customer",
|
||||||
|
$this->fulltext_fields,
|
||||||
|
$this->filter_fields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Deal\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Deal\Model\DealCollectionModel;
|
||||||
|
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||||
|
|
||||||
|
class ADealCollectionController extends aAdminEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var DealCollectionModel $objDealCollectionModel */
|
||||||
|
protected $objDealCollectionModel;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objDealCollectionModel = new DealCollectionModel();
|
||||||
|
parent::__construct($this->objDealCollectionModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllProductIdInCollection($collection_id) {
|
||||||
|
return $this->objDealCollectionModel->getAllProductIdInCollection($collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllDealIdInCollection($collection_id) {
|
||||||
|
return $this->objDealCollectionModel->getAllDealIdInCollection($collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAllDealInCollection($collection_id, $price, $time){
|
||||||
|
return $this->objDealCollectionModel->updateAllDealInCollection($collection_id, $price, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addProductToCollection($product_id, $collection_id){
|
||||||
|
return $this->objDealCollectionModel->addProductToCollection($product_id, $collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeFromCollection($deal_id, $collection_id){
|
||||||
|
$this->objDealCollectionModel->removeFromCollection($deal_id, $collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addToCollection($deal_id, $collection_id){
|
||||||
|
$this->objDealCollectionModel->addToCollection($deal_id, $collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCollectionView($id){
|
||||||
|
$this->objDealCollectionModel->updateCollectionView($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Deal\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Deal\Controller\bDealController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
class ADealController extends bDealController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
public function autoRenew() {
|
||||||
|
$deal_list = $this->objDealModel->getAllAutoRenewableDeal();
|
||||||
|
|
||||||
|
//then renew & log history
|
||||||
|
foreach ($deal_list as $info) {
|
||||||
|
$this->renewDeal($info['id'], $info['from_time'], $info['to_time'], $info['auto_renew_history']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renewDeal($id, $from_time, $to_time, array $auto_renew_history) {
|
||||||
|
/*$obj_from_date = new \DateTime(date("Y-m-d", $from_time));
|
||||||
|
$obj_to_date = new \DateTime(date("Y-m-d", $to_time));
|
||||||
|
$day_diff = $obj_to_date->diff($obj_from_date)->format('%a');
|
||||||
|
|
||||||
|
$obj_to_date->add(new \DateInterval('P'.$day_diff.'D'));
|
||||||
|
$new_date = $obj_to_date->format('Y-m-d');
|
||||||
|
|
||||||
|
$current_date = date("Y-m-d");
|
||||||
|
$from_time_minute = ($from_time > 0) ? date("H:i", $from_time) : "00:00";
|
||||||
|
$to_time_minute = ($to_time > 0) ? date("H:i", $to_time) : "00:00";*/
|
||||||
|
|
||||||
|
$to_time_new = CURRENT_TIME + ($to_time - $from_time);
|
||||||
|
|
||||||
|
$auto_renew_history[] = [
|
||||||
|
"renew_time" => show_datetime_from_unix(CURRENT_TIME),
|
||||||
|
"from_time" => show_datetime_from_unix(CURRENT_TIME),
|
||||||
|
"to_time" => show_datetime_from_unix($to_time_new),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->updateFields( $id,
|
||||||
|
[
|
||||||
|
'from_time' => CURRENT_TIME,
|
||||||
|
'to_time' => $to_time_new,
|
||||||
|
'auto_renew_history' => serialize($auto_renew_history),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
48
inc/Hura8/Components/Deal/Controller/bDealController.php
Normal file
48
inc/Hura8/Components/Deal/Controller/bDealController.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Deal\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Deal\Model\DealModel;
|
||||||
|
use Hura8\Components\Product\AdminController\AProductController;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
class bDealController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $objDealModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objDealModel = new DealModel();
|
||||||
|
parent::__construct($this->objDealModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getList(array $condition) : array
|
||||||
|
{
|
||||||
|
$deal_list = parent::getList($condition);
|
||||||
|
|
||||||
|
$product_list_info = [];
|
||||||
|
$product_list_ids = [];
|
||||||
|
$final_list = [];
|
||||||
|
foreach ($deal_list as $item) {
|
||||||
|
if(!isset($product_list_info[$item['pro_id']])) {
|
||||||
|
$product_list_info[$item['pro_id']]= null;
|
||||||
|
$product_list_ids[] = $item['pro_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$copy = $item;
|
||||||
|
$copy['product_info'] = &$product_list_info[$item['pro_id']];
|
||||||
|
$final_list[] = $copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
$objAProductController = new AProductController();
|
||||||
|
foreach ($objAProductController->getListByIds($product_list_ids) as $pro_id => $info) {
|
||||||
|
$product_list_info[$pro_id] = $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $final_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
223
inc/Hura8/Components/Deal/Model/DealCollectionModel.php
Normal file
223
inc/Hura8/Components/Deal/Model/DealCollectionModel.php
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Deal\Model;
|
||||||
|
|
||||||
|
use Hura8\Components\Product\AdminController\AProductController;
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\TableName;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\System\TimeManager;
|
||||||
|
|
||||||
|
class DealCollectionModel extends aEntityBaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_deal = "tb_deal";
|
||||||
|
protected $tb_collection_item = "tb_deal_collection_item";
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('deal_collection');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function extendedFilterOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition): ?array
|
||||||
|
{
|
||||||
|
$where_clause = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
return [
|
||||||
|
join(" ", $where_clause),
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllProductIdInCollection($collection_id) {
|
||||||
|
$deal_id_list = $this->getAllDealIdInCollection($collection_id);
|
||||||
|
|
||||||
|
if(!sizeof($deal_id_list)) return array();
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT `pro_id` FROM `".$this->tb_deal."` WHERE `id` IN (". join(',', $deal_id_list).") ");
|
||||||
|
|
||||||
|
return array_map(function ($item){
|
||||||
|
return $item['pro_id'];
|
||||||
|
}, $this->db->fetchAll($query));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllDealIdInCollection($collection_id) {
|
||||||
|
$query = $this->db->runQuery("SELECT `deal_id` FROM `".$this->tb_collection_item."` WHERE `collection_id` = ? ", ['d'], [$collection_id]);
|
||||||
|
|
||||||
|
return array_map(function ($item){
|
||||||
|
return $item['deal_id'];
|
||||||
|
}, $this->db->fetchAll($query));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAllDealInCollection($collection_id, $price, $time){
|
||||||
|
|
||||||
|
$from_time = ($time['from_date'] != '') ? strtotime(TimeManager::convert_date_from_javascript($time['from_date'])." ".$time['from_time_minute'].":00") : 0;
|
||||||
|
$to_time = ($time['to_date'] != '') ? strtotime(TimeManager::convert_date_from_javascript($time['to_date'])." ".$time['to_time_minute'].":00") : 0;
|
||||||
|
|
||||||
|
$deal_id_list = $this->getAllDealIdInCollection($collection_id);
|
||||||
|
|
||||||
|
if(!sizeof($deal_id_list)) return false;
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT `id`, `pro_id` FROM `".$this->tb_deal."` WHERE `id` IN (". join(',', $deal_id_list).") ");
|
||||||
|
$product_list_id = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
$product_list_id[$info['pro_id']] = $info['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//get product prices
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
SELECT `id`, price FROM ".TableName::PRODUCT."
|
||||||
|
WHERE `id` IN (". join(',', array_keys($product_list_id)) .")
|
||||||
|
");
|
||||||
|
|
||||||
|
$objDealModel = new DealModel();
|
||||||
|
|
||||||
|
foreach ( $this->db->fetchAll($query) as $_info ) {
|
||||||
|
$product_id = $_info['id'];
|
||||||
|
$product_price = $_info['price'];
|
||||||
|
$deal_price = ($price['type'] == 'percent') ? round($product_price * (100 - $price['value']) / 100) : ($product_price - $price['value']);
|
||||||
|
|
||||||
|
//update
|
||||||
|
$objDealModel->updatePriceAndTime(
|
||||||
|
$product_list_id[$product_id],
|
||||||
|
array(
|
||||||
|
"price" => $deal_price,
|
||||||
|
"from_time" => $from_time,
|
||||||
|
"to_time" => $to_time,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addProductToCollection($product_id, $collection_id){
|
||||||
|
|
||||||
|
$objAProductController = new AProductController();
|
||||||
|
$product_info = $objAProductController->getInfo($product_id);
|
||||||
|
|
||||||
|
if($product_info){
|
||||||
|
|
||||||
|
$objDealModel = new DealModel();
|
||||||
|
|
||||||
|
$deal_id = $objDealModel->create(array(
|
||||||
|
"pro_id" => $product_id,
|
||||||
|
"title" => $product_info['title'],
|
||||||
|
"price" => $product_info['price'],
|
||||||
|
"quantity" => $product_info['quantity'],
|
||||||
|
"min_purchase" => 1,
|
||||||
|
"from_time" => 0,
|
||||||
|
"to_time" => 0,
|
||||||
|
"ordering" => $product_info[''],
|
||||||
|
"description" => '',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->addToCollection($deal_id, $collection_id);
|
||||||
|
|
||||||
|
return $deal_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeFromCollection($deal_id, $collection_id){
|
||||||
|
$this->db->runQuery(
|
||||||
|
"DELETE FROM `".$this->tb_collection_item."` WHERE `deal_id` = ? AND `collection_id` = ? ",
|
||||||
|
['d', 'd'],
|
||||||
|
[$deal_id, $collection_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->updateCollectionCount($collection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addToCollection($deal_id, $collection_id){
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `deal_id` FROM `".$this->tb_collection_item."` WHERE `deal_id`= ? AND `collection_id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'], [$deal_id, $collection_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if( ! $this->db->fetchAssoc($query) ){
|
||||||
|
$this->db->insert(
|
||||||
|
$this->tb_collection_item ,
|
||||||
|
[
|
||||||
|
'collection_id' => $collection_id ,
|
||||||
|
'deal_id' => $deal_id,
|
||||||
|
'create_by' => ADMIN_ID,
|
||||||
|
'create_time' => CURRENT_TIME,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->updateCollectionCount($collection_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateCollectionCount($collection_id){
|
||||||
|
$this->db->runQuery(
|
||||||
|
"UPDATE `".$this->tb_entity."` SET
|
||||||
|
`deal_count` = (SELECT COUNT(*) FROM `".$this->tb_collection_item."` WHERE `collection_id` = ? )
|
||||||
|
WHERE `id` = ? LIMIT 1 ",
|
||||||
|
['d', 'd'],
|
||||||
|
[$collection_id, $collection_id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCollectionView($id){
|
||||||
|
$this->db->runQuery("UPDATE `".$this->tb_entity."` SET `visit` = `visit` + 1 WHERE `id` = ? LIMIT 1 ", ['d'], [ $id ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||||
|
{
|
||||||
|
$info = $input_info;
|
||||||
|
|
||||||
|
$info['create_time'] = CURRENT_TIME;
|
||||||
|
$info['create_by'] = ADMIN_NAME;
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||||
|
{
|
||||||
|
// TODO: Implement afterCreateItem() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info) : AppResponse
|
||||||
|
{
|
||||||
|
$info = $new_input_info;
|
||||||
|
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||||
|
{
|
||||||
|
// TODO: Implement afterUpdateItem() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||||
|
{
|
||||||
|
return new AppResponse('ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterDeleteItem($item_id, $item_info)
|
||||||
|
{
|
||||||
|
// TODO: Implement afterDeleteItem() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
196
inc/Hura8/Components/Deal/Model/DealModel.php
Normal file
196
inc/Hura8/Components/Deal/Model/DealModel.php
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Deal\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\System\Security\DataValidator;
|
||||||
|
use Hura8\System\TimeManager;
|
||||||
|
|
||||||
|
class DealModel extends aEntityBaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_collection_item = "tb_deal_collection_item";
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('deal');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getAllAutoRenewableDeal() {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `id`, `from_time`, `to_time` FROM `". $this->tb_entity ."`
|
||||||
|
WHERE `to_time` < '".CURRENT_TIME."' AND `to_time` > 0 AND `auto_renew` = 1 "
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
|
||||||
|
$where_clause = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
$limit_by_time = false;
|
||||||
|
$limit_by_time_condition = '';
|
||||||
|
|
||||||
|
// get deal by start time
|
||||||
|
// require format: YY-mm-dd h:m:i or YY-mm-dd h:m or timestamp
|
||||||
|
$datetime_pattern = '/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\s[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2})?$/i';
|
||||||
|
|
||||||
|
if(isset($filter_condition['start_time']) && $filter_condition['start_time'] ) {
|
||||||
|
$limit_by_time = true;
|
||||||
|
if(preg_match($datetime_pattern, trim($filter_condition['start_time']))) {
|
||||||
|
$check_time = strtotime($filter_condition['start_time']);
|
||||||
|
}else{
|
||||||
|
$check_time = intval($filter_condition['start_time']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit_by_time_condition .= " AND `from_time` >= '".$check_time."' ";
|
||||||
|
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $check_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get deal by end time
|
||||||
|
// require format: YY-mm-dd h:m:i or YY-mm-dd h:m or timestamp
|
||||||
|
if(isset($filter_condition['end_time']) && $filter_condition['end_time'] ) {
|
||||||
|
$limit_by_time = true;
|
||||||
|
if(preg_match($datetime_pattern, trim($filter_condition['end_time']))) {
|
||||||
|
$check_time = strtotime($filter_condition['end_time']);
|
||||||
|
}else{
|
||||||
|
$check_time = intval($filter_condition['end_time']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit_by_time_condition .= " AND `to_time` <= '".$check_time."' ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $check_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($limit_by_time) {
|
||||||
|
$where_clause[] = " AND `status`= 1 ".$limit_by_time_condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
//type expire
|
||||||
|
if(isset($filter_condition['type']) && $filter_condition['type'] == 'expire' ) {
|
||||||
|
$where_clause[] = "AND `status`= 1 AND `to_time` < ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
//type active: might not have begun yet
|
||||||
|
if(isset($filter_condition['type']) && $filter_condition['type'] == 'active' && !$limit_by_time ) {
|
||||||
|
$where_clause[] = " AND `status` = 1 AND `to_time` >= ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Đang bắt đầu
|
||||||
|
if(isset($filter_condition['type']) && $filter_condition['type'] == 'started' && !$limit_by_time ) {
|
||||||
|
$where_clause[] = " AND `status` = 1 AND `to_time` >= ? AND from_time < ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chưa bắt đầu
|
||||||
|
if(isset($filter_condition['type']) && $filter_condition['type'] == 'coming' && !$limit_by_time ) {
|
||||||
|
$where_clause[] = " AND `status` = 1 AND `from_time` >= ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
//deal collection
|
||||||
|
if(isset($filter_condition['collection_id']) && $filter_condition['collection_id'] > 0) {
|
||||||
|
$where_clause[] = " AND `id` IN ( SELECT `deal_id` FROM `".$this->tb_collection_item."` WHERE `collection_id` = ? ) ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition['collection_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// exclude from collection
|
||||||
|
if(isset($filter_condition['add_to_collection']) && $filter_condition['add_to_collection'] > 0) {
|
||||||
|
$where_clause[] = " AND `id` NOT IN ( SELECT `deal_id` FROM `".$this->tb_collection_item."` WHERE `collection_id` = ? ) ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition['add_to_collection'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// by word filter
|
||||||
|
$filter = $filter_condition['filter'] ?? '';
|
||||||
|
switch ($filter) {
|
||||||
|
case "not-started": // Chưa bắt đầu
|
||||||
|
$where_clause[] = " AND ( ? - `from_time` ) < 0 ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "started": // Đang bắt đầu
|
||||||
|
$where_clause[] = " AND ( ? - `from_time` ) > 0 AND ( `to_time` - ?) > 0 ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "ended": // Hết thời gian
|
||||||
|
$where_clause[] = " AND (`to_time` - ?) < 0 ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = CURRENT_TIME;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "hidden": // Ẩn hiển thị
|
||||||
|
$where_clause[] = " AND `status` = 0 ";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "featured": // Đang nổi bật
|
||||||
|
$where_clause[] = " AND `is_featured` = 1 ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
join(" ", $where_clause),
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info): array
|
||||||
|
{
|
||||||
|
$copy = $item_info;
|
||||||
|
|
||||||
|
$copy['deal_time_happen'] = CURRENT_TIME - $item_info['from_time'];
|
||||||
|
$copy['deal_time_left'] = $item_info['to_time'] - CURRENT_TIME;
|
||||||
|
$copy['is_start'] = (CURRENT_TIME - $item_info['from_time'] > 0) ? 1 : 0;
|
||||||
|
$copy['is_end'] = ($item_info['to_time'] - CURRENT_TIME > 0) ? 0 : 1;
|
||||||
|
|
||||||
|
return $copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info): array
|
||||||
|
{
|
||||||
|
$copy = $item_info;
|
||||||
|
|
||||||
|
$copy['deal_time_happen'] = CURRENT_TIME - $item_info['from_time'];
|
||||||
|
$copy['deal_time_left'] = $item_info['to_time'] - CURRENT_TIME;
|
||||||
|
$copy['is_start'] = (CURRENT_TIME - $item_info['from_time'] > 0) ? 1 : 0;
|
||||||
|
$copy['is_end'] = ($item_info['to_time'] - CURRENT_TIME > 0) ? 0 : 1;
|
||||||
|
|
||||||
|
return $copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
130
inc/Hura8/Components/Marketing/Model/CouponModel.php
Normal file
130
inc/Hura8/Components/Marketing/Model/CouponModel.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
33
inc/Hura8/Components/Marketing/Model/PosterModel.php
Normal file
33
inc/Hura8/Components/Marketing/Model/PosterModel.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
126
inc/Hura8/Components/Marketing/Model/ProductFeedModel.php
Normal file
126
inc/Hura8/Components/Marketing/Model/ProductFeedModel.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Marketing\Model;
|
||||||
|
|
||||||
|
class UProductFeedModel
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Media\Controller\bItemMediaController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class AItemMediaController extends bItemMediaController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
// delete thumb files
|
||||||
|
$item_info = $this->getInfo($item_id);
|
||||||
|
if(!$item_info['file_url']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_name = $item_info['file_url'];
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $file_name;
|
||||||
|
@unlink($file_local_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove original file
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $file_name;
|
||||||
|
@unlink($file_local_path);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Media\Controller\bMediaCategoryController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminCategoryController;
|
||||||
|
use Hura8\Traits\AdminEntityCategoryControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class AMediaCategoryController extends bMediaCategoryController implements iEntityAdminCategoryController
|
||||||
|
{
|
||||||
|
use AdminEntityCategoryControllerTraits;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Media\Controller\bMediaController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class AMediaController extends bMediaController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
public static function createUploadSubFolder() {
|
||||||
|
return date("Y-m-d");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
// delete thumb files
|
||||||
|
$item_info = $this->getInfo($item_id);
|
||||||
|
if(!$item_info['file_url']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
list($sub_folder, $file_name) = explode("/", $item_info['file_url']); // format: Y-m-d/file_name
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/" . $sub_folder . "/". $size. IMAGE_FILE_SEPARATOR . $file_name;
|
||||||
|
@unlink($file_local_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove original file
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/" . $sub_folder . "/". $file_name;
|
||||||
|
@unlink($file_local_path);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Media\Model\ItemMediaModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class bItemMediaController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
static $image_folder = "media/item";
|
||||||
|
|
||||||
|
static $resized_sizes = array(
|
||||||
|
's' => ['width' => 300,]
|
||||||
|
);
|
||||||
|
|
||||||
|
/* @var ItemMediaModel $objItemMediaModel */
|
||||||
|
protected $objItemMediaModel;
|
||||||
|
|
||||||
|
protected $item_type;
|
||||||
|
protected $item_id;
|
||||||
|
|
||||||
|
public function __construct(string $item_type = '', $item_id = 0)
|
||||||
|
{
|
||||||
|
$this->objItemMediaModel = new ItemMediaModel($item_type, $item_id);
|
||||||
|
parent::__construct($this->objItemMediaModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info) : array
|
||||||
|
{
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info) : ?array
|
||||||
|
{
|
||||||
|
if(!$item_info) return null;
|
||||||
|
|
||||||
|
$item_info['display_file'] = STATIC_DOMAIN . "/". static::$image_folder. "/". $item_info['file_url'];
|
||||||
|
$item_info['image'] = self::getResizedImageCollection($item_info['file_url']);
|
||||||
|
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getResizedImageCollection($image_name) {
|
||||||
|
$image = [];
|
||||||
|
|
||||||
|
$size_in_full = [
|
||||||
|
's' => 'small' ,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$image[$size_in_full[$size]] = ($image_name) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $image_name : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Controller;
|
||||||
|
|
||||||
|
use Hura8\System\Controller\aCategoryBaseController;
|
||||||
|
use Hura8\Components\Media\Model\MediaCategoryModel;
|
||||||
|
|
||||||
|
|
||||||
|
class bMediaCategoryController extends aCategoryBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $objMediaCategoryModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objMediaCategoryModel = new MediaCategoryModel();
|
||||||
|
parent::__construct($this->objMediaCategoryModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
59
inc/Hura8/Components/Media/Controller/bMediaController.php
Normal file
59
inc/Hura8/Components/Media/Controller/bMediaController.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Controller;
|
||||||
|
|
||||||
|
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||||
|
use Hura8\Components\Media\Model\MediaModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
|
||||||
|
class bMediaController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
static $image_folder = "media/lib";
|
||||||
|
|
||||||
|
static $resized_sizes = array(
|
||||||
|
's' => ['width' => 300,]
|
||||||
|
);
|
||||||
|
|
||||||
|
protected $objMediaModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objMediaModel = new MediaModel();
|
||||||
|
parent::__construct($this->objMediaModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info) : array
|
||||||
|
{
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info) : ?array
|
||||||
|
{
|
||||||
|
if(!$item_info) return null;
|
||||||
|
|
||||||
|
$item_info['display_file'] = STATIC_DOMAIN . "/". static::$image_folder. "/". $item_info['file_url'];
|
||||||
|
$item_info['image'] = ($item_info['file_type'] == 'image') ? self::getResizedImageCollection($item_info['file_url']) : null;
|
||||||
|
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getResizedImageCollection($image_name) {
|
||||||
|
$image = [];
|
||||||
|
|
||||||
|
$size_in_full = [
|
||||||
|
's' => 'small' ,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$image[$size_in_full[$size]] = ($image_name) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $image_name : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
76
inc/Hura8/Components/Media/Model/ItemMediaModel.php
Normal file
76
inc/Hura8/Components/Media/Model/ItemMediaModel.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\System\Url;
|
||||||
|
|
||||||
|
|
||||||
|
class ItemMediaModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $item_type;
|
||||||
|
protected $item_id;
|
||||||
|
|
||||||
|
public function __construct(string $item_type = '', $item_id = 0) {
|
||||||
|
parent::__construct('item-media');
|
||||||
|
|
||||||
|
$this->item_type = $item_type;
|
||||||
|
$this->item_id = $item_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
if($this->item_type) {
|
||||||
|
$catCondition[] = " AND `item_type` = ? ";
|
||||||
|
$bind_types[] = 's';
|
||||||
|
$bind_values[] = $this->item_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->item_id) {
|
||||||
|
$catCondition[] = " AND `item_id` = ? ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $this->item_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($filter_condition["item_type"]) && $filter_condition["item_type"]){
|
||||||
|
$catCondition[] = " AND `item_type` = ? ";
|
||||||
|
$bind_types[] = 's';
|
||||||
|
$bind_values[] = $filter_condition["item_type"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($filter_condition["item_id"]) && $filter_condition["item_id"]){
|
||||||
|
$catCondition[] = " AND `item_id` = ? ";
|
||||||
|
$bind_types[] = 's';
|
||||||
|
$bind_values[] = $filter_condition["item_id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($filter_condition["file_type"]) && $filter_condition["file_type"]){
|
||||||
|
$catCondition[] = " AND `file_type` = ? ";
|
||||||
|
$bind_types[] = 's';
|
||||||
|
$bind_values[] = $filter_condition["file_type"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
34
inc/Hura8/Components/Media/Model/ItemMediaSearchModel.php
Normal file
34
inc/Hura8/Components/Media/Model/ItemMediaSearchModel.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\Model\aSearchBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class ItemMediaSearchModel extends aSearchBaseModel implements iSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
private $filter_fields = [
|
||||||
|
'item_type' => "tb_item_media.item_type",
|
||||||
|
'item_id' => "tb_item_media.item_id",
|
||||||
|
'file_type' => "tb_item_media.file_type",
|
||||||
|
];
|
||||||
|
|
||||||
|
private $fulltext_fields = [
|
||||||
|
"keywords" => ["tb_item_media.title",],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
"tb_item_media",
|
||||||
|
$this->fulltext_fields,
|
||||||
|
$this->filter_fields
|
||||||
|
);
|
||||||
|
|
||||||
|
//$this->createTableSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
20
inc/Hura8/Components/Media/Model/MediaCategoryModel.php
Normal file
20
inc/Hura8/Components/Media/Model/MediaCategoryModel.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aCategoryBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityCategoryModel;
|
||||||
|
|
||||||
|
|
||||||
|
class MediaCategoryModel extends aCategoryBaseModel implements iEntityCategoryModel
|
||||||
|
{
|
||||||
|
protected $tb_media_per_category = "tb_media_per_category";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct('media-category');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
61
inc/Hura8/Components/Media/Model/MediaModel.php
Normal file
61
inc/Hura8/Components/Media/Model/MediaModel.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\System\Url;
|
||||||
|
|
||||||
|
|
||||||
|
class MediaModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_media_per_category = "tb_media_per_category";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::MEDIA, '', new MediaSearchModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
"category" => getRequestInt("category"),
|
||||||
|
"file_type" => '',
|
||||||
|
);*/
|
||||||
|
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
|
||||||
|
//Tim danh muc
|
||||||
|
if(isset($filter_condition["category"]) && $filter_condition["category"]){
|
||||||
|
$catCondition[] = " AND `id` IN (SELECT `item_id` FROM `".$this->tb_media_per_category."` WHERE `category_id` = ?) ";
|
||||||
|
$bind_types[] = 'd';
|
||||||
|
$bind_values[] = $filter_condition["category"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($filter_condition["file_type"]) && $filter_condition["file_type"]){
|
||||||
|
$catCondition[] = " AND `file_type` = ? ";
|
||||||
|
$bind_types[] = 's';
|
||||||
|
$bind_values[] = $filter_condition["file_type"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
32
inc/Hura8/Components/Media/Model/MediaSearchModel.php
Normal file
32
inc/Hura8/Components/Media/Model/MediaSearchModel.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Media\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\Model\aSearchBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class MediaSearchModel extends aSearchBaseModel implements iSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
private $filter_fields = [
|
||||||
|
'file_type' => "tb_media.file_type",
|
||||||
|
];
|
||||||
|
|
||||||
|
private $fulltext_fields = [
|
||||||
|
"keywords" => ["tb_media.title",],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
"tb_media",
|
||||||
|
$this->fulltext_fields,
|
||||||
|
$this->filter_fields
|
||||||
|
);
|
||||||
|
|
||||||
|
//$this->createTableSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
235
inc/Hura8/Components/Order/AdminController/AOrderController.php
Normal file
235
inc/Hura8/Components/Order/AdminController/AOrderController.php
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Order\AdminController;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Components\Order\Controller\OrderStatus;
|
||||||
|
use Hura8\Components\Order\Model\OrderModel;
|
||||||
|
use Hura8\Events\EventName;
|
||||||
|
use Hura8\Events\RealEvents\OrderEvent;
|
||||||
|
use Hura8\System\Controller\aAdminEntityBaseController;
|
||||||
|
|
||||||
|
class AOrderController extends aAdminEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var OrderModel $objOrderModel */
|
||||||
|
protected $objOrderModel;
|
||||||
|
|
||||||
|
/* @var AOrderStatusController $objAOrderStatusController */
|
||||||
|
protected $objAOrderStatusController;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objAOrderStatusController = new AOrderStatusController();
|
||||||
|
$this->objOrderModel = new OrderModel();
|
||||||
|
parent::__construct($this->objOrderModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateOrderFulfillmentStatus($order_id, $new_status, $comment, $payment_data = []) {
|
||||||
|
|
||||||
|
if(!array_key_exists($new_status, OrderStatus::FULFILLMENT_STATUS)) {
|
||||||
|
return [
|
||||||
|
"status" => 'error',
|
||||||
|
'message' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->objAOrderStatusController->createHistory($order_id, 'fulfillment', $new_status, $comment, $payment_data );
|
||||||
|
|
||||||
|
//cap nhat don hang
|
||||||
|
$this->objOrderModel->update( $order_id, [
|
||||||
|
'fulfillment_status' => $new_status
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->updateDerivedOrderStatus($order_id);
|
||||||
|
|
||||||
|
return [
|
||||||
|
"status" => 'success',
|
||||||
|
'message' => 'Cập nhật thành công',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateOrderPaymentStatus($order_id, $new_status, $comment, $payment_data = []) {
|
||||||
|
|
||||||
|
if(!array_key_exists($new_status, OrderStatus::PAYMENT_STATUS)) {
|
||||||
|
return [
|
||||||
|
"status" => 'error',
|
||||||
|
'message' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->objAOrderStatusController->createHistory($order_id, 'payment', $new_status, $comment, $payment_data );
|
||||||
|
|
||||||
|
//cap nhat don hang
|
||||||
|
$this->objOrderModel->update( $order_id, [
|
||||||
|
'payment_status' => $new_status
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->updateDerivedOrderStatus($order_id);
|
||||||
|
|
||||||
|
return [
|
||||||
|
"status" => 'success',
|
||||||
|
'message' => 'Cập nhật thành công',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateDerivedOrderStatus($order_id) {
|
||||||
|
|
||||||
|
$current_info = $this->getInfo($order_id);
|
||||||
|
|
||||||
|
// order must be success
|
||||||
|
if(
|
||||||
|
$current_info['payment_status'] == OrderStatus::PAYMENT_STATUS['paid']['id'] &&
|
||||||
|
$current_info['fulfillment_status'] == OrderStatus::FULFILLMENT_STATUS['fulfilled']['id']
|
||||||
|
) {
|
||||||
|
|
||||||
|
return $this->objOrderModel->update($order_id, [
|
||||||
|
'order_status' => OrderStatus::ORDER_STATUS['success']['id']
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update processing
|
||||||
|
return $this->objOrderModel->update($order_id, [
|
||||||
|
'order_status' => OrderStatus::ORDER_STATUS['processing']['id']
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateOrderStatus($order_id, $status, $comment) {
|
||||||
|
|
||||||
|
$current_info = $this->getInfo($order_id);
|
||||||
|
|
||||||
|
// cannot update if order has: success or cancel
|
||||||
|
if(in_array($current_info['order_status'], [
|
||||||
|
OrderStatus::ORDER_STATUS['success']['id'],
|
||||||
|
OrderStatus::ORDER_STATUS['canceled']['id'],
|
||||||
|
])) {
|
||||||
|
return [
|
||||||
|
"status" => 'error',
|
||||||
|
'message' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!array_key_exists($status, OrderStatus::ORDER_STATUS)) {
|
||||||
|
return [
|
||||||
|
"status" => 'error',
|
||||||
|
'message' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->objAOrderStatusController->createHistory($order_id, 'order', $status, $comment );
|
||||||
|
|
||||||
|
$this->objOrderModel->update($order_id, [
|
||||||
|
'order_status' => $status
|
||||||
|
]);
|
||||||
|
|
||||||
|
// dispatch
|
||||||
|
$objOrderEvent = new OrderEvent();
|
||||||
|
$objOrderEvent->setUpdateOrderInfo([
|
||||||
|
'orderId' => $order_id,
|
||||||
|
'order_status' => $status,
|
||||||
|
'old_status' => $current_info['order_status']
|
||||||
|
]);
|
||||||
|
get_dispatcher()->dispatch(EventName::ORDER['updated_status'], $objOrderEvent);
|
||||||
|
|
||||||
|
return [
|
||||||
|
"status" => 'success',
|
||||||
|
'message' => 'Cập nhật thành công',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $order_info ) {
|
||||||
|
|
||||||
|
$rs = $order_info;
|
||||||
|
|
||||||
|
$rs["order_date"] = date("d-m-Y", $rs['order_time']);
|
||||||
|
$rs["order_hour"] = date("h:i a", $rs['order_time']);
|
||||||
|
|
||||||
|
if($rs['order_discount']) $rs['order_discount'] = \json_decode($rs['order_discount'], true);
|
||||||
|
|
||||||
|
$rs["payment_status_name"] = (array_key_exists($rs["payment_status"], OrderStatus::PAYMENT_STATUS)) ? OrderStatus::PAYMENT_STATUS[$rs["payment_status"]]['title'] : '';
|
||||||
|
|
||||||
|
$rs["fulfillment_status_name"] = (array_key_exists($rs["fulfillment_status"], OrderStatus::FULFILLMENT_STATUS)) ? OrderStatus::FULFILLMENT_STATUS[$rs["fulfillment_status"]]['title'] : '';
|
||||||
|
|
||||||
|
$rs["order_status_name"] = (array_key_exists($rs["order_status"], OrderStatus::ORDER_STATUS)) ? OrderStatus::ORDER_STATUS[$rs["order_status"]]['title'] : '';
|
||||||
|
|
||||||
|
return $rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getListFilterCondition($list_id) {
|
||||||
|
|
||||||
|
if($list_id == 'mine') {
|
||||||
|
return [
|
||||||
|
'assign_to' => ADMIN_ID,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'new') {
|
||||||
|
return [
|
||||||
|
'status' => 'new',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'unpaid') {
|
||||||
|
return [
|
||||||
|
'payment' => 'unpaid',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'partially-paid') {
|
||||||
|
return [
|
||||||
|
'payment' => 'partially-paid',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'unfulfilled') {
|
||||||
|
return [
|
||||||
|
'fullfillment' => 'unfulfilled',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'partially-fulfilled') {
|
||||||
|
return [
|
||||||
|
'fullfillment' => 'partially-fulfilled',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusHistory($orderId){
|
||||||
|
|
||||||
|
return $this->objAOrderStatusController->getStatusHistory($orderId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItemsForOrderList(array $list_ids, $fields = "*") {
|
||||||
|
|
||||||
|
return $this->objOrderModel->getItemsForOrderList($list_ids, $fields);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createId($order_id){
|
||||||
|
$key_length = strlen($order_id);
|
||||||
|
|
||||||
|
$order_keys = [];
|
||||||
|
for($i=0; $i < 9 - $key_length; $i++){
|
||||||
|
$order_keys[] = "0";
|
||||||
|
}
|
||||||
|
$order_keys[] = $order_id;
|
||||||
|
|
||||||
|
$order_eles = str_split(join("", $order_keys), 3);
|
||||||
|
|
||||||
|
return join("-", $order_eles);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Order\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Order\Model\OrderStatusModel;
|
||||||
|
|
||||||
|
class AOrderStatusController
|
||||||
|
{
|
||||||
|
/* @var OrderStatusModel $objOrderStatusModel */
|
||||||
|
protected $objOrderStatusModel;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objOrderStatusModel = new OrderStatusModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusHistory($orderId){
|
||||||
|
return $this->objOrderStatusModel->getStatusHistory($orderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createHistory($order_id, $status_type = 'order', $system_status = '', $comment = '', array $data= [], array $other_info = []) {
|
||||||
|
return $this->objOrderStatusModel->createHistory($order_id, $status_type , $system_status , $comment, $data, $other_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfo($status_id) {
|
||||||
|
return $this->objOrderStatusModel->getInfo($status_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAll() {
|
||||||
|
return $this->objOrderStatusModel->getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id) {
|
||||||
|
return $this->objOrderStatusModel->delete($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id, array $info) {
|
||||||
|
return $this->objOrderStatusModel->update($id, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(array $info) {
|
||||||
|
return $this->objOrderStatusModel->create($info);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
inc/Hura8/Components/Order/Controller/OrderStatus.php
Normal file
43
inc/Hura8/Components/Order/Controller/OrderStatus.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// https://help.shopify.com/en/manual/orders/order-status
|
||||||
|
|
||||||
|
namespace Hura8\Components\Order\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
class OrderStatus
|
||||||
|
{
|
||||||
|
|
||||||
|
const ORDER_STATUS = [
|
||||||
|
'new' => ['id' => 'new', 'title' => 'Mới'],// 'Mới', //
|
||||||
|
'processing' => ['id' => 'processing', 'title' => 'Đang xử lý'],// 'Đang xử lý', //
|
||||||
|
'success' => ['id' => 'success', 'title' => 'Thành công'],// 'Thành công', //
|
||||||
|
'closed' => ['id' => 'closed', 'title' => 'Đóng lại'],// 'Đóng lại', //
|
||||||
|
//'archived' => 'Lưu kho', //
|
||||||
|
'canceled' => ['id' => 'canceled', 'title' => 'Hủy'],// 'Hủy', //
|
||||||
|
];
|
||||||
|
|
||||||
|
const PAYMENT_STATUS = [
|
||||||
|
'pending' => ['id' => 'pending', 'title' => 'Chờ'],// 'Chờ', // Orders have the Payment pending status for one of the following reasons: During checkout, You create an order, Manual payment methods, such as Cash On Delivery
|
||||||
|
'authorized' => ['id' => 'authorized', 'title' => 'Đã xác nhận'],// 'Đã xác nhận', // The payment provider validated your customer’s payment information. The order is created, customers can complete their checkout, and inventory is reserved.
|
||||||
|
'overdue' => ['id' => 'overdue', 'title' => 'Quá hạn'],// 'Quá hạn', // Payment wasn't captured before the due date that was set in the payment terms on an order that had the Payment pending status.
|
||||||
|
'expiring' => ['id' => 'expiring', 'title' => 'Sắp hết hạn'],// 'Sắp hết hạn', // Expiring isn't a payment status, but the Expiring badge is displayed two days before the deadline for capturing payment on orders that have the Authorized payment status.
|
||||||
|
'expired' => ['id' => 'expired', 'title' => 'Hết hạn'],// 'Hết hạn', // Payment wasn't captured before the date that was set by the payment provider on an order that had the Authorized payment status.
|
||||||
|
'paid' => ['id' => 'paid', 'title' => 'Đã thanh toán'],// 'Đã thanh toán', // Payment was automatically or manually captured, or the order was marked as paid.
|
||||||
|
'refunded' => ['id' => 'refunded', 'title' => 'Đã hoàn lại'],// 'Đã hoàn lại', // The full amount that the customer paid for an order was returned to the customer.
|
||||||
|
'partially-refunded' => ['id' => 'partially-refunded', 'title' => 'Hoàn lại 1 phần'],// 'Hoàn lại 1 phần', // The amount that was returned to a customer is less than the full amount that the customer paid for an order.
|
||||||
|
'partially-paid' => ['id' => 'partially-paid', 'title' => 'Thanh toán 1 phần'],// 'Thanh toán 1 phần', // You manually captured payment for the order and specified less than the full order value as the payment amount.
|
||||||
|
'voided' => ['id' => 'voided', 'title' => 'Hủy'],// 'Hủy', // An unpaid order was manually canceled.
|
||||||
|
'unpaid' => ['id' => 'unpaid', 'title' => 'Chưa thanh toán'],// 'Chưa thanh toán', // Unpaid payment status includes orders that are in Authorized, Pending, Expired, and Partially paid payment status.
|
||||||
|
];
|
||||||
|
|
||||||
|
const FULFILLMENT_STATUS = [
|
||||||
|
'fulfilled' => ['id' => 'fulfilled', 'title' => 'Đã chuyển hết'],// 'Đã chuyển hết', // When you've shipped all the items in an order, it is Fulfilled.
|
||||||
|
'unfulfilled' => ['id' => 'unfulfilled', 'title' => 'Chưa chuyển'],// 'Chưa chuyển', // When an order is placed, it has an Unfulfilled fulfillment status, unless you have selected to automatically capture the payment and automatically fulfill all of the order's line items in the checkout settings.
|
||||||
|
'partially-fulfilled' => ['id' => 'partially-fulfilled', 'title' => 'Chuyển 1 phần'],// 'Chuyển 1 phần', // If you have shipped some, but not all, of the items in an order, then the order has a Partially fulfilled fulfillment status.
|
||||||
|
'scheduled' => ['id' => 'scheduled', 'title' => 'Đã lên kế hoạch'],// 'Đã lên kế hoạch', // Prepaid subscription orders have a Scheduled status until the fulfillment date is reached
|
||||||
|
'onhold ' => ['id' => 'onhold', 'title' => 'Giữ hàng'],// 'Giữ hàng', // When upsell offers are presented to customers at checkout, the order fulfillment status is set to On hold temporarily. When a fulfillment is On hold you can reserve inventory for the order, but you can't fulfill the order until the fulfillment hold is released, and the order fulfillment status changes to Unfulfilled.
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
557
inc/Hura8/Components/Order/Model/OrderModel.php
Normal file
557
inc/Hura8/Components/Order/Model/OrderModel.php
Normal file
@@ -0,0 +1,557 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Order\Model;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Components\Order\Controller\OrderStatus;
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\System\Security\DataClean;
|
||||||
|
use Hura8\System\Security\DataType;
|
||||||
|
use Hura8\System\TimeManager;
|
||||||
|
use Hura8\System\Url;
|
||||||
|
|
||||||
|
class OrderModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $tb_order_detail = "tb_order_detail";
|
||||||
|
|
||||||
|
/* @var iSearch $objSearchModel */
|
||||||
|
protected $objSearchModel;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
|
||||||
|
$this->objSearchModel = new OrderSearchModel();
|
||||||
|
|
||||||
|
parent::__construct(EntityType::ORDER, '', $this->objSearchModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getItems($orderId, $fields = "*") {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
" SELECT ".$fields." FROM `".$this->tb_order_detail."` WHERE `order_id` = ? ",
|
||||||
|
['d'], [ $orderId ]);
|
||||||
|
|
||||||
|
$order_item = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||||
|
|
||||||
|
$item_info = ($info["item_info"]) ? \json_decode($info["item_info"], true) : false;
|
||||||
|
$in_cart = ($info["in_cart"]) ? \json_decode($info["in_cart"], true) : false;
|
||||||
|
|
||||||
|
|
||||||
|
$info['item_info'] = $item_info;
|
||||||
|
$info['in_cart'] = $in_cart;
|
||||||
|
|
||||||
|
$order_item[] = $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
//since we save the entire cart-structure for item_info, we need to re-construct it to make it easier to read and for various reporting/ email etc..
|
||||||
|
protected function buildOrderItemInfo($item_type, array $item_info) {
|
||||||
|
$new_info = [];
|
||||||
|
|
||||||
|
if($item_type == 'product') {
|
||||||
|
|
||||||
|
$new_info = System::stripProperty(array($item_info['info']), [
|
||||||
|
"variant_option",
|
||||||
|
'id',
|
||||||
|
'productId',
|
||||||
|
'priceUnit',
|
||||||
|
'price',
|
||||||
|
'currency',
|
||||||
|
'lastUpdate',
|
||||||
|
'warranty',
|
||||||
|
'productName',
|
||||||
|
'productUrl',
|
||||||
|
'productModel',
|
||||||
|
'productSummary',
|
||||||
|
'marketPrice',
|
||||||
|
'productImage',
|
||||||
|
'brand',
|
||||||
|
'visit',
|
||||||
|
'rating',
|
||||||
|
'reviewCount',
|
||||||
|
'quantity',
|
||||||
|
'productSKU',
|
||||||
|
'hasVAT',
|
||||||
|
'condition',
|
||||||
|
'specialOffer',
|
||||||
|
'specialOfferGroup',
|
||||||
|
'productType',
|
||||||
|
'thum_poster',
|
||||||
|
'promotion_price',
|
||||||
|
'addon'
|
||||||
|
])[0];
|
||||||
|
|
||||||
|
//find variants bought
|
||||||
|
if($new_info['config_count'] > 0) {
|
||||||
|
|
||||||
|
foreach ($item_info['in_cart'] as $_variant) {
|
||||||
|
$new_info['variants'][] = array(
|
||||||
|
"id" => $_variant['id'],
|
||||||
|
"sku" => $_variant['sku'],
|
||||||
|
"title" => $_variant['name'],
|
||||||
|
"image" => ($_variant['image']) ? $_variant['image'] : $item_info['info']['productImage']["medium"],
|
||||||
|
"url" => $item_info['info']['productUrl'],
|
||||||
|
"attribute" => $_variant['attribute'],
|
||||||
|
"price" => $_variant['price'],
|
||||||
|
"addon_total" => 0,
|
||||||
|
"currency" => $item_info['info']['currency'],
|
||||||
|
"priceUnit" => $item_info['info']['priceUnit'],
|
||||||
|
"quantity" => $_variant['quantity'],
|
||||||
|
"buyer_note" => $_variant['buyer_note'],
|
||||||
|
"addon" => [],
|
||||||
|
"promotion" => [
|
||||||
|
"list" => $item_info['info']['specialOffer'],
|
||||||
|
"group" => (isset($_variant['promotion'])) ? $this->buildPromotionFromGroup( $item_info['info']['specialOfferGroup'], $_variant['promotion']) : $this->buildPromotionFromGroup( $item_info['info']['specialOfferGroup'], array() ),
|
||||||
|
],
|
||||||
|
//..any other
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
//product does not have variant
|
||||||
|
$build_addon = [];
|
||||||
|
$total_addon_price = 0;
|
||||||
|
if(isset($item_info['info']['addon']) && isset($item_info['in_cart'][0]['addon'])) {
|
||||||
|
$build_addon = $this->getSelectedAddon($item_info['info']['addon'], $item_info['in_cart'][0]['addon']);
|
||||||
|
foreach ($build_addon as $addon) {
|
||||||
|
$total_addon_price += $addon['price'] * $addon['quantity'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$variant_in_cart = (isset($item_info['in_cart'][0])) ? $item_info['in_cart'][0] : false;
|
||||||
|
|
||||||
|
$new_info['variants'][] = array(
|
||||||
|
"id" => 0,
|
||||||
|
"sku" => $item_info['info']['productSKU'],
|
||||||
|
"title" => $item_info['info']['productName'],
|
||||||
|
"image" => $item_info['info']['productImage']["medium"],
|
||||||
|
"url" => $item_info['info']['productUrl'],
|
||||||
|
"attribute" => [],
|
||||||
|
"price" => $item_info['info']['price'],
|
||||||
|
"addon_total" => $total_addon_price,
|
||||||
|
"currency" => $item_info['info']['currency'],
|
||||||
|
"priceUnit" => $item_info['info']['priceUnit'],
|
||||||
|
"quantity" => $variant_in_cart['quantity'],
|
||||||
|
"buyer_note" => $variant_in_cart['buyer_note'],
|
||||||
|
"addon" => $build_addon,
|
||||||
|
"promotion" => [
|
||||||
|
"list" => $item_info['info']['specialOffer'],
|
||||||
|
"group" => (isset($variant_in_cart['promotion'])) ? $this->buildPromotionFromGroup( $item_info['info']['specialOfferGroup'], $variant_in_cart['promotion']) : $this->buildPromotionFromGroup( $item_info['info']['specialOfferGroup'], array() ),
|
||||||
|
],
|
||||||
|
//..any other
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return $new_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($item_type == 'combo') {
|
||||||
|
|
||||||
|
$new_info = [
|
||||||
|
"price" => $item_info['info']['sale_price'],
|
||||||
|
"quantity" => $item_info['in_cart']['quantity'],
|
||||||
|
"buyer_note" => $item_info['in_cart']['buyer_note'],
|
||||||
|
"url" => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
$new_info['product_list'] = System::stripProperty($item_info['info']['product_list'], [
|
||||||
|
"variant_option",
|
||||||
|
'id',
|
||||||
|
'productId',
|
||||||
|
'priceUnit',
|
||||||
|
'price',
|
||||||
|
'currency',
|
||||||
|
'lastUpdate',
|
||||||
|
'warranty',
|
||||||
|
//'productName',
|
||||||
|
//'productUrl',
|
||||||
|
//'productModel',
|
||||||
|
'productSummary',
|
||||||
|
'marketPrice',
|
||||||
|
'productImage',
|
||||||
|
'brand',
|
||||||
|
'visit',
|
||||||
|
'rating',
|
||||||
|
'reviewCount',
|
||||||
|
'config_count',
|
||||||
|
'quantity',
|
||||||
|
//'productSKU',
|
||||||
|
'hasVAT',
|
||||||
|
'condition',
|
||||||
|
'specialOffer',
|
||||||
|
'specialOfferGroup',
|
||||||
|
'productType',
|
||||||
|
'thum_poster',
|
||||||
|
'promotion_price',
|
||||||
|
'addon',
|
||||||
|
'imageCollection',
|
||||||
|
'variants'
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $new_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($item_type == 'deal') {
|
||||||
|
|
||||||
|
$new_info = [
|
||||||
|
"price" => $item_info['info']['price'],
|
||||||
|
"quantity" => $item_info['in_cart']['quantity'],
|
||||||
|
"buyer_note" => $item_info['in_cart']['buyer_note'],
|
||||||
|
"url" => '/deal/'.$item_info['info']['id'],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $new_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getSelectedAddon($all_product_addons, $in_cart) {
|
||||||
|
|
||||||
|
if(!is_array($all_product_addons) || !is_array($in_cart)) return [];
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
foreach ($all_product_addons as $item) {
|
||||||
|
foreach ($in_cart as $selected) {
|
||||||
|
if($item['addon_id'] == $selected['id']) {
|
||||||
|
$result[] = [
|
||||||
|
"id" => $selected['id'],
|
||||||
|
"title" => $item['title'],
|
||||||
|
"price" => $item['price'],
|
||||||
|
"quantity" => (isset($selected['quantity'])) ? intval($selected['quantity']) : 1,
|
||||||
|
"related_article_url" => $item['related_article_url'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildPromotionFromGroup( $offer_group, $selected_one_promotion) {
|
||||||
|
|
||||||
|
if(!is_array($offer_group) && !is_array($selected_one_promotion)) return false;
|
||||||
|
|
||||||
|
$promotion = [];
|
||||||
|
|
||||||
|
foreach ($offer_group as $group) {
|
||||||
|
if($group['type'] == 'one') {
|
||||||
|
|
||||||
|
$selected_promotion = [];
|
||||||
|
foreach ($group['promotion'] as $promo) {
|
||||||
|
foreach ($selected_one_promotion as $selected) {
|
||||||
|
if($selected['promotion_id'] == $promo['id'] && $selected['group_id'] == $group['id']) {
|
||||||
|
$selected_promotion[] = $promo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$promotion[] = [
|
||||||
|
"id" => $group['id'],
|
||||||
|
"title" => $group['title'],
|
||||||
|
"note" => $group['note'],
|
||||||
|
"promotion" => $selected_promotion,
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$promotion[] = [
|
||||||
|
"id" => $group['id'],
|
||||||
|
"title" => $group['title'],
|
||||||
|
"note" => $group['note'],
|
||||||
|
"promotion" => $group['promotion'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $promotion;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function getListFilterCondition($list_id) {
|
||||||
|
|
||||||
|
if($list_id == 'mine') {
|
||||||
|
return [
|
||||||
|
'assign_to' => ADMIN_ID,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'new') {
|
||||||
|
return [
|
||||||
|
'status' => 'new',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'unpaid') {
|
||||||
|
return [
|
||||||
|
'payment' => 'unpaid',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'partially-paid') {
|
||||||
|
return [
|
||||||
|
'payment' => 'partially-paid',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'unfulfilled') {
|
||||||
|
return [
|
||||||
|
'fullfillment' => 'unfulfilled',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($list_id == 'partially-fulfilled') {
|
||||||
|
return [
|
||||||
|
'fullfillment' => 'partially-fulfilled',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusHistory($orderId){
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
select * from ".TB_ORDER_STATUS_HISTORY."
|
||||||
|
WHERE order_id = ?
|
||||||
|
order by id desc
|
||||||
|
limit 100
|
||||||
|
", ['d'], [ $orderId ] ) ;
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItemsForOrderList(array $list_ids, $fields = "*") {
|
||||||
|
|
||||||
|
if(!sizeof($list_ids)) return [];
|
||||||
|
|
||||||
|
list($parameterized_ids, $bind_types) = create_bind_sql_parameter_from_value_list($list_ids, 'int');
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
SELECT ".$fields." FROM `".$this->tb_order_detail."`
|
||||||
|
WHERE `order_id` IN (".$parameterized_ids.")
|
||||||
|
", $bind_types, $list_ids);
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $rs ) {
|
||||||
|
|
||||||
|
$item_info = unserialize($rs['item_info']);
|
||||||
|
if( isset($item_info["info"]) && isset($item_info["in_cart"])) {
|
||||||
|
$rs['item_info'] = $this->buildOrderItemInfo($rs['item_type'], $item_info );
|
||||||
|
} else {
|
||||||
|
$rs['item_info'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[$rs['order_id']][] = $rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $conditions) : ?array
|
||||||
|
{
|
||||||
|
$catCondition = [];
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
/*
|
||||||
|
$conditions = array(
|
||||||
|
'orderCode' => '',
|
||||||
|
'query' => '',
|
||||||
|
'coupon' => '',
|
||||||
|
'cus_id' => '',
|
||||||
|
'province' => '',
|
||||||
|
'district' => '',
|
||||||
|
'folder' => '',
|
||||||
|
'view_status' => '',
|
||||||
|
'update_by' => '',
|
||||||
|
'shipping_status' => '',
|
||||||
|
'assign_to' => '',
|
||||||
|
'from_date' => '',
|
||||||
|
'to_date' => '',
|
||||||
|
'from_hour' => '',
|
||||||
|
'to_hour' => '',
|
||||||
|
'excluded_ids' => '',
|
||||||
|
'included_ids' => '',
|
||||||
|
'payment' => '',
|
||||||
|
'fullfillment' => '',
|
||||||
|
'list' => '',
|
||||||
|
);*/
|
||||||
|
|
||||||
|
|
||||||
|
// merge with special list
|
||||||
|
if(isset($conditions['list']) && $conditions['list']) {
|
||||||
|
$list_condition = $this->getListFilterCondition($conditions['list']);
|
||||||
|
if($list_condition) {
|
||||||
|
// update and over-write any key in $conditions if exist
|
||||||
|
foreach ($list_condition as $key => $value) {
|
||||||
|
$conditions[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['orderCode']) && $conditions['orderCode']) {
|
||||||
|
$orderCode = DataClean::makeInputSafe($conditions['orderCode'],DataType::INTEGER);
|
||||||
|
$catCondition[] = " AND `orderId` LIKE '".$orderCode."%' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['coupon']) && $conditions['coupon']) {
|
||||||
|
$coupon = preg_replace("/[^a-z0-9_\-\.]/i","", $conditions['coupon']);
|
||||||
|
if($coupon) $catCondition[] = " AND ( LENGTH(`order_discount`) > 10 AND `order_discount` LIKE '%".$coupon."%' ) ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['cus_id']) && $conditions['cus_id']) {
|
||||||
|
$catCondition[] = " AND buyerId = '".intval($conditions['cus_id'])."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['province']) && $conditions['province']) {
|
||||||
|
$catCondition[] = " AND province = '".intval($conditions['province'])."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['district']) && $conditions['district']) {
|
||||||
|
$catCondition[] = " AND district = '".intval($conditions['district'])."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['folder']) && $conditions['folder']) {
|
||||||
|
$catCondition[] = " AND `folder` = '". preg_replace("/[^a-z0-9_\-\.]/i", "", $conditions['folder'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['payment']) && array_key_exists($conditions['payment'], OrderStatus::PAYMENT_STATUS ) ) {
|
||||||
|
$catCondition[] = " AND `payment_status` = '". $this->db->escape($conditions['payment'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['fullfillment']) && array_key_exists($conditions['fullfillment'], OrderStatus::FULFILLMENT_STATUS) ) {
|
||||||
|
$catCondition[] = " AND `fulfillment_status` = '". $this->db->escape($conditions['fullfillment'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['status']) && array_key_exists($conditions['status'], OrderStatus::ORDER_STATUS) ) {
|
||||||
|
$catCondition[] = " AND `order_status` = '". $this->db->escape($conditions['status'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['view_status']) && $conditions['view_status']) {
|
||||||
|
if($conditions['view_status'] == 'no-status') {
|
||||||
|
$catCondition[] = " AND `status_id` = 0 ";
|
||||||
|
} else {
|
||||||
|
$catCondition[] = " AND `status_id` = '". intval($conditions['view_status'])."' ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['update_by']) && $conditions['update_by']) {
|
||||||
|
$catCondition[] = " AND `status_update_by` = '". $this->db->escape($conditions['update_by'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['shipping_status']) && $conditions['shipping_status']) {
|
||||||
|
$catCondition[] = " AND `admin_shipping_status` = '". preg_replace("/[^a-z0-9_\-\.]/i", "", $conditions['shipping_status'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['assign_to']) && $conditions['assign_to']) {
|
||||||
|
$catCondition[] = " AND `assign_to` = '". intval($conditions['assign_to'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
//filter by date
|
||||||
|
if(isset($conditions['from_date']) && $conditions['from_date']) {
|
||||||
|
$catCondition[] = " AND order_time >= '". intval(strtotime(TimeManager::convert_date_from_javascript($conditions['from_date'])." 00:00"))."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions['to_date']) && $conditions['to_date']) {
|
||||||
|
$catCondition[] = " AND order_time <= '".strtotime(TimeManager::convert_date_from_javascript($conditions['to_date'])." 23:59")."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
//filter by hour
|
||||||
|
if(isset($conditions['from_hour']) && $conditions['from_hour']) {
|
||||||
|
$catCondition[] = " AND `order_hour` >= '".intval($conditions['from_hour'])."' ";
|
||||||
|
}
|
||||||
|
if(isset($conditions['to_hour']) && $conditions['to_hour']) {
|
||||||
|
$catCondition[] = " AND `order_hour` <= '".intval($conditions['to_hour'])."' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions["excluded_ids"]) && $conditions["excluded_ids"] ){
|
||||||
|
$list_ids = filterNumber(explode(",", $conditions["excluded_ids"]));
|
||||||
|
if(sizeof($list_ids)) $catCondition[] = " AND `orderId` NOT IN (".join(',', $list_ids ).") ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($conditions["included_ids"]) && $conditions["included_ids"] ){
|
||||||
|
$list_ids = filterNumber(explode(",", $conditions["included_ids"]));
|
||||||
|
if(sizeof($list_ids)) $catCondition[] = " AND `orderId` IN (".join(',', $list_ids ).") ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function beforeCreateItem(array $input_info) : AppResponse
|
||||||
|
{
|
||||||
|
$info = $input_info;
|
||||||
|
|
||||||
|
if(isset($info['file_external_url'])) {
|
||||||
|
if($info['file_external_url'] && !Url::isUrlValid($info['file_external_url'])) {
|
||||||
|
$info['file_external_url'] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$info['create_time'] = CURRENT_TIME;
|
||||||
|
$info['create_by'] = ADMIN_NAME;
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function beforeUpdateItem($item_id, $current_item_info, $new_input_info) : AppResponse
|
||||||
|
{
|
||||||
|
$info = $new_input_info;
|
||||||
|
|
||||||
|
unset($info['id']);
|
||||||
|
|
||||||
|
if(isset($info['file_external_url']) && $info['file_external_url'] && !Url::isUrlValid($info['file_external_url'])) {
|
||||||
|
$info['file_external_url'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$info['last_update'] = CURRENT_TIME;
|
||||||
|
$info['last_update_by'] = ADMIN_NAME;
|
||||||
|
|
||||||
|
return new AppResponse('ok', null, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function beforeDeleteItem($item_id, $item_info) : AppResponse
|
||||||
|
{
|
||||||
|
return new AppResponse('ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterDeleteItem($item_id, $item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function afterCreateItem($new_item_id, $new_item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function afterUpdateItem($item_id, $old_item_info, $new_item_info)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
inc/Hura8/Components/Order/Model/OrderSearchModel.php
Normal file
30
inc/Hura8/Components/Order/Model/OrderSearchModel.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Order\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\iSearch;
|
||||||
|
use Hura8\System\Model\aSearchBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class OrderSearchModel extends aSearchBaseModel implements iSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
private $filter_fields = [
|
||||||
|
"folder" => "tb_order.price",
|
||||||
|
];
|
||||||
|
|
||||||
|
private $fulltext_fields = [
|
||||||
|
"keywords" => ["tb_order.buyerName", ],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
"tb_order",
|
||||||
|
$this->fulltext_fields,
|
||||||
|
$this->filter_fields
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
94
inc/Hura8/Components/Order/Model/OrderStatusModel.php
Normal file
94
inc/Hura8/Components/Order/Model/OrderStatusModel.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Order\Model;
|
||||||
|
|
||||||
|
use Hura8\Database\iConnectDB;
|
||||||
|
|
||||||
|
class OrderStatusModel
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var iConnectDB $db */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
protected $tb_status = 'tb_order_status';
|
||||||
|
protected $tb_status_history = 'tb_order_status_history';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->db = get_db('', ENABLE_DB_DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatusHistory($orderId){
|
||||||
|
$query = $this->db->runQuery("
|
||||||
|
select * from ".$this->tb_status_history."
|
||||||
|
WHERE order_id = ?
|
||||||
|
order by id desc
|
||||||
|
limit 100
|
||||||
|
", ['d'], [ $orderId ] ) ;
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createHistory($order_id, $status_type = 'order', $system_status = '', $comment = '', array $data= [], array $other_info = []) {
|
||||||
|
|
||||||
|
$info = $other_info;
|
||||||
|
|
||||||
|
$info['order_id'] = $order_id;
|
||||||
|
$info['status_type'] = $status_type;
|
||||||
|
$info['system_status'] = $system_status;
|
||||||
|
$info['data'] = \json_encode($data);
|
||||||
|
$info['comment'] = substr($comment, 0, 150);
|
||||||
|
$info['create_time'] = CURRENT_TIME;
|
||||||
|
$info['create_by'] = (defined('ADMIN_NAME')) ? ADMIN_NAME : '';
|
||||||
|
|
||||||
|
return $this->db->insert($this->tb_status_history, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomerCancelStatusId() {
|
||||||
|
$info = $this->db->select($this->tb_status, ['id'], [
|
||||||
|
"system_status" => ["=", "cancel"],
|
||||||
|
'message' => 'Khách hàng hủy',
|
||||||
|
], '', 1);
|
||||||
|
|
||||||
|
if($info) {
|
||||||
|
return $info['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// create and return
|
||||||
|
return $this->create([
|
||||||
|
'message' => 'Khách hàng hủy',
|
||||||
|
'system_status' => "cancel",
|
||||||
|
'create_time' => CURRENT_TIME,
|
||||||
|
'create_by' => 'System',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getInfo($status_id) {
|
||||||
|
return $this->db->getItemInfo($this->tb_status, $status_id, 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAll() {
|
||||||
|
$query = $this->db->runQuery(" select * from ".$this->tb_status." order by `id` desc ") ;
|
||||||
|
$item_list = array();
|
||||||
|
foreach ( $this->db->fetchAll($query) as $rs ) {
|
||||||
|
if(!$rs['system_status']) $rs['system_status'] = 'new';
|
||||||
|
//$rs['system_order_status'] = System::$ORDER_STATUS[$rs['system_status']];
|
||||||
|
$item_list[] = $rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($id) {
|
||||||
|
return $this->db->runQuery("DELETE FROM ".$this->tb_status." WHERE `id` = ? limit 1 ", ['d'], [ $id ]) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id, array $info) {
|
||||||
|
return $this->db->update($this->tb_status, $info, ['id' => $id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(array $info) {
|
||||||
|
return $this->db->insert($this->tb_status, $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Page\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Page\Controller\bPageController;
|
||||||
|
use Hura8\Interfaces\iEntityAdminController;
|
||||||
|
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
class APageController extends bPageController implements iEntityAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
use AdminEntityBaseControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
|
public function updateTableInfo($item_id, array $new_item_info) {
|
||||||
|
return $this->objPageModel->updateTableInfo($item_id, $new_item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteFileBeforeDeleteItem($item_id): bool
|
||||||
|
{
|
||||||
|
// delete thumb files
|
||||||
|
$item_info = $this->getInfo($item_id);
|
||||||
|
$this->deleteThumbnailFile($item_info['thumbnail']);
|
||||||
|
|
||||||
|
//delete media files?
|
||||||
|
// todo:
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function deleteThumbnailFile($file_name): bool
|
||||||
|
{
|
||||||
|
if(!$file_name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::$resized_sizes as $size => $value) {
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". self::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $file_name;
|
||||||
|
unlink($file_local_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove original file
|
||||||
|
$file_local_path = PUBLIC_DIR . "/". self::$image_folder . "/". $file_name;
|
||||||
|
return unlink($file_local_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
92
inc/Hura8/Components/Page/Controller/bPageController.php
Normal file
92
inc/Hura8/Components/Page/Controller/bPageController.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Page\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use Hura8\Components\Page\Model\PageLanguageModel;
|
||||||
|
use Hura8\Components\Page\Model\PageModel;
|
||||||
|
use Hura8\System\Controller\aEntityBaseController;
|
||||||
|
|
||||||
|
class bPageController extends aEntityBaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
static $image_folder = "media/static";
|
||||||
|
|
||||||
|
static $resized_sizes = array(
|
||||||
|
't' => ['width' => 200,] ,
|
||||||
|
'l' => ['width' => 600,] ,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
protected $objPageModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objPageModel = new PageModel();
|
||||||
|
|
||||||
|
if(!$this->isDefaultLanguage()) {
|
||||||
|
//$this->objPageLanguageModel->createTableLang();
|
||||||
|
parent::__construct($this->objPageModel, new PageLanguageModel());
|
||||||
|
}else{
|
||||||
|
parent::__construct($this->objPageModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get full info- basic with description
|
||||||
|
public function getFullInfo($id) : ?array
|
||||||
|
{
|
||||||
|
if(!$id) return null;
|
||||||
|
|
||||||
|
return self::getCache("getFullInfo-".$id."-".$this->view_language, function () use ($id){
|
||||||
|
|
||||||
|
$info = $this->objPageModel->getFullInfo($id);
|
||||||
|
|
||||||
|
if($this->iEntityLanguageModel && $info ) {
|
||||||
|
$item_language_info = $this->iEntityLanguageModel->getInfo($id);
|
||||||
|
if($item_language_info) {
|
||||||
|
return $this->formatItemInfo(array_merge($info, $item_language_info));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->formatItemInfo($info);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInfo(array $item_info)
|
||||||
|
{
|
||||||
|
if(!$item_info) return null;
|
||||||
|
|
||||||
|
$info = $item_info;
|
||||||
|
$info['image'] = self::getResizedImageCollection($info['thumbnail']);
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function formatItemInList(array $item_info)
|
||||||
|
{
|
||||||
|
return $this->formatItemInfo($item_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getResizedImageCollection($image_name) {
|
||||||
|
$image = [];
|
||||||
|
|
||||||
|
$size_in_full = [
|
||||||
|
't' => 'thumb' ,
|
||||||
|
's' => 'small' ,
|
||||||
|
'l' => 'large' ,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (static::$resized_sizes as $size => $value) {
|
||||||
|
$image[$size_in_full[$size]] = ($image_name) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $image_name : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
inc/Hura8/Components/Page/Model/PageLanguageModel.php
Normal file
21
inc/Hura8/Components/Page/Model/PageLanguageModel.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Page\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Model\EntityLanguageModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
class PageLanguageModel extends EntityLanguageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $richtext_fields = [
|
||||||
|
'content',
|
||||||
|
'content_html',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::PAGE, '', $this->richtext_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
76
inc/Hura8/Components/Page/Model/PageModel.php
Normal file
76
inc/Hura8/Components/Page/Model/PageModel.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Page\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Interfaces\iEntityModel;
|
||||||
|
use Hura8\Interfaces\EntityType;
|
||||||
|
use Hura8\System\Controller\UrlManagerController;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
use Hura8\System\ModuleManager;
|
||||||
|
|
||||||
|
class PageModel extends aEntityBaseModel implements iEntityModel
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $richtext_fields = [
|
||||||
|
'content',
|
||||||
|
'content_html',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $tb_page_info = "tb_page_info";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(EntityType::PAGE, '', null, $this->richtext_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getFullInfo($id) : ?array
|
||||||
|
{
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT * FROM `".$this->tb_entity."` basic, `".$this->tb_page_info."` info
|
||||||
|
WHERE basic.`id` = info.`page_id` AND basic.id = ?
|
||||||
|
LIMIT 1 ",
|
||||||
|
['d'], [$id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if( $item_info = $this->db->fetchAssoc($query)){
|
||||||
|
return $item_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition): ?array
|
||||||
|
{
|
||||||
|
/*$condition = array(
|
||||||
|
"q" => "",
|
||||||
|
"status" => 0,
|
||||||
|
);*/
|
||||||
|
|
||||||
|
/*$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,52 +3,16 @@
|
|||||||
namespace Hura8\Components\Product\AdminController;
|
namespace Hura8\Components\Product\AdminController;
|
||||||
|
|
||||||
use Hura8\Components\Product\Controller\bProductCategoryController;
|
use Hura8\Components\Product\Controller\bProductCategoryController;
|
||||||
use Hura8\Interfaces\AppResponse;
|
|
||||||
use Hura8\Components\Product\Model\ProductCategoryInfoModel;
|
|
||||||
use Hura8\Interfaces\iEntityAdminCategoryController;
|
|
||||||
use Hura8\Traits\AdminEntityCategoryControllerTraits;
|
use Hura8\Traits\AdminEntityCategoryControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
class AProductCategoryController extends bProductCategoryController implements iEntityAdminCategoryController
|
class AProductCategoryController extends bProductCategoryController
|
||||||
{
|
{
|
||||||
|
|
||||||
use AdminEntityCategoryControllerTraits;
|
use AdminEntityCategoryControllerTraits;
|
||||||
|
|
||||||
|
|
||||||
public function updateItemCount($id) {
|
|
||||||
$this->objProductCategoryModel->updateItemCount($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getAttributeList($catId) {
|
public function getAttributeList($catId) {
|
||||||
return $this->objProductCategoryModel->getAttributeList($catId);
|
return $this->objProductCategoryModel->getAttributeList($catId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function create(array $info) : AppResponse
|
|
||||||
{
|
|
||||||
$res = parent::create($info);
|
|
||||||
|
|
||||||
if($res->getStatus() == 'ok') {
|
|
||||||
$objProductCategoryInfoModel = new ProductCategoryInfoModel();
|
|
||||||
$objProductCategoryInfoModel->createInfo($res->getData(), $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function update($id, array $info) : AppResponse
|
|
||||||
{
|
|
||||||
if(!$this->isDefaultLanguage()) {
|
|
||||||
return parent::update($id, $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update info
|
|
||||||
$objProductCategoryInfoModel = new ProductCategoryInfoModel();
|
|
||||||
$objProductCategoryInfoModel->updateInfo($id, $info);
|
|
||||||
|
|
||||||
return parent::update($id, $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,12 @@
|
|||||||
namespace Hura8\Components\Product\Model;
|
namespace Hura8\Components\Product\Model;
|
||||||
|
|
||||||
|
|
||||||
use Hura8\Interfaces\AppResponse;
|
use Hura8\Interfaces\iEntityCategoryModel;
|
||||||
use Hura8\System\Controller\UrlManagerController;
|
|
||||||
use Hura8\System\Model\aCategoryBaseModel;
|
use Hura8\System\Model\aCategoryBaseModel;
|
||||||
use Hura8\System\ModuleManager;
|
|
||||||
use Hura8\Interfaces\EntityType;
|
use Hura8\Interfaces\EntityType;
|
||||||
|
|
||||||
|
|
||||||
class ProductCategoryModel extends aCategoryBaseModel
|
class ProductCategoryModel extends aCategoryBaseModel implements iEntityCategoryModel
|
||||||
{
|
{
|
||||||
static $url_module = "product";
|
static $url_module = "product";
|
||||||
static $url_view = "category";
|
static $url_view = "category";
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Province\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Province\Controller\bProvinceController;
|
||||||
|
|
||||||
|
class AProvinceController extends bProvinceController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
151
inc/Hura8/Components/Province/Controller/bProvinceController.php
Normal file
151
inc/Hura8/Components/Province/Controller/bProvinceController.php
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Province\Controller;
|
||||||
|
|
||||||
|
use Hura8\Components\Province\Model\ProvinceModel;
|
||||||
|
use Hura8\Traits\ClassCacheTrait;
|
||||||
|
|
||||||
|
|
||||||
|
class bProvinceController
|
||||||
|
{
|
||||||
|
|
||||||
|
use ClassCacheTrait;
|
||||||
|
|
||||||
|
protected $objProvinceModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objProvinceModel = new ProvinceModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProvinceName($id) {
|
||||||
|
return self::getCache("getProvinceName-".$id, function () use ($id) {
|
||||||
|
$info = $this->objProvinceModel->getProvinceInfo($id, 'name');
|
||||||
|
return ($info) ? $info['name'] : '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDistrictName($id) {
|
||||||
|
return self::getCache("getDistrictName-".$id, function () use ($id) {
|
||||||
|
$info = $this->objProvinceModel->getDistrictInfo($id, 'name');
|
||||||
|
return ($info) ? $info['name'] : '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWardName($id) {
|
||||||
|
return self::getCache("getWardName-".$id, function () use ($id) {
|
||||||
|
$info = $this->objProvinceModel->getWardInfo($id, 'name');
|
||||||
|
return ($info) ? $info['name'] : '';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getProvinceList($field="*") {
|
||||||
|
return self::getCache("getProvinceList-", function () use ($field) {
|
||||||
|
return $this->objProvinceModel->getProvinceList($field);
|
||||||
|
//$pick_keys = ['id', 'api_id', 'name'];
|
||||||
|
|
||||||
|
/*return array_map(function ($item) use($pick_keys){
|
||||||
|
return pick_return_array_key($item, $pick_keys);
|
||||||
|
}, $province_list);*/
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProvinceDistrictList($province_id, $field="*") {
|
||||||
|
|
||||||
|
return self::getCache("getProvinceDistrictList-".$province_id, function () use ($province_id) {
|
||||||
|
return $this->objProvinceModel->getProvinceDistrictList($province_id);
|
||||||
|
//$pick_keys = ['id', 'api_id', 'name'];
|
||||||
|
|
||||||
|
/*return array_map(function ($item) use($pick_keys){
|
||||||
|
return pick_return_array_key($item, $pick_keys);
|
||||||
|
}, $province_list);*/
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllDistrictList() {
|
||||||
|
return self::getCache("getAllDistrictList", function (){
|
||||||
|
return $this->objProvinceModel->getAllDistrictList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDistrictWardList($district_id, $field="*") {
|
||||||
|
return self::getCache("getDistrictWardList-".$district_id, function () use ($district_id) {
|
||||||
|
return $this->objProvinceModel->getDistrictWardList($district_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// these are kept for old time sake
|
||||||
|
/*public static $province_list = array(
|
||||||
|
"1" => "Hà Nội",
|
||||||
|
"2" => "TP HCM",
|
||||||
|
"5" => "Hải Phòng" ,
|
||||||
|
"4" => "Đà Nẵng" ,
|
||||||
|
"6" => "An Giang" ,
|
||||||
|
"7" => "Bà Rịa-Vũng Tàu",
|
||||||
|
"13" => "Bình Dương" ,
|
||||||
|
"15" => "Bình Phước" ,
|
||||||
|
"16" => "Bình Thuận" ,
|
||||||
|
"14" => "Bình Định" ,
|
||||||
|
"8" => "Bạc Liêu",
|
||||||
|
"10" => "Bắc Giang" ,
|
||||||
|
"9" => "Bắc Kạn",
|
||||||
|
"11" => "Bắc Ninh",
|
||||||
|
"12" => "Bến Tre",
|
||||||
|
"18" => "Cao Bằng",
|
||||||
|
"17" => "Cà Mau",
|
||||||
|
"3" => "Cần Thơ",
|
||||||
|
"24" => "Gia Lai",
|
||||||
|
"25" => "Hà Giang",
|
||||||
|
"26" => "Hà Nam",
|
||||||
|
"27" => "Hà Tĩnh",
|
||||||
|
"30" => "Hòa Bình",
|
||||||
|
"28" => "Hải Dương",
|
||||||
|
"29" => "Hậu Giang",
|
||||||
|
"31" => "Hưng Yên",
|
||||||
|
"32" => "Khánh Hòa",
|
||||||
|
"33" => "Kiên Giang",
|
||||||
|
"34" => "Kon Tum",
|
||||||
|
"35" => "Lai Châu",
|
||||||
|
"38" => "Lào Cai",
|
||||||
|
"36" => "Lâm Đồng",
|
||||||
|
"37" => "Lạng Sơn",
|
||||||
|
"39" => "Long An",
|
||||||
|
"40" => "Nam Định",
|
||||||
|
"41" => "Nghệ An",
|
||||||
|
"42" => "Ninh Bình",
|
||||||
|
"43" => "Ninh Thuận",
|
||||||
|
"44" => "Phú Thọ",
|
||||||
|
"45" => "Phú Yên",
|
||||||
|
"46" => "Quảng Bình",
|
||||||
|
"47" => "Quảng Nam",
|
||||||
|
"48" => "Quảng Ngãi",
|
||||||
|
"49" => "Quảng Ninh",
|
||||||
|
"50" => "Quảng Trị",
|
||||||
|
"51" => "Sóc Trăng",
|
||||||
|
"52" => "Sơn La",
|
||||||
|
"53" => "Tây Ninh",
|
||||||
|
"56" => "Thanh Hóa",
|
||||||
|
"54" => "Thái Bình",
|
||||||
|
"55" => "Thái Nguyên",
|
||||||
|
"57" => "Thừa Thiên-Huế",
|
||||||
|
"58" => "Tiền Giang",
|
||||||
|
"59" => "Trà Vinh",
|
||||||
|
"60" => "Tuyên Quang",
|
||||||
|
"61" => "Vĩnh Long",
|
||||||
|
"62" => "Vĩnh Phúc",
|
||||||
|
"63" => "Yên Bái",
|
||||||
|
"19" => "Đắk Lắk",
|
||||||
|
"22" => "Đồng Nai",
|
||||||
|
"23" => "Đồng Tháp",
|
||||||
|
"21" => "Điện Biên",
|
||||||
|
"20" => "Đăk Nông",
|
||||||
|
);
|
||||||
|
|
||||||
|
public static function getName($id) {
|
||||||
|
return (isset(static::$province_list[$id])) ? static::$province_list[$id] : '';
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
73
inc/Hura8/Components/Province/Model/ProvinceModel.php
Normal file
73
inc/Hura8/Components/Province/Model/ProvinceModel.php
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Province\Model;
|
||||||
|
|
||||||
|
use Hura8\Database\iConnectDB;
|
||||||
|
use Hura8\Interfaces\TableName;
|
||||||
|
|
||||||
|
|
||||||
|
class ProvinceModel
|
||||||
|
{
|
||||||
|
|
||||||
|
/* @var iConnectDB $db */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
protected $tb_province = TableName::PROVINCE;
|
||||||
|
protected $tb_province_district = TableName::PROVINCE_DISTRICT;
|
||||||
|
protected $tb_province_ward = TableName::PROVINCE_WARD;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->db = get_db();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProvinceInfo($id, $field="*") {
|
||||||
|
if(!$id) return null;
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT ".$field." FROM `".$this->tb_province."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $id ]);
|
||||||
|
return $this->db->fetchAssoc($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDistrictInfo($id, $field="*") {
|
||||||
|
if(!$id) return null;
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT ".$field." FROM `".$this->tb_province_district."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $id ]);
|
||||||
|
return $this->db->fetchAssoc($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWardInfo($id, $field="*") {
|
||||||
|
if(!$id) return null;
|
||||||
|
|
||||||
|
$query = $this->db->runQuery("SELECT ".$field." FROM `".$this->tb_province_ward."` WHERE `id` = ? LIMIT 1 ", ['d'], [ $id ]);
|
||||||
|
return $this->db->fetchAssoc($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProvinceList($field="*") {
|
||||||
|
$query = $this->db->runQuery("SELECT ".$field." FROM `".$this->tb_province."` ORDER BY `id` ASC ");
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProvinceDistrictList($province_id, $field="*") {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT ".$field." FROM `".$this->tb_province_district."` WHERE `province_id` = ? ORDER BY `ordering` DESC ",
|
||||||
|
['d'], [ $province_id ]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllDistrictList() {
|
||||||
|
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_province_district."` WHERE 1 ORDER BY id ASC ");
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDistrictWardList($district_id, $field="*") {
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT ".$field." FROM `".$this->tb_province_ward."` WHERE `district_id` = ? ORDER BY `ordering` DESC ",
|
||||||
|
['d'],
|
||||||
|
[ $district_id ]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\AdminController;
|
||||||
|
|
||||||
|
use Hura8\System\Permission;
|
||||||
|
use Hura8\Traits\ClassCacheTrait;
|
||||||
|
|
||||||
|
class ClientPermissionController
|
||||||
|
{
|
||||||
|
|
||||||
|
use ClassCacheTrait;
|
||||||
|
|
||||||
|
public function getClientEntityPermission(){
|
||||||
|
return static::getCache("getClientEntityPermission", function (){
|
||||||
|
return $this->getClientEntityPermission_raw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getClientEntityPermission_raw() {
|
||||||
|
|
||||||
|
$system_file = ROOT_DIR. "/config/system/admin.entity.permission.php";
|
||||||
|
$entity_group = include $system_file;
|
||||||
|
|
||||||
|
$client_allowed_entities = Permission::getClientEntities();
|
||||||
|
|
||||||
|
$final_config = [];
|
||||||
|
foreach ($entity_group as $_group) {
|
||||||
|
|
||||||
|
$settings = include ROOT_DIR. "/config/system/entity_permission/".$_group.".php";
|
||||||
|
|
||||||
|
$children_match = [];
|
||||||
|
foreach ($settings['children'] as $_entity => $_p) {
|
||||||
|
if(in_array($_entity, $client_allowed_entities)) {
|
||||||
|
$children_match[$_entity] = $_p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sizeof($children_match)) {
|
||||||
|
$final_config[$_group] = [
|
||||||
|
'title' => $settings['title'],
|
||||||
|
'children' => $children_match,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $final_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getClientMenu() {
|
||||||
|
return static::getCache("getClientMenu", function (){
|
||||||
|
$menu_config_file = ROOT_DIR. "/config/client/admin/admin.menu.php";
|
||||||
|
|
||||||
|
$header_admin_config = [];
|
||||||
|
$menu_group = include $menu_config_file;
|
||||||
|
foreach ($menu_group as $_group) {
|
||||||
|
$content = include ROOT_DIR. "/config/client/admin/admin_menu/".$_group.".php";
|
||||||
|
$enabled_menu_item = array_filter($content['menu'], function ($item){ return $item['enable'];});
|
||||||
|
|
||||||
|
if(sizeof($enabled_menu_item) > 0) {
|
||||||
|
$header_admin_config[$_group] = [
|
||||||
|
'enable' => $content['enable'],
|
||||||
|
'name' => $content['name'],
|
||||||
|
'url' => $content['url'],
|
||||||
|
'menu' => $enabled_menu_item,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $header_admin_config;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Staff\Model\StaffAuthModel;
|
||||||
|
use Hura8\Components\Staff\Model\StaffModel;
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\IDGenerator;
|
||||||
|
|
||||||
|
|
||||||
|
class StaffAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $objStaffAuthModel;
|
||||||
|
protected $objStaffModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objStaffAuthModel = new StaffAuthModel();
|
||||||
|
$this->objStaffModel = new StaffModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLoginListByIds(array $staff_ids) : array
|
||||||
|
{
|
||||||
|
return $this->objStaffAuthModel->getLoginListByIds($staff_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList(array $conditions) : array
|
||||||
|
{
|
||||||
|
return $this->objStaffModel->getList($conditions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfo($id) : ?array
|
||||||
|
{
|
||||||
|
return $this->objStaffModel->getInfo($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmptyInfo(array $additional_fields = []) : array
|
||||||
|
{
|
||||||
|
return $this->objStaffModel->getEmptyInfo($additional_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id, array $input_info) : AppResponse
|
||||||
|
{
|
||||||
|
// change password
|
||||||
|
if(isset($input_info['password']) && strlen($input_info['password']) > 5) {
|
||||||
|
$this->objStaffAuthModel->createOrUpdatePassword($id, $input_info['password']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->objStaffModel->update($id, $input_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(array $input_info, $password = "") : AppResponse
|
||||||
|
{
|
||||||
|
$db_res = $this->objStaffModel->create($input_info);
|
||||||
|
|
||||||
|
if($db_res->getStatus() == 'ok') {
|
||||||
|
|
||||||
|
$new_id = $db_res->getData();
|
||||||
|
|
||||||
|
if(!$password) $password = IDGenerator::createStringId(6);
|
||||||
|
|
||||||
|
$this->objStaffAuthModel->createOrUpdatePassword($new_id, $password);
|
||||||
|
|
||||||
|
return new AppResponse('ok', '', ["id" => $new_id, "password" => $password]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AppResponse('error', 'Cannot create');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Staff\Model\StaffDepartmentModel;
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\Traits\ClassCacheTrait;
|
||||||
|
|
||||||
|
|
||||||
|
class StaffAdminDepartmentController
|
||||||
|
{
|
||||||
|
use ClassCacheTrait;
|
||||||
|
|
||||||
|
protected $objStaffDepartmentModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objStaffDepartmentModel = new StaffDepartmentModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList(array $conditions) {
|
||||||
|
return $this->objStaffDepartmentModel->getList($conditions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInfo($id) {
|
||||||
|
return self::getCache("getInfo-".$id, function () use ($id){
|
||||||
|
return $this->objStaffDepartmentModel->getInfo($id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEmptyInfo(array $additional_fields = [])
|
||||||
|
{
|
||||||
|
return $this->objStaffDepartmentModel->getEmptyInfo($additional_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id, array $input_info) {
|
||||||
|
return $this->objStaffDepartmentModel->update($id, $input_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(array $input_info) {
|
||||||
|
return $this->objStaffDepartmentModel->create($input_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Staff\Model\StaffDepartmentPermissionModel;
|
||||||
|
|
||||||
|
|
||||||
|
class StaffDepartmentPermissionController extends ClientPermissionController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $objStaffDepartmentPermissionModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objStaffDepartmentPermissionModel = new StaffDepartmentPermissionModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDepartmentMenuPermissionSetting($department_id) {
|
||||||
|
|
||||||
|
$current_permission = $this->getDepartmentMenuPermission($department_id);
|
||||||
|
|
||||||
|
$user_menu_settings = [];
|
||||||
|
foreach ($this->getClientMenu() as $group_id => $group_info) {
|
||||||
|
|
||||||
|
$rebuild_menu = [];
|
||||||
|
foreach ($group_info['menu'] as $index => $menu) {
|
||||||
|
$rebuild_menu[$index] = $menu;
|
||||||
|
|
||||||
|
$rebuild_menu[$index]['is_user_permitted'] = (in_array($menu['id'], $current_permission)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_menu_settings[$group_id] = $group_info;
|
||||||
|
$user_menu_settings[$group_id]['menu'] = $rebuild_menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_menu_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function saveDepartmentMenuPermission($department_id, array $new_permission) {
|
||||||
|
$this->objStaffDepartmentPermissionModel->saveDepartmentMenuPermission($department_id, $new_permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDepartmentMenuPermission($department_id) {
|
||||||
|
return $this->objStaffDepartmentPermissionModel->getDepartmentMenuPermission($department_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDepartmentEntityPermissionSetting($department_id) {
|
||||||
|
|
||||||
|
$current_permission = $this->getDepartmentEntityPermission($department_id);
|
||||||
|
|
||||||
|
$_settings = [];
|
||||||
|
foreach ($this->getClientEntityPermission() as $group_id => $group_info) {
|
||||||
|
|
||||||
|
$rebuild_children = [];
|
||||||
|
foreach ($group_info['children'] as $entity => $info) {
|
||||||
|
|
||||||
|
$actions = [];
|
||||||
|
foreach ($info['action'] as $action_key => $action_title) {
|
||||||
|
$actions[] = [
|
||||||
|
'action' => $action_key,
|
||||||
|
'title' => $action_title,
|
||||||
|
'is_user_permitted' => (isset($current_permission[$group_id]) && isset($current_permission[$group_id][$entity]) && isset($current_permission[$group_id][$entity][$action_key])) ? $current_permission[$group_id][$entity][$action_key] : false ,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rebuild_children[$entity] = [
|
||||||
|
'title' => $info['title'],
|
||||||
|
'action_list' => $actions,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$_settings[$group_id] = $group_info;
|
||||||
|
$_settings[$group_id]['children'] = $rebuild_children;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function saveDepartmentEntityPermission($department_id, array $new_permission) {
|
||||||
|
$this->objStaffDepartmentPermissionModel->saveDepartmentEntityPermission(
|
||||||
|
$department_id, $new_permission
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDepartmentEntityPermission($department_id) {
|
||||||
|
return static::getCache("getDepartmentEntityPermission-".$department_id, function () use ($department_id){
|
||||||
|
return $this->objStaffDepartmentPermissionModel->getDepartmentEntityPermission($department_id);
|
||||||
|
}) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Staff\Model\StaffLogModel;
|
||||||
|
|
||||||
|
class StaffLogController
|
||||||
|
{
|
||||||
|
protected $objStaffLogModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objStaffLogModel = new StaffLogModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList(array $conditions) {
|
||||||
|
return $this->objStaffLogModel->getList($conditions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTotal(array $conditions) {
|
||||||
|
return $this->objStaffLogModel->getTotal($conditions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(array $input_info) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\AdminController;
|
||||||
|
|
||||||
|
use Hura8\Components\Staff\Model\StaffPermissionModel;
|
||||||
|
use Hura8\Components\Staff\PublicController\StaffLoginController;
|
||||||
|
|
||||||
|
|
||||||
|
class StaffPermissionController extends ClientPermissionController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $objStaffPermissionModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objStaffPermissionModel = new StaffPermissionModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $entity_group
|
||||||
|
* @param $entity
|
||||||
|
* @param string $action valid values in PermissionType::
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function checkEntityActionPermission($is_super_user, $entity_group, $entity, $action ) : bool {
|
||||||
|
|
||||||
|
// super is allowed by default
|
||||||
|
if($is_super_user) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current_permission = $this->getCurrentUserEntityPermission();
|
||||||
|
|
||||||
|
if (
|
||||||
|
isset($current_permission[$entity_group]) &&
|
||||||
|
isset($current_permission[$entity_group][$entity]) &&
|
||||||
|
isset($current_permission[$entity_group][$entity][$action])
|
||||||
|
) {
|
||||||
|
return $current_permission[$entity_group][$entity][$action] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getUserProductMenuList() {
|
||||||
|
|
||||||
|
return self::getCache("getUserProductMenuList", function (){
|
||||||
|
$menu_list = include CONFIG_DIR. '/client/admin/product_menu.php';
|
||||||
|
|
||||||
|
$final_list = [];
|
||||||
|
foreach (array_filter($menu_list, function ($item){ return $item['enabled'];}) as $key => $value) {
|
||||||
|
|
||||||
|
// check if the current staff can see
|
||||||
|
// todo
|
||||||
|
// ...
|
||||||
|
|
||||||
|
$final_list[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $final_list;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function saveUserMenuPermission($admin_id, array $new_permission) {
|
||||||
|
$this->objStaffPermissionModel->saveUserMenuPermission($admin_id, $new_permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function saveUserEntityPermission($admin_id, array $new_permission) {
|
||||||
|
$this->objStaffPermissionModel->saveUserEntityPermission($admin_id, $new_permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get menu for currently logged-in user
|
||||||
|
*/
|
||||||
|
public function getUserMenu($is_super_user) {
|
||||||
|
|
||||||
|
// super can see all
|
||||||
|
if($is_super_user) {
|
||||||
|
return $this->getClientMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
$current_permission = $this->getCurrentUserMenuPermission();
|
||||||
|
|
||||||
|
$user_menu_settings = [];
|
||||||
|
foreach ($this->getClientMenu() as $group_id => $group_info) {
|
||||||
|
|
||||||
|
$rebuild_menu = [];
|
||||||
|
foreach ($group_info['menu'] as $index => $menu) {
|
||||||
|
if(!in_array($menu['id'], $current_permission)) continue;
|
||||||
|
|
||||||
|
$rebuild_menu[$index] = $menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sizeof($rebuild_menu)) {
|
||||||
|
$user_menu_settings[$group_id] = $group_info;
|
||||||
|
$user_menu_settings[$group_id]['menu'] = $rebuild_menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_menu_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getCurrentUserMenuPermission() {
|
||||||
|
$current_staff_id = StaffLoginController::getLoggedInStaffId();
|
||||||
|
return $this->objStaffPermissionModel->getUserMenuPermission($current_staff_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getCurrentUserEntityPermission() {
|
||||||
|
$current_staff_id = StaffLoginController::getLoggedInStaffId();
|
||||||
|
return $this->objStaffPermissionModel->getUserEntityPermission($current_staff_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getUserMenuPermissionSetting($admin_id) {
|
||||||
|
|
||||||
|
$current_permission = $this->objStaffPermissionModel->getUserMenuPermission($admin_id);
|
||||||
|
|
||||||
|
$user_menu_settings = [];
|
||||||
|
foreach ($this->getClientMenu() as $group_id => $group_info) {
|
||||||
|
|
||||||
|
$rebuild_menu = [];
|
||||||
|
foreach ($group_info['menu'] as $index => $menu) {
|
||||||
|
$rebuild_menu[$index] = $menu;
|
||||||
|
|
||||||
|
$rebuild_menu[$index]['is_user_permitted'] = (in_array($menu['id'], $current_permission)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_menu_settings[$group_id] = $group_info;
|
||||||
|
$user_menu_settings[$group_id]['menu'] = $rebuild_menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user_menu_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getUserEntityPermissionSetting($admin_id) {
|
||||||
|
|
||||||
|
$current_permission = $this->objStaffPermissionModel->getUserEntityPermission($admin_id);
|
||||||
|
|
||||||
|
$_settings = [];
|
||||||
|
|
||||||
|
foreach ($this->getClientEntityPermission() as $group_id => $group_info) {
|
||||||
|
|
||||||
|
$rebuild_children = [];
|
||||||
|
foreach ($group_info['children'] as $entity => $info) {
|
||||||
|
|
||||||
|
$actions = [];
|
||||||
|
foreach ($info['action'] as $action_key => $action_title) {
|
||||||
|
$actions[] = [
|
||||||
|
'action' => $action_key,
|
||||||
|
'title' => $action_title,
|
||||||
|
'is_user_permitted' => (
|
||||||
|
isset($current_permission[$group_id]) &&
|
||||||
|
isset($current_permission[$group_id][$entity]) &&
|
||||||
|
isset($current_permission[$group_id][$entity][$action_key])
|
||||||
|
) ? $current_permission[$group_id][$entity][$action_key] : false ,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rebuild_children[$entity] = [
|
||||||
|
'title' => $info['title'],
|
||||||
|
'action_list' => $actions,
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$_settings[$group_id] = $group_info;
|
||||||
|
$_settings[$group_id]['children'] = $rebuild_children;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
64
inc/Hura8/Components/Staff/Model/StaffAuthModel.php
Normal file
64
inc/Hura8/Components/Staff/Model/StaffAuthModel.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\Model;
|
||||||
|
|
||||||
|
use Hura8\System\Model\AuthModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class StaffAuthModel extends AuthModel
|
||||||
|
{
|
||||||
|
|
||||||
|
private $tb_staff_login = "tb_staff_login";
|
||||||
|
private $tb_staff_access_code = "tb_staff_access_code";
|
||||||
|
|
||||||
|
private $tb_staff_login_log = "tb_staff_login_log";
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct($this->tb_staff_login, $this->tb_staff_access_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getLoginListByIds(array $staff_ids) {
|
||||||
|
if(!sizeof($staff_ids)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
list($parameterized_ids, $bind_types) = create_bind_sql_parameter_from_value_list($staff_ids, 'int');
|
||||||
|
|
||||||
|
$bind_values = $staff_ids;
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT `user_id`, `last_login_time`, `last_login_ip`, `last_login_device`, `last_login_browser`
|
||||||
|
FROM ".$this->tb_staff_login."
|
||||||
|
WHERE `user_id` IN (".$parameterized_ids.") ",
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
);
|
||||||
|
|
||||||
|
$item_list = [];
|
||||||
|
foreach ($this->db->fetchAll($query) as $item) {
|
||||||
|
$item_list[$item['user_id']] = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getLoginLog(array $conditions = []) {
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
$query = $this->db->runQuery(
|
||||||
|
"SELECT * FROM ".$this->tb_staff_login_log." WHERE 1 ORDER BY `id` DESC LIMIT 100 ",
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->db->fetchAll($query) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
40
inc/Hura8/Components/Staff/Model/StaffDepartmentModel.php
Normal file
40
inc/Hura8/Components/Staff/Model/StaffDepartmentModel.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
|
||||||
|
|
||||||
|
class StaffDepartmentModel extends aEntityBaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('department');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||||
|
{
|
||||||
|
$where_clause = "";
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
return [
|
||||||
|
$where_clause,
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\Model;
|
||||||
|
|
||||||
|
class StaffDepartmentPermissionModel
|
||||||
|
{
|
||||||
|
protected $objStaffDepartmentModel;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->objStaffDepartmentModel = new StaffDepartmentModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getDepartmentMenuPermission($department_id) {
|
||||||
|
$_info = $this->objStaffDepartmentModel->getInfo($department_id);
|
||||||
|
|
||||||
|
return ($_info['menu_permission']) ? \json_decode($_info['menu_permission'], true) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function getDepartmentEntityPermission($department_id) {
|
||||||
|
$_info = $this->objStaffDepartmentModel->getInfo($department_id);
|
||||||
|
|
||||||
|
return ($_info['entity_permission']) ? \json_decode($_info['entity_permission'], true) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
38
inc/Hura8/Components/Staff/Model/StaffLogModel.php
Normal file
38
inc/Hura8/Components/Staff/Model/StaffLogModel.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Hura8\Components\Staff\Model;
|
||||||
|
|
||||||
|
use Hura8\Interfaces\AppResponse;
|
||||||
|
use Hura8\System\Model\aEntityBaseModel;
|
||||||
|
|
||||||
|
class StaffLogModel extends aEntityBaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('staff_log');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function extendedFilterOptions() : array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// empty for now
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||||
|
{
|
||||||
|
$where_clause = "";
|
||||||
|
$bind_types = [];
|
||||||
|
$bind_values = [];
|
||||||
|
|
||||||
|
return [
|
||||||
|
$where_clause,
|
||||||
|
$bind_types,
|
||||||
|
$bind_values
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user