https://github.com/edenleung/sku
sku package for vant
https://github.com/edenleung/sku
sku thinkphp vant
Last synced: 10 months ago
JSON representation
sku package for vant
- Host: GitHub
- URL: https://github.com/edenleung/sku
- Owner: edenleung
- Created: 2020-08-17T04:00:08.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-19T08:33:08.000Z (almost 6 years ago)
- Last Synced: 2024-05-19T14:21:26.802Z (about 2 years ago)
- Topics: sku, thinkphp, vant
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sku
## 安装
```bash
$ composer require xiaodi/sku:dev-master
```
## 使用
```php
use xiaodi\Sku\Service\SkuAttr;
use xiaodi\Sku\Service\SkuGoods;
use app\model\SkuAttr;
use app\model\SkuGoods;
$sku_a = new SkuAttr(new \app\model\SkuAttr);
$sku_a->create('内存');
$sku_a->create('存储');
$sku_a->create('4g', [
'pid' => 1
]);
$sku_a->create('128G', [
'pid' => 2
]);
$sku_a->create('8g', [
'pid' => 1
]);
$sku_a->create('256G', [
'pid' => 2
]);
$sku_g = new SkuAttr(new \app\model\SkuGoods);
$sku = new Sku($sku_g, $sku_a);
// add
$mem = $sku_a->name('4g');
$storage = $sku_a->name('128G');
$sku->goods(1)->attrs($mem, $storage)->stock(1000)->price(1999)->add();
// update
$mem = $sku_a->name('8g');
$storage = $sku_a->name('256G');
$sku->goods(1)->attrs($mem, $storage)->stock(2000)->price(2999)->update(1);
// delete
$sku->delete(1);
// vant
$data = $sku->goods(1)->vant();
dump($data);
```
## Tables
```sql
CREATE TABLE `sku_goods` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`goods_id` INT(11) NOT NULL,
`sku_attrs` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`price` INT(11) NOT NULL DEFAULT '0',
`stock_num` INT(11) NOT NULL DEFAULT '0',
`create_time` INT(11) NOT NULL DEFAULT '0',
`update_time` INT(11) NOT NULL DEFAULT '0',
`delete_time` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB;
```
```sql
CREATE TABLE `sku_attr` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`pid` INT(11) NULL DEFAULT '0',
`create_time` INT(11) NOT NULL DEFAULT '0',
`update_time` INT(11) NOT NULL DEFAULT '0',
`delete_time` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE INDEX `name_pid` (`name`, `pid`)
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;
```