|
|
@@ -72,18 +72,16 @@ class MemberWealController extends BaseController
|
|
|
if (empty($data)) {
|
|
|
util::fail('请填写内容');
|
|
|
}
|
|
|
+ $shopId = $this->shopId;
|
|
|
+ $mainId = $this->mainId;
|
|
|
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
-
|
|
|
- $shopId = $this->shopId;
|
|
|
- $mainId = $this->mainId;
|
|
|
-
|
|
|
//验证recharge和give值递增
|
|
|
$prevRecharge = -1;
|
|
|
$prevGive = -1;
|
|
|
- foreach ($data as $item) {
|
|
|
+ foreach ($data as $key => $item) {
|
|
|
$currentRecharge = floatval($item['recharge'] ?? 0);
|
|
|
$currentGive = floatval($item['give'] ?? 0);
|
|
|
if ($currentRecharge <= $prevRecharge) {
|
|
|
@@ -94,8 +92,16 @@ class MemberWealController extends BaseController
|
|
|
}
|
|
|
$prevRecharge = $currentRecharge;
|
|
|
$prevGive = $currentGive;
|
|
|
- $add = ['shopId' => $shopId, 'mainId' => $mainId, 'recharge' => $currentRecharge, 'give' => $currentGive];
|
|
|
- MemberWealClass::add($add, true);
|
|
|
+ $sn = $key + 1;
|
|
|
+ $add = ['shopId' => $shopId, 'mainId' => $mainId, 'recharge' => $currentRecharge, 'give' => $currentGive, 'sn' => $sn];
|
|
|
+ $has = MemberWealClass::getByCondition(['shopId' => $shopId, 'sn' => $sn], true);
|
|
|
+ if (!empty($has)) {
|
|
|
+ $has->recharge = $currentRecharge;
|
|
|
+ $has->give = $currentGive;
|
|
|
+ $has->save();
|
|
|
+ } else {
|
|
|
+ MemberWealClass::add($add, true);
|
|
|
+ }
|
|
|
}
|
|
|
$shop->rechargeWeal = 1;
|
|
|
$shop->save();
|