shop; $shopId = $shop->id; $weal = RechargeSqClass::getAllByCondition(['shopId' => $shopId], null, '*', null); if (!empty($weal)) { foreach ($weal as $key => $value) { $recharge = $value['recharge'] ?? 0; $recharge = floatval($recharge); $give = $value['give'] ?? 0; $give = floatval($give); $weal[$key]['recharge'] = $recharge; $weal[$key]['give'] = $give; } } $rechargeWeal = $shop->rechargeWeal ?? 0; util::success(['weal' => $weal, 'rechargeWeal' => $rechargeWeal]); } public function actionGetRechargeData() { $mainId = $this->mainId; $arr = []; $weal = RechargeSqClass::getAllByCondition(['mainId' => $mainId], 'recharge asc', '*', null, true); if (!empty($weal)) { foreach ($weal as $key => $val) { $recharge = $val->recharge ?? 0; $recharge = floatval($recharge); $give = $val->give ?? 0; $give = floatval($give); $arr[] = ['recharge' => $recharge, 'give' => $give]; } } util::success(['recharge' => $arr]); } public function actionModifyRecharge() { $post = Yii::$app->request->post(); $data = $post['data'] ?? []; if (empty($data)) { util::fail('请填写内容'); } $shopId = $this->shopId; $mainId = $this->mainId; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { //验证recharge和give值递增 $prevRecharge = -1; $prevGive = -1; foreach ($data as $key => $item) { $currentRecharge = floatval($item['recharge'] ?? 0); $currentGive = floatval($item['give'] ?? 0); if ($currentRecharge <= $prevRecharge) { util::fail('充值金额必须递增'); } if ($currentGive <= $prevGive) { //util::fail('赠送金额必须递增'); } $prevRecharge = $currentRecharge; $prevGive = $currentGive; $sn = $key + 1; $add = ['shopId' => $shopId, 'mainId' => $mainId, 'recharge' => $currentRecharge, 'give' => $currentGive, 'sn' => $sn]; $has = RechargeSqClass::getByCondition(['mainId' => $mainId, 'sn' => $sn], true); if (!empty($has)) { $has->recharge = $currentRecharge; $has->give = $currentGive; $has->save(); } else { RechargeSqClass::add($add, true); } } $transaction->commit(); util::complete('设置成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("失败原因:" . $e->getMessage()); util::fail('设置失败'); } } }