index.php 9.25 KB
<?php
use yii\helpers\Url;
use app\ht\widgets\LinkPager;
use common\helpers\ImageManager;
use domain\shop\ShopItemStatus;

$this->title = '商品管理';
$this->params['breadcrumbs'][] = '商城管理';
$this->params['breadcrumbs'][] =  $this->title;
?>

<div class="panel panel-default">
    <div class="panel-body">
        <form action="" method="get" id="search-form" class="filter-form">
            <table width="100%" class="table table-bordered">
                <tbody>
                <tr >
                    <td width="10%" class="text-right">商品名称:</td>
                    <td width="20%" class="text-left"><input type="text" class="form-control" name="name" id="name" value="<?php if (!empty($gets['name'])){ echo $gets['name']; } ?>"></td>
                    <td width="10%" class="text-right">商品添加开始时间:</td>
                    <td width="20%" class="text-left"><input type="date" class="form-control" name="creatTime" value="<?php if (!empty($gets['creatTime'])){ echo $gets['creatTime']; } ?>"></td>
                    <td width="10%" class="text-right">商品添加结束时间:</td>
                    <td width="20%" class="text-left"><input type="date" class="form-control" name="endTime" value="<?php if (!empty($gets['endTime'])){ echo $gets['endTime']; } ?>"></td>
                </tr>
                <tr class="search">
                    <td colspan="4"  class="text-center">
                        <button type="submit" class="btn btn-primary btncls" id="search"><i class="glyphicon glyphicon-search"></i> 查 询  </button>
                        <a class="btn btn-default btncls" href="<?=Url::toRoute(["/shop/goods/index"])?>">重&nbsp;&nbsp;&nbsp;&nbsp;置</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>

<div class="panel panel-default">
    <div  class="panel-body">
        <table class="table table-striped table-bordered"  id="brand-table">
            <thead>
            <tr>
                <th width="6%">ID</th>
                <th width="10%">商品信息</th>
                <th width="20%">商品主图</th>
                <th width="30%">商品详情图</th>
                <th width="10%">新增时间</th>
                <th width="10%">状态</th>
                <th width="14%">操作</th>
            </tr>
            </thead>

            <tbody>
            <?php if ($listdata) { ?>
                <?php foreach ($listdata as $item) : ?>
                    <tr>
                        <td style="padding:12px;">
                            <?= $item['id'] ?>
                        </td>
                        <td style="padding:12px;">
                            商品名称:<?= $item['name'] ?><br/>
                            商品售价:&yen;<?= $item['price'] ?><br/>
                            商品原价:&yen;<?= $item['market_price'] ?><br/>
                            商品描述:<?= $item['desc'] ?><br/>
                            所属工程师:<?= (isset($item['engineer_info'][0]["firstname"]) ? $item['engineer_info'][0]["firstname"] : "") . (isset($item['engineer_info'][0]["lastname"]) ? $item['engineer_info'][0]["lastname"] : "") ?><br/>
                            所属工程师昵称:<?= (isset($item['engineer_info'][0]["nickname"]) ? $item['engineer_info'][0]["nickname"] : "") ?><br/>
                            所属工程师电话:<?= (isset($item['engineer_info'][0]["phone"]) ? $item['engineer_info'][0]["phone"] : "") ?><br/>
                        </td>
                        <td style="padding:12px;">
                            <?php foreach ($item["main_images"] as $main_image) : ?>
                            <img src="<?= ImageManager::getUrl(isset($main_image['path']) ? $main_image['path'] : "") ?>"   height="100" style="padding: 0 1rem 0 0; margin-bottom: 1rem"/>
                            <?php endforeach; ?>
                        </td>
                        <td style="padding:12px;">
                            <?php foreach ($item["detail_images"] as $detail_image) : ?>
                                <img src="<?= ImageManager::getUrl(isset($detail_image['path']) ? $detail_image['path'] : "") ?>"   height="75" style="padding: 0 1rem 0 0; margin-bottom: 1rem"/>
                            <?php endforeach; ?>
                        </td>
                        <td style="padding:12px;">
                            <?= date("Y-m-d H:i:s", $item['created_at'])?>
                        </td>
                        <td style="padding:12px;">
                            <?php if (ShopItemStatus::STATUS_STAY == $item['status']) {?>
                                <span style="background-color: #0a60d6; padding: 6px; color: #ffffff;">
                            <?php } elseif (ShopItemStatus::STATUS_SUCCESS == $item['status']) {?>
                                <span style="background-color: #00aa00; padding: 6px; color: #ffffff;">
                            <?php } elseif (ShopItemStatus::STATUS_REFUSE == $item['status']) {?>
                                <span style="background-color: #C40000; padding: 6px; color: #ffffff;">
                            <?php }?>
                            <?= ShopItemStatus::authStatusLabel($item['status']) ?>
                            </span>
                        </td>
                        <td style="padding:12px;">
                            <button class="btn btn-info btn-sm btn_auth_success" aid="<?=$item['id'] ?>">审核通过</button> &nbsp;|&nbsp;
                            <button class="btn btn-danger btn-sm btn_auth_fail" aid="<?=$item['id'] ?>">审核拒绝</button> &nbsp;|&nbsp;
                            <button class="btn btn-danger btn-sm btn_del" aid="<?=$item['id'] ?>">删除</button>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php } else { ?>
            <tr>
                <td colspan="8">
                    <center>暂无记录</center>
                </td>
            </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>

    <div class="panel-footer">
        <div class="hqy-panel-pager">
            <?= LinkPager::widget([
                'pagination' => $pages,
            ]); ?>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $(".btn_del").bind("click",function () {
            if (confirm("确定要删除商品吗?对应工程师商品列表中也会一并删除,请谨慎操作")){
                var data_id = $.trim($(this).attr("aid"));
                if (data_id == null || data_id == ""){
                    alert("丢失参数,暂时无法删除,请刷新后再试");
                    return false;
                }
                var thiz = $(this);
                $.ajax({
                    type: "post",
                    url: "do-del",
                    dataType:"json",
                    data: $.csrf({"data_id":data_id}),
                    success:function(msg){
                        alert(msg['msg']);
                        if (msg['status'] == 1){
                            thiz.parents("tr").remove();
                        }else{
                            //提示确认失败
                        }
                    },
                    error:function(msg){
                        //提示确认失败
                    }
                });
            }
        }) ;

        $(".btn_auth_fail").bind("click",function () {
            var data_id = $.trim($(this).attr("aid"));
            if (data_id == null || data_id == ""){
                alert("丢失参数,暂时无法审核,请刷新后再试");
                return false;
            }
            var thiz = $(this);
            $.ajax({
                type: "post",
                url: "do-auth",
                dataType:"json",
                data: $.csrf({"data_id":data_id, "auth_type": "auth_fail"}),
                success:function(msg){
                    alert(msg['msg']);
                    if (msg['status'] == 1){
                        window.location.reload();
                    }else{
                        //提示确认失败
                    }
                },
                error:function(msg){
                    //提示确认失败
                }
            });
        }) ;
        $(".btn_auth_success").bind("click",function () {
            var data_id = $.trim($(this).attr("aid"));
            if (data_id == null || data_id == ""){
                alert("丢失参数,暂时无法审核,请刷新后再试");
                return false;
            }
            var thiz = $(this);
            $.ajax({
                type: "post",
                url: "do-auth",
                dataType:"json",
                data: $.csrf({"data_id":data_id, "auth_type": "auth_success"}),
                success:function(msg){
                    alert(msg['msg']);
                    if (msg['status'] == 1){
                        window.location.reload();
                    }else{
                        //提示确认失败
                    }
                },
                error:function(msg){
                    //提示确认失败
                }
            });
        }) ;
    });
</script>