ProductRule.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\model\system;
  3. use library\basic\BaseModel;
  4. use library\traits\ModelTrait;
  5. /**
  6. * 商品规则
  7. * @mixin think\Model
  8. */
  9. class ProductRule extends BaseModel
  10. {
  11. /**
  12. * 模型名称
  13. * @var string
  14. */
  15. protected $name = 'product_rule';
  16. use ModelTrait;
  17. /**
  18. * 列表
  19. * @param $where
  20. * @return array
  21. */
  22. public static function sysPage($where)
  23. {
  24. $model = new self;
  25. if ($where['rule_name']) $model = $model->where('rule_name','LIKE','%'.$where['rule_name'].'%');
  26. //if ($where['mer_id']) $model = $model->where('mer_id', $where['mer_id']);
  27. $model=$model->order('id desc');
  28. $count = $model->count();
  29. $list = $model->page((int)$where['page'], (int)$where['limit'])
  30. ->select()
  31. ->each(function ($item) {
  32. if ($item['rule_value']) {
  33. $specs = json_decode($item['rule_value'],true);
  34. if($specs){
  35. foreach ($specs as $key=>$value){
  36. $attr_name[] = $value['value'];
  37. $attr_value[] = implode(',',$value['detail']);
  38. }
  39. }else{
  40. $attr_name[] = '';
  41. $attr_value[] = '';
  42. }
  43. $item['attr_name'] = implode(',',$attr_name);
  44. $item['attr_value'] = $attr_value;
  45. }
  46. });
  47. return compact('count', 'list');
  48. }
  49. /**
  50. * 详情
  51. * @param $id
  52. * @return array
  53. */
  54. public static function sysInfo($id)
  55. {
  56. $info = self::get($id);
  57. $info['spec'] =json_decode($info['rule_value'],true);
  58. return compact('info');
  59. }
  60. }