affiliate
1.0.0
This is a best practice demonstration system that I have developed for many years in PHP. The front-end uses VueJS 2.6 + ElementUI, the back-end uses PHP Laravel 6.2, and is based on MySQL 5.7 storage. It is not too complicated. It demonstrates the development of a front-end and back-end separation system and shows the operation process of VueJS+PHP(Laravel)+MySQL. It is a complete and operational system. It has alliance customer module, order module and material module. The parts involving RabbitMQ message middleware are not easy to demonstrate, so they are not included.
修改 /etc/hosts
127.0.0.1 www.dev.com api.dev.com admin.dev.com
api 基于Laravel 6.2的Api服务器,演示部署域名: api.dev.com
frontend 给联盟客用的主站界面,演示部署域名: www.dev.com
backend 后台管理界面,演示部署域名: admin.dev.com
use App Http Requests Backend BannerListPost ;
class BannerController extends Controller
{
/**
* 列表
* @author: [email protected]
* Date: 2019-11-13
*
* @param BannerListPost $post
*
* @return IlluminateHttpJsonResponse
*/
public function actionList ( BannerListPost $ post )
{
$ totalRows = 0 ;
$ list = BannerService:: singleton ()-> findListByPage ( $ post , $ totalRows );
foreach ( $ list as $ item ) {
$ item -> thumb_url = UtilHelper:: thumbUrl ( $ item -> pic_url );
$ item -> statusText = BannerEnum:: STATUS_TEXT_LIST [ $ item -> status ] ?? '' ;
}
return $ this -> jsonSuccess ([
' list ' => $ list ,
' page ' => $ post -> page ,
' perPage ' => $ post -> perPage ,
' totalRows ' => $ totalRows
]);
}
}
/**
* 使用Laravel参数验证器
* Class BannerListPost
* @package AppHttpRequests
*
* @property $title string
* @property $status int
*/
class BannerListPost extends BasePageListPost
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules ()
{
return [
' status ' => ' nullable|integer|in:1,2 ' ,
' title ' => ' nullable|min:1|max:50 ' ,
];
}
public function attributes ()
{
return [
' title ' => '标题' ,
' status ' => '上架状态' ,
];
}
}
class BannerService extends BaseService
{
/**
* @author: [email protected]
* Date: 2019-11-13
*
* @param BannerListPost $post
* @param int $totalRows
*
* @return BannerModel[]
*/
public function findListByPage ( BannerListPost $ post , int & $ totalRows )
{
$ where = [];
if ( $ post -> title ) {
$ where [] = [ ' title ' , ' like ' , ' % ' . addcslashes ( $ post -> title , ' % ' ). ' % ' ];
}
if ( $ post -> status ) {
$ where [] = [ ' status ' , ' = ' , $ post -> status ];
}
$ list = BannerModel:: singleton ()-> findListByPage ( $ where , $ post -> page , $ post -> perPage , $ totalRows );
return $ list ;
}
}
class BannerModel extends ValidateBaseModel
{
/**
* 分页获取多个实例(Model数组)
* @author: [email protected]
* Date: 2019-03-02 *
*
* @param array $where
* @param int $page
* @param int $perPage
* @param int $totalRows 返回查询总数
*
* @return static[]
*/
public function findListByPage ( array $ where , $ page , $ perPage , & $ totalRows , $ orderByDesc = ' id ' )
{
$ query = static :: query ();
$ query -> where ( $ where )-> forPage ( $ page , $ perPage )-> orderByDesc ( $ orderByDesc );
$ list = $ query -> get ()-> all ();
$ totalRows = $ query -> toBase ()-> getCountForPagination ();
return $ list ;
}
}