• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / product / 13100246700

02 Feb 2025 03:42PM UTC coverage: 71.116%. Remained the same
13100246700

push

github

semantic-release-bot
chore(release): publish

See CHANGELOG.md for more details.

20 of 31 branches covered (64.52%)

357 of 502 relevant lines covered (71.12%)

25.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/Service/SkuModel.php
1
<?php
2

3
namespace Miaoxing\Product\Service;
4

5
use Miaoxing\Plugin\BaseModel;
6
use Miaoxing\Plugin\Model\HasAppIdTrait;
7
use Miaoxing\Plugin\Model\ModelTrait;
8
use Miaoxing\Plugin\Model\SnowflakeTrait;
9
use Miaoxing\Product\Model\BelongsToProductTrait;
10
use Wei\Model\SoftDeleteTrait;
11
use Wei\Ret;
12

13
/**
14
 * SKU
15
 *
16
 * @property array $specValueIds 多个规格值编号,使用,隔开
17
 * @property string|null $id 编号
18
 * @property string $appId 应用编号
19
 * @property string $outerId 外部编号
20
 * @property string $productId 商品编号
21
 * @property string $no 货号
22
 * @property string $price 销售价
23
 * @property string $marketPrice 划线价
24
 * @property int $score 所需积分
25
 * @property int $stockNum 库存
26
 * @property int $soldNum 销量
27
 * @property string $weight 重量(千克)
28
 * @property int $sort 顺序,从大到小排列
29
 * @property string $image 图片
30
 * @property string|null $createdAt
31
 * @property string|null $updatedAt
32
 * @property string $createdBy
33
 * @property string $updatedBy
34
 * @property string|null $deletedAt
35
 * @property string $deletedBy
36
 */
37
class SkuModel extends BaseModel
38
{
39
    use BelongsToProductTrait;
40
    use HasAppIdTrait;
41
    use ModelTrait;
42
    use SnowflakeTrait;
43
    use SoftDeleteTrait;
44

45
    protected $attributes = [
46
        'specValueIds' => [],
47
    ];
48

49
    protected $columns = [
50
        'specValueIds' => [
51
            'cast' => [
52
                'list',
53
                'type' => 'string',
54
            ],
55
        ],
56
    ];
57

58
    public function getGuarded()
59
    {
60
        return array_merge($this->guarded, [
54✔
61
            'soldNum',
54✔
62
        ]);
54✔
63
    }
64

65
    /**
66
     * 检查当前 SKU 是否可购买
67
     *
68
     * @return Ret
69
     */
70
    public function checkCreateCart(): Ret
71
    {
72
        // 加入购物车之后,再删除 SKU 的情况
73
        if ($this->isDeleted()) {
24✔
74
            return err('该商品规格已下架');
6✔
75
        }
76

77
        if ($this->stockNum <= 0) {
18✔
78
            return err('该商品规格已售罄');
18✔
79
        }
80

81
        return suc('可以购买');
×
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc