• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
孙龙 程序员
少时总觉为人易,华年方知立业难
博客园    首页    新随笔    联系   管理    订阅  订阅

php项目ai用标准模版参考

参考开发文档
1,model文件生成
例如:表名:lie_stock_in_items_ext 则命名model文件为StockInItemsExtModel
以下是model文件内容可以根据下面StockInItemsExtModel创建模型model文件:

<?php
namespace App\Http\Models;
class StockInItemsExtModel extends BaseModel
{
    public $connection = 'mysql';
    protected $table = 'lie_stock_in_items_ext';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];  //设置字段黑名单
    const   CREATED_AT = 'create_time';
    const   UPDATED_AT = 'update_time';
    public $timestamps = false;


    //来源类型常量
    const SOURCE_TYPE_SALES = 1;        //销售
    const SOURCE_TYPE_PURCHASE = 2;     //采购计划
    const SOURCE_TYPE_MES = 3;          //MES系统

    static public $sourceTypeCn = [
        self::SOURCE_TYPE_SALES => '销售',
        self::SOURCE_TYPE_PURCHASE => '采购计划',
        self::SOURCE_TYPE_MES => 'MES系统',
    ];


    /*
     * 自动维护更新时间
     */
    public function fromDateTime($value)
    {
        return strtotime(parent::fromDateTime($value));
    }

    public function getCreateTimeAttribute()
    {
        if ($this->attributes["create_time"] <= 0) {
            return "";
        }
        return date("Y-m-d H:i:s", $this->attributes["create_time"]);
    }


    //关联关系,关联到入库主表
    public function stock_in()
    {
        return $this->belongsTo(StockInModel::class, 'stock_in_id', 'stock_in_id');
    }

    //关联关系,关联到入库明细表
    public function stock_in_item()
    {
        return $this->belongsTo(StockInItemsModel::class, 'stock_in_item_id', 'stock_in_item_id');
    }


    /*
     * 新增
     */
    public function addStockInItemsExt($data)
    {
        $data = $this->filterField($data);
        return static::insertGetId($data);
    }

    public static function createInfo($data)
    {
        return self::insertGetId($data);
    }


    //获取单条数据
    public static function getOneById($id)
    {   
        $res = self::where('id', $id)->first();
        return $res ? $res->toArray() : [];
    }

    //获取多条数据
    public static function getListByIdArr($ids)
    {   
        $res = self::whereIn('id', $ids)->get();
        return $res ? $res->toArray() : [];
    }


    public static function getListByWhere($where)
    {
        $res = self::where($where)->get();
        return $res ? $res->toArray() : [];
    }

    //根据入库单ID获取扩展信息
    public static function getListByStockInId($stockInId)
    {
        return self::where("stock_in_id", intval($stockInId))->get()->toArray();
    }

    //根据入库明细ID获取扩展信息
    public static function getListByStockInItemId($stockInItemId)
    {
        return self::where("stock_in_item_id", intval($stockInItemId))->get()->toArray();
    }

    //根据入库单号获取扩展信息
    public static function getListByStockInSn($stockInSn)
    {
        return self::where("stock_in_sn", trim($stockInSn))->get()->toArray();
    }

    //根据来源ID和来源类型获取扩展信息
    public static function getListBySourceIdAndType($sourceId, $sourceType)
    {
        return self::where("source_id", intval($sourceId))
            ->where("source_type", intval($sourceType))
            ->get()
            ->toArray();
    }

    //修改数据
    public static function updateById($id, $data)
    {
        return self::where('id', $id)->update($data);
    }

    public static function updateByIdArr($idArr, $data)
    {
        return self::whereIn('id', $idArr)->update($data);
    }

    //删除
    public static function delByIds($ids){
        return self::whereIn("id", $ids)->delete();
    }

    //根据入库单ID删除
    public static function delByStockInId($stockInId){
        return self::where("stock_in_id", intval($stockInId))->delete();
    }

    //根据入库明细ID删除
    public static function delByStockInItemId($stockInItemId){
        return self::where("stock_in_item_id", intval($stockInItemId))->delete();
    }
}

本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/p/19846671

posted on 2026-04-10 14:18  孙龙-程序员  阅读(8)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3