coinshare.bak.sql 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. create procedure CoinShare(IN tablename char(16), IN tablepk int)
  2. leave_proc:
  3. BEGIN
  4. /*调用方法 call CoinShare('a', 1)
  5. 返回值说明: 0-错误, 0-成功, 1成功,但之前已处理,本次忽略
  6. A: 会员(付款者:购买服务端普通会员 或 购买服务的人才)
  7. B: 人才/模特 (收款者:充值会员或者 提供服务的人才)
  8. C:经纪人
  9. D:模特的推荐人
  10. E:会员的推荐人
  11. F:平台
  12. */
  13. /*金额*/
  14. declare AmountFee Decimal(10,2) DEFAULT 0;
  15. declare Fee_A Decimal(10,2) DEFAULT 0;
  16. declare Fee_B Decimal(10,2) DEFAULT 0;
  17. declare Fee_C Decimal(10,2) DEFAULT 0;
  18. declare Fee_D Decimal(10,2) DEFAULT 0;
  19. declare Fee_E Decimal(10,2) DEFAULT 0;
  20. declare Fee_F Decimal(10,2) DEFAULT 0;
  21. /*人员PK*/
  22. declare membPK_A int DEFAULT 0;
  23. declare membPK_B int DEFAULT 0;
  24. declare membPK_C int DEFAULT 0;
  25. declare membPK_D int DEFAULT 0;
  26. declare membPK_E int DEFAULT 0;
  27. declare membPK_F int DEFAULT 0;
  28. /*比例*/
  29. declare Rate_A Decimal(10,2) DEFAULT 0;
  30. declare Rate_B Decimal(10,2) DEFAULT 0;
  31. declare Rate_C Decimal(10,2) DEFAULT 0;
  32. declare Rate_D Decimal(10,2) DEFAULT 0;
  33. declare Rate_E Decimal(10,2) DEFAULT 0;
  34. declare Rate_F Decimal(10,2) DEFAULT 0;
  35. #中文含义
  36. declare AccountRecord_stype varchar(20) DEFAULT '';
  37. declare AccountRecord_Atype_A varchar(20) DEFAULT '';
  38. declare AccountRecord_Atype_B varchar(20) DEFAULT '';
  39. declare AccountRecord_Atype_Other varchar(20) DEFAULT '';
  40. declare AccountRecord_abstract varchar(40) DEFAULT '';
  41. declare AccountRecord_ADate datetime;
  42. #其它参数
  43. declare pro_AccFlag int; #结算状态位,1表示可以计算,9表示已经计算
  44. declare pro_iCount int;
  45. declare pro_isR int default 0; #是否红包
  46. declare pro_isV int default 0; #是否视频
  47. declare pro_isS int default 0; #是否商业订单
  48. declare pro_isM int default 0; #是否模卡
  49. declare pro_isP int default 0; #是否活动
  50. declare pro_isInCash int default 0; #是否充值
  51. declare pro_isOutCash int default 0; #是否取现
  52. declare curAccLeft Decimal(10,2); #会员当前余额
  53. declare recordcount int;
  54. #数据库事务变量
  55. DECLARE sql_error INTEGER DEFAULT 0;
  56. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET sql_error=1;
  57. #获得金额,会员和才人的memberPK
  58. if lower(tablename)= lower('RedPacket') THEN #红包
  59. Set pro_isR = 1;
  60. Set AccountRecord_stype = '红包';
  61. Set AccountRecord_Atype_A = '红包支付';
  62. Set AccountRecord_Atype_B = '红包收入';
  63. Set AccountRecord_Atype_Other = '红包分红收入';
  64. select Count(*), Max(a.coin),
  65. Max(a.MemberPK), max(b.MemberPK), max(B.BMemberPK),
  66. max(a.AccFlag)
  67. into pro_iCount, AmountFee,
  68. membPK_A, membPK_B, membPK_C,
  69. pro_AccFlag
  70. from RedPacket a inner join ModelInfo b on a.ModelPK = b.PK
  71. where a.PK = tablepk;
  72. elseif lower(tablename)= lower('VideoRecord') THEN #视频
  73. Set pro_isV = 1;
  74. Set AccountRecord_stype = '聊天';
  75. Set AccountRecord_Atype_A = '聊天支付';
  76. Set AccountRecord_Atype_B = '聊天收入';
  77. Set AccountRecord_Atype_Other = '聊天分成收入';
  78. select Count(*), Max(a.coin),
  79. Max(a.MemberPK), max(b.MemberPK), max(B.BMemberPK),
  80. max(a.AccFlag)
  81. into pro_iCount, AmountFee,
  82. membPK_A, membPK_B, membPK_C,
  83. pro_AccFlag
  84. from VideoRecord a inner join ModelInfo b on a.ModelPK = b.PK
  85. where a.PK = tablepk;
  86. elseif lower(tablename)= lower('OrderRecord') THEN #商业订单
  87. Set pro_isS = 1;
  88. Set AccountRecord_stype = '订单';
  89. Set AccountRecord_Atype_A = '订单支付';
  90. Set AccountRecord_Atype_B = '服务收入';
  91. Set AccountRecord_Atype_Other = '服务分成收入';
  92. Select Count(*), Max(a.Coin),
  93. Max(a.MemberPK), max(b.MemberPK), max(C.MemberPK),
  94. max(a.AccFlag)
  95. into pro_iCount, AmountFee,
  96. membPK_A, membPK_B, membPK_C,
  97. pro_AccFlag
  98. from OrderRecord a Inner Join ModelInfo b on a.ModelPK = b.PK
  99. Left Join BrokerInfor c on a.BrokerPK = c.PK
  100. where a.PK = tablepk;
  101. elseif lower(tablename)= lower('ModelInfo.PK') THEN #是否模卡 (虚拟数据表)
  102. Set AccountRecord_stype = '模卡';
  103. Set AccountRecord_Atype_A = '模卡支付';
  104. Set AccountRecord_Atype_B = '模卡收入';
  105. Set AccountRecord_Atype_Other = '模卡分成收入';
  106. Set pro_isM = 1;
  107. Set membPK_B = -1;
  108. Set pro_AccFlag = 1;
  109. Select Count(*), Max(b.Price), Max(a.MemberPK)
  110. into pro_iCount, AmountFee, membPK_A
  111. From ModelInfo a inner Join ModelCard b on a.CardPK = b.PK
  112. Where a.PK = tablepk;
  113. elseif lower(tablename)= lower('ParttySign') THEN #活动(会员参加付款,平台收款, 模特不收款)
  114. Set AccountRecord_stype = '活动';
  115. Set AccountRecord_Atype_A = '活动支出';
  116. Set AccountRecord_Atype_B = '活动收入';
  117. Set AccountRecord_Atype_Other = '活动分成收入';
  118. Set pro_isP = 1;
  119. Set membPK_B = -1;
  120. select Count(*), Max(a.Fee),
  121. Max(a.MemberPK), max(a.AccFlag)
  122. into pro_iCount, AmountFee, membPK_A, pro_AccFlag
  123. from ParttySign a
  124. Where a.PK = tablepk;
  125. elseif lower(tablename)= lower('CashRecord') THEN #充值,提现
  126. Select Count(*), Max(a.Fee),
  127. Max(case when LOCATE('提现',a.PState)>0 then a.memberPK else -1 end),
  128. Max(case when LOCATE('支付',a.PState)>0 then a.memberPK else -1 end),
  129. Max(case when LOCATE('提现',a.PState)>0 then 1 else 0 end),
  130. Max(case when LOCATE('支付',a.PState)>0 then 1 else 0 end),
  131. Max(a.AccFlag)
  132. into pro_iCount, AmountFee, membPK_A, membPK_B,
  133. pro_isOutCash, pro_isInCash, pro_AccFlag
  134. from CashRecord a
  135. where a.PK = tablepk;
  136. if IFNULL(pro_isOutCash, 0) = 1 then
  137. Set AccountRecord_stype = '充值提现';
  138. elseif IFNULL(pro_isInCash, 0) = 1 then
  139. Set AccountRecord_stype = '充值提现';
  140. else
  141. Select -1 as Result, concat('无法识别当前业务是充值还是提现。') as mess;
  142. LEAVE leave_proc;
  143. end if;
  144. Set AccountRecord_Atype_A = '提现支出';
  145. Set AccountRecord_Atype_B = '充值币额收入';
  146. Set AccountRecord_Atype_Other = '充值提现分成收入';
  147. else
  148. Select -1 as Result, concat('参数tablename=',tablename,',系统暂不支持处理') as mess;
  149. LEAVE leave_proc;
  150. end if;
  151. #检查是否满足分摊计算条件
  152. Set AmountFee = IFNULL(AmountFee,0);
  153. if (pro_iCount <> 1) then
  154. Select -2 as Result, CONCAT('参数:',tablename,'或PK=',Cast(tablepk as CHAR),'传入错误') as mess;
  155. LEAVE leave_proc;
  156. elseif IFNULL(pro_AccFlag,0) = 9 THEN
  157. Select 1 as Result, '当前费用已处理' as mess;
  158. LEAVE leave_proc;
  159. elseif IFNULL(pro_AccFlag,0) <> 1 THEN
  160. Select -3 as Result, '当前业务还未完结' as mess;
  161. LEAVE leave_proc;
  162. elseif IFNULL(membPK_A,0) = 0 or IFNULL(membPK_B,0) = 0 THEN
  163. Select -5 as Result, '当前业务中,数据不完整:会员PK或才人PK为空' as mess;
  164. LEAVE leave_proc;
  165. elseif AmountFee <=0 then
  166. Select -6 as Result, '当前业务中,金额为零,无需处理。' as mess;
  167. LEAVE leave_proc;
  168. end if;
  169. #获得经纪人,模特和会员各自的介绍人
  170. #仅(红包+视频聊天+商业订单演出)才考虑分成部分的人员PK
  171. #当人才的推荐人(D)为经纪人(c)时,作为推荐人的身份部分(D),不参与分成
  172. #推荐人(D)是模特时,不参与分成
  173. if (pro_isR>0 or pro_isV>0 or pro_isS>0) THEN
  174. Select IntroducerPK into membPK_D From memberinfo where PK = membPK_B;
  175. Select IntroducerPK into membPK_E From memberinfo where PK = membPK_A;
  176. end if;
  177. Set membPK_C = ifnull(membPK_C,0);
  178. Set membPK_D = ifnull(membPK_D,0);
  179. Set membPK_E = ifnull(membPK_E,0);
  180. if membPK_D = membPK_C THEN
  181. Set membPK_D=0;
  182. end if;
  183. if (membPK_D>0) and Exists (Select 1 From memberinfo Where PK = membPK_D AND MembType = 7) then
  184. Set membPK_D=0;
  185. END IF;
  186. #获取各类分摊比例
  187. if pro_isR = 1 THEN #红包
  188. Set Rate_A = 100;
  189. select ratio_R, ratio_RB into Rate_B, Rate_C
  190. from ModelInfo b
  191. where b.MemberPK = membPK_B; #模特比例,经纪人比例,这2个信息从模特中获取
  192. select IfNull(c.ratio_RR, b.ratio_RR) into Rate_D
  193. from memberinfo a Left Join ModelInfo b on a.PK = b.MemberPK
  194. Left Join BrokerInfor c on a.PK = C.MemberPK
  195. where a.pk = membPK_D; #模特的推荐人比例,从模特的推荐人的数据中获取
  196. select IfNull(c.ratio_RRM, b.ratio_RRM) into Rate_E
  197. from memberinfo a Left Join ModelInfo b on a.PK = b.MemberPK
  198. Left Join BrokerInfor c on a.PK = C.MemberPK
  199. where a.pk = membPK_E; #会员的推荐人比例,从会员的推荐人的数据中获取
  200. elseif pro_isV = 1 THEN #是否视频
  201. Set Rate_A = 100;
  202. select ratio_V, ratio_VB into Rate_B, Rate_C
  203. from ModelInfo b
  204. where b.MemberPK = membPK_B;
  205. select IfNull(c.ratio_VR, b.ratio_VR) into Rate_D
  206. from memberinfo a Left Join ModelInfo b on a.PK = b.MemberPK
  207. Left Join BrokerInfor c on a.PK = C.MemberPK
  208. where a.pk = membPK_D; #模特的推荐人比例,从模特的推荐人的数据中获取
  209. select IfNull(c.ratio_VRM, b.ratio_VRM) into Rate_E
  210. from memberinfo a Left Join ModelInfo b on a.PK = b.MemberPK
  211. Left Join BrokerInfor c on a.PK = C.MemberPK
  212. where a.pk = membPK_E; #会员的推荐人比例,从会员的推荐人的数据中获取
  213. elseif pro_isS = 1 THEN #是否商业订单
  214. Set Rate_A = 100;
  215. select ratio_S, ratio_SB into Rate_B, Rate_C
  216. from ModelInfo b
  217. where b.MemberPK = membPK_B;
  218. select IfNull(c.ratio_SR, b.ratio_SR) into Rate_D
  219. from memberinfo a Left Join ModelInfo b on a.PK = b.MemberPK
  220. Left Join BrokerInfor c on a.PK = C.MemberPK
  221. where a.pk = membPK_D; #模特的推荐人比例,从模特的推荐人的数据中获取
  222. select IfNull(c.ratio_SRM, b.ratio_SRM) into Rate_E
  223. from memberinfo a Left Join ModelInfo b on a.PK = b.MemberPK
  224. Left Join BrokerInfor c on a.PK = C.MemberPK
  225. where a.pk = membPK_E; #会员的推荐人比例,从会员的推荐人的数据中获取
  226. elseif pro_isM =1 then #是否模卡
  227. Set Rate_A = 100;
  228. elseif pro_isP=1 then #是否活动
  229. Set Rate_A = 100;
  230. elseif pro_isInCash=1 then #是否充值
  231. Set Rate_B = 100;
  232. elseif pro_isOutCash=1 then #是否取现
  233. Set Rate_A = 100;
  234. else
  235. Select -7 as Result, concat('参数tablename=',tablename,',系统暂不支持处理') as mess;
  236. LEAVE leave_proc;
  237. end if;
  238. Set Rate_A = Rate_A/100.0;
  239. Set Rate_B = ifnull(Rate_B,0)/100.0;
  240. Set Rate_C = ifnull(Rate_C,0)/100.0;
  241. Set Rate_D = ifnull(Rate_D,0)/100.0;
  242. Set Rate_E = ifnull(Rate_E,0)/100.0;
  243. if (Rate_B>1 or Rate_C>1 or Rate_D>1 or Rate_E>1) THEN
  244. Select -8 as Result, '当前人才的费用分摊比例设置有误,比例系数不可大于100%.' as mess;
  245. LEAVE leave_proc;
  246. elseIF (Rate_B+Rate_C+Rate_D+Rate_E > 1.2) THEN
  247. Select -9 as Result, '当前人才的费用分摊比例设置有误,各分摊系数相加大于120%' as mess;
  248. LEAVE leave_proc;
  249. end if;
  250. #计算各自分摊金额,平台分摊金额
  251. Select AmountFee * (Case when membPK_A>0 then Rate_A else 0 end),
  252. AmountFee * (Case when membPK_B>0 then Rate_B else 0 end),
  253. AmountFee * (Case when membPK_C>0 then Rate_C else 0 end),
  254. AmountFee * (Case when membPK_D>0 then Rate_D else 0 end),
  255. AmountFee * (Case when membPK_E>0 then Rate_E else 0 end)
  256. into Fee_A, Fee_B, Fee_C, Fee_D, Fee_E;
  257. Set Fee_F = AmountFee - Fee_B - Fee_C - Fee_D - Fee_E;
  258. #检查会员帐户余额是否足够扣除(模卡容许扣款至负数)。
  259. IF (pro_isR=1 OR pro_isV=1 OR pro_isS=1 OR pro_isP=1 OR pro_isOutCash=1 ) then
  260. Select IFNULL(coin_A,0) into curAccLeft From memberinfo where PK = membPK_A;
  261. Set curAccLeft = IFNull(curAccLeft,0);
  262. if Fee_A > curAccLeft THEN
  263. Select -10 as Result, concat('当前会员帐户余额【',CAST(FORMAT(curAccLeft,0) as char),'】,不足以完成业务。') as mess;
  264. LEAVE leave_proc;
  265. end if;
  266. end if;
  267. #设置状态位 + 保存分摊金额 + 记录账户变更表 (启用事务?)
  268. START TRANSACTION;
  269. #a)设置状态位
  270. if lower(tablename)= lower('RedPacket') THEN
  271. Update RedPacket
  272. Set AccFlag = 9
  273. where PK = tablepk and AccFlag=1;
  274. elseif lower(tablename)= lower('VideoRecord') THEN
  275. Update VideoRecord
  276. Set AccFlag = 9
  277. where PK = tablepk and AccFlag=1;
  278. elseif lower(tablename)= lower('OrderRecord') THEN
  279. Update OrderRecord
  280. Set AccFlag = 9
  281. where PK = tablepk and AccFlag=1;
  282. elseif lower(tablename)= lower('ParttySign') THEN
  283. Update ParttySign
  284. Set AccFlag = 9
  285. where PK = tablepk and AccFlag=1;
  286. elseif lower(tablename)= lower('CashRecord') THEN
  287. Update CashRecord
  288. Set AccFlag = 9
  289. where PK = tablepk and AccFlag=1;
  290. elseif lower(tablename)= lower('ModelInfo.PK') then
  291. set recordcount=0; #即不做任何处理
  292. else
  293. ROLLBACK;
  294. Select -11 as Result, concat('参数tablename=',tablename,',系统暂不支持处理') as mess;
  295. LEAVE leave_proc;
  296. end if;
  297. Set recordcount = ROW_COUNT();
  298. if (pro_isM=0) and (recordcount <> 1 ) THEN #不考虑模卡的情况
  299. ROLLBACK;
  300. Select -12 as Result, '当前业务已被处理,不可重复处理。' as mess;
  301. LEAVE leave_proc;
  302. end if;
  303. #保存分摊金额
  304. IF (pro_isR =1 or pro_isV=1 or pro_isS = 1) THEN
  305. #>A 处理会员帐户
  306. if (membPK_A>0) then
  307. Update memberinfo
  308. Set coin_A = ifnull(coin_A,0) - Fee_A,
  309. coin_OR = IFNULL(coin_OR,0) + pro_isR*Fee_A,
  310. coin_OV = IFNULL(coin_OV,0) + pro_isV*Fee_A,
  311. coin_OS = IFNULL(coin_OS,0) + pro_isS*Fee_A
  312. where PK = membPK_A;
  313. end if;
  314. #红包和商业订单,需要扣减(预扣金额)
  315. if (pro_isR=1 or pro_isS = 1) then
  316. Update memberinfo
  317. Set Coin_OI = ifNull(Coin_OI,0) - Fee_A
  318. Where PK = membPK_A;
  319. end if;
  320. #> B模特
  321. if (membPK_B>0) then
  322. Update memberinfo
  323. Set coin_A = ifnull(coin_A,0) + Fee_B,
  324. coin_IR= IFNULL(coin_IR,0) + pro_isR*Fee_B,
  325. coin_IV= IFNULL(coin_IV,0) + pro_isV*Fee_B,
  326. coin_IS= IFNULL(coin_IS,0) + pro_isS*Fee_B
  327. where PK = membPK_B;
  328. end if;
  329. #> C经纪人
  330. if (membPK_C > 0) AND (Fee_C<>0) THEN
  331. Update memberinfo
  332. Set coin_A = ifnull(coin_A,0) + Fee_C,
  333. coin_IRR= IFNULL(coin_IRR,0) + pro_isR*Fee_C,
  334. coin_IVV= IFNULL(coin_IVV,0) + pro_isV*Fee_C,
  335. coin_ISS= IFNULL(coin_ISS,0) + pro_isS*Fee_C
  336. where PK = membPK_C;
  337. end if;
  338. #>D 模特(才人)的推荐人
  339. if (membPK_D > 0) AND (Fee_D<>0) THEN
  340. Update memberinfo
  341. Set coin_A = ifnull(coin_A,0) + Fee_D,
  342. coin_IRRR= IFNULL(coin_IRRR,0) + Fee_D
  343. where PK = membPK_D;
  344. end if;
  345. #>E 会员的推荐人
  346. if (membPK_E > 0) AND (Fee_E<>0) THEN
  347. Update memberinfo
  348. Set coin_A = ifnull(coin_A,0) + Fee_E,
  349. coin_IRRRM= IFNULL(coin_IRRR,0) + Fee_E
  350. where PK = membPK_E;
  351. end if;
  352. ELSEIF pro_isM >0 THEN #是否模卡
  353. Update memberinfo
  354. Set coin_A = ifnull(coin_A,0) - Fee_A,
  355. coin_OM = IFNULL(coin_OM,0) + Fee_A
  356. where PK = membPK_A;
  357. ELSEIF pro_isP >0 THEN #是否活动
  358. Update memberinfo
  359. Set coin_A = ifnull(coin_A,0) - Fee_A,
  360. coin_OP = IFNULL(coin_OP,0) + Fee_A
  361. where PK = membPK_A;
  362. ELSEIF pro_isInCash >0 THEN #是否充值
  363. Update memberinfo
  364. Set coin_A = ifnull(coin_A,0) + Fee_B,
  365. coin_I = IFNULL(coin_I,0) + Fee_B
  366. where PK = membPK_B;
  367. ELSEIF pro_isOutCash >0 THEN #是否取现
  368. Update memberinfo
  369. Set coin_A = ifnull(coin_A,0) - Fee_A,
  370. coin_O = IFNULL(coin_O,0) + Fee_A
  371. where PK = membPK_A;
  372. ELSE
  373. ROLLBACK;
  374. Select -13 as Result, '软件内部错误。' as mess;
  375. LEAVE leave_proc;
  376. END IF;
  377. #记录账户变动记录,为了充分利用索引,临时记录ADate
  378. Set AccountRecord_ADate = SYSDATE();
  379. if (membPK_A>0) AND (Fee_A<>0) then
  380. Insert Into AccountRecord( MemberPK, ADate, SType, LinkPK, AType, Coin )
  381. Values ( membPK_A, AccountRecord_ADate, AccountRecord_stype, tablepk, AccountRecord_Atype_A, Fee_A);
  382. end if;
  383. if (membPK_B>0) AND (Fee_B<>0) then
  384. if (Rate_B < 1) then
  385. Set AccountRecord_abstract = Concat('收入系数:',CAST(FORMAT(Rate_B*100,0) as char), '%');
  386. end if;
  387. Insert Into AccountRecord( MemberPK, ADate, SType, LinkPK, AType, Coin, abstract )
  388. Values ( membPK_B, AccountRecord_ADate, AccountRecord_stype, tablepk, AccountRecord_Atype_B, Fee_B, AccountRecord_abstract);
  389. end if;
  390. if (membPK_C>0) AND (Fee_C<>0) then
  391. Insert Into AccountRecord( MemberPK, ADate, SType, LinkPK, AType, Coin, abstract )
  392. Values ( membPK_C, AccountRecord_ADate, AccountRecord_stype, tablepk, AccountRecord_Atype_Other, Fee_C, Concat('经纪人分成系数:',CAST(FORMAT(Rate_C*100,0) as char), '%'));
  393. end if;
  394. if (membPK_D>0) AND (Fee_D<>0) then
  395. Insert Into AccountRecord( MemberPK, ADate, SType, LinkPK, AType, Coin, abstract )
  396. Values ( membPK_D, AccountRecord_ADate, AccountRecord_stype, tablepk, AccountRecord_Atype_Other, Fee_D, Concat('模特推荐人分红系数:',CAST(FORMAT(Rate_D*100,0) as char), '%'));
  397. end if;
  398. if (membPK_E>0) AND (Fee_E<>0) then
  399. Insert Into AccountRecord( MemberPK, ADate, SType, LinkPK, AType, Coin, abstract )
  400. Values ( membPK_E, AccountRecord_ADate, AccountRecord_stype, tablepk, AccountRecord_Atype_Other, Fee_E, Concat('会员推荐人分红系数:',CAST(FORMAT(Rate_E*100,0) as char), '%'));
  401. end if;
  402. #记录当前余额
  403. Update AccountRecord,
  404. (select PK, coin_A from memberinfo Where PK IN (membPK_A, membPK_B, membPK_C, membPK_D, membPK_E) ) B
  405. Set AccountRecord.Balance = B.coin_A
  406. Where AccountRecord.ADate = AccountRecord_ADate
  407. and AccountRecord.SType= AccountRecord_stype
  408. and AccountRecord.LinkPK= tablepk
  409. and AccountRecord.MemberPK = B.PK;
  410. IF sql_error = 1 THEN
  411. ROLLBACK;
  412. Select -14 as Result, '数据保存发生未知异常' as mess;
  413. LEAVE leave_proc;
  414. ELSE
  415. COMMIT;
  416. #rollback;
  417. END IF;
  418. #返回成功值
  419. Select 0 as Result, 'success' as mess;
  420. END;