123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace app\admin;
- class item extends Base
- {
- public function initialize()
- {
- parent::initialize();
- $this->type_text = json_decode(IN_ITEM_TYPE, true);
- $this->Administrator(6);
- $this->header();
- }
- public function __destruct()
- {
- ?> <script>
- $('input[name=sort]').on('input', function () {
- var sort = $(this).val();
- if (sort != $(this).attr('data-sort'))
- $.ajax({
- url: '?c=ajax&a=item_sort',
- data: {id: $(this).attr('data-id'), sort: sort},
- type: 'post',
- success: function (ret) {
- console.log(ret)
- }
- });
- });
- </script>
- <?php
- $this->footer();
- }
- function index($_var_0 = [])
- {
- $_var_1 = SafeRequest("page", "get");
- $this->search = SafeRequest("search", "get");
- $this->search && ($_var_0[] = ["name|note", "like", "%" . $this->search . "%"]);
- $this->type = SafeRequest("type", "get");
- is_numeric($this->type) && ($_var_0[] = ["type", "=", $this->type]);
- $_var_2 = db("item")->where($_var_0)->order("sort,id desc")->paginate(["page" => $_var_1]);
- $_var_3 = $_var_2->items();
- $_var_4 = getRender($_var_2, $_var_1);
- $_var_5 = $_var_2->total();
- ?><div class="container"><?php
- $this->searchForm("可以输入名称、描述等关键词进行搜索", "", function () {
- ?> <select name="type" onchange="document.btnsearch.submit();">
- <option value="">全部类型</option>
- <?php
- foreach ($this->type_text as $_var_6 => $_var_7) {
- ?> <option value="<?php echo $_var_6;?>" <?php echo is_numeric($this->type) && $this->type == $_var_6 ? "selected=\"selected\"" : "";?>>
- <?php echo $_var_7;?> </option>
- <?php
- }
- ?> </select>
- <?php
- });
- ?>
- <table class="tb tb2">
- <tr><th class="partition">商品列表</th></tr>
- </table>
- <table class="tb tb2">
- <tr class="header">
- <th>ID</th>
- <th>名称</th>
- <th>描述</th>
- <th>数目</th>
- <th>价格</th>
- <th>原价</th>
- <th>类型</th>
- <th>排序</th>
- <th>状态</th>
- <th>编辑操作</th>
- </tr>
- <?php
- if ($_var_5 == 0) {
- ?><tr><td colspan="2" class="td27">没有商品管理</td></tr>
- <?php
- }
- if ($_var_3) {
- foreach ($_var_3 as $_var_8) {
- ?><tr class="hover">
- <td class="td25"><?php echo $_var_8["id"];?></td>
- <td><?php echo lightnum($_var_8["name"], $this->search);?></td>
- <td><?php echo lightnum($_var_8["note"], $this->search);?></td>
- <td><?php echo $_var_8["number"];?></td>
- <td><?php echo $_var_8["price"];?></td>
- <td><?php echo $_var_8["old_price"];?></td>
- <td><?php echo $this->type_text[$_var_8["type"]];?></td>
- <td><input type="text" name="sort" data-id="<?php echo $_var_8["id"];?>" value="<?php echo $_var_8["sort"];?>" data-value="<?php echo $_var_8["sort"];?>" style="width: 30px;"/></td>
- <td>
- <a href="?c=item&a=change_status&id=<?php echo $_var_8["id"];?>&status=<?php echo $_var_8["status"] ? "0" : "1";?>&hash=<?php echo $_COOKIE["in_adminpassword"];?>">
- <img src="static/admincp/image/show_<?php echo $_var_8["status"] ? "yes" : "no";?>.gif" />
- </a>
- </td>
- <script type="text/javascript" src="/xinadmin/js/item.js"></script>
- <td><a href="javascript:;" onclick="x_admin_show('编辑','?c=item&a=edit&id=<?php echo $_var_8["id"];?>')" class="act">编辑</a></td></tr><?php
- }
- }
- ?></table></div><?php echo $_var_4;?><?php
- }
- function edit()
- {
- $_var_9 = SafeRequest("id", "get");
- $_var_10 = $_var_9 ? "编辑" : "新增";
- $_var_11 = db("item")->where("id", $_var_9)->find();
- ?><div class="container"><?php
- $this->nav3();
- ?><table class="tb tb2">
- <form action="?c=item&a=save" method="post" name="form">
- <input type="hidden" name="id" value="<?php echo $_var_9;?>"/>
- <input type="hidden" name="hash" value="<?php echo $_COOKIE["in_adminpassword"];?>" />
- <tr><th colspan="15" class="partition"><?php echo $_var_10;?>商品</th></tr>
- <tr><td colspan="2" class="td27">商品名称:</td></tr>
- <tr><td class="vtop rowform">
- <input type="text" class="txt" value="<?php echo $_var_11["name"];?>" name="name" id="name">
- </td>
- </tr>
- <tr><td colspan="2" class="td27">数目:</td></tr>
- <tr><td class="vtop rowform">
- <input type="number" class="txt" name="number" id="number" value="<?php echo $_var_11["number"];?>">
- </td>
- </tr>
- <tr><td colspan="2" class="td27">价格:</td></tr>
- <tr><td class="vtop rowform">
- <input type="number" class="txt" name="price" id="price" value="<?php echo $_var_11["price"];?>">
- </td>
- </tr>
- <tr><td colspan="2" class="td27">原价:</td></tr>
- <tr><td class="vtop rowform">
- <input type="number" class="txt" name="old_price" id="old_price" value="<?php echo $_var_11["old_price"];?>">
- </td>
- </tr>
- <tr><td colspan="2" class="td27">类型:</td></tr>
- <tr><td class="vtop rowform">
- <select name="type"><?php
- foreach ($this->type_text as $_var_12 => $_var_13) {
- ?><option value="<?php echo $_var_12;?>" <?php echo $_var_11["type"] == $_var_12 ? "selected" : "";?>><?php echo $_var_13;?></option><?php
- }
- ?></select>
- </td>
- </tr>
- <tr><td colspan="2" class="td27">描述:</td></tr>
- <tr><td class="vtop rowform">
- <textarea rows="6" name="note" class="tarea" id="note"><?php echo $_var_11["note"];?></textarea>
- </td>
- </tr>
- <tr><td colspan="15">
- <div class="fixsel">
- <input type="submit" class="btn" onclick="return CheckForm();" value="提交" />
- </div>
- </td></tr>
- </form>
- </table>
- </div>
- <?php
- }
- function save()
- {
- if (!submitcheck("hash", 1)) {
- $this->ShowMessage("表单来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_14 = intval(SafeRequest("id", "post"));
- $_var_15 = SafeRequest("name", "post");
- if (!$_var_15) {
- $this->ShowMessage("商品名称不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_16 = SafeRequest("number", "post");
- if (!$_var_16) {
- $this->ShowMessage("数目不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_17 = SafeRequest("price", "post");
- if (!$_var_17) {
- $this->ShowMessage("价格不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_18 = SafeRequest("old_price", "post");
- $_var_19 = SafeRequest("note", "post");
- $_var_20 = SafeRequest("type", "post");
- $_var_21 = ["name" => $_var_15, "number" => $_var_16, "price" => $_var_17, "old_price" => $_var_18, "type" => $_var_20, "note" => $_var_19];
- if ($_var_14) {
- $_var_22 = db("item")->where("id", $_var_14)->update($_var_21);
- } else {
- if (db("item")->where("name", $_var_15)->where("number", $_var_16)->where("price", $_var_17)->where("type", $_var_20)->count()) {
- $this->ShowMessage("已存在相同的商品", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_22 = db("item")->insert($_var_21);
- }
- $_var_22 && $this->ShowMessage("恭喜您,商品保存成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
- $this->ShowMessage("商品保存失败!请稍后重试!", $_SERVER["HTTP_REFERER"], "infotitle3", 3000, 1);
- }
- function change_status()
- {
- if (!submitcheck("hash", -1)) {
- $this->ShowMessage("链接来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_23 = intval(SafeRequest("id", "get"));
- $_var_24 = intval(SafeRequest("status", "get"));
- $_var_25 = db("item")->where("id", $_var_23)->update(["status" => $_var_24]);
- $this->ShowMessage("恭喜您,状态切换成功!", "?c=item", "infotitle2", 1000, 1);
- }
- }
|