unit unt_LotBill_dyc;

interface

uses
windows, SysUtils, Classes, ComCtrls, Forms, Controls, StrUtils, Math, superobject,
SyncObjs, unt_ShareVar, unt_LotVar, uDycIFace; type
TLotBillDyc = class
private
protected
class function FormatIssueForBill(LotID, AIssue: integer): string;
class function CreateTicketID(LotID, OptID, ChipID: integer): string;
public
class function DoPostWithoutThread(const ALotID: Integer; const BillID, AnteCode,
BillIssue: string; const ChipMul, TicketMoney, AOneMoney: Integer;
const sPlayType:string=''): integer;
class function InitParam(ErrMsgFlag: boolean = true): boolean;
class function DoPrepare(const AChip: TChipProjInfo): integer;
//投注相关操作
class function DoPrint(const AChip: TChipProjInfo; AItem: TListItem;
ShowErrFlag: boolean = true): integer;
class function DoQueryAndFinishPrint(const AChip: TChipProjInfo): integer;
class function PrintQuery(const AValue: ISuperObject): Integer;
end; implementation uses
DmLottery, unt_ActionDef, unt_ShareFunc, unt_LotShareFunc, uXcReqFun, unt_OptVar,
unt_Lottery, LcUtils, unt_StrFunc; { 参数初始化 }
class function TLotBillDyc.InitParam(ErrMsgFlag: boolean): boolean;
var
Version, md5key, url, partnerid: string;
begin
url := GUserIniFile.ReadString(INI_BILL_ROOT, 'billurl_21', '');
Version := GUserIniFile.ReadString(INI_BILL_ROOT, 'billuid_21', '1.0');
partnerid := GUserIniFile.ReadString(INI_BILL_ROOT, 'billkey_21', '');
md5key := GUserIniFile.ReadString(INI_BILL_ROOT, 'billpwd_21', '');
if (url = '') or (md5key = '') then
begin
if ErrMsgFlag then
TShareFunc.ShowWarn('对不起,请配置您的出票服务接口地址!');
Exit;
end;
partnerid := TShareFunc.UncrypString(partnerid); //解密
md5key := TShareFunc.UncrypString(md5key); //解密
InitDycParam(Version,partnerid,md5key,url);
//InitDycParam('31017736722','136016974','d4I9y24I9C3a1i9O','http://openapi.diyicai.com/enterpriseAPI/lotServiceCtrl!login.ac');
Result := true;
end; class function TLotBillDyc.FormatIssueForBill(LotID, AIssue: integer): string;
begin
if LotID=LOT_ID_ELEVEN then
Result := Copy(IntToStr(AIssue),, )
else
Result := IntToStr(AIssue);
end; class function TLotBillDyc.PrintQuery(const AValue: ISuperObject): Integer;
var
sSql: string;
res : ISuperObject;
nChipMoney, nResult: integer;
begin
Result := ;
res := DycTicketCheckOut(AValue.s['DycID']);
if Assigned(res) then
begin
if res.i['Code'] = then
begin
//出票成功
nResult := ;
Result := Result + res.i['Value.amount'];
end
else if res.i['Code'] = then
//出票失败、撤单、流单
nResult :=
else
begin
//其他
nResult := ;
end;
sSql := 'UPDATE Sale_LotBillRec SET BillReturn=''%s'', BillResult=%d WHERE TicketID=''%s''';
sSql := Format(sSql, [res.AsJSon, nResult, AValue.s['LocID']]);
dmLot.conShare.Execute(sSql);
end;
end; class function TLotBillDyc.DoPrepare(const AChip: TChipProjInfo): integer;
var
obj: ISuperObject;
sSql: string;
begin
Result := ;
sSql := 'SELECT TicketID, BillOrder FROM Sale_LotBillRec WHERE (BillResult NOT IN (0,9)) AND LotID='
+ IntToStr(AChip.LotID) + ' AND OptID in ' + ZxhtGetProjID(AChip.OptID);
dmLot.qryPublic.Close;
dmLot.qryPublic.SQL.Text := sSql;
dmLot.qryPublic.Open;
while not dmLot.qryPublic.Eof do
begin
obj := SO;
obj.S['DycID'] := dmLot.qryPublic.FieldByName('BillOrder').AsString;
obj.S['LocID'] := dmLot.qryPublic.FieldByName('TicketID').AsString;
dmLot.qryPublic.Next;
Result:= Result + PrintQuery(obj);
end;
dmLot.qryPublic.Close;
end; class function TLotBillDyc.DoQueryAndFinishPrint(const AChip: TChipProjInfo): integer;
var
sSql, TIDs: string;
begin
//先查询出票结果
Self.DoPrepare(AChip);
Result := ;
sSql := 'SELECT SUM(ChipMoney*ChipMul) FROM Sale_LotBillRec WHERE BillResult=9 AND LotID='
+ IntToStr(AChip.LotID) + ' AND OptID IN ' + ZxhtGetProjID(AChip.OptID);
Result := dmLot.GetFirstValInt(sSql, );
//如果出票成功则自动更新状态
if (Result > ) and (Result = AChip.ChipMoney) then
begin
sSql := 'SELECT BillOrder FROM Sale_LotBillRec WHERE LotID=%d AND OptId IN %s';
sSql := Format(sSql, [AChip.LotID, ZxhtGetProjID(AChip.OptID)]);
try
TIDs := DmLot.GetSomeValStr(sSql, ',', True);
except
TIDs := '';
end;
if TIDs<>'' then
XcFinishPrint(CurrUserInfo.UserID, AChip.LotID, AChip.OptID, TIDs)
else
Result:= ;
end
else Result:=;
end; { 生成唯一的出票票号 }
class function TLotBillDyc.CreateTicketID(LotID, OptID, ChipID: integer):string;
begin
Result := IntToStr(OptID) + 'A' + IntToStr(ChipID);
end; { 不通过线程出票 }
class function TLotBillDyc.DoPostWithoutThread(const ALotID: Integer; const BillID, AnteCode, BillIssue: string;
const ChipMul, TicketMoney, AOneMoney: Integer; const sPlayType:string=''): Integer;
var
nResult: integer;
DycID, sSql: string;
res: ISuperObject;
begin
Result := ;
DycID := '';
res := DycTicketPrint(ALotID, BillID, BillIssue, AnteCode, sPlayType, trunc(TicketMoney / AOneMoney), ChipMul, AOneMoney);
if Assigned(res) then
begin
if res.I['Code'] = then
begin
nResult:= ;
DycID := res.S['Value.aOrderID'];
Result := Result + TicketMoney * ChipMul;
end
else
nResult := ; //收单失败
//更新出票记录
sSql := 'UPDATE Sale_LotBillRec SET BillReturn=''%s'', BillResult=%d, BillMoney=%d, BillTime=''%s'', BillOrder=''%s'' WHERE TicketID=''%s''';
sSql := Format(sSql, [res.AsJSon, nResult, Result, FormatDateTime('yyyy-mm-dd hh:nn:ss', now()), DycID, BillID]);
dmLot.ExecuteUpdate(sSql);
end;
end; function objlstSort(List: TStringList; Index1, Index2: Integer): Integer;
begin
Result:= StrToInt(List[Index1]) - StrToInt(List[Index2]);
end;
{ 出票 }
class function TLotBillDyc.DoPrint(const AChip: TChipProjInfo; AItem: TListItem; ShowErrFlag: boolean): integer;
var
i: Integer;
nOneMoney, nOneCount: integer;
LastPt, sBillIssue, sBillChip: string;
ssChip: TStringList;
LotInfo: TSaleLotRec;
{ 执行出票打印, 返回出票成功金额 }
function DoPostChip(ChipID: integer): integer;
var
chipobj: ISuperObject;
nState, nBillMoney, nBillResult: integer;
sSql, sBillID, sTicket, sValue: string;
begin
Result := ;
//系统流水号
sBillID := Self.CreateTicketID(AChip.LotID, AChip.OptID, ChipID + );
sTicket := sBillChip;
//检查定单是否已经出票
sSql := 'SELECT BillMoney*10+BillResult FROM Sale_LotBillRec WHERE LotID=%d AND OptID=%d AND ChipID=%d';
sSql := Format(sSql, [AChip.LotID, AChip.OptID, ChipID + ]);
nState := dmLot.GetFirstValInt(sSql, -);
if nState >= then
begin
nBillMoney := nState div ;
nState := nState mod ;
end;
if (nState = ) or (nState = ) then
begin
if nState = then
Result := Result + nBillMoney;
Exit;
end;
//插入出票记录
if nState = - then
begin
try
chipobj:=so;
chipobj.S['pt'] := LastPt;
chipobj.S['code']:= sBillChip;
chipobj.I['onemoney'] := AChip.OneMoney;
chipobj.i['chipmoney']:= nOneMoney;
//插入出票记录
sSql := 'INSERT INTO Sale_LotBillRec(TicketID, OptId, ChipID, LotID, LotIssue, UserChip,'
+ ' ChipMoney, ChipMul, PostTime, PostStr, BillSP)'
+ ' VALUES(''%s'', %d, %d, %d, %d, ''%s'', %d,%d, %s, ''%s'', 1010)';
sSql := Format(sSql, [sBillID, AChip.OptID, ChipID + , AChip.LotID,
AChip.LotIssue, chipobj.AsJSon , nOneMoney, AChip.ChipMul, dmLot.DbFunc_Now, sTicket]);
dmLot.ExecuteUpdate(sSql);
except
end;
end;
//出票
Result := Result + Self.DoPostWithoutThread(AChip.LotID, sBillID, sTicket, sBillIssue, achip.ChipMul,
nOneMoney, AChip.OneMoney, LastPt);
end;
function TodyjCode(Acode: string): string;
var
k: Integer;
lst, lst2: TStrings;
ncount: Integer;
tcode: string;
begin
lst := TStringList.Create;
lst2 := TStringList.Create;
lst.Text := Acode;
for k := to lst.Count - do
begin
tcode := lst[k];
ncount := TLottery.GetSomeChipCount(tcode, LotInfo.LotID, LotInfo.LotType, LotInfo.DsCodeNum, LotInfo.DsCodeNum2);
nOneCount := nOneCount + ncount;
if ncount = then
lst2.Add('ds|' + tcode)
else
begin
if Pos('$', tcode) > then
lst2.Add('dt|' + tcode)
else
lst2.add('fs|' + tcode);
end;
end;
result := lst2.text;
lst.free;
lst2.free;
end;
begin
Result := ;
if AChip.LotId<>LOT_ID_ELEVEN then
begin
if ShowErrFlag then
TShareFunc.ShowWarn('对不起,该接口暂时只支持十一运夺金投注!');
Exit;
end;
LastPt := '';
sBillIssue:= Self.FormatIssueForBill(AChip.LotId, AChip.LotIssue);
LotInfo := TLottery.GetOneSaleLottery(AChip.LotId);
ssChip := TStringList.Create;
try
ssChip.Text := AChip.UserChip;
ssChip.Sort;
for i := to ssChip.Count - do
begin
if LastPt='' then
begin
LastPt:= TStrFunc.CopyLeft(ssChip.Strings[i], '|');
sBillChip:= UpperCase(ssChip.Strings[i]);
end else if UpperCase(LastPt)=UpperCase(TStrFunc.CopyLeft(ssChip.Strings[i], '|')) then
sBillChip:= sBillChip + # + UpperCase(ssChip.Strings[i])
else begin
nOneCount := ;
sBillChip := TodyjCode(sBillChip);
nOneMoney := nOneCount * ;
Result := Result + DoPostChip(i);
//状态显示
if Assigned(AItem) then
AItem.SubItems.Strings[] := IntToStr(((i + ) * div ssChip.Count)) + '%';
Application.ProcessMessages;
//重新装载
LastPt:='';
sBillChip:= '';
LastPt:= TStrFunc.CopyLeft(ssChip.Strings[i], '|');
sBillChip:= UpperCase(ssChip.Strings[i]);
end;
end;
if (sBillChip<>'') and (LastPt<>'') then
begin
nOneCount := ;
sBillChip := TodyjCode(sBillChip);
nOneMoney := nOneCount * ;
Result := Result + DoPostChip(I+);
//状态显示
if Assigned(AItem) then
AItem.SubItems.Strings[] := IntToStr(((i + ) * div ssChip.Count)) + '%';
Application.ProcessMessages;
end;
if Result <= then
XcCancelPrint(CurrUserInfo.UserID, AChip.LotID, , 'RecIDs=' + IntToStr(AChip.OptID));
finally
FreeAndNil(ssChip);
end
end; initialization finalization end.

我们公司的delphi代码(胆不是我写的!),看看,你觉得怎么样的更多相关文章

  1. Winsock完成端口模型-Delphi代码

    原文出处 <Windows网络编程技术>第8章 完成端口模型 由于原书附的是C代码,我把其翻译成Delphi代码. 其中winsock2.pas在delphi中不带,要另外下载http:/ ...

  2. Delphi代码中嵌入ASM代码

    前言 Delphi作为一个快速高效的开发平台,使用的人越来越多,但熟悉在Delphi代码中嵌入ASM代码的程序员我想不多,因为这方面的资料太少了,另一方面,它还需要有基本的汇编语言知识,关於汇编语言的 ...

  3. Delphi代码中嵌入ASM代码(简单明了)

    前言 Delphi作为一个快速高效的开发平台,使用的人越来越多,但熟悉在Delphi代码中嵌入ASM代码的程序员我想不多,因为这方面的资料太少了,另一方面,它还需要有基本的汇编语言知识,关於汇编语言的 ...

  4. 公司和家里代码文件同步方案: (git和dropbox实现)

    公司和家里代码文件同步方案: (git和dropbox实现) 参与公司福利购入了有补贴的macbook pro后, 就不用上下班背着电脑了. 但是也出现了另外一问题: 家里和公司代码同步的问题 公司有 ...

  5. Delphi 如何在程序中执行动态生成的Delphi代码

    如何在程序中执行动态生成的Delphi代码 经常发现有人提这类问题,或者提问内容最后归结成这种问题 前些阵子有位高手写了一个“执行动态生成的代码”,这是真正的高手,我没那种功力,我只会投机取巧. 这里 ...

  6. 如何在程序中执行动态生成的Delphi代码

    如何在程序中执行动态生成的Delphi代码 经常发现有人提这类问题,或者提问内容最后归结成这种问题 前些阵子有位高手写了一个“执行动态生成的代码”,这是真正的高手,我没那种功力,我只会投机取巧. 这里 ...

  7. Delphi代码创建形式规范 1.0

                Delphi代码创建形式规范 1.0 本规范的目的:给自己的代码一个统一而标准的外观,增强 可读性,可理解性,可维护性 本规范的原则:名称反映含义,形式反映结构 1.单元风格 ...

  8. Delphi 设计模式:《HeadFirst设计模式》Delphi代码---模式小结之一个叫声接口和几只鸭子[转]

    一.一个叫声接口和几只鸭子 从一个叫声接口开始. {<HeadFirst设计模式>Delphi代码之模式小结 } { 一个叫声接口                            } ...

  9. 只有20行Javascript代码!手把手教你写一个页面模板引擎

    http://www.toobug.net/article/how_to_design_front_end_template_engine.html http://barretlee.com/webs ...

随机推荐

  1. 自学Python-基于tcp协议的socket

    自学Python之路-Python基础+模块+面向对象自学Python之路-Python网络编程自学Python之路-Python并发编程+数据库+前端自学Python之路-django 自学Pyth ...

  2. 【bzoj 4046 加强版】Pork barrel

    刚考完以为是神仙题--后来发现好像挺蠢的-- QwQ 题意 给你一张 \(n\) 个点 \(m\) 条边的无向图(不一定连通),有 \(q\) 组询问,每组询问给你 \(2\) 个正整数 \(l,h\ ...

  3. 使用h5新特性,轻松监听任何App自带返回键

    1.前言 如今h5新特性.新标签.新规范等有很多,而且正在不断完善中,各大浏览器商对它们的支持,也是相当给力.作为前端程序员,我觉得我们还是有必要积极关注并勇敢地加以实践.接下来我将和各位分享一个特别 ...

  4. base64 转 Image

    /// <summary> /// base64 转 Image /// </summary> /// <param name="base64"> ...

  5. 总结c语言

    这个月的总结,我学到的知识虽然不是很多,学的很慢,也不懂什么意思,也没有多加去复习,也许这就是不去敲代码的代价,也只会简单的代码,学的时候真的是找不到思路,觉得这代码跟着老师讲课照着输入进去就可以了, ...

  6. 后端返回图片的url,将其转成base64,再次进行上传

      //将图片变成base64再上传(主要是转化来自客户端的图片)  getUrlBase64=(url, ext)=> {     var canvas = document.createEl ...

  7. LINUX学习之二磁盘篇

    1.Linux系统中,每个设备都被当成一个文件来对待.文件系统的最小单位是区块(Block) 设备 设备在Linux中的文件名 IDE硬盘 /dev/hd[a-d] SCSI/SATA/USB硬盘 / ...

  8. cdh搭建仓库

    搭建内部仓库使用yum安装cm Creating a Permanent Internal Repository 1,安装httpd yum install httpd 删除/etc/httpd/co ...

  9. 1、布局容器Grid、StackPanel、GroupBox、DockPanel、WrapPanel

    Grid——网格布局,其中控件或容器需指定位置 StackPanel——堆叠面板,其中的控件水平布局.竖直布局 DockPanel——停靠面板,内部控件或容器可以放置在上.下.左.右 WrapPane ...

  10. C# 4.0

    序言 动态绑定-dynamic class Program { static void Main(string[] args) { ; ; // Rest the mouse pointer over ...