|
@@ -87,14 +87,12 @@ class CardBatchService
|
|
$model = $cardBatchModel::find($params['card_batch_id']);
|
|
$model = $cardBatchModel::find($params['card_batch_id']);
|
|
$model->card_batch_name = $params['card_batch_name'];
|
|
$model->card_batch_name = $params['card_batch_name'];
|
|
$params['card_batch_status'] = $model->card_batch_status = $cardBatchModel::CARD_BATCH_STATUS[$params['card_batch_status']]; // 批次状态
|
|
$params['card_batch_status'] = $model->card_batch_status = $cardBatchModel::CARD_BATCH_STATUS[$params['card_batch_status']]; // 批次状态
|
|
-
|
|
|
|
-
|
|
|
|
- if($params['validtimes_status'] == 0) {
|
|
|
|
|
|
+ if ($params['validtimes_status'] == 0) {
|
|
$model->card_batch_validtimes = 0; // 卡批次有效期 0=永久 天
|
|
$model->card_batch_validtimes = 0; // 卡批次有效期 0=永久 天
|
|
- } elseif($params['validtimes_status'] == 1) {
|
|
|
|
- $model->card_batch_validtimes = bcadd($model->card_batch_validtimes , $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
|
|
|
|
- } elseif($params['validtimes_status'] == 2) {
|
|
|
|
- $model->card_batch_validtimes = bcsub($model->card_batch_validtimes , $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
|
|
|
|
|
|
+ } elseif ($params['validtimes_status'] == 1) {
|
|
|
|
+ $model->card_batch_validtimes = bcadd($model->card_batch_validtimes, $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
|
|
|
|
+ } elseif ($params['validtimes_status'] == 2) {
|
|
|
|
+ $model->card_batch_validtimes = bcsub($model->card_batch_validtimes, $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
|
|
}
|
|
}
|
|
if ($model->save()) {
|
|
if ($model->save()) {
|
|
// 修改卡批次下面的卡信息
|
|
// 修改卡批次下面的卡信息
|
|
@@ -128,9 +126,6 @@ class CardBatchService
|
|
*/
|
|
*/
|
|
public static function delete($card_batch_ids)
|
|
public static function delete($card_batch_ids)
|
|
{
|
|
{
|
|
- if (!$card_batch_ids) {
|
|
|
|
- return json_fail("数据错误~");
|
|
|
|
- }
|
|
|
|
if (!is_array($card_batch_ids)) {
|
|
if (!is_array($card_batch_ids)) {
|
|
$card_batch_ids = [$card_batch_ids];
|
|
$card_batch_ids = [$card_batch_ids];
|
|
}
|
|
}
|
|
@@ -147,7 +142,7 @@ class CardBatchService
|
|
CardBatch::whereIn('card_batch_id', $card_batch_ids)->delete();
|
|
CardBatch::whereIn('card_batch_id', $card_batch_ids)->delete();
|
|
Card::whereIn('join_card_batch_id', $card_batch_ids)->delete();
|
|
Card::whereIn('join_card_batch_id', $card_batch_ids)->delete();
|
|
Db::commit();
|
|
Db::commit();
|
|
- _syslog("删除储值卡批次", "删除的卡批次ID【". implode(',', $card_batch_ids). '】');
|
|
|
|
|
|
+ _syslog("删除储值卡批次", "删除的卡批次ID【" . implode(',', $card_batch_ids) . '】');
|
|
return json_success("卡批次删除成功");
|
|
return json_success("卡批次删除成功");
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
Db::rollBack();
|
|
Db::rollBack();
|
|
@@ -155,4 +150,125 @@ class CardBatchService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Notes: 卡批次列表
|
|
|
|
+ * User: ZhouBenXu
|
|
|
|
+ * DateTime: 2024/6/28 上午9:43
|
|
|
|
+ * @param $params
|
|
|
|
+ * @return Response
|
|
|
|
+ */
|
|
|
|
+ public static function getList($params)
|
|
|
|
+ {
|
|
|
|
+ $cardBatchModel = new CardBatch();
|
|
|
|
+ $page = $params['page'];
|
|
|
|
+ $page_size = $params['pageSize'];
|
|
|
|
+ $card_batch_name = $params['card_batch_name'] ?? "";
|
|
|
|
+ $card_batch_status = !empty($params['card_batch_status']) ? $cardBatchModel::CARD_BATCH_STATUS[$params['card_batch_status']] : "";
|
|
|
|
+ $join_card_batch_category_id = $params['join_card_batch_category_id'] ?? "";
|
|
|
|
+ $rows = $cardBatchModel::select('*')
|
|
|
|
+ ->when(!empty($card_batch_name) && $card_batch_name != '', function ($query) use ($card_batch_name) {
|
|
|
|
+ $query->where('card_batch_name', 'like', '%' . $card_batch_name . '%');
|
|
|
|
+ })->when(!empty($card_batch_status), function ($query) use ($card_batch_status) {
|
|
|
|
+ $query->where('card_batch_status', $card_batch_status);
|
|
|
|
+ })->when(!empty($join_card_batch_category_id), function ($query) use ($join_card_batch_category_id) {
|
|
|
|
+ $query->where('join_card_batch_category_id', $join_card_batch_category_id);
|
|
|
|
+ })
|
|
|
|
+ ->orderBy('card_batch_id', 'DESC')
|
|
|
|
+ ->forPage($page, $page_size)
|
|
|
|
+ ->get()
|
|
|
|
+ ->toArray();
|
|
|
|
+
|
|
|
|
+ $total = $cardBatchModel::select('*')
|
|
|
|
+ ->when(!empty($card_batch_name) && $card_batch_name != '', function ($query) use ($card_batch_name) {
|
|
|
|
+ $query->where('card_batch_name', 'like', '%' . $card_batch_name . '%');
|
|
|
|
+ })->when(!empty($card_batch_status), function ($query) use ($card_batch_status) {
|
|
|
|
+ $query->where('card_batch_status', $card_batch_status);
|
|
|
|
+ })->when(!empty($join_card_batch_category_id), function ($query) use ($join_card_batch_category_id) {
|
|
|
|
+ $query->where('join_card_batch_category_id', $join_card_batch_category_id);
|
|
|
|
+ })->count();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (!empty($rows)) {
|
|
|
|
+ // 查询求和数据信息
|
|
|
|
+ $card_batch_id_string = implode(',', array_column($rows, 'card_batch_id'));
|
|
|
|
+ $sql = "select join_card_batch_id,
|
|
|
|
+ -- INIT
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'INIT' THEN counts ELSE 0 END),0) as status_INIT_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'INIT' THEN amounts ELSE 0 END),0) as status_INIT_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'INIT' THEN addeds ELSE 0 END),0) as status_INIT_addeds,
|
|
|
|
+ -- PRODUCTED
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PRODUCTED' THEN counts ELSE 0 END),0) as status_PRODUCTED_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PRODUCTED' THEN amounts ELSE 0 END),0) as status_PRODUCTED_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PRODUCTED' THEN addeds ELSE 0 END),0) as status_PRODUCTED_addeds,
|
|
|
|
+ -- ENABLED
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'ENABLED' THEN counts ELSE 0 END),0) as status_ENABLED_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'ENABLED' THEN amounts ELSE 0 END),0) as status_ENABLED_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'ENABLED' THEN addeds ELSE 0 END),0) as status_ENABLED_addeds,
|
|
|
|
+ -- WAITING
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'WAITING' THEN counts ELSE 0 END),0) as status_WAITING_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'WAITING' THEN amounts ELSE 0 END),0) as status_WAITING_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'WAITING' THEN addeds ELSE 0 END),0) as status_WAITING_addeds,
|
|
|
|
+ -- PENDING
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PENDING' THEN counts ELSE 0 END),0) as status_PENDING_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PENDING' THEN amounts ELSE 0 END),0) as status_PENDING_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PENDING' THEN addeds ELSE 0 END),0) as status_PENDING_addeds,
|
|
|
|
+ -- ACTIVED
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'ACTIVED' THEN counts ELSE 0 END),0) as status_ACTIVED_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'ACTIVED' THEN amounts ELSE 0 END),0) as status_ACTIVED_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'ACTIVED' THEN addeds ELSE 0 END),0) as status_ACTIVED_addeds,
|
|
|
|
+ -- DISABLED
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'DISABLED' THEN counts ELSE 0 END),0) as status_DISABLED_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'DISABLED' THEN amounts ELSE 0 END),0) as status_DISABLED_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'DISABLED' THEN addeds ELSE 0 END),0) as status_DISABLED_addeds,
|
|
|
|
+ -- EXPIRED
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'EXPIRED' THEN counts ELSE 0 END),0) as status_EXPIRED_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'EXPIRED' THEN amounts ELSE 0 END),0) as status_EXPIRED_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'EXPIRED' THEN addeds ELSE 0 END),0) as status_EXPIRED_addeds,
|
|
|
|
+ -- PAUSED
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN counts ELSE 0 END),0) as status_PAUSED_counts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN amounts ELSE 0 END),0) as status_PAUSED_amounts,
|
|
|
|
+ IFNULL(SUM(CASE WHEN card_status = 'PAUSED' THEN addeds ELSE 0 END),0) as status_PAUSED_addeds
|
|
|
|
+ from (select join_card_batch_id, card_status, COUNT(*) as counts, SUM(card_amount) as amounts, SUM(card_added) as addeds from app_card where join_card_batch_id in (" . $card_batch_id_string . ") group by join_card_batch_id, card_status) group_data
|
|
|
|
+ group by join_card_batch_id";
|
|
|
|
+
|
|
|
|
+ $card_status_total = Db::select($sql);
|
|
|
|
+ $card_status_total = array_column($card_status_total, null, 'join_card_batch_id');
|
|
|
|
+ foreach ($rows as $key => &$value) {
|
|
|
|
+ $value['card_batch_status'] = array_flip($cardBatchModel::CARD_BATCH_STATUS)[$value['card_batch_status']];
|
|
|
|
+ !empty($value['card_batch_json']) && $value['card_batch_json'] = json_decode($value['card_batch_json'], true);
|
|
|
|
+ !empty($value['card_batch_extend_json']) && $value['card_batch_extend_json'] = json_decode($value['card_batch_extend_json'], true);
|
|
|
|
+ // 合并储值卡面值以及状态数量
|
|
|
|
+ if (!empty($card_status_total[$value['card_batch_id']])) {
|
|
|
|
+ if (is_array($card_status_total[$value['card_batch_id']])) {
|
|
|
|
+ $value = array_merge($value, $card_status_total[$value['card_batch_id']]);
|
|
|
|
+ } else {
|
|
|
|
+ $value = array_merge($value, json_decode(json_encode($card_status_total[$value['card_batch_id']]), true));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return json_success('', compact('rows', 'page', 'page_size', 'total'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Notes: 卡批次详情
|
|
|
|
+ * User: ZhouBenXu
|
|
|
|
+ * DateTime: 2024/6/28 上午10:50
|
|
|
|
+ * @param $card_batch_id
|
|
|
|
+ * @return Response
|
|
|
|
+ */
|
|
|
|
+ public static function getInfo($card_batch_id)
|
|
|
|
+ {
|
|
|
|
+ $cardBatch = CardBatch::where('card_batch_id', $card_batch_id)->first()->toArray();
|
|
|
|
+ if (!empty($cardBatch)) {
|
|
|
|
+ $cardBatch['card_batch_status'] = array_flip(CardBatch::CARD_BATCH_STATUS)[$cardBatch['card_batch_status']];
|
|
|
|
+ !empty($cardBatch['card_batch_json']) && $cardBatch['card_batch_json'] = json_decode($cardBatch['card_batch_json'], true);
|
|
|
|
+ !empty($cardBatch['card_batch_extend_json']) && $cardBatch['card_batch_extend_json'] = json_decode($cardBatch['card_batch_extend_json'], true);
|
|
|
|
+ }
|
|
|
|
+ return json_success('',$cardBatch);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|