# Niushop開源商城后臺功能
---
后臺功能開發基礎功能可以查看thinkphp5手冊:[http://www.hmoore.net/manual/thinkphp5/118003](http://www.hmoore.net/manual/thinkphp5/118003)
下面說一下關于niushop標準化的書寫方法:
### 1. **數據獲取**
niushop獲取數據統一采用request\\(\\)->get\\(\\),或者request->post\\(\\)方法,具體的使用方法可以參看thinkphp,例如:
```php
$brand_name = request()->post('brand_name', '');
$brand_initial = request()->post('brand_initial', '');
$describe = request()->post('describe', '');
$brand_pic = request()->post('brand_pic', '');
$brand_recommend = request()->post('brand_recommend', '');
$category_name = request()->post('category_name', '');
$category_id_1 = request()->post('category_id_1', 0);
$category_id_2 = request()->post('category_id_2', 0);
$category_id_3 = request()->post('category_id_3', 0);
$brand_ads = request()->post('brand_ads', '');
```
### 2. **數據返回:**
niushop針對數據返回統一數據結構,統一采用ajaxReturn方法,例如:
```php
/**
* 添加商品品牌
*/
public function addGoodsBrand()
{
if (request()->isAjax()) {
$goodsbrand = new GoodsBrand();
$brand_name = request()->post('brand_name', '');
$brand_initial = request()->post('brand_initial', '');
$describe = request()->post('describe', '');
$brand_pic = request()->post('brand_pic', '');
$brand_recommend = request()->post('brand_recommend', '');
$category_name = request()->post('category_name', '');
$category_id_1 = request()->post('category_id_1', 0);
$category_id_2 = request()->post('category_id_2', 0);
$category_id_3 = request()->post('category_id_3', 0);
$brand_ads = request()->post('brand_ads', '');
$sort = 0;
$params = [
"shop_id" => $this->instance_id,
"brand_name" => $brand_name,
"brand_initial" => $brand_initial,
"describe" => $describe,
"brand_pic" => $brand_pic,
"brand_recommend" => $brand_recommend,
"category_name" => $category_name,
"category_id_1" => $category_id_1,
"category_id_2" => $category_id_2,
"category_id_3" => $category_id_3,
"sort" => $sort,
"brand_ads" => $brand_ads,
];
$res = $goodsbrand->editGoodsBrand($params);
return AjaxReturn($res);
} else {
$goodscategory = new GoodsCategory();
$list = $goodscategory->getGoodsCategoryListByParentId(0);
$this->assign('goods_category_list', $list);
return view($this->style . "Goods/addGoodsBrand");
}
}
```
### 3. 業務邏輯
niushop針對業務邏輯的處理是在service層中,service路徑:data/service