|
@@ -12,6 +12,7 @@ namespace app\admin\service\card;
|
|
use support\Db;
|
|
use support\Db;
|
|
use support\exception\BusinessException;
|
|
use support\exception\BusinessException;
|
|
use app\model\Card;
|
|
use app\model\Card;
|
|
|
|
+use support\Request;
|
|
|
|
|
|
class CardService
|
|
class CardService
|
|
{
|
|
{
|
|
@@ -212,4 +213,108 @@ class CardService
|
|
return json_success('', $cardInfo);
|
|
return json_success('', $cardInfo);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Notes: 储值卡导出数据
|
|
|
|
+ * User: ZhouBenXu
|
|
|
|
+ * DateTime: 2024/6/28 下午2:44
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @return \support\Response
|
|
|
|
+ */
|
|
|
|
+ public static function exportCard(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $card_ids = $request->get('card_id', '');
|
|
|
|
+ $cardModel = new Card();
|
|
|
|
+ $list = $cardModel::select('*')->whereIn('card_id', $card_ids)->get()->toArray();
|
|
|
|
+ $exportData = [];
|
|
|
|
+ // 增加签名
|
|
|
|
+ if (!empty($list)) {
|
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
|
+ $info['card_name'] = $value['card_name'];
|
|
|
|
+ $info['card_pass'] = $value['card_pass'];
|
|
|
|
+ $info['card_prefix'] = $value['card_prefix'];
|
|
|
|
+ $info['card_suffix'] = $value['card_suffix'];
|
|
|
|
+ $info['card_sort'] = $value['card_sort'];
|
|
|
|
+ $info['card_validtimes'] = $value['card_validtimes'];
|
|
|
|
+ // 生成签名
|
|
|
|
+ $card_no = $value['card_prefix'] . $value['card_sort'] . $value['card_suffix'];
|
|
|
|
+ $card_sign = self::generateSignature($info, $info['card_pass']);
|
|
|
|
+ $card_extend_json['action'] = "bind-card";
|
|
|
|
+ $card_extend_json['data'] = ["card_id" => $card_no, "card_sign" => $card_sign];
|
|
|
|
+ $info['card_no'] = $card_no;
|
|
|
|
+ $info['card_extend_json'] = $card_extend_json;
|
|
|
|
+ $exportData[] = $info;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return json_success('', $exportData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Notes: 生成签名
|
|
|
|
+ * User: ZhouBenXu
|
|
|
|
+ * DateTime: 2024/6/28 下午2:32
|
|
|
|
+ * @param $data
|
|
|
|
+ * @param $secret
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ public static function generateSignature($data, $secret)
|
|
|
|
+ {
|
|
|
|
+ // 将数组转换为字符串,并按照字母排序
|
|
|
|
+ $dataString = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
|
|
|
|
+ // 使用HMAC-SHA256算法生成签名
|
|
|
|
+ $signature = hash_hmac('sha256', $dataString, $secret);
|
|
|
|
+ return $signature;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Notes: 验证签名
|
|
|
|
+ * User: ZhouBenXu
|
|
|
|
+ * DateTime: 2024/6/28 下午2:33
|
|
|
|
+ * @param $data
|
|
|
|
+ * @param $providedSignature
|
|
|
|
+ * @param $secret
|
|
|
|
+ * @return bool
|
|
|
|
+ */
|
|
|
|
+ public static function verifySignature($data, $providedSignature, $secret)
|
|
|
|
+ {
|
|
|
|
+ // 生成数据的签名
|
|
|
|
+ $generatedSignature = self::generateSignature($data, $secret);
|
|
|
|
+ // 比较生成的签名与提供的签名是否一致
|
|
|
|
+ return hash_equals($generatedSignature, $providedSignature);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Notes: 储值卡删除
|
|
|
|
+ * User: ZhouBenXu
|
|
|
|
+ * DateTime: 2024/6/28 下午2:58
|
|
|
|
+ * @param $card_ids
|
|
|
|
+ * @return \support\Response
|
|
|
|
+ */
|
|
|
|
+ public static function delete($card_ids)
|
|
|
|
+ {
|
|
|
|
+ if (!is_array($card_ids)) {
|
|
|
|
+ $card_ids = [$card_ids];
|
|
|
|
+ }
|
|
|
|
+ $card = Card::whereIn('card_id', $card_ids)->get()->toArray();
|
|
|
|
+ if (!$card) {
|
|
|
|
+ return json_fail("数据错误~");
|
|
|
|
+ }
|
|
|
|
+ // 是否有激活的卡片
|
|
|
|
+ if (Card::whereIn('card_id', $card_ids)->where('card_status', 'ACTIVED')->exists()) {
|
|
|
|
+ return json_fail('存在已激活卡片不可以删除');
|
|
|
|
+ }
|
|
|
|
+ Db::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ Card::whereIn('card_id', $card_ids)->delete();
|
|
|
|
+ Db::commit();
|
|
|
|
+// _syslog("删除储值卡", "删除的储值卡ID【" . implode(',', $card_ids) . '】');
|
|
|
|
+ return json_success("储值卡删除成功");
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return json_fail("储值卡删除失败~");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|