$this->shopId, 'delStatus' => 0], 'amount DESC', '*'); $recharge = $this->shop->recharge ?? 0; util::success(['list' => $list, 'recharge' => $recharge]); } //保存红包内容 ssh 20210930 public function actionSaveHb() { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); util::fail('已停用'); //指定只有一二个商家有充值活动使用权 $env = getenv('YII_ENV', 'local'); if ($env == 'production') { $arr = [3, 5, 10, 22, 154, 209, 214]; if (in_array($this->shopId, $arr) == false) { util::fail('您没有权限使用此活动'); } } try { $data = Yii::$app->request->post('data'); $arr = json_decode($data, true); if (is_array($arr) == false) { util::fail('数据错误'); } RechargeHbClass::updateByCondition(['shopId' => $this->shopId], ['delStatus' => 1]); $arr = arrayUtil::arraySort($arr, 'amount'); foreach ($arr as $key => $item) { $mini = $item['miniExpend'] ?? 0; $hbAmount = $item['hbAmount'] ?? 0; if ($mini <= $hbAmount) { util::fail('最低消费金额要大于红包金额'); } $valid = $item['valid'] ?? 0; if (empty($valid)) { util::fail('请填写红包有效期'); } $num = $item['num'] ?? 0; if ($num <= 0) { util::fail('请填写红包数量'); } $totalHb = bcmul($hbAmount, $num, 2); $amount = $item['amount'] ?? 0; if ($totalHb >= $amount) { $index = $key + 1; util::fail('第' . $index . '个红包,红包总金额超过充值金额'); } $item['shopId'] = $this->shopId; $item['sjId'] = $this->sjId; $item['totalHb'] = $totalHb; RechargeHbClass::add($item); } $rechargeSwitch = Yii::$app->request->post('rechargeSwitch', 0); $this->shop->recharge = $rechargeSwitch; $this->shop->save(); $transaction->commit(); util::complete(); } catch (\Exception $e) { $transaction->rollBack(); util::fail('没有保存成功'); } } }