文件还在测试中

This commit is contained in:
2026-08-08 15:53:53 +08:00
parent 5f1e7adb64
commit 8101177cb5
241 changed files with 18074 additions and 22 deletions
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Core\Model;
class AdminUser extends Model
{
protected $table = 'admin_users';
protected $orderBy = 'id';
public function byUsername(string $u)
{
return $this->where('username', $u);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Core\Model;
class Banner extends Model
{
protected $table = 'banners';
protected $orderBy = 'sort_order';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\CRM;
use Core\Model;
class Contact extends Model
{
protected $table = 'crm_contacts';
protected $orderBy = 'id';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\CRM;
use Core\Model;
class Customer extends Model
{
protected $table = 'crm_customers';
protected $orderBy = 'id';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\CRM;
use Core\Model;
class FollowUp extends Model
{
protected $table = 'crm_followups';
protected $orderBy = 'id';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\CRM;
use Core\Model;
class Lead extends Model
{
protected $table = 'crm_leads';
protected $orderBy = 'id';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Core\Model;
class Category extends Model
{
protected $table = 'categories';
protected $orderBy = 'sort_order';
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Core\Model;
/**
* 客户案例模型(table = cases,避开 PHP 关键字 case
* 与 News 同构:支持 status 展示开关、按 published_at 排序。
*/
class CustomerCase extends Model
{
protected $table = 'cases';
protected $orderBy = 'published_at';
public function published(int $limit = 20): array
{
$all = array_filter($this->all(), fn($c) => ($c['status'] ?? 1) == 1);
return array_slice($all, 0, $limit);
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Core\Model;
class News extends Model
{
protected $table = 'news';
protected $orderBy = 'published_at';
public function published(int $limit = 20): array
{
$all = array_filter($this->all(), fn($n) => ($n['status'] ?? 1) == 1);
return array_slice($all, 0, $limit);
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Core\Model;
class Order extends Model
{
protected $table = 'orders';
protected $orderBy = 'id';
/** 按订单号查询 */
public function byNo(string $no)
{
return $this->where('order_no', $no);
}
/** 某客户的订单列表(按手机号或邮箱匹配) */
public function byCustomer(string $phone): array
{
$out = [];
foreach ($this->all() as $r) {
if (($r['phone'] ?? '') === $phone || ($r['email'] ?? '') === $phone) $out[] = $r;
}
return $out;
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models\PSI;
use Core\Model;
/**
* PSI 紧急事件 / 站内提醒(psi_events
* 所有 PSI 相关人员可见;read_by 记录已读的管理员 uid。
*/
class Event extends Model
{
protected $table = 'psi_events';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class Material extends Model
{
protected $table = 'psi_materials';
protected $orderBy = 'id';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class Outbound extends Model
{
protected $table = 'psi_outbounds';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class OutboundItem extends Model
{
protected $table = 'psi_outbound_items';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class Product extends Model
{
protected $table = 'psi_products';
protected $orderBy = 'id';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class Purchase extends Model
{
protected $table = 'psi_purchases';
protected $orderBy = 'id';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class PurchaseOrder extends Model
{
protected $table = 'psi_purchase_orders';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class PurchaseOrderItem extends Model
{
protected $table = 'psi_purchase_order_items';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class Sales extends Model
{
protected $table = 'psi_sales';
protected $orderBy = 'id';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class SalesOrder extends Model
{
protected $table = 'psi_sales_orders';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class SalesOrderItem extends Model
{
protected $table = 'psi_sales_order_items';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class StockMove extends Model
{
protected $table = 'psi_stock_moves';
protected $orderBy = 'id';
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models\PSI;
use Core\Model;
class Supplier extends Model
{
protected $table = 'psi_suppliers';
protected $orderBy = 'id';
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Core\Model;
class Page extends Model
{
protected $table = 'pages';
protected $orderBy = 'id';
public function bySlug(string $slug)
{
return $this->where('slug', $slug);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Core\Db;
use Core\Model;
/**
* 逐页 SEO 设置模型
* 表 page_seo 以 page_keyhome/products/product_category/news/cases/about/contact)为主键,
* 后台可逐页维护 标题/描述/关键词/Open Graph/规范链接/收录开关。
*/
class PageSeo extends Model
{
protected $table = 'page_seo';
protected $primaryKey = 'id';
/** 按 page_key 取单条 */
public function getByKey(string $key): ?array
{
$row = Db::query("SELECT * FROM {$this->table} WHERE page_key = ?", [$key])->fetch();
return $row ?: null;
}
/** 全部以 page_key 为索引返回 */
public function allIndexed(): array
{
$rows = Db::query("SELECT * FROM {$this->table} ORDER BY sort ASC, id ASC")->fetchAll();
$out = [];
foreach ($rows as $r) {
$out[$r['page_key']] = $r;
}
return $out;
}
/** 存在则更新,不存在则插入 */
public function saveRow(string $key, array $data): void
{
$exists = Db::query("SELECT 1 FROM {$this->table} WHERE page_key = ?", [$key])->fetch();
if ($exists) {
$sets = [];
$params = [];
foreach ($data as $k => $v) {
$sets[] = "`{$k}` = ?";
$params[] = $v;
}
$params[] = $key;
Db::query("UPDATE {$this->table} SET " . implode(', ', $sets) . " WHERE page_key = ?", $params);
} else {
$cols = array_keys($data);
$ph = array_fill(0, count($cols), '?');
Db::query(
"INSERT INTO {$this->table} (`page_key`, `" . implode('`,`', $cols) . "`) VALUES (?, " . implode(',', $ph) . ")",
array_merge([$key], array_values($data))
);
}
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Core\Model;
class Payment extends Model
{
protected $table = 'payments';
protected $orderBy = 'id';
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Core\Model;
class Product extends Model
{
protected $table = 'products';
protected $orderBy = 'sort_order';
public function byCategory(int $catId): array
{
return $this->whereAll('category_id', $catId);
}
public function featured(int $limit = 6): array
{
return array_slice(array_filter($this->all(), fn($p) => ($p['status'] ?? 1) == 1), 0, $limit);
}
public function specsArray($p): array
{
$s = $p['specs'] ?? '';
if (is_array($s)) return $s;
$dec = json_decode((string)$s, true);
return is_array($dec) ? $dec : [];
}
public function galleryArray($p): array
{
$g = $p['gallery'] ?? '';
if (is_array($g)) return $g;
$dec = json_decode((string)$g, true);
return is_array($dec) ? $g : [];
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Core\Model;
class Setting extends Model
{
protected $table = 'settings';
protected $orderBy = 'id';
/** 读取单个设置 */
public function get(string $key, $default = '')
{
$row = $this->where('skey', $key);
return $row ? $row['sval'] : $default;
}
/** 批量读取为 [skey => sval] */
public function allKV(): array
{
$out = [];
foreach ($this->all() as $r) $out[$r['skey']] = $r['sval'];
return $out;
}
/** 设置(不存在则新增) */
public function set(string $key, $val, string $group = 'site'): void
{
$row = $this->where('skey', $key);
if ($row) {
$this->update($row['id'], ['sval' => $val, 'sgroup' => $group]);
} else {
$this->insert(['skey' => $key, 'sval' => $val, 'sgroup' => $group]);
}
}
/** 批量保存 */
public function saveMany(array $pairs, string $group = 'site'): void
{
foreach ($pairs as $k => $v) $this->set($k, $v, $group);
}
}