Chain.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 附件店铺控制器
  15. */
  16. class Chain extends MobileMall {
  17. public function initialize() {
  18. parent::initialize();
  19. }
  20. /**
  21. * @api {POST} api/Chain/chain_list 门店列表
  22. * @apiVersion 1.0.0
  23. * @apiGroup Chain
  24. *
  25. * @apiParam {Int} brand 所属品牌id
  26. * @apiParam {Int} category 所属分类id
  27. * @apiParam {String} keyword 关键字
  28. * @apiParam {String} longitude 经度
  29. * @apiParam {String} latitude 纬度
  30. * @apiParam {String} sort_key 键
  31. * @apiParam {String} sort_value 值
  32. * @apiParam {Int} page 当前第几页
  33. * @apiParam {Int} per_page 每页多少
  34. *
  35. * @apiSuccess {String} code 返回码,10000为成功
  36. * @apiSuccess {String} message 返回消息
  37. * @apiSuccess {Object} result 返回数据
  38. * @apiSuccess {Object[]} result.chain 店铺列表 (返回字段参考chain)
  39. * @apiSuccess {Float} result.chain.distance 距离
  40. * @apiSuccess {Float} result.chain.chain_credit_percent 店铺信用评分
  41. * @apiSuccess {Int} result.page_total 总页数
  42. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  43. */
  44. public function chain_list() {
  45. //查询条件
  46. $condition = array();
  47. $condition[] = array('chain_state', '=', 1);
  48. if (!empty(input('post.keyword'))) {
  49. $condition[] = array('chain_addressname', 'like', '%' . input('post.keyword') . '%');
  50. }
  51. $lat = input('post.latitude', 0);
  52. $lng = input('post.longitude', 0);
  53. if (!is_numeric($lat) || !is_numeric($lng)) {
  54. ds_json_encode(10001, lang('param_error'));
  55. }
  56. $order = 'distance asc';
  57. $chain_object = Db::name('chain')->where($condition)
  58. ->where('(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lat . '-chain_latitude)/360),2)+COS(PI()*' . $lat . '/180)* COS(chain_latitude * PI()/180)*POW(SIN(PI()*(' . $lng . '-chain_longitude)/360),2)))) < 100000')
  59. ->fieldRaw('chain_id,store_id,chain_addressname,chain_area_info,chain_address,(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(' . $lat . '-chain_latitude)/360),2)+COS(PI()*' . $lat . '/180)* COS(chain_latitude * PI()/180)*POW(SIN(PI()*(' . $lng . '-chain_longitude)/360),2)))) as distance')
  60. ->order($order)
  61. ->paginate(['list_rows' => $this->pagesize, 'query' => request()->param()], false);
  62. $chain = $chain_object->items();
  63. $store_model = model('store');
  64. $goods_model = model('goods');
  65. foreach ($chain as $key => $value) {
  66. $store_info = $store_model->getStoreInfoByID($value['store_id']);
  67. $chain[$key]['distance'] = round($value['distance'], 2);
  68. $chain[$key]['chain_avatar'] = get_store_logo($store_info['store_avatar'], 'store_avatar');
  69. $condition = array();
  70. $condition[] = array('chain_id', '=', $value['chain_id']);
  71. $condition[] = array('goods_storage', '>', 0);
  72. $chain_goods_commonid = Db::name('chain_goods')->where($condition)->column('goods_commonid');
  73. if (!empty($chain_goods_commonid)) {
  74. $chain[$key]['goods_list'] = $goods_model->getGoodsListByColorDistinct(array(array('store_id', '=', $value['store_id']), array('goods_commend', '=', 1), array('goods_commonid', 'in', $chain_goods_commonid)), 'goods_image,goods_id,goods_price', 'goods_id desc', 0, 4);
  75. foreach ($chain[$key]['goods_list'] as $k => $v) {
  76. $chain[$key]['goods_list'][$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $value['chain_id']);
  77. }
  78. } else {
  79. $chain[$key]['goods_list'] = array();
  80. }
  81. }
  82. $result = array_merge(array('chain_list' => $chain), mobile_page($chain_object));
  83. ds_json_encode(10000, '', $result);
  84. }
  85. }