|
|
@@ -10,6 +10,8 @@ use bizHd\hb\classes\HbManageClass;
|
|
|
use bizHd\recharge\classes\RechargeShbClass;
|
|
|
use common\components\util;
|
|
|
use bizHd\hb\classes\HbClass;
|
|
|
+use hd\models\hb\CreateHbForm;
|
|
|
+use hd\models\hb\UpdateHbForm;
|
|
|
use Yii;
|
|
|
|
|
|
class HbController extends BaseController
|
|
|
@@ -98,14 +100,12 @@ class HbController extends BaseController
|
|
|
*/
|
|
|
public function actionCreateHb()
|
|
|
{
|
|
|
- // TODO
|
|
|
- // $form = new \hd\models\hb\CreateHbForm();
|
|
|
- // $form->load(Yii::$app->request->post(), '');
|
|
|
- // if (!$form->validateForm()) {
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // $data = $form->attributes;
|
|
|
- $post = Yii::$app->request->post();
|
|
|
+ $form = new CreateHbForm();
|
|
|
+ $form->load(Yii::$app->request->post(), '');
|
|
|
+ if (!$form->validateForm()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $post = $form->attributes;
|
|
|
|
|
|
$duration = intval($post['days']);
|
|
|
$count = $post['count'] ?? 1;
|
|
|
@@ -124,7 +124,7 @@ class HbController extends BaseController
|
|
|
'willTime' => $endTime,
|
|
|
'duration' => $duration,
|
|
|
'getType' => 1, //取得方式 0新人领取 1门店发放 2充值赠送
|
|
|
- 'remark' => $post['remark'],
|
|
|
+ 'remark' => $post['remark'] ?? '',
|
|
|
];
|
|
|
|
|
|
$manageData = [
|
|
|
@@ -152,16 +152,13 @@ class HbController extends BaseController
|
|
|
*/
|
|
|
public function actionUpdateHb()
|
|
|
{
|
|
|
- // TODO
|
|
|
- // $hbId = Yii::$app->request->get('hbId');
|
|
|
- // $form = new \hd\models\hb\UpdateHbForm();
|
|
|
- // $form->load(Yii::$app->request->post(), '');
|
|
|
- // if (!$form->validateForm()) {
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // $data = $form->attributes;
|
|
|
- $data = Yii::$app->request->post();
|
|
|
- $id = $data['id'];
|
|
|
+ $rawPost = Yii::$app->request->post();
|
|
|
+ $form = new UpdateHbForm();
|
|
|
+ $form->load($rawPost, '');
|
|
|
+ if (!$form->validateForm()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $id = (int)$form->id;
|
|
|
$hb = HbClass::getById($id, true);
|
|
|
|
|
|
//检测是否是本门店的红包
|
|
|
@@ -169,8 +166,15 @@ class HbController extends BaseController
|
|
|
util::fail('不是本门店的红包');
|
|
|
}
|
|
|
|
|
|
- foreach($data as $key => $val){
|
|
|
- $hb->$key = $val;
|
|
|
+ // 仅更新允许字段,且只更新请求中实际传入的字段(避免用 null 覆盖原值)
|
|
|
+ $allowFields = array_keys($form->attributes);
|
|
|
+ foreach ($allowFields as $field) {
|
|
|
+ if ($field === 'id') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (array_key_exists($field, $rawPost)) {
|
|
|
+ $hb->$field = $form->$field;
|
|
|
+ }
|
|
|
}
|
|
|
// 当操作作废时,status改为-1,同时将endTime改为当前时间
|
|
|
if($hb->status == -1){
|
|
|
@@ -213,7 +217,6 @@ class HbController extends BaseController
|
|
|
public function actionDeleteHbRule()
|
|
|
{
|
|
|
$id = Yii::$app->request->post('id');
|
|
|
- var_dump($id); die;
|
|
|
$re = RechargeShbClass::deleteById($id);
|
|
|
if($re == 1){
|
|
|
util::complete();
|