# fast **Repository Path**: Dogw/fast ## Basic Information - **Project Name**: fast - **Description**: 云课堂 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-23 - **Last Updated**: 2024-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README MVC C:Controller 控制器 业务逻辑 M:Model 模型 操作数据(数据库) 增删查改 数据库查询 V:View 视图(页面) 页面html显示 公司通讯录案例做法:纯源生PHP源代码 没有任何架构可言 业务逻辑、数据库查询、页面html显示 过程式的写法 Thinkphp框架5.0 PHP框架 MVC架构 常见封装(文件上传 、分页、验证码) 纯裸框架 底层框架 FastAdmin 二次开发系统 基于Thinkphp5.0版本 ERP系统标准版该有的功能(管理员/系统设置/权限管理) 30%功能 就不用做了 FastAdmin 属于在 基于Thinkphp的基础上,迭代了一些功能上去。可以帮助我们不用完全从0开始做 我们更多的精力需要放到 需求 业务逻辑的实现上面 云课堂(前台 + 后台) FastAdmin官网:https://www.fastadmin.net/ 自己项目的命名:fast 配置站点:www.fast.com 指向到:public/ .htaccess -> apache的URL重写文件 前台:www.fast.com 后台:www.fast.com/erp.php 账号:admin 密码:admin123 前台程序入口:public/index.php 后台程序入口:public/erp.php 应用程序目录:application 在执行命令的时候,一定要先进入到项目的根目录 前台模块:home 创建前台模块: php think build --module home 想访问home模块 application: MVC www.fast.com -> 指向到 public 目录下 application/ 应用程序的MVC的目录 config.php 应用的配置文件 'app_debug' => true, //开启调试 // 默认模块名 'default_module' => 'index', /application/index/ // 默认控制器名 'default_controller' => 'Index', /application/index/controller/Index.php // 默认操作名 'default_action' => 'index', /application/index/controller/Index.php -> public function index public/ 公共访问目录 index.php 程序的入口文件 think 框架的命令行文件 独立模块:前台(home)、后台(admin) 独立模块: MVC url地址开始入手 http://www.fast.com/index.php apache http://www.fast.com/index.php/index/index/index http://www.fast.com/index.php/模块/控制器/方法 http://www.fast.com/home/business/index 如果自己创建一个模块,需要用到命令行 php think build --module 模块的名称 php think build --module home 自己创建一个控制器,需要用到命令行 php think make:controller 模块/控制器名 php think make:controller home/Business 页面URL:http://www.fast.com/home(模块)/index(控制器)/index(方法) 控制器文件C:application/home/controller/Index.php(public index) 模板文件V:application/home/view/index/index.html 前台静态资源文件:public/assets/home/ http://www.fast.com/home/index/login 生成url地址:url('模块/控制器/方法') //找对应的模块下的config文件下进行模块布局 模板布局:home/config.php 开启模板布局 清除缓存的命令 php think clear 不要把所有的程序都写在一个控制器中 要按照模块的概念去分离 跟用户有关 user 跟商户有关 business 跟课程有关 subject 跟订单有关 order 跟商品有关 product 跟支付有关 pay 如果view 中模版文件夹下的文件于 控制器下的方法名字不对应 public function index(){ return $this->view->fetch('business/center'); } 创建模型 把business 的模型创建在公共部分中 php think make:model common/Business/Business php think make:model common/Business/Source //validate验证器 //注册功能的实现 配制中文不值要在config中设置 还需要 在相应的模块中添加lang中文文件 通过url地址 -> 访问控制器 -> 视图 控制器:C -> 写业务逻辑 视图:V -> 显示页面 模型:M -> 数据库操作 验证器:validate 接收数据 $_POST $_GET $_FILES name="nickname" 将模型放到 公共模块 common php think make:model 模块/模型文件 php think make:model common/Business/Business php think make:model common/Business/Source 在程序调试中: 单条数据打印: $business = $this->BusinessModel->find() var_dump($businss->toArray()); //将对象集合 转换为数组 只用于打印(1位数组) 多条数据打印: $business = $this->BusinessModel->select() var_dump(collection($business)->toArray()); //将对象集合 转换为数组 只用于打印(2位数组) 调试SQL语句打印: echo $this->BusinessModel->getLastSql(); exit; helpers.php 公共函数库 composer == nodejs npm npm 包管理工具 下载插件 -> package.json composer 包管理工具 下载插件 composer.json 安装第三方插件 composer require jian1098/tp5-validate:dev-master php think make:validate common/Business/Business PHP单继承面向对象 Business => Home => Controller 判断某个数据是否在数组里面 in_array(数据,数组) //把数据赋值到模版里去 $this->view->assign('名称',模版变量值) //获取当前的模块名 $module = $this->request->module(); //获取当前的控制器名 $controller = $this->request->controller(); //获取当前的方法名 $action = $this->request->action(); $strurl = $module.'/'.$controller.'/'.$action; return $strurl; 前端赋值 {$名称.属性} //cookie普通的删除方法 // cookie('busid',NULL); // cookie('mobile',NULL); //个人资料界面 //由common 中的Home 控制器下的 isLogin方法 将 登录的查询的数据放在 模版上 $this->view->assign('businessLogin',$businessLogin); 然后 前端赋值 {$businessLogin.属性} m处理数据 v显示页面 c处理业务 redirect重定向 做地址 创建地址 的模型 php think make:model common/Region request()->domain() $default = trim(config('site.cover'));//上传系统的默认图 save()方法即有插入又有更新 把插入方法改成修改 ..->isUpdate(true)->save(数据) // echo model('Business.Business')->getLastSql(); 修改数据的时候要记得给id // var_dump($data); // exit; 邮箱认证 接口 阿里云 sendclond 163 不可以这样写 {if condition="{!$businessLogin.auth}"} {/if} {if condition="!$businessLogin.auth"} {/if} destroy() 删除 例子 $this->BusinessModel->startTrans(); startTrans()开启事务 rollback()回滚 commit()提交 //原样输出 {literal} 不解析tp框架 {/literal} //保留的文件路径 imagejpeg imagepng // 释放内存 imagedestroy($PosterImg); imagedestroy($QrcodeImg); imagedestroy($AvatarImg); 安装二维码插件 composer require dh2y/think-qrcode:1.0 在二维码生成的过程中会出现容错率这个概念 L(Low):约7%的容错率,可以容忍较小的错误。 M(Medium):约15%的容错率,可以容忍中等程度的错误。 Q(Quartile):约25%的容错率,可以容忍较大程度的错误。 H(High):约30%的容错率,可以容忍最高程度的错误。 //容错率解析 $level = ['L', 'M', 'Q', 'H']; // 索引数组 // 只返回一个随机键名(索引) $singleIndex = array_rand($level); echo $singleIndex; // 输出可能是 0, 1, 2, 或 3 // 返回一个包含两个随机键名的数组 $multipleIndexes = array_rand($level, 2); print_r($multipleIndexes); // 输出可能是 Array ( [0] => 0, [1] => 3 ),但顺序和具体值会随机变化 // 使用返回的键名来获取对应的值 echo $level[$singleIndex]; // 输出可能是 'L', 'M', 'Q', 或 'H' // 对于多个键名,你可能需要遍历数组来获取对应的值 foreach ($multipleIndexes as $index) { echo $level[$index] . "\n"; // 输出两个随机选择的容错率级别 } //js中自带的复制功能 // 复制可编辑标签中的value值得内容 function copy1() { const inputEle = document.querySelector("#input"); inputEle.select(); // 鼠标选择的内容 document.execCommand("copy"); // 复制 } //画报功能 string(53) "uploads/20240927/f6a43b6821c6f11a217944062becb1ef.png" 二维码存入的地址 \uploads\qrcode\1727423485.png file_get_contents()读取本地文件 imagecreatefromstring()创建图片实例 list($width, $height)=getimagesize($filename); //缩放比例 $per=round(400/$width,3); $n_w=$width*$per; $n_h=$height*$per; $new=imagecreatetruecolor($n_w, $n_h); $img=imagecreatefromjpeg($filename); //copy部分图像并调整 imagecopyresized($new, $img,0, 0,0, 0,$n_w, $n_h, $width, $height); imagesx(图片对象) 求图片的宽 //将某个图片 嵌入到另一个图片里面 imagecopymerge() imagecolorallocate 把文字放入图片里 imagettftext() echo str_replace("world","Shanghai","Hello world!"); 如果发起ajax请求的话 ,返回值的时候不要打印,否则会印象值 Db类 Db::name(数据库名字)->方法 tp手册 数据库 查询 链式 助手函数--测试会停止后面代码 halt() //获取get请求 request()->get('name','默认值',‘过滤方法’) // 请求类 => request // $keyword = request()->get('keyword','','trim'); $keyword = $this->request->param('keyword','','trim'); // 模型 => 对某个数据表进行增删查改 Db => 对整个数据库 // where => WHERE `auth` = '1' // $businessData = Db::table('fa_business')->where('auth','1')->where('money','>',0)->order('createtime desc')->select(); // var_dump($businessData); // exit; // $businessCount = Db::name('business')->where([ // 'auth' => '1', // 'money' => ['>',0] // ])->count(); // 助手函数 => model halt => 调试并且停止执行后面代码 // halt($businessCount); $where = []; if($keyword) { $where['nickname|mobile'] = ['LIKE',"%$keyword%"]; } // 只需要id nickname mobile createtime $businessData = Db::name('business')->field('id,nickname,mobile,createtime')->where($where)->order('createtime desc')->select(); $this->assign([ 'businessData' => $businessData ]); return $this->fetch(); 前端的foreach循环 {foreach $businessLogin as $key=>$value} {$value.id} {/foreach} whereTime()拿时间 public function edit() { $id = $this->request->param('id',0,'trim'); $business = Db::name('business')->find($id); if(!$business) { $this->error('用户不存在'); } // 判断是否有POST请求 if($this->request->isPost()) { $params = $this->request->param(); //删除id unset($params['id']); // halt($params); $result = Db::name('business')->where('id',$id)->update($params); // halt(Db::getLastSql()); if($result) { $this->success('更新成功',url('/home/index/index')); }else{ $this->error('更新失败'); } // halt($business); } $sourceData = Db::name('business_source')->select(); $this->assign([ 'business' => $business, 'sourceData' => $sourceData ]); return $this->fetch(); } 查询一个字段的方法:value -> string 查询两个字段的方法:column(字段1,字段2) -> 数组 [字段1=>字段2] 不会给到模型的自定义字段 多个字段的方法:field->select() 在通过toArray打印数据 1.创建模型 课程 课程老师 课程分类 3个模型 css object-fit 执行 find 和select方法 会自动调用 模型中的获取器方法 做课程 SELECT * FROM fa_subject LEFT JOIN fa_teacher 课程名称 课程分类 老师名称 价格 订单数量 数量index 关联查询的例子 public function subject() { //Order->belongsTo(课程的模型, 外键字段subid, 主键) return $this->belongsTo('app\common\model\Subject\Subject', 'subid', 'id', [], 'LEFT')->setEagerlyType(0); //0 1 } //做学员评论 business comment subject 五角星做法初步思路 for循环 亮的五角星 { } for循环 不亮的五角星 { } 做老师info页面 不需要ajax 上边部分 需要老师的名称 课程的数量 职务 粉丝 需要ajax 下边需要 该老师教的课程 课程分类 创建时间 价格 关注数 图片 js获取参数的方法{ // 假设这是你的当前URL const url = new URL(window.location.href); // 获取参数值 const param1 = url.searchParams.get('paramName1'); const param2 = url.searchParams.get('paramName2'); console.log(param1); // 输出第一个参数的值 console.log(param2); // 输出第二个参数的值 } 查看粉丝的信息 nickname avatar_text auth mobile gender_text position :sticky 粘性定位的元素是依赖于用户的滚动,在 position:relative 与 position:fixed 定位之间切换。 它的行为就像 position:relative; $this->request->url()返回当前界面 $this->request->server('HTTP_REFERER') 返回上一层层的页面 http%3A%2F%2Fwww.fast.com%2Fhome%2Findex%2Flogin.html http%3A%2F%2Fwww.fast.com%2Fhome%2Findex%2Flogin.html http%3A%2F%2Fwww.fast.com%2Fhome%2Findex%2Flogin.html on() 和 click() 的区别: 二者在绑定静态控件时没有区别,但是如果面对动态产生的控件,只有 on() 能成功的绑定到动态控件中。 array_filter 去空 array_unique去重 in_array 判断在一个数组中是否存在某一个数据 array_search 找到索引位置 likes_active 创建模型 使用ajax传值 收藏表 avatar_text price title 查询某个用户的优惠券数量 data coupon两个数组 coupon.map(function(item){ data.push({value:item.id,text:`【优惠券活动】 ${item.coupon.title} ¥${item.coupon.rate*100} 折`}) }) map方法是js当中遍历数组的 json_encode()将php数据转化成json数据 json_decode()将json数据转化成php数据 JSON.parse()//将json数据格式化成js数据 // 将数组转换为JSON字符串 JSON.stringify(); //bcsub(被减数,减数,保留几位小数); bcsub(99.99, 11.11, 2); // "88.88" //bcmul(被乘数,乘数,保留几位小数); bcmul(11.11, 11.11, 2); // "123.43" //bcdiv(被除数,除数,保留几位小数); bcdiv(100, 3, 2); // "33.33" //bcpow(数字,次方,保留几位小数); bcpow(2.1,3, 2); // "9.26" //bcsqrt(被开方数,保留几位小数); 此函数开平方 bcsqrt( 3, 5) // "1.73205" //bccomp('数字','数字','精确位数') — 比较两个任意精度的数字 bccomp('1','2'); // -1 :前面的数小于后面的数 bccomp('1.00001','1' ,3); // 0 :前面的数等于后面的数 bccomp('1.00001','1',5); // 1 :前面的数大于后面的数 array(7) { ["id"]=> int(44) ["cid"]=> int(1) ["busid"]=> int(56) ["createtime"]=> int(1728464416) ["status"]=> string(1) "1" ["coupon"]=> array(11) { ["id"]=> int(1) ["title"]=> string(18) "购物节优惠券" ["thumb"]=> string(23) "/uploads/20231206/1.jpg" ["createtime"]=> int(1709222400) ["endtime"]=> int(1716998400) ["rate"]=> string(4) "0.95" ["total"]=> int(16) ["status"]=> string(1) "1" ["createtime_text"]=> string(10) "2024-03-01" ["endtime_text"]=> string(10) "2024-05-30" ["thumb_text"]=> string(73) "http://www.fast.com/uploads/20240928/12102e9d856b0c0e9b797b87db989710.gif" } ["createtime_text"]=> string(10) "2024-10-09" } //做个人优惠券 未使用 已使用 已过期 disabled button按钮无法点击 余额充值 ----------------------后台-------------------------- ------------------------------------------------- 菜单规则 -> 角色组 -> 管理员 左侧菜单(操作的功能) 先有菜单规则,角色组才可以去关联规则,管理选择角色。 后台开发功能: 1、手动去创建文件 2、命令行的方式创建文件 后台开发一个功能需要的文件有哪些: 可以将有关系的一系列的方法:放到一个顶级菜单下面 客户中心 business application/admin/controller/business 客户来源(数据列表) business/source application/admin/controller/business/Source.php 查(列表) business/source/index Source.php -> public functin index() 增(添加) business/source/add Source.php -> function add() 改(更新) business/source/edit 删(删除) business/source/del 客户公海 申请 分配 删除 客户私海 添加 编辑 删除 回收 查看资料 C控制器:application/admin/controller/business/Source.php V视图:application/admin/view/business/source/index.html... M模型:application/common/model/business/Source.php JS的控制器!:public/assets/js/backend/business/source.js 语言包文件:application/admin/lang/business/source.php 创建控制器 php think make:controller admin/business/Source 每一个控制器请求的方法对应JS模块中一个方法 PHP控制器 === JS模块控制器 PHP控制器: index add edit del JS模块控制器: index add edit del application/common/controller/Backend.php PHP公共控制器 public/assets/js/backend.js JS公共模块控制器 列表返回的数据数定死选项名 total => 列表总数 rows => 列表返回名称 trait是一种为类提供跨类共享代码的机制。 require-table.js 查看默认表格属性 模块化的概念 js只做页面渲染 后端做增删改查 回收站 恢复 删除(软删除)-> 不是真正的删除 给数据标记一个状态 销毁 (真正的删除) business/source/recyclebin 回收站 business/source/destroy 真实删除 business/source/restore 还原 客户公海 -> 二级菜单 business/highsea business/highsea/index 列表 business/highsea/apply 领取 business/highsea/allot 分配 business/highsea/del 软删除 客户私海 -> 二级菜单 business/privatesea business/privatesea/index 私海列表 business/privatesea/add 添加资源 business/privatesea/edit 编辑资源 saveAll 方法新增数据默认会自动识别数据是需要新增还是更新操作,当数据中存在主键的时候会认为是更 新操作,如果你需要带主键数据批量新增,可以使用下面的方式: 客户私海:business/privatesea 查看:business/privatesea/index 添加:business/privatesea/add 销售自己录入的客户资源(添加动作insert) 分配动作 insert -> business adminid = auth->id insert -> business_receive status = allot 编辑:business/privatesea/edit 更新客户资料 删除:business/privatesea/del 软删除 回收:business/privatesea/recovery 详情:business/info php think make:controller admin/business/Privatesea php think make:controller admin/business/Info 图标 fa fa-eye fa fa-eye 回收 fa fa-recycle array(29) { ["id"]=> int(67) ["mobile"]=> string(11) "15543210983" ["nickname"]=> string(4) "qwe1" ["password"]=> string(32) "d6091b999db3fc3fc6145a53ed7669f2" ["salt"]=> string(10) "WLp3QcrU3M" ["avatar"]=> string(73) "http://www.fast.com/uploads/20241017/589e0eb72f5e4c76461eac0fdf65740b.gif" ["gender"]=> string(1) "2" ["sourceid"]=> int(2) ["deal"]=> string(1) "0" ["openid"]=> NULL ["province"]=> string(6) "450000" ["city"]=> string(6) "450900" ["district"]=> string(6) "450921" ["adminid"]=> int(1) ["createtime"]=> int(1729155494) ["deletetime"]=> NULL ["money"]=> string(4) "0.00" ["email"]=> string(10) "123@qq.com" ["auth"]=> string(1) "1" ["poster"]=> NULL ["parentid"]=> NULL ["gender_text"]=> string(3) "女" ["poster_text"]=> string(73) "http://www.fast.com/uploads/20240927/f6a43b6821c6f11a217944062becb1ef.png" ["province_text"]=> string(21) "广西壮族自治区" ["city_text"]=> string(9) "玉林市" ["district_text"]=> string(6) "容县" ["avatar_text"]=> string(73) "http://www.fast.com/uploads/20240928/12102e9d856b0c0e9b797b87db989710.gif" ["createtime_text"]=> string(10) "2024-10-17" ["region_text"]=> string(38) "广西壮族自治区-玉林市-容县" } recyclebin //使用命令 php think crud -t business_visit -u 1 -c business/Visit //云课堂subject //课程分类 subject/category subject/category/index 列表 subject/category/add 添加 subject/category/edit 编辑 subject/category/del 删除 课程管理 subject/subject php think crud -t subject -u 1 -c subject/Subject 订单管理 subject/order php think crud -t subject_order -u 1 -c subject/Order 名师管理 subject/teacher 回收站 subject/recyclebin/ 客户详情中的回访记录 里面后期添加一个插件 改变按钮颜色 bootstrap 客户私海 //收获地址 php think crud -t business_address -u 1 -c business/Address 名师管理 php think crud -t subject_teacher -u 1 -c subject/Teacher Summernote富文本编辑器 插件 //章节 php think crud -t subject_chapter -u 1 -c subject/Chapter //必须默认触发shown.bs.tab事件 $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab"); 优惠券 php think crud -t coupon -u 1 -c coupon/Coupon //记住选项卡的一种方式 通过命令直接实现选项卡的功能