12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\api\logic;
-
- use app\common\basics\Logic;
- use app\common\model\goods\GoodsBrand;
-
- class GoodsBrandLogic extends Logic
- {
-
-
- public static function getGoodsBrandList()
- {
- $where = [
- 'del' => 0,
- 'is_show' => 1,
- ];
- $list = GoodsBrand::field('id,name,image,initial')
- ->where($where)
- ->order('sort', 'asc')
- ->select()
- ->toArray();
-
- return self::format($list);
- }
-
-
-
- public static function format($list)
- {
-
- $letters = range('A', 'Z');
- $newList = [];
- foreach($letters as $key => $letter) {
- $newList[$key]['letter'] = $letter;
- $newList[$key]['list'] = [];
- foreach($list as $item) {
- if(strtoupper($item['initial']) == $letter) {
- $newList[$key]['list'][] = $item;
- }
- }
-
- if(!$newList[$key]['list']) {
- unset($newList[$key]);
- }
- }
-
- $newList = array_merge([], $newList);
- return $newList;
- }
- }
|