StoreProductRule.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\models\store;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. /**
  6. * 商品规则
  7. * @mixin think\Model
  8. */
  9. class StoreProductRule extends BaseModel
  10. {
  11. /**
  12. * 模型名称
  13. * @var string
  14. */
  15. protected $name = 'store_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', 'LIKE', '%' . $where['rule_name'] . '%');
  26. $model = $model->order('id desc');
  27. $list = $model->page((int)$where['page'], (int)$where['limit'])
  28. ->select()
  29. ->each(function ($item) {
  30. if ($item['rule_value']) {
  31. $specs = json_decode($item['rule_value'], true);
  32. foreach ($specs as $key => $value) {
  33. $attr_name[] = $value['value'];
  34. $attr_value[] = implode(',', $value['detail']);
  35. }
  36. $item['attr_name'] = implode(',', $attr_name);
  37. $item['attr_value'] = $attr_value;
  38. }
  39. });
  40. $data = count($list) ? $list->toArray() : [];
  41. $count = $model->count();
  42. return compact('count', 'data');
  43. }
  44. /**
  45. * 详情
  46. * @param $id
  47. * @return array
  48. */
  49. public static function sysInfo($id)
  50. {
  51. $info = self::get($id);
  52. $info['rule_value'] = json_decode($info['rule_value'], true);
  53. return $info;
  54. }
  55. }