member_fcode.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/4/6
  6. * Time: 下午1:42
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/fcode/mfcode.php');
  9. require_once (BASE_ROOT_PATH . '/helper/fcode/operator.php');
  10. require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
  11. class member_fcodeControl extends mbMemberControl
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function listOp()
  18. {
  19. $mod_fcode = Model('goods_fcode');
  20. $items = $mod_fcode->getFcodeList(array('mobile' => session_helper::cur_mobile()),'*','fc_state asc,fc_id asc',$this->page_size());
  21. $page_count = $mod_fcode->gettotalpage();
  22. $fcodes = [];
  23. $gids = [];
  24. foreach ($items as $item) {
  25. $fcoder = new fcode\mfcode($item);
  26. $fcode = $fcoder->format();
  27. $gids[] = intval($fcode['goods_id']);
  28. $fcodes[] = $fcode;
  29. }
  30. if(empty($fcodes))
  31. {
  32. return self::outsuccess(array('special_list' => null,
  33. 'fcodes' => null,
  34. 'summary' => null,
  35. 'groupbuy' => null,
  36. 'limitime' => null,
  37. 'bundling' => null,
  38. 'mobile_page' => mobile_page($page_count)));
  39. }
  40. else
  41. {
  42. $blocks = $this->format($fcodes);
  43. $helper = new goods_helper();
  44. $ret = $helper->cart_summary($gids,$related_goods);
  45. return self::outsuccess(array('special_list' => $blocks,
  46. 'fcodes' => $fcodes,
  47. 'summary' => $ret['summary'],
  48. 'groupbuy' => $ret['groupbuy'],
  49. 'limitime' => $ret['limitime'],
  50. 'bundling' => $ret['bundling'],
  51. 'mobile_page' => mobile_page($page_count)));
  52. }
  53. }
  54. private function format($fcodes)
  55. {
  56. $blocks = [];
  57. foreach ($fcodes as $fcode)
  58. {
  59. $block = [];
  60. $block['item_title'] = '';
  61. $block['item_type'] = 'home1';
  62. $item['image'] = '';
  63. $item['show_type'] = "fcode";
  64. $item['show_data'] = strval($fcode['fcode_id']);
  65. $item['type'] = "goods";
  66. $item['data'] = strval($fcode['goods_id']);;
  67. $item['title'] = '';
  68. $block['items'][] = $item;
  69. $blocks[] = $block;
  70. $blocks[] = special_formater::def_divider();
  71. }
  72. return $blocks;
  73. }
  74. public function addOp()
  75. {
  76. $fc_code = $_GET['fcode'];
  77. $user_key = $_GET['key'];
  78. if(empty($fc_code) || empty($user_key)) {
  79. return self::outerr(errcode::ErrParamter,"参数错误,请输入正确的参数");
  80. }
  81. try
  82. {
  83. $fcode = new fcode\mfcode($fc_code);
  84. if($fcode->used()) {
  85. return self::outerr(errcode::ErrParamter,"该F码已经使用过了,不能添加.");
  86. }
  87. if($fcode->expired()) {
  88. return self::outerr(errcode::ErrParamter,"该F码已经过期,不能添加.");
  89. }
  90. if($fcode->user_key() != $user_key) {
  91. return self::outerr(errcode::ErrParamter,"密钥不正确,可能输入错误或者已经被其他人占用.");
  92. }
  93. $oper = new fcode\operator($fcode->commonid(),$fcode->batch_code());
  94. $oper->change($fcode->params(),session_helper::cur_mobile());
  95. return self::outsuccess(null);
  96. }
  97. catch (Exception $ex) {
  98. return self::outerr(errcode::ErrParamter,"参数错误,没有此F码.");
  99. }
  100. }
  101. }