|
|
@@ -20,48 +20,37 @@ class XrFlController extends BaseController
|
|
|
//保存福利内容 shish 20210930
|
|
|
public function actionSaveFl()
|
|
|
{
|
|
|
- $connection = Yii::$app->db;//事务处理
|
|
|
- $transaction = $connection->beginTransaction();
|
|
|
-
|
|
|
- try {
|
|
|
- $data = Yii::$app->request->post('data');
|
|
|
- $arr = json_decode($data, true);
|
|
|
- if (is_array($arr) == false) {
|
|
|
- util::fail('数据错误');
|
|
|
+ $data = Yii::$app->request->post('data');
|
|
|
+ $arr = json_decode($data, true);
|
|
|
+ if (is_array($arr) == false) {
|
|
|
+ util::fail('数据错误');
|
|
|
+ }
|
|
|
+ XrFlClass::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('最低消费金额要大于红包金额');
|
|
|
}
|
|
|
- XrFlClass::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);
|
|
|
- $item['shopId'] = $this->shopId;
|
|
|
- $item['sjId'] = $this->sjId;
|
|
|
- $item['totalHb'] = $totalHb;
|
|
|
- XrFlClass::add($item);
|
|
|
+ $valid = $item['valid'] ?? 0;
|
|
|
+ if (empty($valid)) {
|
|
|
+ util::fail('请填写红包有效期');
|
|
|
}
|
|
|
- $xrFlSwitch = Yii::$app->request->post('xrFlSwitch', 0);
|
|
|
- $this->shop->xrFl = $xrFlSwitch;
|
|
|
- $this->shop->save();
|
|
|
-
|
|
|
- $transaction->commit();
|
|
|
- util::complete();
|
|
|
- } catch (\Exception $e) {
|
|
|
- $transaction->rollBack();
|
|
|
- util::fail('保存失败');
|
|
|
+ $num = $item['num'] ?? 0;
|
|
|
+ if ($num <= 0) {
|
|
|
+ util::fail('请填写红包数量');
|
|
|
+ }
|
|
|
+ $totalHb = bcmul($hbAmount, $num, 2);
|
|
|
+ $item['shopId'] = $this->shopId;
|
|
|
+ $item['sjId'] = $this->sjId;
|
|
|
+ $item['totalHb'] = $totalHb;
|
|
|
+ XrFlClass::add($item);
|
|
|
}
|
|
|
+ $xrFlSwitch = Yii::$app->request->post('xrFlSwitch', 0);
|
|
|
+ $this->shop->xrFl = $xrFlSwitch;
|
|
|
+ $this->shop->save();
|
|
|
}
|
|
|
|
|
|
}
|