c
This commit is contained in:
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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user