Order.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <?php
  2. /**
  3. * Order.php UTF-8
  4. * 订单信息
  5. *
  6. * @date : 2018/1/19 14:59
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\request;
  13. use think\Log;
  14. use think\Session;
  15. class Order {
  16. private $order_id = '';
  17. private $app_id = 0;
  18. private $status = 1;
  19. private $is_standard = 2;
  20. private $currency = 'CNY';
  21. private $cp_order_id = '';
  22. private $product_price = 0.00;
  23. private $product_real_price = 0.00;
  24. private $product_id = '';
  25. private $product_cnt = 1;
  26. private $product_name = '';
  27. private $product_desc = '';
  28. private $ext = ''; /* CP附加参数 */
  29. private $cp_payback_url = ''; /* CP回调地址 */
  30. private $coupon_amount = 0; /* 代金卷抵扣 */
  31. private $ptb_amount = 0; /* 平台币使用金额 */
  32. private $gm_amount = 0; /* 游戏币使用金额 */
  33. private $integral = 0; /* 游戏币使用金额 */
  34. private $integral_money = 0; /* 使用积分抵扣金额 */
  35. private $rebate_amount = 0; /* 返利金额 */
  36. private $payway = ''; /* 支付方式 */
  37. private $pay_time = 0; /* 支付完成时间 */
  38. private $is_distribute = ''; /* 是否已发货 */
  39. public function __construct($data = []) {
  40. if (!empty($data)) {
  41. $this->setData($data);
  42. }
  43. }
  44. /**
  45. * 设置订单数据
  46. *
  47. * @param array $data
  48. */
  49. public function setData($data = []) {
  50. if (empty($data)) {
  51. return;
  52. }
  53. $this->setOrderId(get_val($data, 'order_id'));
  54. $this->setIsStandard(get_val($data, 'is_standard', 2));
  55. $this->setCurrency(get_val($data, 'currency', 'CNY'));
  56. $this->setCpOrderId(get_val($data, 'cp_order_id'));
  57. $this->setProductPrice(get_val($data, 'product_price', 0.00));
  58. $this->setProductRealPrice(get_val($data, 'product_price', 0.00));
  59. $this->setProductId(get_val($data, 'product_id'));
  60. $this->setProductCnt(get_val($data, 'product_cnt', 1));
  61. $this->setProductName(get_val($data, 'product_name'));
  62. $this->setProductDesc(get_val($data, 'product_desc'));
  63. $this->setExt(get_val($data, 'ext'));
  64. }
  65. /**
  66. * 从查询中设置订单数据
  67. *
  68. * @param array $order_data
  69. */
  70. public function setDataFromOrder($order_data = []) {
  71. if (empty($order_data)) {
  72. return;
  73. }
  74. $this->setOrderId($order_data['order_id']);
  75. $this->setAppId($order_data['app_id']);
  76. $this->setCpOrderId($order_data['cp_order_id']);
  77. $this->setCurrency($order_data['currency']);
  78. $this->setProductPrice($order_data['amount']);
  79. $this->setProductRealPrice($order_data['real_amount']);
  80. $this->setProductId($order_data['product_id']);
  81. $this->setProductCnt($order_data['product_cnt']);
  82. $this->setProductName($order_data['product_name']);
  83. $this->setProductDesc($order_data['payext']['product_desc']);
  84. $this->setCouponAmount($order_data['coupon_amount']);
  85. $this->setPtbAmount($order_data['ptb_amount']);
  86. $this->setGmAmount($order_data['gm_amount']);
  87. $this->setIntegral($order_data['integral']);
  88. $this->setIntegralMoney($order_data['integral_money']);
  89. $this->setRebateAmount($order_data['rebate_amount']);
  90. $this->setPayway($order_data['payway']);
  91. $this->setStatus($order_data['status']);
  92. $this->setPayTime($order_data['pay_time']);
  93. }
  94. /**
  95. * @return string
  96. */
  97. public function getOrderId() {
  98. return $this->order_id;
  99. }
  100. /**
  101. * @param string $order_id
  102. */
  103. public function setOrderId($order_id) {
  104. $this->order_id = $order_id;
  105. }
  106. /**
  107. * @return int
  108. */
  109. public function getIsStandard() {
  110. return $this->is_standard;
  111. }
  112. /**
  113. * @param int $is_standard
  114. */
  115. public function setIsStandard($is_standard) {
  116. $this->is_standard = $is_standard;
  117. }
  118. /**
  119. * @return string
  120. */
  121. public function getCurrency() {
  122. return $this->currency;
  123. }
  124. /**
  125. * @param string $currency
  126. */
  127. public function setCurrency($currency) {
  128. $this->currency = $currency;
  129. }
  130. /**
  131. * @return string
  132. */
  133. public function getCpOrderId() {
  134. return $this->cp_order_id;
  135. }
  136. /**
  137. * @param string $cp_order_id
  138. */
  139. public function setCpOrderId($cp_order_id) {
  140. $this->cp_order_id = $cp_order_id;
  141. }
  142. /**
  143. * @return float
  144. */
  145. public function getProductPrice() {
  146. return $this->product_price;
  147. }
  148. /**
  149. * @param float $product_price
  150. */
  151. public function setProductPrice($product_price) {
  152. $this->product_price = $product_price;
  153. }
  154. /**
  155. * @return string
  156. */
  157. public function getProductId() {
  158. return $this->product_id;
  159. }
  160. /**
  161. * @param string $product_id
  162. */
  163. public function setProductId($product_id) {
  164. $this->product_id = $product_id;
  165. }
  166. /**
  167. * @return int
  168. */
  169. public function getProductCnt() {
  170. return $this->product_cnt;
  171. }
  172. /**
  173. * @param int $product_cnt
  174. */
  175. public function setProductCnt($product_cnt) {
  176. $this->product_cnt = $product_cnt;
  177. }
  178. /**
  179. * @return string
  180. */
  181. public function getProductName() {
  182. return $this->product_name;
  183. }
  184. /**
  185. * @param string $product_name
  186. */
  187. public function setProductName($product_name) {
  188. $this->product_name = $product_name;
  189. }
  190. /**
  191. * @return string
  192. */
  193. public function getProductDesc() {
  194. return $this->product_desc;
  195. }
  196. /**
  197. * @param string $product_desc
  198. */
  199. public function setProductDesc($product_desc) {
  200. $this->product_desc = $product_desc;
  201. }
  202. /**
  203. * @return string
  204. */
  205. public function getExt() {
  206. return $this->ext;
  207. }
  208. /**
  209. * @param string $ext
  210. */
  211. public function setExt($ext) {
  212. $this->ext = $ext;
  213. }
  214. /**
  215. * @return float
  216. */
  217. public function getProductRealPrice() {
  218. return $this->product_real_price;
  219. }
  220. /**
  221. * @param float $product_real_price
  222. */
  223. public function setProductRealPrice($product_real_price) {
  224. $this->product_real_price = $product_real_price;
  225. }
  226. /**
  227. * @return string
  228. */
  229. public function getCpPaybackUrl() {
  230. return $this->cp_payback_url;
  231. }
  232. /**
  233. * @param string $cp_payback_url
  234. */
  235. public function setCpPaybackUrl($cp_payback_url) {
  236. $this->cp_payback_url = $cp_payback_url;
  237. }
  238. /**
  239. * @param $order_id
  240. *
  241. * @return string
  242. */
  243. public function genPayToken($order_id) {
  244. $_pay_token = md5(md5($order_id).time());
  245. Session::set('pay_token', $_pay_token);
  246. return $_pay_token;
  247. }
  248. /**
  249. * @param string $pay_token
  250. *
  251. * @return bool
  252. */
  253. public function checkPayToken($pay_token) {
  254. $_check_pay_token = Session::get('pay_token');
  255. if (empty($_check_pay_token) || 0 != strcmp($_check_pay_token, $pay_token)) {
  256. return false;
  257. }
  258. Session::delete('pay_token');
  259. return true;
  260. }
  261. /**
  262. * @return int
  263. */
  264. public function getCouponAmount() {
  265. return $this->coupon_amount;
  266. }
  267. /**
  268. * @param int $coupon_amount
  269. */
  270. public function setCouponAmount($coupon_amount) {
  271. $this->coupon_amount = $coupon_amount;
  272. }
  273. /**
  274. * @return int
  275. */
  276. public function getPtbAmount() {
  277. return $this->ptb_amount;
  278. }
  279. /**
  280. * @param int $ptb_amount
  281. */
  282. public function setPtbAmount($ptb_amount) {
  283. $this->ptb_amount = $ptb_amount;
  284. }
  285. /**
  286. * @return int
  287. */
  288. public function getGmAmount() {
  289. return $this->gm_amount;
  290. }
  291. /**
  292. * @param int $gm_amount
  293. */
  294. public function setGmAmount($gm_amount) {
  295. $this->gm_amount = $gm_amount;
  296. }
  297. /**
  298. * @return int
  299. */
  300. public function getIntegral() {
  301. return $this->integral;
  302. }
  303. /**
  304. * @param int $integral
  305. */
  306. public function setIntegral($integral) {
  307. $this->integral = $integral;
  308. }
  309. /**
  310. * @return int
  311. */
  312. public function getIntegralMoney() {
  313. return $this->integral_money;
  314. }
  315. /**
  316. * @param int $integral_money
  317. */
  318. public function setIntegralMoney($integral_money) {
  319. $this->integral_money = $integral_money;
  320. }
  321. /**
  322. * @return int
  323. */
  324. public function getRebateAmount() {
  325. return $this->rebate_amount;
  326. }
  327. /**
  328. * @param int $rebate_amount
  329. */
  330. public function setRebateAmount($rebate_amount) {
  331. $this->rebate_amount = $rebate_amount;
  332. }
  333. /**
  334. * @return string
  335. */
  336. public function getPayway() {
  337. return $this->payway;
  338. }
  339. /**
  340. * @param string $payway
  341. */
  342. public function setPayway($payway) {
  343. $this->payway = $payway;
  344. }
  345. /**
  346. * @return string
  347. */
  348. public function getPayTime() {
  349. return $this->pay_time;
  350. }
  351. /**
  352. * @param string $pay_time
  353. */
  354. public function setPayTime($pay_time) {
  355. $this->pay_time = $pay_time;
  356. }
  357. /**
  358. * @return string
  359. */
  360. public function getIsDistribute() {
  361. return $this->is_distribute;
  362. }
  363. /**
  364. * @param string $is_distribute
  365. */
  366. public function setIsDistribute($is_distribute) {
  367. $this->is_distribute = $is_distribute;
  368. }
  369. public function toArray() {
  370. // TODO: wuyonghong 2018/4/27
  371. $_data = [
  372. 'order_id' => $this->getOrderId(),
  373. 'cp_order_id' => $this->getCpOrderId(),
  374. 'is_standard' => $this->getIsStandard(),
  375. 'currency' => $this->getCurrency(),
  376. 'amount' => $this->getProductPrice(),
  377. 'real_amount' => $this->getProductRealPrice(),
  378. 'product_id' => $this->getProductId(),
  379. 'product_cnt' => $this->getProductCnt(),
  380. 'product_name' => $this->getProductName(),
  381. 'product_desc' => $this->getProductPrice(),
  382. 'ext' => $this->getExt(),
  383. 'cp_payback_url' => $this->getCpPaybackUrl(),
  384. 'coupon_amount' => $this->getCouponAmount(),
  385. 'ptb_amount' => $this->getPtbAmount(),
  386. 'gm_amount' => $this->getGmAmount(),
  387. 'integral' => $this->getIntegral(),
  388. 'integral_money' => $this->getIntegralMoney(),
  389. 'rebate_amount' => $this->getRebateAmount(),
  390. 'payway' => $this->getPayway(),
  391. 'pay_time' => $this->getPayTime(),
  392. 'is_distribute' => $this->getIsDistribute(),
  393. ];
  394. return $_data;
  395. }
  396. /**
  397. * @return int
  398. */
  399. public function getAppId() {
  400. return $this->app_id;
  401. }
  402. /**
  403. * @param int $app_id
  404. */
  405. public function setAppId($app_id) {
  406. $this->app_id = $app_id;
  407. }
  408. /**
  409. * @return int
  410. */
  411. public function getStatus() {
  412. return $this->status;
  413. }
  414. /**
  415. * @param int $status
  416. */
  417. public function setStatus($status) {
  418. $this->status = $status;
  419. }
  420. }