积分智能合约
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | pragma solidity ^0.4.22; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { function mul(uint256 a, uint256 b) internal constant returns (uint256) { uint256 c = a * b; assert(a == 0 || c / a == b); return c; } function div(uint256 a, uint256 b) internal constant returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function sub(uint256 a, uint256 b) internal constant returns (uint256) { assert(b <= a); return a - b; } function add(uint256 a, uint256 b) internal constant returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } } //管理者 contract owned { address public owner; function owned() public { owner = msg.sender; } // onlyOwner 函数修改器是一个合约属性,可以被继承,还能被重写。它用于在函数执行前检查某种前置条件 modifier onlyOwner { require(msg.sender == owner); _; } //实现所有权转移 function transferOwnership(address newOwner) onlyOwner public { owner = newOwner; } } //必须是合约创建者才能添加积分 销毁积分 contract JiFen is owned { using SafeMath for uint256; function JiFen() public {} //事件机制测试 event Instructor(bytes32 txid,bytes32 memberOID); struct TxDetail{ bytes32 txid; //交易编号 bytes32 memberOID; //交易者编号 string companyOID; //所属租户 string siteOID; //所属场站 string createTime; //创建时间 string updateTime; //更新时间 string integral; //积分数 string types_deductibleAmount_consumeAmount_goods_goodsQty; //类型 抵扣金额 消费金额 消费商品 商品数量 } //查看对应账号的积分余额。 任何人都可以查到任何地址的余额,正如所有数据在区块链上都是公开的。 mapping(bytes32 => uint256) public balanceOf; //用户交易明细 mapping(bytes32 => bytes32[]) public user_txs; //交易细节 mapping(bytes32 => TxDetail) public tx_details; //分配积分流程函数1、增加积分 2、增加交易明细 3、维护用户交易明细 function distributeJiFen_flow(uint256 value,bytes32 txid,bytes32 memberOID,string companyOID,string siteOID,string createTime,string updateTime,string integral,string types_deductibleAmount_consumeAmount_goods_goodsQty) onlyOwner public returns (bool, string){ balanceOf[memberOID] = balanceOf[memberOID].add(value); tx_details[txid] = TxDetail(txid,memberOID,companyOID,siteOID,createTime,updateTime,integral,types_deductibleAmount_consumeAmount_goods_goodsQty); emit Instructor(txid, memberOID); user_txs[memberOID].push(txid); return (true,"success"); } //分配积分流程函数1、减少积分 2、增加交易明细 3、维护用户交易明细 function deductJiFen_flow(uint256 value,bytes32 txid,bytes32 memberOID,string companyOID,string siteOID,string createTime,string updateTime,string integral,string types_deductibleAmount_consumeAmount_goods_goodsQty) onlyOwner public returns (bool, string){ require(balanceOf[memberOID] >= value); // Check if the targeted balance is enough balanceOf[memberOID] = balanceOf[memberOID].sub(value); // Subtract from the targeted balance tx_details[txid] = TxDetail(txid,memberOID,companyOID,siteOID,createTime,updateTime,integral,types_deductibleAmount_consumeAmount_goods_goodsQty); emit Instructor(txid, memberOID); user_txs[memberOID].push(txid); return (true,"success"); } function getUser_txsLength(bytes32 memberOID) public constant returns (uint256) { return user_txs[memberOID].length; } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构