Inviterpro.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 分销商品控制器
  10. */
  11. class Inviterpro extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. }
  17. /*
  18. * 获取分销商品列表
  19. */
  20. public function index()
  21. {
  22. if (!config('ds_config.inviter_open')) {
  23. $result = array_merge(array('goods_list' => array(),), mobile_page(''));
  24. } else {
  25. $goods_model = model('goods');
  26. $condition = array();
  27. $condition[] = array('inviter_open', '=', 1);
  28. if (input('param.keyword')) {
  29. $condition[] = array('goods_name', 'like', '%' . input('param.keyword') . '%');
  30. }
  31. if (input('param.gc_id')) {
  32. $condition[] = array('gc_id_1', '=', intval(input('param.gc_id')));
  33. }
  34. $cache_key = 'api-inviterpro' . md5(serialize($condition)) . '-' . intval(input('param.page'));
  35. $result = rcache($cache_key);
  36. if (empty($result)) {
  37. $goods_list = $goods_model->getGoodsCommonList($condition, '*', 10);
  38. foreach ($goods_list as $key => $goods) {
  39. $goods_info = $goods_model->getGoodsInfo(array('goods_commonid' => $goods['goods_commonid']), 'goods_id');
  40. $goods_list[$key]['goods_id'] = $goods_info['goods_id'];
  41. $goods_list[$key]['goods_image_url'] = goods_cthumb($goods['goods_image'], 240);
  42. $goods_list[$key]['inviter_amount'] = 0;
  43. if (config('ds_config.inviter_show')) {
  44. $inviter_amount = round($goods['inviter_ratio'] / 100 * $goods['goods_price'] * floatval(config('ds_config.inviter_ratio_1')) / 100, 2);
  45. if ($inviter_amount > 0) {
  46. $goods_list[$key]['inviter_amount'] = $inviter_amount;
  47. }
  48. }
  49. }
  50. $page_count = $goods_model->page_info;
  51. $result = array_merge(array('goods_list' => $goods_list,), mobile_page($page_count));
  52. wcache($cache_key, $result);
  53. }
  54. }
  55. ds_json_encode(10000, '', $result);
  56. }
  57. }