<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller\Admin\Customer;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Master\CustomerStatus;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Admin\CustomerType;
use Eccube\Repository\CustomerRepository;
use Eccube\Util\StringUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
class CustomerEditController extends AbstractController
{
/**
* @var CustomerRepository
*/
protected $customerRepository;
/**
* @var EncoderFactoryInterface
*/
protected $encoderFactory;
public function __construct(
CustomerRepository $customerRepository,
EncoderFactoryInterface $encoderFactory
) {
$this->customerRepository = $customerRepository;
$this->encoderFactory = $encoderFactory;
}
/**
* @Route("/%eccube_admin_route%/customer/new", name="admin_customer_new")
* @Route("/%eccube_admin_route%/customer/{id}/edit", requirements={"id" = "\d+"}, name="admin_customer_edit")
* @Template("@admin/Customer/edit.twig")
*/
public function index(Request $request, $id = null)
{
$this->entityManager->getFilters()->enable('incomplete_order_status_hidden');
// 編集
if ($id) {
$Customer = $this->customerRepository
->find($id);
if (is_null($Customer)) {
throw new NotFoundHttpException();
}
$oldStatusId = $Customer->getStatus()->getId();
// 編集用にデフォルトパスワードをセット
$previous_password = $Customer->getPassword();
$Customer->setPassword($this->eccubeConfig['eccube_default_password']);
// 新規登録
} else {
$Customer = $this->customerRepository->newCustomer();
$oldStatusId = null;
}
// 会員登録フォーム
$builder = $this->formFactory
->createBuilder(CustomerType::class, $Customer);
$event = new EventArgs(
[
'builder' => $builder,
'Customer' => $Customer,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_INITIALIZE, $event);
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
log_info('会員登録開始', [$Customer->getId()]);
$encoder = $this->encoderFactory->getEncoder($Customer);
if ($Customer->getPassword() === $this->eccubeConfig['eccube_default_password']) {
$Customer->setPassword($previous_password);
} else {
if ($Customer->getSalt() === null) {
$Customer->setSalt($encoder->createSalt());
$Customer->setSecretKey($this->customerRepository->getUniqueSecretKey());
}
$Customer->setPassword($encoder->encodePassword($Customer->getPassword(), $Customer->getSalt()));
}
// 退会ステータスに更新の場合、ダミーのアドレスに更新
$newStatusId = $Customer->getStatus()->getId();
if ($oldStatusId != $newStatusId && $newStatusId == CustomerStatus::WITHDRAWING) {
$Customer->setEmail(StringUtil::random(60).'@dummy.dummy');
}
$this->entityManager->persist($Customer);
$this->entityManager->flush();
log_info('会員登録完了', [$Customer->getId()]);
$event = new EventArgs(
[
'form' => $form,
'Customer' => $Customer,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE, $event);
$this->addSuccess('admin.common.save_complete', 'admin');
return $this->redirectToRoute('admin_customer_edit', [
'id' => $Customer->getId(),
]);
}
return [
'form' => $form->createView(),
'Customer' => $Customer,
];
}
/**
* @Route("/%eccube_admin_route%/customer/balance", name="admin_customer_balance")
* @Template("@admin/Customer/balance.twig")
*/
public function balance(Request $request, $id = null)
{
// DB アクセス用Class 展開
$em = $this -> getDoctrine() ->getManager() ;
// 初期画面か入金画面 どちらかの選択(POST Dataがない場合:初期画面)
// 初期画面
if(!($request->getMethod() === 'POST')){
$query = 'select * from dtb_customer where customer_status_id=2 order by create_date' ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$count = 0 ;
foreach($buff as $info){
$customer_info[$count]["id"] = $info["id"] ;
$customer_info[$count]["myouji"] = $info["name01"] ;
$customer_info[$count]["namae"] = $info["name02"] ;
$customer_info[$count]["kana1"] = $info["kana01"] ;
$customer_info[$count]["kana2"] = $info["kana02"] ;
$customer_info[$count]["number"] = $info["phone_number"] ;
$c_id = $info["id"] ;
$query = 'select input from dtb_customer_payhis where customer_id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$total_in = 0 ;
foreach($buff as $inp){
$total_in = $total_in + $inp["input"] ;
}
$balance["input"] = number_format($total_in) ;
$query = 'select output from dtb_customer_payhis where customer_id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$total_out = 0 ;
foreach($buff as $out){
$total_out = $total_out + $out["output"] ;
}
$balance["output"] = number_format($total_out) ;
$customer_info[$count]["zandaka"] = number_format($total_in - $total_out) ;
$count ++ ;
}
$customer_status = 1 ;
$info = [] ;
return['customer_info' => $customer_info,'info'=>$info,'status'=>$customer_status,] ;
}
// ユーザ選択または入金画面
else{
$pdata = $_POST ;
// ユーザー情報読み出し
$c_id = $pdata["id"] ;
$query = 'select id, sex_id, name01, name02, kana01, kana02 from dtb_customer where id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement -> fetchall() ;
foreach($buff as $info){
$customer_info["id"] = $info["id"] ;
$customer_info["sex"] = $info["sex_id"] ;
$customer_info["name1"] = $info["name01"] ;
$customer_info["name2"] = $info["name02"] ;
$customer_info["kana1"] = $info["kana01"] ;
$customer_info["kana2"] = $info["kana02"] ;
}
if(!(isset($pdata["input"]))){
$customer_status = 2 ;
$query = 'select input from dtb_customer_payhis where customer_id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$total_in = 0 ;
foreach($buff as $inp){
$total_in = $total_in + $inp["input"] ;
}
$balance["input"] = number_format($total_in) ;
$query = 'select output from dtb_customer_payhis where customer_id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$total_out = 0 ;
foreach($buff as $out){
$total_out = $total_out + $out["output"] ;
}
$balance["output"] = number_format($total_out) ;
$balance["zandaka"] = number_format($total_in - $total_out) ;
return[
'customer_info' => $customer_info,
'balance' => $balance,
'status'=>$customer_status,
] ;
}
else{
$customer_status = 3 ;
// 操作Log 保存機能追加
//var_dump($_SESSION) ;
$spl_read = ($_SESSION['_sf2_attributes']['_security_admin']) ;
$search_word = 's:30:' ;
$read_buffer = strstr($spl_read,$search_word) ;
$breplace ='"' ;
$areplace ='ふ' ;
$access_buff = str_replace($breplace,$areplace,$read_buffer,$number) ;
$num_buff = mb_strpos((string)$access_buff,"ふ") ;
$num_buff = $num_buff + 2 ;
$num_buff = mb_strpos((string)$access_buff,"ふ", $num_buff) ;
$num_buff = $num_buff + 2 ;
$num_buff = mb_strpos((string)$access_buff,"ふ", $num_buff) ;
$id_numtop = $num_buff ;
$num_buff = $num_buff + 2 ;
$num_buff = mb_strpos((string)$access_buff,"ふ", $num_buff) ;
$id_numend = $num_buff ;
$cut_off = $id_numend - $id_numtop-1 ;
$cut_top= $id_numtop+7 ;
$access_id = substr((string)$access_buff,$cut_top,$cut_off) ;
$input = $pdata["input"] ;
$create = date("Y-m-d H:i:s") ;
$query = 'insert into dtb_customer_payhis (customer_id, input, create_time, access_id) values ('.$c_id.', '.$input.', "'.$create.'", "'.$access_id.'")' ;
$statement = $em->getConnection() -> prepare($query) ;
$result = $statement -> execute() ;
$query = 'select input, create_time from dtb_customer_payhis where customer_id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$total_in = 0 ;
foreach($buff as $inp){
$total_in = $total_in + $inp["input"] ;
if($inp["create_time"] == $create){
$inp_cost = $inp["input"] ;
}
}
$balance["input"] = number_format($total_in) ;
$query = 'select output from dtb_customer_payhis where customer_id='.$c_id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement -> execute() ;
$buff = $statement->fetchall() ;
$total_out = 0 ;
foreach($buff as $out){
$total_out = $total_out + $out["output"] ;
}
$balance["output"] = number_format($total_out) ;
$balance["zandaka"] = number_format($total_in - $total_out) ;
$balance["nyukin"] = number_format($inp_cost) ;
return[
'customer_info' => $customer_info,
'balance' => $balance,
'status'=>$customer_status,
] ;
}
}
}
/**
* @Route("/%eccube_admin_route%/customer/authent", name="admin_customer_authent")
* @Template("@admin/Customer/authent.twig")
*/
public function authent(Request $request, $id = null)
{
// DB アクセス用Class 展開
$p_data = $_POST ;
$message = '' ;
$em = $this -> getDoctrine() ->getManager() ;
// 初期画面か入金画面 どちらかの選択(POST Dataがない場合:初期画面)
// 初期画面
if(!isset($p_data['mode'])){
// $info['status'] = 1 ;
$query = 'select * from dtb_customer where customer_status_id=1' ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff = $statement->fetchall() ;
$count = 0 ;
foreach($buff as $a){
$info[$count]['id'] = $a['id'] ;
$info[$count]['sex'] = $a['sex_id'] ;
$info[$count]['name1'] = $a['name01'] ;
$info[$count]['name2'] = $a['name02'] ;
$info[$count]['comp'] = $a['company_name'] ;
$info[$count]['addr1'] = $a['addr01'] ;
$info[$count]['addr2'] = $a['addr02'] ;
$info[$count]['phone'] = $a['phone_number'] ;
$info[$count]['status'] = 1 ;
$count ++ ;
}
return[
'info'=>$info,
'msg'=>$message,
] ;
}
else{
if ($p_data['mode'] == 'confirmed'){
// $info['status'] = 2 ;
$count = 0 ;
foreach($p_data['auth'] as $a){
if(isset($a['select'])){
if($a['select'] == 1){
$id = $a['id'] ;
$query = 'select * from dtb_customer where id='.$id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff = $statement->fetchall() ;
foreach($buff as $a){
$info[$count]['id'] = $a['id'] ;
$info[$count]['sex'] = $a['sex_id'] ;
$info[$count]['name1'] = $a['name01'] ;
$info[$count]['name2'] = $a['name02'] ;
$info[$count]['comp'] = $a['company_name'] ;
$info[$count]['addr1'] = $a['addr01'] ;
$info[$count]['addr2'] = $a['addr02'] ;
$info[$count]['phone'] = $a['phone_number'] ;
$info[$count]['status'] = 2 ;
}
$count++ ;
}
}
}
if($count == 0){
$query = 'select * from dtb_customer where customer_status_id=1' ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff = $statement->fetchall() ;
$count = 0 ;
foreach($buff as $a){
$info[$count]['id'] = $a['id'] ;
$info[$count]['sex'] = $a['sex_id'] ;
$info[$count]['name1'] = $a['name01'] ;
$info[$count]['name2'] = $a['name02'] ;
$info[$count]['comp'] = $a['company_name'] ;
$info[$count]['addr1'] = $a['addr01'] ;
$info[$count]['addr2'] = $a['addr02'] ;
$info[$count]['phone'] = $a['phone_number'] ;
$info[$count]['status'] = 1 ;
$count ++ ;
}
$message = '1' ;
}
return[
'info'=>$info,
'msg'=>$message,
] ;
}
else{
$query = 'select email01,email03,email04 from dtb_base_info' ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff = $statement->fetchall() ;
foreach($buff as $a){
$from = $a['email01'] ;
$bcc = $a['email03'] ;
$path = $a['email04'] ;
}
foreach($p_data['auth'] as $a){
$create = date("Y-m-d H:i:s") ;
$id = $a['id'] ;
$query = 'UPDATE dtb_customer SET customer_status_id=2, update_date= "'.$create.'" where id='.$id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$query = 'select * from dtb_customer where id='.$id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff = $statement->fetchall() ;
foreach($buff as $b){
$id = $b['id'] ;
$name1 = $b['name01'] ;
$name2 = $b['name02'] ;
$kana1 = $b['kana01'] ;
$kana2 = $b['kana02'] ;
$addr = $b['email'] ;
}
$header_msg =$name1.' '.$name2.' 様 ('.$kana1.' '.$kana2.'様)' ;
$footer_msg1 = "お客様の会員登録が完了いたしましたので、ご連絡差し上げます" ;
$footer_msg2 = "ご登録のID及びパスワードにて「ログイン」可能です。" ;
$mail = $header_msg."\n\n" ;
$mail .= $footer_msg1."\n" ;
$mail .= $footer_msg2."\n" ;
$mail .= "\n本メールは淘淘市場より、送信しております。\nもし、お心当たりがない場合は、その旨".$from."
までご連絡頂ければ幸いです" ;
//日本語設定を行う
mb_language("Japanese");
mb_internal_encoding("UTF-8");
$mail_to = $addr ; //送信先メールアドレス
$mail_subject = "会員登録完了のお知らせ"; //メールの件名
$mail_body = $mail; //メールの本文
$mail_header = "from:".$from; //フォームで入力されたメールアドレスを送信元として表示する
$mail_header .= "\n" ;
$mail_header .= "Bcc:".$bcc ;
$mail_path = "-f$path" ;
$mailsend = mb_send_mail($mail_to, $mail_subject, $mail_body, $mail_header,$mail_path);
}
$info[0]['status'] = 3 ;
return[
'info'=>$info,
] ;
}
}
}
/**
* @Route("/%eccube_admin_route%/customer/acclog", name="admin_customer_acclog")
* @Template("@admin/Customer/acclog.twig")
*/
public function acclog(Request $request, $id = null){
$p_data=$_POST ;
var_dump($p_data) ;
$em = $this -> getDoctrine() ->getManager() ;
$info = [] ;
$opt_val=[] ;
if(!isset($p_data['page'])){
$page = 0 ;
}
else{
$page = $p_data['page'] ;
if(isset($p_data['offset_page_p'])){
$page = $page - 1 ;
if($page <= 0){
$page = 0 ;
}
}
elseif(isset($p_data['offset_page_n'])){
$page = $page + 1 ;
}
}
$c_id = false ;
if(isset($p_data['select_id'])){
$c_id = $p_data['select_id'] ;
if($p_data['select_id'] != $p_data['bc_id']){
$page = 0 ;
}
}
$time_str = false ;
if(isset($p_data['period_str'])){
$time_str = $p_data['period_str'] ;
if($p_data['period_str'] != $p_data['bp_str']){
$page = 0 ;
}
}
$time_end = false ;
if(isset($p_data['period_end'])){
$time_end = $p_data['period_end'] ;
if($p_data['period_end'] != $p_data['bp_end']){
$page = 0 ;
}
}
$state['page'] = $page ;
$state['c_id'] = $c_id ;
$state['end'] = $time_end ;
$state['str'] = $time_str ;
$query = 'select * from dtb_customer_payhis' ;
$cquery = '' ;
$tsquery = '' ;
$teqyert = '' ;
$flg_where = 0 ;
if($c_id){
$cquery = ' Where customer_id = '.$c_id ;
$flg_where = 1 ;
$query = $query.$cquery ;
}
if($time_str){
if($flg_where == 0){
$tsquery = ' Where "'.$time_str.'" <= create_time' ;
$flg_where = 1 ;
}
else{
$tsquery = ' and "'.$time_str.'" <= create_time' ;
}
$query= $query.$tsquery ;
}
if($time_end){
if($flg_where == 0){
$tequery = ' Where create_time <= "'.$time_end.'"' ;
$flg_where = 1 ;
}
else{
$tequery = ' and create_time <= "'.$time_end.'"' ;
}
$query=$query.$tequery ;
}
$query = $query.' order by create_time desc' ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff = $statement->fetchall() ;
$count = 0 ;
foreach($buff as $a){
$ibuff[$count]['c_id'] = $a['customer_id'] ;
$balance = $a['input'] ;
$ibuff[$count]['input'] = number_format($balance) ;
$ibuff[$count]['time'] = $a['create_time'] ;
$ibuff[$count]['access'] = $a['access_id'] ;
$id = $a['customer_id'] ;
$query = 'select name01, name02 from dtb_customer where id='.$id ;
$statement = $em->getConnection()->prepare($query) ;
$result = $statement->execute() ;
$buff1 = $statement -> fetch() ;
$name = $buff1['name01'].' '.$buff1['name02'] ;
$ibuff[$count]['name'] = $name ;
$count ++ ;
}
$roll = $page*(30/3) ;
$ct_option = 0 ;
$state['terminate'] = 0 ;
for($subcount = 0; $subcount<(30/3); $subcount++ ){
$offcount = $roll+$subcount ;
if(isset($ibuff[$offcount]['c_id'])){
$info[$subcount]['c_id'] = $ibuff[$offcount]['c_id'] ;
$info[$subcount]['input'] = $ibuff[$offcount]['input'] ;
$info[$subcount]['time'] = $ibuff[$offcount]['time'] ;
$info[$subcount]['access'] = $ibuff[$offcount]['access'] ;
$info[$subcount]['name'] = $ibuff[$offcount]['name'] ;
if(isset($opt_val[0]['c_id'])){
$flg_confirm = 0 ;
for($i=0; $i< $ct_option; $i++){
if($opt_val[($i)]['c_id'] == $info[$subcount]['c_id']){
$flg_confirm =1 ;
}
}
if($flg_confirm == 0){
$opt_val[$ct_option]['c_id'] = $info[$subcount]['c_id'] ;
$opt_val[$ct_option]['name'] = $info[$subcount]['name'] ;
if((isset($p_data['select_id'])) && ($p_data['select_id'] == $info[$subcount]['c_id'])){
$opt_val[$ct_option]['selstate'] = 1 ;
}
else{
$opt_val[$ct_option]['selstate'] = 0 ;
}
$ct_option ++ ;
}
}
else{
$opt_val[$ct_option]['c_id'] = $info[$subcount]['c_id'] ;
$opt_val[$ct_option]['name'] = $info[$subcount]['name'] ;
$opt_val[$ct_option]['selstate'] = 0 ;
$ct_option ++ ;
}
}
else{
$state['terminate'] = 1 ;
$subcount = (30/3) ;
}
}
return[
'info'=> $info,
'opt_val'=>$opt_val,
'state' => $state,
] ;
}
}