123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\model\system;
- use library\basic\BaseModel;
- use library\traits\ModelTrait;
- /**
- * 商品规则
- * @mixin think\Model
- */
- class ProductRule extends BaseModel
- {
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'product_rule';
- use ModelTrait;
- /**
- * 列表
- * @param $where
- * @return array
- */
- public static function sysPage($where)
- {
- $model = new self;
- if ($where['rule_name']) $model = $model->where('rule_name','LIKE','%'.$where['rule_name'].'%');
- //if ($where['mer_id']) $model = $model->where('mer_id', $where['mer_id']);
- $model=$model->order('id desc');
- $count = $model->count();
- $list = $model->page((int)$where['page'], (int)$where['limit'])
- ->select()
- ->each(function ($item) {
- if ($item['rule_value']) {
- $specs = json_decode($item['rule_value'],true);
- if($specs){
- foreach ($specs as $key=>$value){
- $attr_name[] = $value['value'];
- $attr_value[] = implode(',',$value['detail']);
- }
- }else{
- $attr_name[] = '';
- $attr_value[] = '';
- }
- $item['attr_name'] = implode(',',$attr_name);
- $item['attr_value'] = $attr_value;
- }
- });
- return compact('count', 'list');
- }
- /**
- * 详情
- * @param $id
- * @return array
- */
- public static function sysInfo($id)
- {
- $info = self::get($id);
- $info['spec'] =json_decode($info['rule_value'],true);
- return compact('info');
- }
- }
|