RepairOrderRepairPlan.php
1.29 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
<?php
namespace domain\order;
use Yii;
use domain\order\models\RepairOrderRepairPlan as RepairOrderRepairPlanModel;
/**
* 维修方案
*/
class RepairOrderRepairPlan
{
/**
* @return null|object
* @throws \yii\base\InvalidConfigException
*/
static function create($sItems)
{
if (empty($sItems)) {
return null;
}
$classData = [
'class' => RepairOrderRepairPlanModel::className()
];
foreach($sItems as $k => $v) {
$classData[$k] = $v;
}
$repairPlanModel = Yii::createObject($classData);
if($repairPlanModel->save()) {
return $repairPlanModel;
} else {
return null;
}
}
/**
* @param $orderId
* @param $plans
*/
static function batchCreate($orderId, $plans)
{
RepairOrderRepairPlanModel::deleteAll(['repair_order_id' => $orderId]);
$totalPrice = 0;
foreach($plans as $k => $plan) {
$item = [
'repair_order_id' => $orderId,
'repair_plan' => $plan['content'],
'price' => $plan['price'],
];
$totalPrice = $totalPrice + $plan['price']*1;
self::create($item);
}
return $totalPrice;
}
}