|
|
@@ -51,26 +51,28 @@ class HbController extends BaseController
|
|
|
*/
|
|
|
public function actionHbList()
|
|
|
{
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
$where = ['shopId' => $this->shopId];
|
|
|
- $customId = Yii::$app->request->get('customId', '');
|
|
|
+ $customId = $get['customId'] ?? 0;
|
|
|
if (!empty($customId)) {
|
|
|
$where['customId'] = $customId;
|
|
|
}
|
|
|
- $status = Yii::$app->request->get('status', '');
|
|
|
- if (isset($status) && $status != '') {
|
|
|
- if ($status == -1) { // 已失效包含:1作废 与 过期(0未使用但endTime<当前时间) --- 所以当操作作废时,status改为-1,同时将endTime改为当前时间
|
|
|
- $where['endTime<'] = time();
|
|
|
- } else {
|
|
|
- $where['status'] = $status;
|
|
|
- }
|
|
|
+ $status = $get['status'] ?? '';
|
|
|
+ if ($status != '') {
|
|
|
+ $where['status'] = $status;
|
|
|
}
|
|
|
- $list = HbClass::getList('*', $where, 'id desc', 'custom');
|
|
|
- if (!empty($list['list'])) {
|
|
|
- foreach ($list['list'] as &$v) {
|
|
|
+ $respond = HbClass::getList('*', $where, 'id desc', 'custom');
|
|
|
+ if (!empty($respond['list'])) {
|
|
|
+ foreach ($respond['list'] as &$v) {
|
|
|
$v['customName'] = $v['custom']['name'];
|
|
|
+ if ($v['status'] == 0 && $v['endTime'] < time()) {
|
|
|
+ //发现红包已过期,需要作废,多有处作废操作,搜索关键词 cancellation_hb
|
|
|
+ $id = $v['id'];
|
|
|
+ HbClass::updateById($id, ['status' => -1]);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- util::success($list);
|
|
|
+ util::success($respond);
|
|
|
}
|
|
|
|
|
|
// 单个门店下所有可用红包
|
|
|
@@ -81,9 +83,17 @@ class HbController extends BaseController
|
|
|
$where = [];
|
|
|
$where['customId'] = $get['customId'];
|
|
|
$where['status'] = 0;
|
|
|
- $where['endTime>'] = time();
|
|
|
-
|
|
|
$list = HbClass::getAllByCondition($where, 'id DESC');
|
|
|
+ //已经过期的就不再显示,并且作废,多有处作废操作,搜索关键词 cancellation_hb
|
|
|
+ if (!empty($list)) {
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ if ($v['endTime'] < time()) {
|
|
|
+ unset($list[$v]);
|
|
|
+ $id = $v['id'];
|
|
|
+ HbClass::updateById($id, ['status' => -1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
util::success($list);
|
|
|
}
|
|
|
|
|
|
@@ -178,12 +188,12 @@ class HbController extends BaseController
|
|
|
|
|
|
try {
|
|
|
//当是退回红包时,必须检测对应订单 actPrice 为0
|
|
|
- if (isset($form->status) && $form->status == 0){
|
|
|
- if($hb->status == 1){
|
|
|
+ if (isset($form->status) && $form->status == 0) {
|
|
|
+ if ($hb->status == 1) {
|
|
|
//查询订单数据,校验 actPrice,按情况更新
|
|
|
$order = OrderClass::getById($form->orderId, true, 'id, hbId, hbAmount, actPrice');
|
|
|
- if($order->hbId == $id){
|
|
|
- if($order->actPrice == 0.00){
|
|
|
+ if ($order->hbId == $id) {
|
|
|
+ if ($order->actPrice == 0.00) {
|
|
|
//更新订单数据
|
|
|
$order->hbId = -$order->hbId;
|
|
|
$order->save();
|
|
|
@@ -191,11 +201,11 @@ class HbController extends BaseController
|
|
|
Yii::error('使用红包的订单 actPrice 不等于0,无法执行红包退回。hbId=' . $id);
|
|
|
util::fail('使用红包的订单 actPrice 不等于0,无法执行红包退回');
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Yii::error("订单中的红包id与当前红包不匹配。hbId={$id}, orderId={$form->orderId}");
|
|
|
util::fail('订单中的红包id与当前红包不匹配');
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Yii::error("当前红包状态不是已使用,不能变更未使用。hbId={$id}");
|
|
|
util::fail("当前红包状态不是已使用,不能变更未使用");
|
|
|
}
|
|
|
@@ -211,7 +221,7 @@ class HbController extends BaseController
|
|
|
$hb->$field = $form->$field;
|
|
|
}
|
|
|
}
|
|
|
- // 当操作作废时,status改为-1,同时将endTime改为当前时间
|
|
|
+ // 当操作作废时,status改为-1,同时将endTime改为当前时间,多有处作废操作,搜索关键词 cancellation_hb
|
|
|
if (isset($form->status) && $form->status == -1 && $hb->status != -1) {
|
|
|
$hb->endTime = time();
|
|
|
//记录作废人
|