|
|
@@ -1,6 +1,9 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
+use bizHd\member\classes\MemberWealClass;
|
|
|
+use bizHd\shop\classes\ShopClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
@@ -21,7 +24,43 @@ class MemberWealController extends BaseController
|
|
|
public function actionModify()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- print_r($post);
|
|
|
+ $shopId = $this->shopId;
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $has = MemberWealClass::getByCondition(['shopId' => $shopId], true);
|
|
|
+ if (!empty($has)) {
|
|
|
+ util::fail('已经设置过,不能再修改');
|
|
|
+ }
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $reduceDay = $post['reduceDay'] ?? 0;
|
|
|
+ ShopClass::updateById($shopId, ['reduceDay' => $reduceDay]);
|
|
|
+ $data = $post['data'] ?? [];
|
|
|
+ if (empty($data)) {
|
|
|
+ util::fail('没有折扣数据');
|
|
|
+ }
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $discount = $v['discount'] ?? 0.95;
|
|
|
+ $levelSn = $v['key'] ?? 'general';
|
|
|
+ $level = $v['level'] ?? 1;
|
|
|
+ $it = [
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'level' => $level,
|
|
|
+ 'levelSn' => $levelSn,
|
|
|
+ 'discount' => $discount,
|
|
|
+ ];
|
|
|
+ MemberWealClass::add($it, true);
|
|
|
+ }
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete('设置成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ Yii::info("失败原因:" . $e->getMessage());
|
|
|
+ util::fail('设置失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|