mfcode.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/4/6
  6. * Time: 下午8:47
  7. */
  8. namespace fcode;
  9. require_once (BASE_ROOT_PATH . '/helper/goods/commonid_helper.php');
  10. use Exception;
  11. use commonid_helper;
  12. class mfcode
  13. {
  14. private $mParams;
  15. public function __construct($param)
  16. {
  17. if(is_array($param))
  18. {
  19. $this->mParams = $param;
  20. }
  21. elseif(is_numeric($param))
  22. {
  23. $fc_id = intval($param);
  24. if($fc_id <= 0) {
  25. throw new Exception("错误的参数");
  26. }
  27. else
  28. {
  29. $mod_fcode = Model('goods_fcode');
  30. $result = $mod_fcode->find($fc_id);
  31. if(empty($result)) {
  32. throw new Exception("没有这个F码");
  33. } else {
  34. $this->mParams = $result;
  35. }
  36. }
  37. }
  38. elseif(is_string($param))
  39. {
  40. $fc_code = $param;
  41. $mod_fcode = Model('goods_fcode');
  42. $fcode = $mod_fcode->where(array('fc_code' => $fc_code))->find();
  43. if(empty($fcode)) {
  44. throw new Exception("没有这个F码");
  45. } else {
  46. $this->mParams = $fcode;
  47. }
  48. }
  49. else {
  50. throw new Exception("错误的参数");
  51. }
  52. }
  53. public function params() {
  54. return $this->mParams;
  55. }
  56. public function format()
  57. {
  58. $result = [];
  59. $result['fcode_id'] = $this->fc_id();
  60. $result['goods_id'] = commonid_helper::instance()->one_goods($this->commonid());
  61. $result['fcode'] = $this->fcode();
  62. $result['key'] = $this->user_key();
  63. $result['usable_time'] = $this->usable_time();
  64. $result['used'] = $this->used();
  65. $result['expired'] = $this->expired();
  66. return $result;
  67. }
  68. public function fc_id() {
  69. return intval($this->mParams['fc_id']);
  70. }
  71. public function commonid() {
  72. return intval($this->mParams['goods_commonid']);
  73. }
  74. public function batch_code() {
  75. return ($this->mParams['batch_code']);
  76. }
  77. public function fcode() {
  78. return $this->mParams['fc_code'];
  79. }
  80. public function used() {
  81. return (intval($this->mParams['fc_state']) == 1);
  82. }
  83. public function user_key() {
  84. return $this->mParams['user_key'];
  85. }
  86. public function mobile() {
  87. return $this->mParams['mobile'];
  88. }
  89. public function grabed() {
  90. return intval($this->mParams['grab_state']) == 1;
  91. }
  92. public function binded() {
  93. return intval($this->mParams['grab_state']) == 2;
  94. }
  95. public function usable_time() {
  96. return intval($this->mParams['usable_time']);
  97. }
  98. public function expired() {
  99. return $this->usable_time() <= time();
  100. }
  101. public function can_use() {
  102. return ($this->commonid() > 0 && $this->expired() == false && $this->used() == false);
  103. }
  104. }