Houseactivityspec.php
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace app\admin\model;
use think\Model;
class Houseactivityspec extends Model
{
// 表名
protected $name = 'house_activity_spec';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 批量添加活动sku记录
* @param $house_activity_id
* @param $spec_list
* @return array|false
* @throws \Exception
*/
public function addSkuList($house_activity_id, $spec_list)
{
$data = [];
foreach ($spec_list as $item) {
$data[] = array_merge($item['form'], [
'spec_sku_id' => $item['spec_sku_id'],
'house_activity_id' => $house_activity_id,
]);
}
return $this->saveAll($data);
}
/**
* 添加商品活动关系记录
* @param $house_activity_id
* @param $spec_attr
* @return array|false
* @throws \Exception
*/
public function addGoodsSpecRel($house_activity_id, $spec_attr)
{
$data = [];
array_map(function ($val) use (&$data, $house_activity_id) {
array_map(function ($item) use (&$val, &$data, $house_activity_id) {
$data[] = [
'house_activity_id' => $house_activity_id,
'spec_id' => $val['group_id'],
'spec_value_id' => $item['item_id'],
];
}, $val['spec_items']);
}, $spec_attr);
$model = new Houseactivityspecrel;
return $model->saveAll($data);
}
/**
* 移除指定活动的所有sku
* @param $house_activity_id
* @return int
*/
public function removeAll($house_activity_id)
{
$model = new Houseactivityspecrel;
$model->where('house_activity_id','=', $house_activity_id)->delete();
return $this->where('house_activity_id','=', $house_activity_id)->delete();
}
}