提交服务端基础框架
This commit is contained in:
37
Server/application/common/model/ProductGroupModel.php
Normal file
37
Server/application/common/model/ProductGroupModel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ProductGroupModel extends Model {
|
||||
|
||||
/**
|
||||
* 获取关联数组
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function assoc() {
|
||||
$assoc = NULL;
|
||||
if (is_null($assoc)) {
|
||||
$assoc = [];
|
||||
foreach (static::where(1)
|
||||
->order('id', 'DESC')
|
||||
->select() as $model) {
|
||||
$assoc[$model->getAttr('id')] = $model->getAttr('name');
|
||||
}
|
||||
}
|
||||
return $assoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*
|
||||
* @return ProductModel
|
||||
*/
|
||||
public function productNum() {
|
||||
return ProductModel::where(1)
|
||||
->where('group_id', $this->getAttr('id'))
|
||||
->count();
|
||||
}
|
||||
}
|
||||
26
Server/application/common/model/ProductModel.php
Normal file
26
Server/application/common/model/ProductModel.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ProductModel extends Model {
|
||||
|
||||
const IS_USED_NO = 0;
|
||||
const IS_USED_YES = 10;
|
||||
|
||||
protected $json = ['cb', 'images', 'labels', 'themes', 'opts'];
|
||||
protected $jsonAssoc = TRUE;
|
||||
|
||||
/**
|
||||
* 获取是否使用
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
static public function isUsedAssoc() {
|
||||
return [
|
||||
static::IS_USED_NO => '未使用',
|
||||
static::IS_USED_YES => '已使用',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user