|
|
@@ -0,0 +1,73 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace ghs\controllers;
|
|
|
+
|
|
|
+use biz\market\classes\XrFlClass;
|
|
|
+use common\components\arrayUtil;
|
|
|
+use common\components\util;
|
|
|
+use Yii;
|
|
|
+
|
|
|
+class XrFlController extends BaseController
|
|
|
+{
|
|
|
+
|
|
|
+ public function actionDetail()
|
|
|
+ {
|
|
|
+ $list = XrFlClass::getAllByCondition(['shopId' => $this->shopId, 'delStatus' => 0], 'hbAmount DESC', '*');
|
|
|
+ $xrFl = $this->shop->xrFl ?? 0;
|
|
|
+ util::success(['list' => $list, 'xrFl' => $xrFl]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存福利内容 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('数据错误');
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ $amount = $item['amount'] ?? 0;
|
|
|
+ if ($totalHb >= $amount) {
|
|
|
+ $index = $key + 1;
|
|
|
+ util::fail('第' . $index . '个红包,红包总金额超过充值金额');
|
|
|
+ }
|
|
|
+
|
|
|
+ $item['shopId'] = $this->shopId;
|
|
|
+ $item['sjId'] = $this->sjId;
|
|
|
+ $item['totalHb'] = $totalHb;
|
|
|
+ XrFlClass::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('没有保存成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|